Re: [PATCH] kthread_should_stop_check_freeze (was: Re: [PATCH -mm 3/7] Freezer: Remove PF_NOFREEZE from rcutorture thread)
From: Rafael J. Wysocki
Date: Mon Mar 12 2007 - 07:16:58 EST
Hi,
On Monday, 12 March 2007 09:14, Pavel Machek wrote:
> Hi!
>
> > > > 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@xxxxxxxxxxxxxxxxxx>
> >
> > > 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;
> > > +}
>
> Can we get better name for this function?
Well, I took the name from the Oleg's message. Can you please suggest
something?
> Why is it useful?
Because we want to avoid repeating
while (!kthread_should_stop()) {
try_to_freeze();
...
}
in many places?
> Caller can do "try_to_freeze()" as well, no?
Sure, it just eliminates one line of code.
> > > }
> > > 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;
>
> Aha, I see, here it probably becomes handy.
>
> Actually, no... I do not see it. Why don't you simply move first
> try_to_freeze() to beggining of the loop and do
>
> - while (!kthread_should_stop()) {
> schedule_timeout_uninterruptible(1);
> try_to_freeze()
> }
Yes, but then the second loop will contain one more line of code.
Greetings,
Rafael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/