From: Oleg Nesterov <oleg@redhat.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
LKML <linux-kernel@vger.kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>, Ingo Molnar <mingo@kernel.org>,
Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH V2] task_work: avoid unneeded cmpxchg() in task_work_run()
Date: Wed, 10 Oct 2012 19:50:32 +0200 [thread overview]
Message-ID: <20121010175032.GA22642@redhat.com> (raw)
In-Reply-To: <5075098E.9090808@cn.fujitsu.com>
On 10/10, Lai Jiangshan wrote:
>
> --- a/kernel/task_work.c
> +++ b/kernel/task_work.c
> @@ -52,16 +52,7 @@ void task_work_run(void)
> struct callback_head *work, *head, *next;
>
> for (;;) {
> - /*
> - * work->func() can do task_work_add(), do not set
> - * work_exited unless the list is empty.
> - */
> - do {
> - work = ACCESS_ONCE(task->task_works);
> - head = !work && (task->flags & PF_EXITING) ?
> - &work_exited : NULL;
> - } while (cmpxchg(&task->task_works, work, head) != work);
> -
> + work = xchg(&task->task_works, NULL);
> if (!work)
> break;
> /*
> @@ -90,3 +81,17 @@ void task_work_run(void)
> } while (work);
> }
> }
> +
> +void exit_task_work(struct task_struct *task)
> +{
> + for (;;) {
> + /*
> + * work->func() can do task_work_add(), do not set
> + * work_exited unless the list is empty.
> + */
> + if (unlikely(task->task_works))
> + task_work_run();
> + if (cmpxchg(&task->task_works, NULL, &work_exited) == NULL)
> + break;
> + }
> +}
I agree, this looks fine.
But if you add "unlikely" before task_work_run(), then probably
it should do
while (cmpxchg(&task->task_works, NULL, work_exited))
task_work_run();
? it looks more simple/clean.
(OTOH I am not sure "unlikely" is true, note that exit_files() will
offload ____fput() to task_work_run()).
But you did not answer, and I am curious. What was your original
motivation? Is xchg really faster than cmpxchg?
Oleg.
next prev parent reply other threads:[~2012-10-10 17:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-08 9:18 [PATCH] task_work: avoid unneeded cmpxchg() in task_work_run() Lai Jiangshan
2012-10-08 12:38 ` Oleg Nesterov
2012-10-09 11:04 ` Peter Zijlstra
2012-10-10 5:37 ` [PATCH V2] " Lai Jiangshan
2012-10-10 17:50 ` Oleg Nesterov [this message]
2012-10-10 17:50 ` Peter Zijlstra
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=20121010175032.GA22642@redhat.com \
--to=oleg@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=edumazet@google.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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