Messages in this thread Patch in this message | | | From | Andrei Vagin <> | Date | Wed, 26 Oct 2022 23:51:18 -0700 | Subject | Re: [PATCH 3/5] sched: add a few helpers to wake up tasks on the current cpu |
| |
On Thu, Oct 20, 2022 at 5:44 PM Andrei Vagin <avagin@gmail.com> wrote: > > On Thu, Oct 20, 2022 at 04:15:04PM +0200, Peter Zijlstra wrote: > > On Wed, Oct 19, 2022 at 06:10:46PM -0700, Andrei Vagin wrote: > > > Add complete_on_current_cpu, wake_up_poll_on_current_cpu helpers to wake > > > up processes on the current CPU. > > > > There is an astounding lack of *why* in this changelog. > > I use them in the next patch to handle seccomp user notify requests > faster. > > The seccomp notify mechanism allows less privileged processes to offload > specific syscalls to more privileged processes. In many cases, the > workflow is fully synchronous. It means a target process triggers a > system call, the kernel stops it and wakes up a supervisor process that > handles the system call and returns controls back to the target process. > In this context, "synchronous" means that only one process is running > and another one is waiting. > > New helpers advices the scheduler to move the wakee to the current CPU. > For synchronous workflows like described above, these helpers makes > context switches a few times faster.
Peter,
I've found that I don't understand why WF_SYNC doesn't work in this case. The test from the last patch shows performance improvements in the case of WF_CURRENT_CPU, but WF_SYNC doesn't make any difference. I looked at the code and found that select_task_rq_fair calls select_idle_sibling, but it doesn't take into account the sync flag.
Does it make sense to do something like this:
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 4ebe7222664c..c29f758ccfe3 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7249,7 +7249,8 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags) new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag); } else if (wake_flags & WF_TTWU) { /* XXX always ? */ /* Fast path */ - new_cpu = select_idle_sibling(p, prev_cpu, new_cpu); + if (!(sync && cpu == new_cpu && this_rq()->nr_running == 1)) + new_cpu = select_idle_sibling(p, prev_cpu, new_cpu); } rcu_read_unlock();
With this patch, the test shows the same numbers for WF_CURRENT_CPU and WF_SYNC.
Thanks, Andrei
| |