linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] timers: Small fixes
@ 2022-04-05 19:17 Anna-Maria Behnsen
  2022-04-05 19:17 ` [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu Anna-Maria Behnsen
  2022-04-05 19:17 ` [PATCH 2/2] timers: Fix warning in __run_timers() Anna-Maria Behnsen
  0 siblings, 2 replies; 7+ messages in thread
From: Anna-Maria Behnsen @ 2022-04-05 19:17 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner, Peter Zijlstra, Frederic Weisbecker

This short queue fixes a missing initialization and a warning in timer
code.

Thanks,
	Anna-Maria


Anna-Maria Behnsen (2):
  timers: Initialize base::next_expiry_recalc during prepare cpu
  timers: Fix warning in __run_timers()

 kernel/time/timer.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu
  2022-04-05 19:17 [PATCH 0/2] timers: Small fixes Anna-Maria Behnsen
@ 2022-04-05 19:17 ` Anna-Maria Behnsen
  2022-04-05 21:51   ` Frederic Weisbecker
  2022-04-09 20:22   ` [tip: timers/core] timers: Initialize base::next_expiry_recalc in timers_prepare_cpu() tip-bot2 for Anna-Maria Behnsen
  2022-04-05 19:17 ` [PATCH 2/2] timers: Fix warning in __run_timers() Anna-Maria Behnsen
  1 sibling, 2 replies; 7+ messages in thread
From: Anna-Maria Behnsen @ 2022-04-05 19:17 UTC (permalink / raw)
  To: linux-kernel; +Cc: Thomas Gleixner, Peter Zijlstra, Frederic Weisbecker

When base::next_expiry_recalc is not initialized to false during cpu
bringup in HOTPLUG_CPU and is accidently true and no timer is queued in the
meantime, the loop through the wheel to find __next_timer_interrupt() might
be done for nothing.

Therefore initialize base::next_expiry_recalc to false in
timers_prepare_cpu().

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
 kernel/time/timer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 85f1021ad459..4af98e77cd78 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1950,6 +1950,7 @@ int timers_prepare_cpu(unsigned int cpu)
 		base = per_cpu_ptr(&timer_bases[b], cpu);
 		base->clk = jiffies;
 		base->next_expiry = base->clk + NEXT_TIMER_MAX_DELTA;
+		base->next_expiry_recalc = false;
 		base->timers_pending = false;
 		base->is_idle = false;
 	}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] timers: Fix warning in __run_timers()
  2022-04-05 19:17 [PATCH 0/2] timers: Small fixes Anna-Maria Behnsen
  2022-04-05 19:17 ` [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu Anna-Maria Behnsen
@ 2022-04-05 19:17 ` Anna-Maria Behnsen
  2022-04-05 21:43   ` Frederic Weisbecker
  2022-04-09 20:22   ` [tip: timers/core] timers: Fix warning condition " tip-bot2 for Anna-Maria Behnsen
  1 sibling, 2 replies; 7+ messages in thread
From: Anna-Maria Behnsen @ 2022-04-05 19:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: Thomas Gleixner, Peter Zijlstra, Frederic Weisbecker, Johannes Berg

When the timer base is empty, base::next_expiry is set to base::clk +
NEXT_TIMER_MAX_DELTA and base::next_expiry_recalc is false. When no timer
is queued until jiffies reaches base::next_expiry value, the warning for
not finding any expired timer and base::next_expiry_recalc is false in
__run_timers() triggers.

To prevent triggering the warning in this valid scenario
base::timers_pending needs to be added to the warning condition.

