From: Pingfan Liu <kernelfans@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Pingfan Liu <kernelfans@gmail.com>,
Petr Mladek <pmladek@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Wang Qing <wangqing@vivo.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Santosh Sivaraj <santosh@fossix.org>
Subject: [PATCH 4/5] kernel/watchdog_hld: simplify the detecting of hld watchdog
Date: Wed, 15 Sep 2021 11:51:02 +0800 [thread overview]
Message-ID: <20210915035103.15586-5-kernelfans@gmail.com> (raw)
In-Reply-To: <20210915035103.15586-1-kernelfans@gmail.com>
By utilizing the new interface model, the stages of probe and enable can
be merged, which saves the pair of perf_event alloc and free.
Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Wang Qing <wangqing@vivo.com>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Santosh Sivaraj <santosh@fossix.org>
To: linux-kernel@vger.kernel.org
---
include/linux/nmi.h | 8 ++------
kernel/watchdog.c | 16 ++++++++++++++--
kernel/watchdog_hld.c | 21 +++------------------
3 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/include/linux/nmi.h b/include/linux/nmi.h
index 70665fa6e0a9..e41cdf3edba7 100644
--- a/include/linux/nmi.h
+++ b/include/linux/nmi.h
@@ -101,20 +101,16 @@ extern void arch_touch_nmi_watchdog(void);
extern void hardlockup_detector_perf_stop(void);
extern void hardlockup_detector_perf_restart(void);
extern void hardlockup_detector_perf_disable(void);
-extern void hardlockup_detector_perf_enable(void);
+extern int hardlockup_detector_perf_enable(void);
extern void hardlockup_detector_perf_cleanup(void);
-extern int hardlockup_detector_perf_init(void);
#else
static inline void hardlockup_detector_perf_stop(void) { }
static inline void hardlockup_detector_perf_restart(void) { }
static inline void hardlockup_detector_perf_disable(void) { }
-static inline void hardlockup_detector_perf_enable(void) { }
+static inline int hardlockup_detector_perf_enable(void) { return -ENODEV; }
static inline void hardlockup_detector_perf_cleanup(void) { }
# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
-static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
static inline void arch_touch_nmi_watchdog(void) {}
-# else
-static inline int hardlockup_detector_perf_init(void) { return 0; }
# endif
#endif
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 4ab71943d65f..3f5efbd5961c 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -99,7 +99,17 @@ static watchdog_nmi_status_reporter status_reporter;
*/
void __weak watchdog_nmi_enable(unsigned int cpu)
{
- hardlockup_detector_perf_enable();
+ struct watchdog_nmi_status data;
+ int ret;
+
+ ret = hardlockup_detector_perf_enable();
+ /* No concurrent risk because BP executes this before smp_init() */
+ if (watchdog_enabled & NMI_WATCHDOG_UNDETERMINED
+ && status_reporter) {
+ data.cpu = cpu;
+ data.status = ret;
+ (*status_reporter)(&data);
+ }
}
void __weak watchdog_nmi_disable(unsigned int cpu)
@@ -130,7 +140,9 @@ static void watchdog_nmi_report_capability(struct watchdog_nmi_status *data)
*/
int __weak __init watchdog_nmi_probe(watchdog_nmi_status_reporter notifier)
{
- return hardlockup_detector_perf_init();
+ status_reporter = notifier;
+
+ return -EBUSY;
}
/**
diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c
index 6876e796dbf5..2894778fbc6d 100644
--- a/kernel/watchdog_hld.c
+++ b/kernel/watchdog_hld.c
@@ -190,16 +190,17 @@ static int hardlockup_detector_event_create(void)
/**
* hardlockup_detector_perf_enable - Enable the local event
*/
-void hardlockup_detector_perf_enable(void)
+int hardlockup_detector_perf_enable(void)
{
if (hardlockup_detector_event_create())
- return;
+ return -ENODEV;
/* use original value for check */
if (!atomic_fetch_inc(&watchdog_cpus))
pr_info("Enabled. Permanently consumes one hw-PMU counter.\n");
perf_event_enable(this_cpu_read(watchdog_ev));
+ return 0;
}
/**
@@ -281,19 +282,3 @@ void __init hardlockup_detector_perf_restart(void)
perf_event_enable(event);
}
}
-
-/**
- * hardlockup_detector_perf_init - Probe whether NMI event is available at all
- */
-int __init hardlockup_detector_perf_init(void)
-{
- int ret = hardlockup_detector_event_create();
-
- if (ret) {
- pr_info("Perf NMI watchdog permanently disabled\n");
- } else {
- perf_event_release_kernel(this_cpu_read(watchdog_ev));
- this_cpu_write(watchdog_ev, NULL);
- }
- return ret;
-}
--
2.31.1
next prev parent reply other threads:[~2021-09-15 3:51 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
2021-09-17 14:43 ` Pingfan Liu
2021-09-15 3:51 ` Pingfan Liu [this message]
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=20210915035103.15586-5-kernelfans@gmail.com \
--to=kernelfans@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=santosh@fossix.org \
--cc=wangqing@vivo.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