From: Namhyung Kim <namhyung@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
Rusty Russell <rusty@rustcorp.com.au>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Tejun Heo <tj@kernel.org>
Subject: Re: [RFC patch 1/5] kthread: Implement park/unpark facility
Date: Thu, 14 Jun 2012 11:32:06 +0900 [thread overview]
Message-ID: <8762au62u1.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <20120613105815.132283147@linutronix.de> (Thomas Gleixner's message of "Wed, 13 Jun 2012 11:00:54 -0000")
Hi, Thomas
A nitpick and questions. :)
On Wed, 13 Jun 2012 11:00:54 -0000, Thomas Gleixner wrote:
> To avoid the full teardown/setup of per cpu kthreads in the case of
> cpu hot(un)plug, provide a facility which allows to put the kthread
> into a park position and unpark it when the cpu comes online again.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
[snip]
>
> /**
> + * kthread_create_on_cpu - Create a cpu bound kthread
> + * @threadfn: the function to run until signal_pending(current).
> + * @data: data ptr for @threadfn.
> + * @node: memory node number.
Should be @cpu.
> + * @namefmt: printf-style name for the thread.
> + *
> + * Description: This helper function creates and names a kernel thread
> + * and binds it to a given CPU. The thread will be woken and put into
> + * park mode.
> + */
> +struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
> + void *data, unsigned int cpu,
> + const char *namefmt)
> +{
> + struct task_struct *p;
> +
> + p = kthread_create_on_node(threadfn, data, cpu_to_node(cpu), namefmt,
> + cpu);
> + if (IS_ERR(p))
> + return p;
> + /* Park the thread, mark it percpu and then bind it */
> + kthread_park(p);
Why park? AFAIK the p is not running after creation, so binding it
doesn't need parking, right?
> + set_bit(KTHREAD_IS_PER_CPU, &to_kthread(p)->flags);
> + to_kthread(p)->cpu = cpu;
> + __kthread_bind(p, cpu);
> + return p;
> +}
> +
> +/**
> + * kthread_unpark - unpark a thread created by kthread_create().
> + * @k: thread created by kthread_create().
> + *
> + * Sets kthread_should_park() for @k to return false, wakes it, and
> + * waits for it to return. If the thread is marked percpu then its
> + * bound to the cpu again.
> + */
> +void kthread_unpark(struct task_struct *k)
> +{
> + struct kthread *kthread;
> +
> + get_task_struct(k);
> +
> + kthread = to_kthread(k);
> + barrier(); /* it might have exited */
> + if (k->vfork_done != NULL) {
Does is guarantee it's not exited? If so, as it is used a couple of
times, wouldn't it be better making it up a (static?) helper (with
comments, hopefully) something like a kthread_is_alive() ?
> + clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
> + if (test_bit(KTHREAD_IS_PARKED, &kthread->flags)) {
> + if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags))
> + __kthread_bind(k, kthread->cpu);
> + wake_up_process(k);
> + }
> + }
> + put_task_struct(k);
> +}
> +
> +/**
> + * kthread_park - park a thread created by kthread_create().
> + * @k: thread created by kthread_create().
> + *
> + * Sets kthread_should_park() for @k to return true, wakes it, and
> + * waits for it to return. This can also be called after kthread_create()
> + * instead of calling wake_up_process(): the thread will park without
> + * calling threadfn().
> + *
> + * Returns 0 if the thread is parked, -ENOSYS if the thread exited.
> + * If called by the kthread itself just the park bit is set.
> + */
> +int kthread_park(struct task_struct *k)
> +{
> + struct kthread *kthread;
> + int ret = -ENOSYS;
> +
> + get_task_struct(k);
> +
> + kthread = to_kthread(k);
> + barrier(); /* it might have exited */
> + if (k->vfork_done != NULL) {
> + if (!test_bit(KTHREAD_IS_PARKED, &kthread->flags)) {
> + set_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
> + if (k != current) {
> + wake_up_process(k);
> + wait_for_completion(&kthread->parked);
> + }
> + }
> + ret = 0;
> + }
> + put_task_struct(k);
> + return ret;
> +}
> +
> +/**
> * kthread_stop - stop a thread created by kthread_create().
> * @k: thread created by kthread_create().
> *
> @@ -259,7 +398,7 @@ int kthread_stop(struct task_struct *k)
> kthread = to_kthread(k);
> barrier(); /* it might have exited */
> if (k->vfork_done != NULL) {
> - kthread->should_stop = 1;
> + set_bit(KTHREAD_SHOULD_STOP, &kthread->flags);
I wonder whether it also needs to unpark @k. Isn't it possible to stop a
parked thread?
Thanks,
Namhyung
> wake_up_process(k);
> wait_for_completion(&kthread->exited);
> }
next prev parent reply other threads:[~2012-06-14 2:34 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-13 11:00 [RFC patch 0/5] Per cpu thread hotplug infrastructure Thomas Gleixner
2012-06-13 11:00 ` [RFC patch 2/5] smpboot: Provide infrastructure for percpu hotplug threads Thomas Gleixner
2012-06-13 18:33 ` Paul E. McKenney
2012-06-13 18:56 ` Thomas Gleixner
2012-06-14 8:08 ` Peter Zijlstra
2012-06-14 8:17 ` Peter Zijlstra
2012-06-15 1:53 ` Tejun Heo
2012-06-15 9:58 ` Peter Zijlstra
2012-06-14 8:37 ` Thomas Gleixner
2012-06-14 8:38 ` Peter Zijlstra
2012-06-13 18:57 ` Paul E. McKenney
2012-06-13 19:02 ` Thomas Gleixner
2012-06-13 19:17 ` Paul E. McKenney
2012-06-13 20:47 ` Paul E. McKenney
2012-06-14 4:51 ` Paul E. McKenney
2012-06-14 11:20 ` Thomas Gleixner
2012-06-14 12:59 ` Paul E. McKenney
2012-06-14 13:01 ` Peter Zijlstra
2012-06-14 14:47 ` Paul E. McKenney
2012-06-14 14:56 ` Peter Zijlstra
2012-06-14 15:07 ` Thomas Gleixner
2012-06-14 15:45 ` Paul E. McKenney
2012-06-14 16:20 ` Thomas Gleixner
2012-06-14 13:32 ` Thomas Gleixner
2012-06-14 13:47 ` Thomas Gleixner
2012-06-14 14:12 ` Thomas Gleixner
2012-06-14 15:01 ` Paul E. McKenney
2012-06-14 15:08 ` Thomas Gleixner
2012-06-14 14:50 ` Paul E. McKenney
2012-06-14 15:02 ` Thomas Gleixner
2012-06-14 15:38 ` Paul E. McKenney
2012-06-14 16:19 ` Thomas Gleixner
2012-06-14 16:48 ` Paul E. McKenney
2012-06-14 22:40 ` Paul E. McKenney
2012-06-14 8:31 ` Srivatsa S. Bhat
2012-06-14 8:44 ` Thomas Gleixner
2012-06-18 8:47 ` Cyrill Gorcunov
2012-06-18 8:50 ` Thomas Gleixner
2012-06-13 11:00 ` [RFC patch 1/5] kthread: Implement park/unpark facility Thomas Gleixner
2012-06-14 2:32 ` Namhyung Kim [this message]
2012-06-14 8:35 ` Thomas Gleixner
2012-06-14 8:59 ` Thomas Gleixner
2012-06-14 8:36 ` Srivatsa S. Bhat
2012-06-14 20:01 ` Silas Boyd-Wickizer
2012-06-14 20:13 ` Thomas Gleixner
2012-06-14 22:13 ` Silas Boyd-Wickizer
2012-06-15 1:44 ` Tejun Heo
2012-06-13 11:00 ` [RFC patch 3/5] softirq: Use hotplug thread infrastructure Thomas Gleixner
2012-06-13 11:00 ` [RFC patch 5/5] infiniband: ehca: " Thomas Gleixner
2012-06-18 6:30 ` Rusty Russell
2012-06-18 8:08 ` Thomas Gleixner
2012-06-24 10:29 ` Thomas Gleixner
2012-06-13 11:00 ` [RFC patch 4/5] watchdog: " Thomas Gleixner
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=8762au62u1.fsf@sejong.aot.lge.com \
--to=namhyung@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rusty@rustcorp.com.au \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--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
Powered by JetHome