Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1786208pxb; Mon, 20 Sep 2021 05:24:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpkdtxBVU2V0j4E4hNCDF2BRLfeLglMHd1t/7heyizhv4p+cwVRaWO0H7WlCV0QHva2XA5 X-Received: by 2002:a92:1304:: with SMTP id 4mr17181311ilt.196.1632140682449; Mon, 20 Sep 2021 05:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632140682; cv=none; d=google.com; s=arc-20160816; b=HbyJuV9gMUGDsw+Oz22BcDY1ObOKdvIvn3S2jmDYcTkUhEMPcE9cp5ZWtjh215SumL G6MHEJqZfa9ms4p0/oBEIaylF36vCEuKW6CIFCQnLI7weow9OSCjvUZRX/WrqDUMAqJn OdVZmZhjG4Zbc6KNnE1wgO+yemUHWpvNcIvK0kBIQuXd1btvchdOSl+7rR5ZlgjuRGhM C7v+aLvtlDlx455JsKfwfEK/6+WzfU/6O3vtH5TdyuSaEz1K7/wSJG/rYAsIrRsLsR0y A7ZVIi5cjNZW73WuZVGUY8B+ylvdMU632uhyZUyCnaa6xA1O+aSzlz7kpIkYaPtfZuTm pSHQ== 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=019wXnCAxMvTlV6EoifAZHeBxG76xSVoI2H7fG2HMoo=; b=ZWI+ByXMrvHsDh/vrEh6vSoMIBthjsT0EncwKg70ZLxqQmbXGQwxfyUuw8+VzhTM0Z MyKmwlvDHKDzoEbdN3INBH2aJfUb/5uoIVwiWclnqLs0WXNONcPjY7/wiJ6VB3LRNDRP Y8vGaDA0iAXF3hO1k6leW4vv9/V0P8QQs5a4HtgA1ESkxIonth6bDx/thJDdEB8ri4AN 6OklhI6UXtP/xiTjsISmKVmtWBp0qwOw4By0gXhyXqklYJwq9SWzEDULCHWD3XBbwWgD zVHm7wE7XX4/vHXSF9/L3G4LMDVW4ijnI6y5m3eiIMm8/dTtwGUPxiSSnTlSN6JTBlC/ gmEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=DhTX+IYY; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si1684179jaf.91.2021.09.20.05.24.30; Mon, 20 Sep 2021 05:24:42 -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=@suse.com header.s=susede1 header.b=DhTX+IYY; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234184AbhITIWQ (ORCPT + 99 others); Mon, 20 Sep 2021 04:22:16 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34360 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230112AbhITIWQ (ORCPT ); Mon, 20 Sep 2021 04:22:16 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0951D21F71; Mon, 20 Sep 2021 08:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1632126048; h=from:from:reply-to: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=019wXnCAxMvTlV6EoifAZHeBxG76xSVoI2H7fG2HMoo=; b=DhTX+IYYsryFVSZvYhYE6Ein1y3JvlrjNTs5nJmNnXpXVuMpQjwgU6IDWKxGLGWtr0VL+2 Xr8kuN1e6V8Bg1b8H2ILtaKJhlfVRzFIpn3P6DxTV9O5ZPWdtr1T76s5NA7V4uBRKxzmU8 KrL5m5ihOsEijtdgEBb6ZIBejvQtExE= Received: from suse.cz (unknown [10.100.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 638D9A3B98; Mon, 20 Sep 2021 08:20:47 +0000 (UTC) Date: Mon, 20 Sep 2021 10:20:46 +0200 From: Petr Mladek To: Pingfan Liu 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2021-09-17 23:41:31, Pingfan Liu wrote: > On Thu, Sep 16, 2021 at 10:36:10AM +0200, Petr Mladek wrote: > > On Thu 2021-09-16 10:29:05, Petr Mladek wrote: > > > On Wed 2021-09-15 11:51:01, Pingfan Liu wrote: > > > > When lockup_detector_init()->watchdog_nmi_probe(), PMU may be not ready > > > > yet. E.g. on arm64, PMU is not ready until > > > > device_initcall(armv8_pmu_driver_init). And it is deeply integrated > > > > with the driver model and cpuhp. Hence it is hard to push this > > > > initialization before smp_init(). > > > > > > > > But it is easy to take an opposite approach by enabling watchdog_hld to > > > > get the capability of PMU async. > > > > > > This is another cryptic description. I have probably got it after > > > looking at the 5th patch (was not Cc :-( > > > > > > > The async model is achieved by introducing an extra parameter notifier > > > > of watchdog_nmi_probe(). > > > > > > I would say that the code is horrible and looks too complex. > > > > > > What about simply calling watchdog_nmi_probe() and > > > lockup_detector_setup() once again when watchdog_nmi_probe() > > > failed in lockup_detector_init()? > > > > > > Or do not call lockup_detector_init() at all in > > > kernel_init_freeable() when PMU is not ready yet. > > > > BTW: It is an overkill to create your own kthread just to run some > > code just once. And you implemeted it a wrong way. The kthread > > 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. > 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. 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); [...] } You do not have to solve this if you use the system workqueue (system_wq). Best Regards, Petr