mirror of
https://github.com/apache/nuttx.git
synced 2026-09-11 21:20:10 +00:00
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:
parent
2075eb7932
commit
a633353ec3
28 changed files with 174 additions and 355 deletions
|
|
@ -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 \
|
||||
{ \
|
||||
|
|
|
|||
|
|
@ -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) */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue