diff options
-rw-r--r-- | kern/thread.c | 22 | ||||
-rw-r--r-- | kern/thread.h | 46 |
2 files changed, 54 insertions, 14 deletions
diff --git a/kern/thread.c b/kern/thread.c index f0153d7f..e9cb0c27 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -1534,11 +1534,7 @@ thread_setup_reaper(void) condition_init(&thread_reap_condition); list_init(&thread_reap_list); - attr.name = "x15_thread_reap"; - attr.cpumap = NULL; - attr.task = NULL; - attr.policy = THREAD_SCHED_POLICY_TS; - attr.priority = THREAD_SCHED_TS_PRIO_DEFAULT; + thread_attr_init(&attr, "x15_thread_reap"); error = thread_create(&thread, &attr, thread_reap, NULL); if (error) @@ -1609,11 +1605,10 @@ thread_setup_balancer(struct thread_runq *runq) cpumap_zero(cpumap); cpumap_set(cpumap, thread_runq_id(runq)); snprintf(name, sizeof(name), "x15_thread_balance/%u", thread_runq_id(runq)); - attr.name = name; - attr.cpumap = cpumap; - attr.task = NULL; - attr.policy = THREAD_SCHED_POLICY_RR; - attr.priority = THREAD_SCHED_RT_PRIO_MIN; + thread_attr_init(&attr, name); + thread_attr_set_cpumap(&attr, cpumap); + thread_attr_set_policy(&attr, THREAD_SCHED_POLICY_RR); + thread_attr_set_priority(&attr, THREAD_SCHED_RT_PRIO_MIN); error = thread_create(&balancer, &attr, thread_balance, runq); cpumap_destroy(cpumap); @@ -1680,10 +1675,9 @@ thread_setup_idler(struct thread_runq *runq) panic("thread: unable to allocate idler thread stack"); snprintf(name, sizeof(name), "x15_thread_idle/%u", thread_runq_id(runq)); - attr.name = name; - attr.cpumap = cpumap; - attr.task = NULL; - attr.policy = THREAD_SCHED_POLICY_IDLE; + thread_attr_init(&attr, name); + thread_attr_set_cpumap(&attr, cpumap); + thread_attr_set_policy(&attr, THREAD_SCHED_POLICY_IDLE); thread_init(idler, stack, &attr, thread_idle, runq); cpumap_destroy(cpumap); diff --git a/kern/thread.h b/kern/thread.h index 0efb8268..fa8d2eca 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -184,6 +184,52 @@ struct thread_attr { }; /* + * Initialize thread creation attributes with default values. + * + * It is guaranteed that these default values include : + * - no processor affinity + * - task is inherited from parent thread + * - policy is time-sharing + * - priority is time-sharing default + * + * If the policy is changed, the priority, if applicable, must be updated + * as well. + */ +static inline void +thread_attr_init(struct thread_attr *attr, const char *name) +{ + attr->name = name; + attr->cpumap = NULL; + attr->task = NULL; + attr->policy = THREAD_SCHED_POLICY_TS; + attr->priority = THREAD_SCHED_TS_PRIO_DEFAULT; +} + +static inline void +thread_attr_set_cpumap(struct thread_attr *attr, struct cpumap *cpumap) +{ + attr->cpumap = cpumap; +} + +static inline void +thread_attr_set_task(struct thread_attr *attr, struct task *task) +{ + attr->task = task; +} + +static inline void +thread_attr_set_policy(struct thread_attr *attr, unsigned char policy) +{ + attr->policy = policy; +} + +static inline void +thread_attr_set_priority(struct thread_attr *attr, unsigned short priority) +{ + attr->priority = priority; +} + +/* * Early initialization of the thread module. * * These function make it possible to use migration and preemption control |