LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Pingfan Liu <piliu@redhat.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Pingfan Liu <kernelfans@gmail.com>,
linux-kernel@vger.kernel.org, Sumit Garg <sumit.garg@linaro.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Marc Zyngier <maz@kernel.org>,
Julien Thierry <jthierry@redhat.com>,
Kees Cook <keescook@chromium.org>,
Masahiro Yamada <masahiroy@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Wang Qing <wangqing@vivo.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Santosh Sivaraj <santosh@fossix.org>
Subject: Re: [PATCH 3/5] kernel/watchdog: adapt the watchdog_hld interface for async model
Date: Wed, 22 Sep 2021 12:26:57 +0800 [thread overview]
Message-ID: <YUqwkXkIu9Wx+Btg@piliu.users.ipa.redhat.com> (raw)
In-Reply-To: <YUhEXj88J3olXRB1@alley>
On Mon, Sep 20, 2021 at 10:20:46AM +0200, Petr Mladek wrote:
> On Fri 2021-09-17 23:41:31, Pingfan Liu wrote:
[...]
> >
> > I had thought about queue_work_on() in watchdog_nmi_enable(). But since
> > this work will block the worker kthread for this cpu. So finally,
> > another worker kthread should be created for other work.
>
> This is not a problem. workqueues use a pool of workers that are
> already created and can be used when one worker gets blocked.
>
Yes, you are right. The creation is dynamic and immune to blocking.
> > But now, I think queue_work_on() may be more neat.
> >
> > > must wait in a loop until someone else stop it and read
> > > the exit code.
> > >
> > Is this behavior mandotory? Since this kthread can decide the exit
> > condition by itself.
>
> I am pretty sure. Unfortunately, I can't find it in the documentation.
>
> My view is the following. Each process has a task_struct. The
> scheduler needs task_struct so that it can switch processes.
> The task_struct must still exist when the process exits.
> The scheduler puts the task into TASK_DEAD state.
> Another process has to read the exit code and destroy the
> task struct.
>
Thanks for bringing up this, and I have an opportunity to think about it.
The core of the problem is put_task_struct(), and who releases the
last one.
It should be: finish_task_switch()->put_task_struct_rcu_user()->delayed_put_task_struct()->put_task_struct(),
if (unlikely(prev_state == TASK_DEAD)). It does not depend on another task.
> See, do_exit() in kernel/exit.c. It ends with do_dead_task().
> It is the point when the process goes into TASK_DEAD state.
>
> For a good example, see lib/test_vmalloc.c. The kthread waits
> until anyone want him to stop:
>
> static int test_func(void *private)
> {
> [...]
>
> /*
> * Wait for the kthread_stop() call.
> */
> while (!kthread_should_stop())
> msleep(10);
>
> return 0;
> }
>
> The kthreads are started and stopped in:
>
> static void do_concurrent_test(void)
> {
> [...]
> for (i = 0; i < nr_threads; i++) {
> [...]
> t->task = kthread_run(test_func, t, "vmalloc_test/%d", i);
> [...]
> /*
> * Sleep quiet until all workers are done with 1 second
> * interval. Since the test can take a lot of time we
> * can run into a stack trace of the hung task. That is
> * why we go with completion_timeout and HZ value.
> */
> do {
> ret = wait_for_completion_timeout(&test_all_done_comp, HZ);
> } while (!ret);
> [...]
> for (i = 0; i < nr_threads; i++) {
> [...]
> if (!IS_ERR(t->task))
> kthread_stop(t->task);
> [...]
> }
They are good and elegant examples.
>
>
> You do not have to solve this if you use the system workqueue
> (system_wq).
>
Yes, workqueue is a better choice.
Thanks for your great patience.
Regards,
Pingfan
next prev parent reply other threads:[~2021-09-22 4:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-15 3:50 [PATCH 0/5] watchdog_hld cleanup and async model for arm64 Pingfan Liu
2021-09-15 3:50 ` [PATCH 1/5] kernel/watchdog: remove useless WATCHDOG_DEFAULT Pingfan Liu
2021-09-15 3:51 ` [PATCH 2/5] kernel/watchdog_hld: clarify the condition in hardlockup_detector_event_create() Pingfan Liu
2021-09-15 4:06 ` Andrew Morton
2021-09-16 3:47 ` Pingfan Liu
2021-09-15 13:45 ` Peter Zijlstra
2021-09-16 3:57 ` Pingfan Liu
2021-09-16 8:02 ` Petr Mladek
2021-09-17 15:08 ` Pingfan Liu
2021-09-15 3:51 ` [PATCH 3/5] kernel/watchdog: adapt the watchdog_hld interface for async model Pingfan Liu
2021-09-15 14:02 ` Peter Zijlstra
2021-09-16 3:07 ` Pingfan Liu
2021-09-16 8:29 ` Petr Mladek
2021-09-16 8:36 ` Petr Mladek
2021-09-17 15:41 ` Pingfan Liu
2021-09-20 8:20 ` Petr Mladek
2021-09-22 4:26 ` Pingfan Liu [this message]
2021-09-17 14:43 ` Pingfan Liu
2021-09-15 3:51 ` [PATCH 4/5] kernel/watchdog_hld: simplify the detecting of hld watchdog Pingfan Liu
2021-09-15 3:51 ` [PATCH 5/5] arm64/watchdog_hld: enable hard lockup on arm64 platform Pingfan Liu
2021-09-17 15:11 ` Pingfan Liu
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=YUqwkXkIu9Wx+Btg@piliu.users.ipa.redhat.com \
--to=piliu@redhat.com \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=catalin.marinas@arm.com \
--cc=jolsa@redhat.com \
--cc=jthierry@redhat.com \
--cc=keescook@chromium.org \
--cc=kernelfans@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=samitolvanen@google.com \
--cc=santosh@fossix.org \
--cc=sumit.garg@linaro.org \
--cc=wangqing@vivo.com \
--cc=will@kernel.org \
--subject='Re: [PATCH 3/5] kernel/watchdog: adapt the watchdog_hld interface for async model' \
/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
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).