Skip to content

Commit 907c548

Browse files
Vikram Mulukutlapundiramit
authored andcommitted
sched: walt: Correct WALT window size initialization
It is preferable that WALT window rollover occurs just before a tick, since the tick is an opportune moment to record a complete window's statistics, as well as report those stats to the cpu frequency governor. When CONFIG_HZ results in a TICK_NSEC that isn't a integral number, this requirement may be violated. Account for this by reducing the WALT window size to the nearest multiple of TICK_NSEC. Commit d368c6f ("sched: walt: fix window misalignment when HZ=300") attempted to do this but WALT isn't using MIN_SCHED_RAVG_WINDOW as the window size and the patch was doing nothing. Also, change the type of 'walt_disabled' to bool and warn if an invalid window size causes WALT to be disabled. Change-Id: Ie3dcfc21a3df4408254ca1165a355bbe391ed5c7 Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
1 parent 2b022c3 commit 907c548

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

include/trace/events/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ TRACE_EVENT(sched_contrib_scale_f,
642642
extern unsigned int sysctl_sched_use_walt_cpu_util;
643643
extern unsigned int sysctl_sched_use_walt_task_util;
644644
extern unsigned int walt_ravg_window;
645-
extern unsigned int walt_disabled;
645+
extern bool walt_disabled;
646646
#endif
647647

648648
/*

kernel/sched/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ static inline unsigned long capacity_orig_of(int cpu)
15601560

15611561
extern unsigned int sysctl_sched_use_walt_cpu_util;
15621562
extern unsigned int walt_ravg_window;
1563-
extern unsigned int walt_disabled;
1563+
extern bool walt_disabled;
15641564

15651565
/*
15661566
* cpu_util returns the amount of capacity of a CPU that is used by CFS

kernel/sched/walt.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,17 @@ static __read_mostly unsigned int walt_io_is_busy = 0;
4141

4242
unsigned int sysctl_sched_walt_init_task_load_pct = 15;
4343

44-
/* 1 -> use PELT based load stats, 0 -> use window-based load stats */
45-
unsigned int __read_mostly walt_disabled = 0;
44+
/* true -> use PELT based load stats, false -> use window-based load stats */
45+
bool __read_mostly walt_disabled = false;
4646

47-
/* Window size (in ns) */
48-
__read_mostly unsigned int walt_ravg_window = 20000000;
49-
50-
/* Min window size (in ns) = 10ms */
51-
#ifdef CONFIG_HZ_300
5247
/*
53-
* Tick interval becomes to 3333333 due to
54-
* rounding error when HZ=300.
48+
* Window size (in ns). Adjust for the tick size so that the window
49+
* rollover occurs just before the tick boundary.
5550
*/
56-
#define MIN_SCHED_RAVG_WINDOW (3333333 * 6)
57-
#else
58-
#define MIN_SCHED_RAVG_WINDOW 10000000
59-
#endif
60-
61-
/* Max window size (in ns) = 1s */
62-
#define MAX_SCHED_RAVG_WINDOW 1000000000
51+
__read_mostly unsigned int walt_ravg_window =
52+
(20000000 / TICK_NSEC) * TICK_NSEC;
53+
#define MIN_SCHED_RAVG_WINDOW ((10000000 / TICK_NSEC) * TICK_NSEC)
54+
#define MAX_SCHED_RAVG_WINDOW ((1000000000 / TICK_NSEC) * TICK_NSEC)
6355

6456
static unsigned int sync_cpu;
6557
static ktime_t ktime_last;
@@ -180,10 +172,28 @@ static int exiting_task(struct task_struct *p)
180172

181173
static int __init set_walt_ravg_window(char *str)
182174
{
175+
unsigned int adj_window;
176+
bool no_walt = walt_disabled;
177+
183178
get_option(&str, &walt_ravg_window);
184179

185-
walt_disabled = (walt_ravg_window < MIN_SCHED_RAVG_WINDOW ||
186-
walt_ravg_window > MAX_SCHED_RAVG_WINDOW);
180+
/* Adjust for CONFIG_HZ */
181+
adj_window = (walt_ravg_window / TICK_NSEC) * TICK_NSEC;
182+
183+
/* Warn if we're a bit too far away from the expected window size */
184+
WARN(adj_window < walt_ravg_window - NSEC_PER_MSEC,
185+
"tick-adjusted window size %u, original was %u\n", adj_window,
186+
walt_ravg_window);
187+
188+
walt_ravg_window = adj_window;
189+
190+
walt_disabled = walt_disabled ||
191+
(walt_ravg_window < MIN_SCHED_RAVG_WINDOW ||
192+
walt_ravg_window > MAX_SCHED_RAVG_WINDOW);
193+
194+
WARN(!no_walt && walt_disabled,
195+
"invalid window size, disabling WALT\n");
196+
187197
return 0;
188198
}
189199

kernel/sched/walt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ static inline u64 walt_ktime_clock(void) { return 0; }
5959

6060
#endif /* CONFIG_SCHED_WALT */
6161

62-
extern unsigned int walt_disabled;
62+
extern bool walt_disabled;
6363

6464
#endif

0 commit comments

Comments
 (0)