[PATCH] Small futex improvement

From: Luca Barbieri (ldb@ldb.ods.org)
Date: Mon Nov 18 2002 - 11:00:43 EST


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.

--- linux-2.5.47_ldb/kernel/futex.c~ 2002-11-01 13:31:28.000000000 +0100
+++ linux-2.5.47_ldb/kernel/futex.c 2002-11-17 21:50:41.000000000 +0100
@@ -314,6 +314,23 @@ out:
         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)
 {
         struct futex_q *q = filp->private_data;
@@ -421,17 +438,9 @@ out:
 
 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;
         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;
 
         /* Must be "naturally" aligned */
@@ -440,7 +449,7 @@ asmlinkage int sys_futex(unsigned long u
 
         switch (op) {
         case FUTEX_WAIT:
- ret = futex_wait(uaddr, pos_in_page, val, time);
+ ret = futex_wait_utime(uaddr, pos_in_page, val, utime);
                 break;
         case FUTEX_WAKE:
                 ret = futex_wake(uaddr, pos_in_page, val);



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Nov 23 2002 - 22:00:22 EST