Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched_ext: Simplify task state handling

Task states (NONE, INIT, READY, ENABLED) were defined in a separate enum with
unshifted values and then shifted when stored in scx_entity.flags. Simplify by
defining them as pre-shifted values directly in scx_ent_flags and removing the
separate scx_task_state enum. This removes the need for shifting when
reading/writing state values.

scx_get_task_state() now returns the masked flags value directly.
scx_set_task_state() accepts the pre-shifted state value. scx_dump_task()
shifts down for display to maintain readable output.

No functional changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>

Tejun Heo 7203d77d a90449b1

+25 -22
+16 -12
include/linux/sched/ext.h
··· 93 93 struct rcu_head rcu; 94 94 }; 95 95 96 - /* scx_entity.flags */ 96 + /* sched_ext_entity.flags */ 97 97 enum scx_ent_flags { 98 98 SCX_TASK_QUEUED = 1 << 0, /* on ext runqueue */ 99 99 SCX_TASK_IN_CUSTODY = 1 << 1, /* in custody, needs ops.dequeue() when leaving */ ··· 101 101 SCX_TASK_DEQD_FOR_SLEEP = 1 << 3, /* last dequeue was for SLEEP */ 102 102 SCX_TASK_SUB_INIT = 1 << 4, /* task being initialized for a sub sched */ 103 103 104 - SCX_TASK_STATE_SHIFT = 8, /* bit 8 and 9 are used to carry scx_task_state */ 104 + /* 105 + * Bits 8 and 9 are used to carry task state: 106 + * 107 + * NONE ops.init_task() not called yet 108 + * INIT ops.init_task() succeeded, but task can be cancelled 109 + * READY fully initialized, but not in sched_ext 110 + * ENABLED fully initialized and in sched_ext 111 + */ 112 + SCX_TASK_STATE_SHIFT = 8, /* bits 8 and 9 are used to carry task state */ 105 113 SCX_TASK_STATE_BITS = 2, 106 114 SCX_TASK_STATE_MASK = ((1 << SCX_TASK_STATE_BITS) - 1) << SCX_TASK_STATE_SHIFT, 107 115 108 - SCX_TASK_CURSOR = 1 << 31, /* iteration cursor, not a task */ 109 - }; 116 + SCX_TASK_NONE = 0 << SCX_TASK_STATE_SHIFT, 117 + SCX_TASK_INIT = 1 << SCX_TASK_STATE_SHIFT, 118 + SCX_TASK_READY = 2 << SCX_TASK_STATE_SHIFT, 119 + SCX_TASK_ENABLED = 3 << SCX_TASK_STATE_SHIFT, 110 120 111 - /* scx_entity.flags & SCX_TASK_STATE_MASK */ 112 - enum scx_task_state { 113 - SCX_TASK_NONE, /* ops.init_task() not called yet */ 114 - SCX_TASK_INIT, /* ops.init_task() succeeded, but task can be cancelled */ 115 - SCX_TASK_READY, /* fully initialized, but not in sched_ext */ 116 - SCX_TASK_ENABLED, /* fully initialized and in sched_ext */ 117 - 118 - SCX_TASK_NR_STATES, 121 + /* iteration cursor, not a task */ 122 + SCX_TASK_CURSOR = 1 << 31, 119 123 }; 120 124 121 125 /* scx_entity.dsq_flags */
+9 -10
kernel/sched/ext.c
··· 3284 3284 3285 3285 #endif /* CONFIG_EXT_GROUP_SCHED */ 3286 3286 3287 - static enum scx_task_state scx_get_task_state(const struct task_struct *p) 3287 + static u32 scx_get_task_state(const struct task_struct *p) 3288 3288 { 3289 - return (p->scx.flags & SCX_TASK_STATE_MASK) >> SCX_TASK_STATE_SHIFT; 3289 + return p->scx.flags & SCX_TASK_STATE_MASK; 3290 3290 } 3291 3291 3292 - static void scx_set_task_state(struct task_struct *p, enum scx_task_state state) 3292 + static void scx_set_task_state(struct task_struct *p, u32 state) 3293 3293 { 3294 - enum scx_task_state prev_state = scx_get_task_state(p); 3294 + u32 prev_state = scx_get_task_state(p); 3295 3295 bool warn = false; 3296 - 3297 - BUILD_BUG_ON(SCX_TASK_NR_STATES > (1 << SCX_TASK_STATE_BITS)); 3298 3296 3299 3297 switch (state) { 3300 3298 case SCX_TASK_NONE: ··· 3311 3313 return; 3312 3314 } 3313 3315 3314 - WARN_ONCE(warn, "sched_ext: Invalid task state transition %d -> %d for %s[%d]", 3316 + WARN_ONCE(warn, "sched_ext: Invalid task state transition 0x%x -> 0x%x for %s[%d]", 3315 3317 prev_state, state, p->comm, p->pid); 3316 3318 3317 3319 p->scx.flags &= ~SCX_TASK_STATE_MASK; 3318 - p->scx.flags |= state << SCX_TASK_STATE_SHIFT; 3320 + p->scx.flags |= state; 3319 3321 } 3320 3322 3321 3323 static int __scx_init_task(struct scx_sched *sch, struct task_struct *p, bool fork) ··· 5792 5794 own_marker, sch_id_buf, 5793 5795 jiffies_delta_msecs(p->scx.runnable_at, dctx->at_jiffies)); 5794 5796 dump_line(s, " scx_state/flags=%u/0x%x dsq_flags=0x%x ops_state/qseq=%lu/%lu", 5795 - scx_get_task_state(p), p->scx.flags & ~SCX_TASK_STATE_MASK, 5797 + scx_get_task_state(p) >> SCX_TASK_STATE_SHIFT, 5798 + p->scx.flags & ~SCX_TASK_STATE_MASK, 5796 5799 p->scx.dsq_flags, ops_state & SCX_OPSS_STATE_MASK, 5797 5800 ops_state >> SCX_OPSS_QSEQ_SHIFT); 5798 5801 dump_line(s, " sticky/holding_cpu=%d/%d dsq_id=%s", ··· 6557 6558 6558 6559 static bool assert_task_ready_or_enabled(struct task_struct *p) 6559 6560 { 6560 - enum scx_task_state state = scx_get_task_state(p); 6561 + u32 state = scx_get_task_state(p); 6561 6562 6562 6563 switch (state) { 6563 6564 case SCX_TASK_READY: