mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aaron Tomlin <atomlin@atomlin.com>
To: akpm@linux-foundation.org, lance.yang@linux.dev,
	mhiramat@kernel.org, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] hung_task: Migrate hung_task_detect_count to sysfs
Date: Sat, 29 Nov 2025 18:51:59 -0500	[thread overview]
Message-ID: <20251129235159.1227977-1-atomlin@atomlin.com> (raw)

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


             reply	other threads:[~2025-11-29 23:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-29 23:51 Aaron Tomlin [this message]
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

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=20251129235159.1227977-1-atomlin@atomlin.com \
    --to=atomlin@atomlin.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lance.yang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    /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

all inboxes | Powered by JetHome®