mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Lance Yang <ioworker0@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Waiman Long <longman@redhat.com>,
	Joel Granados <joel.granados@kernel.org>,
	Anna Schumaker <anna.schumaker@oracle.com>,
	Kent Overstreet <kent.overstreet@linux.dev>,
	Yongliang Gao <leonylgao@tencent.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Tomasz Figa <tfiga@chromium.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] samples: Add hung_task detector mutex blocking sample
Date: Wed, 26 Feb 2025 16:04:30 +0900	[thread overview]
Message-ID: <20250226160430.d74c50d370dcef2904417d1e@kernel.org> (raw)
In-Reply-To: <CAK1f24nLDHLChnwG14rNa5RYik-3+Sqz74OAR1PsWvg3Zu_2+w@mail.gmail.com>

On Wed, 26 Feb 2025 09:50:32 +0800
Lance Yang <ioworker0@gmail.com> wrote:

> On Tue, Feb 25, 2025 at 3:02 PM Masami Hiramatsu (Google)
> <mhiramat@kernel.org> wrote:
> >
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> >
> > Add a hung_task detector mutex blocking test sample code.
> >
> > This module will create a dummy file on the debugfs. That file will
> > cause the read process to sleep for enough long time (256 seconds)
> > while holding a mutex. As a result, the second process will wait on
> > the mutex for a prolonged duration and be detected by the hung_task
> > detector.
> >
> > Usage is;
> >
> >  > cd /sys/kernel/debug/hung_task
> >  > cat mutex & cat mutex
> >
> > and wait for hung_task message.
> >
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > ---
> >  samples/Kconfig                     |    9 +++++
> >  samples/Makefile                    |    1 +
> >  samples/hung_task/Makefile          |    2 +
> >  samples/hung_task/hung_task_mutex.c |   66 +++++++++++++++++++++++++++++++++++
> >  4 files changed, 78 insertions(+)
> >  create mode 100644 samples/hung_task/Makefile
> >  create mode 100644 samples/hung_task/hung_task_mutex.c
> >
> > diff --git a/samples/Kconfig b/samples/Kconfig
> > index 820e00b2ed68..09011be2391a 100644
> > --- a/samples/Kconfig
> > +++ b/samples/Kconfig
> > @@ -300,6 +300,15 @@ config SAMPLE_CHECK_EXEC
> >           demonstrate how they should be used with execveat(2) +
> >           AT_EXECVE_CHECK.
> >
> > +config SAMPLE_HUNG_TASK
> > +       tristate "Hung task detector test code"
> > +       depends on DETECT_HUNG_TASK && DEBUG_FS
> > +       help
> > +         Build a module which provide a simple debugfs file. If user reads
> > +         the file, it will sleep long time (256 seconds) with holding a
> > +         mutex. Thus if there are 2 or more processes read this file, it
> > +         will be detected by the hung_task watchdog.
> > +
> >  source "samples/rust/Kconfig"
> 
> I'm just wondering if we should also make the SAMPLE_HUNG_TASK
> depend on !PREEMPT_RT for now?

Yeah, I also have a question. This does not check the blocker,
but just providing the testing interface with mutex. So there is
no direct connection with DETECT_HUNG_TASK_BLOCKER. Thus I didn't
add the dependency.

Thank you,

