This will be used by kselftest to verify the CGroup cookie value that is
set by the CGroup interface.

Reviewed-by: Josh Don <josh...@google.com>
Tested-by: Julien Desfossez <jdesfos...@digitalocean.com>
Signed-off-by: Joel Fernandes (Google) <j...@joelfernandes.org>
---
 kernel/sched/core.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8f17ec8e993e..f1d9762b571a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -10277,6 +10277,21 @@ static u64 cpu_core_tag_color_read_u64(struct 
cgroup_subsys_state *css, struct c
        return tg->core_tag_color;
 }
 
+#ifdef CONFIG_SCHED_DEBUG
+static u64 cpu_core_group_cookie_read_u64(struct cgroup_subsys_state *css, 
struct cftype *cft)
+{
+       unsigned long group_cookie, color;
+
+       cpu_core_get_group_cookie_and_color(css_tg(css), &group_cookie, &color);
+
+       /*
+        * Combine group_cookie and color into a single 64 bit value, for
+        * display purposes only.
+        */
+       return (group_cookie << 32) | (color & 0xffffffff);
+}
+#endif
+
 struct write_core_tag {
        struct cgroup_subsys_state *css;
        unsigned long cookie;
@@ -10550,6 +10565,14 @@ static struct cftype cpu_legacy_files[] = {
                .read_u64 = cpu_core_tag_color_read_u64,
                .write_u64 = cpu_core_tag_color_write_u64,
        },
+#ifdef CONFIG_SCHED_DEBUG
+       /* Read the effective cookie (color+tag) of the group. */
+       {
+               .name = "core_group_cookie",
+               .flags = CFTYPE_NOT_ON_ROOT,
+               .read_u64 = cpu_core_group_cookie_read_u64,
+       },
+#endif
 #endif
 #ifdef CONFIG_UCLAMP_TASK_GROUP
        {
@@ -10737,6 +10760,14 @@ static struct cftype cpu_files[] = {
                .read_u64 = cpu_core_tag_color_read_u64,
                .write_u64 = cpu_core_tag_color_write_u64,
        },
+#ifdef CONFIG_SCHED_DEBUG
+       /* Read the effective cookie (color+tag) of the group. */
+       {
+               .name = "core_group_cookie",
+               .flags = CFTYPE_NOT_ON_ROOT,
+               .read_u64 = cpu_core_group_cookie_read_u64,
+       },
+#endif
 #endif
 #ifdef CONFIG_CFS_BANDWIDTH
        {
-- 
2.29.2.299.gdc1121823c-goog

Reply via email to