From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Oleg Nesterov <oleg@tv-sign.ru>,
Anton Blanchard <anton@samba.org>, Andrew Morton <akpm@osdl.org>,
Pavel Machek <pavel@ucw.cz>, LKML <linux-kernel@vger.kernel.org>,
Aneesh Kumar <aneesh.kumar@gmail.com>,
Srivatsa Vaddagiri <vatsa@in.ibm.com>,
Gautham R Shenoy <ego@in.ibm.com>
Subject: Re: [PATCH] kthread_should_stop_check_freeze (was: Re: [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread)
Date: Sun, 11 Mar 2007 21:38:54 -0700 [thread overview]
Message-ID: <20070312043854.GA4124@linux.vnet.ibm.com> (raw)
In-Reply-To: <200703111849.09966.rjw@sisk.pl>
On Sun, Mar 11, 2007 at 06:49:08PM +0100, Rafael J. Wysocki wrote:
> On Saturday, 3 March 2007 18:32, Oleg Nesterov wrote:
> > On 03/02, Paul E. McKenney wrote:
> > >
> > > On Sat, Mar 03, 2007 at 02:33:37AM +0300, Oleg Nesterov wrote:
> > > > On 03/02, Paul E. McKenney wrote:
> > > > >
> > > > > One way to embed try_to_freeze() into kthread_should_stop() might be
> > > > > as follows:
> > > > >
> > > > > int kthread_should_stop(void)
> > > > > {
> > > > > if (kthread_stop_info.k == current)
> > > > > return 1;
> > > > > try_to_freeze();
> > > > > return 0;
> > > > > }
> > > >
> > > > I think this is dangerous. For example, worker_thread() will probably
> > > > need some special actions after return from refrigerator. Also, a kernel
> > > > thread may check kthread_should_stop() in the place where try_to_freeze()
> > > > is not safe.
> > > >
> > > > Perhaps we should introduce a new helper which does this.
> > >
> > > Good point -- the return value from try_to_freeze() is lost if one uses
> > > the above approach. About one third of the calls to try_to_freeze()
> > > in 2.6.20 pay attention to the return value.
> > >
> > > One approach would be to have a kthread_should_stop_nofreeze() for those
> > > cases, and let the default be to try to freeze.
> >
> > I personally think we should do the opposite, add kthread_should_stop_check_freeze()
> > or something. kthread_should_stop() is like signal_pending(), we can use
> > it under spin_lock (and it is probably used this way by some out-of-tree
> > driver). The new helper is obviously "might_sleep()".
>
> Something like this, perhaps:
Looks good to me! The other kthread_should_stop() calls in
rcutorture.c should also become kthread_should_top_check_freeze().
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> include/linux/kthread.h | 1 +
> kernel/kthread.c | 16 ++++++++++++++++
> kernel/rcutorture.c | 5 ++---
> 3 files changed, 19 insertions(+), 3 deletions(-)
>
> Index: linux-2.6.21-rc3-mm2/kernel/kthread.c
> ===================================================================
> --- linux-2.6.21-rc3-mm2.orig/kernel/kthread.c 2007-03-08 21:58:48.000000000 +0100
> +++ linux-2.6.21-rc3-mm2/kernel/kthread.c 2007-03-11 18:32:59.000000000 +0100
> @@ -13,6 +13,7 @@
> #include <linux/file.h>
> #include <linux/module.h>
> #include <linux/mutex.h>
> +#include <linux/freezer.h>
> #include <asm/semaphore.h>
>
> /*
> @@ -60,6 +61,21 @@ int kthread_should_stop(void)
> }
> EXPORT_SYMBOL(kthread_should_stop);
>
> +/**
> + * kthread_should_stop_check_freeze - check if the thread should return now and
> + * if not, check if there is a freezing request pending for it.
> + */
> +int kthread_should_stop_check_freeze(void)
> +{
> + might_sleep();
> + if (kthread_stop_info.k == current)
> + return 1;
> +
> + try_to_freeze();
> + return 0;
> +}
> +EXPORT_SYMBOL(kthread_should_stop_check_freeze);
> +
> static void kthread_exit_files(void)
> {
> struct fs_struct *fs;
> Index: linux-2.6.21-rc3-mm2/include/linux/kthread.h
> ===================================================================
> --- linux-2.6.21-rc3-mm2.orig/include/linux/kthread.h 2007-02-04 19:44:54.000000000 +0100
> +++ linux-2.6.21-rc3-mm2/include/linux/kthread.h 2007-03-11 18:37:10.000000000 +0100
> @@ -29,5 +29,6 @@ struct task_struct *kthread_create(int (
> void kthread_bind(struct task_struct *k, unsigned int cpu);
> int kthread_stop(struct task_struct *k);
> int kthread_should_stop(void);
> +int kthread_should_stop_check_freeze(void);
>
> #endif /* _LINUX_KTHREAD_H */
> Index: linux-2.6.21-rc3-mm2/kernel/rcutorture.c
> ===================================================================
> --- linux-2.6.21-rc3-mm2.orig/kernel/rcutorture.c 2007-03-11 11:39:06.000000000 +0100
> +++ linux-2.6.21-rc3-mm2/kernel/rcutorture.c 2007-03-11 18:45:00.000000000 +0100
> @@ -540,10 +540,9 @@ rcu_torture_writer(void *arg)
> }
> rcu_torture_current_version++;
> oldbatch = cur_ops->completed();
> - try_to_freeze();
> - } while (!kthread_should_stop() && !fullstop);
> + } while (!kthread_should_stop_check_freeze() && !fullstop);
> VERBOSE_PRINTK_STRING("rcu_torture_writer task stopping");
> - while (!kthread_should_stop())
> + while (!kthread_should_stop_check_freeze())
> schedule_timeout_uninterruptible(1);
> return 0;
> }
next prev parent reply other threads:[~2007-03-12 4:44 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-26 7:00 [PATCH -mm 0/6] Freezer changes Rafael J. Wysocki
2007-02-26 7:02 ` [PATCH -mm 1/6] Freezer: Read PF_BORROWED_MM in a nonracy way Rafael J. Wysocki
2007-02-26 7:05 ` [PATCH -mm 2/6] Freezer: Fix memory ordering in refrigerator Rafael J. Wysocki
2007-02-26 11:32 ` Oleg Nesterov
2007-02-26 7:06 ` [PATCH -mm 3/6] Freezer: Close theoretical race between refrigerator and thaw_tasks Rafael J. Wysocki
2007-02-26 7:08 ` [PATCH -mm 4/6] Freezer: Remove PF_NOFREEZE from rcutorture thread Rafael J. Wysocki
2007-02-26 7:11 ` [PATCH -mm 5/6] Freezer: Remove PF_NOFREEZE from bluetooth threads Rafael J. Wysocki
2007-02-26 7:13 ` [PATCH -mm 6/6] Freezer: Add try_to_freeze calls to all kernel threads Rafael J. Wysocki
2007-03-01 15:05 ` [PATCH -mm 0/7] Freezer changes (take 2) Rafael J. Wysocki
2007-03-01 15:06 ` [PATCH -mm 1/7] Freezer: Read PF_BORROWED_MM in a nonracy way Rafael J. Wysocki
2007-03-01 15:08 ` [PATCH -mm 2/7] Freezer: Close theoretical race between refrigerator and thaw_tasks Rafael J. Wysocki
2007-03-01 16:39 ` Pavel Machek
2007-03-01 15:09 ` [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread Rafael J. Wysocki
2007-03-01 19:38 ` Anton Blanchard
2007-03-01 19:54 ` Rafael J. Wysocki
2007-03-02 21:35 ` Paul E. McKenney
2007-03-02 22:16 ` Anton Blanchard
2007-03-02 23:33 ` Oleg Nesterov
2007-03-03 0:58 ` Paul E. McKenney
2007-03-03 17:32 ` Oleg Nesterov
2007-03-04 4:34 ` Srivatsa Vaddagiri
2007-03-11 17:49 ` [PATCH] kthread_should_stop_check_freeze (was: Re: [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread) Rafael J. Wysocki
2007-03-12 4:38 ` Paul E. McKenney [this message]
2007-03-12 8:14 ` Pavel Machek
2007-03-12 11:19 ` Rafael J. Wysocki
2007-03-12 12:23 ` Oleg Nesterov
2007-03-12 13:24 ` [PATCH] kthread_should_stop_check_freeze Cedric Le Goater
2007-03-12 18:25 ` Rafael J. Wysocki
2007-03-12 22:39 ` [PATCH] kthread_should_stop_check_freeze (was: Re: [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread) Pavel Machek
2007-03-12 22:45 ` Anton Blanchard
2007-03-13 3:14 ` Srivatsa Vaddagiri
2007-03-13 9:16 ` Christoph Hellwig
2007-03-13 9:58 ` Srivatsa Vaddagiri
2007-03-13 10:20 ` Christoph Hellwig
2007-03-20 18:08 ` Pavel Machek
2007-03-13 0:58 ` Paul E. McKenney
2007-03-20 18:10 ` Pavel Machek
2007-03-13 5:27 ` Gautham R Shenoy
2007-03-13 5:42 ` Srivatsa Vaddagiri
2007-03-03 1:03 ` [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread Rafael J. Wysocki
2007-03-02 6:57 ` Gautham R Shenoy
2007-03-02 21:46 ` Paul E. McKenney
2007-03-01 15:10 ` [PATCH -mm 4/7] Freezer: Remove PF_NOFREEZE from bluetooth threads Rafael J. Wysocki
2007-03-01 15:12 ` [PATCH -mm 5/7] Freezer: Add try_to_freeze calls to all kernel threads Rafael J. Wysocki
2007-03-01 15:15 ` [PATCH -mm 6/7] Freezer: Fix vfork problem Rafael J. Wysocki
2007-03-01 15:17 ` [PATCH -mm 7/7] Freezer: Take kernel_execve into consideration Rafael J. Wysocki
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=20070312043854.GA4124@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akpm@osdl.org \
--cc=aneesh.kumar@gmail.com \
--cc=anton@samba.org \
--cc=ego@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@tv-sign.ru \
--cc=pavel@ucw.cz \
--cc=rjw@sisk.pl \
--cc=vatsa@in.ibm.com \
/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).