Skip to contentSkip to conversation

sched: Get group names back in /proc/sched_debug

PATCH In review Bharata B Rao 3 participants 7 messages Jan 10, 2011 – Jan 11, 2011

lore
Share & tools
lore
#0 lore raw

cover sched: Get group names back in /proc/sched_debug

Hi,

With autogroup patches, the group names got dropped off from /proc/sched_debug. Without group name info, it is difficult to figure out which cfs_rq or task belongs to which group in /proc/sched_debug output.

This patchset brings back the group name and also adds autogroup names to /proc/sched_debug output.

Before this patchset
====================

# grep cfs_rq /proc/sched_debug 
cfs_rq[0]:
cfs_rq[0]:
cfs_rq[1]:
cfs_rq[1]:
cfs_rq[2]:
cfs_rq[2]:
cfs_rq[3]:
cfs_rq[3]:
cfs_rq[4]:
cfs_rq[5]:
cfs_rq[6]:
cfs_rq[7]:
cfs_rq[8]:
cfs_rq[9]:
cfs_rq[10]:
cfs_rq[11]:
cfs_rq[12]:
cfs_rq[13]:
cfs_rq[13]:
cfs_rq[14]:
cfs_rq[14]:
cfs_rq[15]:
cfs_rq[15]:
# grep while1 /proc/sched_debug 
R         while1  2203     48420.920338      5007   120     48420.920338     48951.419166         7.485277
R         while1  2226     23823.872648      2865   120     23823.872648     28347.561387         3.988024
R         while1  2204     43006.490234      4851   120     43006.490234     48459.814725         0.000000

With this patchset
==================

# grep cfs_rq /proc/sched_debug 
cfs_rq[0]:/autogroup-52
cfs_rq[0]:/autogroup-0
cfs_rq[1]:/autogroup-54
cfs_rq[1]:/autogroup-0
cfs_rq[2]:/autogroup-51
cfs_rq[2]:/autogroup-0
cfs_rq[3]:/autogroup-0
cfs_rq[4]:/autogroup-50
cfs_rq[4]:/autogroup-0
cfs_rq[5]:/autogroup-11
cfs_rq[5]:/autogroup-0
cfs_rq[6]:/autogroup-0
cfs_rq[7]:/autogroup-0
cfs_rq[8]:/autogroup-13
cfs_rq[8]:/autogroup-0
cfs_rq[9]:/autogroup-0
cfs_rq[10]:/autogroup-52
cfs_rq[10]:/autogroup-0
cfs_rq[11]:/autogroup-52
cfs_rq[11]:/autogroup-0
cfs_rq[12]:/autogroup-0
cfs_rq[13]:/autogroup-0
cfs_rq[14]:/1
cfs_rq[14]:/autogroup-0
cfs_rq[15]:/autogroup-0
# grep while1 /proc/sched_debug 
R         while1  2208     38199.296761      3826   120     38199.296761     38200.395907         4.341835 /autogroup-54
R         while1  2205     31251.518310      5629   120     31251.518310     54431.493631         6.882145 /autogroup-50
R         while1  2206     43920.889967      5402   120     43920.889967     53954.315334         0.000000 /1

Regards,
Bharata.

#1 lore raw

PATCH 1/2 sched: Reinstate group names in /proc/sched_debug.

sched: Reinstate group names in /proc/sched_debug.

Displaying of group names in /proc/sched_debug was dropped in autogroup patches. Add group names while displaying cfs_rq and tasks information.

---
 kernel/sched_debug.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
kernel/sched_debug.c +34 -0
@@ -16,6 +16,9 @@
 #include <linux/kallsyms.h>
 #include <linux/utsname.h>
 
+static char group_path[PATH_MAX];
+static DEFINE_SPINLOCK(sched_debug_lock);
+
 /*
  * This allows printing both to /proc/sched_debug and
  * to the console
@@ -86,6 +89,23 @@ static void print_cfs_group_stats(struct
 }
 #endif
 
+#ifdef CONFIG_CGROUP_SCHED
+static char * task_group_path(struct task_group *tg)
+{
+	/*
+	 * May be NULL if the underlying cgroup isn't fully-created yet
+	 */
+	if (!tg->css.cgroup) {
+		group_path[0] = '\0';
+		return group_path;
+	}
+	rcu_read_lock();
+	cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
+	rcu_read_unlock();
+	return group_path;
+}
+#endif
+
 static void
 print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 {
@@ -108,6 +128,9 @@ print_task(struct seq_file *m, struct rq
 	SEQ_printf(m, "%15Ld %15Ld %15Ld.%06ld %15Ld.%06ld %15Ld.%06ld",
 		0LL, 0LL, 0LL, 0L, 0LL, 0L, 0LL, 0L);
 #endif
+#ifdef CONFIG_CGROUP_SCHED
+	SEQ_printf(m, " %s", task_group_path(task_group(p)));
+#endif
 
 	SEQ_printf(m, "\n");
 }
@@ -144,7 +167,11 @@ void print_cfs_rq(struct seq_file *m, in
 	struct sched_entity *last;
 	unsigned long flags;
 
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_FAIR_GROUP_SCHED)
+	SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
+#else
 	SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
+#endif
 	SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "exec_clock",
 			SPLIT_NS(cfs_rq->exec_clock));
 
