cpu_mask_t
Subsystems (2)
PATCH 1/1 cpu_mask_t
This fixes the last of my cpu_online_map damage, completing the abstraction.
Please apply,
Rusty.
Name: CPU mask patch
Author: Rusty Russell
Status: Trivial
D: This patch adds a cpu_mask_t for easy future expansion of cpu masks,
D: and an easy "migrate_to_cpu()" call for simple in-kernel affinity. It
D: also changes any_online_cpu to return NR_CPUS on failure, like
D: find_first_bit.
include/linux/init_task.h +1 -1
@@ -48,7 +48,7 @@ prio: MAX_PRIO-20, static_prio: MAX_PRIO-20, policy: SCHED_OTHER, - cpus_allowed: -1, + cpus_allowed: CPU_MASK_ALL, mm: NULL, active_mm: &init_mm, run_list: LIST_HEAD_INIT(tsk.run_list),
include/linux/sched.h +12 -5
@@ -20,6 +20,7 @@#include <asm/page.h> #include <asm/ptrace.h> #include <asm/mmu.h> +#include <asm/current.h> #include <linux/smp.h> #include <linux/sem.h>
@@ -263,7 +264,7 @@unsigned long sleep_timestamp;unsigned long policy; -unsigned long cpus_allowed; +cpu_mask_t cpus_allowed;unsigned int time_slice;struct list_head tasks;
@@ -407,9 +408,17 @@#define _STK_LIM (8*1024*1024)#if CONFIG_SMP -extern void set_cpus_allowed (task_t *p,unsigned long new_mask); +extern void set_cpus_allowed (task_t *p,cpu_mask_t new_mask); +static inline void migrate_to_cpu (unsigned int cpu) +{ +cpu_mask_t mask =CPU_MASK_NONE ; +BUG_ON (!cpu_online (cpu)); +__set_bit (cpu, (unsigned long *)&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);
@@ -475,8 +484,6 @@/* per-UID process charging. */ extern struct user_struct *alloc_uid (uid_t );extern void free_uid (struct user_struct *); - -#include <asm/current.h> extern unsigned long itimer_ticks;extern unsigned long itimer_next;
include/linux/smp.h +5 -2
@@ -86,13 +86,16 @@#define smp_call_function (func,info,retry,wait) ({ 0; })static inline void smp_send_reschedule (int cpu) { }static inline void smp_send_reschedule_all (void ) { } -#define cpu_online_map 1#define cpu_online (cpu) 1#define num_online_cpus () 1#define __per_cpu_data#define per_cpu (var, cpu) var#define this_cpu (var) var - +typedef unsigned long cpu_mask_t ; +#define CPU_MASK_ALL 1 +#define CPU_MASK_NONE 0 +#define cpu_online_mask (res,mask) do { *(res) = ((mask) & 1); } while(0) +#define any_online_cpu (mask) (((mask) & 1) ? 0 : 1)#endif /* !SMP */ #define get_cpu () ({ preempt_disable(); smp_processor_id(); })
arch/ppc64/kernel/rtasd.c +2 -3
@@ -221,7 +221,7 @@#endif cpu =0 ; -set_cpus_allowed (current,1UL <<cpu_logical_map (cpu)); +migrate_to_cpu (cpu);while (1 ) { do {
@@ -255,8 +255,7 @@ cpu =0 ; } -set_cpus_allowed (current,1UL <<cpu_logical_map (cpu)); - +migrate_to_cpu (cpu);/* Check all cpus for pending events before sleeping*/ if (!first_pass) {
include/asm-i386/smp.h +17 -8
@@ -99,14 +99,6 @@return hweight32 (cpu_online_map); } -extern inline int any_online_cpu (unsigned int mask) -{ -if (mask & cpu_online_map) -return __ffs (mask & cpu_online_map); - -return -1 ; -} -static __inlineint hard_smp_processor_id (void ) {/* we don't want to mark this access volatile - bad code generation */
@@ -117,6 +109,23 @@ {/* we don't want to mark this access volatile - bad code generation */ return GET_APIC_LOGICAL_ID (*(unsigned long *)(APIC_BASE +APIC_LDR )); +} + +/* This has to be bitop capable, so for most archs, an unsigned long */ +typedef unsigned long cpu_mask_t ; +#define CPU_MASK_ALL (~0UL) +#define CPU_MASK_NONE (0UL) + +static inline void cpu_online_mask (cpu_mask_t *res,cpu_mask_t mask) +{ + *res = (mask & cpu_online_map); +} + +static inline unsigned int any_online_cpu (cpu_mask_t mask) +{ +if (mask & cpu_online_map) +return __ffs (mask & cpu_online_map); +return NR_CPUS ; }#endif /* !__ASSEMBLY__ */
include/asm-ia64/smp.h +12 -2
@@ -51,12 +51,22 @@return hweight64 (cpu_online_map); } -extern inline int any_online_cpu (unsigned int mask) +/* This has to be bitop capable, so for most archs, an unsigned long */ +typedef unsigned long cpu_mask_t ; +#define CPU_MASK_ALL (~0UL) +#define CPU_MASK_NONE (0UL) + +static inline void cpu_online_mask (cpu_mask_t *res,cpu_mask_t mask) +{ + *res = (mask & cpu_online_map); +} + +static inline unsigned int any_online_cpu (cpu_mask_t mask) {if (mask & cpu_online_map)return __ffs (mask & cpu_online_map); -return -1 ; +return NR_CPUS ; }/*
include/asm-ppc/smp.h +11 -2
@@ -54,12 +54,21 @@return hweight32 (cpu_online_map); } -extern inline int any_online_cpu (unsigned int mask) +typedef unsigned long cpu_mask_t ; +#define CPU_MASK_ALL (~0UL) +#define CPU_MASK_NONE (0UL) + +static inline void cpu_online_mask (cpu_mask_t *res,cpu_mask_t mask) +{ + *res = (mask & cpu_online_map); +} + +static inline unsigned int any_online_cpu (cpu_mask_t mask) {if (mask & cpu_online_map)return __ffs (mask & cpu_online_map); -return -1 ; +return NR_CPUS ; }extern int smp_hw_index[];
kernel/sched.c +23 -21
133 lines not on this page · raw message
kernel/softirq.c +1 -2
@@ -370,8 +370,7 @@ 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 ();
Documentation/sched-coding.txt +4 -1
@@ -103,7 +103,10 @@ 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.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.