From 2abfd07b1c1a62af4bb5ac8f3f3f6fc3ed4ba82c Mon Sep 17 00:00:00 2001 From: Yihao Wu Date: Thu, 18 Jun 2020 18:30:20 +0800 Subject: [PATCH 1465/2944] alinux: sched: Add "nr" to sched latency histogram to #28739709 Sometimes histogram is not precise enough because each sample is roughly accounted into a histogram bar. And average latency is more pratical for some users. This patch adds a "nr" field in 4 latency histogram interfaces, so lat(avg) = total(ms) / nr And compared to histogram, average latency is better to be used as a SLI because of simplicity. Example $ cat /sys/fs/cgroup/cpuacct/a/cpuacct.wait_latency 0-1ms: 4139 1-4ms: 317 4-7ms: 568 7-10ms: 0 10-100ms: 42324 100-500ms: 9131 500-1000ms: 95 1000-5000ms: 134 5000-10000ms: 0 >=10000ms: 0 total(ms): 4256455 nr: 182128 Signed-off-by: Yihao Wu Acked-by: Michael Wang --- kernel/sched/cpuacct.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 68569a5..ee5e966 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -67,6 +67,7 @@ enum sched_lat_count_t { SCHED_LAT_5000_10000, SCHED_LAT_10000_INF, SCHED_LAT_TOTAL, + SCHED_LAT_NR, SCHED_LAT_NR_COUNT, }; @@ -258,6 +259,7 @@ void task_ca_update_block(struct task_struct *tsk, u64 runtime) msecs = runtime >> 20; /* Proximately to speed up */ idx = get_sched_lat_count_idx(msecs); this_cpu_inc(ca->lat_stat_cpu->item[s][idx]); + this_cpu_inc(ca->lat_stat_cpu->item[s][SCHED_LAT_NR]); this_cpu_add(ca->lat_stat_cpu->item[s][SCHED_LAT_TOTAL], runtime); rcu_read_unlock(); } @@ -284,6 +286,7 @@ void cpuacct_update_latency(struct sched_entity *se, u64 delta) msecs = delta >> 20; /* Proximately to speed up */ idx = get_sched_lat_count_idx(msecs); this_cpu_inc(ca->lat_stat_cpu->item[s][idx]); + this_cpu_inc(ca->lat_stat_cpu->item[s][SCHED_LAT_NR]); this_cpu_add(ca->lat_stat_cpu->item[s][SCHED_LAT_TOTAL], delta); rcu_read_unlock(); } @@ -888,6 +891,8 @@ static int sched_lat_stat_show(struct seq_file *sf, void *v) sched_lat_stat_gather(ca, s, SCHED_LAT_10000_INF)); seq_printf(sf, "total(ms): \t%llu\n", sched_lat_stat_gather(ca, s, SCHED_LAT_TOTAL) / 1000000); + seq_printf(sf, "nr: \t%llu\n", + sched_lat_stat_gather(ca, s, SCHED_LAT_NR)); return 0; } -- 1.8.3.1