From: brookxu <brookxu.cn@gmail.com>
To: adobriyan@gmail.com, bsingharora@gmail.com,
akpm@linux-foundation.org, ebiederm@xmission.com,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] delayacct: add a proc file to dump the delay info
Date: Mon, 19 Apr 2021 22:37:07 +0800 [thread overview]
Message-ID: <3da76d1d565c423c6cbf92b02cbae9f86cd5accd.1618841970.git.brookxu@tencent.com> (raw)
In-Reply-To: <8ac9f35074326cb36e3cdbf0ad70b36dc3412e86.1618841970.git.brookxu@tencent.com>
In-Reply-To: <8ac9f35074326cb36e3cdbf0ad70b36dc3412e86.1618841970.git.brookxu@tencent.com>
From: Chunguang Xu <brookxu@tencent.com>
Many distributions do not install the getdelay tool by
default, similar to task_io_accounting, adding a proc
file to make access easier.
v2: Fix some errors prompted by the kernel test robot.
Signed-off-by: Chunguang Xu <brookxu@tencent.com>
Reported-by: kernel test robot <lkp@intel.com>
---
fs/proc/base.c | 7 +++++++
kernel/delayacct.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b3422cd..4de261a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -96,6 +96,7 @@
#include <linux/posix-timers.h>
#include <linux/time_namespace.h>
#include <linux/resctrl.h>
+#include <linux/delayacct.h>
#include <trace/events/oom.h>
#include "internal.h"
#include "fd.h"
@@ -3244,6 +3245,9 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
#ifdef CONFIG_TASK_IO_ACCOUNTING
ONE("io", S_IRUSR, proc_tgid_io_accounting),
#endif
+#ifdef CONFIG_TASK_DELAY_ACCT
+ ONE("delays", S_IRUSR, proc_delayacct_show),
+#endif
#ifdef CONFIG_USER_NS
REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
@@ -3583,6 +3587,9 @@ static int proc_tid_comm_permission(struct inode *inode, int mask)
#ifdef CONFIG_TASK_IO_ACCOUNTING
ONE("io", S_IRUSR, proc_tid_io_accounting),
#endif
+#ifdef CONFIG_TASK_DELAY_ACCT
+ ONE("delays", S_IRUSR, proc_delayacct_show),
+#endif
#ifdef CONFIG_USER_NS
REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index ec580cb..87d091a 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -14,6 +14,7 @@
#include <linux/sysctl.h>
#include <linux/delayacct.h>
#include <linux/module.h>
+#include <linux/seq_file.h>
int delayacct_on __read_mostly = 1; /* Delay accounting turned on/off */
EXPORT_SYMBOL_GPL(delayacct_on);
@@ -26,6 +27,18 @@ static int __init delayacct_setup_disable(char *str)
}
__setup("nodelayacct", delayacct_setup_disable);
+struct delayacct_stat {
+ const char *name;
+ unsigned int idx;
+};
+
+static struct delayacct_stat delayacct_stats[] = {
+ {"blkio", DELAYACCT_BLKIO},
+ {"swapin", DELAYACCT_SWAPIN},
+ {"pagecache_thrashing", DELAYACCT_THRASHING},
+ {"mem_reclaim", DELAYACCT_FREEPAGES}
+};
+
void delayacct_init(void)
{
delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC|SLAB_ACCOUNT);
@@ -126,3 +139,31 @@ u64 __delayacct_blkio_ticks(struct task_struct *tsk)
return ret;
}
+#define K(x) ({ u64 _tmp = x; do_div(_tmp, 1000); _tmp; })
+
+int proc_delayacct_show(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task)
+{
+ struct delayacct_count *delays;
+ int idx;
+
+ if (!task->delays)
+ return 0;
+
+ delays = task->delays->delays;
+ for (idx = 0; idx < ARRAY_SIZE(delayacct_stats); idx++) {
+ u32 item = delayacct_stats[idx].idx;
+ u64 mean = delays[item].delay;
+
+ if (delays[item].count)
+ do_div(mean, delays[item].count);
+
+ seq_printf(m, "%s %llu %llu %u %llu\n",
+ delayacct_stats[idx].name,
+ K(mean),
+ K(delays[item].max),
+ delays[item].count,
+ K(delays[item].delay));
+ }
+ return 0;
+}
--
1.8.3.1
next prev parent reply other threads:[~2021-04-19 14:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 14:37 [PATCH v2 1/2] delayacct: refactor the code to simplify the implementation brookxu
2021-04-19 14:37 ` brookxu [this message]
2021-05-10 3:58 ` [PATCH v2 2/2] delayacct: add a proc file to dump the delay info Andrew Morton
2021-05-10 8:48 ` Balbir Singh
2021-05-11 1:10 ` brookxu
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=3da76d1d565c423c6cbf92b02cbae9f86cd5accd.1618841970.git.brookxu@tencent.com \
--to=brookxu.cn@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).