Date: Sat, 11 Aug 2007 13:28:38 GMT From: Roman Divacky <rdivacky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 125054 for review Message-ID: <200708111328.l7BDScgr041714@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125054 Change 125054 by rdivacky@rdivacky_witten on 2007/08/11 13:27:47 Prepare for using memory-location independant memid instead of plain uaddr. Affected files ... .. //depot/projects/soc2007/rdivacky/linux_futex/sys/compat/linux/linux_futex.c#10 edit Differences ... ==== //depot/projects/soc2007/rdivacky/linux_futex/sys/compat/linux/linux_futex.c#10 (text+ko) ==== @@ -67,7 +67,7 @@ TAILQ_ENTRY(waiting_proc) wp_list; }; struct futex { - void *f_uaddr; + intptr_t f_memid; int f_refcount; LIST_ENTRY(futex) f_list; TAILQ_HEAD(lf_waiting_proc, waiting_proc) f_waiting_proc; @@ -86,11 +86,12 @@ #define FUTEX_SYSTEM_LOCK sx_xlock(&futex_lock) #define FUTEX_SYSTEM_UNLOCK sx_xunlock(&futex_lock) -static struct futex *futex_get(void *, int); +static struct futex *futex_get(intptr_t, int); static void futex_put(struct futex *); static int futex_sleep(struct futex *, struct thread *, unsigned long); static int futex_wake(struct futex *, int, struct futex *, int); static int futex_atomic_op(struct thread *td, int encoded_op, caddr_t uaddr); +static intptr_t futex_hash(void *addr); /* support.s */ int futex_xchgl(int oparg, caddr_t uaddr, int *oldval); @@ -106,11 +107,11 @@ int ret; struct l_timespec timeout = {0, 0}; int error = 0; - struct futex *f; + struct futex *f, *f2; struct futex *newf; int timeout_hz; struct timeval tv = {0, 0}; - struct futex *f2; + intptr_t m, m2; int op_ret; #ifdef DEBUG @@ -167,8 +168,8 @@ (timeout_hz == 0)) timeout_hz = 1; - - f = futex_get(args->uaddr, FUTEX_UNLOCKED); + m = futex_hash(args->uaddr); + f = futex_get(m, FUTEX_UNLOCKED); ret = futex_sleep(f, td, timeout_hz); futex_put(f); @@ -220,7 +221,8 @@ printf("FUTEX_WAKE %d: uaddr = %p, val = %d\n", td->td_proc->p_pid, args->uaddr, args->val); #endif - f = futex_get(args->uaddr, FUTEX_UNLOCKED); + m = futex_hash(args->uaddr); + f = futex_get(m, FUTEX_UNLOCKED); td->td_retval[0] = futex_wake(f, args->val, NULL, 0); futex_put(f); @@ -241,8 +243,10 @@ return EAGAIN; } - f = futex_get(args->uaddr, FUTEX_UNLOCKED); - newf = futex_get(args->uaddr2, FUTEX_UNLOCKED); + m = futex_hash(args->uaddr); + m2 = futex_hash(args->uaddr2); + f = futex_get(m, FUTEX_UNLOCKED); + newf = futex_get(m2, FUTEX_UNLOCKED); td->td_retval[0] = futex_wake(f, args->val, newf, (int)(unsigned long)args->timeout); futex_put(f); @@ -254,8 +258,10 @@ case LINUX_FUTEX_REQUEUE: FUTEX_SYSTEM_LOCK; - f = futex_get(args->uaddr, FUTEX_UNLOCKED); - newf = futex_get(args->uaddr2, FUTEX_UNLOCKED); + m = futex_hash(args->uaddr); + m2 = futex_hash(args->uaddr2); + f = futex_get(m, FUTEX_UNLOCKED); + newf = futex_get(m2, FUTEX_UNLOCKED); td->td_retval[0] = futex_wake(f, args->val, newf, (int)(unsigned long)args->timeout); futex_put(f); @@ -279,8 +285,10 @@ td->td_proc->p_pid, args->uaddr, args->op, args->val, args->uaddr2, args->val3); #endif - f = futex_get(args->uaddr, FUTEX_UNLOCKED); - f2 = futex_get(args->uaddr2, FUTEX_UNLOCKED); + m = futex_hash(args->uaddr); + m2 = futex_hash(args->uaddr2); + f = futex_get(m, FUTEX_UNLOCKED); + f2 = futex_get(m2, FUTEX_UNLOCKED); /* * This function returns positive number as results and @@ -334,14 +342,14 @@ } static struct futex * -futex_get(void *uaddr, int locked) +futex_get(intptr_t memid, int locked) { struct futex *f; if (locked == FUTEX_UNLOCKED) FUTEX_LOCK; LIST_FOREACH(f, &futex_list, f_list) { - if (f->f_uaddr == uaddr) { + if (f->f_memid == memid) { f->f_refcount++; if (locked == FUTEX_UNLOCKED) FUTEX_UNLOCK; @@ -350,7 +358,7 @@ } f = malloc(sizeof(*f), M_LINUX, M_WAITOK); - f->f_uaddr = uaddr; + f->f_memid = memid; f->f_refcount = 1; TAILQ_INIT(&f->f_waiting_proc); LIST_INSERT_HEAD(&futex_list, f, f_list); @@ -438,7 +446,7 @@ } else { if (newf != NULL) { /* futex_put called after tsleep */ - wp->wp_new_futex = futex_get(newf->f_uaddr, + wp->wp_new_futex = futex_get(newf->f_memid, FUTEX_LOCKED); wakeup_one(wp); if (count - n >= n2) @@ -513,3 +521,9 @@ return (-ENOSYS); } } + +static intptr_t +futex_hash(void *addr) +{ + return (intptr_t)addr; +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708111328.l7BDScgr041714>