Received: by 10.213.65.68 with SMTP id h4csp482038imn; Tue, 27 Mar 2018 03:12:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/zf46H6xmIslJpzjx6EDbrujoklu3s+ns4SAmzMI9b172JDIAV5bPND20AOvrmyy0uz5RK X-Received: by 2002:a17:902:b10c:: with SMTP id q12-v6mr3718909plr.399.1522145550216; Tue, 27 Mar 2018 03:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522145550; cv=none; d=google.com; s=arc-20160816; b=MjqiBEXKkJHct7hPtwvfiIBe/Y8L77kjI8tMDQ/lMNydPWe0qRWl/GhkhvOjycckI6 6XfWRbpUMjMSLLSkIJ0hSkuOaWPDEe973mJ9kRZOXgjLuHQByDuLH/LmfP+6mM1t1245 pOetIJ2mSmSH8ThhESNPfCENSmHBaktbAEi4bWl7gArBLCtIzXKlGY2GCoMODune2Mq+ /FqqMfk+qykYYNhF9yj/yIKdROofU/xSRIlDLykOypR0P533M9xeJL0mfK/82ats/+fk LmX9GfmD4Y28qaR4q9aHGRu26PHmMA5e3ymbVvigmdgUxxAM0cZ8arPC3I1fWCucGSXO FCwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=e8esV7GhxfjB4z2f8dGjyY3qb1LMkeV2dimv5Ol8gK4=; b=O5Jgn1XmjdHInmwolLlpSFAo9lMACrSaPe2MYap3khYjSXFN1J9OmGdJwe6dVIMFbh ekKbF+1EZe2dDvexPXEEiGJwubqt54r0g+/0NtNmcBWtGvJPD4I/2Zn1rSx+y+xu4H67 F66FQdZC0Yr+HV4LcU/Px0aZ2/ClwZutPgoZnra0Ng8J7pLqONDt9kaajCi5U6PSf3iD ALbltsKUisop2fBdqJQkP4aIhjV/vWkj0/tTlxo4xWE0SV5W8Ykl+fJ8yuqJwBF8gIDV kX6XY7kDVIFucX3ziKk/RmQq2N4k2bCcsl8Hqef1wcaAbnpD6tHH/wYf6JD/e8Cv7nF/ BI/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k70si657399pga.118.2018.03.27.03.12.15; Tue, 27 Mar 2018 03:12:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752233AbeC0KLJ (ORCPT + 99 others); Tue, 27 Mar 2018 06:11:09 -0400 Received: from terminus.zytor.com ([198.137.202.136]:49925 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751056AbeC0KLI (ORCPT ); Tue, 27 Mar 2018 06:11:08 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2RAAd8q609620; Tue, 27 Mar 2018 03:10:39 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2RAAdPH609617; Tue, 27 Mar 2018 03:10:39 -0700 Date: Tue, 27 Mar 2018 03:10:39 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Eric Dumazet Message-ID: 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 Reply-To: tglx@linutronix.de, eric.dumazet@gmail.com, mingo@kernel.org, bp@alien8.de, hpa@zytor.com, edumazet@google.com, linux-kernel@vger.kernel.org, hughd@google.com In-Reply-To: <20180323215818.127774-2-edumazet@google.com> References: <20180323215818.127774-2-edumazet@google.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cleanups] x86/cpuid: Allow cpuid_read() to schedule Git-Commit-ID: 67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1 Gitweb: https://git.kernel.org/tip/67bbd7a8d6bcdc44cc27105ae8c374e9176ceaf1 Author: Eric Dumazet AuthorDate: Fri, 23 Mar 2018 14:58:18 -0700 Committer: Thomas Gleixner 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 Signed-off-by: Thomas Gleixner Acked-by: Ingo Molnar Cc: Hugh Dickins Cc: Borislav Petkov Cc: Eric Dumazet 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 #include #include +#include #include #include @@ -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;