]> Gentwo Git Trees - linux/.git/commitdiff
sched_ext: Minor cleanups to scx_task_iter
authorTejun Heo <tj@kernel.org>
Tue, 4 Nov 2025 21:42:55 +0000 (11:42 -1000)
committerTejun Heo <tj@kernel.org>
Tue, 4 Nov 2025 21:46:25 +0000 (11:46 -1000)
- Use memset() in scx_task_iter_start() instead of zeroing fields individually.

- In scx_task_iter_next(), move __scx_task_iter_maybe_relock() after the batch
  check which is simpler.

- Update comment to reflect that tasks are removed from scx_tasks when dead
  (commit 7900aa699c34 ("sched_ext: Fix cgroup exit ordering by moving
  sched_ext_free() to finish_task_switch()")).

No functional changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/sched/ext.c

index 5af015891b15d23e514e60ed53ecab43b3e33b7d..652a364e9e4cbc61aef76bcb9a12138899151ad3 100644 (file)
@@ -470,16 +470,16 @@ struct scx_task_iter {
  * RCU read lock or obtaining a reference count.
  *
  * All tasks which existed when the iteration started are guaranteed to be
- * visited as long as they still exist.
+ * visited as long as they are not dead.
  */
 static void scx_task_iter_start(struct scx_task_iter *iter)
 {
+       memset(iter, 0, sizeof(*iter));
+
        spin_lock_irq(&scx_tasks_lock);
 
        iter->cursor = (struct sched_ext_entity){ .flags = SCX_TASK_CURSOR };
        list_add(&iter->cursor.tasks_node, &scx_tasks);
-       iter->locked_task = NULL;
-       iter->cnt = 0;
        iter->list_locked = true;
 }
 
@@ -545,14 +545,13 @@ static struct task_struct *scx_task_iter_next(struct scx_task_iter *iter)
        struct list_head *cursor = &iter->cursor.tasks_node;
        struct sched_ext_entity *pos;
 
-       __scx_task_iter_maybe_relock(iter);
-
        if (!(++iter->cnt % SCX_TASK_ITER_BATCH)) {
                scx_task_iter_unlock(iter);
                cond_resched();
-               __scx_task_iter_maybe_relock(iter);
        }
 
+       __scx_task_iter_maybe_relock(iter);
+
        list_for_each_entry(pos, cursor, tasks_node) {
                if (&pos->tasks_node == &scx_tasks)
                        return NULL;