lkml.org 
[lkml]   [2011]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectSubject: PATCH[1:2] priority System V Semaphores
From
Date
From bf3cbcb4d90bdd0b06048091ff516e1dfd61e349 Mon Sep 17 00:00:00 2001
From: raz <raziebe@gmail.com>
Date: Tue, 20 Dec 2011 22:38:14 +0200

Current Linux implementation for System V semaphores is FIFO.
Meaning, first task to sleep on the semaphore is the first
task to awake.
This patch (and the one follows) makes it possible to
have the higher (rt) priority task awake first.

For user space usage i present SETFIFO and SETPRIO
new options for semctl.
To define a priority semaphore do:

...
semid = semget(..)
..
semctl(semid, semnum, SETPRIO)

semctl marks semnum semaphore in a semaphore array
as priority semaphore.

Signed-off-by: raz <raziebe@gmail.com>
---
include/linux/sem.h | 4 ++++
ipc/sem.c | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/include/linux/sem.h b/include/linux/sem.h
index 10d6b22..d553406 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -19,6 +19,10 @@
#define SEM_STAT 18
#define SEM_INFO 19

+/* semctl Additional Command Definitions. */
+#define SETPRIO 20 /* priority semaphore */
+#define SETFIFO 21 /* fifo based semahphore */
+
/* Obsolete, used only for backwards compatibility and libc5 compiles */
struct semid_ds {
struct ipc_perm sem_perm; /* permissions .. see ipc.h */
diff --git a/ipc/sem.c b/ipc/sem.c
index 5215a81..90dc5a1 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -90,10 +90,13 @@
#include <asm/uaccess.h>
#include "util.h"

+#define PRIO_SEM 1
+
/* One semaphore structure for each semaphore in the system. */
struct sem {
int semval; /* current value */
int sempid; /* pid of last operation */
+ int flags; /* PRIO of FIFO, defaults to FIFO */
struct list_head sem_pending; /* pending single-sop operations */
};

@@ -1009,6 +1012,18 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
case GETNCNT:
err = count_semncnt(sma,semnum);
goto out_unlock;
+ case SETPRIO:
+ {
+ curr->flags |= PRIO_SEM;
+ err = 0;
+ goto out_unlock;
+ }
+ case SETFIFO:
+ {
+ curr->flags &= ~PRIO_SEM;
+ err = 0;
+ goto out_unlock;
+ }
case GETZCNT:
err = count_semzcnt(sma,semnum);
goto out_unlock;
@@ -1144,6 +1159,8 @@ SYSCALL_DEFINE(semctl)(int semid, int semnum, int cmd, union semun arg)
case GETZCNT:
case SETVAL:
case SETALL:
+ case SETFIFO:
+ case SETPRIO:
err = semctl_main(ns,semid,semnum,cmd,version,arg);
return err;
case IPC_RMID:
--
1.7.5.4





\
 
 \ /
  Last update: 2011-12-20 23:23    [W:0.098 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site