migrate_to_cpu helper.
Subsystems (2)
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
@@ -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
@@ -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
@@ -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 , ¶m);
@@ -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
@@ -370,8 +370,7 @@ static int ksoftirqd(void * __bind_cpu) current->flags |=PF_IOTHREAD ;sigfillset (¤t->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.