[PATCH v8 -tip 21/26] sched: Handle task addition to CGroup

From: Joel Fernandes (Google)
Date: Mon Oct 19 2020 - 21:45:00 EST


Due to earlier patches, the old way of computing a task's cookie when it
is added to a CGroup,is outdated. Update it by fetching the group's
cookie using the new helpers.

Tested-by: Julien Desfossez <jdesfossez@xxxxxxxxxxxxxxxx>
Signed-off-by: Joel Fernandes (Google) <joel@xxxxxxxxxxxxxxxxx>
---
kernel/sched/core.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 61e1dcf11000..1321c26a8385 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8505,6 +8505,9 @@ void sched_offline_group(struct task_group *tg)
spin_unlock_irqrestore(&task_group_lock, flags);
}

+#define SCHED_CORE_GROUP_COOKIE_MASK ((1UL << (sizeof(unsigned long) * 4)) - 1)
+static unsigned long cpu_core_get_group_cookie(struct task_group *tg);
+
static void sched_change_group(struct task_struct *tsk, int type)
{
struct task_group *tg;
@@ -8519,11 +8522,13 @@ static void sched_change_group(struct task_struct *tsk, int type)
tg = autogroup_task_group(tsk, tg);

#ifdef CONFIG_SCHED_CORE
- if ((unsigned long)tsk->sched_task_group == tsk->core_cookie)
- tsk->core_cookie = 0UL;
+ if (tsk->core_group_cookie) {
+ tsk->core_group_cookie = 0UL;
+ tsk->core_cookie &= ~SCHED_CORE_GROUP_COOKIE_MASK;
+ }

- if (tg->core_tagged /* && !tsk->core_cookie ? */)
- tsk->core_cookie = (unsigned long)tg;
+ tsk->core_group_cookie = cpu_core_get_group_cookie(tg);
+ tsk->core_cookie |= tsk->core_group_cookie;
#endif

tsk->sched_task_group = tg;
@@ -9471,7 +9476,7 @@ static unsigned long cpu_core_get_group_cookie(struct task_group *tg)

if (tg->core_tagged) {
unsigned long cookie = ((unsigned long)tg << 8) | color;
- cookie &= (1UL << (sizeof(unsigned long) * 4)) - 1;
+ cookie &= SCHED_CORE_GROUP_COOKIE_MASK;
return cookie;
}
}
--
2.29.0.rc1.297.gfa9743e501-goog