linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: xuhaifeng <xuhaifeng@oppo.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, bristot@redhat.com
Cc: linux-kernel@vger.kernel.org, xuhaifeng <xuhaifeng@oppo.com>
Subject: [PATCH] sched: optimize __cond_resched_lock()
Date: Tue, 21 Dec 2021 15:23:16 +0800	[thread overview]
Message-ID: <20211221072316.42-1-xuhaifeng@oppo.com> (raw)

if the kernel is preemptible(CONFIG_PREEMPTION=y), schedule()may be
called twice, once via spin_unlock, once via preempt_schedule_common.

we can add one conditional, check TIF_NEED_RESCHED flag again,
to avoid this.

Signed-off-by: xuhaifeng <xuhaifeng@oppo.com>
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 83872f95a1ea..fb011e613497 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8219,7 +8219,7 @@ int __cond_resched_lock(spinlock_t *lock)

        if (spin_needbreak(lock) || resched) {
                spin_unlock(lock);
-               if (resched)
+               if (resched && need_resched())
                        preempt_schedule_common();
                else
                        cpu_relax();
--
2.17.1

________________________________
OPPO

本电子邮件及其附件含有OPPO公司的保密信息,仅限于邮件指明的收件人使用(包含个人及群组)。禁止任何人在未经授权的情况下以任何形式使用。如果您错收了本邮件,请立即以电子邮件通知发件人并删除本邮件及其附件。

This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!

             reply	other threads:[~2021-12-21  7:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21  7:23 xuhaifeng [this message]
2021-12-21  8:52 ` [PATCH] sched: optimize __cond_resched_lock() Peter Zijlstra
2021-12-21 10:09   ` Peter Zijlstra
2021-12-21 12:01     ` Peter Zijlstra
2021-12-21 13:30     ` xuhaifeng
2022-01-18 11:18     ` [tip: sched/urgent] sched: Avoid double preemption in __cond_resched_*lock*() tip-bot2 for Peter Zijlstra

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=20211221072316.42-1-xuhaifeng@oppo.com \
    --to=xuhaifeng@oppo.com \
    --cc=bristot@redhat.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=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).