> 
> Thanks,
> Lance
> 
> >
> >  source "samples/damon/Kconfig"
> > diff --git a/samples/Makefile b/samples/Makefile
> > index f24cd0d72dd0..bf6e6fca5410 100644
> > --- a/samples/Makefile
> > +++ b/samples/Makefile
> > @@ -42,3 +42,4 @@ obj-$(CONFIG_SAMPLE_FPROBE)           += fprobe/
> >  obj-$(CONFIG_SAMPLES_RUST)             += rust/
> >  obj-$(CONFIG_SAMPLE_DAMON_WSSE)                += damon/
> >  obj-$(CONFIG_SAMPLE_DAMON_PRCL)                += damon/
> > +obj-$(CONFIG_SAMPLE_HUNG_TASK)         += hung_task/
> > diff --git a/samples/hung_task/Makefile b/samples/hung_task/Makefile
> > new file mode 100644
> > index 000000000000..fe9dde799880
> > --- /dev/null
> > +++ b/samples/hung_task/Makefile
> > @@ -0,0 +1,2 @@
> > +# SPDX-License-Identifier: GPL-2.0-only
> > +obj-$(CONFIG_SAMPLE_HUNG_TASK) += hung_task_mutex.o
> > \ No newline at end of file
> > diff --git a/samples/hung_task/hung_task_mutex.c b/samples/hung_task/hung_task_mutex.c
> > new file mode 100644
> > index 000000000000..7a29f2246d22
> > --- /dev/null
> > +++ b/samples/hung_task/hung_task_mutex.c
> > @@ -0,0 +1,66 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * hung_task_mutex.c - Sample code which causes hung task by mutex
> > + *
> > + * Usage: load this module and read `<debugfs>/hung_task/mutex`
> > + *        by 2 or more processes.
> > + *
> > + * This is for testing kernel hung_task error message.
> > + * Note that this will make your system freeze and maybe
> > + * cause panic. So do not use this except for the test.
> > + */
> > +
> > +#include <linux/debugfs.h>
> > +#include <linux/delay.h>
> > +#include <linux/fs.h>
> > +#include <linux/module.h>
> > +#include <linux/mutex.h>
> > +
> > +#define HUNG_TASK_DIR   "hung_task"
> > +#define HUNG_TASK_FILE  "mutex"
> > +#define SLEEP_SECOND 256
> > +
> > +static const char dummy_string[] = "This is a dummy string.";
> > +static DEFINE_MUTEX(dummy_mutex);
> > +struct dentry *hung_task_dir;
> > +
> > +static ssize_t read_dummy(struct file *file, char __user *user_buf,
> > +                         size_t count, loff_t *ppos)
> > +{
> > +       /* If the second task waits on the lock, it is uninterruptible sleep. */
> > +       guard(mutex)(&dummy_mutex);
> > +
> > +       /* When the first task sleep here, it is interruptible. */
> > +       msleep_interruptible(SLEEP_SECOND * 1000);
> > +
> > +       return simple_read_from_buffer(user_buf, count, ppos,
> > +                               dummy_string, sizeof(dummy_string));
> > +}
> > +
> > +static const struct file_operations hung_task_fops = {
> > +       .read = read_dummy,
> > +};
> > +
> > +static int __init hung_task_sample_init(void)
> > +{
> > +       hung_task_dir = debugfs_create_dir(HUNG_TASK_DIR, NULL);
> > +       if (IS_ERR(hung_task_dir))
> > +               return PTR_ERR(hung_task_dir);
> > +
> > +       debugfs_create_file(HUNG_TASK_FILE, 0400, hung_task_dir,
> > +                           NULL, &hung_task_fops);
> > +
> > +       return 0;
> > +}
> > +
> > +static void __exit hung_task_sample_exit(void)
> > +{
> > +       debugfs_remove_recursive(hung_task_dir);
> > +}
> > +
> > +module_init(hung_task_sample_init);
> > +module_exit(hung_task_sample_exit);
> > +
> > +MODULE_LICENSE("GPL");
> > +MODULE_AUTHOR("Masami Hiramatsu");
> > +MODULE_DESCRIPTION("Simple sleep under mutex file for testing hung task");
> >


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2025-02-26  7:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25  7:02 [PATCH v4 0/2] hung_task: Dump the blocking task stacktrace Masami Hiramatsu (Google)
2025-02-25  7:02 ` [PATCH v4 1/2] hung_task: Show the blocker task if the task is hung on mutex Masami Hiramatsu (Google)
2025-02-26  1:23   ` Waiman Long
2025-03-06  2:32     ` Masami Hiramatsu
     [not found]       ` <5f7bc403-be75-4ae3-b6ff-5ff0673847f9@redhat.com>
2025-03-06  3:10         ` Waiman Long
2025-03-13  3:55           ` Masami Hiramatsu
2025-02-26  1:44   ` Lance Yang
2025-02-26  4:38   ` Sergey Senozhatsky
2025-02-26 15:07     ` Steven Rostedt
2025-03-13 22:29   ` Andrew Morton
2025-03-14  3:57     ` Masami Hiramatsu
2025-07-30  7:59   ` Sergey Senozhatsky
2025-07-30  8:51     ` Masami Hiramatsu
2025-07-30  9:36       ` Lance Yang
2025-07-30 10:01         ` Masami Hiramatsu
2025-07-30 10:42           ` Lance Yang
2025-07-30 10:16         ` Sergey Senozhatsky
2025-07-30 10:40           ` Lance Yang
2025-07-30  9:53       ` [RFC PATCH] hung_task: Dump blocker task if it is not hung Masami Hiramatsu (Google)
2025-07-30 13:28         ` Sergey Senozhatsky
2025-07-30 13:55           ` Masami Hiramatsu
2025-07-30 13:46         ` Lance Yang
2025-07-30 21:50           ` Masami Hiramatsu
2025-07-30  9:56       ` [PATCH v4 1/2] hung_task: Show the blocker task if the task is hung on mutex Sergey Senozhatsky
2025-07-30  9:22     ` Lance Yang
2025-07-30  9:46       ` Sergey Senozhatsky
2025-02-25  7:02 ` [PATCH v4 2/2] samples: Add hung_task detector mutex blocking sample Masami Hiramatsu (Google)
2025-02-26  1:50   ` Lance Yang
2025-02-26  7:04     ` Masami Hiramatsu [this message]
2025-02-26 11:58       ` Lance Yang

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=20250226160430.d74c50d370dcef2904417d1e@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=anna.schumaker@oracle.com \
    --cc=boqun.feng@gmail.com \
    --cc=ioworker0@gmail.com \
    --cc=joel.granados@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=leonylgao@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tfiga@chromium.org \
    --cc=will@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

all inboxes | Powered by JetHome®