From f499ceb734c1bef6ac7f150d9cbb787285ebee6d Mon Sep 17 00:00:00 2001 From: Shaleen Agrawal Date: Tue, 18 Jan 2022 11:00:13 -0800 Subject: [PATCH] sched: Simplify sliding window logic The sliding window logic in update_history is unnecessary complicated and involves moving each window entry into a new position. Instead, we can simply replace the older entries in place. Change-Id: I49a80184241393219f421421f07514e01b8a674e Signed-off-by: Shaleen Agrawal --- include/linux/sched/walt.h | 1 + kernel/sched/walt/walt.c | 22 +++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/linux/sched/walt.h b/include/linux/sched/walt.h index e7813c280140..ce8e5bcee7cf 100644 --- a/include/linux/sched/walt.h +++ b/include/linux/sched/walt.h @@ -119,6 +119,7 @@ struct walt_task_struct { u64 sum_exec_snapshot; u64 total_exec; int mvp_prio; + int cidx; }; #define wts_to_ts(wts) ({ \ diff --git a/kernel/sched/walt/walt.c b/kernel/sched/walt/walt.c index 59b49318212f..45e96ac17e00 100644 --- a/kernel/sched/walt/walt.c +++ b/kernel/sched/walt/walt.c @@ -1857,7 +1857,7 @@ static void update_history(struct rq *rq, struct task_struct *p, { struct walt_task_struct *wts = (struct walt_task_struct *) p->android_vendor_data1; u32 *hist = &wts->sum_history[0]; - int ridx, widx; + int i; u32 max = 0, avg, demand, pred_demand; u64 sum = 0; u16 demand_scaled, pred_demand_scaled; @@ -1868,20 +1868,15 @@ static void update_history(struct rq *rq, struct task_struct *p, goto done; /* Push new 'runtime' value onto stack */ - widx = sched_ravg_hist_size - 1; - ridx = widx - samples; - for (; ridx >= 0; --widx, --ridx) { - hist[widx] = hist[ridx]; - sum += hist[widx]; - if (hist[widx] > max) - max = hist[widx]; + for (; samples > 0; samples--) { + hist[wts->cidx] = runtime; + wts->cidx = ++(wts->cidx) % sched_ravg_hist_size; } - for (widx = 0; widx < samples && widx < sched_ravg_hist_size; widx++) { - hist[widx] = runtime; - sum += hist[widx]; - if (hist[widx] > max) - max = hist[widx]; + for (i = 0; i < sched_ravg_hist_size; i++) { + sum += hist[i]; + if (hist[i] > max) + max = hist[i]; } wts->sum = 0; @@ -2260,6 +2255,7 @@ static void init_new_task_load(struct task_struct *p) wts->sum_exec_snapshot = 0; wts->total_exec = 0; wts->mvp_prio = WALT_NOT_MVP; + wts->cidx = 0; __sched_fork_init(p); }