Skip to contentSkip to conversation

PI-futex: scheduler support for PI

PATCH In review Ingo Molnar 2 participants 3 messages Mar 25, 2006 – Mar 26, 2006 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 4/10 PI-futex: scheduler support for PI

From: Ingo Molnar <[email protected]>

add framework to boost/unboost the priority of RT tasks.

This consists of:

- caching the 'normal' priority in ->normal_prio
- providing a functions to set/get the priority of the task
- make sched_setscheduler() aware of boosting

----

 include/linux/init_task.h |    1 
 include/linux/sched.h     |   19 +++++-
 kernel/sched.c            |  136 ++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 138 insertions(+), 18 deletions(-)
include/linux/init_task.h +1 -0
Index: linux-pi-futex.mm.q/include/linux/init_task.h
===================================================================
@@ -87,6 +87,7 @@ extern struct group_info init_groups;
 	.lock_depth	= -1,						\
 	.prio		= MAX_PRIO-20,					\
 	.static_prio	= MAX_PRIO-20,					\
+	.normal_prio	= MAX_PRIO-20,					\
 	.policy		= SCHED_NORMAL,					\
 	.cpus_allowed	= CPU_MASK_ALL,					\
 	.mm		= NULL,						\
include/linux/sched.h +17 -2
Index: linux-pi-futex.mm.q/include/linux/sched.h
===================================================================
@@ -486,7 +486,8 @@ struct signal_struct {
 
 #define MAX_PRIO		(MAX_RT_PRIO + 40)
 
-#define rt_task(p)		(unlikely((p)->prio < MAX_RT_PRIO))
+#define rt_prio(prio)		unlikely((prio) < MAX_RT_PRIO)
+#define rt_task(p)		rt_prio((p)->prio)
 #define batch_task(p)		(unlikely((p)->policy == SCHED_BATCH))
 
 /*
@@ -726,7 +727,7 @@ struct task_struct {
 #endif
 #endif
 	int load_weight;	/* for niceness load balancing purposes */
-	int prio, static_prio;
+	int prio, static_prio, normal_prio;
 	struct list_head run_list;
 	prio_array_t *array;
 
@@ -854,6 +855,9 @@ struct task_struct {
 /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
 	spinlock_t alloc_lock;
 
+	/* Protection of the PI data structures: */
+	spinlock_t pi_lock;
+
 #ifdef CONFIG_DEBUG_MUTEXES
 	/* mutex deadlock detection */
 	struct mutex_waiter *blocked_on;
@@ -1020,6 +1024,17 @@ static inline void idle_task_exit(void) 
 #endif
 
 extern void sched_idle_next(void);
+
+#ifdef CONFIG_RT_MUTEXES
+extern int rt_mutex_getprio(task_t *p);
+extern void rt_mutex_setprio(task_t *p, int prio);
+#else
+static inline int rt_mutex_getprio(task_t *p)
+{
+	return p->normal_prio;
+}
+#endif
+
 extern void set_user_nice(task_t *p, long nice);
 extern int task_prio(const task_t *p);
 extern int task_nice(const task_t *p);
kernel/sched.c +120 -16

217 lines not on this page · raw message

#1 lore raw
Quoted 17 lines · Ingo Molnar

From: Ingo Molnar <[email protected]>

add framework to boost/unboost the priority of RT tasks.

This consists of:

- caching the 'normal' priority in ->normal_prio
- providing a functions to set/get the priority of the task
- make sched_setscheduler() aware of boosting

...

kernel/sched.c +4 -0
+#ifdef CONFIG_RT_MUTEXES
+
+/*
+ * rt_mutex_setprio - set the current priority of a task

kernel/sched.c long fastcall __sched sleep_on_timeout(w · line 3686

Quoted 10 lines
kernel/sched.c +10 -0
+ * @p: task
+ * @prio: prio value (kernel-internal form)
+ *
+ * This function changes the 'effective' priority of a task. It does
+ * not touch ->normal_prio like __setscheduler().
+ *
+ * Used by the rt_mutex code to implement priority inheritance logic.
+ */
+void rt_mutex_setprio(task_t *p, int prio)
+{

This function is not really rt-mutex-related at all, is it? It's just a piece of new scheduler functionality which various things might use.

If so, it should be named something non-mutexy and should be under a different CONFIG_option which CONFIG_RT_MUTEXES selects.

Of course, we can do all that later on, if/when something else needs this facility.

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 9 lines
kernel/sched.c +9 -0
+#ifdef CONFIG_RT_MUTEXES
+
+/*
+ * rt_mutex_setprio - set the current priority of a task
+ * @p: task
+ * @prio: prio value (kernel-internal form)
+ *
+ * This function changes the 'effective' priority of a task. It does
+ * not touch ->normal_prio like __setscheduler().
Quoted 8 lines

kernel/sched.c long fastcall __sched sleep_on_timeout(w · line 3686

Quoted 5 lines

+ *
+ * Used by the rt_mutex code to implement priority inheritance logic.
+ */

kernel/sched.c +2 -0
+void rt_mutex_setprio(task_t *p, int prio)
+{

This function is not really rt-mutex-related at all, is it? It's just a piece of new scheduler functionality which various things might use.

well, this particular function should only be used by the rt-mutex subsystem, because it sets the priority of a task unconditionally. Priority will vary depending on how other tasks block on a lock held by this task. So if some other subsystem changes the priority via this interface, it will both interfere with PI, and PI will interfere with this.

Ingo