From 549ffdbf7a59b0cbbfadde8847fb68c56211cfc6 Mon Sep 17 00:00:00 2001 From: Shaleen Agrawal Date: Thu, 5 May 2022 18:34:17 -0700 Subject: [PATCH] Revert "sched: walt: Remove finding historical runtimes in pred" This reverts commit 5c435ea559e452a09484fc20b65c3e128a77d8ab. Change-Id: Iabbe633fed376b0ca3bfb5dad78ce96f512f367c Signed-off-by: Shaleen Agrawal --- include/linux/sched/walt.h | 1 + kernel/sched/walt/trace.h | 9 ++++++++- kernel/sched/walt/walt.c | 29 +++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/linux/sched/walt.h b/include/linux/sched/walt.h index 0bf24642e528..9bb6ceada1a7 100644 --- a/include/linux/sched/walt.h +++ b/include/linux/sched/walt.h @@ -97,6 +97,7 @@ struct walt_task_struct { u32 sum, demand; u32 coloc_demand; u32 sum_history[RAVG_HIST_SIZE]; + u16 sum_history_util[RAVG_HIST_SIZE]; u32 curr_window_cpu[WALT_NR_CPUS]; u32 prev_window_cpu[WALT_NR_CPUS]; u32 curr_window, prev_window; diff --git a/kernel/sched/walt/trace.h b/kernel/sched/walt/trace.h index 70de6d14d1bc..0bfd17eea7fc 100644 --- a/kernel/sched/walt/trace.h +++ b/kernel/sched/walt/trace.h @@ -84,6 +84,7 @@ TRACE_EVENT(sched_update_history, __field(unsigned int, coloc_demand) __field(unsigned int, pred_demand_scaled) __array(u32, hist, RAVG_HIST_SIZE) + __array(u16, hist_util, RAVG_HIST_SIZE) __field(unsigned int, nr_big_tasks) __field(int, cpu) ), @@ -99,11 +100,13 @@ TRACE_EVENT(sched_update_history, __entry->pred_demand_scaled = wts->pred_demand_scaled; memcpy(__entry->hist, wts->sum_history, RAVG_HIST_SIZE * sizeof(u32)); + memcpy(__entry->hist_util, wts->sum_history_util, + RAVG_HIST_SIZE * sizeof(u16)); __entry->nr_big_tasks = wrq->walt_stats.nr_big_tasks; __entry->cpu = rq->cpu; ), - TP_printk("%d (%s): runtime %u samples %d event %s demand %u (hist: %u %u %u %u %u %u %u %u) coloc_demand %u pred_demand_scaled %u cpu %d nr_big %u", + TP_printk("%d (%s): runtime %u samples %d event %s demand %u (hist: %u %u %u %u %u %u %u %u) (hist_util: %u %u %u %u %u %u %u %u) coloc_demand %u pred_demand_scaled %u cpu %d nr_big %u", __entry->pid, __entry->comm, __entry->runtime, __entry->samples, task_event_names[__entry->evt], @@ -112,6 +115,10 @@ TRACE_EVENT(sched_update_history, __entry->hist[2], __entry->hist[3], __entry->hist[4], __entry->hist[5], __entry->hist[6], __entry->hist[7], + __entry->hist_util[0], __entry->hist_util[1], + __entry->hist_util[2], __entry->hist_util[3], + __entry->hist_util[4], __entry->hist_util[5], + __entry->hist_util[6], __entry->hist_util[7], __entry->coloc_demand, __entry->pred_demand_scaled, __entry->cpu, __entry->nr_big_tasks) ); diff --git a/kernel/sched/walt/walt.c b/kernel/sched/walt/walt.c index d138ddc8e61d..1a7aa6fa6701 100644 --- a/kernel/sched/walt/walt.c +++ b/kernel/sched/walt/walt.c @@ -1185,7 +1185,9 @@ static inline int busy_to_bucket(u16 normalized_rt) * A new predicted busy time is returned for task @p based on @runtime * passed in. The function searches through buckets that represent busy * time equal to or bigger than @runtime and attempts to find the bucket - * to use for prediction. Once found, it returns the midpoint of that bucket. + * to use for prediction. Once found, it searches through historical busy + * time and returns the latest that falls into the bucket. If no such busy + * time exists, it returns the medium of that bucket. */ static u32 get_pred_busy(struct task_struct *p, int start, u16 runtime_scaled, u16 bucket_bitmask) @@ -1195,6 +1197,8 @@ static u32 get_pred_busy(struct task_struct *p, int first = NUM_BUSY_BUCKETS, final = NUM_BUSY_BUCKETS; u16 ret = runtime_scaled; u16 next_mask = bucket_bitmask >> start; + u16 *hist_util = wts->sum_history_util; + int i; /* skip prediction for new tasks due to lack of history */ if (unlikely(is_new_task(p))) @@ -1221,11 +1225,24 @@ static u32 get_pred_busy(struct task_struct *p, } dmax = (final + 1) << (SCHED_CAPACITY_SHIFT - NUM_BUSY_BUCKETS_SHIFT); + /* + * search through runtime history and return first runtime that falls + * into the range of predicted bucket. + */ + for (i = 0; i < RAVG_HIST_SIZE; i++) { + if (hist_util[i] >= dmin && hist_util[i] < dmax) { + ret = hist_util[i]; + break; + } + } + /* no historical runtime within bucket found, use average of the bin */ + if (ret < dmin) + ret = (u16) (((u32)dmin + dmax) / 2); /* * when updating in middle of a window, runtime could be higher * than all recorded history. Always predict at least runtime. */ - ret = max(runtime_scaled, (u16) (((u32)dmin + dmax) / 2)); + ret = max(runtime_scaled, ret); out: trace_sched_update_pred_demand(p, runtime_scaled, ret, start, first, final, wts); @@ -1896,19 +1913,23 @@ 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]; + u16 *hist_util = &wts->sum_history_util[0]; int i; u32 max = 0, avg, demand; u64 sum = 0; - u16 demand_scaled, pred_demand_scaled; + u16 demand_scaled, pred_demand_scaled, runtime_scaled; + struct walt_rq *wrq = (struct walt_rq *) rq->android_vendor_data1; /* Ignore windows where task had no activity */ if (!runtime || is_idle_task(p) || !samples) goto done; + runtime_scaled = scale_time_to_util(runtime); /* Push new 'runtime' value onto stack */ for (; samples > 0; samples--) { hist[wts->cidx] = runtime; + hist_util[wts->cidx] = runtime_scaled; wts->cidx = ++(wts->cidx) & RAVG_HIST_MASK; } @@ -1931,7 +1952,7 @@ static void update_history(struct rq *rq, struct task_struct *p, else demand = max(avg, runtime); } - pred_demand_scaled = predict_and_update_buckets(p, scale_time_to_util(runtime)); + pred_demand_scaled = predict_and_update_buckets(p, runtime_scaled); demand_scaled = scale_time_to_util(demand); /*