From: Haakon Bugge <haakon.bugge@oracle.com>
To: Imran Khan <imran.f.khan@oracle.com>
Cc: Tejun Heo <tj@kernel.org>,
"jiangshanlai@gmail.com" <jiangshanlai@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] workqueue: introduce queue_delayed_work_on_offline_safe.
Date: Mon, 3 Feb 2025 11:48:30 +0000 [thread overview]
Message-ID: <28ECBC8D-FD58-4A32-A9DE-7839BD2A77D7@oracle.com> (raw)
In-Reply-To: <08fd6f46-1e85-4642-b2ca-17013cb7a9c9@oracle.com>
On 31 Jan 2025, at 12:16, Imran Khan <imran.f.khan@oracle.com> wrote:
> Hello again Tejun,
> sorry, just found one mistake in earlier shared patch, it
> missed an unlock done below:
>
> Thanks,
> Imran
> On 31/1/2025 9:37 pm, imran.f.khan@oracle.com wrote:
> Hello Tejun,
>
> [...]
>
> Could you kindly let me know, if it would be acceptable, to have
> queue_delayed_work_on_offline_safe, as a wrapper around
> queue_delayed_work_on, such that it can check and ensure CPU's
> availability. If it can't, then it can simply return false and let
> caller decide which cpu to use next. Something like below:
>
>
> diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
> index b0dc957c3e560..57f39807f3bf1 100644
> --- a/include/linux/workqueue.h
> +++ b/include/linux/workqueue.h
> @@ -589,6 +589,9 @@ extern bool queue_work_node(int node, struct workqueue_struct *wq,
> struct work_struct *work);
> extern bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
> struct delayed_work *work, unsigned long delay);
> +extern bool queue_delayed_work_on_offline_safe(int cpu,
> + struct workqueue_struct *wq, struct delayed_work *work,
> + unsigned long delay);
Hi Imran,
I am not quite sure this signature will be OK. See below.
> extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
> struct delayed_work *dwork, unsigned long delay);
> extern bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork);
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 9362484a653c4..7d3b8050422e4 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -2565,6 +2565,37 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
> }
> EXPORT_SYMBOL(queue_delayed_work_on);
>
> +/**
> + * queue_delayed_work_on_offline_safe - queue work on specific online CPU after
> + * delay,
> + *
> + * @cpu: CPU number to execute work on
> + * @wq: workqueue to use
> + * @dwork: work to queue
> + * @delay: number of jiffies to wait before queueing
> + *
> + * a wrapper, around queue_delayed_work_on, that checks and ensures that
> + * specified @cpu is online. If @cpu is found to be offline or if its online
> + * status can't be reliably determined, return false and leave the decision,
> + * of selecting new cpu for delayed_work, to caller.
The return value here is ambiguous.
> + *
> + */
> +bool queue_delayed_work_on_offline_safe(int cpu, struct workqueue_struct *wq,
> + struct delayed_work *dwork, unsigned long delay)
> +{
> + bool ret = false;
> + int locked = 0;
> +
> + if ((locked = cpus_read_trylock()) && cpu_online(cpu)) {
> + ret = queue_delayed_work_on(cpu, wq, dwork, delay);
Now, ret will be false if the work was already queued.
> cpus_read_unlock();
> + } else if (locked)
> + cpus_read_unlock();
> +
> + return ret;
If false is returned, it is a) because the designated @cpu was reliable detected online but the work was already queued or b) because the designated @cpu could not reliable be detected online.
Hence, I think you need to distinguish these cases. I suggest to keep the bool return value to mean what it does for queue_delayed_work_on() and add a bool pointer as argument which can be used to determine reliable online detection of @cpu or not.
A nit is that you should have braces on both the if/else clauses is any of them have it. But even simpler, do not use "else if" but an ordinary "if (locked)", and this way, you can remove the first cpus_read_unlock().
Thxs, Håkon
> +}
> +EXPORT_SYMBOL(queue_delayed_work_on_offline_safe);
> +
> +
>
> If this looks acceptable to you, I can send a v2 of earlier patch.
>
> Thanks,
> Imran
next prev parent reply other threads:[~2025-02-03 11:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 4:35 Imran Khan
2025-01-13 18:21 ` Tejun Heo
2025-01-14 3:01 ` imran.f.khan
2025-01-17 5:27 ` imran.f.khan
2025-01-31 10:37 ` imran.f.khan
2025-01-31 11:16 ` imran.f.khan
2025-02-03 11:48 ` Haakon Bugge [this message]
2025-02-04 5:54 ` imran.f.khan
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=28ECBC8D-FD58-4A32-A9DE-7839BD2A77D7@oracle.com \
--to=haakon.bugge@oracle.com \
--cc=imran.f.khan@oracle.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.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
all inboxes | Powered by JetHome®