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/core: Reorganize ttwu_do_wakeup() and ttwu_do_activate()

ttwu_do_activate() is used for a complete wakeup, in which we will
activate_task() and use ttwu_do_wakeup() to mark the task runnable
and perform wakeup-preemption, also call class->task_woken() callback
and update the rq->idle_stamp.

Since ttwu_runnable() is not a complete wakeup, don't need all those
done in ttwu_do_wakeup(), so we can move those to ttwu_do_activate()
to simplify ttwu_do_wakeup(), making it only mark the task runnable
to be reused in ttwu_runnable() and try_to_wake_up().

This patch should not have any functional changes.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20221223103257.4962-2-zhouchengming@bytedance.com

authored by

Chengming Zhou and committed by
Ingo Molnar
160fb0d8 efe09385

+31 -33
+31 -33
kernel/sched/core.c
··· 3625 3625 } 3626 3626 3627 3627 /* 3628 - * Mark the task runnable and perform wakeup-preemption. 3628 + * Mark the task runnable. 3629 3629 */ 3630 - static void ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags, 3631 - struct rq_flags *rf) 3630 + static inline void ttwu_do_wakeup(struct task_struct *p) 3632 3631 { 3633 - check_preempt_curr(rq, p, wake_flags); 3634 3632 WRITE_ONCE(p->__state, TASK_RUNNING); 3635 3633 trace_sched_wakeup(p); 3634 + } 3635 + 3636 + static void 3637 + ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, 3638 + struct rq_flags *rf) 3639 + { 3640 + int en_flags = ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK; 3641 + 3642 + lockdep_assert_rq_held(rq); 3643 + 3644 + if (p->sched_contributes_to_load) 3645 + rq->nr_uninterruptible--; 3646 + 3647 + #ifdef CONFIG_SMP 3648 + if (wake_flags & WF_MIGRATED) 3649 + en_flags |= ENQUEUE_MIGRATED; 3650 + else 3651 + #endif 3652 + if (p->in_iowait) { 3653 + delayacct_blkio_end(p); 3654 + atomic_dec(&task_rq(p)->nr_iowait); 3655 + } 3656 + 3657 + activate_task(rq, p, en_flags); 3658 + check_preempt_curr(rq, p, wake_flags); 3659 + 3660 + ttwu_do_wakeup(p); 3636 3661 3637 3662 #ifdef CONFIG_SMP 3638 3663 if (p->sched_class->task_woken) { ··· 3685 3660 rq->idle_stamp = 0; 3686 3661 } 3687 3662 #endif 3688 - } 3689 - 3690 - static void 3691 - ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, 3692 - struct rq_flags *rf) 3693 - { 3694 - int en_flags = ENQUEUE_WAKEUP | ENQUEUE_NOCLOCK; 3695 - 3696 - lockdep_assert_rq_held(rq); 3697 - 3698 - if (p->sched_contributes_to_load) 3699 - rq->nr_uninterruptible--; 3700 - 3701 - #ifdef CONFIG_SMP 3702 - if (wake_flags & WF_MIGRATED) 3703 - en_flags |= ENQUEUE_MIGRATED; 3704 - else 3705 - #endif 3706 - if (p->in_iowait) { 3707 - delayacct_blkio_end(p); 3708 - atomic_dec(&task_rq(p)->nr_iowait); 3709 - } 3710 - 3711 - activate_task(rq, p, en_flags); 3712 - ttwu_do_wakeup(rq, p, wake_flags, rf); 3713 3663 } 3714 3664 3715 3665 /* ··· 3728 3728 update_rq_clock(rq); 3729 3729 check_preempt_curr(rq, p, wake_flags); 3730 3730 } 3731 - WRITE_ONCE(p->__state, TASK_RUNNING); 3732 - trace_sched_wakeup(p); 3731 + ttwu_do_wakeup(p); 3733 3732 ret = 1; 3734 3733 } 3735 3734 __task_rq_unlock(rq, &rf); ··· 4094 4095 goto out; 4095 4096 4096 4097 trace_sched_waking(p); 4097 - WRITE_ONCE(p->__state, TASK_RUNNING); 4098 - trace_sched_wakeup(p); 4098 + ttwu_do_wakeup(p); 4099 4099 goto out; 4100 4100 } 4101 4101