Fixes: 31cd0e119d50 ("timers: Recalculate next timer interrupt only when necessary")
Reported-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
 kernel/time/timer.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 4af98e77cd78..204d6cd83d0e 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1722,11 +1722,14 @@ static inline void __run_timers(struct timer_base *base)
 	       time_after_eq(jiffies, base->next_expiry)) {
 		levels = collect_expired_timers(base, heads);
 		/*
-		 * The only possible reason for not finding any expired
-		 * timer at this clk is that all matching timers have been
-		 * dequeued.
+		 * The two possible reasons for not finding any expired
+		 * timer at this clk are that all matching timers have been
+		 * dequeued or no timer has been queued since
+		 * base::next_expiry was set to base::clk +
+		 * NEXT_TIMER_MAX_DELTA.
 		 */
-		WARN_ON_ONCE(!levels && !base->next_expiry_recalc);
+		WARN_ON_ONCE(!levels && !base->next_expiry_recalc
+			     && base->timers_pending);
 		base->clk++;
 		base->next_expiry = __next_timer_interrupt(base);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] timers: Fix warning in __run_timers()
  2022-04-05 19:17 ` [PATCH 2/2] timers: Fix warning in __run_timers() Anna-Maria Behnsen
@ 2022-04-05 21:43   ` Frederic Weisbecker
  2022-04-09 20:22   ` [tip: timers/core] timers: Fix warning condition " tip-bot2 for Anna-Maria Behnsen
  1 sibling, 0 replies; 7+ messages in thread
From: Frederic Weisbecker @ 2022-04-05 21:43 UTC (permalink / raw)
  To: Anna-Maria Behnsen
  Cc: linux-kernel, Thomas Gleixner, Peter Zijlstra, Johannes Berg

On Tue, Apr 05, 2022 at 09:17:32PM +0200, Anna-Maria Behnsen wrote:
> When the timer base is empty, base::next_expiry is set to base::clk +
> NEXT_TIMER_MAX_DELTA and base::next_expiry_recalc is false. When no timer
> is queued until jiffies reaches base::next_expiry value, the warning for
> not finding any expired timer and base::next_expiry_recalc is false in
> __run_timers() triggers.
> 
> To prevent triggering the warning in this valid scenario
> base::timers_pending needs to be added to the warning condition.
> 
> Fixes: 31cd0e119d50 ("timers: Recalculate next timer interrupt only when necessary")
> Reported-by: Johannes Berg <johannes@sipsolutions.net>
> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

Thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu
  2022-04-05 19:17 ` [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu Anna-Maria Behnsen
@ 2022-04-05 21:51   ` Frederic Weisbecker
  2022-04-09 20:22   ` [tip: timers/core] timers: Initialize base::next_expiry_recalc in timers_prepare_cpu() tip-bot2 for Anna-Maria Behnsen
  1 sibling, 0 replies; 7+ messages in thread
From: Frederic Weisbecker @ 2022-04-05 21:51 UTC (permalink / raw)
  To: Anna-Maria Behnsen; +Cc: linux-kernel, Thomas Gleixner, Peter Zijlstra

On Tue, Apr 05, 2022 at 09:17:31PM +0200, Anna-Maria Behnsen wrote:
> When base::next_expiry_recalc is not initialized to false during cpu
> bringup in HOTPLUG_CPU and is accidently true and no timer is queued in the
> meantime, the loop through the wheel to find __next_timer_interrupt() might
> be done for nothing.
> 
> Therefore initialize base::next_expiry_recalc to false in
> timers_prepare_cpu().
> 
> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: timers/core] timers: Initialize base::next_expiry_recalc in timers_prepare_cpu()
  2022-04-05 19:17 ` [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu Anna-Maria Behnsen
  2022-04-05 21:51   ` Frederic Weisbecker
