[PATCH] sched: skip autogroup when looking for all rt sched groups

From: Yong Zhang
Date: Wed Jun 22 2011 - 01:22:46 EST


From: Yong Zhang <yong.zhang0@xxxxxxxxx>
Subject: [PATCH] sched: skip autogroup when looking for all rt sched groups

Since [commit ec514c48: sched: Fix rt_rq runtime leakage bug],
'cat /proc/sched_debug' will print data of root_task_group.rt_rq
multi times, this is due to autogroup has no its own rt group,
instead rt group of autogroup is linked to root_task_group.

So skip it when we are looking for all rt sched groups, and it
will also save some noop operation against root_task_group when
__disable_runtime()/__enable_runtime().

Signed-off-by: Yong Zhang <yong.zhang0@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Mike Galbraith <efault@xxxxxx>
---

Since webmail may mangle the patch, attach it too.

kernel/sched_autogroup.h | 1 +
kernel/sched_rt.c | 29 ++++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/kernel/sched_autogroup.h b/kernel/sched_autogroup.h
index 0557705..c2f0e72 100644
--- a/kernel/sched_autogroup.h
+++ b/kernel/sched_autogroup.h
@@ -13,6 +13,7 @@ struct autogroup {
int nice;
};

+static inline bool task_group_is_autogroup(struct task_group *tg);
static inline struct task_group *
autogroup_task_group(struct task_struct *p, struct task_group *tg);

diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index 10d0182..8edf487 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -185,11 +185,30 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq)

typedef struct task_group *rt_rq_iter_t;

-#define for_each_rt_rq(rt_rq, iter, rq) \
- for (iter = list_entry_rcu(task_groups.next, typeof(*iter), list); \
- (&iter->list != &task_groups) && \
- (rt_rq = iter->rt_rq[cpu_of(rq)]); \
- iter = list_entry_rcu(iter->list.next, typeof(*iter), list))
+/* autogroup is not related to rt group, skip it */
+#define find_first_valid_task_group(iter) \
+ ({ \
+ list_for_each_entry_rcu(iter, &task_groups, list) \
+ if (!task_group_is_autogroup(iter)) \
+ break; \
+ iter; \
+ })
+
+#define find_next_valid_task_group(iter) \
+ ({ \
+ do { \
+ iter = list_entry_rcu(iter->list.next, \
+ typeof(*iter), list); \
+ } while (&iter->list != &task_groups && \
+ task_group_is_autogroup(iter)); \
+ iter; \
+ })
+
+#define for_each_rt_rq(rt_rq, iter, rq) \
+ for (find_first_valid_task_group(iter); \
+ (&iter->list != &task_groups) && \
+ (rt_rq = iter->rt_rq[cpu_of(rq)]); \
+ find_next_valid_task_group(iter))

static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq)
{
--
1.7.4.1
From 40117635a8f22a05a4eed98c40fcaf67ad90f738 Mon Sep 17 00:00:00 2001
From: Yong Zhang <yong.zhang0@xxxxxxxxx>
Date: Wed, 22 Jun 2011 12:52:40 +0800
Subject: [PATCH] sched: skip autogroup when looking for all rt sched groups

Since [commit ec514c48: sched: Fix rt_rq runtime leakage bug],
'cat /proc/sched_debug' will print data of root_task_group.rt_rq
multi times, this is due to autogroup has no its own rt group,
instead rt group of autogroup is linked to root_task_group.

So skip it when we are looking for all rt sched groups, and it
will also save some noop operation against root_task_group when
__disable_runtime()/__enable_runtime().

Signed-off-by: Yong Zhang <yong.zhang0@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Mike Galbraith <efault@xxxxxx>
---

Since webmail may mangle the patch, attach it too.

kernel/sched_autogroup.h | 1 +
kernel/sched_rt.c | 29 ++++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/kernel/sched_autogroup.h b/kernel/sched_autogroup.h
index 0557705..c2f0e72 100644
--- a/kernel/sched_autogroup.h
+++ b/kernel/sched_autogroup.h
@@ -13,6 +13,7 @@ struct autogroup {
int nice;
};

+static inline bool task_group_is_autogroup(struct task_group *tg);
static inline struct task_group *
autogroup_task_group(struct task_struct *p, struct task_group *tg);

diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index 10d0182..8edf487 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -185,11 +185,30 @@ static inline u64 sched_rt_period(struct rt_rq *rt_rq)

typedef struct task_group *rt_rq_iter_t;

-#define for_each_rt_rq(rt_rq, iter, rq) \
- for (iter = list_entry_rcu(task_groups.next, typeof(*iter), list); \
- (&iter->list != &task_groups) && \
- (rt_rq = iter->rt_rq[cpu_of(rq)]); \
- iter = list_entry_rcu(iter->list.next, typeof(*iter), list))
+/* autogroup is not related to rt group, skip it */
+#define find_first_valid_task_group(iter) \
+ ({ \
+ list_for_each_entry_rcu(iter, &task_groups, list) \
+ if (!task_group_is_autogroup(iter)) \
+ break; \
+ iter; \
+ })
+
+#define find_next_valid_task_group(iter) \
+ ({ \
+ do { \
+ iter = list_entry_rcu(iter->list.next, \
+ typeof(*iter), list); \
+ } while (&iter->list != &task_groups && \
+ task_group_is_autogroup(iter)); \
+ iter; \
+ })
+
+#define for_each_rt_rq(rt_rq, iter, rq) \
+ for (find_first_valid_task_group(iter); \
+ (&iter->list != &task_groups) && \
+ (rt_rq = iter->rt_rq[cpu_of(rq)]); \
+ find_next_valid_task_group(iter))

static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq)
{
--
1.7.4.1