Commit 8ab9bc8e authored by Luca Barbieri's avatar Luca Barbieri Committed by David S. Miller

[PATCH] Small futex improvement

This patch makes the futex code check utime only when waiting.
This makes it possible to do futex wakes without clearing the register
containing the utime parameter.

The code also becomes cleaner.
parent 4b95a3f7
...@@ -315,6 +315,23 @@ static int futex_wait(unsigned long uaddr, ...@@ -315,6 +315,23 @@ static int futex_wait(unsigned long uaddr,
return ret; return ret;
} }
static inline int futex_wait_utime(unsigned long uaddr,
int offset,
int val,
struct timespec* utime)
{
unsigned long time = MAX_SCHEDULE_TIMEOUT;
if (utime) {
struct timespec t;
if (copy_from_user(&t, utime, sizeof(t)) != 0)
return -EFAULT;
time = timespec_to_jiffies(&t) + 1;
}
return futex_wait(uaddr, offset, val, time);
}
static int futex_close(struct inode *inode, struct file *filp) static int futex_close(struct inode *inode, struct file *filp)
{ {
struct futex_q *q = filp->private_data; struct futex_q *q = filp->private_data;
...@@ -422,17 +439,9 @@ static int futex_fd(unsigned long uaddr, int offset, int signal) ...@@ -422,17 +439,9 @@ static int futex_fd(unsigned long uaddr, int offset, int signal)
asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *utime) asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *utime)
{ {
unsigned long time = MAX_SCHEDULE_TIMEOUT;
unsigned long pos_in_page; unsigned long pos_in_page;
int ret; int ret;
if (utime) {
struct timespec t;
if (copy_from_user(&t, utime, sizeof(t)) != 0)
return -EFAULT;
time = timespec_to_jiffies(&t) + 1;
}
pos_in_page = uaddr % PAGE_SIZE; pos_in_page = uaddr % PAGE_SIZE;
/* Must be "naturally" aligned */ /* Must be "naturally" aligned */
...@@ -441,7 +450,7 @@ asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec * ...@@ -441,7 +450,7 @@ asmlinkage int sys_futex(unsigned long uaddr, int op, int val, struct timespec *
switch (op) { switch (op) {
case FUTEX_WAIT: case FUTEX_WAIT:
ret = futex_wait(uaddr, pos_in_page, val, time); ret = futex_wait_utime(uaddr, pos_in_page, val, utime);
break; break;
case FUTEX_WAKE: case FUTEX_WAKE:
ret = futex_wake(uaddr, pos_in_page, val); ret = futex_wake(uaddr, pos_in_page, val);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment