linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] tg: count the sum wait time of an task group
@ 2018-07-02  7:29 王贇
  2018-07-02 12:03 ` Peter Zijlstra
  2018-07-03  5:42 ` [PATCH] tg: show " 王贇
  0 siblings, 2 replies; 11+ messages in thread
From: 王贇 @ 2018-07-02  7:29 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, linux-kernel

Although we can rely on cpuacct to present the cpu usage of task
group, it is hard to tell how intense the competition is between
these groups on cpu resources.

Monitoring the wait time of each process could cost too much, and
there is no good way to accurately represent the conflict with
these info, we need the wait time on group dimension.

Thus we introduced group's wait_sum provided by kernel to represent
the conflict between task groups, whenever a group's cfs_rq ends
waiting, it's wait time accounted to the sum.

The cpu.stat is modified to show the new statistic, like:

   nr_periods 0
   nr_throttled 0
   throttled_time 0
   wait_sum 2035098795584

Now we can monitor the changing on wait_sum to tell how suffering
a task group is in the fight of cpu resources.

Signed-off-by: Michael Wang <yun.wang@linux.alibaba.com>
---
  kernel/sched/core.c  | 2 ++
  kernel/sched/fair.c  | 4 ++++
  kernel/sched/sched.h | 1 +
  3 files changed, 7 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 78d8fac..ac27b8d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6787,6 +6787,8 @@ static int cpu_cfs_stat_show(struct seq_file *sf, 
void *v)
  	seq_printf(sf, "nr_periods %d\n", cfs_b->nr_periods);
  	seq_printf(sf, "nr_throttled %d\n", cfs_b->nr_throttled);
  	seq_printf(sf, "throttled_time %llu\n", cfs_b->throttled_time);
+	if (schedstat_enabled())
+		seq_printf(sf, "wait_sum %llu\n", tg->wait_sum);

  	return 0;
  }
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 1866e64..ef82ceb 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -862,6 +862,7 @@ static void update_curr_fair(struct rq *rq)
  static inline void
  update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
  {
+	struct task_group *tg;
  	struct task_struct *p;
  	u64 delta;

@@ -882,6 +883,9 @@ static void update_curr_fair(struct rq *rq)
  			return;
  		}
  		trace_sched_stat_wait(p, delta);
+	} else {
+		tg = group_cfs_rq(se)->tg;
+		__schedstat_add(tg->wait_sum, delta);
  	}

  	__schedstat_set(se->statistics.wait_max,
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6601baf..bb9b4fb 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -358,6 +358,7 @@ struct task_group {
  	/* runqueue "owned" by this group on each CPU */
  	struct cfs_rq		**cfs_rq;
  	unsigned long		shares;
+	u64			wait_sum;

  #ifdef	CONFIG_SMP
  	/*
-- 
1.8.3.1


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

end of thread, other threads:[~2018-07-25 14:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02  7:29 [RFC PATCH] tg: count the sum wait time of an task group 王贇
2018-07-02 12:03 ` Peter Zijlstra
2018-07-03  2:10   ` 王贇
2018-07-03  5:42 ` [PATCH] tg: show " 王贇
2018-07-04  3:27   ` [PATCH v2] " 王贇
2018-07-09  9:12     ` 王贇
2018-07-17  3:28     ` 王贇
2018-07-23  9:31     ` Peter Zijlstra
2018-07-23 12:32       ` 王贇
2018-07-23 13:31     ` [PATCH v3] " 王贇
2018-07-25 14:23     ` [tip:sched/core] sched/debug: Show the sum wait time of a " tip-bot for Yun Wang

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).