Skip to content
Permalink
Browse files
delayacct: Add a proc file to dump the delay info
Many distributions do not install the getdelay tool by
default, similar to task_io_accounting, adding a proc
file to make access easier.

Signed-off-by: Chunguang Xu <brookxu@tencent.com>
  • Loading branch information
brookxu-tx authored and intel-lab-lkp committed Apr 13, 2021
1 parent 37860ad commit 7023a409dec95195a0e3360a36e8cb66363a9457
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
@@ -95,6 +95,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"
@@ -3243,6 +3244,9 @@ static const struct pid_entry tgid_base_stuff[] = {
#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 const struct pid_entry tid_base_stuff[] = {
#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),
@@ -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;
};

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) ((x) / 1000)

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 = 0;

if (delays[item].count)
mean = div_u64(delays[item].delay, 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;
}

0 comments on commit 7023a40

Please sign in to comment.