From f5c802e3d9895e00cbbe4706128cac31321dc0bc Mon Sep 17 00:00:00 2001 From: He Yujie Date: Tue, 30 Sep 2025 15:09:33 +0800 Subject: [PATCH] sched/dynamic_affinity: Calculate cpu capacity in real time when realtime tasks are running on this cpu hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICVGAJ -------------------------------- The task_rq selection of dynamic affinity use cpu capacity to determine select_cpus range. When realtime tasks are running on the cpu all the time, cfs tasks and the thread of softirq is suppressed, and the cpu capacity is not updated in time. As a result, the select_cpus range is always selected for preferred_cpus. then cfs task will never be able to run because realtime tasks has been running. Therefore, if realtime tasks is running during the task_rq selection of dynamic affinity, the cpu capacity should be calculated to solve such a problem. Fixes: 2a3bb3c0af29 ("sched: Adjust wakeup cpu range according CPU util dynamicly") Signed-off-by: He Yujie Signed-off-by: Liu Kai --- kernel/sched/fair.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 848d45f2bc49..173bcf208cee 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8267,6 +8267,19 @@ static inline unsigned long taskgroup_cpu_util(struct task_group *tg, return cpu_util(cpu); } +static unsigned long scale_rt_capacity(int cpu); + +static inline unsigned long calc_cpu_capacity(int cpu) +{ + unsigned long capacity; + + capacity = scale_rt_capacity(cpu); + if (!capacity) + capacity = 1; + + return capacity; +} + /* * set_task_select_cpus: select the cpu range for task * @p: the task whose available cpu range will to set @@ -8328,8 +8341,12 @@ static void set_task_select_cpus(struct task_struct *p, int *idlest_cpu, } util_avg_sum += taskgroup_cpu_util(tg, cpu); - tg_capacity += capacity_of(cpu); nr_cpus_valid++; + + if (cpu_rq(cpu)->rt.rt_nr_running) + tg_capacity += calc_cpu_capacity(cpu); + else + tg_capacity += capacity_of(cpu); } rcu_read_unlock(); -- Gitee