Skip to contentSkip to conversation

PI-futex: FUTEX_LOCK_PI/FUTEX_UNLOCK_PI support

PATCH In review Ingo Molnar 1 participant 1 message Mar 25, 2006

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 10/10 PI-futex: FUTEX_LOCK_PI/FUTEX_UNLOCK_PI support

From: Ingo Molnar <[email protected]>

this adds the actual pi-futex implementation, based on rt-mutexes.

----

 include/linux/futex.h |    6 
 include/linux/sched.h |    3 
 kernel/exit.c         |    8 
 kernel/fork.c         |    3 
 kernel/futex.c        |  696 +++++++++++++++++++++++++++++++++++++++++++++++---
 kernel/futex_compat.c |   11 
 6 files changed, 686 insertions(+), 41 deletions(-)
include/linux/futex.h +6 -0
Index: linux-pi-futex.mm.q/include/linux/futex.h
===================================================================
@@ -12,6 +12,8 @@
 #define FUTEX_REQUEUE		3
 #define FUTEX_CMP_REQUEUE	4
 #define FUTEX_WAKE_OP		5
+#define FUTEX_LOCK_PI		6
+#define FUTEX_UNLOCK_PI		7
 
 /*
  * Support for robust futexes: the kernel cleans up held futexes at
@@ -97,10 +99,14 @@ extern int handle_futex_death(u32 __user
 
 #ifdef CONFIG_FUTEX
 extern void exit_robust_list(struct task_struct *curr);
+extern void exit_pi_state_list(struct task_struct *curr);
 #else
 static inline void exit_robust_list(struct task_struct *curr)
 {
 }
+static inline void exit_pi_state_list(struct task_struct *curr)
+{
+}
 #endif
 
 #define FUTEX_OP_SET		0	/* *(int *)UADDR2 = OPARG; */
include/linux/sched.h +3 -0
Index: linux-pi-futex.mm.q/include/linux/sched.h
===================================================================
@@ -705,6 +705,7 @@ static inline void prefetch_stack(struct
 
 struct audit_context;		/* See audit.c */
 struct mempolicy;
+struct futex_pi_state;
 
 enum sleep_type {
 	SLEEP_NORMAL,
@@ -917,6 +918,8 @@ struct task_struct {
 #ifdef CONFIG_COMPAT
 	struct compat_robust_list_head __user *compat_robust_list;
 #endif
+	struct list_head pi_state_list;
+	struct futex_pi_state *pi_state_cache;
 
 	atomic_t fs_excl;	/* holding fs exclusive resources */
 	struct rcu_head rcu;
kernel/exit.c +8 -0
Index: linux-pi-futex.mm.q/kernel/exit.c
===================================================================
@@ -928,6 +928,14 @@ fastcall NORET_TYPE void do_exit(long co
 	tsk->mempolicy = NULL;
 #endif
 	/*
+	 * This must happen late, after the PID is not
+	 * hashed anymore:
+	 */
+	if (unlikely(!list_empty(&tsk->pi_state_list)))
+		exit_pi_state_list(tsk);
+	if (unlikely(current->pi_state_cache))
+		kfree(current->pi_state_cache);
+	/*
 	 * If DEBUG_MUTEXES is on, make sure we are holding no locks:
 	 */
 	mutex_debug_check_no_locks_held(tsk);
kernel/fork.c +3 -0
Index: linux-pi-futex.mm.q/kernel/fork.c
===================================================================
@@ -1087,6 +1087,9 @@ static task_t *copy_process(unsigned lon
 #ifdef CONFIG_COMPAT
 	p->compat_robust_list = NULL;
 #endif
+	INIT_LIST_HEAD(&p->pi_state_list);
+	p->pi_state_cache = NULL;
+
 	/*
 	 * sigaltstack should be cleared when sharing the same VM
 	 */
kernel/futex.c +658 -38

845 lines not on this page · raw message

kernel/futex_compat.c +8 -3
Index: linux-pi-futex.mm.q/kernel/futex_compat.c
===================================================================
@@ -129,14 +129,19 @@ asmlinkage long compat_sys_futex(u32 __u
 	unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
 	int val2 = 0;
 
-	if (utime && (op == FUTEX_WAIT)) {
+	if (utime && (op == FUTEX_WAIT || op == FUTEX_LOCK_PI)) {
 		if (get_compat_timespec(&t, utime))
 			return -EFAULT;
 		if (!timespec_valid(&t))
 			return -EINVAL;
-		timeout = timespec_to_jiffies(&t) + 1;
+		if (op == FUTEX_WAIT)
+			timeout = timespec_to_jiffies(&t) + 1;
+		else {
+			timeout = t.tv_sec;
+			val2 = t.tv_nsec;
+		}
 	}
-	if (op >= FUTEX_REQUEUE)
+	if (op == FUTEX_REQUEUE || op == FUTEX_CMP_REQUEUE)
 		val2 = (int) (unsigned long) utime;
 
 	return do_futex(uaddr, op, val, timeout, uaddr2, val2, val3);