Skip to contentSkip to conversation

Add optional functions to set_task_cpu

PATCH In review Con Kolivas 2 participants 3 messages Nov 1, 2004 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add optional functions to set_task_cpu

Add optional functions to set_task_cpu

Some cpu schedulers may want to do work when set task_cpu is called. For completeness, Add a common version of task_cpu and set_task_cpu to scheduler.c and make it privatised.

Add support to ingosched and staircase.

include/linux/sched.h +2 -27
Index: linux-2.6.10-rc1-mm2-plugsched1/include/linux/sched.h
===================================================================
@@ -1076,33 +1076,8 @@ extern void recalc_sigpending(void);
 
 extern void signal_wake_up(struct task_struct *t, int resume_stopped);
 
-/*
- * Wrappers for p->thread_info->cpu access. No-op on UP.
- */
-#ifdef CONFIG_SMP
-
-static inline unsigned int task_cpu(const struct task_struct *p)
-{
-	return p->thread_info->cpu;
-}
-
-static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
-{
-	p->thread_info->cpu = cpu;
-}
-
-#else
-
-static inline unsigned int task_cpu(const struct task_struct *p)
-{
-	return 0;
-}
-
-static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
-{
-}
-
-#endif /* CONFIG_SMP */
+extern unsigned int task_cpu(const struct task_struct *p);
+extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
 
 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
 extern void arch_pick_mmap_layout(struct mm_struct *mm);
include/linux/scheduler.h +8 -0
Index: linux-2.6.10-rc1-mm2-plugsched1/include/linux/scheduler.h
===================================================================
@@ -10,6 +10,8 @@
  */
 struct sched_drv
 {
+	unsigned int (*task_cpu)(const struct task_struct *);
+	void (*set_task_cpu)(struct task_struct *, unsigned int);
 	void (*init_sched_domain_sysctl)(void);
 	void (*destroy_sched_domain_sysctl)(void);
 	void (*account_steal_time)(struct task_struct *, cputime_t);
@@ -57,6 +59,12 @@ struct sched_drv
 };
 
 /*
+ * List functions that have common variants that many schedulers use.
+ */
+extern unsigned int common_task_cpu(const struct task_struct *p);
+extern void common_set_task_cpu(struct task_struct *p, unsigned int cpu);
+
+/*
  * All private per-scheduler entries in task_struct are defined here as
  * separate structs placed into the cpusched union in task_struct.
  */
kernel/sched.c +2 -0
Index: linux-2.6.10-rc1-mm2-plugsched1/kernel/sched.c
===================================================================
@@ -4085,6 +4085,8 @@ static void ingo_destroy_sched_domain_sy
 #endif
 
 struct sched_drv ingo_sched_drv = {
+	.task_cpu		= common_task_cpu,
+	.set_task_cpu		= common_set_task_cpu,
 	.init_sched_domain_sysctl = ingo_init_sched_domain_sysctl,
 	.destroy_sched_domain_sysctl = ingo_destroy_sched_domain_sysctl,
 	.account_steal_time	= ingo_account_steal_time,
kernel/scheduler.c +39 -1
Index: linux-2.6.10-rc1-mm2-plugsched1/kernel/scheduler.c
===================================================================
@@ -44,6 +44,10 @@
 DEFINE_PER_CPU(struct kernel_stat, kstat);
 EXPORT_PER_CPU_SYMBOL(kstat);
 
+unsigned int task_cpu(const struct task_struct *p);
+
+void set_task_cpu(struct task_struct *p, unsigned int cpu);
+
 #ifdef CONFIG_SMP
 /***
  * kick_process - kick a running thread to enter/exit the kernel
@@ -62,7 +66,31 @@ void kick_process(task_t *p)
 		smp_send_reschedule(cpu);
 	preempt_enable();
 }
-#endif
+
+/*
+ * Wrappers for p->thread_info->cpu access. No-op on UP.
+ */
+unsigned int common_task_cpu(const struct task_struct *p)
+{
+	return p->thread_info->cpu;
+}
+
+void common_set_task_cpu(struct task_struct *p, unsigned int cpu)
+{
+	p->thread_info->cpu = cpu;
+}
+
+#else
+
+unsigned int common_task_cpu(const struct task_struct *p)
+{
+	return 0;
+}
+
+void common_set_task_cpu(struct task_struct *p, unsigned int cpu)
+{
+}
+#endif /* CONFIG_SMP */
 
 #ifdef CONFIG_PREEMPT
 #ifdef CONFIG_DEBUG_PREEMPT
@@ -1000,6 +1028,16 @@ static int __init scheduler_setup(char *
 
 __setup ("cpusched=", scheduler_setup);
 
+unsigned int task_cpu(const struct task_struct *p)
+{
+	return scheduler->task_cpu(p);
+}
+
+void set_task_cpu(struct task_struct *p, unsigned int cpu)
+{
+	scheduler->set_task_cpu(p, cpu);
+}
+
 void init_sched_domain_sysctl(void)
 {
 	scheduler->init_sched_domain_sysctl();
kernel/staircase.c +2 -0
Index: linux-2.6.10-rc1-mm2-plugsched1/kernel/staircase.c
===================================================================
@@ -3817,6 +3817,8 @@ static void sc_destroy_sched_domain_sysc
 #endif
 
 struct sched_drv sc_sched_drv = {
+	.task_cpu		= common_task_cpu,
+	.set_task_cpu		= common_set_task_cpu,
 	.init_sched_domain_sysctl = sc_init_sched_domain_sysctl,
 	.destroy_sched_domain_sysctl = sc_destroy_sched_domain_sysctl,
 	.account_steal_time	= sc_account_steal_time,
#1 lore raw

It would be nice to get nicksched included too.

- mattt

Quoted 1 line · Con Kolivas

Add optional functions to set_task_cpu

#2 lore raw
Quoted 1 line · Matt Heler

It would be nice to get nicksched included too.

I'd like that too, but ultimately that's up to Nick's discretion.

Cheers,
Con