if (psci_ops.migrate_info_type)
migrate_type = psci_ops.migrate_info_type();
if (migrate_type == PSCI_0_2_TOS_UP_MIGRATE ||
migrate_type == PSCI_0_2_TOS_UP_NO_MIGRATE) { /* There is a UP Trusted OS, find on which core it resides. */
for_each_online_cpu(cpu) if (psci_tos_resident_on(cpu)) {
tos_resident_cpu = cpu; break;
} if (tos_resident_cpu == -1)
pr_warn("UP Trusted OS resides on no online CPU\n");
}
return0;
}
/* *offlined_cpusisatemporaryarraybutpassingitasanargumentavoids *multipleallocations.
*/ staticunsignedint down_and_up_cpus(conststruct cpumask *cpus, struct cpumask *offlined_cpus)
{ int cpu; int err = 0;
cpumask_clear(offlined_cpus);
/* Try to power down all CPUs in the mask. */
for_each_cpu(cpu, cpus) { int ret = remove_cpu(cpu);
/* *cpu_down()checksthenumberofonlineCPUsbeforetheTOS *residentCPU.
*/ if (cpumask_weight(offlined_cpus) + 1 == nb_available_cpus) { if (ret != -EBUSY) {
pr_err("Unexpected return code %d while trying " "to power down last online CPU %d\n",
ret, cpu);
++err;
}
} elseif (cpu == tos_resident_cpu) { if (ret != -EPERM) {
pr_err("Unexpected return code %d while trying " "to power down TOS resident CPU %d\n",
ret, cpu);
++err;
}
} elseif (ret != 0) {
pr_err("Error occurred (%d) while trying " "to power down CPU %d\n", ret, cpu);
++err;
}
if (ret == 0)
cpumask_set_cpu(cpu, offlined_cpus);
}
/* Try to power up all the CPUs that have been offlined. */
for_each_cpu(cpu, offlined_cpus) { int ret = add_cpu(cpu);
if (ret != 0) {
pr_err("Error occurred (%d) while trying " "to power up CPU %d\n", ret, cpu);
++err;
} else {
cpumask_clear_cpu(cpu, offlined_cpus);
}
}
staticint hotplug_tests(void)
{ int i, nb_cpu_group, err = -ENOMEM;
cpumask_var_t offlined_cpus, *cpu_groups; char *page_buf;
if (!alloc_cpumask_var(&offlined_cpus, GFP_KERNEL)) return err;
nb_cpu_group = alloc_init_cpu_groups(&cpu_groups); if (nb_cpu_group < 0) goto out_free_cpus;
page_buf = (char *)__get_free_page(GFP_KERNEL); if (!page_buf) goto out_free_cpu_groups;
/* *OfcoursethelastCPUcannotbepowereddownandcpu_down()should *refusedoingthat.
*/
pr_info("Trying to turn off and on again all CPUs\n");
err = down_and_up_cpus(cpu_online_mask, offlined_cpus);
/* *TakedownCPUsbycpugroupthistime.WhenthelastCPUisturned *off,thecpugroupitselfshouldshutdown.
*/ for (i = 0; i < nb_cpu_group; ++i) {
ssize_t len = cpumap_print_to_pagebuf(true, page_buf,
cpu_groups[i]); /* Remove trailing newline. */
page_buf[len - 1] = '\0';
pr_info("Trying to turn off and on again group %d (CPUs %s)\n",
i, page_buf);
err += down_and_up_cpus(cpu_groups[i], offlined_cpus);
}
if (broadcast) { /* *Thelocaltimerwillbeshutdown,weneedtoentertick *broadcast.
*/
ret = tick_broadcast_enter(); if (ret) { /* *Intheabsenceofhardwarebroadcastmechanism, *thisCPUmightbeusedtobroadcastwakeups,which *maybewhyenteringtickbroadcasthasfailed. *Thereislittlethekernelcandotoworkaround *that,soenterWFIinstead(idlestate0).
*/
cpu_do_idle();
ret = 0; goto out_arch_exit;
}
}
ret = state->enter(dev, drv, index);
if (broadcast)
tick_broadcast_exit();
out_arch_exit:
arch_cpu_idle_exit();
return ret;
}
staticint suspend_test_thread(void *arg)
{ int cpu = (long)arg; int i, nb_suspend = 0, nb_shallow_sleep = 0, nb_err = 0; struct cpuidle_device *dev; struct cpuidle_driver *drv; /* No need for an actual callback, we just want to wake up the CPU. */ struct timer_list wakeup_timer;
/* Wait for the main thread to give the start signal. */
wait_for_completion(&suspend_threads_started);
/* Set maximum priority to preempt all other threads on this CPU. */
sched_set_fifo(current);
dev = this_cpu_read(cpuidle_devices);
drv = cpuidle_get_cpu_driver(dev);
pr_info("CPU %d entering suspend cycles, states 1 through %d\n",
cpu, drv->state_count - 1);
timer_setup_on_stack(&wakeup_timer, dummy_callback, 0); for (i = 0; i < NUM_SUSPEND_CYCLE; ++i) { int index; /* *Testallpossiblestates,except0(whichisusuallyWFIand *doesn'tusePSCI).
*/ for (index = 1; index < drv->state_count; ++index) { int ret; struct cpuidle_state *state = &drv->states[index];
if (atomic_dec_return_relaxed(&nb_active_threads) == 0)
complete(&suspend_threads_done);
for (;;) { /* Needs to be set first to avoid missing a wakeup. */
set_current_state(TASK_INTERRUPTIBLE); if (kthread_should_park()) break;
schedule();
}
pr_info("CPU %d suspend test results: success %d, shallow states %d, errors %d\n",
cpu, nb_suspend, nb_shallow_sleep, nb_err);
kthread_parkme();
return nb_err;
}
staticint suspend_tests(void)
{ int i, cpu, err = 0; struct task_struct **threads; int nb_threads = 0;
threads = kmalloc_array(nb_available_cpus, sizeof(*threads),
GFP_KERNEL); if (!threads) return -ENOMEM;
for_each_online_cpu(cpu) { struct task_struct *thread; /* Check that cpuidle is available on that CPU. */ struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
if (!dev || !drv) {
pr_warn("cpuidle not available on CPU %d, ignoring\n",
cpu); continue;
}
thread = kthread_create_on_cpu(suspend_test_thread,
(void *)(long)cpu, cpu, "psci_suspend_test"); if (IS_ERR(thread))
pr_err("Failed to create kthread on CPU %d\n", cpu); else
threads[nb_threads++] = thread;
}
if (nb_threads < 1) {
err = -ENODEV; goto out;
}
atomic_set(&nb_active_threads, nb_threads);
/* *Wakeupthesuspendthreads.Toavoidthemainthreadbeingpreempted *beforeallthethreadshavebeenunparked,thesuspendthreadswill *waitforthecompletionofsuspend_threads_started.
*/ for (i = 0; i < nb_threads; ++i)
wake_up_process(threads[i]);
complete_all(&suspend_threads_started);
wait_for_completion(&suspend_threads_done);
/* Stop and destroy all threads, get return status. */ for (i = 0; i < nb_threads; ++i) {
err += kthread_park(threads[i]);
err += kthread_stop(threads[i]);
}
out:
cpuidle_resume_and_unlock();
kfree(threads); return err;
}
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 und die Messung sind noch experimentell.