Skip to contentSkip to conversation

sysfs: add counters for lockups and stalls

PATCH In review Max Kellermann 3 participants 6 messages May 4, 2025 – Jun 4, 2025 RCU

lore
Share & tools
lore
#0 lore raw

v2 cover sysfs: add counters for lockups and stalls

Commits 9db89b411170 ("exit: Expose "oops_count" to sysfs") and 8b05aa263361 ("panic: Expose "warn_count" to sysfs") added counters for oopses and warnings to sysfs, and these two patches do the same for hard/soft lockups and RCU stalls.

All of these counters are useful for monitoring tools to detect whether the machine is healthy. If the kernel has experienced a lockup or a stall, it's probably due to a kernel bug, and I'd like to detect that quickly and easily. There is currently no way to detect that, other than parsing dmesg. Or observing indirect effects: such as certain tasks not responding, but then I need to observe all tasks, and it may take a while until these effects become visible/measurable. I'd rather be able to detect the primary cause more quickly, possibly before everything falls apart.

Max Kellermann (2):
kernel/watchdog: add /sys/kernel/{hard,soft}lockup_count kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

 .../ABI/testing/sysfs-kernel-hardlockup_count |  7 +++
 .../ABI/testing/sysfs-kernel-rcu_stall_count  |  6 +++
 .../ABI/testing/sysfs-kernel-softlockup_count |  7 +++
 kernel/rcu/tree_stall.h                       | 26 +++++++++
 kernel/watchdog.c                             | 53 +++++++++++++++++++
 5 files changed, 99 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-hardlockup_count
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-rcu_stall_count
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-softlockup_count
Signature · 1 line
2.47.2
#1 lore raw

PATCH v2 1/2 kernel/watchdog: add /sys/kernel/{hard,soft}lockup_count

There is /proc/sys/kernel/hung_task_detect_count, /sys/kernel/warn_count and /sys/kernel/oops_count but there is no userspace-accessible counter for hard/soft lockups. Having this is useful for monitoring tools.

---
v1 -> v2: added documentation; added patch set cover letter with
justification

---
 .../ABI/testing/sysfs-kernel-hardlockup_count |  7 +++
 .../ABI/testing/sysfs-kernel-softlockup_count |  7 +++
 kernel/watchdog.c                             | 53 +++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-hardlockup_count
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-softlockup_count
Documentation/ABI/testing/sysfs-kernel-hardlockup_count new file +7 -0
new file mode 100644
index 000000000000..dfdd4078b077
@@ -0,0 +1,7 @@
+What:		/sys/kernel/hardlockup_count
+Date:		May 2025
+KernelVersion:	6.16
+Contact:	Linux kernel mailing list <[email protected]>
+Description:
+		Shows how many times the system has detected a hard lockup since last boot.
+		Available only if CONFIG_HARDLOCKUP_DETECTOR is enabled.
Documentation/ABI/testing/sysfs-kernel-softlockup_count new file +7 -0
new file mode 100644
index 000000000000..337ff5531b5f
@@ -0,0 +1,7 @@
+What:		/sys/kernel/softlockup_count
+Date:		May 2025
+KernelVersion:	6.16
+Contact:	Linux kernel mailing list <[email protected]>
+Description:
+		Shows how many times the system has detected a soft lockup since last boot.
+		Available only if CONFIG_SOFTLOCKUP_DETECTOR is enabled.
kernel/watchdog.c +53 -0

77 lines not on this page · raw message

Signature · 1 line
2.47.2
#2 lore raw

PATCH v2 2/2 kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

In reply to Max Kellermann

Exposing a simple counter to userspace for monitoring tools.

---
v1 -> v2: added documentation

---
 .../ABI/testing/sysfs-kernel-rcu_stall_count  |  6 +++++
 kernel/rcu/tree_stall.h                       | 26 +++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-rcu_stall_count
