[PATCH 0/7] timers/nohz: Fixes and cleanups v2
From: Frederic Weisbecker
Date: Mon Feb 20 2023 - 07:41:44 EST
Try to (partially) fix the issue reported in https://lore.kernel.org/lkml/20230128020051.2328465-1-liaoyu15@xxxxxxxxxx/
Changes since v1:
* Fix compute_delta left unused (thanks Hillf)
* Pass directly struct tick_sched to get_cpu_sleep_time_us()
* Add Peterz ack
* Remove selftests with wrong assertions
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
timers/core
HEAD: 0b86fc6ed10742ec8e54cd4d495c1ce9d4c1b4e0
Thanks,
Frederic
---
Frederic Weisbecker (7):
timers/nohz: Restructure and reshuffle struct tick_sched
timers/nohz: Only ever update sleeptime from idle exit
timers/nohz: Protect idle/iowait sleep time under seqcount
timers/nohz: Add a comment about broken iowait counter update race
timers/nohz: Remove middle-function __tick_nohz_idle_stop_tick()
MAINTAINERS: Remove stale email address
selftests/proc: Remove idle time monotonicity assertions
MAINTAINERS | 2 +-
kernel/time/tick-sched.c | 135 ++++++++++++-------------
kernel/time/tick-sched.h | 67 +++++++-----
tools/testing/selftests/proc/.gitignore | 2 -
tools/testing/selftests/proc/Makefile | 2 -
tools/testing/selftests/proc/proc-uptime-001.c | 45 ---------
tools/testing/selftests/proc/proc-uptime-002.c | 79 ---------------
tools/testing/selftests/proc/proc-uptime.h | 60 -----------
8 files changed, 106 insertions(+), 286 deletions(-)
---
git range-diff since v1
1: 899f01a80e5b ! 1: 0e7aede86812 timers/nohz: Restructure and reshuffle struct tick_sched
@@ Commit message
@last_jiffies and @idle_expires.
Reported-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
+ Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Hillf Danton <hdanton@xxxxxxxx>
Cc: Yu Liao <liaoyu15@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Wei Li <liwei391@xxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
- Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
## kernel/time/tick-sched.h ##
2: 4ea8a8e98eb0 ! 2: 8e8a18cee3d5 timers/nohz: Only ever update sleeptime from idle exit
@@ Commit message
reader VS writer races to handle. A subsequent patch will fix one.
Reported-by: Yu Liao <liaoyu15@xxxxxxxxxx>
+ Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Hillf Danton <hdanton@xxxxxxxx>
Cc: Yu Liao <liaoyu15@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
@@ Commit message
Cc: Wei Li <liwei391@xxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
- Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
## kernel/time/tick-sched.c ##
@@ kernel/time/tick-sched.c: static void tick_nohz_start_idle(struct tick_sched *ts
sched_clock_idle_sleep_event();
}
-+static u64 get_cpu_sleep_time_us(int cpu, ktime_t *sleeptime,
++static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime,
+ bool compute_delta, u64 *last_update_time)
+{
-+ struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
+ ktime_t now, idle;
+
+ if (!tick_nohz_active)
@@ kernel/time/tick-sched.c: static void tick_nohz_start_idle(struct tick_sched *ts
+ if (last_update_time)
+ *last_update_time = ktime_to_us(now);
+
-+ if (ts->idle_active && !nr_iowait_cpu(cpu)) {
++ if (ts->idle_active && compute_delta) {
+ ktime_t delta = ktime_sub(now, ts->idle_entrytime);
+
+ idle = ktime_add(*sleeptime, delta);
@@ kernel/time/tick-sched.c: static void tick_nohz_start_idle(struct tick_sched *ts
-
- return ktime_to_us(idle);
-+ return get_cpu_sleep_time_us(cpu, &ts->idle_sleeptime,
++ return get_cpu_sleep_time_us(ts, &ts->idle_sleeptime,
+ !nr_iowait_cpu(cpu), last_update_time);
}
EXPORT_SYMBOL_GPL(get_cpu_idle_time_us);
@@ kernel/time/tick-sched.c: EXPORT_SYMBOL_GPL(get_cpu_idle_time_us);
- }
- return ktime_to_us(iowait);
-+ return get_cpu_sleep_time_us(cpu, &ts->iowait_sleeptime,
++ return get_cpu_sleep_time_us(ts, &ts->iowait_sleeptime,
+ nr_iowait_cpu(cpu), last_update_time);
}
EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us);
3: 131b09a345c6 ! 3: 61b56e1d6c33 timers/nohz: Protect idle/iowait sleep time under seqcount
@@ Commit message
can hardly be fixed.
Reported-by: Yu Liao <liaoyu15@xxxxxxxxxx>
+ Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Hillf Danton <hdanton@xxxxxxxx>
Cc: Yu Liao <liaoyu15@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
@@ Commit message
Cc: Wei Li <liwei391@xxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
- Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
## kernel/time/tick-sched.c ##
@@ kernel/time/tick-sched.c: static void tick_nohz_stop_idle(struct tick_sched *ts,
sched_clock_idle_sleep_event();
}
-@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(int cpu, ktime_t *sleeptime,
+@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime,
+ bool compute_delta, u64 *last_update_time)
{
- struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
ktime_t now, idle;
+ unsigned int seq;
if (!tick_nohz_active)
return -1;
-@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(int cpu, ktime_t *sleeptime,
+@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime,
if (last_update_time)
*last_update_time = ktime_to_us(now);
-- if (ts->idle_active && !nr_iowait_cpu(cpu)) {
+- if (ts->idle_active && compute_delta) {
- ktime_t delta = ktime_sub(now, ts->idle_entrytime);
+ do {
+ seq = read_seqcount_begin(&ts->idle_sleeptime_seq);
@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(int cpu, ktime_t *sle
- } else {
- idle = *sleeptime;
- }
-+ if (ts->idle_active && !nr_iowait_cpu(cpu)) {
++ if (ts->idle_active && compute_delta) {
+ ktime_t delta = ktime_sub(now, ts->idle_entrytime);
+
+ idle = ktime_add(*sleeptime, delta);
4: 4ff478886c2c ! 4: 9147cd64f3ba timers/nohz: Add a comment about broken iowait counter update race
@@ Commit message
This is unfortunately hardly fixable. Just add a comment about that
condition.
+ Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Hillf Danton <hdanton@xxxxxxxx>
Cc: Yu Liao <liaoyu15@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
@@ Commit message
Cc: Wei Li <liwei391@xxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
- Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
## kernel/time/tick-sched.c ##
-@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(int cpu, ktime_t *sleeptime,
+@@ kernel/time/tick-sched.c: static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime,
* counters if NULL.
*
* Return the cumulative idle time (since boot) for a given
5: 6eb31238e057 ! 5: 4863214a905f timers/nohz: Remove middle-function __tick_nohz_idle_stop_tick()
@@ Commit message
tick_nohz_idle_stop_tick() and its implementation. Remove that
unnecessary step.
+ Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Hillf Danton <hdanton@xxxxxxxx>
Cc: Yu Liao <liaoyu15@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
@@ Commit message
Cc: Wei Li <liwei391@xxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
- Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
## kernel/time/tick-sched.c ##
6: d1dc3edc39a7 ! 6: 170828be3e96 MAINTAINERS: Remove stale email address
@@ Metadata
## Commit message ##
MAINTAINERS: Remove stale email address
+ Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Hillf Danton <hdanton@xxxxxxxx>
Cc: Yu Liao <liaoyu15@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
@@ Commit message
Cc: Wei Li <liwei391@xxxxxxxxxx>
Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
- Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
## MAINTAINERS ##
-: ------------ > 7: 0b86fc6ed107 selftests/proc: Remove idle time monotonicity assertions