From: Nikolay Borisov <n.borisov.lkml@gmail.com>
To: zhenggy <zhenggy@chinatelecom.cn>,
mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
srw@sladewatkins.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched: Fix rq nr_uninterruptible count
Date: Tue, 28 Feb 2023 11:38:11 +0200 [thread overview]
Message-ID: <6e35e516-e567-57cb-ac1f-013228a04df4@gmail.com> (raw)
In-Reply-To: <95d8be30-986c-4a2f-6913-a7813556874a@chinatelecom.cn>
On 28.02.23 г. 10:46 ч., zhenggy wrote:
> When an uninterrptable task is queue to a differect cpu as where
> it is dequeued, the rq nr_uninterruptible will be incorrent, so
> fix it.
>
> Signed-off-by: GuoYong Zheng <zhenggy@chinatelecom.cn>
37 * - cpu_rq()->nr_uninterruptible isn't accurately tracked
per-CPU because
38 * this would add another cross-CPU cacheline miss and atomic
operation
39 * to the wakeup path. Instead we increment on whatever CPU
the task ran
40 * when it went into uninterruptible state and decrement on
whatever CPU
41 * did the wakeup. This means that only the sum of
nr_uninterruptible over
42 * all CPUs yields the correct result.
> ---
> kernel/sched/core.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 25b582b..cd5ef6e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4068,6 +4068,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
> {
> unsigned long flags;
> int cpu, success = 0;
> + struct rq *src_rq, *dst_rq;
>
> preempt_disable();
> if (p == current) {
> @@ -4205,6 +4206,16 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
> atomic_dec(&task_rq(p)->nr_iowait);
> }
>
> + if (p->sched_contributes_to_load) {
> + src_rq = cpu_rq(task_cpu(p));
> + dst_rq = cpu_rq(cpu);
> +
> + double_rq_lock(src_rq, dst_rq);
> + src_rq->nr_uninterruptible--;
> + dst_rq->nr_uninterruptible++;
> + double_rq_unlock(src_rq, dst_rq);
> + }
> +
> wake_flags |= WF_MIGRATED;
> psi_ttwu_dequeue(p);
> set_task_cpu(p, cpu);
next prev parent reply other threads:[~2023-02-28 9:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 8:46 [PATCH] sched: Fix rq nr_uninterruptible count zhenggy
2023-02-28 9:38 ` Nikolay Borisov [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-02-28 7:08 zhenggy
2023-02-28 8:13 ` Slade's Kernel Patch Bot
2023-02-28 8:56 ` Bagas Sanjaya
2023-02-28 9:27 ` Mike Galbraith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6e35e516-e567-57cb-ac1f-013228a04df4@gmail.com \
--to=n.borisov.lkml@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=srw@sladewatkins.net \
--cc=vincent.guittot@linaro.org \
--cc=zhenggy@chinatelecom.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox