diff --git a/ChangeLog b/ChangeLog index 4506db9338..b0bb7c11e1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11498,4 +11498,10 @@ other way too, but this is more compliant with POSIX (2016-02-18). * fs/ procfs/fs_procfsproc.c: Add support for showing CPU if SMP is is enabled (2016-02-19). - + * include/pthread.h, sched.h, sys/types.h and other files: Rename + cpuset_t to cpu_set_t which is the type used in some non-standard + Linux/GNU interfaces. Move definitions of cpu_set_t to include/sys/types.h. + Add prototypes for sched_setaffinity(), sched_getaffinity(), + pthread_attr_setaffinity_np(), pthread_attr_getaffinity_np(), + pthread_setaffinity_np(), and pthread_getaffinity_np(). No implementation + is yet in place (2016-02-19). diff --git a/configs b/configs index d5a1be277d..82e43f4b00 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit d5a1be277d62a97c5115175b55771841495dcde7 +Subproject commit 82e43f4b0032f3dff1de6c91863424caf6c770fd diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 9fadbb3784..3ce3391b01 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -41,6 +41,8 @@ ****************************************************************************/ #include + +#include #include #ifdef CONFIG_SPINLOCK @@ -73,18 +75,6 @@ struct spinlock_s #endif }; -/* This is the smallest integer type that will not a bitset of all CPUs */ - -#if (CONFIG_SMP_NCPUS <= 8) -typedef volatile uint8_t cpuset_t; -#elif (CONFIG_SMP_NCPUS <= 16) -typedef volatile uint16_t cpuset_t; -#elif (CONFIG_SMP_NCPUS <= 32) -typedef volatile uint32_t cpuset_t; -#else -# error SMP: Extensions needed to support this number of CPUs -#endif - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -286,7 +276,7 @@ void spin_unlockr(FAR struct spinlock_s *lock); * ****************************************************************************/ -void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_setbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock); @@ -307,7 +297,7 @@ void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, * ****************************************************************************/ -void spin_clrbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock); diff --git a/include/pthread.h b/include/pthread.h index 00cd95772d..a949cf41f4 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -290,6 +290,16 @@ int pthread_attr_setinheritsched(FAR pthread_attr_t *attr, int pthread_attr_getinheritsched(FAR const pthread_attr_t *attr, FAR int *inheritsched); +#ifdef CONFIG_SMP +/* Set or obtain thread affinity attributes */ + +int pthread_attr_setaffinity_np(FAR pthread_attr_t *attr, + size_t cpusetsize, + FAR const cpu_set_t *cpuset); +int pthread_attr_getaffinity_np(FAR const pthread_attr_t *attr, + size_t cpusetsize, cpu_set_t *cpuset); +#endif + /* Set or obtain the default stack size */ int pthread_attr_setstacksize(FAR pthread_attr_t *attr, long stacksize); @@ -346,6 +356,15 @@ int pthread_setschedparam(pthread_t thread, int policy, FAR const struct sched_param *param); int pthread_setschedprio(pthread_t thread, int prio); +/* Thread affinity */ + +#ifdef CONFIG_SMP +int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, + FAR const cpu_set_t *cpuset); +int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, + FAR cpu_set_t *cpuset); +#endif + /* Thread-specific Data Interfaces */ int pthread_key_create(FAR pthread_key_t *key, diff --git a/include/sched.h b/include/sched.h index f3b675da72..6f3a8115c4 100644 --- a/include/sched.h +++ b/include/sched.h @@ -131,6 +131,14 @@ int sched_get_priority_max(int policy); int sched_get_priority_min(int policy); int sched_rr_get_interval(pid_t pid, FAR struct timespec *interval); +#ifdef CONFIG_SMP +/* Task affinity */ + +int sched_setaffinity(pid_t pid, size_t cpusetsize, + FAR const cpu_set_t *mask); +int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask); +#endif + /* Task Switching Interfaces (non-standard) */ int sched_lock(void); diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 0e9357834c..36742f062b 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -68,7 +70,7 @@ extern volatile spinlock_t g_cpu_irqlock; /* Used to keep track of which CPU(s) hold the IRQ lock. */ extern volatile spinlock_t g_cpu_irqsetlock; -extern volatile cpuset_t g_cpu_irqset; +extern volatile cpu_set_t g_cpu_irqset; #endif /**************************************************************************** diff --git a/sched/irq/irq_csection.c b/sched/irq/irq_csection.c index fedf44b906..e2bb1d995f 100644 --- a/sched/irq/irq_csection.c +++ b/sched/irq/irq_csection.c @@ -39,6 +39,8 @@ #include +#include + #include #include @@ -59,7 +61,7 @@ volatile spinlock_t g_cpu_irqlock = SP_UNLOCKED; /* Used to keep track of which CPU(s) hold the IRQ lock. */ volatile spinlock_t g_cpu_irqsetlock; -volatile cpuset_t g_cpu_irqset; +volatile cpu_set_t g_cpu_irqset; /**************************************************************************** * Public Functions diff --git a/sched/sched/sched.h b/sched/sched/sched.h index ca701a8a83..32fe377532 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -358,7 +358,7 @@ extern volatile spinlock_t g_cpu_schedlock; /* Used to keep track of which CPU(s) hold the IRQ lock. */ extern volatile spinlock_t g_cpu_locksetlock; -extern volatile cpuset_t g_cpu_lockset; +extern volatile cpu_set_t g_cpu_lockset; #endif /* CONFIG_SMP */ diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index bf4bf86322..83ba4b8635 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -111,7 +112,7 @@ volatile spinlock_t g_cpu_schedlock = SP_UNLOCKED; /* Used to keep track of which CPU(s) hold the IRQ lock. */ volatile spinlock_t g_cpu_locksetlock; -volatile cpuset_t g_cpu_lockset; +volatile cpu_set_t g_cpu_lockset; #endif /* CONFIG_SMP */ diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index 38e7c23b26..79d904e7ef 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -312,7 +313,7 @@ void spin_unlockr(FAR struct spinlock_s *lock) * ****************************************************************************/ -void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_setbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock) { @@ -347,7 +348,7 @@ void spin_setbit(FAR volatile cpuset_t *set, unsigned int cpu, * ****************************************************************************/ -void spin_clrbit(FAR volatile cpuset_t *set, unsigned int cpu, +void spin_clrbit(FAR volatile cpu_set_t *set, unsigned int cpu, FAR volatile spinlock_t *setlock, FAR volatile spinlock_t *orlock) {