nohz: Random fixes
Subsystems (6)
cover nohz: Random fixes
Hi,
A few fixes for nohz against -rc1. I'll likely send the non-rfc part to Ingo tomorrow, unless anybody has concerns.
Thanks.
---
Frederic Weisbecker (6):
vtime: Use consistent clocks among nohz accounting
watchdog: Boot-disable by default on full dynticks
kvm: Move guest entry/exit APIs to context_tracking
kthread: Enable parking requests from setup() and unpark() callbacks
watchdog: Rename confusing state variable
watchdog: Fix internal state with boot user disabled watchdog
Li Zhong (1):
nohz: Fix notifier return val that enforce timekeeping
Steven Rostedt (1):
nohz: Warn if the machine can not perform nohz_full
include/linux/context_tracking.h | 35 +++++++++++++++++++++++++++++++++++ include/linux/kvm_host.h | 37 +------------------------------------ include/linux/nmi.h | 2 +- include/linux/vtime.h | 4 ++-- kernel/context_tracking.c | 1 - kernel/sched/core.c | 2 +- kernel/sched/cputime.c | 6 +++--- kernel/smpboot.c | 6 ++++++ kernel/sysctl.c | 4 ++-- kernel/time/tick-sched.c | 7 ++++++- kernel/watchdog.c | 34 ++++++++++++++++++++-------------- 11 files changed, 77 insertions(+), 61 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/8 nohz: Warn if the machine can not perform nohz_full
From: Steven Rostedt <[email protected]>
If the user configures NO_HZ_FULL and defines nohz_full=XXX on the kernel command line, or enables NO_HZ_FULL_ALL, but nohz fails due to the machine having a unstable clock, warn about it.
We do not want users thinking that they are getting the benefit of nohz when their machine can not support it.
--- kernel/time/tick-sched.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
kernel/time/tick-sched.c +5 -0
@@ -178,6 +178,11 @@ static bool can_stop_full_tick(void)*/ if (!sched_clock_stable) {trace_tick_stop (0 ,"unstable sched clock\n" ); +/* +* Don't allow the user to think they can get +* full NO_HZ with this machine. +*/ +WARN_ONCE (1 ,"NO_HZ FULL will not work with unstable sched clock" );return false; }#endif
Signature · 1 line
1.7.5.4
PATCH 2/8 vtime: Use consistent clocks among nohz accounting
In reply to Frederic WeisbeckerWhile computing the cputime delta of dynticks CPUs, we are mixing up clocks of differents natures:
* local_clock() which takes care of unstable clock sources and fix these if needed.
* sched_clock() which is the weaker version of local_clock(). It doesn't compute any fixup in case of unstable source.
If the clock source is stable, those two clocks are the same and we can safely compute the difference against two random points.
Otherwise it results in random deltas as sched_clock() can randomly drift away, back or forward, from local_clock().
As a consequence, some strange behaviour with unstable tsc has been observed such as non progressing constant zero cputime. (The 'top' command showing no load).
Fix this by only using local_clock(), or its irq safe/remote equivalent, in vtime code.
--- include/linux/vtime.h | 4 ++-- kernel/sched/core.c | 2 +- kernel/sched/cputime.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
include/linux/vtime.h +2 -2
@@ -34,7 +34,7 @@ static inline void vtime_user_exit(struct task_struct *tsk) }extern void vtime_guest_enter (struct task_struct *tsk);extern void vtime_guest_exit (struct task_struct *tsk); -extern void vtime_init_idle (struct task_struct *tsk); +extern void vtime_init_idle (struct task_struct *tsk,int cpu);#else static inline void vtime_account_irq_exit (struct task_struct *tsk) {
@@ -45,7 +45,7 @@ static inline void vtime_user_enter(struct task_struct *tsk) { }static inline void vtime_user_exit (struct task_struct *tsk) { }static inline void vtime_guest_enter (struct task_struct *tsk) { }static inline void vtime_guest_exit (struct task_struct *tsk) { } -static inline void vtime_init_idle (struct task_struct *tsk) { } +static inline void vtime_init_idle (struct task_struct *tsk,int cpu) { }#endif #ifdef CONFIG_IRQ_TIME_ACCOUNTING
kernel/sched/core.c +1 -1
@@ -4745,7 +4745,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)*/ idle->sched_class = &idle_sched_class;ftrace_graph_init_idle_task (idle, cpu); -vtime_init_idle (idle); +vtime_init_idle (idle, cpu);#if defined(CONFIG_SMP )sprintf (idle->comm,"%s/%d" ,INIT_TASK_COMM , cpu);#endif
kernel/sched/cputime.c +3 -3
@@ -747,17 +747,17 @@ void arch_vtime_task_switch(struct task_struct *prev)write_seqlock (¤t->vtime_seqlock); current->vtime_snap_whence =VTIME_SYS ; - current->vtime_snap =sched_clock (); + current->vtime_snap =sched_clock_cpu (smp_processor_id ());write_sequnlock (¤t->vtime_seqlock); } -void vtime_init_idle (struct task_struct *t) +void vtime_init_idle (struct task_struct *t,int cpu) {unsigned long flags;write_seqlock_irqsave (&t->vtime_seqlock, flags); t->vtime_snap_whence =VTIME_SYS ; - t->vtime_snap =sched_clock (); + t->vtime_snap =sched_clock_cpu (cpu);write_sequnlock_irqrestore (&t->vtime_seqlock, flags); }
Signature · 1 line
1.7.5.4
Re: [PATCH 2/8] vtime: Use consistent clocks among nohz accounting
Am 20.05.2013 18:01, schrieb Frederic Weisbecker:
Quoted 2 lines
While computing the cputime delta of dynticks CPUs, we are mixing up clocks of differents natures:
[...]
Quoted 3 lines
As a consequence, some strange behaviour with unstable tsc has been observed such as non progressing constant zero cputime. (The 'top' command showing no load).
This happens for example on my trusty ThinkPad X200s (family 6 model 23 stepping 10 Core 2 duo), seriously confusing its user (me :-).
Quoted 14 lines
Fix this by only using
local_clock(), or its irq safe/remote equivalent, in vtime code.Reported-by Mike Galbraith <[email protected]>Suggested-by Mike Galbraith <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Borislav Petkov <[email protected]>Cc Li Zhong <[email protected]>Cc Mike Galbraith <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>
FWIW:
This patch fixes the 0% CPU issue on openSUSE Factory kernels for me.
Best regards,
Stefan
Signature · 6 lines
Stefan Seyfried Linux Consultant & Developer -- GPG Key: 0x731B665B B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
Steven Rostedt
reviewerRe: [PATCH 2/8] vtime: Use consistent clocks among nohz accounting
Quoted 2 lines · Stefan Seyfried
FWIW:
Tested-by Stefan Seyfried <[email protected]>
FWIW, we can always use testers. Thanks for testing!
-- Steve
Re: [PATCH 2/8] vtime: Use consistent clocks among nohz accounting
In reply to Stefan SeyfriedQuoted 28 lines · Stefan Seyfried
Am 20.05.2013 18:01, schrieb Frederic Weisbecker:
Quoted 2 lines
While computing the cputime delta of dynticks CPUs, we are mixing up clocks of differents natures:
[...]
Quoted 3 lines
As a consequence, some strange behaviour with unstable tsc has been observed such as non progressing constant zero cputime. (The 'top' command showing no load).
This happens for example on my trusty ThinkPad X200s (family 6 model 23 stepping 10 Core 2 duo), seriously confusing its user (me :-).
Quoted 14 lines
Fix this by only using
local_clock(), or its irq safe/remote equivalent, in vtime code.Reported-by Mike Galbraith <[email protected]>Suggested-by Mike Galbraith <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Borislav Petkov <[email protected]>Cc Li Zhong <[email protected]>Cc Mike Galbraith <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>
Quoted 4 lines
FWIW:
Tested-by Stefan Seyfried <[email protected]>This patch fixes the 0% CPU issue on openSUSE Factory kernels for me.
Thanks! The patch has been committed already so I can't add your Tested-by:
but feedbacks on testing are always appeciated.
Re: [PATCH 2/8] vtime: Use consistent clocks among nohz accounting
Am 03.06.2013 21:48, schrieb Frederic Weisbecker:
Quoted 8 lines · Stefan Seyfried
Quoted 4 lines
FWIW:
Tested-by Stefan Seyfried <[email protected]>This patch fixes the 0% CPU issue on openSUSE Factory kernels for me.
Thanks! The patch has been committed already so I can't add your Tested-by:
but feedbacks on testing are always appeciated.
But it did not end up in Linus' tree yet. That would be more important for me than the credits in the commit message :-)
Thanks,
Stefan
Signature · 6 lines
Stefan Seyfried Linux Consultant & Developer -- GPG Key: 0x731B665B B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
Re: [PATCH 2/8] vtime: Use consistent clocks among nohz accounting
Quoted 5 lines · Stefan Seyfried
Am 03.06.2013 21:48, schrieb Frederic Weisbecker:
Quoted 4 lines · Stefan Seyfried
Quoted 3 lines
FWIW:
Tested-by Stefan Seyfried <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This patch fixes the 0% CPU issue on openSUSE Factory kernels for me.
Thanks! The patch has been committed already so I can't add your Tested-by:
but feedbacks on testing are always appeciated.But it did not end up in Linus' tree yet. That would be more important for me than the credits in the commit message :-)
It will soon :)
Quoted 11 lines
Thanks,
Stefan
Signature · 6 lines
Stefan Seyfried Linux Consultant & Developer -- GPG Key: 0x731B665B B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
PATCH 3/8 watchdog: Boot-disable by default on full dynticks
In reply to Frederic WeisbeckerWhen the watchdog runs, it prevents the full dynticks CPUs from stopping their tick because the hard lockup detector uses perf events internally, which in turn rely on the periodic tick.
Since this is a rather confusing behaviour that is not easy to track down and identify for those who want to test CONFIG_NO_HZ_FULL, let's default disable the watchdog on boot time when full dynticks is enabled.
The user can still enable it later on runtime using proc or sysctl.
--- kernel/watchdog.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
kernel/watchdog.c +6 -0
@@ -543,6 +543,12 @@ static struct smp_hotplug_thread watchdog_threads = {void __init lockup_detector_init (void ) { +#ifdef CONFIG_NO_HZ_FULL + watchdog_enabled =0 ; + watchdog_disabled =1 ; +pr_warning ("Disabled lockup detectors by default because of full dynticks\n" ); +pr_warning ("You can overwrite that with 'sysctl -w kernel.watchdog=1'\n" ); +#endif set_sample_period ();if (smpboot_register_percpu_thread (&watchdog_threads)) {pr_err ("Failed to create watchdog threads, disabled\n" );
Signature · 1 line
1.7.5.4
Re: [PATCH 3/8] watchdog: Boot-disable by default on full dynticks
Quoted 5 lines · Frederic Weisbecker
When the watchdog runs, it prevents the full dynticks CPUs from stopping their tick because the hard lockup detector uses perf events internally, which in turn rely on the periodic tick.
Quoted 7 lines
Since this is a rather confusing behaviour that is not easy to track down and identify for those who want to test
CONFIG_NO_HZ_FULL, let's default disable the watchdog on boot time when full dynticks is enabled.The user can still enable it later on runtime using proc or sysctl.
I thought Peter committed a patch to perf so that this isn't needed any more?
Cheers,
Don
Quoted 36 lines
Reported-by Steven Rostedt <[email protected]>Suggested-by Peter Zijlstra <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Ingo Molnar <[email protected]>Cc Andrew Morton <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zhong <[email protected]>Cc Don Zickus <[email protected]>--- kernel/watchdog.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)kernel/watchdog.c +6
-0@@ -543,6 +543,12 @@ static struct smp_hotplug_thread watchdog_threads = {void __init lockup_detector_init (void ) { +#ifdef CONFIG_NO_HZ_FULL + watchdog_enabled =0 ; + watchdog_disabled =1 ; +pr_warning ("Disabled lockup detectors by default because of full dynticks\n" ); +pr_warning ("You can overwrite that with 'sysctl -w kernel.watchdog=1'\n" ); +#endif set_sample_period ();if (smpboot_register_percpu_thread (&watchdog_threads)) {pr_err ("Failed to create watchdog threads, disabled\n" );Signature · 1 line
1.7.5.4
Re: [PATCH 3/8] watchdog: Boot-disable by default on full dynticks
Quoted 11 lines · Don Zickus
Quoted 10 lines · Frederic Weisbecker
When the watchdog runs, it prevents the full dynticks CPUs from stopping their tick because the hard lockup detector uses perf events internally, which in turn rely on the periodic tick.
Since this is a rather confusing behaviour that is not easy to track down and identify for those who want to test
CONFIG_NO_HZ_FULL, let's default disable the watchdog on boot time when full dynticks is enabled.
Quoted 5 lines
Quoted 2 lines
The user can still enable it later on runtime using proc or sysctl.
I thought Peter committed a patch to perf so that this isn't needed any more?
There is the patchset that converts perf_event_task_tick() to an hrtimer. But I'm not sure it covers everything. Also this will be for the next merge window. And in the end this moves the problem elsewhere: we still have timer interrupts, they just come as specific hrtimers, although may be less often, I haven't looked yet at the patchset.
PATCH 4/8 kvm: Move guest entry/exit APIs to context_tracking
In reply to Frederic WeisbeckerThe kvm_host.h header file doesn't handle well inclusion when archs don't support KVM.
This results in build crashes for such archs when they want to implement context tracking because this subsystem includes kvm_host.h in order to implement the guest_enter/exit APIs but it doesn't handle KVM off case.
To fix this, move the guest_enter()/guest_exit() declarations and generic implementation to the context tracking headers. These generic APIs actually belong to this subsystem, besides other domains boundary tracking like user_enter() et al.
KVM now properly becomes a user of this library, not the other buggy way around.
--- include/linux/context_tracking.h | 35 +++++++++++++++++++++++++++++++++++ include/linux/kvm_host.h | 37 +------------------------------------ kernel/context_tracking.c | 1 - 3 files changed, 36 insertions(+), 37 deletions(-)
include/linux/context_tracking.h +35 -0
@@ -3,6 +3,7 @@#include <linux/sched.h> #include <linux/percpu.h> +#include <linux/vtime.h> #include <asm/ptrace.h> struct context_tracking {
@@ -19,6 +20,26 @@ struct context_tracking { } state; }; +static inline void __guest_enter (void ) +{ +/* +* This is running in ioctl context so we can avoid +* the call to vtime_account() with its unnecessary idle check. +*/ +vtime_account_system (current); + current->flags |=PF_VCPU ; +} + +static inline void __guest_exit (void ) +{ +/* +* This is running in ioctl context so we can avoid +* the call to vtime_account() with its unnecessary idle check. +*/ +vtime_account_system (current); + current->flags &= ~PF_VCPU ; +} +#ifdef CONFIG_CONTEXT_TRACKING DECLARE_PER_CPU(struct context_tracking, context_tracking);
@@ -35,6 +56,9 @@ static inline bool context_tracking_active(void)extern void user_enter (void );extern void user_exit (void ); +extern void guest_enter (void ); +extern void guest_exit (void ); +static inline enum ctx_state exception_enter (void ) {enum ctx_state prev_ctx;
@@ -57,6 +81,17 @@ extern void context_tracking_task_switch(struct task_struct *prev,static inline bool context_tracking_in_user (void ) {return false; }static inline void user_enter (void ) { }static inline void user_exit (void ) { } + +static inline void guest_enter (void ) +{ +__guest_enter (); +} + +static inline void guest_exit (void ) +{ +__guest_exit (); +} +static inline enum ctx_state exception_enter (void ) {return 0 ; }static inline void exception_exit (enum ctx_state prev_ctx) { } static inline void context_tracking_task_switch(struct task_struct *prev,
include/linux/kvm_host.h +1 -36
@@ -23,6 +23,7 @@#include <linux/ratelimit.h> #include <linux/err.h> #include <linux/irqflags.h> +#include <linux/context_tracking.h> #include <asm/signal.h> #include <linux/kvm.h>
@@ -760,42 +761,6 @@ static inline int kvm_iommu_unmap_guest(struct kvm *kvm) }#endif -static inline void __guest_enter (void ) -{ -/* -* This is running in ioctl context so we can avoid -* the call to vtime_account() with its unnecessary idle check. -*/ -vtime_account_system (current); - current->flags |=PF_VCPU ; -} - -static inline void __guest_exit (void ) -{ -/* -* This is running in ioctl context so we can avoid -* the call to vtime_account() with its unnecessary idle check. -*/ -vtime_account_system (current); - current->flags &= ~PF_VCPU ; -} - -#ifdef CONFIG_CONTEXT_TRACKING -extern void guest_enter (void ); -extern void guest_exit (void ); - -#else /* !CONFIG_CONTEXT_TRACKING */ -static inline void guest_enter (void ) -{ -__guest_enter (); -} - -static inline void guest_exit (void ) -{ -__guest_exit (); -} -#endif /* !CONFIG_CONTEXT_TRACKING */ -static inline void kvm_guest_enter (void ) {unsigned long flags;
kernel/context_tracking.c +0 -1
@@ -15,7 +15,6 @@*/ #include <linux/context_tracking.h> -#include <linux/kvm_host.h> #include <linux/rcupdate.h> #include <linux/sched.h> #include <linux/hardirq.h>
Signature · 1 line
1.7.5.4
PATCH 5/8 nohz: Fix notifier return val that enforce timekeeping
In reply to Frederic WeisbeckerFrom: Li Zhong <[email protected]>
In tick_nohz_cpu_down_callback() if the cpu is the one handling timekeeping , we must return something that stops the CPU_DOWN_PREPARE notifiers and then start notify CPU_DOWN_FAILED on the already called notifier call backs.
However traditional errno values are not handled by the notifier unless these are encapsulated using errno_to_notifier().
Hence the current -EINVAL is misinterpreted and converted to junk after notifier_to_errno(), leaving the notifier subsystem to random behaviour such as eventually allowing the cpu to go down.
Fix this by using the standard NOTIFY_BAD instead.
--- kernel/time/tick-sched.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/time/tick-sched.c +1 -1
@@ -311,7 +311,7 @@ static int __cpuinit tick_nohz_cpu_down_callback(struct notifier_block *nfb,* we can't safely shutdown that CPU. */ if (have_nohz_full_mask && tick_do_timer_cpu == cpu) -return -EINVAL ; +return NOTIFY_BAD ;break ; }return NOTIFY_OK ;
Signature · 1 line
1.7.5.4
RFC PATCH 6/8 kthread: Enable parking requests from setup() and unpark() callbacks
In reply to Frederic WeisbeckerWhen the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the setup() callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.
However the parking request is not well handled when done from the setup() callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.
In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
We could workaround some solution in the watchdog code like forcing one pass to the thread function and immediately return to park.
But supporting parking requests from ->setup() or ->unpark() callbacks look like proper way to implement cancellation in general. So let's fix it that way.
--- kernel/smpboot.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
kernel/smpboot.c +6 -0
@@ -151,6 +151,12 @@ static int smpboot_thread_fn(void *data)break ; } +/* Check if setup or unpark actually want us to park */ +if (kthread_should_stop () ||kthread_should_park ()) { +preempt_enable (); +continue ; + } +if (!ht->thread_should_run (td->cpu)) {preempt_enable ();schedule ();
Signature · 1 line
1.7.5.4
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
Quoted 16 lines · Frederic Weisbecker
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
Quoted 4 lines
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Out of curiosity, this can happen only for short period of time right?After some time this will work right as the thread get back in action after the schedule call.Then sysctl and procfs will work I think.
Quoted 47 lines
We could workaround some solution in the watchdog code like forcing one pass to the thread function and immediately return to park.
But supporting parking requests from ->setup() or ->unpark() callbacks look like proper way to implement cancellation in general. So let's fix it that way.
Signed-off-by Frederic Weisbecker <[email protected]>Cc Srivatsa S. Bhat <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Borislav Petkov <[email protected]>Cc Li Zhong <[email protected]>Cc Don Zickus <[email protected]>--- kernel/smpboot.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)kernel/smpboot.c +6
-1@@ -151,6 +151,12 @@ static int smpboot_thread_fn(void *data)break ; } +/* Check if setup or unpark actually want us to park */ +if (kthread_should_stop () ||kthread_should_park ()) { +preempt_enable (); +continue ; + } +if (!ht->thread_should_run (td->cpu)) {preempt_enable ();schedule (); --1.7.5.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
Quoted 17 lines · anish singh
Quoted 16 lines · Frederic Weisbecker
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
Quoted 7 lines
Quoted 4 lines
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Out of curiosity, this can happen only for short period of time right?After some time this will work right as the thread get back in action after the schedule call.Then sysctl and procfs will work I think.
kthread_unpark() can wake up a task only if the task is in TASK_PARKED state. But since the above task would be in TASK_INTERRUPTIBLE state (since it is not parked), kthread_unpark() will be powerless to do anything.
Regards,
Srivatsa S. Bhat
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
Quoted 22 lines · Srivatsa S. Bhat
Quoted 21 lines · anish singh
Quoted 20 lines · Frederic Weisbecker
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Quoted 7 lines
Quoted 3 lines
Out of curiosity, this can happen only for short period of time right?After some time this will work right as the thread get back in action after the schedule call.Then sysctl and procfs will work I think.
kthread_unpark()can wake up a task only if the task is inTASK_PARKEDstate. But since the above task would be inTASK_INTERRUPTIBLEstate (since it is not parked),kthread_unpark()will be powerless to do anything.
Yes but this will happen only for a short period of time right? After the schdule() call the below code gets executed in while() loop.
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;
}
As we have already called kthread_park this above if() condition gets true and it will park the thread wouldn't it?But this will happen after the schedule call which is not right as mentioned by fredrick.
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
Quoted 28 lines · anish singh
Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · anish singh
Quoted 16 lines · Frederic Weisbecker
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
Quoted 4 lines
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Out of curiosity, this can happen only for short period of time right?After some time this will work right as the thread get back in action after the schedule call.Then sysctl and procfs will work I think.
Quoted 6 lines
Quoted 3 lines
kthread_unpark()can wake up a task only if the task is inTASK_PARKEDstate. But since the above task would be inTASK_INTERRUPTIBLEstate (since it is not parked),kthread_unpark()will be powerless to do anything.Yes but this will happen only for a short period of time right? After the
schdule()call the below code gets executed inwhile()loop.
schedule() is not just another function call from which you'll simply return "after a short period of time". We have set the task's state to TASK_INTERRUPTIBLE at the beginning of the loop. So the call to schedule() will kick the task out of the runqueue, since it is not runnable any more.
You need somebody to do a wake_up_process() or something similar to make the task runnable again, after which it gets back to the runqueue and gets a chance to run. But the only one who can do wake_up_process() for this watchdog task in this case, is the kthread_unpark() code, which needs the task to be in TASK_PARKED state, not TASK_INTERRUPTIBLE. So the call to wake_up_state() returns without doing anything, leaving the watchdog task non-runnable. This is what Frederic referred to, when he said that enabling nmi watchdog via sysctl/procfs won't do anything.
Quoted 13 lines
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;
}
Quoted 4 lines
As we have already called
kthread_parkthis aboveif()condition gets true and it will park the thread wouldn't it?But this will happen after the schedule call which is not right as mentioned by fredrick.
Regards,
Srivatsa S. Bhat
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
In reply to anish singh2013/5/21, anish singh <[email protected]>:
Quoted 50 lines
Quoted 28 lines · Srivatsa S. Bhat
Quoted 18 lines · anish singh
Quoted 16 lines · Frederic Weisbecker
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
Quoted 8 lines
Quoted 4 lines
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Out of curiosity, this can happen only for short period of time right?After
some time this will work right as the thread get back in action after the schedule call.Then sysctl and procfs will work I think.Quoted 4 lines
kthread_unpark()can wake up a task only if the task is inTASK_PARKEDstate. But since the above task would be inTASK_INTERRUPTIBLEstate (since it is not parked),kthread_unpark()will be powerless to do anything.Yes but this will happen only for a short period of time right? After the
schdule()call the below code gets executed inwhile()loop.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;
}
Quoted 5 lines
As we have already called
kthread_parkthis aboveif()condition gets true and
it will park the thread wouldn't it?But this will happen after the schedule call which is not right as mentioned by fredrick.
But we are scheduling in TASK_INTERRUPTIBLE mode so we are going to sleep until some other thread wake us. But we are unparked instead of being awoken. This just have no effect because kthread_unpark() is a no-op on non-parked kthreads.
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
In reply to Frederic WeisbeckerQuoted 21 lines · Frederic Weisbecker
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Quoted 4 lines
We could workaround some solution in the watchdog code like forcing one pass to the thread function and immediately return to park.
But supporting parking requests from ->setup() or ->unpark()
unpark() can already do a proper park, because immediately after coming out of the parked state, the 'continue' statement helps re-evaluate the stop/park condition.
So this fix is only for the ->setup() case.
Quoted 3 lines
callbacks look like proper way to implement cancellation in general. So let's fix it that way.
Sounds good to me.
But I wonder what nmi_watchdog=0 should actually mean, semantically.. The current code works as if the user asked us not to run the watchdog threads, but it could as well be interpreted as if the user does not want to run *any* watchdog-related *code*. In that case, ideally we should *unregister* the watchdog threads, instead of just parking them. And when the user enables them again via sysctl/procfs, we should register the watchdog threads with the smpboot infrastructure.
I'm not saying that the current semantics is wrong, but if we really implement it the other way I proposed above, then we won't have to deal with weird issues like ->setup() code wanting to park, and watchdog threads unparking and parking themselves on every CPU hotplug operation, despite the fact that the user specified nmi_watchdog=0 on the kernel command line.
Regards,
Srivatsa S. Bhat
Quoted 32 lines
Signed-off-by Frederic Weisbecker <[email protected]>Cc Srivatsa S. Bhat <[email protected]>Cc Steven Rostedt <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Borislav Petkov <[email protected]>Cc Li Zhong <[email protected]>Cc Don Zickus <[email protected]>--- kernel/smpboot.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)kernel/smpboot.c +6
-0@@ -151,6 +151,12 @@ static int smpboot_thread_fn(void *data)break ; } +/* Check if setup or unpark actually want us to park */ +if (kthread_should_stop () ||kthread_should_park ()) { +preempt_enable (); +continue ; + } +if (!ht->thread_should_run (td->cpu)) {preempt_enable ();schedule ();
Re: [RFC PATCH 6/8] kthread: Enable parking requests from setup() and unpark() callbacks
2013/5/21 Srivatsa S. Bhat <[email protected]>:
Quoted 22 lines · Frederic Weisbecker
Quoted 21 lines
When the watchdog code is boot-disabled by the user, for example through the 'nmi_watchdog=0' boot option, the
setup()callback of the watchdog kthread requests to park the task, and that until the user later re-enables the watchdog through sysctl or procfs.However the parking request is not well handled when done from the
setup()callback. After ->setup() is called, the generic smpboot kthread loop directly tries to call the thread function or wait for some event if ->thread_should_run() is false.In the case of the watchdog kthread, ->thread_should_run() returns false and the kthread goes to sleep and wait for the watchdog timer to wake it up. But the timer is not enabled since the user requested to disable the watchdog. We want the kthread to park instead of waiting for events that can't happen.
As a result, later unpark requests after sysctl write through 'sysctl -w kernel.watchdog=1' won't wake up/unpark the task as expected, since it's not parked anyway, leaving the value modified without triggering any action.
Quoted 8 lines
Quoted 4 lines
We could workaround some solution in the watchdog code like forcing one pass to the thread function and immediately return to park.
But supporting parking requests from ->setup() or ->unpark()
unpark()can already do a proper park, because immediately after coming out of the parked state, the 'continue' statement helps re-evaluate the stop/park condition.
Right.
Quoted 19 lines
So this fix is only for the ->setup() case.
Quoted 3 lines
callbacks look like proper way to implement cancellation in general. So let's fix it that way.
Sounds good to me.
Reviewed-by Srivatsa S. Bhat <[email protected]>But I wonder what nmi_watchdog=0 should actually mean, semantically.. The current code works as if the user asked us not to run the watchdog threads, but it could as well be interpreted as if the user does not want to run *any* watchdog-related *code*. In that case, ideally we should *unregister* the watchdog threads, instead of just parking them. And when the user enables them again via sysctl/procfs, we should register the watchdog threads with the smpboot infrastructure.
Quoted 6 lines
I'm not saying that the current semantics is wrong, but if we really implement it the other way I proposed above, then we won't have to deal with weird issues like ->setup() code wanting to park, and watchdog threads unparking and parking themselves on every CPU hotplug operation, despite the fact that the user specified nmi_watchdog=0 on the kernel command line.
That's an interesting point. It seems that using smpboot register/unregister operations for sysctl control would be more appropriate and less complicated. I'm going to give it a try.
Thanks!
RFC PATCH 7/8 watchdog: Rename confusing state variable
In reply to Frederic WeisbeckerWe have two very conflicting state variable names in the watchdog:
* watchdog_enabled: This one reflects the user interface. It's set to 1 by default and can be overriden with boot options or sysctl/procfs interface.
* watchdog_disabled: This is the internal toggle state that tells if watchdog threads, timers and NMI events are currently running or not. This state depends on the user settings and hardware support. It's a convenient state latch.
Now we really need to find clearer names because those are just too confusing to encourage deep review.
watchdog_enabled now becomes watchdog_user_enabled to reflect its purpose as an interface.
watchdog_disabled becomes watchdog_running to suggest its role as a pure internal state.
--- include/linux/nmi.h | 2 +- kernel/sysctl.c | 4 ++-- kernel/watchdog.c | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-)
include/linux/nmi.h +1 -1
@@ -46,7 +46,7 @@ static inline bool trigger_all_cpu_backtrace(void)#ifdef CONFIG_LOCKUP_DETECTOR int hw_nmi_is_cpu_stuck (struct pt_regs *);u64 hw_nmi_get_sample_period (int watchdog_thresh); -extern int watchdog_enabled; +extern int watchdog_user_enabled;extern int watchdog_thresh;struct ctl_table ; extern int proc_dowatchdog(struct ctl_table *, int ,
kernel/sysctl.c +2 -2
@@ -801,7 +801,7 @@ static struct ctl_table kern_table[] = {#if defined(CONFIG_LOCKUP_DETECTOR ) { .procname = "watchdog", - .data = &watchdog_enabled, + .data = &watchdog_user_enabled, .maxlen = sizeof (int), .mode = 0644, .proc_handler = proc_dowatchdog,
@@ -828,7 +828,7 @@ static struct ctl_table kern_table[] = { }, { .procname = "nmi_watchdog", - .data = &watchdog_enabled, + .data = &watchdog_user_enabled, .maxlen = sizeof (int), .mode = 0644, .proc_handler = proc_dowatchdog,
kernel/watchdog.c +16 -16
@@ -29,9 +29,9 @@#include <linux/kvm_para.h> #include <linux/perf_event.h> -int watchdog_enabled =1 ; +int watchdog_user_enabled =1 ;int __read_mostly watchdog_thresh =10 ; -static int __read_mostly watchdog_disabled; +static int __read_mostly watchdog_running =1 ;static u64 __read_mostly sample_period; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);
@@ -63,7 +63,7 @@ static int __init hardlockup_panic_setup(char *str)else if (!strncmp (str,"nopanic" ,7 )) hardlockup_panic =0 ;else if (!strncmp (str,"0" ,1 )) - watchdog_enabled =0 ; + watchdog_user_enabled =0 ;return 1 ; }__setup ("nmi_watchdog=" , hardlockup_panic_setup);
@@ -82,7 +82,7 @@ __setup("softlockup_panic=", softlockup_panic_setup);static int __init nowatchdog_setup (char *str) { - watchdog_enabled =0 ; + watchdog_user_enabled =0 ;return 1 ; }__setup ("nowatchdog" , nowatchdog_setup);
@@ -90,7 +90,7 @@ __setup("nowatchdog", nowatchdog_setup);/* deprecated */ static int __init nosoftlockup_setup (char *str) { - watchdog_enabled =0 ; + watchdog_user_enabled =0 ;return 1 ; }__setup ("nosoftlockup" , nosoftlockup_setup);
@@ -158,7 +158,7 @@ void touch_all_softlockup_watchdogs(void)#ifdef CONFIG_HARDLOCKUP_DETECTOR void touch_nmi_watchdog (void ) { -if (watchdog_enabled) { +if (watchdog_user_enabled) {unsigned cpu;for_each_present_cpu (cpu) {
@@ -347,7 +347,7 @@ static void watchdog_enable(unsigned int cpu)hrtimer_init (hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); hrtimer->function = watchdog_timer_fn; -if (!watchdog_enabled) { +if (!watchdog_user_enabled) {kthread_park (current);return ; }
@@ -482,8 +482,8 @@ static void watchdog_enable_all_cpus(void) {unsigned int cpu; -if (watchdog_disabled) { - watchdog_disabled =0 ; +if (!watchdog_running) { + watchdog_running =1 ;for_each_online_cpu (cpu)kthread_unpark (per_cpu (softlockup_watchdog, cpu)); }
@@ -493,8 +493,8 @@ static void watchdog_disable_all_cpus(void) {unsigned int cpu; -if (!watchdog_disabled) { - watchdog_disabled =1 ; +if (watchdog_running) { + watchdog_running =0 ;for_each_online_cpu (cpu)kthread_park (per_cpu (softlockup_watchdog, cpu)); }
@@ -509,7 +509,7 @@ int proc_dowatchdog(struct ctl_table *table, int write, {int ret; -if (watchdog_disabled <0 ) +if (watchdog_running <0 )return -ENODEV ; ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos);
@@ -522,7 +522,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,* disabled. The 'watchdog_disabled' variable check in * watchdog_*_all_cpus() function takes care of this. */ -if (watchdog_enabled && watchdog_thresh) +if (watchdog_user_enabled && watchdog_thresh)watchdog_enable_all_cpus ();else watchdog_disable_all_cpus ();
@@ -544,14 +544,14 @@ static struct smp_hotplug_thread watchdog_threads = {void __init lockup_detector_init (void ) {#ifdef CONFIG_NO_HZ_FULL - watchdog_enabled =0 ; - watchdog_disabled =1 ; + watchdog_user_enabled =0 ; + watchdog_running =0 ;pr_warning ("Disabled lockup detectors by default because of full dynticks\n" );pr_warning ("You can overwrite that with 'sysctl -w kernel.watchdog=1'\n" );#endif set_sample_period ();if (smpboot_register_percpu_thread (&watchdog_threads)) {pr_err ("Failed to create watchdog threads, disabled\n" ); - watchdog_disabled = -ENODEV ; + watchdog_running = -ENODEV ; } }
Signature · 1 line
1.7.5.4
Re: [RFC PATCH 7/8] watchdog: Rename confusing state variable
Quoted 12 lines · Frederic Weisbecker
We have two very conflicting state variable names in the watchdog:
*
watchdog_enabled: This one reflects the user interface. It's set to 1 by default and can be overriden with boot options or sysctl/procfs interface.*
watchdog_disabled: This is the internal toggle state that tells if watchdog threads, timers and NMI events are currently running or not. This state depends on the user settings and hardware support. It's a convenient state latch.
Quoted 8 lines
Now we really need to find clearer names because those are just too confusing to encourage deep review.
watchdog_enablednow becomeswatchdog_user_enabledto reflect its purpose as an interface.
watchdog_disabledbecomeswatchdog_runningto suggest its role as a pure internal state.
Heh. Thanks for the cleanup.
Quoted 168 lines
Signed-off-by Frederic Weisbecker <[email protected]>Cc Ingo Molnar <[email protected]>Cc Don Zickus <[email protected]>Cc Peter Zijlstra <[email protected]>--- include/linux/nmi.h | 2 +- kernel/sysctl.c | 4 ++-- kernel/watchdog.c | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-)include/linux/nmi.h +1
-1@@ -46,7 +46,7 @@ static inline bool trigger_all_cpu_backtrace(void)#ifdef CONFIG_LOCKUP_DETECTOR int hw_nmi_is_cpu_stuck (struct pt_regs *);u64 hw_nmi_get_sample_period (int watchdog_thresh); -extern int watchdog_enabled; +extern int watchdog_user_enabled;extern int watchdog_thresh;struct ctl_table ; extern int proc_dowatchdog(struct ctl_table *, int ,kernel/sysctl.c +2
-2@@ -801,7 +801,7 @@ static struct ctl_table kern_table[] = {#if defined(CONFIG_LOCKUP_DETECTOR ) { .procname = "watchdog", - .data = &watchdog_enabled, + .data = &watchdog_user_enabled, .maxlen = sizeof (int), .mode = 0644, .proc_handler = proc_dowatchdog,@@ -828,7 +828,7 @@ static struct ctl_table kern_table[] = { }, { .procname = "nmi_watchdog", - .data = &watchdog_enabled, + .data = &watchdog_user_enabled, .maxlen = sizeof (int), .mode = 0644, .proc_handler = proc_dowatchdog,kernel/watchdog.c +16
-16@@ -29,9 +29,9 @@#include <linux/kvm_para.h> #include <linux/perf_event.h> -int watchdog_enabled =1 ; +int watchdog_user_enabled =1 ;int __read_mostly watchdog_thresh =10 ; -static int __read_mostly watchdog_disabled; +static int __read_mostly watchdog_running =1 ;static u64 __read_mostly sample_period; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);@@ -63,7 +63,7 @@ static int __init hardlockup_panic_setup(char *str)else if (!strncmp (str,"nopanic" ,7 )) hardlockup_panic =0 ;else if (!strncmp (str,"0" ,1 )) - watchdog_enabled =0 ; + watchdog_user_enabled =0 ;return 1 ; }__setup ("nmi_watchdog=" , hardlockup_panic_setup);@@ -82,7 +82,7 @@ __setup("softlockup_panic=", softlockup_panic_setup);static int __init nowatchdog_setup (char *str) { - watchdog_enabled =0 ; + watchdog_user_enabled =0 ;return 1 ; }__setup ("nowatchdog" , nowatchdog_setup);@@ -90,7 +90,7 @@ __setup("nowatchdog", nowatchdog_setup);/* deprecated */ static int __init nosoftlockup_setup (char *str) { - watchdog_enabled =0 ; + watchdog_user_enabled =0 ;return 1 ; }__setup ("nosoftlockup" , nosoftlockup_setup);@@ -158,7 +158,7 @@ void touch_all_softlockup_watchdogs(void)#ifdef CONFIG_HARDLOCKUP_DETECTOR void touch_nmi_watchdog (void ) { -if (watchdog_enabled) { +if (watchdog_user_enabled) {unsigned cpu;for_each_present_cpu (cpu) {@@ -347,7 +347,7 @@ static void watchdog_enable(unsigned int cpu)hrtimer_init (hrtimer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); hrtimer->function = watchdog_timer_fn; -if (!watchdog_enabled) { +if (!watchdog_user_enabled) {kthread_park (current);return ; }@@ -482,8 +482,8 @@ static void watchdog_enable_all_cpus(void) {unsigned int cpu; -if (watchdog_disabled) { - watchdog_disabled =0 ; +if (!watchdog_running) { + watchdog_running =1 ;for_each_online_cpu (cpu)kthread_unpark (per_cpu (softlockup_watchdog, cpu)); }@@ -493,8 +493,8 @@ static void watchdog_disable_all_cpus(void) {unsigned int cpu; -if (!watchdog_disabled) { - watchdog_disabled =1 ; +if (watchdog_running) { + watchdog_running =0 ;for_each_online_cpu (cpu)kthread_park (per_cpu (softlockup_watchdog, cpu)); }@@ -509,7 +509,7 @@ int proc_dowatchdog(struct ctl_table *table, int write, {int ret; -if (watchdog_disabled <0 ) +if (watchdog_running <0 )return -ENODEV ; ret =proc_dointvec_minmax (table, write, buffer, lenp, ppos);@@ -522,7 +522,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,* disabled. The 'watchdog_disabled' variable check in * watchdog_*_all_cpus() function takes care of this. */ -if (watchdog_enabled && watchdog_thresh) +if (watchdog_user_enabled && watchdog_thresh)watchdog_enable_all_cpus ();else watchdog_disable_all_cpus ();@@ -544,14 +544,14 @@ static struct smp_hotplug_thread watchdog_threads = {void __init lockup_detector_init (void ) {#ifdef CONFIG_NO_HZ_FULL - watchdog_enabled =0 ; - watchdog_disabled =1 ; + watchdog_user_enabled =0 ; + watchdog_running =0 ;pr_warning ("Disabled lockup detectors by default because of full dynticks\n" );pr_warning ("You can overwrite that with 'sysctl -w kernel.watchdog=1'\n" );#endif set_sample_period ();if (smpboot_register_percpu_thread (&watchdog_threads)) {pr_err ("Failed to create watchdog threads, disabled\n" ); - watchdog_disabled = -ENODEV ; + watchdog_running = -ENODEV ; } }Signature · 1 line
1.7.5.4
RFC PATCH 8/8 watchdog: Fix internal state with boot user disabled watchdog
In reply to Frederic WeisbeckerWhen the watchdog is disabled through the 'nmi_watchdog=0' boot parameter, the watchdog_running internal state isn't cleared. Hence further enablements through sysctl/procfs are ignored because the subsystem spuriously thinks it's already running.
Initialize it properly on boot.
--- kernel/watchdog.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/watchdog.c +2 -2
@@ -31,7 +31,7 @@int watchdog_user_enabled =1 ;int __read_mostly watchdog_thresh =10 ; -static int __read_mostly watchdog_running =1 ; +static int __read_mostly watchdog_running;static u64 __read_mostly sample_period; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);
@@ -545,10 +545,10 @@ void __init lockup_detector_init(void) {#ifdef CONFIG_NO_HZ_FULL watchdog_user_enabled =0 ; - watchdog_running =0 ;pr_warning ("Disabled lockup detectors by default because of full dynticks\n" );pr_warning ("You can overwrite that with 'sysctl -w kernel.watchdog=1'\n" );#endif + watchdog_running = watchdog_user_enabled;set_sample_period ();if (smpboot_register_percpu_thread (&watchdog_threads)) {pr_err ("Failed to create watchdog threads, disabled\n" );
Signature · 1 line
1.7.5.4
Re: [RFC PATCH 8/8] watchdog: Fix internal state with boot user disabled watchdog
Quoted 7 lines · Frederic Weisbecker
When the watchdog is disabled through the 'nmi_watchdog=0' boot parameter, the
watchdog_runninginternal state isn't cleared. Hence further enablements through sysctl/procfs are ignored because the subsystem spuriously thinks it's already running.Initialize it properly on boot.
Looks fine to me. Can't think of a case where this breaks something.
Quoted 37 lines
Signed-off-by Frederic Weisbecker <[email protected]>Cc Don Zickus <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>--- kernel/watchdog.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)kernel/watchdog.c +2
-2@@ -31,7 +31,7 @@int watchdog_user_enabled =1 ;int __read_mostly watchdog_thresh =10 ; -static int __read_mostly watchdog_running =1 ; +static int __read_mostly watchdog_running;static u64 __read_mostly sample_period; static DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);@@ -545,10 +545,10 @@ void __init lockup_detector_init(void) {#ifdef CONFIG_NO_HZ_FULL watchdog_user_enabled =0 ; - watchdog_running =0 ;pr_warning ("Disabled lockup detectors by default because of full dynticks\n" );pr_warning ("You can overwrite that with 'sysctl -w kernel.watchdog=1'\n" );#endif + watchdog_running = watchdog_user_enabled;set_sample_period ();if (smpboot_register_percpu_thread (&watchdog_threads)) {pr_err ("Failed to create watchdog threads, disabled\n" );Signature · 1 line
1.7.5.4