Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp140419pxb; Tue, 21 Sep 2021 21:29:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7klhpaZEXOrUn1jpH3yDrNWo96Hu0RReD+MgPnfJFt3XSLUyp7uPmio00nwH1Id/SJax6 X-Received: by 2002:a6b:dd0c:: with SMTP id f12mr2811536ioc.117.1632284966633; Tue, 21 Sep 2021 21:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632284966; cv=none; d=google.com; s=arc-20160816; b=XSFc9A/moWyHNETLUCbcZ5elOaDSAMLFdxbryv2fidb8EaEtDPd2RCRBeKuXvuwX0w 74Cfb4UzvHf5vNIhx9QgXqjM/1hDHNA6WwbNcCLOB16lI6iUOLAoGodaFZ5FBLs8RIqm gxkhBbyzNpm9+ivBQ/eepRyuXWbSZXeYcHVpv7uSgIL2tf7YAUaU24vXr73StD1bLRq1 oHcKwo32IlyabC5Jo8vAGBq5yT7VeYtwEcPEZw8WE82sOkEsdDzEvjMeMV3e7c4uIZcV XYXkIBd7Fz3Tu0AbvNmb6vHuhbUz4cuuVUMgp+iTeXb56hM6/2OxQS/cHVwt0uKNN25Y Exag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QuPNzSc1xq7ojG5bGphV95EXs7lOrOu+HqPJxaJcYAs=; b=Xo9kgjlDz0IOI9D5IGxtGwxsDfFZ7L2Q0LtT3JGfhm3MVuaZT6WQ0KXEDpylFZ7PoC 2vJMtIyViuDVgifY10VARRNpxWcuhZiYP3hQPzM1ZY1uX06Q4IjS/RT1QskAGXZkjXUl WP54XQoGTVbD7IczqwvSkI3zu/31fdU61kbKBxBboS+Pfhq1FfCsf3O7AAwRAZ2o/5aQ Rd4LeiMuoY5ho9vJ5uwgfHgmNnROnlHX+3f64gOINIGjx1rUgZ5p1HTq04IEWdm7ZU5J dAKaJPLL+U46wnAhiKAqkTzdB21T+GiOVGljelvebV4wky5Ey96g6dSAFNS0vRh5wKTg M1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Aig1Ng8n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t19si1016680jac.62.2021.09.21.21.29.15; Tue, 21 Sep 2021 21:29:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Aig1Ng8n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbhIVE2x (ORCPT + 99 others); Wed, 22 Sep 2021 00:28:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50838 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbhIVE2x (ORCPT ); Wed, 22 Sep 2021 00:28:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632284843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QuPNzSc1xq7ojG5bGphV95EXs7lOrOu+HqPJxaJcYAs=; b=Aig1Ng8njS9cvS6CwFZmNqjN7bXXfXY73DmoLTKiOYJN2WBYOeAyzbW3oed5GdHG06DpSq PlCB7qKcivlzpRI4N3GCiznS6z60IvTKZQvHm6lcgbPnJH/PzNf/WHZ1mix0lHOvJl5fAC aFiEAWxsaFxNtjdukCj7Yektp8pYUGA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-380-mbnnFDW_NUe9kp-mY2F35A-1; Wed, 22 Sep 2021 00:27:21 -0400 X-MC-Unique: mbnnFDW_NUe9kp-mY2F35A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BA19802936; Wed, 22 Sep 2021 04:27:18 +0000 (UTC) Received: from piliu.users.ipa.redhat.com (ovpn-8-17.pek2.redhat.com [10.72.8.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50917380; Wed, 22 Sep 2021 04:27:00 +0000 (UTC) Date: Wed, 22 Sep 2021 12:26:57 +0800 From: Pingfan Liu To: Petr Mladek Cc: Pingfan Liu , linux-kernel@vger.kernel.org, Sumit Garg , Catalin Marinas , Will Deacon , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Marc Zyngier , Julien Thierry , Kees Cook , Masahiro Yamada , Sami Tolvanen , Andrew Morton , Wang Qing , "Peter Zijlstra (Intel)" , Santosh Sivaraj Subject: Re: [PATCH 3/5] kernel/watchdog: adapt the watchdog_hld interface for async model Message-ID: References: <20210915035103.15586-1-kernelfans@gmail.com> <20210915035103.15586-4-kernelfans@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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