[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20070313052716.GA11982@in.ibm.com>
Date: Tue, 13 Mar 2007 10:57:16 +0530
From: Gautham R Shenoy <ego@...ibm.com>
To: "Rafael J. Wysocki" <rjw@...k.pl>
Cc: Oleg Nesterov <oleg@...sign.ru>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
Anton Blanchard <anton@...ba.org>,
Andrew Morton <akpm@...l.org>, Pavel Machek <pavel@....cz>,
LKML <linux-kernel@...r.kernel.org>,
Aneesh Kumar <aneesh.kumar@...il.com>,
Srivatsa Vaddagiri <vatsa@...ibm.com>
Subject: Re: [PATCH] kthread_should_stop_check_freeze (was: Re: [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread)
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:
>
> 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);
I would prefer to have try_to_freeze() followed by the
kthread_stop_info.k check. Something like
if (try_to_freeze())
/*some barrier ensuring all writes are completed */
if (kthread_stop_info.k == current)
return 1;
return 0;
This would be helpful in situations (atleast for cpu-hotplug)
where we want to stop a frozen thread immediately after thawing it.
Something like
CPU_DEAD:
thaw_process(p);
kthread_stop(p);
p = NULL;
Is there a problem with this line of thinking ?
thanks and regards
gautham.
--
Gautham R Shenoy
Linux Technology Center
IBM India.
"Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists