Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

scx: Account for ops.set_weight() scx_post_fork() path #4

Merged
merged 1 commit into from
Apr 14, 2023
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
23 changes: 18 additions & 5 deletions kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,13 @@ static void scx_ops_disable_task(struct task_struct *p)
}
}

static void set_task_scx_weight(struct task_struct *p)
{
u32 weight = sched_prio_to_weight[p->static_prio - MAX_RT_PRIO];

p->scx.weight = sched_weight_to_cgroup(weight);
}

/**
* refresh_scx_weight - Refresh a task's ext weight
* @p: task to refresh ext weight for
Expand All @@ -2275,9 +2282,8 @@ static void scx_ops_disable_task(struct task_struct *p)
*/
static void refresh_scx_weight(struct task_struct *p)
{
u32 weight = sched_prio_to_weight[p->static_prio - MAX_RT_PRIO];

p->scx.weight = sched_weight_to_cgroup(weight);
lockdep_assert_rq_held(task_rq(p));
set_task_scx_weight(p);
if (SCX_HAS_OP(set_weight))
SCX_CALL_OP_TASK(SCX_KF_REST, set_weight, p, p->scx.weight);
}
Expand Down Expand Up @@ -2305,14 +2311,21 @@ int scx_fork(struct task_struct *p)

void scx_post_fork(struct task_struct *p)
{
refresh_scx_weight(p);

if (scx_enabled()) {
struct rq_flags rf;
struct rq *rq;

rq = task_rq_lock(p, &rf);
/*
* Set the weight manually before calling ops.enable() so that
* the scheduler doesn't see a stale value if they inspect the
* task struct. We'll invoke ops.set_weight() afterwards, as it
* would be odd to receive a callback on the task before we
* tell the scheduler that it's been fully enabled.
*/
set_task_scx_weight(p);
scx_ops_enable_task(p);
refresh_scx_weight(p);
task_rq_unlock(rq, p, &rf);
}

Expand Down