Skip to content

Commit c87e283

Browse files
Ingo MolnarLinus Torvalds
authored andcommitted
[PATCH] pi-futex: futex_lock_pi/futex_unlock_pi support
This adds the actual pi-futex implementation, based on rt-mutexes. [dino@in.ibm.com: fix an oops-causing race] Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Dinakar Guniguntala <dino@in.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 0cdbee9 commit c87e283

File tree

7 files changed

+828
-41
lines changed

7 files changed

+828
-41
lines changed

include/linux/futex.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#define FUTEX_REQUEUE 3
1313
#define FUTEX_CMP_REQUEUE 4
1414
#define FUTEX_WAKE_OP 5
15+
#define FUTEX_LOCK_PI 6
16+
#define FUTEX_UNLOCK_PI 7
17+
#define FUTEX_TRYLOCK_PI 8
1518

1619
/*
1720
* Support for robust futexes: the kernel cleans up held futexes at
@@ -97,10 +100,14 @@ extern int handle_futex_death(u32 __user *uaddr, struct task_struct *curr);
97100

98101
#ifdef CONFIG_FUTEX
99102
extern void exit_robust_list(struct task_struct *curr);
103+
extern void exit_pi_state_list(struct task_struct *curr);
100104
#else
101105
static inline void exit_robust_list(struct task_struct *curr)
102106
{
103107
}
108+
static inline void exit_pi_state_list(struct task_struct *curr)
109+
{
110+
}
104111
#endif
105112

106113
#define FUTEX_OP_SET 0 /* *(int *)UADDR2 = OPARG; */

include/linux/sched.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct sched_param {
8484
#include <asm/processor.h>
8585

8686
struct exec_domain;
87+
struct futex_pi_state;
8788

8889
/*
8990
* List of flags we want to share for kernel threads,
@@ -915,6 +916,8 @@ struct task_struct {
915916
#ifdef CONFIG_COMPAT
916917
struct compat_robust_list_head __user *compat_robust_list;
917918
#endif
919+
struct list_head pi_state_list;
920+
struct futex_pi_state *pi_state_cache;
918921

919922
atomic_t fs_excl; /* holding fs exclusive resources */
920923
struct rcu_head rcu;

kernel/exit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,14 @@ fastcall NORET_TYPE void do_exit(long code)
925925
mpol_free(tsk->mempolicy);
926926
tsk->mempolicy = NULL;
927927
#endif
928+
/*
929+
* This must happen late, after the PID is not
930+
* hashed anymore:
931+
*/
932+
if (unlikely(!list_empty(&tsk->pi_state_list)))
933+
exit_pi_state_list(tsk);
934+
if (unlikely(current->pi_state_cache))
935+
kfree(current->pi_state_cache);
928936
/*
929937
* If DEBUG_MUTEXES is on, make sure we are holding no locks:
930938
*/

kernel/fork.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,9 @@ static task_t *copy_process(unsigned long clone_flags,
10921092
#ifdef CONFIG_COMPAT
10931093
p->compat_robust_list = NULL;
10941094
#endif
1095+
INIT_LIST_HEAD(&p->pi_state_list);
1096+
p->pi_state_cache = NULL;
1097+
10951098
/*
10961099
* sigaltstack should be cleared when sharing the same VM
10971100
*/

0 commit comments

Comments
 (0)