static inline struct autogroup *autogroup_task_get(struct task_struct *p) { struct autogroup *ag; unsigned long flags; if (!lock_task_sighand(p, &flags)) return autogroup_kref_get(&autogroup_default); ag = autogroup_kref_get(p->signal->autogroup); unlock_task_sighand(p, &flags); return ag; }
static void autogroup_move_group(struct task_struct *p, struct autogroup *ag) { struct autogroup *prev; struct task_struct *t; unsigned long flags; BUG_ON(!lock_task_sighand(p, &flags)); prev = p->signal->autogroup; if (prev == ag) { unlock_task_sighand(p, &flags); return; } p->signal->autogroup = autogroup_kref_get(ag); if (!ACCESS_ONCE(sysctl_sched_autogroup_enabled)) goto out; t = p; do { sched_move_task(t); } while_each_thread(p, t); out: unlock_task_sighand(p, &flags); autogroup_kref_put(prev); }
static void autogroup_move_group(struct task_struct *p, struct autogroup *ag) { struct autogroup *prev; struct task_struct *t; unsigned long flags; BUG_ON(!lock_task_sighand(p, &flags)); prev = p->signal->autogroup; if (prev == ag) { unlock_task_sighand(p, &flags); return; } p->signal->autogroup = autogroup_kref_get(ag); /* * We can't avoid sched_move_task() after we changed signal->autogroup, * this process can already run with task_group() == prev->tg or we can * race with cgroup code which can read autogroup = prev under rq->lock. * In the latter case for_each_thread() can not miss a migrating thread, * cpu_cgroup_attach() must not be possible after cgroup_exit() and it * can't be removed from thread list, we hold ->siglock. * * If an exiting thread was already removed from thread list we rely on * sched_autogroup_exit_task(). */ for_each_thread(p, t) sched_move_task(t); unlock_task_sighand(p, &flags); autogroup_kref_put(prev); }
static inline struct autogroup *autogroup_create(void) { struct autogroup *ag = kzalloc(sizeof(*ag), GFP_KERNEL); struct task_group *tg; if (!ag) goto out_fail; tg = sched_create_group(&init_task_group); if (IS_ERR(tg)) goto out_free; kref_init(&ag->kref); init_rwsem(&ag->lock); ag->id = atomic_inc_return(&autogroup_seq_nr); ag->tg = tg; tg->autogroup = ag; return ag; out_free: kfree(ag); out_fail: if (printk_ratelimit()) { printk(KERN_WARNING "autogroup_create: %s failure.\n", ag ? "sched_create_group()" : "kmalloc()"); } return autogroup_kref_get(&autogroup_default); }
static inline struct autogroup *autogroup_create(void) { struct autogroup *ag = kzalloc(sizeof(*ag), GFP_KERNEL); struct task_group *tg; if (!ag) goto out_fail; tg = sched_create_group(&root_task_group); if (IS_ERR(tg)) goto out_free; sched_online_group(tg, &root_task_group); kref_init(&ag->kref); init_rwsem(&ag->lock); ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr); ag->tg = tg; #ifdef CONFIG_RT_GROUP_SCHED /* * Autogroup RT tasks are redirected to the root task group * so we don't have to move tasks around upon policy change, * or flail around trying to allocate bandwidth on the fly. * A bandwidth exception in __sched_setscheduler() allows * the policy change to proceed. Thereafter, task_group() * returns &root_task_group, so zero bandwidth is required. */ free_rt_sched_group(tg); tg->rt_se = root_task_group.rt_se; tg->rt_rq = root_task_group.rt_rq; #endif tg->autogroup = ag; return ag; out_free: kfree(ag); out_fail: if (printk_ratelimit()) { printk(KERN_WARNING "autogroup_create: %s failure.\n", ag ? "sched_create_group()" : "kmalloc()"); } return autogroup_kref_get(&autogroup_default); }