Re: [PATCH 3/6] sched: add a few helpers to wake up tasks on the current cpu

From: Bernd Schubert
Date: Wed Apr 26 2023 - 15:35:33 EST


On 4/26/23 20:52, Andrei Vagin wrote:
> On Wed, Apr 26, 2023 at 7:43 AM Bernd Schubert <bschubert@xxxxxxx> wrote:
>>
>>> Add complete_on_current_cpu, wake_up_poll_on_current_cpu helpers to wake
>>> up tasks on the current CPU.
>>
>>> These two helpers are useful when the task needs to make a synchronous context
>>> switch to another task. In this context, synchronous means it wakes up the
>>> target task and falls asleep right after that.
>>
>>> One example of such workloads is seccomp user notifies. This mechanism allows
>>> the supervisor process handles system calls on behalf of a target process.
>>> While the supervisor is handling an intercepted system call, the target process
>>> will be blocked in the kernel, waiting for a response to come back.
>>
>>> On-CPU context switches are much faster than regular ones.
>>
>>> Signed-off-by: Andrei Vagin <avagin@xxxxxxxxxx>
>>
>> Avoiding cpu switches is very desirable for fuse, I'm working on fuse over uring
>> with per core queues. In my current branch and running a single threaded bonnie++
>> I get about 9000 creates/s when I bind the process to a core, about 7000 creates/s
>> when I set SCHED_IDLE for the ring threads and back to 9000 with SCHED_IDLE and
>> disabling cpu migration in fs/fuse/dev.c request_wait_answer() before going into
>> the waitq and enabling it back after waking up.
>>
>> I had reported this a few weeks back
>> https://lore.kernel.org/lkml/d0ed1dbd-1b7e-bf98-65c0-7f61dd1a3228@xxxxxxx/
>> and had been pointed to your and Prateeks patch series. I'm now going
>> through these series. Interesting part is that a few weeks I didn't need
>> SCHED_IDLE, just disabling/enabling migration before/after waking up was
>> enough.
>>
>> [...]
>>
>>> EXPORT_SYMBOL(swake_up_one);
>>> diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
>>> index 133b74730738..47803a0b8d5d 100644
>>> --- a/kernel/sched/wait.c
>>> +++ b/kernel/sched/wait.c
>>> @@ -161,6 +161,11 @@ int __wake_up(struct wait_queue_head *wq_head, unsigned int mode,
>>> }
>>> EXPORT_SYMBOL(__wake_up);
>>
>>> +void __wake_up_on_current_cpu(struct wait_queue_head *wq_head, unsigned int mode, void *key)
>>> +{
>>> + __wake_up_common_lock(wq_head, mode, 1, WF_CURRENT_CPU, key);
>>> +}
>>
>> I'm about to test this instead of migrate_disable/migrate_enable, but the symbol needs
>> to be exported - any objection to do that right from the beginning in your patch?
>
> I think EXPORT_SYMBOL_GPL should not trigger any objections and it
> covers your case, doesn't it?

Ah yes, sure, _GPL is fine. I have applied 2/6 and 3/6 in my branch and then have

wait.h
#define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE)

and and using that in fuse_request_end() - works fine and no migration on wake up.
Though, I still need SCHED_IDLE for the uring thread to avoid a later migration,
will open a separate thread for that.


Thanks,
Bernd