sched/fair: Fix misuse of available_idle_cpu()
PATCH 1/1 sched/fair: Fix misuse of available_idle_cpu()
The function available_idle_cpu() was introduced to distinguish between the code paths that cares if the vCPU is preempted and the ones don't care. In general, available_idle_cpu() is used in selecting cpus for immediate use, e.g. ttwu. While idle_cpu() is used in the paths that only cares about the cpu is idle or not, and __update_idle_core() is one of them.
Use idle_cpu() instead in the idle path to make has_idle_core a better hint.
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -6302,7 +6302,7 @@ void __update_idle_core(struct rq *rq)if (cpu == core)continue ; -if (!available_idle_cpu (cpu)) +if (!idle_cpu (cpu)) goto unlock; }
Signature · 1 line
2.37.3
Quoted 7 lines · Abel Wu
The function
available_idle_cpu()was introduced to distinguish between the code paths that cares if the vCPU is preempted and the ones don't care. In general,available_idle_cpu()is used in selecting cpus for immediate use, e.g. ttwu. Whileidle_cpu()is used in the paths that only cares about the cpu is idle or not, and__update_idle_core()is one of them.
Quoted 5 lines
Use
idle_cpu()instead in the idle path to makehas_idle_corea better hint.Fixes 943d355d7fee (sched/core: Distinguish between idle_cpu() calls based on desired effect, introduce available_idle_cpu())Signed-off-by Abel Wu <[email protected]>
Seems fair. As vCPU preemption is specific to virtualisation, it is very unlikely that SMT is exposed to the guest so the impact of the patch is minimal but I still think it's right so;
Signature · 2 lines
Mel Gorman SUSE Labs
Peter Zijlstra
maintainerQuoted 8 lines · Mel Gorman
Quoted 7 lines · Abel Wu
The function
available_idle_cpu()was introduced to distinguish between the code paths that cares if the vCPU is preempted and the ones don't care. In general,available_idle_cpu()is used in selecting cpus for immediate use, e.g. ttwu. Whileidle_cpu()is used in the paths that only cares about the cpu is idle or not, and__update_idle_core()is one of them.
Quoted 8 lines
Quoted 5 lines
Use
idle_cpu()instead in the idle path to makehas_idle_corea better hint.Fixes 943d355d7fee (sched/core: Distinguish between idle_cpu() calls based on desired effect, introduce available_idle_cpu())Signed-off-by Abel Wu <[email protected]>Seems fair. As vCPU preemption is specific to virtualisation, it is very unlikely that SMT is exposed to the guest so the impact of the patch is
Right; only pinned guests typically expose such topology information (anything else would be quite broken).
Quoted 1 line
minimal but I still think it's right so;
I'm not convinced; all of select_idle_sibling() seems to use available_idle_cpu(), and that's the only consumer of __update_idle_core(), so in that respect the current state makes sense.
Quoted 18 lines · Peter Zijlstra
Quoted 8 lines · Mel Gorman
Quoted 7 lines · Abel Wu
The function
available_idle_cpu()was introduced to distinguish between the code paths that cares if the vCPU is preempted and the ones don't care. In general,available_idle_cpu()is used in selecting cpus for immediate use, e.g. ttwu. Whileidle_cpu()is used in the paths that only cares about the cpu is idle or not, and__update_idle_core()is one of them.Quoted 8 lines
Quoted 5 lines
Use
idle_cpu()instead in the idle path to makehas_idle_corea better hint.Fixes 943d355d7fee (sched/core: Distinguish between idle_cpu() calls based on desired effect, introduce available_idle_cpu())Signed-off-by Abel Wu <[email protected]>Seems fair. As vCPU preemption is specific to virtualisation, it is very unlikely that SMT is exposed to the guest so the impact of the patch is
Quoted 8 lines
Right; only pinned guests typically expose such topology information (anything else would be quite broken).
Quoted 1 line
minimal but I still think it's right so;
I'm not convinced; all of
select_idle_sibling()seems to useavailable_idle_cpu(), and that's the only consumer of__update_idle_core(), so in that respect the current state makes sense.
Hi Peter, Mel, thanks for your reviewing!
My thought was that the preempted core can become active again before select_idle_sibling() is called, so using available_idle_cpu() in __update_idle_core() can potentially lose the opportunity to kick an idle core running. While the downside of using idle_cpu() is that a full scan can be triggered irrespective of non-preempted cores exist, but even available_idle_cpu() can not make sure of that either.
BTW, I am also confused with select_idle_core() in which all the cpus of a core need to be non-preempted before the core can be taken as an idle core. IMHO, it might be enough that at least one cpu of an idle core is non-preempted and allowed by task's taskset.
Thanks & BR,
Abel
Ping :)
Quoted 13 lines · Abel Wu
Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Mel Gorman
Quoted 10 lines · Abel Wu
The function
available_idle_cpu()was introduced to distinguish between the code paths that cares if the vCPU is preempted and the ones don't care. In general,available_idle_cpu()is used in selecting cpus for immediate use, e.g. ttwu. Whileidle_cpu()is used in the paths that only cares about the cpu is idle or not, and__update_idle_core()is one of them.Use
idle_cpu()instead in the idle path to makehas_idle_corea better hint.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Fixes 943d355d7fee (sched/core: Distinguish between idle_cpu() calls based on desired effect, introduce available_idle_cpu())Signed-off-by Abel Wu <[email protected]>Seems fair. As vCPU preemption is specific to virtualisation, it is very unlikely that SMT is exposed to the guest so the impact of the patch is
Right; only pinned guests typically expose such topology information (anything else would be quite broken).
Yes, and it is common in our ECS servers to use pinned guests.
Quoted 20 lines
Quoted 6 lines
Quoted 2 lines
minimal but I still think it's right so;
I'm not convinced; all of
select_idle_sibling()seems to useavailable_idle_cpu(), and that's the only consumer of__update_idle_core(), so in that respect the current state makes sense.Hi Peter, Mel, thanks for your reviewing!
My thought was that the preempted core can become active again before
select_idle_sibling()is called, so usingavailable_idle_cpu()in__update_idle_core()can potentially lose the opportunity to kick an idle core running. While the downside of usingidle_cpu()is that a full scan can be triggered irrespective of non-preempted cores exist, but evenavailable_idle_cpu()can not make sure of that either.BTW, I am also confused with
select_idle_core()in which all the cpus of a core need to be non-preempted before the core can be taken as an idle core. IMHO, it might be enough that at least one cpu of an idle core is non-preempted and allowed by task's taskset.