#ifdef CONFIG_GENERIC_SMP_IDLE_THREAD /* * For the hotplug case we keep the task structs around and reuse * them.
*/ static DEFINE_PER_CPU(struct task_struct *, idle_threads);
/** * idle_init - Initialize the idle thread for a cpu * @cpu: The cpu for which the idle thread should be initialized * * Creates the thread if it does not exist.
*/ static __always_inline void idle_init(unsignedint cpu)
{ struct task_struct *tsk = per_cpu(idle_threads, cpu);
if (!tsk) {
tsk = fork_idle(cpu); if (IS_ERR(tsk))
pr_err("SMP: fork_idle() failed for CPU %u\n", cpu); else
per_cpu(idle_threads, cpu) = tsk;
}
}
/** * idle_threads_init - Initialize idle threads for all cpus
*/ void __init idle_threads_init(void)
{ unsignedint cpu, boot_cpu;
boot_cpu = smp_processor_id();
for_each_possible_cpu(cpu) { if (cpu != boot_cpu)
idle_init(cpu);
}
} #endif
/** * smpboot_thread_fn - percpu hotplug thread loop function * @data: thread data pointer * * Checks for thread stop and park conditions. Calls the necessary * setup, cleanup, park and unpark functions for the registered * thread. * * Returns 1 when the thread should exit, 0 otherwise.
*/ staticint smpboot_thread_fn(void *data)
{ struct smpboot_thread_data *td = data; struct smp_hotplug_thread *ht = td->ht;
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
preempt_disable(); if (kthread_should_stop()) {
__set_current_state(TASK_RUNNING);
preempt_enable(); /* cleanup must mirror setup */ if (ht->cleanup && td->status != HP_THREAD_NONE)
ht->cleanup(td->cpu, cpu_online(td->cpu));
kfree(td); return 0;
}
if (kthread_should_park()) {
__set_current_state(TASK_RUNNING);
preempt_enable(); if (ht->park && td->status == HP_THREAD_ACTIVE) {
BUG_ON(td->cpu != smp_processor_id());
ht->park(td->cpu);
td->status = HP_THREAD_PARKED;
}
kthread_parkme(); /* We might have been woken for stop */ continue;
}
BUG_ON(td->cpu != smp_processor_id());
/* Check for state change setup */ switch (td->status) { case HP_THREAD_NONE:
__set_current_state(TASK_RUNNING);
preempt_enable(); if (ht->setup)
ht->setup(td->cpu);
td->status = HP_THREAD_ACTIVE; continue;
case HP_THREAD_PARKED:
__set_current_state(TASK_RUNNING);
preempt_enable(); if (ht->unpark)
ht->unpark(td->cpu);
td->status = HP_THREAD_ACTIVE; continue;
}
tsk = kthread_create_on_cpu(smpboot_thread_fn, td, cpu,
ht->thread_comm); if (IS_ERR(tsk)) {
kfree(td); return PTR_ERR(tsk);
}
kthread_set_per_cpu(tsk, cpu); /* * Park the thread so that it could start right on the CPU * when it is available.
*/
kthread_park(tsk);
get_task_struct(tsk);
*per_cpu_ptr(ht->store, cpu) = tsk; if (ht->create) { /* * Make sure that the task has actually scheduled out * into park position, before calling the create * callback. At least the migration thread callback * requires that the task is off the runqueue.
*/ if (!wait_task_inactive(tsk, TASK_PARKED))
WARN_ON(1); else
ht->create(cpu);
} return 0;
}
int smpboot_create_threads(unsignedint cpu)
{ struct smp_hotplug_thread *cur; int ret = 0;
mutex_lock(&smpboot_threads_lock);
list_for_each_entry(cur, &hotplug_threads, list) {
ret = __smpboot_create_thread(cur, cpu); if (ret) break;
}
mutex_unlock(&smpboot_threads_lock); return ret;
}
/** * smpboot_register_percpu_thread - Register a per_cpu thread related * to hotplug * @plug_thread: Hotplug thread descriptor * * Creates and starts the threads on all online cpus.
*/ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
{ unsignedint cpu; int ret = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.