lkml.org 
[lkml]   [2022]   [May]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH v2] sched: Queue task on wakelist in the same llc if the wakee cpu is idle
Date
On 31/05/22 14:55, Mel Gorman wrote:
> On Tue, May 31, 2022 at 12:50:49PM +0100, Valentin Schneider wrote:
>> >> With all that in mind, I'm curious whether your patch is functionaly close
>> >> to the below.
>> >>
>> >> ---
>> >> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> >> index 66c4e5922fe1..ffd43264722a 100644
>> >> --- a/kernel/sched/core.c
>> >> +++ b/kernel/sched/core.c
>> >> @@ -3836,7 +3836,7 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags)
>> >> * the soon-to-be-idle CPU as the current CPU is likely busy.
>> >> * nr_running is checked to avoid unnecessary task stacking.
>> >> */
>> >> - if ((wake_flags & WF_ON_CPU) && cpu_rq(cpu)->nr_running <= 1)
>> >> + if (cpu_rq(cpu)->nr_running <= 1)
>> >> return true;
>> >>
>> >> return false;
>> >
>> > It's a little different. This may bring extra IPIs when nr_running == 1
>> > and the current task on wakee cpu is not the target wakeup task (i.e.,
>> > rq->curr == another_task && rq->curr != p). Then this another_task may
>> > be disturbed by IPI which is not expected. So IMO the promise by
>> > WF_ON_CPU is necessary.
>>
>> You're right, actually taking a second look at that WF_ON_CPU path,
>> shouldn't the existing condition be:
>>
>> if ((wake_flags & WF_ON_CPU) && !cpu_rq(cpu)->nr_running)
>>
>> ? Per the p->on_rq and p->on_cpu ordering, if we have WF_ON_CPU here then
>> we must have !p->on_rq, so the deactivate has happened, thus the task
>> being alone on the rq implies nr_running==0.
>>
>> @Mel, do you remember why you went for <=1 here? I couldn't find any clues
>> on the original posting.
>>
>
> I don't recall exactly why I went with <= 1 there but I may not have
> considered the memory ordering of on_rq and nr_running and the comment
> above it is literally what I was thinking at the time. I think you're
> right and that check can be !cpu_rq(cpu)->nr_running.
>

Thanks!

So I'm thinking we could first make that into

if ((wake_flags & WF_ON_CPU) && !cpu_rq(cpu)->nr_running)

Then building on this, we can generalize using the wakelist to any remote
idle CPU (which on paper isn't as much as a clear win as just WF_ON_CPU,
depending on how deeply idle the CPU is...)

We need the cpu != this_cpu check, as that's currently served by the
WF_ON_CPU check (AFAIU we can only observe p->on_cpu in there for remote
tasks).

---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 66c4e5922fe1..60038743f2f1 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3830,13 +3830,20 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags)
if (!cpus_share_cache(smp_processor_id(), cpu))
return true;

+ if (cpu == smp_processor_id())
+ return false;
+
/*
* If the task is descheduling and the only running task on the
* CPU then use the wakelist to offload the task activation to
* the soon-to-be-idle CPU as the current CPU is likely busy.
* nr_running is checked to avoid unnecessary task stacking.
+ *
+ * Note that we can only get here with (wakee) p->on_rq=0,
+ * p->on_cpu can be whatever, we've done the dequeue, so
+ * the wakee has been accounted out of ->nr_running
*/
- if ((wake_flags & WF_ON_CPU) && cpu_rq(cpu)->nr_running <= 1)
+ if (!cpu_rq(cpu)->nr_running)
return true;

return false;
\
 
 \ /
  Last update: 2022-05-31 17:58    [W:0.198 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site