From patchwork Sun Dec 20 03:45:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoming Ni X-Patchwork-Id: 346308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 867C8C35270 for ; Sun, 20 Dec 2020 03:46:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6560A23A9D for ; Sun, 20 Dec 2020 03:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbgLTDp4 (ORCPT ); Sat, 19 Dec 2020 22:45:56 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10052 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgLTDp4 (ORCPT ); Sat, 19 Dec 2020 22:45:56 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cz7ks2h6JzM6xk; Sun, 20 Dec 2020 11:44:21 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Sun, 20 Dec 2020 11:45:07 +0800 From: Xiaoming Ni To: , , , , , , , , CC: , Subject: [PATCH v2 1/4] panic: Add new API in_panic_state() Date: Sun, 20 Dec 2020 11:45:02 +0800 Message-ID: <20201220034505.113118-2-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201220034505.113118-1-nixiaoming@huawei.com> References: <20201220034505.113118-1-nixiaoming@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 --- 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 From patchwork Sun Dec 20 03:45:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoming Ni X-Patchwork-Id: 346309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FCA7C3526E for ; Sun, 20 Dec 2020 03:46:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8C1F23AC0 for ; Sun, 20 Dec 2020 03:46:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727553AbgLTDqI (ORCPT ); Sat, 19 Dec 2020 22:46:08 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9542 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgLTDqA (ORCPT ); Sat, 19 Dec 2020 22:46:00 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cz7lB0RjHzhvJy; Sun, 20 Dec 2020 11:44:38 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Sun, 20 Dec 2020 11:45:08 +0800 From: Xiaoming Ni To: , , , , , , , , CC: , Subject: [PATCH v2 4/4] leds:trigger:ledtrig-heartbeat: Replace "panic_heartbeats" with in_panic_state() Date: Sun, 20 Dec 2020 11:45:05 +0800 Message-ID: <20201220034505.113118-5-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201220034505.113118-1-nixiaoming@huawei.com> References: <20201220034505.113118-1-nixiaoming@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Replace the global variable "panic_heartbeats" with in_panic_state() Signed-off-by: Xiaoming Ni --- drivers/leds/trigger/ledtrig-heartbeat.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c index 36b6709afe9f..f24d64cf0a62 100644 --- a/drivers/leds/trigger/ledtrig-heartbeat.c +++ b/drivers/leds/trigger/ledtrig-heartbeat.c @@ -19,8 +19,6 @@ #include #include "../leds.h" -static int panic_heartbeats; - struct heartbeat_trig_data { struct led_classdev *led_cdev; unsigned int phase; @@ -39,7 +37,7 @@ static void led_heartbeat_function(struct timer_list *t) led_cdev = heartbeat_data->led_cdev; - if (unlikely(panic_heartbeats)) { + if (unlikely(in_panic_state())) { led_set_brightness_nosleep(led_cdev, LED_OFF); return; } @@ -169,28 +167,15 @@ static int heartbeat_reboot_notifier(struct notifier_block *nb, return NOTIFY_DONE; } -static int heartbeat_panic_notifier(struct notifier_block *nb, - unsigned long code, void *unused) -{ - panic_heartbeats = 1; - return NOTIFY_DONE; -} - static struct notifier_block heartbeat_reboot_nb = { .notifier_call = heartbeat_reboot_notifier, }; -static struct notifier_block heartbeat_panic_nb = { - .notifier_call = heartbeat_panic_notifier, -}; - static int __init heartbeat_trig_init(void) { int rc = led_trigger_register(&heartbeat_led_trigger); if (!rc) { - atomic_notifier_chain_register(&panic_notifier_list, - &heartbeat_panic_nb); register_reboot_notifier(&heartbeat_reboot_nb); } return rc; @@ -199,8 +184,6 @@ static int __init heartbeat_trig_init(void) static void __exit heartbeat_trig_exit(void) { unregister_reboot_notifier(&heartbeat_reboot_nb); - atomic_notifier_chain_unregister(&panic_notifier_list, - &heartbeat_panic_nb); led_trigger_unregister(&heartbeat_led_trigger); }