linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: raz ben yehuda <raziebe@gmail.com>
To: linux-rt-users@vger.kernel.org
Subject: Subject: [PATCH 1/2] priority System V Semaphores
Date: Wed, 21 Dec 2011 00:26:38 +0200	[thread overview]
Message-ID: <1324419998.20886.8.camel@raz> (raw)

>From bf3cbcb4d90bdd0b06048091ff516e1dfd61e349 Mon Sep 17 00:00:00 2001
From: raz <raziebe@gmail.com>
Date: Tue, 20 Dec 2011 22:38:14 +0200


Currnet 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




                 reply	other threads:[~2011-12-20 22:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324419998.20886.8.camel@raz \
    --to=raziebe@gmail.com \
    --cc=linux-rt-users@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).