2.5.49 - semaphore operations with timeouts

2.5.49 - semaphore operations with timeouts

Post by Mark Fashe » Wed, 27 Nov 2002 01:20:12



This patch adds a system call semtimedop which allows a program to execute a
semaphore operation with a timeout. The function behaves just like semop
except if the calling process has to be suspended. If the process has been
suspended for longer than the timeout (and of course, its semaphore
operation hasn't completed) then the system call returns EAGAIN to the
calling process (via errno). Calling semtimedop with a NULL timeout is
identical to calling semop.

The overall impact to the semaphore code is minor.

Userspace code to use/test this can be found at:
http://www.exothermic.org/linux/semtimedop.tar.gz
        --Mark

diff -urNp linux-2.5.49-orig/arch/i386/kernel/sys_i386.c linux-2.5.49/arch/i386/kernel/sys_i386.c
--- linux-2.5.49-orig/arch/i386/kernel/sys_i386.c       2002-11-22 13:41:11.000000000 -0800
+++ linux-2.5.49/arch/i386/kernel/sys_i386.c    2002-11-22 17:30:28.000000000 -0800
@@ -140,7 +140,11 @@ asmlinkage int sys_ipc (uint call, int f

        switch (call) {
        case SEMOP:
-               return sys_semop (first, (struct sembuf *)ptr, second);
+               return sys_semtimedop (first, (struct sembuf *)ptr, second, NULL);
+       case SEMTIMEDOP:
+               return sys_semtimedop (first, (struct sembuf *)ptr, second,
+                                                          (const struct timespec *)fifth);
+
        case SEMGET:
                return sys_semget (first, second, third);
        case SEMCTL: {
diff -urNp linux-2.5.49-orig/arch/ia64/ia32/sys_ia32.c linux-2.5.49/arch/ia64/ia32/sys_ia32.c
--- linux-2.5.49-orig/arch/ia64/ia32/sys_ia32.c 2002-11-22 13:40:49.000000000 -0800
+++ linux-2.5.49/arch/ia64/ia32/sys_ia32.c      2002-11-22 17:30:28.000000000 -0800
@@ -2124,6 +2124,7 @@ struct ipc_kludge {
 #define SEMOP           1
 #define SEMGET          2
 #define SEMCTL          3
+#define SEMTIMEDOP      4
 #define MSGSND         11
 #define MSGRCV         12
 #define MSGGET         13
diff -urNp linux-2.5.49-orig/arch/ia64/kernel/entry.S linux-2.5.49/arch/ia64/kernel/entry.S
--- linux-2.5.49-orig/arch/ia64/kernel/entry.S  2002-11-22 13:40:24.000000000 -0800
+++ linux-2.5.49/arch/ia64/kernel/entry.S       2002-11-22 17:30:28.000000000 -0800
@@ -1254,7 +1254,7 @@ sys_call_table:
        data8 sys_epoll_create
        data8 sys_epoll_ctl
        data8 sys_epoll_wait                    // 1245
-       data8 ia64_ni_syscall
+       data8 sys_semtimedop
        data8 ia64_ni_syscall
        data8 ia64_ni_syscall
        data8 ia64_ni_syscall
diff -urNp linux-2.5.49-orig/include/asm-i386/ipc.h linux-2.5.49/include/asm-i386/ipc.h
--- linux-2.5.49-orig/include/asm-i386/ipc.h    2002-11-22 13:40:58.000000000 -0800
+++ linux-2.5.49/include/asm-i386/ipc.h 2002-11-22 17:28:36.000000000 -0800
@@ -14,6 +14,7 @@ struct ipc_kludge {
 #define SEMOP           1
 #define SEMGET          2
 #define SEMCTL          3
+#define SEMTIMEDOP      4
 #define MSGSND         11
 #define MSGRCV         12
 #define MSGGET         13
diff -urNp linux-2.5.49-orig/include/asm-ia64/unistd.h linux-2.5.49/include/asm-ia64/unistd.h
--- linux-2.5.49-orig/include/asm-ia64/unistd.h 2002-11-22 13:40:19.000000000 -0800
+++ linux-2.5.49/include/asm-ia64/unistd.h      2002-11-22 17:28:36.000000000 -0800
@@ -235,6 +235,7 @@
 #define __NR_epoll_create              1243
 #define __NR_epoll_ctl                 1244
 #define __NR_epoll_wait                        1245
+#define __NR_semtimedop                        1246

 #if !defined(__ASSEMBLY__) && !defined(ASSEMBLER)

diff -urNp linux-2.5.49-orig/include/linux/sem.h linux-2.5.49/include/linux/sem.h
--- linux-2.5.49-orig/include/linux/sem.h       2002-11-22 13:40:39.000000000 -0800
+++ linux-2.5.49/include/linux/sem.h    2002-11-22 17:28:36.000000000 -0800
@@ -140,6 +140,8 @@ struct sysv_sem {
 asmlinkage long sys_semget (key_t key, int nsems, int semflg);
 asmlinkage long sys_semop (int semid, struct sembuf *sops, unsigned nsops);
 asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg);
+asmlinkage long sys_semtimedop (int semid, struct sembuf *sops,
+                                                               unsigned nsops, const struct timespec *timeout);

 #endif /* __KERNEL__ */

diff -urNp linux-2.5.49-orig/ipc/sem.c linux-2.5.49/ipc/sem.c
--- linux-2.5.49-orig/ipc/sem.c 2002-11-22 13:40:29.000000000 -0800
+++ linux-2.5.49/ipc/sem.c      2002-11-22 17:28:36.000000000 -0800
@@ -62,6 +62,7 @@
 #include <linux/spinlock.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
+#include <linux/time.h>
 #include <linux/smp_lock.h>
 #include <linux/security.h>
 #include <asm/uaccess.h>
@@ -969,6 +970,12 @@ static int alloc_undo(struct sem_array *

 asmlinkage long sys_semop (int semid, struct sembuf *tsops, unsigned nsops)
 {
+    return sys_semtimedop(semid, tsops, nsops, NULL);
+}
+
+asmlinkage long sys_semtimedop (int semid, struct sembuf *tsops,
+                                                               unsigned nsops, const struct timespec *timeout)
+{
        int error = -EINVAL;
        struct sem_array *sma;
        struct sembuf fast_sops[SEMOPM_FAST];
@@ -976,6 +983,7 @@ asmlinkage long sys_semop (int semid, st
        struct sem_undo *un;
        int undos = 0, decrease = 0, alter = 0;
        struct sem_queue queue;
+       unsigned long offset = MAX_SCHEDULE_TIMEOUT;

        if (nsops < 1 || semid < 0)
@@ -991,6 +999,19 @@ asmlinkage long sys_semop (int semid, st
                error=-EFAULT;
                goto out_free;
        }
+       if (timeout) {
+         struct timespec _timeout;
+         if (copy_from_user(&_timeout, timeout, sizeof(*timeout))) {
+               error = -EFAULT;
+               goto out_free;
+         }
+         if (_timeout.tv_sec < 0 || _timeout.tv_nsec < 0 ||
+                 _timeout.tv_nsec >= 1000000000L) {
+               error = -EINVAL;
+               goto out_free;
+         }
+         offset = timespec_to_jiffies(&_timeout);
+       }
        lock_semundo();
        sma = sem_lock(semid);
        error=-EINVAL;
@@ -1058,7 +1079,7 @@ asmlinkage long sys_semop (int semid, st
                sem_unlock(sma);
                unlock_semundo();

-               schedule();
+               offset = schedule_timeout(offset);

                lock_semundo();
                sma = sem_lock(semid);
@@ -1084,6 +1105,8 @@ asmlinkage long sys_semop (int semid, st
                                break;
                } else {
                        error = queue.status;
+                       if (error == -EINTR && offset == 0)
+                           error = -EAGAIN;
                        if (queue.prev) /* got Interrupt */
                                break;
                        /* Everything done by update_queue */
diff -urNp linux-2.5.49-orig/ipc/util.c linux-2.5.49/ipc/util.c
--- linux-2.5.49-orig/ipc/util.c        2002-11-22 13:40:39.000000000 -0800
+++ linux-2.5.49/ipc/util.c     2002-11-22 17:28:36.000000000 -0800
@@ -538,6 +538,13 @@ asmlinkage long sys_semop (int semid, st
        return -ENOSYS;
 }

+asmlinkage long sys_semtimedop (int semid, struct sembuf *sops, unsigned nsops,
+                                                               const struct timespec *timeout)
+{
+       return -ENOSYS;
+}
+
+
 asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
 {
        return -ENOSYS;
diff -urNp linux-2.5.49-orig/ipc/util.c.orig linux-2.5.49/ipc/util.c.orig
--- linux-2.5.49-orig/ipc/util.c.orig   1969-12-31 16:00:00.000000000 -0800
+++ linux-2.5.49/ipc/util.c.orig        2002-11-22 13:40:39.000000000 -0800
@@ -0,0 +1,587 @@
+/*
+ * linux/ipc/util.c
+ * Copyright (C) 1992 Krishna Balasubramanian
+ *
+ * Sep 1997 - Call suser() last after "normal" permission checks so we
+ *            get BSD style process accounting right.
+ *            Occurs in several places in the IPC code.
+ *            Chris Evans, <ch...@ferret.lmh.ox.ac.uk>
+ * Nov 1999 - ipc helper functions, unified SMP locking
+ *           Manfred Spraul <manfr...@colorfullife.com>
+ * Oct 2002 - One lock per IPC id. RCU ipc_free for lock-free grow_ary().
+ *            Mingming Cao <c...@us.ibm.com>
+ */
+
+#include <linux/config.h>
+#include <linux/mm.h>
+#include <linux/shm.h>
+#include <linux/init.h>
+#include <linux/msg.h>
+#include <linux/smp_lock.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/highuid.h>
+#include <linux/security.h>
+#include <linux/rcupdate.h>
+#include <linux/workqueue.h>
+
+#if defined(CONFIG_SYSVIPC)
+
+#include "util.h"
+
+/**
+ *     ipc_init        -       initialise IPC subsystem
+ *
+ *     The various system5 IPC resources (semaphores, messages and shared
+ *     memory are initialised
+ */
+
+void __init ipc_init (void)
+{
+       sem_init();
+       msg_init();
+       shm_init();
+       return;
+}
+
+/**
+ *     ipc_init_ids            -       initialise IPC identifiers
+ *     @ids: Identifier set
+ *     @size: Number of identifiers
+ *
+ *     Given a size for the ipc identifier range (limited below IPCMNI)
+ *     set up the sequence range to use then allocate and initialise the
+ *     array itself.
+ */
+
+void __init ipc_init_ids(struct ipc_ids* ids, int size)
+{
+       int i;
+       sema_init(&ids->sem,1);
+
+       if(size > IPCMNI)
+               size = IPCMNI;
+       ids->size = size;
+       ids->in_use = 0;
+       ids->max_id = -1;
+       ids->seq = 0;
+       {
+               int seq_limit = INT_MAX/SEQ_MULTIPLIER;
+               if(seq_limit > USHRT_MAX)
+                       ids->seq_max = USHRT_MAX;
+                else
+                       ids->seq_max = seq_limit;
+       }
+
+       ids->entries = ipc_rcu_alloc(sizeof(struct ipc_id)*size);
+
+       if(ids->entries == NULL) {
+               printk(KERN_ERR "ipc_init_ids() failed, ipc service disabled.\n");
+               ids->size = 0;
+       }
+       for(i=0;i<ids->size;i++)
+               ids->entries[i].p = NULL;
+}
+
+/**
+ *     ipc_findkey     -       find a key in an ipc identifier set    
+ *     @ids: Identifier set
+ *     @key: The key to find
+ *    
+ *     Requires ipc_ids.sem locked.
+ *     Returns the identifier if found or -1 if not.
+ */
+
+int ipc_findkey(struct ipc_ids* ids, key_t key)
+{
+       int id;
+       struct kern_ipc_perm* p;
+       int max_id = ids->max_id;
+
+       for (id = 0; id <= max_id; id++) {
+               p = ids->entries[id].p;
+               if(p==NULL)
+                       continue;
+               if (key == p->key)
+                       return id;
+       }
+       return -1;
+}
+
+/*
+ * Requires ipc_ids.sem locked
+ */
+static int grow_ary(struct ipc_ids* ids, int newsize)
+{
+       struct ipc_id* new;
+       struct ipc_id* old;
+       int i;
+
+       if(newsize > IPCMNI)
+               newsize = IPCMNI;
+       if(newsize <= ids->size)
+               return newsize;
+
+       new = ipc_rcu_alloc(sizeof(struct ipc_id)*newsize);
+       if(new == NULL)
+               return ids->size;
+       memcpy(new, ids->entries, sizeof(struct ipc_id)*ids->size);
+       for(i=ids->size;i<newsize;i++) {
+               new[i].p = NULL;
+       }
+       old = ids->entries;
+       i = ids->size;
+
+       /*
+        * before setting the ids->entries to the new array, there must be a
+        * wmb() to make sure that the memcpyed contents of the new array are
+        * visible before the new array becomes visible.
+        */
+       wmb();
+       ids->entries = new;
+       wmb();
+       ids->size = newsize;
+
+       ipc_rcu_free(old, sizeof(struct ipc_id)*i);
+       return ids->size;
+}
+
+/**
+ *     ipc_addid       -       add an IPC
...

read more »

 
 
 

2.5.49 - semaphore operations with timeouts

Post by Mark Fashe » Wed, 27 Nov 2002 03:30:12


[ Ok, I'm an idiot. This is the proper patch - the previous one had some
  whitespace issues and left around a spare copy of util.c ]

This patch adds a system call semtimedop which allows a program to execute a
semaphore operation with a timeout. The function behaves just like semop
except if the calling process has to be suspended. If the process has been
suspended for longer than the timeout (and of course, its semaphore
operation hasn't completed) then the system call returns EAGAIN to the
calling process (via errno). Calling semtimedop with a NULL timeout is
identical to calling semop.

The overall impact to the semaphore code is minor.

Userspace code to use/test this can be found at:
http://www.exothermic.org/linux/semtimedop.tar.gz
        --Mark

diff -urNp linux-2.5.49-orig/arch/i386/kernel/sys_i386.c linux-2.5.49/arch/i386/kernel/sys_i386.c
--- linux-2.5.49-orig/arch/i386/kernel/sys_i386.c       2002-11-22 13:41:11.000000000 -0800
+++ linux-2.5.49/arch/i386/kernel/sys_i386.c    2002-11-22 17:28:35.000000000 -0800
@@ -140,7 +140,11 @@ asmlinkage int sys_ipc (uint call, int f

        switch (call) {
        case SEMOP:
-               return sys_semop (first, (struct sembuf *)ptr, second);
+               return sys_semtimedop (first, (struct sembuf *)ptr, second, NULL);
+       case SEMTIMEDOP:
+               return sys_semtimedop (first, (struct sembuf *)ptr, second,
+                                                          (const struct timespec *)fifth);
+
        case SEMGET:
                return sys_semget (first, second, third);
        case SEMCTL: {
diff -urNp linux-2.5.49-orig/arch/ia64/ia32/sys_ia32.c linux-2.5.49/arch/ia64/ia32/sys_ia32.c
--- linux-2.5.49-orig/arch/ia64/ia32/sys_ia32.c 2002-11-22 13:40:49.000000000 -0800
+++ linux-2.5.49/arch/ia64/ia32/sys_ia32.c      2002-11-22 17:28:35.000000000 -0800
@@ -2124,6 +2124,7 @@ struct ipc_kludge {
 #define SEMOP           1
 #define SEMGET          2
 #define SEMCTL          3
+#define SEMTIMEDOP      4
 #define MSGSND         11
 #define MSGRCV         12
 #define MSGGET         13
diff -urNp linux-2.5.49-orig/arch/ia64/kernel/entry.S linux-2.5.49/arch/ia64/kernel/entry.S
--- linux-2.5.49-orig/arch/ia64/kernel/entry.S  2002-11-22 13:40:24.000000000 -0800
+++ linux-2.5.49/arch/ia64/kernel/entry.S       2002-11-22 17:28:35.000000000 -0800
@@ -1254,7 +1254,7 @@ sys_call_table:
        data8 sys_epoll_create
        data8 sys_epoll_ctl
        data8 sys_epoll_wait                    // 1245
-       data8 ia64_ni_syscall
+       data8 sys_semtimedop
        data8 ia64_ni_syscall
        data8 ia64_ni_syscall
        data8 ia64_ni_syscall
diff -urNp linux-2.5.49-orig/include/asm-i386/ipc.h linux-2.5.49/include/asm-i386/ipc.h
--- linux-2.5.49-orig/include/asm-i386/ipc.h    2002-11-22 13:40:58.000000000 -0800
+++ linux-2.5.49/include/asm-i386/ipc.h 2002-11-22 17:28:36.000000000 -0800
@@ -14,6 +14,7 @@ struct ipc_kludge {
 #define SEMOP           1
 #define SEMGET          2
 #define SEMCTL          3
+#define SEMTIMEDOP      4
 #define MSGSND         11
 #define MSGRCV         12
 #define MSGGET         13
diff -urNp linux-2.5.49-orig/include/asm-ia64/unistd.h linux-2.5.49/include/asm-ia64/unistd.h
--- linux-2.5.49-orig/include/asm-ia64/unistd.h 2002-11-22 13:40:19.000000000 -0800
+++ linux-2.5.49/include/asm-ia64/unistd.h      2002-11-22 17:28:36.000000000 -0800
@@ -235,6 +235,7 @@
 #define __NR_epoll_create              1243
 #define __NR_epoll_ctl                 1244
 #define __NR_epoll_wait                        1245
+#define __NR_semtimedop                        1246

 #if !defined(__ASSEMBLY__) && !defined(ASSEMBLER)

diff -urNp linux-2.5.49-orig/include/linux/sem.h linux-2.5.49/include/linux/sem.h
--- linux-2.5.49-orig/include/linux/sem.h       2002-11-22 13:40:39.000000000 -0800
+++ linux-2.5.49/include/linux/sem.h    2002-11-22 17:28:36.000000000 -0800
@@ -140,6 +140,8 @@ struct sysv_sem {
 asmlinkage long sys_semget (key_t key, int nsems, int semflg);
 asmlinkage long sys_semop (int semid, struct sembuf *sops, unsigned nsops);
 asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg);
+asmlinkage long sys_semtimedop (int semid, struct sembuf *sops,
+                                                               unsigned nsops, const struct timespec *timeout);

 #endif /* __KERNEL__ */

diff -urNp linux-2.5.49-orig/ipc/sem.c linux-2.5.49/ipc/sem.c
--- linux-2.5.49-orig/ipc/sem.c 2002-11-22 13:40:29.000000000 -0800
+++ linux-2.5.49/ipc/sem.c      2002-11-25 17:08:32.000000000 -0800
@@ -62,6 +62,7 @@
 #include <linux/spinlock.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
+#include <linux/time.h>
 #include <linux/smp_lock.h>
 #include <linux/security.h>
 #include <asm/uaccess.h>
@@ -969,6 +970,12 @@ static int alloc_undo(struct sem_array *

 asmlinkage long sys_semop (int semid, struct sembuf *tsops, unsigned nsops)
 {
+       return sys_semtimedop(semid, tsops, nsops, NULL);
+}
+
+asmlinkage long sys_semtimedop (int semid, struct sembuf *tsops,
+                                                               unsigned nsops, const struct timespec *timeout)
+{
        int error = -EINVAL;
        struct sem_array *sma;
        struct sembuf fast_sops[SEMOPM_FAST];
@@ -976,6 +983,7 @@ asmlinkage long sys_semop (int semid, st
        struct sem_undo *un;
        int undos = 0, decrease = 0, alter = 0;
        struct sem_queue queue;
+       unsigned long offset = MAX_SCHEDULE_TIMEOUT;

        if (nsops < 1 || semid < 0)
@@ -991,6 +999,19 @@ asmlinkage long sys_semop (int semid, st
                error=-EFAULT;
                goto out_free;
        }
+       if (timeout) {
+               struct timespec _timeout;
+               if (copy_from_user(&_timeout, timeout, sizeof(*timeout))) {
+                       error = -EFAULT;
+                       goto out_free;
+               }
+               if (_timeout.tv_sec < 0 || _timeout.tv_nsec < 0 ||
+                       _timeout.tv_nsec >= 1000000000L) {
+                       error = -EINVAL;
+                       goto out_free;
+               }
+               offset = timespec_to_jiffies(&_timeout);
+       }
        lock_semundo();
        sma = sem_lock(semid);
        error=-EINVAL;
@@ -1058,7 +1079,7 @@ asmlinkage long sys_semop (int semid, st
                sem_unlock(sma);
                unlock_semundo();

-               schedule();
+               offset = schedule_timeout(offset);

                lock_semundo();
                sma = sem_lock(semid);
@@ -1084,6 +1105,8 @@ asmlinkage long sys_semop (int semid, st
                                break;
                } else {
                        error = queue.status;
+                       if (error == -EINTR && offset == 0)
+                               error = -EAGAIN;
                        if (queue.prev) /* got Interrupt */
                                break;
                        /* Everything done by update_queue */
diff -urNp linux-2.5.49-orig/ipc/util.c linux-2.5.49/ipc/util.c
--- linux-2.5.49-orig/ipc/util.c        2002-11-22 13:40:39.000000000 -0800
+++ linux-2.5.49/ipc/util.c     2002-11-22 17:28:36.000000000 -0800
@@ -538,6 +538,13 @@ asmlinkage long sys_semop (int semid, st
        return -ENOSYS;
 }

+asmlinkage long sys_semtimedop (int semid, struct sembuf *sops, unsigned nsops,
+                                                               const struct timespec *timeout)
+{
+       return -ENOSYS;
+}
+
+
 asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
 {
        return -ENOSYS;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

2.5.49 - semaphore operations with timeouts

Post by Mark Fashe » Thu, 28 Nov 2002 00:40:14


Linus,
  Please apply this patch. There are cases during which an application may
not want to wait (potentially) forever on a semaphore operation - it needs a
timeout. Oracle (DB) uses this sort of thing in Solaris to gain a few
percent in performance increases over the alternative (setting alarms to
interrupt semaphore operations). Other applications may find utility in this
added functionality as well - if you're using semaphores already, this is a
more portable solution to the problem than using timed futexes (semtimedop
works on sysv semaphores). As far as code goes, the amount of change is tiny
- this patch is so simple, it really ought to be a shoo-in...
        --Mark

On Mon, Nov 25, 2002 at 05:25:54PM -0800, Mark Fasheh wrote:
> [ Ok, I'm an idiot. This is the proper patch - the previous one had some
>   whitespace issues and left around a spare copy of util.c ]

> This patch adds a system call semtimedop which allows a program to execute a
> semaphore operation with a timeout. The function behaves just like semop
> except if the calling process has to be suspended. If the process has been
> suspended for longer than the timeout (and of course, its semaphore
> operation hasn't completed) then the system call returns EAGAIN to the
> calling process (via errno). Calling semtimedop with a NULL timeout is
> identical to calling semop.

> The overall impact to the semaphore code is minor.

> Userspace code to use/test this can be found at:
> http://www.exothermic.org/linux/semtimedop.tar.gz
>         --Mark

diff -urNp linux-2.5.49-orig/arch/i386/kernel/sys_i386.c linux-2.5.49/arch/i386/kernel/sys_i386.c
--- linux-2.5.49-orig/arch/i386/kernel/sys_i386.c       2002-11-22 13:41:11.000000000 -0800
+++ linux-2.5.49/arch/i386/kernel/sys_i386.c    2002-11-22 17:28:35.000000000 -0800
@@ -140,7 +140,11 @@ asmlinkage int sys_ipc (uint call, int f

        switch (call) {
        case SEMOP:
-               return sys_semop (first, (struct sembuf *)ptr, second);
+               return sys_semtimedop (first, (struct sembuf *)ptr, second, NULL);
+       case SEMTIMEDOP:
+               return sys_semtimedop (first, (struct sembuf *)ptr, second,
+                                                          (const struct timespec *)fifth);
+
        case SEMGET:
                return sys_semget (first, second, third);
        case SEMCTL: {
diff -urNp linux-2.5.49-orig/arch/ia64/ia32/sys_ia32.c linux-2.5.49/arch/ia64/ia32/sys_ia32.c
--- linux-2.5.49-orig/arch/ia64/ia32/sys_ia32.c 2002-11-22 13:40:49.000000000 -0800
+++ linux-2.5.49/arch/ia64/ia32/sys_ia32.c      2002-11-22 17:28:35.000000000 -0800
@@ -2124,6 +2124,7 @@ struct ipc_kludge {
 #define SEMOP           1
 #define SEMGET          2
 #define SEMCTL          3
+#define SEMTIMEDOP      4
 #define MSGSND         11
 #define MSGRCV         12
 #define MSGGET         13
diff -urNp linux-2.5.49-orig/arch/ia64/kernel/entry.S linux-2.5.49/arch/ia64/kernel/entry.S
--- linux-2.5.49-orig/arch/ia64/kernel/entry.S  2002-11-22 13:40:24.000000000 -0800
+++ linux-2.5.49/arch/ia64/kernel/entry.S       2002-11-22 17:28:35.000000000 -0800
@@ -1254,7 +1254,7 @@ sys_call_table:
        data8 sys_epoll_create
        data8 sys_epoll_ctl
        data8 sys_epoll_wait                    // 1245
-       data8 ia64_ni_syscall
+       data8 sys_semtimedop
        data8 ia64_ni_syscall
        data8 ia64_ni_syscall
        data8 ia64_ni_syscall
diff -urNp linux-2.5.49-orig/include/asm-i386/ipc.h linux-2.5.49/include/asm-i386/ipc.h
--- linux-2.5.49-orig/include/asm-i386/ipc.h    2002-11-22 13:40:58.000000000 -0800
+++ linux-2.5.49/include/asm-i386/ipc.h 2002-11-22 17:28:36.000000000 -0800
@@ -14,6 +14,7 @@ struct ipc_kludge {
 #define SEMOP           1
 #define SEMGET          2
 #define SEMCTL          3
+#define SEMTIMEDOP      4
 #define MSGSND         11
 #define MSGRCV         12
 #define MSGGET         13
diff -urNp linux-2.5.49-orig/include/asm-ia64/unistd.h linux-2.5.49/include/asm-ia64/unistd.h
--- linux-2.5.49-orig/include/asm-ia64/unistd.h 2002-11-22 13:40:19.000000000 -0800
+++ linux-2.5.49/include/asm-ia64/unistd.h      2002-11-22 17:28:36.000000000 -0800
@@ -235,6 +235,7 @@
 #define __NR_epoll_create              1243
 #define __NR_epoll_ctl                 1244
 #define __NR_epoll_wait                        1245
+#define __NR_semtimedop                        1246

 #if !defined(__ASSEMBLY__) && !defined(ASSEMBLER)

diff -urNp linux-2.5.49-orig/include/linux/sem.h linux-2.5.49/include/linux/sem.h
--- linux-2.5.49-orig/include/linux/sem.h       2002-11-22 13:40:39.000000000 -0800
+++ linux-2.5.49/include/linux/sem.h    2002-11-22 17:28:36.000000000 -0800
@@ -140,6 +140,8 @@ struct sysv_sem {
 asmlinkage long sys_semget (key_t key, int nsems, int semflg);
 asmlinkage long sys_semop (int semid, struct sembuf *sops, unsigned nsops);
 asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg);
+asmlinkage long sys_semtimedop (int semid, struct sembuf *sops,
+                                                               unsigned nsops, const struct timespec *timeout);

 #endif /* __KERNEL__ */

diff -urNp linux-2.5.49-orig/ipc/sem.c linux-2.5.49/ipc/sem.c
--- linux-2.5.49-orig/ipc/sem.c 2002-11-22 13:40:29.000000000 -0800
+++ linux-2.5.49/ipc/sem.c      2002-11-25 17:08:32.000000000 -0800
@@ -62,6 +62,7 @@
 #include <linux/spinlock.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
+#include <linux/time.h>
 #include <linux/smp_lock.h>
 #include <linux/security.h>
 #include <asm/uaccess.h>
@@ -969,6 +970,12 @@ static int alloc_undo(struct sem_array *

 asmlinkage long sys_semop (int semid, struct sembuf *tsops, unsigned nsops)
 {
+       return sys_semtimedop(semid, tsops, nsops, NULL);
+}
+
+asmlinkage long sys_semtimedop (int semid, struct sembuf *tsops,
+                                                               unsigned nsops, const struct timespec *timeout)
+{
        int error = -EINVAL;
        struct sem_array *sma;
        struct sembuf fast_sops[SEMOPM_FAST];
@@ -976,6 +983,7 @@ asmlinkage long sys_semop (int semid, st
        struct sem_undo *un;
        int undos = 0, decrease = 0, alter = 0;
        struct sem_queue queue;
+       unsigned long offset = MAX_SCHEDULE_TIMEOUT;

        if (nsops < 1 || semid < 0)
@@ -991,6 +999,19 @@ asmlinkage long sys_semop (int semid, st
                error=-EFAULT;
                goto out_free;
        }
+       if (timeout) {
+               struct timespec _timeout;
+               if (copy_from_user(&_timeout, timeout, sizeof(*timeout))) {
+                       error = -EFAULT;
+                       goto out_free;
+               }
+               if (_timeout.tv_sec < 0 || _timeout.tv_nsec < 0 ||
+                       _timeout.tv_nsec >= 1000000000L) {
+                       error = -EINVAL;
+                       goto out_free;
+               }
+               offset = timespec_to_jiffies(&_timeout);
+       }
        lock_semundo();
        sma = sem_lock(semid);
        error=-EINVAL;
@@ -1058,7 +1079,7 @@ asmlinkage long sys_semop (int semid, st
                sem_unlock(sma);
                unlock_semundo();

-               schedule();
+               offset = schedule_timeout(offset);

                lock_semundo();
                sma = sem_lock(semid);
@@ -1084,6 +1105,8 @@ asmlinkage long sys_semop (int semid, st
                                break;
                } else {
                        error = queue.status;
+                       if (error == -EINTR && offset == 0)
+                               error = -EAGAIN;
                        if (queue.prev) /* got Interrupt */
                                break;
                        /* Everything done by update_queue */
diff -urNp linux-2.5.49-orig/ipc/util.c linux-2.5.49/ipc/util.c
--- linux-2.5.49-orig/ipc/util.c        2002-11-22 13:40:39.000000000 -0800
+++ linux-2.5.49/ipc/util.c     2002-11-22 17:28:36.000000000 -0800
@@ -538,6 +538,13 @@ asmlinkage long sys_semop (int semid, st
        return -ENOSYS;
 }

+asmlinkage long sys_semtimedop (int semid, struct sembuf *sops, unsigned nsops,
+                                                               const struct timespec *timeout)
+{
+       return -ENOSYS;
+}
+
+
 asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
 {
        return -ENOSYS;

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

 
 
 

1. 2.5.49-ac1 - more info on make error

| Knowing that modules are still broken, I changed all modules to be
| built-in and dropped all support for modules and retried the compile. I
| have disabled all but the features I really want to test on the new
| kernel, so I will not be reducing the features any more.

I haven't seen any replies or fixes for this.  Have you?

drivers/built-in.o(.data+0x31e14): undefined reference to `local symbols
in discarded section .exit.text'

Please visit http://www.kernelnewbies.org/scripts/ and download
the 'reference-discarded.pl' script, run it, and let us know where the
problem is.

--
~Randy

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. alpha parts

3. 2.5.49 ignores user suspend

4. How to get MAC address from application

5. 2.5.49-ac1 local data...

6. procps-0.99.final.tgz

7. 2.5.49 - shutdown issues on Dell Latitude

8. printer not responding - i86 computer

9. Literacy watch 2.5.49

10. COM20020 Driver Patches for 2.5.49

11. [2.5.49-bk1]Kprobes Printk Sample Driver

12. unixbench result for kernel 2.5.49 and 2.5.50

13. 2.5.49-ac1 : include/asm-386/io_apic.h