@@ -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)
@@ -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
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(+)