Per cpu thread hotplug infrastructure
Subsystems (2)
v2 cover Per cpu thread hotplug infrastructure
The following series implements the infrastructure for parking and unparking kernel threads to avoid the full teardown and fork on cpu hotplug operations along with management infrastructure for hotplug and users.
Changes since V1:
- Addressed the review comments
- Fixed a missing state update in parkme (reported by Paul)
- Simplified rcu_yield()
- Added Pauls RCU conversion
Full diffstat below. Due to the RCU cleanup we now remove more code than we add. :)
Thanks,
tglx
--- drivers/infiniband/hw/ehca/ehca_irq.c | 240 ++++++++------------- drivers/infiniband/hw/ehca/ehca_irq.h | 5 include/linux/kthread.h | 11 include/linux/smpboot.h | 40 +++ kernel/cpu.c | 10 kernel/kthread.c | 184 ++++++++++++++-- kernel/rcutree.c | 12 - kernel/rcutree.h | 15 - kernel/rcutree_plugin.h | 375 +++++----------------------------- kernel/rcutree_trace.c | 3 kernel/smpboot.c | 206 ++++++++++++++++++ kernel/smpboot.h | 4 kernel/softirq.c | 84 +------ kernel/watchdog.c | 232 ++++++--------------- 14 files changed, 678 insertions(+), 743 deletions(-)
RFC PATCH v2 1/7 rcu: Yield simpler
The rcu_yield() code is amazing. It's there to avoid starvation of the system when lots of (boosting) work is to be done.
Now looking at the code it's functionality is:
Make the thread SCHED_OTHER and very nice, i.e. get it out of the way Arm a timer with 2 ticks
schedule()
Now if the system goes idle the rcu task returns, regains SCHED_FIFO and plugs on. If the systems stays busy the timer fires and wakes a per node kthread which in turn makes the per cpu thread SCHED_FIFO and brings it back on the cpu. For the boosting thread the "make it FIFO" bit is missing and it just runs some magic boost checks. Now this is a lot of code with extra threads and complexity.
It's way simpler to let the tasks when they detect overload schedule away for 2 ticks and defer the normal wakeup as long as they are in yielded state and the cpu is not idle.
That solves the same problem and the only difference is that when the cpu goes idle it's not guaranteed that the thread returns right away, but it won't be longer out than two ticks, so no harm is done. If that's an issue than it is way simpler just to wake the task from idle as RCU has callbacks there anyway.
--- kernel/rcutree.c | 8 - kernel/rcutree.h | 7 - kernel/rcutree_plugin.h | 210 ++++++++---------------------------------------- 3 files changed, 41 insertions(+), 184 deletions(-)
kernel/rcutree.c +4 -4
@@ -131,7 +131,7 @@ DEFINE_PER_CPU(char, rcu_cpu_has_work);#endif /* #ifdef CONFIG_RCU_BOOST */ -static void rcu_node_kthread_setaffinity (struct rcu_node *rnp,int outgoingcpu); +static void rcu_boost_kthread_setaffinity (struct rcu_node *rnp,int outgoingcpu);static void invoke_rcu_core (void );static void invoke_rcu_callbacks (struct rcu_state *rsp,struct rcu_data *rdp);
@@ -1459,7 +1459,7 @@ static void rcu_cleanup_dead_cpu(int cpu/* Adjust any no-longer-needed kthreads. */ rcu_stop_cpu_kthread (cpu); -rcu_node_kthread_setaffinity (rnp,-1 ); +rcu_boost_kthread_setaffinity (rnp,-1 );/* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
@@ -2513,11 +2513,11 @@ static int __cpuinit rcu_cpu_notify(strubreak ;case CPU_ONLINE :case CPU_DOWN_FAILED : -rcu_node_kthread_setaffinity (rnp,-1 ); +rcu_boost_kthread_setaffinity (rnp,-1 );rcu_cpu_kthread_setrt (cpu,1 );break ;case CPU_DOWN_PREPARE : -rcu_node_kthread_setaffinity (rnp, cpu); +rcu_boost_kthread_setaffinity (rnp, cpu);rcu_cpu_kthread_setrt (cpu,0 );break ;case CPU_DYING :
kernel/rcutree.h +1 -6
@@ -464,13 +464,8 @@ static void invoke_rcu_callbacks_kthreadstatic bool rcu_is_callbacks_kthread (void );#ifdef CONFIG_RCU_BOOST static void rcu_preempt_do_callbacks (void ); -static void rcu_boost_kthread_setaffinity (struct rcu_node *rnp, -cpumask_var_t cm);static int __cpuinit rcu_spawn_one_boost_kthread (struct rcu_state *rsp, -struct rcu_node *rnp, -int rnp_index); -static void invoke_rcu_node_kthread (struct rcu_node *rnp); -static void rcu_yield (void (*f)(unsigned long ),unsigned long arg); +struct rcu_node *rnp);#endif /* #ifdef CONFIG_RCU_BOOST */ static void rcu_cpu_kthread_setrt (int cpu,int to_rt);static void __cpuinit rcu_prepare_kthreads (int cpu);
kernel/rcutree_plugin.h +36 -174
331 lines not on this page · raw message
RFC PATCH v2 2/7 kthread: Implement park/unpark facility
In reply to Thomas GleixnerTo avoid the full teardown/setup of per cpu kthreads in the case of cpu hot(un)plug, provide a facility which allows to put the kthread into a park position and unpark it when the cpu comes online again.
--- include/linux/kthread.h | 11 ++ kernel/kthread.c | 184 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 175 insertions(+), 20 deletions(-)
include/linux/kthread.h +10 -1
@@ -14,6 +14,11 @@ struct task_struct *kthread_create_on_no kthread_create_on_node(threadfn, data, -1, namefmt, ##arg) +struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data), + void *data, + unsigned int cpu, + const char *namefmt); +/** * kthread_run - create and wake a thread. * @threadfn: the function to run until signal_pending(current).
@@ -34,9 +39,13 @@ struct task_struct *kthread_create_on_novoid kthread_bind (struct task_struct *k,unsigned int cpu);int kthread_stop (struct task_struct *k); -int kthread_should_stop (void ); +bool kthread_should_stop (void ); +bool kthread_should_park (void );bool kthread_freezable_should_stop (bool *was_frozen);void *kthread_data (struct task_struct *k); +int kthread_park (struct task_struct *k); +void kthread_unpark (struct task_struct *k); +void kthread_parkme (void );int kthreadd (void *unused);extern struct task_struct *kthreadd_task;
kernel/kthread.c +165 -19
257 lines not on this page · raw message
Re: [RFC patch V2 2/7] kthread: Implement park/unpark facility
Quoted 4 lines · Thomas Gleixner
To avoid the full teardown/setup of per cpu kthreads in the case of cpu hot(un)plug, provide a facility which allows to put the kthread into a park position and unpark it when the cpu comes online again.
Please see a comment below. Other than that, you can add my
if you want.
Quoted 5 lines
Signed-off-by Thomas Gleixner <[email protected]>--- include/linux/kthread.h | 11 ++ kernel/kthread.c | 184 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 175 insertions(+), 20 deletions(-)
[snip]
Quoted 6 lines
/**
+ *kthread_create_on_cpu- Create a cpu bound kthread
+ * @threadfn: the function to run untilsignal_pending(current).
+ * @data: data ptr for @threadfn.
+ * @cpu: The cpu on which the thread should be bound,
+ * @namefmt: printf-style name for the thread.
How about adding a comment that @namefmt can handle a single %u only for the cpu number in the current implementation?
Thanks,
Namhyung
Quoted 21 lines
+ *
+ * Description: This helper function creates and names a kernel thread
+ * The thread will be woken and put into park mode.
+ */kernel/kthread.c +17
-0+struct task_struct *kthread_create_on_cpu (int (*threadfn)(void *data), +void *data,unsigned int cpu, +const char *namefmt) +{ +struct task_struct *p; + + p =kthread_create_on_node (threadfn, data,cpu_to_node (cpu), namefmt, + cpu); +if (IS_ERR (p)) +return p; +set_bit (KTHREAD_IS_PER_CPU , &to_kthread (p)->flags); +to_kthread (p)->cpu = cpu; +/* Park the thread to get it out of TASK_UNINTERRUPTIBLE state */ +kthread_park (p); +return p; +} +
Re: [RFC patch V2 2/7] kthread: Implement park/unpark facility
Quoted 11 lines · Namhyung Kim
Quoted 4 lines · Thomas Gleixner
To avoid the full teardown/setup of per cpu kthreads in the case of cpu hot(un)plug, provide a facility which allows to put the kthread into a park position and unpark it when the cpu comes online again.
Please see a comment below. Other than that, you can add my
Reviewed-by Namhyung Kim <[email protected]>if you want.
My pleasure.
Quoted 14 lines
Quoted 6 lines
Signed-off-by Thomas Gleixner <[email protected]>--- include/linux/kthread.h | 11 ++ kernel/kthread.c | 184 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 175 insertions(+), 20 deletions(-)[snip]
Quoted 6 lines
/**
+ *kthread_create_on_cpu- Create a cpu bound kthread
+ * @threadfn: the function to run untilsignal_pending(current).
+ * @data: data ptr for @threadfn.
+ * @cpu: The cpu on which the thread should be bound,
+ * @namefmt: printf-style name for the thread.
Quoted 2 lines
How about adding a comment that @namefmt can handle a single %u only for the cpu number in the current implementation?
Good point!
Thanks for taking your time!
tglx
RFC PATCH v2 3/7 smpboot: Provide infrastructure for percpu hotplug threads
In reply to Thomas GleixnerProvide a generic interface for setting up and tearing down percpu threads.
On registration the threads for already online cpus are created and started. On deregistration (modules) the threads are stoppped.
During hotplug operations the threads are created, started, parked and unparked. The datastructure for registration provides a pointer to percpu storage space and optional setup, cleanup, park, unpark functions. These functions are called when the thread state changes.
Thread functions should look like the following:
int thread_fn(void *cookie)
{
while (!smpboot_thread_check_parking(cookie)) {
do_stuff();
}
return 0;
}--- include/linux/smpboot.h | 40 +++++++++ kernel/cpu.c | 10 ++ kernel/smpboot.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++ kernel/smpboot.h | 4 4 files changed, 259 insertions(+), 1 deletion(-)
include/linux/smpboot.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _LINUX_SMPBOOT_H +#define _LINUX_SMPBOOT_H + +#include <linux/types.h> + +struct task_struct ; +/* Cookie handed to the thread_fn*/ +struct smpboot_thread_data ; + +/** +* struct smp_hotplug_thread - CPU hotplug related thread descriptor +* @store: Pointer to per cpu storage for the task pointers +* @list: List head for core management +* @thread_fn: The associated thread function +* @setup: Optional setup function, called when the thread gets +* operational the first time +* @cleanup: Optional cleanup function, called when the thread +* should stop (module exit) +* @park: Optional park function, called when the thread is +* parked (cpu offline) +* @unpark: Optional unpark function, called when the thread is +* unparked (cpu online) +* @thread_comm: The base name of the thread +*/ +struct smp_hotplug_thread { +struct task_struct __percpu **store; +struct list_head list; +int (*thread_fn)(void *data); +void (*setup)(unsigned int cpu); +void (*cleanup)(unsigned int cpu,bool online); +void (*park)(unsigned int cpu); +void (*unpark)(unsigned int cpu); +const char *thread_comm; +}; + +int smpboot_register_percpu_thread (struct smp_hotplug_thread *plug_thread); +void smpboot_unregister_percpu_thread (struct smp_hotplug_thread *plug_thread); +int smpboot_thread_check_parking (struct smpboot_thread_data *td); + +#endif
kernel/cpu.c +9 -1
@@ -280,12 +280,13 @@ static int __ref _cpu_down(unsigned int __func__, cpu); goto out_release; } +smpboot_park_threads (cpu); err =__stop_machine (take_cpu_down, &tcd_param,cpumask_of (cpu));if (err) {/* CPU didn't die: tell everyone. Can't complain. */ +smpboot_unpark_threads (cpu);cpu_notify_nofail (CPU_DOWN_FAILED | mod, hcpu); - goto out_release; }BUG_ON (cpu_online (cpu));
@@ -354,6 +355,10 @@ static int __cpuinit _cpu_up(unsigned in goto out; } + ret =smpboot_create_threads (cpu); +if (ret) + goto out; + ret =__cpu_notify (CPU_UP_PREPARE | mod, hcpu,-1 , &nr_calls);if (ret) { nr_calls--;
@@ -368,6 +373,9 @@ static int __cpuinit _cpu_up(unsigned in goto out_notify;BUG_ON (!cpu_online (cpu)); +/* Wake the per cpu threads */ +smpboot_unpark_threads (cpu); +/* Now call notifier in preparation. */ cpu_notify (CPU_ONLINE | mod, hcpu);
kernel/smpboot.c +206 -0
220 lines not on this page · raw message
kernel/smpboot.h +4 -0
@@ -13,4 +13,8 @@ static inline void idle_thread_set_boot_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); +#endif
RFC PATCH v2 4/7 softirq: Use hotplug thread infrastructure
In reply to Thomas Gleixner--- kernel/softirq.c | 84 +++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 66 deletions(-)
kernel/softirq.c +18 -66
@@ -23,6 +23,7 @@#include <linux/rcupdate.h> #include <linux/ftrace.h> #include <linux/smp.h> +#include <linux/smpboot.h> #include <linux/tick.h> #define CREATE_TRACE_POINTS
@@ -733,24 +734,17 @@ void __init softirq_init(void)open_softirq (HI_SOFTIRQ , tasklet_hi_action); } -static int run_ksoftirqd (void * __bind_cpu) +static int run_ksoftirqd (void *td) { -set_current_state (TASK_INTERRUPTIBLE ); - -while (!kthread_should_stop ()) { +while (!smpboot_thread_check_parking (td)) { +set_current_state (TASK_INTERRUPTIBLE );preempt_disable (); -if (!local_softirq_pending ()) { +if (!local_softirq_pending ())schedule_preempt_disabled (); - }__set_current_state (TASK_RUNNING );while (local_softirq_pending ()) { -/* Preempt disable stops cpu going offline. -If already offline, we'll be on wrong CPU: -don't process */ -if (cpu_is_offline ((long )__bind_cpu)) - goto wait_to_die;local_irq_disable ();if (local_softirq_pending ())__do_softirq ();
@@ -758,23 +752,10 @@ static int run_ksoftirqd(void * __bind_csched_preempt_enable_no_resched ();cond_resched ();preempt_disable (); -rcu_note_context_switch ((long )__bind_cpu); +rcu_note_context_switch (smp_processor_id ()); }preempt_enable (); -set_current_state (TASK_INTERRUPTIBLE ); } -__set_current_state (TASK_RUNNING ); -return 0 ; - -wait_to_die: -preempt_enable (); -/* Wait for kthread_stop */ -set_current_state (TASK_INTERRUPTIBLE ); -while (!kthread_should_stop ()) { -schedule (); -set_current_state (TASK_INTERRUPTIBLE ); - } -__set_current_state (TASK_RUNNING );return 0 ; }
@@ -841,50 +822,17 @@ static int __cpuinit cpu_callback(struct unsigned long action, void *hcpu) { - int hotcpu = (unsigned long)hcpu; -struct task_struct *p; -switch (action) { -case CPU_UP_PREPARE : -case CPU_UP_PREPARE_FROZEN : - p =kthread_create_on_node (run_ksoftirqd, - hcpu, -cpu_to_node (hotcpu), -"ksoftirqd/%d" , hotcpu); -if (IS_ERR (p)) { -printk ("ksoftirqd for %i failed\n" , hotcpu); -return notifier_from_errno (PTR_ERR (p)); - } -kthread_bind (p, hotcpu); -per_cpu (ksoftirqd, hotcpu) = p; -break ; -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -wake_up_process (per_cpu (ksoftirqd, hotcpu)); -break ;#ifdef CONFIG_HOTPLUG_CPU -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -if (!per_cpu (ksoftirqd, hotcpu)) -break ; -/* Unbind so it can run. Fall thru. */ -kthread_bind (per_cpu (ksoftirqd, hotcpu), -cpumask_any (cpu_online_mask));case CPU_DEAD :case CPU_DEAD_FROZEN : { -static const struct sched_param param = { - .sched_priority =MAX_RT_PRIO -1 - }; - - p =per_cpu (ksoftirqd, hotcpu); -per_cpu (ksoftirqd, hotcpu) =NULL ; -sched_setscheduler_nocheck (p,SCHED_FIFO , ¶m); -kthread_stop (p); +int hotcpu = (unsigned long )hcpu; +takeover_tasklets (hotcpu);break ; }#endif /* CONFIG_HOTPLUG_CPU */ - } + }return NOTIFY_OK ; }
@@ -892,14 +840,18 @@ static struct notifier_block __cpuinitda .notifier_call = cpu_callback }; +static struct smp_hotplug_thread softirq_threads = { + .store = &ksoftirqd, + .thread_fn = run_ksoftirqd, + .thread_comm ="ksoftirqd/%u" , +}; +static __init int spawn_ksoftirqd (void ) { -void *cpu = (void *)(long )smp_processor_id (); -int err =cpu_callback (&cpu_nfb,CPU_UP_PREPARE , cpu); - -BUG_ON (err !=NOTIFY_OK ); -cpu_callback (&cpu_nfb,CPU_ONLINE , cpu);register_cpu_notifier (&cpu_nfb); + +BUG_ON (smpboot_register_percpu_thread (&softirq_threads)); +return 0 ; }early_initcall (spawn_ksoftirqd);
Re: [RFC patch V2 4/7] softirq: Use hotplug thread infrastructure
Quoted 1 line · Thomas Gleixner
Signed-off-by Thomas Gleixner <[email protected]>
And I got the following build errors on !SMP:
kernel/built-in.o: In function `run_ksoftirqd':/usr/local/autobench/var/tmp/build/kernel/softirq.c:739: undefined reference to .smpboot_thread_check_parking' kernel/built-in.o: In function watchdog':/usr/local/autobench/var/tmp/build/kernel/watchdog.c:383: undefined reference to .smpboot_thread_check_parking' kernel/built-in.o: In function spawn_ksoftirqd':/usr/local/autobench/var/tmp/build/kernel/softirq.c:853: undefined reference to .smpboot_register_percpu_thread' kernel/built-in.o: In function lockup_detector_init':/usr/local/autobench/var/tmp/build/kernel/watchdog.c:514: undefined reference to `.smpboot_register_percpu_thread'
My guess is that !SMP needs empty definitions of these functions.
Thanx, Paul
Quoted 150 lines
--- kernel/softirq.c | 84 +++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 66 deletions(-)Index:
tip/kernel/softirq.c
===================================================================kernel/softirq.c +18
-66@@ -23,6 +23,7 @@#include <linux/rcupdate.h> #include <linux/ftrace.h> #include <linux/smp.h> +#include <linux/smpboot.h> #include <linux/tick.h> #define CREATE_TRACE_POINTS @@ -733,24 +734,17 @@ void __init softirq_init(void)open_softirq (HI_SOFTIRQ , tasklet_hi_action); } -static int run_ksoftirqd (void * __bind_cpu) +static int run_ksoftirqd (void *td) { -set_current_state (TASK_INTERRUPTIBLE ); - -while (!kthread_should_stop ()) { +while (!smpboot_thread_check_parking (td)) { +set_current_state (TASK_INTERRUPTIBLE );preempt_disable (); -if (!local_softirq_pending ()) { +if (!local_softirq_pending ())schedule_preempt_disabled (); - }__set_current_state (TASK_RUNNING );while (local_softirq_pending ()) { -/* Preempt disable stops cpu going offline. -If already offline, we'll be on wrong CPU: -don't process */ -if (cpu_is_offline ((long )__bind_cpu)) - goto wait_to_die;local_irq_disable ();if (local_softirq_pending ())__do_softirq ();@@ -758,23 +752,10 @@ static int run_ksoftirqd(void * __bind_csched_preempt_enable_no_resched ();cond_resched ();preempt_disable (); -rcu_note_context_switch ((long )__bind_cpu); +rcu_note_context_switch (smp_processor_id ()); }preempt_enable (); -set_current_state (TASK_INTERRUPTIBLE ); } -__set_current_state (TASK_RUNNING ); -return 0 ; - -wait_to_die: -preempt_enable (); -/* Wait for kthread_stop */ -set_current_state (TASK_INTERRUPTIBLE ); -while (!kthread_should_stop ()) { -schedule (); -set_current_state (TASK_INTERRUPTIBLE ); - } -__set_current_state (TASK_RUNNING );return 0 ; }@@ -841,50 +822,17 @@ static int __cpuinit cpu_callback(struct unsigned long action, void *hcpu) { - int hotcpu = (unsigned long)hcpu; -struct task_struct *p; -switch (action) { -case CPU_UP_PREPARE : -case CPU_UP_PREPARE_FROZEN : - p =kthread_create_on_node (run_ksoftirqd, - hcpu, -cpu_to_node (hotcpu), -"ksoftirqd/%d" , hotcpu); -if (IS_ERR (p)) { -printk ("ksoftirqd for %i failed\n" , hotcpu); -return notifier_from_errno (PTR_ERR (p)); - } -kthread_bind (p, hotcpu); -per_cpu (ksoftirqd, hotcpu) = p; -break ; -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -wake_up_process (per_cpu (ksoftirqd, hotcpu)); -break ;#ifdef CONFIG_HOTPLUG_CPU -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -if (!per_cpu (ksoftirqd, hotcpu)) -break ; -/* Unbind so it can run. Fall thru. */ -kthread_bind (per_cpu (ksoftirqd, hotcpu), -cpumask_any (cpu_online_mask));case CPU_DEAD :case CPU_DEAD_FROZEN : { -static const struct sched_param param = { - .sched_priority =MAX_RT_PRIO -1 - }; - - p =per_cpu (ksoftirqd, hotcpu); -per_cpu (ksoftirqd, hotcpu) =NULL ; -sched_setscheduler_nocheck (p,SCHED_FIFO , ¶m); -kthread_stop (p); +int hotcpu = (unsigned long )hcpu; +takeover_tasklets (hotcpu);break ; }#endif /* CONFIG_HOTPLUG_CPU */ - } + }return NOTIFY_OK ; }@@ -892,14 +840,18 @@ static struct notifier_block __cpuinitda .notifier_call = cpu_callback }; +static struct smp_hotplug_thread softirq_threads = { + .store = &ksoftirqd, + .thread_fn = run_ksoftirqd, + .thread_comm ="ksoftirqd/%u" , +}; +static __init int spawn_ksoftirqd (void ) { -void *cpu = (void *)(long )smp_processor_id (); -int err =cpu_callback (&cpu_nfb,CPU_UP_PREPARE , cpu); - -BUG_ON (err !=NOTIFY_OK ); -cpu_callback (&cpu_nfb,CPU_ONLINE , cpu);register_cpu_notifier (&cpu_nfb); + +BUG_ON (smpboot_register_percpu_thread (&softirq_threads)); +return 0 ; }early_initcall (spawn_ksoftirqd);
RFC PATCH v2 5/7 watchdog: Use hotplug thread infrastructure
In reply to Thomas Gleixner--- kernel/watchdog.c | 232 ++++++++++++++++-------------------------------------- 1 file changed, 69 insertions(+), 163 deletions(-)
kernel/watchdog.c +69 -163
@@ -22,6 +22,7 @@#include <linux/notifier.h> #include <linux/module.h> #include <linux/sysctl.h> +#include <linux/smpboot.h> #include <asm/irq_regs.h> #include <linux/kvm_para.h>
@@ -29,6 +30,7 @@int watchdog_enabled =1 ;int __read_mostly watchdog_thresh =10 ; +static int __read_mostly watchdog_disabled; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts); static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog);
@@ -256,6 +258,9 @@ static void watchdog_interrupt_count(voistatic inline void watchdog_interrupt_count (void ) {return ; }#endif /* CONFIG_HARDLOCKUP_DETECTOR */ +static int watchdog_nmi_enable (unsigned int cpu); +static void watchdog_nmi_disable (unsigned int cpu); +/* watchdog kicker functions */ static enum hrtimer_restart watchdog_timer_fn (struct hrtimer *hrtimer) {
@@ -327,23 +332,46 @@ static enum hrtimer_restart watchdog_timreturn HRTIMER_RESTART ; } - -/* -* The watchdog thread - touches the timestamp. -*/ -static int watchdog (void *unused) +static void watchdog_enable (unsigned int cpu) { -struct sched_param param = { .sched_priority =0 };struct hrtimer *hrtimer = &__raw_get_cpu_var (watchdog_hrtimer); -/* initialize timestamp */ -__touch_watchdog (); +/* Enable the perf event */ +watchdog_nmi_enable (cpu);/* kick off the timer for the hardlockup detector */ +hrtimer_init (hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + hrtimer->function = watchdog_timer_fn; +/* done here because hrtimer_start can only pin to smp_processor_id() */ hrtimer_start (hrtimer,ns_to_ktime (get_sample_period ()),HRTIMER_MODE_REL_PINNED ); +/* initialize timestamp */ +__touch_watchdog (); +} + +static void watchdog_disable (unsigned int cpu) +{ +struct hrtimer *hrtimer = &__raw_get_cpu_var (watchdog_hrtimer); + +hrtimer_cancel (hrtimer); +/* disable the perf event */ +watchdog_nmi_disable (cpu); +} + +/* +* The watchdog thread - touches the timestamp. +*/ +static int watchdog (void *td) +{ +struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; + +if (!watchdog_enabled) +kthread_park (current); + +sched_setscheduler (current,SCHED_FIFO , ¶m); +set_current_state (TASK_INTERRUPTIBLE );/* * Run briefly (kicked by the hrtimer callback function) once every
@@ -352,27 +380,16 @@ static int watchdog(void *unused)* 2*watchdog_thresh seconds then the debug-printout triggers in * watchdog_timer_fn(). */ -while (!kthread_should_stop ()) { +while (!smpboot_thread_check_parking (td)) { +set_current_state (TASK_INTERRUPTIBLE );__touch_watchdog ();schedule (); - -if (kthread_should_stop ()) -break ; - -set_current_state (TASK_INTERRUPTIBLE ); } -/* -* Drop the policy/priority elevation during thread exit to avoid a -* scheduling latency spike. -*/ -__set_current_state (TASK_RUNNING ); -sched_setscheduler (current,SCHED_NORMAL , ¶m);return 0 ; } -#ifdef CONFIG_HARDLOCKUP_DETECTOR -static int watchdog_nmi_enable (int cpu) +static int watchdog_nmi_enable (unsigned int cpu) {struct perf_event_attr *wd_attr;struct perf_event *event =per_cpu (watchdog_ev, cpu);
@@ -395,7 +412,6 @@ static int watchdog_nmi_enable(int cpu) goto out_save; } -/* vary the KERN level based on the returned errno */ if (PTR_ERR (event) == -EOPNOTSUPP )pr_info ("disabled (cpu%i): not supported (no LAPIC?)\n" , cpu);
@@ -416,7 +432,7 @@ out:return 0 ; } -static void watchdog_nmi_disable (int cpu) +static void watchdog_nmi_disable (unsigned int cpu) {struct perf_event *event =per_cpu (watchdog_ev, cpu);
@@ -430,107 +446,35 @@ static void watchdog_nmi_disable(int cpu return; }#else -static int watchdog_nmi_enable (int cpu) {return 0 ; } -static void watchdog_nmi_disable (int cpu) {return ; } +static int watchdog_nmi_enable (unsigned int cpu) {return 0 ; } +static void watchdog_nmi_disable (unsigned int cpu) {return ; }#endif /* CONFIG_HARDLOCKUP_DETECTOR */ /* prepare/enable/disable routines */ -static void watchdog_prepare_cpu (int cpu) -{ -struct hrtimer *hrtimer = &per_cpu (watchdog_hrtimer, cpu); - -WARN_ON (per_cpu (softlockup_watchdog, cpu)); -hrtimer_init (hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); - hrtimer->function = watchdog_timer_fn; -} - -static int watchdog_enable (int cpu) -{ -struct task_struct *p =per_cpu (softlockup_watchdog, cpu); -int err =0 ; - -/* enable the perf event */ - err =watchdog_nmi_enable (cpu); - -/* Regardless of err above, fall through and start softlockup */ - -/* create the watchdog thread */ -if (!p) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; - p =kthread_create_on_node (watchdog,NULL ,cpu_to_node (cpu),"watchdog/%d" , cpu); -if (IS_ERR (p)) { -pr_err ("softlockup watchdog for %i failed\n" , cpu); -if (!err) { -/* if hardlockup hasn't already set this */ - err =PTR_ERR (p); -/* and disable the perf event */ -watchdog_nmi_disable (cpu); - } - goto out; - } -sched_setscheduler (p,SCHED_FIFO , ¶m); -kthread_bind (p, cpu); -per_cpu (watchdog_touch_ts, cpu) =0 ; -per_cpu (softlockup_watchdog, cpu) = p; -wake_up_process (p); - } - -out: -return err; -} - -static void watchdog_disable (int cpu) -{ -struct task_struct *p =per_cpu (softlockup_watchdog, cpu); -struct hrtimer *hrtimer = &per_cpu (watchdog_hrtimer, cpu); - -/* -* cancel the timer first to stop incrementing the stats -* and waking up the kthread -*/ -hrtimer_cancel (hrtimer); - -/* disable the perf event */ -watchdog_nmi_disable (cpu); - -/* stop the watchdog thread */ -if (p) { -per_cpu (softlockup_watchdog, cpu) =NULL ; -kthread_stop (p); - } -} -/* sysctl functions */ #ifdef CONFIG_SYSCTL static void watchdog_enable_all_cpus (void ) { -int cpu; - - watchdog_enabled =0 ; - -for_each_online_cpu (cpu) -if (!watchdog_enable (cpu)) -/* if any cpu succeeds, watchdog is considered -enabled for the system */ - watchdog_enabled =1 ; - -if (!watchdog_enabled) -pr_err ("failed to be enabled on some cpus\n" ); +unsigned int cpu; +if (watchdog_disabled) { + watchdog_disabled =0 ; +for_each_online_cpu (cpu) +kthread_unpark (per_cpu (softlockup_watchdog, cpu)); + } }static void watchdog_disable_all_cpus (void ) { -int cpu; +unsigned int cpu; -for_each_online_cpu (cpu) -watchdog_disable (cpu); - -/* if all watchdogs are disabled, then they are disabled for the system */ - watchdog_enabled =0 ; +if (!watchdog_disabled) { + watchdog_disabled =1 ; +for_each_online_cpu (cpu) +kthread_park (per_cpu (softlockup_watchdog, cpu)); + } } -/* * proc handler for /proc/sys/kernel/nmi_watchdog,watchdog_thresh */
@@ -540,73 +484,35 @@ int proc_dowatchdog(struct ctl_table *ta {int ret; +if (watchdog_disabled <0 ) +return -ENODEV ; + ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos);if (ret || !write) - goto out; +return ret;if (watchdog_enabled && watchdog_thresh)watchdog_enable_all_cpus ();else watchdog_disable_all_cpus (); -out:return ret; }#endif /* CONFIG_SYSCTL */ - -/* -* Create/destroy watchdog threads as CPUs come and go: -*/ -static int __cpuinit -cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) -{ -int hotcpu = (unsigned long )hcpu; - -switch (action) { -case CPU_UP_PREPARE : -case CPU_UP_PREPARE_FROZEN : -watchdog_prepare_cpu (hotcpu); -break ; -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -if (watchdog_enabled) -watchdog_enable (hotcpu); -break ; -#ifdef CONFIG_HOTPLUG_CPU -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -watchdog_disable (hotcpu); -break ; -case CPU_DEAD : -case CPU_DEAD_FROZEN : -watchdog_disable (hotcpu); -break ; -#endif /* CONFIG_HOTPLUG_CPU */ - } - -/* -* hardlockup and softlockup are not important enough -* to block cpu bring up. Just always succeed and -* rely on printk output to flag problems. -*/ -return NOTIFY_OK ; -} - -static struct notifier_block __cpuinitdata cpu_nfb = { - .notifier_call = cpu_callback +static struct smp_hotplug_thread watchdog_threads = { + .store = &softlockup_watchdog, + .thread_fn = watchdog, + .thread_comm ="watchdog/%u" , + .setup = watchdog_enable, + .park = watchdog_disable, + .unpark = watchdog_enable, };void __init lockup_detector_init (void ) { -void *cpu = (void *)(long )smp_processor_id (); -int err; - - err =cpu_callback (&cpu_nfb,CPU_UP_PREPARE , cpu); -WARN_ON (notifier_to_errno (err)); - -cpu_callback (&cpu_nfb,CPU_ONLINE , cpu); -register_cpu_notifier (&cpu_nfb); - -return ; +if (smpboot_register_percpu_thread (&watchdog_threads)) { +pr_err ("Failed to create watchdog threads, disabled\n" ); + watchdog_disabled = -ENODEV ; + } }
RFC PATCH v2 6/7 rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread
In reply to Thomas GleixnerFrom: "Paul E. McKenney" <[email protected]>
Bring RCU into the new-age CPU-hotplug fold by modifying RCU's per-CPU kthread code to use the new smp_hotplug_thread facility.
[ tglx: Adapted it to use callbacks and to the simplified rcu yield ]
kernel/rcutree.c +0 -4
@@ -125,7 +125,6 @@ static int rcu_scheduler_fully_active __*/ static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);DEFINE_PER_CPU (unsigned int , rcu_cpu_kthread_status); -DEFINE_PER_CPU (int, rcu_cpu_kthread_cpu); DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);DEFINE_PER_CPU (char, rcu_cpu_has_work);
@@ -1458,7 +1457,6 @@ static void rcu_cleanup_dead_cpu(int cpustruct rcu_node *rnp = rdp->mynode;/* Outgoing CPU's rdp & rnp. */ /* Adjust any no-longer-needed kthreads. */ -rcu_stop_cpu_kthread (cpu);rcu_boost_kthread_setaffinity (rnp,-1 );/* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
@@ -2514,11 +2512,9 @@ static int __cpuinit rcu_cpu_notify(strucase CPU_ONLINE :case CPU_DOWN_FAILED :rcu_boost_kthread_setaffinity (rnp,-1 ); -rcu_cpu_kthread_setrt (cpu,1 );break ;case CPU_DOWN_PREPARE :rcu_boost_kthread_setaffinity (rnp, cpu); -rcu_cpu_kthread_setrt (cpu,0 );break ;case CPU_DYING :case CPU_DYING_FROZEN :
kernel/rcutree.h +0 -8
@@ -178,12 +178,6 @@ struct rcu_node {/* Refused to boost: not sure why, though. */ /* This can happen due to race conditions. */ #endif /* #ifdef CONFIG_RCU_BOOST */ -struct task_struct *node_kthread_task; -/* kthread that takes care of this rcu_node */ -/* structure, for example, awakening the */ -/* per-CPU kthreads as needed. */ -unsigned int node_kthread_status; -/* State of node_kthread_task for tracing. */ }____cacheline_internodealigned_in_smp ;/*
@@ -434,7 +428,6 @@ static int rcu_preempt_blocked_readers_c#ifdef CONFIG_HOTPLUG_CPU static void rcu_report_unblock_qs_rnp (struct rcu_node *rnp,unsigned long flags); -static void rcu_stop_cpu_kthread (int cpu);#endif /* #ifdef CONFIG_HOTPLUG_CPU */ static void rcu_print_detail_task_stall (struct rcu_state *rsp);static int rcu_print_task_stall (struct rcu_node *rnp);
@@ -467,7 +460,6 @@ static void rcu_preempt_do_callbacks(voistatic int __cpuinit rcu_spawn_one_boost_kthread (struct rcu_state *rsp,struct rcu_node *rnp);#endif /* #ifdef CONFIG_RCU_BOOST */ -static void rcu_cpu_kthread_setrt (int cpu,int to_rt);static void __cpuinit rcu_prepare_kthreads (int cpu);static void rcu_prepare_for_idle_init (int cpu);static void rcu_cleanup_after_idle (int cpu);
kernel/rcutree_plugin.h +25 -144
246 lines not on this page · raw message
kernel/rcutree_trace.c +1 -2
@@ -83,11 +83,10 @@ static void print_one_rcu_data(struct se rdp->nxttail[RCU_WAIT_TAIL]], ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);#ifdef CONFIG_RCU_BOOST -seq_printf (m," kt=%d/%c/%d ktl=%x" , +seq_printf (m," kt=%d/%c ktl=%x" ,per_cpu (rcu_cpu_has_work, rdp->cpu),convert_kthread_status (per_cpu (rcu_cpu_kthread_status, rdp->cpu)), -per_cpu (rcu_cpu_kthread_cpu, rdp->cpu),per_cpu (rcu_cpu_kthread_loops, rdp->cpu) &0xffff );#endif /* #ifdef CONFIG_RCU_BOOST */ seq_printf (m," b=%ld" , rdp->blimit);
RFC PATCH v2 7/7 infiniband: ehca: Use hotplug thread infrastructure
In reply to Thomas GleixnerGet rid of the hotplug notifiers and use the generic hotplug thread infrastructure.
--- drivers/infiniband/hw/ehca/ehca_irq.c | 240 ++++++++++++---------------------- drivers/infiniband/hw/ehca/ehca_irq.h | 5 2 files changed, 92 insertions(+), 153 deletions(-)
drivers/infiniband/hw/ehca/ehca_irq.c +89 -151
@@ -42,6 +42,7 @@*/ #include <linux/slab.h> +#include <linux/smpboot.h> #include "ehca_classes.h" #include "ehca_irq.h"
@@ -652,7 +653,7 @@ void ehca_tasklet_eq(unsigned long data)ehca_process_eq ((struct ehca_shca *)data,1 ); } -static inline int find_next_online_cpu (struct ehca_comp_pool *pool) +static int find_next_online_cpu (struct ehca_comp_pool *pool) {int cpu;unsigned long flags;
@@ -662,10 +663,15 @@ static inline int find_next_online_cpu(sehca_dmp (cpu_online_mask,cpumask_size (),"" );spin_lock_irqsave (&pool->last_cpu_lock, flags); - cpu =cpumask_next (pool->last_cpu, cpu_online_mask); -if (cpu >= nr_cpu_ids) - cpu =cpumask_first (cpu_online_mask); - pool->last_cpu = cpu; +while (1 ) { + cpu =cpumask_next (pool->last_cpu, cpu_online_mask); +if (cpu >= nr_cpu_ids) + cpu =cpumask_first (cpu_online_mask); + pool->last_cpu = cpu; +/* Might be on the way out */ +if (per_cpu_ptr (pool->cpu_comp_tasks, cpu)->active) +break ; + }spin_unlock_irqrestore (&pool->last_cpu_lock, flags);return cpu;
@@ -719,19 +725,18 @@ static void queue_comp_task(struct ehca_static void run_comp_task (struct ehca_cpu_comp_task *cct) {struct ehca_cq *cq; -unsigned long flags; -spin_lock_irqsave (&cct->task_lock, flags); +spin_lock_irq (&cct->task_lock);while (!list_empty (&cct->cq_list)) { cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); -spin_unlock_irqrestore (&cct->task_lock, flags); +spin_unlock_irq (&cct->task_lock);comp_event_callback (cq);if (atomic_dec_and_test (&cq->nr_events))wake_up (&cq->wait_completion); -spin_lock_irqsave (&cct->task_lock, flags); +spin_lock_irq (&cct->task_lock);spin_lock (&cq->task_lock); cq->nr_callbacks--;if (!cq->nr_callbacks) {
@@ -741,17 +746,51 @@ static void run_comp_task(struct ehca_cpspin_unlock (&cq->task_lock); } -spin_unlock_irqrestore (&cct->task_lock, flags); +spin_unlock_irq (&cct->task_lock); } -static int comp_task (void *__cct) +static void comp_task_park (unsigned int cpu) { -struct ehca_cpu_comp_task *cct = __cct; -int cql_empty; +struct ehca_cpu_comp_task *cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); +struct ehca_cpu_comp_task *target; +struct ehca_cq *cq, *tmp; +LIST_HEAD (list); + +spin_lock_irq (&cct->task_lock); + cct->cq_jobs =0 ; + cct->active =0 ; +list_splice_init (&cct->cq_list, &list); +spin_unlock_irq (&cct->task_lock); + + cpu =find_next_online_cpu (pool); + target =per_cpu_ptr (pool->cpu_comp_tasks, cpu); +spin_lock_irq (&target->task_lock); +list_for_each_entry_safe (cq, tmp, &list, entry) { +list_del (&cq->entry); +__queue_comp_task (cq, target); + } +spin_unlock_irq (&target->task_lock); +} + +static void comp_task_stop (unsigned int cpu,bool online) +{ +struct ehca_cpu_comp_task *cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); + +spin_lock_irq (&cct->task_lock); + cct->cq_jobs =0 ; + cct->active =0 ; +WARN_ON (!list_empty (&cct->cq_list)); +spin_unlock_irq (&cct->task_lock); +} + +static int comp_task (void *td) +{ +struct ehca_cpu_comp_task *cct =this_cpu_ptr (pool->cpu_comp_tasks);DECLARE_WAITQUEUE (wait, current); +int cql_empty; -set_current_state (TASK_INTERRUPTIBLE ); -while (!kthread_should_stop ()) { +while (!smpboot_thread_check_parking (td)) { +set_current_state (TASK_INTERRUPTIBLE );add_wait_queue (&cct->wait_queue, &wait);spin_lock_irq (&cct->task_lock);
@@ -768,131 +807,21 @@ static int comp_task(void *__cct) cql_empty =list_empty (&cct->cq_list);spin_unlock_irq (&cct->task_lock);if (!cql_empty) -run_comp_task (__cct); - -set_current_state (TASK_INTERRUPTIBLE ); +run_comp_task (cct); } -__set_current_state (TASK_RUNNING ); -return 0 ; } -static struct task_struct *create_comp_task (struct ehca_comp_pool *pool, -int cpu) -{ -struct ehca_cpu_comp_task *cct; - - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); -spin_lock_init (&cct->task_lock); -INIT_LIST_HEAD (&cct->cq_list); -init_waitqueue_head (&cct->wait_queue); - cct->task =kthread_create_on_node (comp_task, cct,cpu_to_node (cpu), -"ehca_comp/%d" , cpu); - -return cct->task; -} - -static void destroy_comp_task (struct ehca_comp_pool *pool, -int cpu) -{ -struct ehca_cpu_comp_task *cct; -struct task_struct *task; -unsigned long flags_cct; - - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); - -spin_lock_irqsave (&cct->task_lock, flags_cct); - - task = cct->task; - cct->task =NULL ; - cct->cq_jobs =0 ; - -spin_unlock_irqrestore (&cct->task_lock, flags_cct); - -if (task) -kthread_stop (task); -} - -static void __cpuinit take_over_work (struct ehca_comp_pool *pool,int cpu) -{ -struct ehca_cpu_comp_task *cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); -LIST_HEAD (list); -struct ehca_cq *cq; -unsigned long flags_cct; - -spin_lock_irqsave (&cct->task_lock, flags_cct); - -list_splice_init (&cct->cq_list, &list); - -while (!list_empty (&list)) { - cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); - -list_del (&cq->entry); -__queue_comp_task (cq,this_cpu_ptr (pool->cpu_comp_tasks)); - } - -spin_unlock_irqrestore (&cct->task_lock, flags_cct); - -} - -static int __cpuinit comp_pool_callback (struct notifier_block *nfb, -unsigned long action, -void *hcpu) -{ -unsigned int cpu = (unsigned long )hcpu; -struct ehca_cpu_comp_task *cct; - -switch (action) { -case CPU_UP_PREPARE : -case CPU_UP_PREPARE_FROZEN : -ehca_gen_dbg ("CPU: %x (CPU_PREPARE)" , cpu); -if (!create_comp_task (pool, cpu)) { -ehca_gen_err ("Can't create comp_task for cpu: %x" , cpu); -return notifier_from_errno (-ENOMEM ); - } -break ; -case CPU_UP_CANCELED : -case CPU_UP_CANCELED_FROZEN : -ehca_gen_dbg ("CPU: %x (CPU_CANCELED)" , cpu); - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); -kthread_bind (cct->task,cpumask_any (cpu_online_mask)); -destroy_comp_task (pool, cpu); -break ; -case CPU_ONLINE : -case CPU_ONLINE_FROZEN : -ehca_gen_dbg ("CPU: %x (CPU_ONLINE)" , cpu); - cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); -kthread_bind (cct->task, cpu); -wake_up_process (cct->task); -break ; -case CPU_DOWN_PREPARE : -case CPU_DOWN_PREPARE_FROZEN : -ehca_gen_dbg ("CPU: %x (CPU_DOWN_PREPARE)" , cpu); -break ; -case CPU_DOWN_FAILED : -case CPU_DOWN_FAILED_FROZEN : -ehca_gen_dbg ("CPU: %x (CPU_DOWN_FAILED)" , cpu); -break ; -case CPU_DEAD : -case CPU_DEAD_FROZEN : -ehca_gen_dbg ("CPU: %x (CPU_DEAD)" , cpu); -destroy_comp_task (pool, cpu); -take_over_work (pool, cpu); -break ; - } - -return NOTIFY_OK ; -} - -static struct notifier_block comp_pool_callback_nb__cpuinitdata = { - .notifier_call = comp_pool_callback, - .priority =0 , +static struct smp_hotplug_thread comp_pool_threads = { + .thread_fn = comp_task, + .thread_comm ="ehca_comp/%u" , + .cleanup = comp_task_stop, + .park = comp_task_park, };int ehca_create_comp_pool (void ) { -int cpu; -struct task_struct *task; +int cpu, ret = -ENOMEM ;if (!ehca_scaling_code)return 0 ;
@@ -905,38 +834,47 @@ int ehca_create_comp_pool(void) pool->last_cpu =cpumask_any (cpu_online_mask); pool->cpu_comp_tasks = alloc_percpu(struct ehca_cpu_comp_task); -if (pool->cpu_comp_tasks ==NULL ) { -kfree (pool); -return -EINVAL ; - } +if (!pool->cpu_comp_tasks) + goto out_pool; -for_each_online_cpu (cpu) { - task =create_comp_task (pool, cpu); -if (task) { -kthread_bind (task, cpu); -wake_up_process (task); - } + pool->cpu_comp_threads = alloc_percpu(struct task_struct *); +if (!pool->cpu_comp_threads) + goto out_tasks; + +for_each_present_cpu (cpu) { +struct ehca_cpu_comp_task *cct; + + cct =per_cpu_ptr (pool->cpu_comp_tasks, cpu); +spin_lock_init (&cct->task_lock); +INIT_LIST_HEAD (&cct->cq_list); +init_waitqueue_head (&cct->wait_queue); } -register_hotcpu_notifier (&comp_pool_callback_nb); + comp_pool_threads.store = pool->cpu_comp_threads; + ret =smpboot_register_percpu_thread (&comp_pool_threads); +if (ret) + goto out_threads; -printk (KERN_INFO "eHCA scaling code enabled\n" ); +pr_info ("eHCA scaling code enabled\n" ); +return ret; -return 0 ; +out_threads: +free_percpu (pool->cpu_comp_threads); +out_tasks: +free_percpu (pool->cpu_comp_tasks); +out_pool: +kfree (pool); +return ret; }void ehca_destroy_comp_pool (void ) { -int i; -if (!ehca_scaling_code)return ; -unregister_hotcpu_notifier (&comp_pool_callback_nb); - -for_each_online_cpu (i) -destroy_comp_task (pool, i); +smpboot_unregister_percpu_thread (&comp_pool_threads); +free_percpu (pool->cpu_comp_threads);free_percpu (pool->cpu_comp_tasks);kfree (pool); }
drivers/infiniband/hw/ehca/ehca_irq.h +3 -2
@@ -60,13 +60,14 @@ void ehca_process_eq(struct ehca_shca *sstruct ehca_cpu_comp_task {wait_queue_head_t wait_queue;struct list_head cq_list; -struct task_struct *task;spinlock_t task_lock;int cq_jobs; +int active; };struct ehca_comp_pool { -struct ehca_cpu_comp_task *cpu_comp_tasks; +struct ehca_cpu_comp_task __percpu *cpu_comp_tasks; +struct task_struct *__percpu *cpu_comp_threads;int last_cpu;spinlock_t last_cpu_lock; };
Quoted 7 lines · Thomas Gleixner
The following series implements the infrastructure for parking and unparking kernel threads to avoid the full teardown and fork on cpu hotplug operations along with management infrastructure for hotplug and users.
Changes since V1:
Quoted 7 lines
- Addressed the review comments
- Fixed a missing state update in parkme (reported by Paul)
- Simplifiedrcu_yield()
- Added Pauls RCU conversionFull diffstat below. Due to the RCU cleanup we now remove more code than we add. :)
;-)
With the exception of a build error for CONFIG_SMP=y:
I finally tracked down a hang, which turned out to be an unrelated bug of mine that happened to be triggered more reliably with these patches applied, hence the delay. Sigh!
For CONFIG_SMP=y:
softirq.c:(.text+0xa6d3): undefined reference to smpboot_thread_check_parking' softirq.c:(.init.text+0x4aa): undefined reference to smpboot_register_percpu_thread' softirq.c:(.text+0xb763): undefined reference to smpboot_thread_check_parking' softirq.c:(.init.text+0x48e): undefined reference to smpboot_register_percpu_thread'
My approach would be to make smpboot.o be unconditionally created by kernel/Makefile and to use conditional compilation as needed. The real question is whether we want to allow parking in !SMP kernels. I cannot see why we wouldn't -- there might be other reasons to park besides CPU hotplug. Thoughts?
Thanx, Paul
Quoted 20 lines
Thanks,
tglx
--- drivers/infiniband/hw/ehca/ehca_irq.c | 240 ++++++++------------- drivers/infiniband/hw/ehca/ehca_irq.h | 5 include/linux/kthread.h | 11 include/linux/smpboot.h | 40 +++ kernel/cpu.c | 10 kernel/kthread.c | 184 ++++++++++++++-- kernel/rcutree.c | 12 - kernel/rcutree.h | 15 - kernel/rcutree_plugin.h | 375 +++++----------------------------- kernel/rcutree_trace.c | 3 kernel/smpboot.c | 206 ++++++++++++++++++ kernel/smpboot.h | 4 kernel/softirq.c | 84 +------ kernel/watchdog.c | 232 ++++++--------------- 14 files changed, 678 insertions(+), 743 deletions(-)
Peter Zijlstra
maintainerQuoted 2 lines · Paul E. McKenney
there might be other reasons to park besides
CPU hotplug. Thoughts?
s2r, freezers and similar stuff?
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Paul E. McKenney
there might be other reasons to park besides
CPU hotplug. Thoughts?s2r, freezers and similar stuff?
OK, so it sounds like the full functionality should be available in !SMP kernels, then...
Thanx, Paul