From 1efc36b815769cb8c7dae1d53373b190c017f5d1 Mon Sep 17 00:00:00 2001 From: JianMin Liu Date: Wed, 4 Aug 2021 11:52:40 +0800 Subject: [PATCH] ANDROID: sched: add a helper function to change PELT half-life Add a new helper function and export it for vendor module to dynamically switch to an alternative half-life at runtime. Bug: 195474490 Signed-off-by: JianMin Liu Change-Id: Ife41997a032fe3384cfa126cbf7aee929c5c11cf --- kernel/sched/pelt.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index cd54fab42cf4..bbb0de2219f9 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -32,15 +32,16 @@ int pelt_load_avg_period = PELT32_LOAD_AVG_PERIOD; int pelt_load_avg_max = PELT32_LOAD_AVG_MAX; const u32 *pelt_runnable_avg_yN_inv = pelt32_runnable_avg_yN_inv; -static int __init set_pelt(char *str) +int get_pelt_halflife(void) { - int rc, num; + return pelt_load_avg_period; +} +EXPORT_SYMBOL_GPL(get_pelt_halflife); - rc = kstrtoint(str, 0, &num); - if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); - return 0; - } +static int __set_pelt_halflife(void *data) +{ + int rc = 0; + int num = *(int *)data; switch (num) { case PELT8_LOAD_AVG_PERIOD: @@ -56,10 +57,32 @@ static int __init set_pelt(char *str) pr_info("PELT half life is set to %dms\n", num); break; default: - pr_err("Default PELT half life is 32ms\n"); + rc = -EINVAL; + pr_err("Failed to set PELT half life to %dms, the current value is %dms\n", + num, pelt_load_avg_period); } - return 0; + return rc; +} + +int set_pelt_halflife(int num) +{ + return stop_machine(__set_pelt_halflife, &num, NULL); +} +EXPORT_SYMBOL_GPL(set_pelt_halflife); + +static int __init set_pelt(char *str) +{ + int rc, num; + + rc = kstrtoint(str, 0, &num); + if (rc) { + pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + return 0; + } + + __set_pelt_halflife(&num); + return rc; } early_param("pelt", set_pelt);