@@ -548,6 +548,11 @@ sched_core_dequeue(struct rq *rq, struct task_struct *p, int flags) { }
548548 * ON_RQ_MIGRATING state is used for migration without holding both
549549 * rq->locks. It indicates task_cpu() is not stable, see task_rq_lock().
550550 *
551+ * Additionally it is possible to be ->on_rq but still be considered not
552+ * runnable when p->se.sched_delayed is true. These tasks are on the runqueue
553+ * but will be dequeued as soon as they get picked again. See the
554+ * task_is_runnable() helper.
555+ *
551556 * p->on_cpu <- { 0, 1 }:
552557 *
553558 * is set by prepare_task() and cleared by finish_task() such that it will be
@@ -2012,18 +2017,18 @@ void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
20122017 if (!(flags & ENQUEUE_NOCLOCK ))
20132018 update_rq_clock (rq );
20142019
2015- if (!(flags & ENQUEUE_RESTORE )) {
2016- sched_info_enqueue (rq , p );
2017- psi_enqueue (p , (flags & ENQUEUE_WAKEUP ) && !(flags & ENQUEUE_MIGRATED ));
2018- }
2019-
20202020 p -> sched_class -> enqueue_task (rq , p , flags );
20212021 /*
20222022 * Must be after ->enqueue_task() because ENQUEUE_DELAYED can clear
20232023 * ->sched_delayed.
20242024 */
20252025 uclamp_rq_inc (rq , p );
20262026
2027+ if (!(flags & ENQUEUE_RESTORE )) {
2028+ sched_info_enqueue (rq , p );
2029+ psi_enqueue (p , flags & ENQUEUE_MIGRATED );
2030+ }
2031+
20272032 if (sched_core_enabled (rq ))
20282033 sched_core_enqueue (rq , p );
20292034}
@@ -2041,7 +2046,7 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
20412046
20422047 if (!(flags & DEQUEUE_SAVE )) {
20432048 sched_info_dequeue (rq , p );
2044- psi_dequeue (p , flags & DEQUEUE_SLEEP );
2049+ psi_dequeue (p , !( flags & DEQUEUE_SLEEP ) );
20452050 }
20462051
20472052 /*
@@ -4317,9 +4322,10 @@ static bool __task_needs_rq_lock(struct task_struct *p)
43174322 * @arg: Argument to function.
43184323 *
43194324 * Fix the task in it's current state by avoiding wakeups and or rq operations
4320- * and call @func(@arg) on it. This function can use ->on_rq and task_curr()
4321- * to work out what the state is, if required. Given that @func can be invoked
4322- * with a runqueue lock held, it had better be quite lightweight.
4325+ * and call @func(@arg) on it. This function can use task_is_runnable() and
4326+ * task_curr() to work out what the state is, if required. Given that @func
4327+ * can be invoked with a runqueue lock held, it had better be quite
4328+ * lightweight.
43234329 *
43244330 * Returns:
43254331 * Whatever @func returns
@@ -6537,6 +6543,7 @@ static void __sched notrace __schedule(int sched_mode)
65376543 * as a preemption by schedule_debug() and RCU.
65386544 */
65396545 bool preempt = sched_mode > SM_NONE ;
6546+ bool block = false;
65406547 unsigned long * switch_count ;
65416548 unsigned long prev_state ;
65426549 struct rq_flags rf ;
@@ -6622,6 +6629,7 @@ static void __sched notrace __schedule(int sched_mode)
66226629 * After this, schedule() must not care about p->state any more.
66236630 */
66246631 block_task (rq , prev , flags );
6632+ block = true;
66256633 }
66266634 switch_count = & prev -> nvcsw ;
66276635 }
@@ -6667,7 +6675,7 @@ static void __sched notrace __schedule(int sched_mode)
66676675
66686676 migrate_disable_switch (rq , prev );
66696677 psi_account_irqtime (rq , prev , next );
6670- psi_sched_switch (prev , next , ! task_on_rq_queued ( prev ) );
6678+ psi_sched_switch (prev , next , block );
66716679
66726680 trace_sched_switch (preempt , prev , next , prev_state );
66736681
@@ -7010,20 +7018,20 @@ int default_wake_function(wait_queue_entry_t *curr, unsigned mode, int wake_flag
70107018}
70117019EXPORT_SYMBOL (default_wake_function );
70127020
7013- void __setscheduler_prio (struct task_struct * p , int prio )
7021+ const struct sched_class * __setscheduler_class (struct task_struct * p , int prio )
70147022{
70157023 if (dl_prio (prio ))
7016- p -> sched_class = & dl_sched_class ;
7017- else if (rt_prio (prio ))
7018- p -> sched_class = & rt_sched_class ;
7024+ return & dl_sched_class ;
7025+
7026+ if (rt_prio (prio ))
7027+ return & rt_sched_class ;
7028+
70197029#ifdef CONFIG_SCHED_CLASS_EXT
7020- else if (task_should_scx (p ))
7021- p -> sched_class = & ext_sched_class ;
7030+ if (task_should_scx (p ))
7031+ return & ext_sched_class ;
70227032#endif
7023- else
7024- p -> sched_class = & fair_sched_class ;
70257033
7026- p -> prio = prio ;
7034+ return & fair_sched_class ;
70277035}
70287036
70297037#ifdef CONFIG_RT_MUTEXES
@@ -7069,7 +7077,7 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
70697077{
70707078 int prio , oldprio , queued , running , queue_flag =
70717079 DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK ;
7072- const struct sched_class * prev_class ;
7080+ const struct sched_class * prev_class , * next_class ;
70737081 struct rq_flags rf ;
70747082 struct rq * rq ;
70757083
@@ -7127,6 +7135,11 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
71277135 queue_flag &= ~DEQUEUE_MOVE ;
71287136
71297137 prev_class = p -> sched_class ;
7138+ next_class = __setscheduler_class (p , prio );
7139+
7140+ if (prev_class != next_class && p -> se .sched_delayed )
7141+ dequeue_task (rq , p , DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK );
7142+
71307143 queued = task_on_rq_queued (p );
71317144 running = task_current (rq , p );
71327145 if (queued )
@@ -7164,7 +7177,9 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
71647177 p -> rt .timeout = 0 ;
71657178 }
71667179
7167- __setscheduler_prio (p , prio );
7180+ p -> sched_class = next_class ;
7181+ p -> prio = prio ;
7182+
71687183 check_class_changing (rq , p , prev_class );
71697184
71707185 if (queued )
@@ -10458,7 +10473,9 @@ void task_tick_mm_cid(struct rq *rq, struct task_struct *curr)
1045810473 return ;
1045910474 if (time_before (now , READ_ONCE (curr -> mm -> mm_cid_next_scan )))
1046010475 return ;
10461- task_work_add (curr , work , TWA_RESUME );
10476+
10477+ /* No page allocation under rq lock */
10478+ task_work_add (curr , work , TWA_RESUME | TWAF_NO_ALLOC );
1046210479}
1046310480
1046410481void sched_mm_cid_exit_signals (struct task_struct * t )
0 commit comments