On Mon, Oct 19, 2020 at 6:45 PM Joel Fernandes (Google) <j...@joelfernandes.org> wrote: > > +static unsigned long cpu_core_get_group_cookie(struct task_group *tg) > +{ > + unsigned long color = 0; > + > + if (!tg) > + return 0; > + > + for (; tg; tg = tg->parent) { > + if (tg->core_tag_color) { > + WARN_ON_ONCE(color); > + color = tg->core_tag_color; > + } > + > + if (tg->core_tagged) { > + unsigned long cookie = ((unsigned long)tg << 8) | > color; > + cookie &= (1UL << (sizeof(unsigned long) * 4)) - 1; > + return cookie; > + } > + } > + > + return 0; > +}
I'm a bit wary of how core_task_cookie and core_group_cookie are truncated to the lower half of their bits and combined into the overall core_cookie. Now that core_group_cookie is further losing 8 bits to color, that leaves (in the case of 32 bit unsigned long) only 8 bits to uniquely identify the group contribution to the cookie. Also, I agree that 256 colors is likely adequate, but it would be nice to avoid this restriction. I'd like to propose the following alternative, which involves creating a new struct to represent the core cookie: struct core_cookie { unsigned long task_cookie; unsigned long group_cookie; unsigned long color; /* can be further extended with arbitrary fields */ struct rb_node node; refcount_t; }; struct rb_root core_cookies; /* (sorted), all active core_cookies */ seqlock_t core_cookies_lock; /* protects against removal/addition to core_cookies */ struct task_struct { ... unsigned long core_cookie; /* (struct core_cookie *) */ } A given task stores the address of a core_cookie struct in its core_cookie field. When we reconfigure a task's color/task_cookie/group_cookie, we can first look for an existing core_cookie that matches those settings, or create a new one.