Skip to contentSkip to conversation

migrate_to_cpu helper.

PATCH New Rusty Russell 1 participant 1 message Jul 16, 2002

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

PATCH 1/1 migrate_to_cpu helper.

Part I of II, weaning us off "cpu mask is always an unsigned long".

Name: migrate_to_cpu patch
Author: Rusty Russell
Status: Trivial

D: This patch adds an easy "migrate_to_cpu()" call for simple
D: in-kernel affinity, in preparation for generic cpu maps.

Documentation/sched-coding.txt +4 -1
diff -urpN -I $.*$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25.30418/Documentation/sched-coding.txt linux-2.5.25.30418.updated/Documentation/sched-coding.txt
@@ -103,7 +103,10 @@ void set_user_nice(task_t *p, long nice)
 	Sets the "nice" value of task p to the given value.
 int setscheduler(pid_t pid, int policy, struct sched_param *param)
 	Sets the scheduling policy and parameters for the given pid.
-void set_cpus_allowed(task_t *p, unsigned long new_mask)
+void migrate_to_cpu(unsigned int cpu)
+	Migrates the current task to the cpu and nails it there.  This
+	is a more convenient form of:
+void set_cpus_allowed(task_t *p, cpu_mask_t new_mask)
 	Sets a given task's CPU affinity and migrates it to a proper cpu.
 	Callers must have a valid reference to the task and assure the
 	task not exit prematurely.  No locks can be held during the call.
include/linux/sched.h +9 -1
diff -urpN -I $.*$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25.30418/include/linux/sched.h linux-2.5.25.30418.updated/include/linux/sched.h
@@ -408,8 +408,16 @@ do { if (atomic_dec_and_test(&(tsk)->usa
 
 #if CONFIG_SMP
 extern void set_cpus_allowed(task_t *p, unsigned long new_mask);
+static inline void migrate_to_cpu(unsigned int cpu)
+{
+	unsigned long mask = 0;
+	BUG_ON(!cpu_online(cpu));
+	__set_bit(cpu, &mask);
+	set_cpus_allowed(current, mask);
+}
 #else
-# define set_cpus_allowed(p, new_mask) do { } while (0)
+#define set_cpus_allowed(p, new_mask) do { } while (0)
+#define migrate_to_cpu(cpu) do { BUG_ON((cpu) != 0); } while(0)
 #endif
 
 extern void set_user_nice(task_t *p, long nice);
kernel/sched.c +2 -2
diff -urpN -I $.*$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25.30418/kernel/sched.c linux-2.5.25.30418.updated/kernel/sched.c
@@ -1807,7 +1807,7 @@ static int migration_thread(void * bind_
 	if (cpu != master_migration_thread) {
 		while (!cpu_rq(master_migration_thread)->migration_thread)
 			yield();
-		set_cpus_allowed(current, 1UL << cpu);
+		migrate_to_cpu(cpu);
 	}
 	printk("migration_task %d on cpu=%dn", cpu, smp_processor_id());
 	ret = setscheduler(0, SCHED_FIFO, &param);
@@ -1870,7 +1870,7 @@ void __init migration_init(void)
 	int cpu;
 
 	master_migration_thread = smp_processor_id();
-	current->cpus_allowed = 1UL << master_migration_thread;
+	migrate_to_cpu(master_migration_thread);
 	
 	for (cpu = 0; cpu < NR_CPUS; cpu++) {
 		if (!cpu_online(cpu))
kernel/softirq.c +1 -2
diff -urpN -I $.*$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25.30418/kernel/softirq.c linux-2.5.25.30418.updated/kernel/softirq.c
@@ -370,8 +370,7 @@ static int ksoftirqd(void * __bind_cpu)
 	current->flags |= PF_IOTHREAD;
 	sigfillset(&current->blocked);
 
-	/* Migrate to the right CPU */
-	set_cpus_allowed(current, 1UL << cpu);
+	migrate_to_cpu(cpu);
 	if (smp_processor_id() != cpu)
 		BUG();
 

--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.