From: Peter Zijlstra <peterz@infradead.org>
To: Andrei Vagin <avagin@google.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
Christian Brauner <brauner@kernel.org>,
Andrei Vagin <avagin@gmail.com>,
Andy Lutomirski <luto@amacapital.net>,
Juri Lelli <juri.lelli@redhat.com>,
Peter Oskolkov <posk@google.com>,
Tycho Andersen <tycho@tycho.pizza>,
Will Drewry <wad@chromium.org>
Subject: Re: [PATCH 3/5] sched: add a few helpers to wake up tasks on the current cpu
Date: Mon, 16 Jan 2023 10:59:34 +0100 [thread overview]
Message-ID: <Y8UgBnsaGDUJKH5A@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20230110213010.2683185-4-avagin@google.com>
On Tue, Jan 10, 2023 at 01:30:08PM -0800, Andrei Vagin wrote:
> diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
> index d57a5c1c1cd9..a1931a79c05a 100644
> --- a/kernel/sched/completion.c
> +++ b/kernel/sched/completion.c
> @@ -38,6 +38,18 @@ void complete(struct completion *x)
> }
> EXPORT_SYMBOL(complete);
>
> +void complete_on_current_cpu(struct completion *x)
> +{
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&x->wait.lock, flags);
> +
> + if (x->done != UINT_MAX)
> + x->done++;
> + swake_up_locked_on_current_cpu(&x->wait);
> + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
> +}
> +
> /**
> * complete_all: - signals all threads waiting on this completion
> * @x: holds the state of this particular completion
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 6478e819eb99..c81866821139 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6874,7 +6874,7 @@ asmlinkage __visible void __sched preempt_schedule_irq(void)
> int default_wake_function(wait_queue_entry_t *curr, unsigned mode, int wake_flags,
> void *key)
> {
> - WARN_ON_ONCE(IS_ENABLED(CONFIG_SCHED_DEBUG) && wake_flags & ~WF_SYNC);
> + WARN_ON_ONCE(IS_ENABLED(CONFIG_SCHED_DEBUG) && wake_flags & ~(WF_SYNC|WF_CURRENT_CPU));
> return try_to_wake_up(curr->private, mode, wake_flags);
> }
> EXPORT_SYMBOL(default_wake_function);
> diff --git a/kernel/sched/swait.c b/kernel/sched/swait.c
> index 76b9b796e695..9ebe23868942 100644
> --- a/kernel/sched/swait.c
> +++ b/kernel/sched/swait.c
> @@ -31,6 +31,17 @@ void swake_up_locked(struct swait_queue_head *q)
> }
> EXPORT_SYMBOL(swake_up_locked);
>
> +void swake_up_locked_on_current_cpu(struct swait_queue_head *q)
> +{
> + struct swait_queue *curr;
> +
> + if (list_empty(&q->task_list))
> + return;
> +
> + curr = list_first_entry(&q->task_list, typeof(*curr), task_list);
> + try_to_wake_up(curr->task, TASK_NORMAL, WF_CURRENT_CPU);
> + list_del_init(&curr->task_list);
> +}
> /*
> * Wake up all waiters. This is an interface which is solely exposed for
> * completions and not for general usage.
> 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);
> +}
> +
> /*
> * Same as __wake_up but called with the spinlock in wait_queue_head_t held.
> */
So I hate this patch, it adds a whole ton of duplication and litter for
no real reason afaict. For instance you could've just added an
wake_flags argument to swake_up_locked(), there's not *that* many users
-- unlike complete().
And for complete() instead of fully duplicating the function (always a
bad idea) you could've made complete_flags() and implemented complete()
using that, or something.
Anyway, let me go (finally) have a look at Chen's patch, since that
might render all this moot.
next prev parent reply other threads:[~2023-01-16 10:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-10 21:30 [PATCH 0/5 v3 RESEND] seccomp: add the synchronous mode for seccomp_unotify Andrei Vagin
2023-01-10 21:30 ` [PATCH 1/5] seccomp: don't use semaphore and wait_queue together Andrei Vagin
2023-01-12 14:58 ` Tycho Andersen
2023-01-13 21:51 ` Andrei Vagin
2023-01-16 9:48 ` Peter Zijlstra
2023-01-10 21:30 ` [PATCH 2/5] sched: add WF_CURRENT_CPU and externise ttwu Andrei Vagin
2023-01-12 7:35 ` Chen Yu
2023-01-13 21:39 ` Andrei Vagin
2023-01-14 15:59 ` Chen Yu
2023-01-18 6:10 ` Andrei Vagin
2023-01-10 21:30 ` [PATCH 3/5] sched: add a few helpers to wake up tasks on the current cpu Andrei Vagin
2023-01-16 9:59 ` Peter Zijlstra [this message]
2023-01-19 6:45 ` Andrei Vagin
2023-01-19 10:09 ` Peter Zijlstra
2023-01-10 21:30 ` [PATCH 4/5] seccomp: add the synchronous mode for seccomp_unotify Andrei Vagin
2023-01-12 15:00 ` Tycho Andersen
2023-01-14 1:16 ` Andrei Vagin
2023-01-10 21:30 ` [PATCH 5/5] selftest/seccomp: add a new test for the sync mode of seccomp_user_notify Andrei Vagin
-- strict thread matches above, loose matches on Subject: below --
2022-11-11 7:31 [PATCH 0/5 v3] seccomp: add the synchronous mode for seccomp_unotify Andrei Vagin
2022-11-11 7:31 ` [PATCH 3/5] sched: add a few helpers to wake up tasks on the current cpu Andrei Vagin
2022-10-20 1:10 [PATCH 0/5 v2] seccomp: add the synchronous mode for seccomp_unotify Andrei Vagin
2022-10-20 1:10 ` [PATCH 3/5] sched: add a few helpers to wake up tasks on the current cpu Andrei Vagin
2022-10-20 14:15 ` Peter Zijlstra
2022-10-21 0:44 ` Andrei Vagin
2022-10-27 6:51 ` Andrei Vagin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y8UgBnsaGDUJKH5A@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=avagin@gmail.com \
--cc=avagin@google.com \
--cc=brauner@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=posk@google.com \
--cc=tycho@tycho.pizza \
--cc=vincent.guittot@linaro.org \
--cc=wad@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).