[v5,07/18] timers: Ease code in run_local_timers()

Message ID 20230301141744.16063-8-anna-maria@linutronix.de
State New
Headers
Series timer: Move from a push remote at enqueue to a pull at expiry model |

Commit Message

Anna-Maria Behnsen March 1, 2023, 2:17 p.m. UTC
  The logic for raising a softirq the way it is implemented right now, is
readable for two timer bases. When increasing numbers of timer bases, code
gets harder to read. With the introduction of the timer migration
hierarchy, there will be three timer bases.

Therefore ease the code. No functional change.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
v5: New patch to decrease patch size of follow up patches
---
 kernel/time/timer.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
  

Comments

Frederic Weisbecker April 12, 2023, 2:32 p.m. UTC | #1
On Wed, Mar 01, 2023 at 03:17:33PM +0100, Anna-Maria Behnsen wrote:
> The logic for raising a softirq the way it is implemented right now, is
> readable for two timer bases. When increasing numbers of timer bases, code
> gets harder to read. With the introduction of the timer migration
> hierarchy, there will be three timer bases.
> 
> Therefore ease the code. No functional change.
> 
> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>

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

Patch

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index d74d538e06a2..d3e1776b505b 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -2058,16 +2058,14 @@  static void run_local_timers(void)
 	struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
 
 	hrtimer_run_queues();
-	/* Raise the softirq only if required. */
-	if (time_before(jiffies, base->next_expiry)) {
-		if (!IS_ENABLED(CONFIG_NO_HZ_COMMON))
-			return;
-		/* CPU is awake, so check the deferrable base. */
-		base++;
-		if (time_before(jiffies, base->next_expiry))
+
+	for (int i = 0; i < NR_BASES; i++, base++) {
+		/* Raise the softirq only if required. */
+		if (time_after_eq(jiffies, base->next_expiry)) {
+			raise_softirq(TIMER_SOFTIRQ);
 			return;
+		}
 	}
-	raise_softirq(TIMER_SOFTIRQ);
 }
 
 /*