Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport cgroup method bal fix #18

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,17 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset)

cgroup_taskset_for_each(p, css, tset) {
struct cgroup *from = tg_cgrp(task_group(p));
struct cgroup *to = tg_cgrp(css_tg(css));

WARN_ON_ONCE(p->scx.cgrp_moving_from);

/*
* sched_move_task() omits identity migrations. Let's match the
* behavior so that ops.cgroup_prep_move() and ops.cgroup_move()
* always match one-to-one.
*/
if (from == to)
continue;

if (SCX_HAS_OP(cgroup_prep_move)) {
ret = SCX_CALL_OP_RET(SCX_KF_SLEEPABLE, cgroup_prep_move,
Expand All @@ -2720,17 +2731,14 @@ int scx_cgroup_can_attach(struct cgroup_taskset *tset)
goto err;
}

WARN_ON_ONCE(p->scx.cgrp_moving_from);
p->scx.cgrp_moving_from = from;
}

return 0;

err:
cgroup_taskset_for_each(p, css, tset) {
if (!p->scx.cgrp_moving_from)
break;
if (SCX_HAS_OP(cgroup_cancel_move))
if (SCX_HAS_OP(cgroup_cancel_move) && p->scx.cgrp_moving_from)
SCX_CALL_OP(SCX_KF_SLEEPABLE, cgroup_cancel_move, p,
p->scx.cgrp_moving_from, css->cgroup);
p->scx.cgrp_moving_from = NULL;
Expand Down Expand Up @@ -2758,12 +2766,13 @@ void scx_move_task(struct task_struct *p)
if (!scx_enabled())
return;

if (SCX_HAS_OP(cgroup_move)) {
if (WARN_ON_ONCE(!p->scx.cgrp_moving_from))
return;
/*
* @p must have ops.cgroup_prep_move() called on it and thus
* cgrp_moving_from set.
*/
if (SCX_HAS_OP(cgroup_move) && !WARN_ON_ONCE(!p->scx.cgrp_moving_from))
SCX_CALL_OP_TASK(SCX_KF_UNLOCKED, cgroup_move, p,
p->scx.cgrp_moving_from, tg_cgrp(task_group(p)));
}
p->scx.cgrp_moving_from = NULL;
}

Expand All @@ -2781,11 +2790,9 @@ void scx_cgroup_cancel_attach(struct cgroup_taskset *tset)
goto out_unlock;

cgroup_taskset_for_each(p, css, tset) {
if (SCX_HAS_OP(cgroup_cancel_move)) {
WARN_ON_ONCE(!p->scx.cgrp_moving_from);
if (SCX_HAS_OP(cgroup_cancel_move) && p->scx.cgrp_moving_from)
SCX_CALL_OP(SCX_KF_SLEEPABLE, cgroup_cancel_move, p,
p->scx.cgrp_moving_from, css->cgroup);
}
p->scx.cgrp_moving_from = NULL;
}
out_unlock:
Expand Down