lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6d7288f0-1b85-6a4f-d39e-a46675f60d5f@bytedance.com>
Date:   Wed, 21 Dec 2022 10:01:30 +0800
From:   Chengming Zhou <zhouchengming@...edance.com>
To:     mingo@...hat.com, peterz@...radead.org
Cc:     juri.lelli@...hat.com, vincent.guittot@...aro.org,
        dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
        mgorman@...e.de, bristot@...hat.com, vschneid@...hat.com,
        linux-kernel@...r.kernel.org, bagasdotme@...il.com,
        yu.c.chen@...el.com
Subject: Re: [PATCH v5 1/2] sched/core: Minor optimize ttwu_runnable()

Hello, ping :-)


On 2022/12/8 11:20, Chengming Zhou wrote:
> ttwu_runnable() is used as a fast wakeup path when the wakee task
> is running on CPU or runnable on RQ, in both cases we can just
> set its state to TASK_RUNNING to prevent a sleep.
> 
> If the wakee task is on_cpu running, we don't need to update_rq_clock()
> or check_preempt_curr().
> 
> But if the wakee task is on_rq && !on_cpu (e.g. an IRQ hit before
> the task got to schedule() and the task been preempted), we should
> check_preempt_curr() to see if it can preempt the current running.
> 
> This also removes the class->task_woken() callback from ttwu_runnable(),
> which wasn't required per the RT/DL implementations: any required push
> operation would have been queued during class->set_next_task() when p
> got preempted.
> 
> ttwu_runnable() also loses the update to rq->idle_stamp, as by definition
> the rq cannot be idle in this scenario.
> 
> Signed-off-by: Chengming Zhou <zhouchengming@...edance.com>
> Suggested-by: Valentin Schneider <vschneid@...hat.com>
> Suggested-by: Peter Zijlstra <peterz@...radead.org>
> Reviewed-by: Valentin Schneider <vschneid@...hat.com>
> ---
> v5:
>  - Split the reorganization and optimization into two patches
>    per Chen Yu. Thanks!
> 
> v4:
>  - s/This patch reorg/Reorganize/ per Bagas Sanjaya. Thanks!
> 
> v3:
>  - Improve the changelog per Valentin Schneider. Thanks!
> 
> v2:
>  - keep check_preempt_curr() for on_rq && !on_cpu case in ttwu_runnable(),
>    per Valentin Schneider.
>  - reorg ttwu_do_wakeup() and ttwu_do_activate() code, so ttwu_do_wakeup()
>    can be reused in ttwu_runnable(), per Peter Zijlstra.
>  - reuse ttwu_do_wakeup() in try_to_wake_up() (p == current) fast path too,
>    so ttwu_do_wakeup() become the only place we mark task runnable.
> ---
>  kernel/sched/core.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 314c2c0219d9..60aa7774e5f4 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3718,9 +3718,16 @@ static int ttwu_runnable(struct task_struct *p, int wake_flags)
>  
>  	rq = __task_rq_lock(p, &rf);
>  	if (task_on_rq_queued(p)) {
> -		/* check_preempt_curr() may use rq clock */
> -		update_rq_clock(rq);
> -		ttwu_do_wakeup(rq, p, wake_flags, &rf);
> +		if (!task_on_cpu(rq, p)) {
> +			/*
> +			 * When on_rq && !on_cpu the task is preempted, see if
> +			 * it should preempt whatever is current there now.
> +			 */
> +			update_rq_clock(rq);
> +			check_preempt_curr(rq, p, wake_flags);
> +		}
> +		WRITE_ONCE(p->__state, TASK_RUNNING);
> +		trace_sched_wakeup(p);
>  		ret = 1;
>  	}
>  	__task_rq_unlock(rq, &rf);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