linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoming Ni <nixiaoming@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-leds@vger.kernel.org>,
	<pavel@ucw.cz>, <dmurphy@ti.com>, <akpm@linux-foundation.org>,
	<keescook@chromium.org>, <gpiccoli@canonical.com>,
	<penguin-kernel@i-love.sakura.ne.jp>, <rdunlap@infradead.org>
Cc: <nixiaoming@huawei.com>, <wangle6@huawei.com>
Subject: [PATCH v2 1/4] panic: Add new API in_panic_state()
Date: Sun, 20 Dec 2020 11:45:02 +0800	[thread overview]
Message-ID: <20201220034505.113118-2-nixiaoming@huawei.com> (raw)
In-Reply-To: <20201220034505.113118-1-nixiaoming@huawei.com>

For some features (such as hang_task, ledtrig-activity, ledtrig-heartbeat)
different processing logics need to be performed based on whether the
current system is in panic state:
	1: Register hook for panic_notifier_list.
	2. Assign a value to the global variable in the hook function.
	3. Determine whether the system is in panic state based on the
          global variable and perform different processing.
Duplicate code snippets exist, and the timing judgment is relatively lag.
Therefore, consider extracting the new API: bool in_panic_state(void).

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 include/linux/kernel.h | 1 +
 kernel/panic.c         | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f7902d8c1048..c9a9078157b6 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -167,6 +167,7 @@ void __might_fault(const char *file, int line);
 static inline void might_fault(void) { }
 #endif
 
+extern bool in_panic_state(void);
 extern struct atomic_notifier_head panic_notifier_list;
 extern long (*panic_blink)(int state);
 __printf(1, 2)
diff --git a/kernel/panic.c b/kernel/panic.c
index 332736a72a58..351627883a04 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -125,6 +125,12 @@ void __weak crash_smp_send_stop(void)
 
 atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
 
+bool in_panic_state(void)
+{
+	return (atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
+}
+EXPORT_SYMBOL(in_panic_state);
+
 /*
  * A variant of panic() called from NMI context. We return if we've already
  * panicked on this CPU. If another CPU already panicked, loop in
-- 
2.27.0


  reply	other threads:[~2020-12-20  3:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-20  3:45 [PATCH v2 0/4] panic: Add new API in_panic_state() Xiaoming Ni
2020-12-20  3:45 ` Xiaoming Ni [this message]
2020-12-20  3:45 ` [PATCH v2 2/4] hung_task: Replace "did_panic" with in_panic_state() Xiaoming Ni
2020-12-20  3:45 ` [PATCH v2 3/4] leds:trigger:ledtrig-activity Replace "panic_detected" " Xiaoming Ni
2020-12-20  3:45 ` [PATCH v2 4/4] leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" " Xiaoming Ni

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=20201220034505.113118-2-nixiaoming@huawei.com \
    --to=nixiaoming@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=dmurphy@ti.com \
    --cc=gpiccoli@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=rdunlap@infradead.org \
    --cc=wangle6@huawei.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;
as well as URLs for NNTP newsgroup(s).