forked from Minki/linux
Merge branch 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull cpu hotplug updates from Thomas Gleixner: "This is the first part of the ongoing cpu hotplug rework: - Initial implementation of the state machine - Runs all online and prepare down callbacks on the plugged cpu and not on some random processor - Replaces busy loop waiting with completions - Adds tracepoints so the states can be followed" More detailed commentary on this work from an earlier email: "What's wrong with the current cpu hotplug infrastructure? - Asymmetry The hotplug notifier mechanism is asymmetric versus the bringup and teardown. This is mostly caused by the notifier mechanism. - Largely undocumented dependencies While some notifiers use explicitely defined notifier priorities, we have quite some notifiers which use numerical priorities to express dependencies without any documentation why. - Control processor driven Most of the bringup/teardown of a cpu is driven by a control processor. While it is understandable, that preperatory steps, like idle thread creation, memory allocation for and initialization of essential facilities needs to be done before a cpu can boot, there is no reason why everything else must run on a control processor. Before this patch series, bringup looks like this: Control CPU Booting CPU do preparatory steps kick cpu into life do low level init sync with booting cpu sync with control cpu bring the rest up - All or nothing approach There is no way to do partial bringups. That's something which is really desired because we waste e.g. at boot substantial amount of time just busy waiting that the cpu comes to life. That's stupid as we could very well do preparatory steps and the initial IPI for other cpus and then go back and do the necessary low level synchronization with the freshly booted cpu. - Minimal debuggability Due to the notifier based design, it's impossible to switch between two stages of the bringup/teardown back and forth in order to test the correctness. So in many hotplug notifiers the cancel mechanisms are either not existant or completely untested. - Notifier [un]registering is tedious To [un]register notifiers we need to protect against hotplug at every callsite. There is no mechanism that bringup/teardown callbacks are issued on the online cpus, so every caller needs to do it itself. That also includes error rollback. What's the new design? The base of the new design is a symmetric state machine, where both the control processor and the booting/dying cpu execute a well defined set of states. Each state is symmetric in the end, except for some well defined exceptions, and the bringup/teardown can be stopped and reversed at almost all states. So the bringup of a cpu will look like this in the future: Control CPU Booting CPU do preparatory steps kick cpu into life do low level init sync with booting cpu sync with control cpu bring itself up The synchronization step does not require the control cpu to wait. That mechanism can be done asynchronously via a worker or some other mechanism. The teardown can be made very similar, so that the dying cpu cleans up and brings itself down. Cleanups which need to be done after the cpu is gone, can be scheduled asynchronously as well. There is a long way to this, as we need to refactor the notion when a cpu is available. Today we set the cpu online right after it comes out of the low level bringup, which is not really correct. The proper mechanism is to set it to available, i.e. cpu local threads, like softirqd, hotplug thread etc. can be scheduled on that cpu, and once it finished all booting steps, it's set to online, so general workloads can be scheduled on it. The reverse happens on teardown. First thing to do is to forbid scheduling of general workloads, then teardown all the per cpu resources and finally shut it off completely. This patch series implements the basic infrastructure for this at the core level. This includes the following: - Basic state machine implementation with well defined states, so ordering and prioritization can be expressed. - Interfaces to [un]register state callbacks This invokes the bringup/teardown callback on all online cpus with the proper protection in place and [un]installs the callbacks in the state machine array. For callbacks which have no particular ordering requirement we have a dynamic state space, so that drivers don't have to register an explicit hotplug state. If a callback fails, the code automatically does a rollback to the previous state. - Sysfs interface to drive the state machine to a particular step. This is only partially functional today. Full functionality and therefor testability will be achieved once we converted all existing hotplug notifiers over to the new scheme. - Run all CPU_ONLINE/DOWN_PREPARE notifiers on the booting/dying processor: Control CPU Booting CPU do preparatory steps kick cpu into life do low level init sync with booting cpu sync with control cpu wait for boot bring itself up Signal completion to control cpu In a previous step of this work we've done a full tree mechanical conversion of all hotplug notifiers to the new scheme. The balance is a net removal of about 4000 lines of code. This is not included in this series, as we decided to take a different approach. Instead of mechanically converting everything over, we will do a proper overhaul of the usage sites one by one so they nicely fit into the symmetric callback scheme. I decided to do that after I looked at the ugliness of some of the converted sites and figured out that their hotplug mechanism is completely buggered anyway. So there is no point to do a mechanical conversion first as we need to go through the usage sites one by one again in order to achieve a full symmetric and testable behaviour" * 'smp-hotplug-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (23 commits) cpu/hotplug: Document states better cpu/hotplug: Fix smpboot thread ordering cpu/hotplug: Remove redundant state check cpu/hotplug: Plug death reporting race rcu: Make CPU_DYING_IDLE an explicit call cpu/hotplug: Make wait for dead cpu completion based cpu/hotplug: Let upcoming cpu bring itself fully up arch/hotplug: Call into idle with a proper state cpu/hotplug: Move online calls to hotplugged cpu cpu/hotplug: Create hotplug threads cpu/hotplug: Split out the state walk into functions cpu/hotplug: Unpark smpboot threads from the state machine cpu/hotplug: Move scheduler cpu_online notifier to hotplug core cpu/hotplug: Implement setup/removal interface cpu/hotplug: Make target state writeable cpu/hotplug: Add sysfs state interface cpu/hotplug: Hand in target state to _cpu_up/down cpu/hotplug: Convert the hotplugged cpu work to a state machine cpu/hotplug: Convert to a state machine for the control processor cpu/hotplug: Add tracepoints ...
This commit is contained in:
commit
710d60cbf1
@ -168,7 +168,7 @@ smp_callin(void)
|
||||
cpuid, current, current->active_mm));
|
||||
|
||||
preempt_disable();
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
/* Wait until hwrpb->txrdy is clear for cpu. Return -1 on timeout. */
|
||||
|
@ -142,7 +142,7 @@ void start_kernel_secondary(void)
|
||||
|
||||
local_irq_enable();
|
||||
preempt_disable();
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -409,7 +409,7 @@ asmlinkage void secondary_start_kernel(void)
|
||||
/*
|
||||
* OK, it's off to the idle thread for us
|
||||
*/
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
void __init smp_cpus_done(unsigned int max_cpus)
|
||||
|
@ -195,7 +195,7 @@ asmlinkage void secondary_start_kernel(void)
|
||||
/*
|
||||
* OK, it's off to the idle thread for us
|
||||
*/
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HOTPLUG_CPU
|
||||
|
@ -333,7 +333,7 @@ void secondary_start_kernel(void)
|
||||
|
||||
/* We are done with local CPU inits, unblock the boot CPU. */
|
||||
set_cpu_online(cpu, true);
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
void __init smp_prepare_boot_cpu(void)
|
||||
|
@ -180,7 +180,7 @@ void start_secondary(void)
|
||||
|
||||
local_irq_enable();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -454,7 +454,7 @@ start_secondary (void *unused)
|
||||
preempt_disable();
|
||||
smp_callin();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -432,7 +432,7 @@ int __init start_secondary(void *unused)
|
||||
*/
|
||||
local_flush_tlb_all();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -396,7 +396,7 @@ asmlinkage void secondary_start_kernel(void)
|
||||
/*
|
||||
* OK, it's off to the idle thread for us
|
||||
*/
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
void __init smp_cpus_done(unsigned int max_cpus)
|
||||
|
@ -328,7 +328,7 @@ asmlinkage void start_secondary(void)
|
||||
WARN_ON_ONCE(!irqs_disabled());
|
||||
mp_ops->smp_finish();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
static void stop_this_cpu(void *dummy)
|
||||
|
@ -675,7 +675,7 @@ int __init start_secondary(void *unused)
|
||||
#ifdef CONFIG_GENERIC_CLOCKEVENTS
|
||||
init_clockevents();
|
||||
#endif
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -305,7 +305,7 @@ void __init smp_callin(void)
|
||||
|
||||
local_irq_enable(); /* Interrupts have been off until now */
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
|
||||
/* NOTREACHED */
|
||||
panic("smp_callin() AAAAaaaaahhhh....\n");
|
||||
|
@ -727,7 +727,7 @@ void start_secondary(void *unused)
|
||||
|
||||
local_irq_enable();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
|
||||
BUG();
|
||||
}
|
||||
|
@ -798,7 +798,7 @@ static void smp_start_secondary(void *cpuvoid)
|
||||
set_cpu_online(smp_processor_id(), true);
|
||||
inc_irq_stat(CPU_RST);
|
||||
local_irq_enable();
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
/* Upping and downing of CPUs */
|
||||
|
@ -203,7 +203,7 @@ asmlinkage void start_secondary(void)
|
||||
set_cpu_online(cpu, true);
|
||||
per_cpu(cpu_state, cpu) = CPU_ONLINE;
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
extern struct {
|
||||
|
@ -364,7 +364,7 @@ static void sparc_start_secondary(void *arg)
|
||||
local_irq_enable();
|
||||
|
||||
wmb();
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
|
||||
/* We should never reach here! */
|
||||
BUG();
|
||||
|
@ -134,7 +134,7 @@ void smp_callin(void)
|
||||
|
||||
local_irq_enable();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
void cpu_panic(void)
|
||||
|
@ -208,7 +208,7 @@ void online_secondary(void)
|
||||
/* Set up tile-timer clock-event device on this cpu */
|
||||
setup_tile_timer();
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
int __cpu_up(unsigned int cpu, struct task_struct *tidle)
|
||||
|
@ -256,7 +256,7 @@ static void notrace start_secondary(void *unused)
|
||||
x86_cpuinit.setup_percpu_clockev();
|
||||
|
||||
wmb();
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
int topology_update_package_map(unsigned int apicid, unsigned int cpu)
|
||||
|
@ -112,7 +112,7 @@ asmlinkage __visible void cpu_bringup_and_idle(int cpu)
|
||||
xen_pvh_secondary_vcpu_init(cpu);
|
||||
#endif
|
||||
cpu_bringup();
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
static void xen_smp_intr_free(unsigned int cpu)
|
||||
|
@ -157,7 +157,7 @@ void secondary_start_kernel(void)
|
||||
|
||||
complete(&cpu_running);
|
||||
|
||||
cpu_startup_entry(CPUHP_ONLINE);
|
||||
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
||||
}
|
||||
|
||||
static void mx_cpu_start(void *p)
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <linux/node.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/cpumask.h>
|
||||
#include <linux/cpuhotplug.h>
|
||||
|
||||
struct device;
|
||||
struct device_node;
|
||||
@ -27,6 +28,9 @@ struct cpu {
|
||||
struct device dev;
|
||||
};
|
||||
|
||||
extern void boot_cpu_init(void);
|
||||
extern void boot_cpu_state_init(void);
|
||||
|
||||
extern int register_cpu(struct cpu *cpu, int num);
|
||||
extern struct device *get_cpu_device(unsigned cpu);
|
||||
extern bool cpu_is_hotpluggable(unsigned cpu);
|
||||
@ -74,7 +78,7 @@ enum {
|
||||
/* migration should happen before other stuff but after perf */
|
||||
CPU_PRI_PERF = 20,
|
||||
CPU_PRI_MIGRATION = 10,
|
||||
CPU_PRI_SMPBOOT = 9,
|
||||
|
||||
/* bring up workqueues before normal notifiers and down after */
|
||||
CPU_PRI_WORKQUEUE_UP = 5,
|
||||
CPU_PRI_WORKQUEUE_DOWN = -5,
|
||||
@ -97,9 +101,7 @@ enum {
|
||||
* Called on the new cpu, just before
|
||||
* enabling interrupts. Must not sleep,
|
||||
* must not fail */
|
||||
#define CPU_DYING_IDLE 0x000B /* CPU (unsigned)v dying, reached
|
||||
* idle loop. */
|
||||
#define CPU_BROKEN 0x000C /* CPU (unsigned)v did not die properly,
|
||||
#define CPU_BROKEN 0x000B /* CPU (unsigned)v did not die properly,
|
||||
* perhaps due to preemption. */
|
||||
|
||||
/* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
|
||||
@ -118,6 +120,7 @@ enum {
|
||||
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
extern bool cpuhp_tasks_frozen;
|
||||
/* Need to know about CPUs going up/down? */
|
||||
#if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
|
||||
#define cpu_notifier(fn, pri) { \
|
||||
@ -167,7 +170,6 @@ static inline void __unregister_cpu_notifier(struct notifier_block *nb)
|
||||
}
|
||||
#endif
|
||||
|
||||
void smpboot_thread_init(void);
|
||||
int cpu_up(unsigned int cpu);
|
||||
void notify_cpu_starting(unsigned int cpu);
|
||||
extern void cpu_maps_update_begin(void);
|
||||
@ -177,6 +179,7 @@ extern void cpu_maps_update_done(void);
|
||||
#define cpu_notifier_register_done cpu_maps_update_done
|
||||
|
||||
#else /* CONFIG_SMP */
|
||||
#define cpuhp_tasks_frozen 0
|
||||
|
||||
#define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
|
||||
#define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
|
||||
@ -215,10 +218,6 @@ static inline void cpu_notifier_register_done(void)
|
||||
{
|
||||
}
|
||||
|
||||
static inline void smpboot_thread_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SMP */
|
||||
extern struct bus_type cpu_subsys;
|
||||
|
||||
@ -265,11 +264,6 @@ static inline int disable_nonboot_cpus(void) { return 0; }
|
||||
static inline void enable_nonboot_cpus(void) {}
|
||||
#endif /* !CONFIG_PM_SLEEP_SMP */
|
||||
|
||||
enum cpuhp_state {
|
||||
CPUHP_OFFLINE,
|
||||
CPUHP_ONLINE,
|
||||
};
|
||||
|
||||
void cpu_startup_entry(enum cpuhp_state state);
|
||||
|
||||
void cpu_idle_poll_ctrl(bool enable);
|
||||
@ -280,14 +274,15 @@ void arch_cpu_idle_enter(void);
|
||||
void arch_cpu_idle_exit(void);
|
||||
void arch_cpu_idle_dead(void);
|
||||
|
||||
DECLARE_PER_CPU(bool, cpu_dead_idle);
|
||||
|
||||
int cpu_report_state(int cpu);
|
||||
int cpu_check_up_prepare(int cpu);
|
||||
void cpu_set_state_online(int cpu);
|
||||
#ifdef CONFIG_HOTPLUG_CPU
|
||||
bool cpu_wait_death(unsigned int cpu, int seconds);
|
||||
bool cpu_report_death(void);
|
||||
void cpuhp_report_idle_dead(void);
|
||||
#else
|
||||
static inline void cpuhp_report_idle_dead(void) { }
|
||||
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
|
||||
|
||||
#endif /* _LINUX_CPU_H_ */
|
||||
|
93
include/linux/cpuhotplug.h
Normal file
93
include/linux/cpuhotplug.h
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef __CPUHOTPLUG_H
|
||||
#define __CPUHOTPLUG_H
|
||||
|
||||
enum cpuhp_state {
|
||||
CPUHP_OFFLINE,
|
||||
CPUHP_CREATE_THREADS,
|
||||
CPUHP_NOTIFY_PREPARE,
|
||||
CPUHP_BRINGUP_CPU,
|
||||
CPUHP_AP_IDLE_DEAD,
|
||||
CPUHP_AP_OFFLINE,
|
||||
CPUHP_AP_NOTIFY_STARTING,
|
||||
CPUHP_AP_ONLINE,
|
||||
CPUHP_TEARDOWN_CPU,
|
||||
CPUHP_AP_ONLINE_IDLE,
|
||||
CPUHP_AP_SMPBOOT_THREADS,
|
||||
CPUHP_AP_NOTIFY_ONLINE,
|
||||
CPUHP_AP_ONLINE_DYN,
|
||||
CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 30,
|
||||
CPUHP_ONLINE,
|
||||
};
|
||||
|
||||
int __cpuhp_setup_state(enum cpuhp_state state, const char *name, bool invoke,
|
||||
int (*startup)(unsigned int cpu),
|
||||
int (*teardown)(unsigned int cpu));
|
||||
|
||||
/**
|
||||
* cpuhp_setup_state - Setup hotplug state callbacks with calling the callbacks
|
||||
* @state: The state for which the calls are installed
|
||||
* @name: Name of the callback (will be used in debug output)
|
||||
* @startup: startup callback function
|
||||
* @teardown: teardown callback function
|
||||
*
|
||||
* Installs the callback functions and invokes the startup callback on
|
||||
* the present cpus which have already reached the @state.
|
||||
*/
|
||||
static inline int cpuhp_setup_state(enum cpuhp_state state,
|
||||
const char *name,
|
||||
int (*startup)(unsigned int cpu),
|
||||
int (*teardown)(unsigned int cpu))
|
||||
{
|
||||
return __cpuhp_setup_state(state, name, true, startup, teardown);
|
||||
}
|
||||
|
||||
/**
|
||||
* cpuhp_setup_state_nocalls - Setup hotplug state callbacks without calling the
|
||||
* callbacks
|
||||
* @state: The state for which the calls are installed
|
||||
* @name: Name of the callback.
|
||||
* @startup: startup callback function
|
||||
* @teardown: teardown callback function
|
||||
*
|
||||
* Same as @cpuhp_setup_state except that no calls are executed are invoked
|
||||
* during installation of this callback. NOP if SMP=n or HOTPLUG_CPU=n.
|
||||
*/
|
||||
static inline int cpuhp_setup_state_nocalls(enum cpuhp_state state,
|
||||
const char *name,
|
||||
int (*startup)(unsigned int cpu),
|
||||
int (*teardown)(unsigned int cpu))
|
||||
{
|
||||
return __cpuhp_setup_state(state, name, false, startup, teardown);
|
||||
}
|
||||
|
||||
void __cpuhp_remove_state(enum cpuhp_state state, bool invoke);
|
||||
|
||||
/**
|
||||
* cpuhp_remove_state - Remove hotplug state callbacks and invoke the teardown
|
||||
* @state: The state for which the calls are removed
|
||||
*
|
||||
* Removes the callback functions and invokes the teardown callback on
|
||||
* the present cpus which have already reached the @state.
|
||||
*/
|
||||
static inline void cpuhp_remove_state(enum cpuhp_state state)
|
||||
{
|
||||
__cpuhp_remove_state(state, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* cpuhp_remove_state_nocalls - Remove hotplug state callbacks without invoking
|
||||
* teardown
|
||||
* @state: The state for which the calls are removed
|
||||
*/
|
||||
static inline void cpuhp_remove_state_nocalls(enum cpuhp_state state)
|
||||
{
|
||||
__cpuhp_remove_state(state, false);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
void cpuhp_online_idle(enum cpuhp_state state);
|
||||
#else
|
||||
static inline void cpuhp_online_idle(enum cpuhp_state state) { }
|
||||
#endif
|
||||
|
||||
#endif
|
@ -47,6 +47,8 @@
|
||||
* runtime initialization.
|
||||
*/
|
||||
|
||||
struct notifier_block;
|
||||
|
||||
typedef int (*notifier_fn_t)(struct notifier_block *nb,
|
||||
unsigned long action, void *data);
|
||||
|
||||
|
@ -332,9 +332,7 @@ void rcu_init(void);
|
||||
void rcu_sched_qs(void);
|
||||
void rcu_bh_qs(void);
|
||||
void rcu_check_callbacks(int user);
|
||||
struct notifier_block;
|
||||
int rcu_cpu_notify(struct notifier_block *self,
|
||||
unsigned long action, void *hcpu);
|
||||
void rcu_report_dead(unsigned int cpu);
|
||||
|
||||
#ifndef CONFIG_TINY_RCU
|
||||
void rcu_end_inkernel_boot(void);
|
||||
|
66
include/trace/events/cpuhp.h
Normal file
66
include/trace/events/cpuhp.h
Normal file
@ -0,0 +1,66 @@
|
||||
#undef TRACE_SYSTEM
|
||||
#define TRACE_SYSTEM cpuhp
|
||||
|
||||
#if !defined(_TRACE_CPUHP_H) || defined(TRACE_HEADER_MULTI_READ)
|
||||
#define _TRACE_CPUHP_H
|
||||
|
||||
#include <linux/tracepoint.h>
|
||||
|
||||
TRACE_EVENT(cpuhp_enter,
|
||||
|
||||
TP_PROTO(unsigned int cpu,
|
||||
int target,
|
||||
int idx,
|
||||
int (*fun)(unsigned int)),
|
||||
|
||||
TP_ARGS(cpu, target, idx, fun),
|
||||
|
||||
TP_STRUCT__entry(
|
||||
__field( unsigned int, cpu )
|
||||
__field( int, target )
|
||||
__field( int, idx )
|
||||
__field( void *, fun )
|
||||
),
|
||||
|
||||
TP_fast_assign(
|
||||
__entry->cpu = cpu;
|
||||
__entry->target = target;
|
||||
__entry->idx = idx;
|
||||
__entry->fun = fun;
|
||||
),
|
||||
|
||||
TP_printk("cpu: %04u target: %3d step: %3d (%pf)",
|
||||
__entry->cpu, __entry->target, __entry->idx, __entry->fun)
|
||||
);
|
||||
|
||||
TRACE_EVENT(cpuhp_exit,
|
||||
|
||||
TP_PROTO(unsigned int cpu,
|
||||
int state,
|
||||
int idx,
|
||||
int ret),
|
||||
|
||||
TP_ARGS(cpu, state, idx, ret),
|
||||
|
||||
TP_STRUCT__entry(
|
||||
__field( unsigned int, cpu )
|
||||
__field( int, state )
|
||||
__field( int, idx )
|
||||
__field( int, ret )
|
||||
),
|
||||
|
||||
TP_fast_assign(
|
||||
__entry->cpu = cpu;
|
||||
__entry->state = state;
|
||||
__entry->idx = idx;
|
||||
__entry->ret = ret;
|
||||
),
|
||||
|
||||
TP_printk(" cpu: %04u state: %3d step: %3d ret: %d",
|
||||
__entry->cpu, __entry->state, __entry->idx, __entry->ret)
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
/* This part must be outside protection */
|
||||
#include <trace/define_trace.h>
|
16
init/main.c
16
init/main.c
@ -385,7 +385,6 @@ static noinline void __init_refok rest_init(void)
|
||||
int pid;
|
||||
|
||||
rcu_scheduler_starting();
|
||||
smpboot_thread_init();
|
||||
/*
|
||||
* We need to spawn init first so that it obtains pid 1, however
|
||||
* the init task will end up wanting to create kthreads, which, if
|
||||
@ -449,20 +448,6 @@ void __init parse_early_param(void)
|
||||
done = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Activate the first processor.
|
||||
*/
|
||||
|
||||
static void __init boot_cpu_init(void)
|
||||
{
|
||||
int cpu = smp_processor_id();
|
||||
/* Mark the boot cpu "present", "online" etc for SMP and UP case */
|
||||
set_cpu_online(cpu, true);
|
||||
set_cpu_active(cpu, true);
|
||||
set_cpu_present(cpu, true);
|
||||
set_cpu_possible(cpu, true);
|
||||
}
|
||||
|
||||
void __init __weak smp_setup_processor_id(void)
|
||||
{
|
||||
}
|
||||
@ -522,6 +507,7 @@ asmlinkage __visible void __init start_kernel(void)
|
||||
setup_command_line(command_line);
|
||||
setup_nr_cpu_ids();
|
||||
setup_per_cpu_areas();
|
||||
boot_cpu_state_init();
|
||||
smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
|
||||
|
||||
build_all_zonelists(NULL, NULL);
|
||||
|
1182
kernel/cpu.c
1182
kernel/cpu.c
File diff suppressed because it is too large
Load Diff
@ -2605,28 +2605,6 @@ static void rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The CPU is exiting the idle loop into the arch_cpu_idle_dead()
|
||||
* function. We now remove it from the rcu_node tree's ->qsmaskinit
|
||||
* bit masks.
|
||||
*/
|
||||
static void rcu_cleanup_dying_idle_cpu(int cpu, struct rcu_state *rsp)
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned long mask;
|
||||
struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
|
||||
struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
|
||||
|
||||
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
|
||||
return;
|
||||
|
||||
/* Remove outgoing CPU from mask in the leaf rcu_node structure. */
|
||||
mask = rdp->grpmask;
|
||||
raw_spin_lock_irqsave_rcu_node(rnp, flags); /* Enforce GP memory-order guarantee. */
|
||||
rnp->qsmaskinitnext &= ~mask;
|
||||
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* The CPU has been completely removed, and some other CPU is reporting
|
||||
* this fact from process context. Do the remainder of the cleanup,
|
||||
@ -4246,6 +4224,46 @@ static void rcu_prepare_cpu(int cpu)
|
||||
rcu_init_percpu_data(cpu, rsp);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HOTPLUG_CPU
|
||||
/*
|
||||
* The CPU is exiting the idle loop into the arch_cpu_idle_dead()
|
||||
* function. We now remove it from the rcu_node tree's ->qsmaskinit
|
||||
* bit masks.
|
||||
* The CPU is exiting the idle loop into the arch_cpu_idle_dead()
|
||||
* function. We now remove it from the rcu_node tree's ->qsmaskinit
|
||||
* bit masks.
|
||||
*/
|
||||
static void rcu_cleanup_dying_idle_cpu(int cpu, struct rcu_state *rsp)
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned long mask;
|
||||
struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
|
||||
struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
|
||||
|
||||
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
|
||||
return;
|
||||
|
||||
/* Remove outgoing CPU from mask in the leaf rcu_node structure. */
|
||||
mask = rdp->grpmask;
|
||||
raw_spin_lock_irqsave_rcu_node(rnp, flags); /* Enforce GP memory-order guarantee. */
|
||||
rnp->qsmaskinitnext &= ~mask;
|
||||
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
||||
}
|
||||
|
||||
void rcu_report_dead(unsigned int cpu)
|
||||
{
|
||||
struct rcu_state *rsp;
|
||||
|
||||
/* QS for any half-done expedited RCU-sched GP. */
|
||||
preempt_disable();
|
||||
rcu_report_exp_rdp(&rcu_sched_state,
|
||||
this_cpu_ptr(rcu_sched_state.rda), true);
|
||||
preempt_enable();
|
||||
for_each_rcu_flavor(rsp)
|
||||
rcu_cleanup_dying_idle_cpu(cpu, rsp);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Handle CPU online/offline notification events.
|
||||
*/
|
||||
@ -4277,17 +4295,6 @@ int rcu_cpu_notify(struct notifier_block *self,
|
||||
for_each_rcu_flavor(rsp)
|
||||
rcu_cleanup_dying_cpu(rsp);
|
||||
break;
|
||||
case CPU_DYING_IDLE:
|
||||
/* QS for any half-done expedited RCU-sched GP. */
|
||||
preempt_disable();
|
||||
rcu_report_exp_rdp(&rcu_sched_state,
|
||||
this_cpu_ptr(rcu_sched_state.rda), true);
|
||||
preempt_enable();
|
||||
|
||||
for_each_rcu_flavor(rsp) {
|
||||
rcu_cleanup_dying_idle_cpu(cpu, rsp);
|
||||
}
|
||||
break;
|
||||
case CPU_DEAD:
|
||||
case CPU_DEAD_FROZEN:
|
||||
case CPU_UP_CANCELED:
|
||||
|
@ -5434,16 +5434,6 @@ static int sched_cpu_active(struct notifier_block *nfb,
|
||||
set_cpu_rq_start_time();
|
||||
return NOTIFY_OK;
|
||||
|
||||
case CPU_ONLINE:
|
||||
/*
|
||||
* At this point a starting CPU has marked itself as online via
|
||||
* set_cpu_online(). But it might not yet have marked itself
|
||||
* as active, which is essential from here on.
|
||||
*/
|
||||
set_cpu_active(cpu, true);
|
||||
stop_machine_unpark(cpu);
|
||||
return NOTIFY_OK;
|
||||
|
||||
case CPU_DOWN_FAILED:
|
||||
set_cpu_active(cpu, true);
|
||||
return NOTIFY_OK;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <linux/sched.h>
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/cpuidle.h>
|
||||
#include <linux/cpuhotplug.h>
|
||||
#include <linux/tick.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/stackprotector.h>
|
||||
@ -193,8 +194,6 @@ exit_idle:
|
||||
rcu_idle_exit();
|
||||
}
|
||||
|
||||
DEFINE_PER_CPU(bool, cpu_dead_idle);
|
||||
|
||||
/*
|
||||
* Generic idle loop implementation
|
||||
*
|
||||
@ -221,10 +220,7 @@ static void cpu_idle_loop(void)
|
||||
rmb();
|
||||
|
||||
if (cpu_is_offline(smp_processor_id())) {
|
||||
rcu_cpu_notify(NULL, CPU_DYING_IDLE,
|
||||
(void *)(long)smp_processor_id());
|
||||
smp_mb(); /* all activity before dead. */
|
||||
this_cpu_write(cpu_dead_idle, true);
|
||||
cpuhp_report_idle_dead();
|
||||
arch_cpu_idle_dead();
|
||||
}
|
||||
|
||||
@ -291,5 +287,6 @@ void cpu_startup_entry(enum cpuhp_state state)
|
||||
boot_init_stack_canary();
|
||||
#endif
|
||||
arch_cpu_idle_prepare();
|
||||
cpuhp_online_idle(state);
|
||||
cpu_idle_loop();
|
||||
}
|
||||
|
@ -568,6 +568,7 @@ void __init smp_init(void)
|
||||
unsigned int cpu;
|
||||
|
||||
idle_threads_init();
|
||||
cpuhp_threads_init();
|
||||
|
||||
/* FIXME: This should be done in userspace --RR */
|
||||
for_each_present_cpu(cpu) {
|
||||
|
@ -226,7 +226,7 @@ static void smpboot_unpark_thread(struct smp_hotplug_thread *ht, unsigned int cp
|
||||
kthread_unpark(tsk);
|
||||
}
|
||||
|
||||
void smpboot_unpark_threads(unsigned int cpu)
|
||||
int smpboot_unpark_threads(unsigned int cpu)
|
||||
{
|
||||
struct smp_hotplug_thread *cur;
|
||||
|
||||
@ -235,6 +235,7 @@ void smpboot_unpark_threads(unsigned int cpu)
|
||||
if (cpumask_test_cpu(cpu, cur->cpumask))
|
||||
smpboot_unpark_thread(cur, cpu);
|
||||
mutex_unlock(&smpboot_threads_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void smpboot_park_thread(struct smp_hotplug_thread *ht, unsigned int cpu)
|
||||
@ -245,7 +246,7 @@ static void smpboot_park_thread(struct smp_hotplug_thread *ht, unsigned int cpu)
|
||||
kthread_park(tsk);
|
||||
}
|
||||
|
||||
void smpboot_park_threads(unsigned int cpu)
|
||||
int smpboot_park_threads(unsigned int cpu)
|
||||
{
|
||||
struct smp_hotplug_thread *cur;
|
||||
|
||||
@ -253,6 +254,7 @@ void smpboot_park_threads(unsigned int cpu)
|
||||
list_for_each_entry_reverse(cur, &hotplug_threads, list)
|
||||
smpboot_park_thread(cur, cpu);
|
||||
mutex_unlock(&smpboot_threads_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void smpboot_destroy_threads(struct smp_hotplug_thread *ht)
|
||||
|
@ -14,7 +14,9 @@ static inline void idle_threads_init(void) { }
|
||||
#endif
|
||||
|
||||
int smpboot_create_threads(unsigned int cpu);
|
||||
void smpboot_park_threads(unsigned int cpu);
|
||||
void smpboot_unpark_threads(unsigned int cpu);
|
||||
int smpboot_park_threads(unsigned int cpu);
|
||||
int smpboot_unpark_threads(unsigned int cpu);
|
||||
|
||||
void __init cpuhp_threads_init(void);
|
||||
|
||||
#endif
|
||||
|
@ -1442,6 +1442,19 @@ config DEBUG_BLOCK_EXT_DEVT
|
||||
|
||||
Say N if you are unsure.
|
||||
|
||||
config CPU_HOTPLUG_STATE_CONTROL
|
||||
bool "Enable CPU hotplug state control"
|
||||
depends on DEBUG_KERNEL
|
||||
depends on HOTPLUG_CPU
|
||||
default n
|
||||
help
|
||||
Allows to write steps between "offline" and "online" to the CPUs
|
||||
sysfs target file so states can be stepped granular. This is a debug
|
||||
option for now as the hotplug machinery cannot be stopped and
|
||||
restarted at arbitrary points yet.
|
||||
|
||||
Say N if your are unsure.
|
||||
|
||||
config NOTIFIER_ERROR_INJECTION
|
||||
tristate "Notifier error injection"
|
||||
depends on DEBUG_KERNEL
|
||||
|
Loading…
Reference in New Issue
Block a user