From: tip-bot for Eric Dumazet <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hughd@google.com, edumazet@google.com,
linux-kernel@vger.kernel.org, eric.dumazet@gmail.com,
mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com,
bp@alien8.de
Subject: [tip:x86/cleanups] x86/cpuid: Allow cpuid_read() to schedule
Date: Tue, 27 Mar 2018 03:10:39 -0700 [thread overview]
Message-ID: <tip-67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1@git.kernel.org> (raw)
In-Reply-To: <20180323215818.127774-2-edumazet@google.com>
Commit-ID: 67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1
Gitweb: https://git.kernel.org/tip/67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1
Author: Eric Dumazet <edumazet@google.com>
AuthorDate: Fri, 23 Mar 2018 14:58:18 -0700
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 27 Mar 2018 12:01:48 +0200
x86/cpuid: Allow cpuid_read() to schedule
High latencies can be observed caused by a daemon periodically reading
CPUID on all cpus. On KASAN enabled kernels ~10ms latencies can be
observed. Even without KASAN, sending an IPI to a CPU, which is in a deep
sleep state or in a long hard IRQ disabled section, waiting for the answer
can consume hundreds of microseconds.
cpuid_read() is invoked in preemptible context, so it can be converted to
sleep instead of busy wait.
Switching to smp_call_function_single_async() and a completion allows to
reschedule and reduces CPU usage and latencies.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Link: https://lkml.kernel.org/r/20180323215818.127774-2-edumazet@google.com
---
arch/x86/kernel/cpuid.c | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 0931a105ffe1..1d300f96df4b 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -40,6 +40,7 @@
#include <linux/notifier.h>
#include <linux/uaccess.h>
#include <linux/gfp.h>
+#include <linux/completion.h>
#include <asm/processor.h>
#include <asm/msr.h>
@@ -47,19 +48,27 @@
static struct class *cpuid_class;
static enum cpuhp_state cpuhp_cpuid_state;
+struct cpuid_regs_done {
+ struct cpuid_regs regs;
+ struct completion done;
+};
+
static void cpuid_smp_cpuid(void *cmd_block)
{
- struct cpuid_regs *cmd = (struct cpuid_regs *)cmd_block;
+ struct cpuid_regs_done *cmd = cmd_block;
+
+ cpuid_count(cmd->regs.eax, cmd->regs.ecx,
+ &cmd->regs.eax, &cmd->regs.ebx,
+ &cmd->regs.ecx, &cmd->regs.edx);
- cpuid_count(cmd->eax, cmd->ecx,
- &cmd->eax, &cmd->ebx, &cmd->ecx, &cmd->edx);
+ complete(&cmd->done);
}
static ssize_t cpuid_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
char __user *tmp = buf;
- struct cpuid_regs cmd;
+ struct cpuid_regs_done cmd;
int cpu = iminor(file_inode(file));
u64 pos = *ppos;
ssize_t bytes = 0;
@@ -68,19 +77,28 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
if (count % 16)
return -EINVAL; /* Invalid chunk size */
+ init_completion(&cmd.done);
for (; count; count -= 16) {
- cmd.eax = pos;
- cmd.ecx = pos >> 32;
- err = smp_call_function_single(cpu, cpuid_smp_cpuid, &cmd, 1);
+ call_single_data_t csd = {
+ .func = cpuid_smp_cpuid,
+ .info = &cmd,
+ };
+
+ cmd.regs.eax = pos;
+ cmd.regs.ecx = pos >> 32;
+
+ err = smp_call_function_single_async(cpu, &csd);
if (err)
break;
- if (copy_to_user(tmp, &cmd, 16)) {
+ wait_for_completion(&cmd.done);
+ if (copy_to_user(tmp, &cmd.regs, 16)) {
err = -EFAULT;
break;
}
tmp += 16;
bytes += 16;
*ppos = ++pos;
+ reinit_completion(&cmd.done);
}
return bytes ? bytes : err;
next prev parent reply other threads:[~2018-03-27 10:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 21:58 [PATCH v3 1/2] x86, msr: allow rdmsr_safe_on_cpu() to schedule Eric Dumazet
2018-03-23 21:58 ` [PATCH v3 2/2] x86, cpuid: allow cpuid_read() " Eric Dumazet
2018-03-23 22:17 ` H. Peter Anvin
2018-03-24 1:01 ` Eric Dumazet
2018-03-25 22:11 ` H. Peter Anvin
2018-03-27 10:10 ` tip-bot for Eric Dumazet [this message]
2018-03-24 8:09 ` [PATCH v3 1/2] x86, msr: allow rdmsr_safe_on_cpu() " Ingo Molnar
2018-03-24 10:50 ` Thomas Gleixner
2018-03-24 14:29 ` Eric Dumazet
2018-03-25 14:12 ` Borislav Petkov
2018-03-26 1:21 ` H. Peter Anvin
2018-03-26 6:40 ` Ingo Molnar
[not found] ` <CANn89iKy_jVpBvAebJFm1UKVKfG=p+R4B1tXmC4waeK7YzZh2g@mail.gmail.com>
2018-03-26 14:23 ` Thomas Gleixner
2018-03-27 9:36 ` Ingo Molnar
2018-03-27 10:10 ` [tip:x86/cleanups] x86/msr: Allow " tip-bot for Eric Dumazet
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=tip-67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1@git.kernel.org \
--to=tipbot@zytor.com \
--cc=bp@alien8.de \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=hpa@zytor.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/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).