Documentation/ABI/testing/sysfs-kernel-rcu_stall_count new file +6 -0
new file mode 100644
index 000000000000..a4a97a7f4a4d
@@ -0,0 +1,6 @@
+What:		/sys/kernel/rcu_stall_count
+Date:		May 2025
+KernelVersion:	6.16
+Contact:	Linux kernel mailing list <[email protected]>
+Description:
+		Shows how many times the system has detected an RCU stall since last boot.
kernel/rcu/tree_stall.h +26 -0
index 925fcdad5dea..158330524795 100644
@@ -20,6 +20,28 @@
 int sysctl_panic_on_rcu_stall __read_mostly;
 int sysctl_max_rcu_stall_to_panic __read_mostly;
 
+#ifdef CONFIG_SYSFS
+
+static unsigned int rcu_stall_count;
+
+static ssize_t rcu_stall_count_show(struct kobject *kobj, struct kobj_attribute *attr,
+				    char *page)
+{
+	return sysfs_emit(page, "%u\n", rcu_stall_count);
+}
+
+static struct kobj_attribute rcu_stall_count_attr = __ATTR_RO(rcu_stall_count);
+
+static __init int kernel_rcu_stall_sysfs_init(void)
+{
+	sysfs_add_file_to_group(kernel_kobj, &rcu_stall_count_attr.attr, NULL);
+	return 0;
+}
+
+late_initcall(kernel_rcu_stall_sysfs_init);
+
+#endif // CONFIG_SYSFS
+
 #ifdef CONFIG_PROVE_RCU
 #define RCU_STALL_DELAY_DELTA		(5 * HZ)
 #else
@@ -784,6 +806,10 @@ static void check_cpu_stall(struct rcu_data *rdp)
 		if (kvm_check_and_clear_guest_paused())
 			return;
 