@@ -191,7 +218,11 @@ void print_cfs_rq(struct seq_file *m, in
 
 void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
 {
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_RT_GROUP_SCHED)
+	SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, task_group_path(rt_rq->tg));
+#else
 	SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
+#endif
 
 #define P(x) \
 	SEQ_printf(m, "  .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
@@ -212,6 +243,7 @@ extern __read_mostly int sched_clock_run
 static void print_cpu(struct seq_file *m, int cpu)
 {
 	struct rq *rq = cpu_rq(cpu);
+	unsigned long flags;
 
 #ifdef CONFIG_X86
 	{
@@ -266,10 +298,12 @@ static void print_cpu(struct seq_file *m
 
 #undef P
 #endif
+	spin_lock_irqsave(&sched_debug_lock, flags);
 	print_cfs_stats(m, cpu);
 	print_rt_stats(m, cpu);
 
 	print_rq(m, rq, cpu);
+	spin_unlock_irqrestore(&sched_debug_lock, flags);
 }
 
 static const char *sched_tunable_scaling_names[] = {
#2 lore raw

Re: [PATCH -tip 1/2] sched: Reinstate group names in /proc/sched_debug.

kernel/sched_debug.c void print_cfs_rq(struct seq_file *m, in · line 170

Quoted 12 lines · Bharata B Rao

sched: Reinstate group names in /proc/sched_debug.

Displaying of group names in /proc/sched_debug was dropped in autogroup patches. Add group names while displaying cfs_rq and tasks information.

---

kernel/sched_debug.c +1 -0
@@ -144,7 +167,11 @@ void print_cfs_rq(struct seq_file *m, in
        struct sched_entity *last;
        unsigned long flags;
 
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_FAIR_GROUP_SCHED)

defined(CONFIG_CGROUP_SCHED) is not necessary here, CONFIG_[FAIR|RT]_GROUP_SCHED always imply CONFIG_CGROUP_SCHED

kernel/sched_debug.c void print_cfs_rq(struct seq_file *m, in · line 221

Quoted 12 lines
kernel/sched_debug.c +4 -0
+       SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, task_group_path(cfs_rq->tg));
+#else
        SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
+#endif
        SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "exec_clock",
                        SPLIT_NS(cfs_rq->exec_clock));
 
@@ -191,7 +218,11 @@ void print_cfs_rq(struct seq_file *m, in
 
  void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
  {
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_RT_GROUP_SCHED)

Ditto.

Thanks,
Yong

Signature · 1 line
Only stand for myself
#3 lore raw

Re: [PATCH -tip 1/2] sched: Reinstate group names in /proc/sched_debug.

Quoted 13 lines · Yong Zhang
Quoted 11 lines · Bharata B Rao

sched: Reinstate group names in /proc/sched_debug.

Displaying of group names in /proc/sched_debug was dropped in autogroup patches. Add group names while displaying cfs_rq and tasks information.

---

kernel/sched_debug.c +0 -0
@@ -144,7 +167,11 @@ void print_cfs_rq(struct seq_file *m, in
        struct sched_entity *last;
        unsigned long flags;
 
Quoted 4 lines

kernel/sched_debug.c void print_cfs_rq(struct seq_file *m, in · line 170

Quoted 1 line
kernel/sched_debug.c +1 -0
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_FAIR_GROUP_SCHED)

defined(CONFIG_CGROUP_SCHED) is not necessary here, CONFIG_[FAIR|RT]_GROUP_SCHED always imply CONFIG_CGROUP_SCHED

Took care of this in my latest post.

Thanks,
Bharata.

#4 lore raw

PATCH 2/2 sched: Display autogroup names in /proc/sched_debug.

In reply to Bharata B Rao

sched: Display autogroup names in /proc/sched_debug.

Add autogroup name to cfs_rq and tasks information in /proc/sched_debug.

---
 kernel/sched_debug.c |    8 ++++++++
 1 file changed, 8 insertions(+)
kernel/sched_debug.c +8 -0
@@ -92,6 +92,14 @@ static void print_cfs_group_stats(struct
 #ifdef CONFIG_CGROUP_SCHED
 static char * task_group_path(struct task_group *tg)
 {
+#ifdef CONFIG_SCHED_AUTOGROUP
+	int enabled = ACCESS_ONCE(sysctl_sched_autogroup_enabled);
+
+	if (enabled && tg->autogroup) {
+		autogroup_path(tg, group_path, PATH_MAX);
+		return group_path;
+	}
+#endif
 	/*
 	 * May be NULL if the underlying cgroup isn't fully-created yet
 	 */
#5 lore raw

Re: [PATCH -tip 2/2] sched: Display autogroup names in /proc/sched_debug.

Quoted 16 lines · Bharata B Rao

sched: Display autogroup names in /proc/sched_debug.

Add autogroup name to cfs_rq and tasks information in /proc/sched_debug.

---
 kernel/sched_debug.c |    8 ++++++++
 1 file changed, 8 insertions(+)
kernel/sched_debug.c +1 -0
@@ -92,6 +92,14 @@ static void print_cfs_group_stats(struct
 #ifdef CONFIG_CGROUP_SCHED
 static char * task_group_path(struct task_group *tg)
 {
+#ifdef CONFIG_SCHED_AUTOGROUP

kernel/sched_debug.c static void print_cfs_group_stats(struct · line 105

Quoted 10 lines
kernel/sched_debug.c +7 -0
+	int enabled = ACCESS_ONCE(sysctl_sched_autogroup_enabled);
+
+	if (enabled && tg->autogroup) {
+		autogroup_path(tg, group_path, PATH_MAX);
+		return group_path;
+	}
+#endif
 	/*
 	 * May be NULL if the underlying cgroup isn't fully-created yet
 	 */

What prevents the task being moved, and the task group being freed under you? Looks to me like task_group_path() needs rcu_read_lock(). It is locked in the other two instances. How about the below?

Date: Mon, 10 Jan 2011 10:46:43 +0530
From: Bharata B Rao <[email protected]>
To: [email protected]
Cc: Mike Galbraith <[email protected]>, Peter Zijlstra <[email protected]>, Ingo Molnar <[email protected]>
Subject: [PATCH -tip 2/2] sched: Display autogroup names in /proc/sched_debug.

sched: Display autogroup names in /proc/sched_debug.

Add autogroup name to cfs_rq and tasks information in /proc/sched_debug.

---
 kernel/sched_autogroup.c |    5 +++++
 kernel/sched_debug.c     |    7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
kernel/sched_debug.c +5 -2
Index: linux-2.6/kernel/sched_debug.c
===================================================================
@@ -92,6 +92,9 @@ static void print_cfs_group_stats(struct
 #ifdef CONFIG_CGROUP_SCHED
 static char * task_group_path(struct task_group *tg)
 {
+	if (autogroup_path(tg, group_path, PATH_MAX))
+		return group_path;
+
 	/*
 	 * May be NULL if the underlying cgroup isn't fully-created yet
 	 */
@@ -99,9 +102,7 @@ static char * task_group_path(struct tas
 		group_path[0] = '\0';
 		return group_path;
 	}
-	rcu_read_lock();
 	cgroup_path(tg->css.cgroup, group_path, PATH_MAX);
-	rcu_read_unlock();
 	return group_path;
 }
 #endif
@@ -302,7 +303,9 @@ static void print_cpu(struct seq_file *m
 	print_cfs_stats(m, cpu);
 	print_rt_stats(m, cpu);
 
+	rcu_read_lock();
 	print_rq(m, rq, cpu);
+	rcu_read_unlock();
 	spin_unlock_irqrestore(&sched_debug_lock, flags);
 }
 
kernel/sched_autogroup.c +5 -0
Index: linux-2.6/kernel/sched_autogroup.c
===================================================================
@@ -231,6 +231,11 @@ void proc_sched_autogroup_show_task(stru
 #ifdef CONFIG_SCHED_DEBUG
 static inline int autogroup_path(struct task_group *tg, char *buf, int buflen)
 {
+	int enabled = ACCESS_ONCE(sysctl_sched_autogroup_enabled);
+
+	if (!enabled || tg == &root_task_group)
+		return 0;
+
 	return snprintf(buf, buflen, "%s-%ld", "/autogroup", tg->autogroup->id);
 }
 #endif /* CONFIG_SCHED_DEBUG */
#6 lore raw

Re: [PATCH -tip 2/2] sched: Display autogroup names in /proc/sched_debug.

Quoted 23 lines · Mike Galbraith
Quoted 22 lines · Bharata B Rao

sched: Display autogroup names in /proc/sched_debug.

Add autogroup name to cfs_rq and tasks information in /proc/sched_debug.

---
 kernel/sched_debug.c |    8 ++++++++
 1 file changed, 8 insertions(+)
kernel/sched_debug.c +7 -0
@@ -92,6 +92,14 @@ static void print_cfs_group_stats(struct
 #ifdef CONFIG_CGROUP_SCHED
 static char * task_group_path(struct task_group *tg)
 {
+#ifdef CONFIG_SCHED_AUTOGROUP
+	int enabled = ACCESS_ONCE(sysctl_sched_autogroup_enabled);
+
+	if (enabled && tg->autogroup) {
+		autogroup_path(tg, group_path, PATH_MAX);
+		return group_path;
+	}
Quoted 8 lines

kernel/sched_debug.c static void print_cfs_group_stats(struct · line 100

Quoted 4 lines
kernel/sched_debug.c +1 -0
+#endif
 	/*
 	 * May be NULL if the underlying cgroup isn't fully-created yet
 	 */

What prevents the task being moved, and the task group being freed under you? Looks to me like task_group_path() needs rcu_read_lock(). It is locked in the other two instances. How about the below?

You are right, we need rcu_read_lock() there. Let me spin out an other version with the changes.

Thanks,
Bharata.