Add a CPU affinity set to the TCB if SMP is enable and use this CPU set as a mask for determining which CPUs the thread may run on. Add an affinity field to the attrributes to permit controlling which CPUs a pthread may run on. Implements pthread_att_setaffinity_np() and pthread_attr_getaffinity_np().

This commit is contained in:
Gregory Nutt 2016-02-19 17:33:35 -06:00
parent 2075eb7932
commit a633353ec3
28 changed files with 174 additions and 355 deletions

View file

@ -57,7 +57,24 @@
# define PTHREAD_DEFAULT_POLICY SCHED_RR
#endif
#ifdef CONFIG_SCHED_SPORADIC
/* A lot of hassle to use the old-fashioned struct initializers. But this
* gives us backward compatibility with some very old compilers.
*/
#if defined(CONFIG_SCHED_SPORADIC) && defined(CONFIG_SMP)
# define PTHREAD_ATTR_INITIALIZER \
{ \
PTHREAD_DEFAULT_PRIORITY, /* priority */ \
PTHREAD_DEFAULT_POLICY, /* policy */ \
PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \
0, /* low_priority */ \
0, /* max_repl */ \
0, /* affinity */ \
PTHREAD_STACK_DEFAULT, /* stacksize */ \
{0, 0}, /* repl_period */ \
{0, 0} /* budget */ \
}
#elif defined(CONFIG_SCHED_SPORADIC)
# define PTHREAD_ATTR_INITIALIZER \
{ \
PTHREAD_DEFAULT_PRIORITY, /* priority */ \
@ -69,6 +86,15 @@
{0, 0}, /* repl_period */ \
{0, 0}, /* budget */ \
}
#elif defined(CONFIG_SMP)
# define PTHREAD_ATTR_INITIALIZER \
{ \
PTHREAD_DEFAULT_PRIORITY, /* priority */ \
PTHREAD_DEFAULT_POLICY, /* policy */ \
PTHREAD_EXPLICIT_SCHED, /* inheritsched */ \
0, /* affinity */ \
PTHREAD_STACK_DEFAULT, /* stacksize */ \
}
#else
# define PTHREAD_ATTR_INITIALIZER \
{ \

View file

@ -148,7 +148,7 @@
# define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */
# define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */
# define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheding policy */
#define TCB_FLAG_CPU_ASSIGNED (1 << 6) /* Bit 6: Assigned to a CPU */
#define TCB_FLAG_CPU_LOCKED (1 << 6) /* Bit 6: Locked to this CPU */
#define TCB_FLAG_EXIT_PROCESSING (1 << 7) /* Bit 7: Exitting */
/* Bits 8-15: Available */
@ -562,6 +562,7 @@ struct tcb_s
uint8_t task_state; /* Current state of the thread */
#ifdef CONFIG_SMP
uint8_t cpu; /* CPU index if running or assigned */
cpu_set_t affinity; /* Bit set of permitted CPUs */
#endif
uint16_t flags; /* Misc. general status flags */
int16_t lockcount; /* 0=preemptable (not-locked) */