@ 2022-04-09 20:22   ` tip-bot2 for Anna-Maria Behnsen
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Anna-Maria Behnsen @ 2022-04-09 20:22 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anna-Maria Behnsen, Thomas Gleixner, Frederic Weisbecker, x86,
	linux-kernel

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     2731aa7d65dbb31c6dad14347c37d522bb3bc7c6
Gitweb:        https://git.kernel.org/tip/2731aa7d65dbb31c6dad14347c37d522bb3bc7c6
Author:        Anna-Maria Behnsen <anna-maria@linutronix.de>
AuthorDate:    Tue, 05 Apr 2022 21:17:31 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Sat, 09 Apr 2022 22:19:39 +02:00

timers: Initialize base::next_expiry_recalc in timers_prepare_cpu()

When base::next_expiry_recalc is not initialized to false during cpu
bringup in HOTPLUG_CPU and is accidently true and no timer is queued in the
meantime, the loop through the wheel to find __next_timer_interrupt() might
be done for nothing.

Therefore initialize base::next_expiry_recalc to false in
timers_prepare_cpu().

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/r/20220405191732.7438-2-anna-maria@linutronix.de

---
 kernel/time/timer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 9dd2a39..204d6cd 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1953,6 +1953,7 @@ int timers_prepare_cpu(unsigned int cpu)
 		base = per_cpu_ptr(&timer_bases[b], cpu);
 		base->clk = jiffies;
 		base->next_expiry = base->clk + NEXT_TIMER_MAX_DELTA;
+		base->next_expiry_recalc = false;
 		base->timers_pending = false;
 		base->is_idle = false;
 	}

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [tip: timers/core] timers: Fix warning condition in __run_timers()
  2022-04-05 19:17 ` [PATCH 2/2] timers: Fix warning in __run_timers() Anna-Maria Behnsen
  2022-04-05 21:43   ` Frederic Weisbecker
@ 2022-04-09 20:22   ` tip-bot2 for Anna-Maria Behnsen
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Anna-Maria Behnsen @ 2022-04-09 20:22 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Johannes Berg, Anna-Maria Behnsen, Thomas Gleixner,
	Frederic Weisbecker, x86, linux-kernel

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     c54bc0fc84214b203f7a0ebfd1bd308ce2abe920
Gitweb:        https://git.kernel.org/tip/c54bc0fc84214b203f7a0ebfd1bd308ce2abe920
Author:        Anna-Maria Behnsen <anna-maria@linutronix.de>
AuthorDate:    Tue, 05 Apr 2022 21:17:32 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Sat, 09 Apr 2022 22:17:47 +02:00

timers: Fix warning condition in __run_timers()

When the timer base is empty, base::next_expiry is set to base::clk +
NEXT_TIMER_MAX_DELTA and base::next_expiry_recalc is false. When no timer
is queued until jiffies reaches base::next_expiry value, the warning for
not finding any expired timer and base::next_expiry_recalc is false in
__run_timers() triggers.

To prevent triggering the warning in this valid scenario
base::timers_pending needs to be added to the warning condition.

Fixes: 31cd0e119d50 ("timers: Recalculate next timer interrupt only when necessary")
Reported-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/r/20220405191732.7438-3-anna-maria@linutronix.de

---
 kernel/time/timer.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 85f1021..9dd2a39 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1722,11 +1722,14 @@ static inline void __run_timers(struct timer_base *base)
 	       time_after_eq(jiffies, base->next_expiry)) {
 		levels = collect_expired_timers(base, heads);
 		/*
-		 * The only possible reason for not finding any expired
-		 * timer at this clk is that all matching timers have been
-		 * dequeued.
+		 * The two possible reasons for not finding any expired
+		 * timer at this clk are that all matching timers have been
+		 * dequeued or no timer has been queued since
+		 * base::next_expiry was set to base::clk +
+		 * NEXT_TIMER_MAX_DELTA.
 		 */
-		WARN_ON_ONCE(!levels && !base->next_expiry_recalc);
+		WARN_ON_ONCE(!levels && !base->next_expiry_recalc
+			     && base->timers_pending);
 		base->clk++;
 		base->next_expiry = __next_timer_interrupt(base);
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-09 20:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 19:17 [PATCH 0/2] timers: Small fixes Anna-Maria Behnsen
2022-04-05 19:17 ` [PATCH 1/2] timers: Initialize base::next_expiry_recalc during prepare cpu Anna-Maria Behnsen
2022-04-05 21:51   ` Frederic Weisbecker
2022-04-09 20:22   ` [tip: timers/core] timers: Initialize base::next_expiry_recalc in timers_prepare_cpu() tip-bot2 for Anna-Maria Behnsen
2022-04-05 19:17 ` [PATCH 2/2] timers: Fix warning in __run_timers() Anna-Maria Behnsen
2022-04-05 21:43   ` Frederic Weisbecker
2022-04-09 20:22   ` [tip: timers/core] timers: Fix warning condition " tip-bot2 for Anna-Maria Behnsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).