+#ifdef CONFIG_SYSFS
+		++rcu_stall_count;
+#endif
+
 		rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_NORM, (void *)j - gps);
 		if (READ_ONCE(csd_lock_suppress_rcu_stall) && csd_lock_is_stuck()) {
 			pr_err("INFO: %s detected stall, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);
Signature · 1 line
2.47.2
#3 lore raw

Re: [PATCH v2 2/2] kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

Hello Andrew,

Quoted 57 lines · Max Kellermann

Exposing a simple counter to userspace for monitoring tools.

---
v1 -> v2: added documentation

---
  .../ABI/testing/sysfs-kernel-rcu_stall_count  |  6 +++++
  kernel/rcu/tree_stall.h                       | 26 +++++++++++++++++++
  2 files changed, 32 insertions(+)

create mode 100644 Documentation/ABI/testing/sysfs-kernel-rcu_stall_count

Documentation/ABI/testing/sysfs-kernel-rcu_stall_count new file +6 -0
new file mode 100644
index 000000000000..a4a97a7f4a4d
@@ -0,0 +1,6 @@
+What:		/sys/kernel/rcu_stall_count
+Date:		May 2025
+KernelVersion:	6.16
+Contact:	Linux kernel mailing list <[email protected]>
+Description:
+		Shows how many times the system has detected an RCU stall since last boot.
kernel/rcu/tree_stall.h +22 -0
index 925fcdad5dea..158330524795 100644
@@ -20,6 +20,28 @@
  int sysctl_panic_on_rcu_stall __read_mostly;
  int sysctl_max_rcu_stall_to_panic __read_mostly;
 
+#ifdef CONFIG_SYSFS
+
+static unsigned int rcu_stall_count;
+
+static ssize_t rcu_stall_count_show(struct kobject *kobj, struct kobj_attribute *attr,
+				    char *page)
+{
+	return sysfs_emit(page, "%u\n", rcu_stall_count);
+}
+
+static struct kobj_attribute rcu_stall_count_attr = __ATTR_RO(rcu_stall_count);
+
+static __init int kernel_rcu_stall_sysfs_init(void)
+{
+	sysfs_add_file_to_group(kernel_kobj, &rcu_stall_count_attr.attr, NULL);
+	return 0;
+}
+
+late_initcall(kernel_rcu_stall_sysfs_init);
+
+#endif // CONFIG_SYSFS
+
  #ifdef CONFIG_PROVE_RCU
  #define RCU_STALL_DELAY_DELTA		(5 * HZ)
  #else

kernel/rcu/tree_stall.h static void check_cpu_stall(struct rcu_data *rdp) · line 815

Quoted 10 lines
kernel/rcu/tree_stall.h +4 -0
@@ -784,6 +806,10 @@ static void check_cpu_stall(struct rcu_data *rdp)
  		if (kvm_check_and_clear_guest_paused())
  			return;
 
+#ifdef CONFIG_SYSFS
+		++rcu_stall_count;
+#endif
+
  		rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_NORM, (void *)j - gps);
  		if (READ_ONCE(csd_lock_suppress_rcu_stall) && csd_lock_is_stuck()) {
  			pr_err("INFO: %s detected stall, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);

It seems like this patch was not applied properly to the upstream tree.

Out of the three hunks in this patch, only the first one is applied; the second and third hunks are missing.

commit 2536c5c7d6ae5e1d844aa21f28b326b5e7f815ef
Author: Max Kellermann <[email protected]>
Date:   Sun May 4 20:08:31 2025 +0200

    kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

    Expose a simple counter to userspace for monitoring tools.

Thanks,
Sourabh Jain

#4 lore raw

Re: [PATCH v2 2/2] kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

Quoted 14 lines · On Tue, 3 Jun 2025 22:09:30 +0530 Sourabh Jain <[email protected]>…

Hello Andrew,

kernel/rcu/tree_stall.h static void check_cpu_stall(struct rcu_data *rdp) · line 815

Quoted 5 lines
kernel/rcu/tree_stall.h +2 -0
+#endif
+
  		rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_NORM, (void *)j - gps);
  		if (READ_ONCE(csd_lock_suppress_rcu_stall) && csd_lock_is_stuck()) {
  			pr_err("INFO: %s detected stall, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);

It seems like this patch was not applied properly to the upstream tree.

Out of the three hunks in this patch, only the first one is applied; the second
and third hunks are missing.

Quoted 7 lines

commit 2536c5c7d6ae5e1d844aa21f28b326b5e7f815ef
Author: Max Kellermann <[email protected]>
Date:   Sun May 4 20:08:31 2025 +0200

    kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

    Expose a simple counter to userspace for monitoring tools.

OK. iirc there was quite a lot of churn and conflicts here :)

Please send a fixup against latest -linus?

#5 lore raw

Re: [PATCH v2 2/2] kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

Quoted 19 lines · Andrew Morton
Quoted 17 lines · On Tue, 3 Jun 2025 22:09:30 +0530 Sourabh Jain <[email protected]>…

Hello Andrew,

kernel/rcu/tree_stall.h static void check_cpu_stall(struct rcu_data *rdp) · line 815

Quoted 5 lines
kernel/rcu/tree_stall.h +2 -0
+#endif
+
   		rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_NORM, (void *)j - gps);
   		if (READ_ONCE(csd_lock_suppress_rcu_stall) && csd_lock_is_stuck()) {
   			pr_err("INFO: %s detected stall, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);

It seems like this patch was not applied properly to the upstream tree.

Out of the three hunks in this patch, only the first one is applied; the second
and third hunks are missing.

commit 2536c5c7d6ae5e1d844aa21f28b326b5e7f815ef
Author: Max Kellermann <[email protected]>
Date:   Sun May 4 20:08:31 2025 +0200

Quoted 6 lines
Quoted 3 lines

    kernel/rcu/tree_stall: add /sys/kernel/rcu_stall_count

    Expose a simple counter to userspace for monitoring tools.

OK. iirc there was quite a lot of churn and conflicts here :)

Please send a fixup against latest -linus?

Sure, I will wait for a day or two to see if Max is interested in sending the fix-up patch. Otherwise, I will send it.

Thanks,
Sourabh Jain