mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hung_task: Migrate hung_task_detect_count to sysfs
@ 2025-11-29 23:51 Aaron Tomlin
  2025-11-30  5:43 ` Lance Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Aaron Tomlin @ 2025-11-29 23:51 UTC (permalink / raw)
  To: akpm, lance.yang, mhiramat, gregkh; +Cc: linux-kernel

The hung_task_detect_count metric, which tracks the cumulative number of
tasks detected as hung since boot, is currently exposed via the legacy
/proc/sys/kernel/hung_task_detect_count sysctl file.

Migrate this metric to a read-only file in the /sys/kernel/ hierarchy:
/sys/kernel/hung_task_detect_count. The sysctl file is removed, and the
metric is now controlled by the CONFIG_SYSFS Kconfig option.

This patch is made to continue the effort of moving read-only
statistics and counters out of the /proc/sys/ hierarchy and into the
more appropriate /sys filesystem. The internal variable is renamed from
sysctl_hung_task_detect_count to hung_task_detect_count and its
increment logic is updated to use the more efficient prefix form.

The documentation is updated to reflect the removal of the sysctl entry.

Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
 .../sysfs-kernel-hung_task_detect_count       |  7 ++++
 Documentation/admin-guide/sysctl/kernel.rst   |  9 ----
 kernel/hung_task.c                            | 42 +++++++++++--------
 3 files changed, 31 insertions(+), 27 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count

diff --git a/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count b/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count
new file mode 100644
index 000000000000..92ee79ccfe6d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count
@@ -0,0 +1,7 @@
+What:		/sys/kernel/hung_task_detect_count
+Date:		Nov 2025
+KernelVersion:	6.18
+Contact:	Linux kernel mailing list <linux-kernel@vger.kernel.org>
+Description:
+        Indicates the total number of tasks that have been detected as hung since
+        the system boot.
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index f3ee807b5d8b..4d9b7b18712f 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -413,15 +413,6 @@ The upper bound on the number of tasks that are checked.
 This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
 
 
-hung_task_detect_count
-======================
-
-Indicates the total number of tasks that have been detected as hung since
-the system boot.
-
-This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
-
-
 hung_task_timeout_secs
 ======================
 
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index b2c1f14b8129..8f4371ac6837 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -32,10 +32,27 @@
  */
 static int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT;
 
-/*
- * Total number of tasks detected as hung since boot:
- */
-static unsigned long __read_mostly sysctl_hung_task_detect_count;
+#ifdef CONFIG_SYSFS
+/* Total number of tasks detected as hung since boot */
+static unsigned long hung_task_detect_count;
+
+static ssize_t hung_task_detect_count_show(struct kobject *kobj,
+					   struct kobj_attribute *attr,
+					   char *page)
+{
+	return sysfs_emit(page, "%lu\n", hung_task_detect_count);
+}
+
+static struct kobj_attribute hung_task_detect_count_attr = __ATTR_RO(hung_task_detect_count);
+
+static __init int kernel_hung_task_detect_sysfs_init(void)
+{
+	sysfs_add_file_to_group(kernel_kobj,
+				&hung_task_detect_count_attr.attr, NULL);
+	return 0;
+}
+late_initcall(kernel_hung_task_detect_sysfs_init);
+#endif
 
 /*
  * Limit number of tasks checked in a batch.
@@ -222,13 +239,9 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
 {
 	if (!task_is_hung(t, timeout))
 		return;
-
-	/*
-	 * This counter tracks the total number of tasks detected as hung
-	 * since boot.
-	 */
-	sysctl_hung_task_detect_count++;
-
+#ifdef CONFIG_SYSFS
+	++hung_task_detect_count;
+#endif
 	trace_sched_process_hang(t);
 
 	if (sysctl_hung_task_panic) {
@@ -423,13 +436,6 @@ static const struct ctl_table hung_task_sysctls[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_NEG_ONE,
 	},
-	{
-		.procname	= "hung_task_detect_count",
-		.data		= &sysctl_hung_task_detect_count,
-		.maxlen		= sizeof(unsigned long),
-		.mode		= 0444,
-		.proc_handler	= proc_doulongvec_minmax,
-	},
 };
 
 static void __init hung_task_sysctl_init(void)
-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-01 22:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-29 23:51 [PATCH] hung_task: Migrate hung_task_detect_count to sysfs Aaron Tomlin
2025-11-30  5:43 ` Lance Yang
2025-11-30  8:30   ` Greg KH
2025-11-30 17:11   ` Aaron Tomlin
2025-12-01  3:08     ` Lance Yang
2025-12-01 22:57       ` Aaron Tomlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®