linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: menglong8.dong@gmail.com
To: helgaas@kernel.org
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Menglong Dong <imagedong@tencent.com>
Subject: [PATCH v2] pci: call cond_resched() after pci bus config writing
Date: Fri, 15 Oct 2021 10:40:25 +0800	[thread overview]
Message-ID: <20211015024025.2916363-1-imagedong@tencent.com> (raw)

From: Menglong Dong <imagedong@tencent.com>

While the system is running in KVM, pci config writing for virtio devices
may cost long time (about 1-2ms), as it causes VM-exit. During
__pci_bus_assign_resources(), pci_setup_bridge(), which can write pci
config up to 10 times, can be called many times without any
cond_resched(). So __pci_bus_assign_resources() can cause 25+ms
scheduling latency with !CONFIG_PREEMPT.

To solve this problem, call cond_resched() after pci config writing.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
v2:
- use cond_resched() instead of _cond_resched()
---
 drivers/pci/access.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 46935695cfb9..4c52a50f2c46 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -57,6 +57,7 @@ int noinline pci_bus_write_config_##size \
 	pci_lock_config(flags);						\
 	res = bus->ops->write(bus, devfn, pos, len, value);		\
 	pci_unlock_config(flags);					\
+	cond_resched();						\
 	return res;							\
 }
 
-- 
2.27.0


             reply	other threads:[~2021-10-15  2:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  2:40 menglong8.dong [this message]
2021-10-15 11:06 ` [PATCH v2] pci: call cond_resched() after pci bus config writing Bjorn Helgaas

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=20211015024025.2916363-1-imagedong@tencent.com \
    --to=menglong8.dong@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=helgaas@kernel.org \
    --cc=imagedong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.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).