Skip to content

Commit

Permalink
Merge pull request torvalds#111 from sched-ext/htejun
Browse files Browse the repository at this point in the history
  • Loading branch information
Byte-Lab authored Jan 8, 2024
2 parents 5445296 + 22c3627 commit 8c7f9b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
34 changes: 14 additions & 20 deletions include/linux/sched/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,15 +613,24 @@ enum scx_ent_flags {
SCX_TASK_QUEUED = 1 << 0, /* on ext runqueue */
SCX_TASK_BAL_KEEP = 1 << 1, /* balance decided to keep current */
SCX_TASK_DDSP_PRIQ = 1 << 2, /* task should be enqueued on priq when directly dispatched */
SCX_TASK_STATE_0 = 1 << 3, /* first bit encoding the task's current state */
SCX_TASK_STATE_1 = 1 << 4, /* second bit encoding the task's current state */
SCX_TASK_RESET_RUNNABLE_AT = 1 << 3, /* runnable_at should be reset */
SCX_TASK_DEQD_FOR_SLEEP = 1 << 4, /* last dequeue was for SLEEP */

SCX_TASK_RESET_RUNNABLE_AT = 1 << 16, /* runnable_at should be reset */
SCX_TASK_DEQD_FOR_SLEEP = 1 << 17, /* last dequeue was for SLEEP */
SCX_TASK_STATE_SHIFT = 8, /* bit 8 and 9 are used to carry scx_task_state */
SCX_TASK_STATE_BITS = 2,
SCX_TASK_STATE_MASK = ((1 << SCX_TASK_STATE_BITS) - 1) << SCX_TASK_STATE_SHIFT,

SCX_TASK_CURSOR = 1 << 31, /* iteration cursor, not a task */
};

/* scx_entity.flags & SCX_TASK_STATE_MASK */
enum scx_task_state {
SCX_TASK_NONE, /* ops.init_task() not called yet */
SCX_TASK_INIT, /* ops.init_task() succeeded, but task can be cancelled */
SCX_TASK_READY, /* fully initialized, but not in sched_ext */
SCX_TASK_ENABLED, /* fully initialized and in sched_ext */

SCX_TASK_STATE_MASK = SCX_TASK_STATE_0 | SCX_TASK_STATE_1,
SCX_TASK_NR_STATES,
};

/* scx_entity.dsq_flags */
Expand Down Expand Up @@ -655,21 +664,6 @@ enum scx_kf_mask {
__SCX_KF_TERMINAL = SCX_KF_ENQUEUE | SCX_KF_SELECT_CPU | SCX_KF_REST,
};

/* scx_entity.task_state */
enum scx_task_state {
/* ops.prep_enable() has not yet been called on task */
SCX_TASK_NONE,

/* ops.prep_enable() succeeded on task, but it still be cancelled */
SCX_TASK_INIT,

/* Task is fully initialized, but not being scheduled in sched_ext */
SCX_TASK_READY,

/* Task is fully initialized and is being scheduled in sched_ext */
SCX_TASK_ENABLED,
};

/*
* The following is embedded in task_struct and contains all fields necessary
* for a task to be scheduled by SCX.
Expand Down
34 changes: 15 additions & 19 deletions kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2313,41 +2313,34 @@ static struct cgroup *tg_cgrp(struct task_group *tg)

static enum scx_task_state scx_get_task_state(const struct task_struct *p)
{
int state = p->scx.flags & SCX_TASK_STATE_MASK;

switch (state) {
case SCX_TASK_STATE_0 | SCX_TASK_STATE_1:
return SCX_TASK_ENABLED;
case SCX_TASK_STATE_1:
return SCX_TASK_READY;
case SCX_TASK_STATE_0:
return SCX_TASK_INIT;
default:
return SCX_TASK_NONE;
}
return (p->scx.flags & SCX_TASK_STATE_MASK) >> SCX_TASK_STATE_SHIFT;
}

static void scx_set_task_state(struct task_struct *p, enum scx_task_state state)
{
enum scx_task_state prev_state = scx_get_task_state(p);

p->scx.flags &= ~SCX_TASK_STATE_MASK;
BUILD_BUG_ON(SCX_TASK_NR_STATES > (1 << SCX_TASK_STATE_BITS));

switch (state) {
case SCX_TASK_NONE:
return;
break;
case SCX_TASK_INIT:
WARN_ON_ONCE(prev_state != SCX_TASK_NONE);
p->scx.flags |= SCX_TASK_STATE_0;
return;
break;
case SCX_TASK_READY:
WARN_ON_ONCE(prev_state == SCX_TASK_NONE);
p->scx.flags |= SCX_TASK_STATE_1;
return;
break;
case SCX_TASK_ENABLED:
WARN_ON_ONCE(prev_state != SCX_TASK_READY);
p->scx.flags |= (SCX_TASK_STATE_0 | SCX_TASK_STATE_1);
break;
default:
WARN_ON_ONCE(true);
return;
}

p->scx.flags &= ~SCX_TASK_STATE_MASK;
p->scx.flags |= state << SCX_TASK_STATE_SHIFT;
}

static int scx_ops_init_task(struct task_struct *p, struct task_group *tg)
Expand Down Expand Up @@ -2447,6 +2440,9 @@ static void scx_ops_exit_task(struct task_struct *p)
case SCX_TASK_ENABLED:
scx_ops_disable_task(p);
break;
default:
WARN_ON_ONCE(true);
return;
}

if (SCX_HAS_OP(exit_task))
Expand Down

0 comments on commit 8c7f9b2

Please sign in to comment.