Merge pull request #595 from multics69/lavd-turbo-tuning

scx_lavd: improve  the autopilot mode
This commit is contained in:
Changwoo Min 2024-09-01 16:24:41 +09:00 committed by GitHub
commit f2122c4197
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 12 deletions

View File

@ -80,18 +80,17 @@ enum consts {
LAVD_PREEMPT_KICK_MARGIN = (1ULL * NSEC_PER_MSEC),
LAVD_PREEMPT_TICK_MARGIN = (100ULL * NSEC_PER_USEC),
LAVD_SYS_STAT_INTERVAL_NS = (25ULL * NSEC_PER_MSEC),
LAVD_SYS_STAT_INTERVAL_NS = (50ULL * NSEC_PER_MSEC),
LAVD_CC_PER_CORE_MAX_CTUIL = 500, /* maximum per-core CPU utilization */
LAVD_CC_PER_TURBO_CORE_MAX_CTUIL = 750, /* maximum per-core CPU utilization for a turbo core */
LAVD_CC_NR_ACTIVE_MIN = 1, /* num of mininum active cores */
LAVD_CC_NR_OVRFLW = 1, /* num of overflow cores */
LAVD_CC_CPU_PIN_INTERVAL = (3ULL * LAVD_TIME_ONE_SEC),
LAVD_CC_CPU_PIN_INTERVAL = (2ULL * LAVD_TIME_ONE_SEC),
LAVD_CC_CPU_PIN_INTERVAL_DIV = (LAVD_CC_CPU_PIN_INTERVAL /
LAVD_SYS_STAT_INTERVAL_NS),
LAVD_AP_LOW_UTIL = 50, /* powersave mode when cpu util <= 5% */
LAVD_AP_HIGH_UTIL = 300, /* balanced mode when 5% < cpu util <= 30%,
performance mode when cpu util > 30% */
LAVD_AP_HIGH_UTIL = 700, /* balanced mode when 10% < cpu util <= 40%,
performance mode when cpu util > 40% */
LAVD_CPDOM_MAX_NR = 32, /* maximum number of compute domain */
LAVD_CPDOM_MAX_DIST = 4, /* maximum distance from one compute domain to another */

View File

@ -207,6 +207,8 @@ private(LAVD) struct bpf_cpumask __kptr *active_cpumask; /* CPU mask for active
private(LAVD) struct bpf_cpumask __kptr *ovrflw_cpumask; /* CPU mask for overflow CPUs */
private(LAVD) struct bpf_cpumask cpdom_cpumask[LAVD_CPDOM_MAX_NR]; /* CPU mask for each compute domain */
static u64 LAVD_AP_LOW_UTIL;
/*
* CPU topology
*/
@ -1517,7 +1519,6 @@ static s32 pick_idle_cpu(struct task_struct *p, struct task_ctx *taskc,
* Pick an idle core among turbo boost-enabled CPUs with a matching
* core type.
*/
start_turbo_mask:
if (no_prefer_turbo_core || !turbo_cpumask)
goto start_llc_mask;
@ -1559,7 +1560,6 @@ start_tmask:
/*
* Pick a idle core among active CPUs.
*/
start_amask:
cpu_id = pick_idle_cpu_in(a_cpumask);
if (cpu_id >= 0) {
*is_idle = true;
@ -2331,6 +2331,12 @@ static int calc_cpuperf_target(struct sys_stat *stat_cur,
if (!stat_cur || !taskc || !cpuc)
return -EINVAL;
if (no_freq_scaling) {
cpuc->cpuperf_task = SCX_CPUPERF_ONE;
cpuc->cpuperf_avg = SCX_CPUPERF_ONE;
return 0;
}
/*
* We determine the clock frequency of a CPU using two factors: 1) the
* current CPU utilization (cpuc->util) and 2) the current task's
@ -2428,7 +2434,7 @@ void BPF_STRUCT_OPS(lavd_tick, struct task_struct *p_run)
* task continues to run.
*/
freq_out:
if (!no_freq_scaling && !preempted)
if (!preempted)
try_decrease_cpuperf_target(cpuc_run);
}
@ -2514,10 +2520,8 @@ void BPF_STRUCT_OPS(lavd_running, struct task_struct *p)
* urgently increases according to task's target but it decreases
* gradually according to EWMA of past performance targets.
*/
if (!no_freq_scaling) {
calc_cpuperf_target(stat_cur, taskc, cpuc);
try_increase_cpuperf_target(cpuc);
}
calc_cpuperf_target(stat_cur, taskc, cpuc);
try_increase_cpuperf_target(cpuc);
/*
* Update running task's information for preemption
@ -3167,6 +3171,24 @@ static s32 init_sys_stat(u64 now)
return 0;
}
static void init_autopilot_low_util(void)
{
if (nr_cpus_big < nr_cpus_onln) {
/*
* When there are little cores, we move up to the balanced mode
* if one little core is fully utilized.
*/
LAVD_AP_LOW_UTIL = 1000 / nr_cpus_onln;
}
else {
/*
* When there are only big cores, we move up to the balanced
* mode if two big cores are fully utilized.
*/
LAVD_AP_LOW_UTIL = (2 * 1000) / nr_cpus_onln;
}
}
s32 BPF_STRUCT_OPS_SLEEPABLE(lavd_init)
{
u64 now = bpf_ktime_get_ns();
@ -3204,6 +3226,11 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(lavd_init)
if (err)
return err;
/*
* Initialize the low cpu watermark for autopilot mode.
*/
init_autopilot_low_util();
/*
* Initilize the current logical clock and service time.
*/