From: Frederic Weisbecker <fweisbec@gmail.com>
To: Mandeep Singh Baines <msb@google.com>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@elte.hu>,
rientjes@google.com, mbligh@google.com, thockin@google.com,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v4] softlockup: remove hung_task_check_count
Date: Tue, 27 Jan 2009 10:27:10 +0100 [thread overview]
Message-ID: <20090127092709.GA5878@nowhere> (raw)
In-Reply-To: <20090127003055.GA21269@google.com>
On Mon, Jan 26, 2009 at 04:30:55PM -0800, Mandeep Singh Baines wrote:
> Peter Zijlstra (peterz@infradead.org) wrote:
> > On Mon, 2009-01-26 at 09:36 -0800, Mandeep Baines wrote:
> >
> > > Unfortunately, this can't be done for hung_task. It writes to the
> > > task_struct here:
> >
> > Don't top post!
> >
> > > static void check_hung_task(struct task_struct *t, unsigned long now,
> > > unsigned long timeout)
> > > {
> > > unsigned long switch_count = t->nvcsw + t->nivcsw;
> > >
> > > if (t->flags & PF_FROZEN)
> > > return;
> > >
> > > if (switch_count != t->last_switch_count || !t->last_switch_timestamp) {
> > > t->last_switch_count = switch_count;
> > > t->last_switch_timestamp = now;
> > > return;
> > > }
> > >
> > > It is able to get away with using only a read_lock because no one else
> > > reads or writes to these fields.
> >
> > How would RCU be different here?
> >
>
> My bad, RCU wouldn't be any different. I misunderstood how RCU works. Just
> spent the morning reading the LWN 3-part series on RCU and I think I'm able to
> grok it now;)
>
> Below is a patch to hung_task which removes the hung_task_check_count and
> converts the read_locks to RCU.
>
> Thanks Frédéric and Peter!
>
> ---
> To avoid holding the tasklist lock too long, hung_task_check_count was used
> as an upper bound on the number of tasks that are checked by hung_task.
> This patch removes the hung_task_check_count sysctl.
>
> Instead of checking a limited number of tasks, all tasks are checked. To
> avoid holding the CPU for too long, need_resched() is checked often. To
> avoid blocking out writers, the read_lock has been converted to an
> rcu_read_lock().
>
> It is safe convert to an rcu_read_lock() because the tasks and thread_group
> lists are both protected by list_*_rcu() operations. The worst that can
> happen is that hung_task will update last_switch_timestamp field of a DEAD
> task.
>
> The design was proposed by Frédéric Weisbecker. Peter Zijlstra suggested
> the use of RCU.
>
> Signed-off-by: Mandeep Singh Baines <msb@google.com>
> ---
> include/linux/sched.h | 1 -
> kernel/hung_task.c | 12 +++---------
> kernel/sysctl.c | 9 ---------
> 3 files changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index f2f94d5..278121c 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -315,7 +315,6 @@ static inline void touch_all_softlockup_watchdogs(void)
>
> #ifdef CONFIG_DETECT_HUNG_TASK
> extern unsigned int sysctl_hung_task_panic;
> -extern unsigned long sysctl_hung_task_check_count;
> extern unsigned long sysctl_hung_task_timeout_secs;
> extern unsigned long sysctl_hung_task_warnings;
> extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
> diff --git a/kernel/hung_task.c b/kernel/hung_task.c
> index ba8ccd4..7d67350 100644
> --- a/kernel/hung_task.c
> +++ b/kernel/hung_task.c
> @@ -17,11 +17,6 @@
> #include <linux/sysctl.h>
>
> /*
> - * Have a reasonable limit on the number of tasks checked:
> - */
> -unsigned long __read_mostly sysctl_hung_task_check_count = 1024;
> -
> -/*
> * Zero means infinite timeout - no checking done:
> */
> unsigned long __read_mostly sysctl_hung_task_timeout_secs = 120;
> @@ -116,7 +111,6 @@ static void check_hung_task(struct task_struct *t, unsigned long now,
> */
> static void check_hung_uninterruptible_tasks(unsigned long timeout)
> {
> - int max_count = sysctl_hung_task_check_count;
> unsigned long now = get_timestamp();
> struct task_struct *g, *t;
>
> @@ -127,16 +121,16 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
> if (test_taint(TAINT_DIE) || did_panic)
> return;
>
> - read_lock(&tasklist_lock);
> + rcu_read_lock();
> do_each_thread(g, t) {
> - if (!--max_count)
> + if (need_resched())
> goto unlock;
> /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */
> if (t->state == TASK_UNINTERRUPTIBLE)
> check_hung_task(t, now, timeout);
> } while_each_thread(g, t);
> unlock:
> - read_unlock(&tasklist_lock);
> + rcu_read_unlock();
> }
>
> static void update_poll_jiffies(void)
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 2481ed3..16526a2 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -820,15 +820,6 @@ static struct ctl_table kern_table[] = {
> },
> {
> .ctl_name = CTL_UNNUMBERED,
> - .procname = "hung_task_check_count",
> - .data = &sysctl_hung_task_check_count,
> - .maxlen = sizeof(unsigned long),
> - .mode = 0644,
> - .proc_handler = &proc_doulongvec_minmax,
> - .strategy = &sysctl_intvec,
> - },
> - {
> - .ctl_name = CTL_UNNUMBERED,
> .procname = "hung_task_timeout_secs",
> .data = &sysctl_hung_task_timeout_secs,
> .maxlen = sizeof(unsigned long),
> --
> 1.5.4.5
>
That looks good :-)
next prev parent reply other threads:[~2009-01-27 9:27 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-25 20:50 [RFC][PATCH 2/2] add a counter for writers spinning on a rwlock Frederic Weisbecker
2009-01-26 13:32 ` Ingo Molnar
2009-01-26 13:48 ` Peter Zijlstra
2009-01-26 15:25 ` Frédéric Weisbecker
2009-01-26 15:37 ` Peter Zijlstra
2009-01-26 16:04 ` Frédéric Weisbecker
2009-01-26 17:36 ` Mandeep Baines
2009-01-26 17:41 ` Peter Zijlstra
2009-01-27 0:30 ` [PATCH v4] softlockup: remove hung_task_check_count Mandeep Singh Baines
2009-01-27 9:27 ` Frederic Weisbecker [this message]
2009-01-27 13:26 ` Ingo Molnar
2009-01-27 18:48 ` Mandeep Singh Baines
2009-01-28 8:25 ` Peter Zijlstra
2009-01-29 1:42 ` Mandeep Singh Baines
2009-01-30 20:41 ` Mandeep Singh Baines
2009-01-30 20:46 ` [PATCH 1/2] softlockup: convert read_lock in hung_task to rcu_read_lock Mandeep Singh Baines
2009-01-30 20:49 ` [PATCH 2/2] softlockup: check all tasks in hung_task Mandeep Singh Baines
2009-01-31 19:22 ` Peter Zijlstra
2009-02-03 0:05 ` [PATCH 2/2 v2] " Mandeep Singh Baines
2009-02-03 12:23 ` Ingo Molnar
2009-02-03 20:56 ` [PATCH 2/2 v3] " Mandeep Singh Baines
2009-02-04 19:43 ` Ingo Molnar
2009-02-05 4:35 ` [PATCH 2/2 v4] " Mandeep Singh Baines
2009-02-05 14:34 ` Ingo Molnar
2009-02-05 17:48 ` Andrew Morton
2009-02-05 18:07 ` Ingo Molnar
2009-02-05 18:30 ` Andrew Morton
2009-02-05 18:58 ` Ingo Molnar
2009-02-05 18:40 ` Mandeep Singh Baines
2009-02-05 17:56 ` [PATCH] softlockup: convert read_lock in hung_task to rcu_read_lock Mandeep Singh Baines
2009-02-05 18:13 ` Ingo Molnar
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=20090127092709.GA5878@nowhere \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbligh@google.com \
--cc=mingo@elte.hu \
--cc=msb@google.com \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=thockin@google.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