Received: by 10.213.65.68 with SMTP id h4csp1601024imn; Mon, 19 Mar 2018 08:27:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELu/vPV78J8EXmwBg06jmC6BK1ID51ztqMG8OjVAlbdnoWmECdaHa0OrnAzXCQmKt0CUXPfg X-Received: by 2002:a17:902:85:: with SMTP id a5-v6mr8220619pla.99.1521473239334; Mon, 19 Mar 2018 08:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521473239; cv=none; d=google.com; s=arc-20160816; b=Nt29vPsVbPu/4tL8Te+vnL0VhDUSStR7HlCL04tYjfoCm20jMx/wojH+e0qY708Rfo qmi/RLdiXcHEUktS09U1znDto9mrAgf51OFbgneLZhIl9h38iz3egI0D5hyb+deX4qCk fK2j8sMITSumMBaggQlLuPO72I3DiReL/NtyhEYpHMH+wYQ35OReKzlQVu4SeHv7g818 SERKRRcK9gpoBjC4Ay0AKf7uh2eKpkjpxTJ2hPvKQX3+4+DlYkUyxkm36WdNwKwdeT7v VqDysOdhG+Ca9lv9MOVjBUcJ6zqWqXBGD4RO17ygDUmcUrF4036dYzXWqyjEIMcLfOqq hlhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IdaycAEsutTIBnqIrOI+kPzjQzA1AIcJvluleI6YrvY=; b=HqwmF1FstdL1lGm0stgtGPqgyYCB+NazdU5cHJISFxoOongkHODdC05KXwS3KnEM9E 6SpUA/bXK0zWG51xr7RfWZWhiP7JIeXrgFVDc0DQywvpyIuC+VC8ZOd84igYUroNcn/T k0EGkhM3CSicTN7593vdxnWvG5uCHh8tZIPpqMjFtnyeYyaeOOojltTXEjbMBXBhNhaK BSji/K36jn91ODowlPoJxPum+Y7PUGaEJx6LFt8V41V1BkYBYrcUA42KC5k+35NzEB3a QRSJNfskKeiA9w5ouu3TZDfcjkx2Vchn1mdS07eiAvWhPtStaeGqXNOIlNb+vxUZS8OA 0LeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iOlA65vr; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si132098pgb.365.2018.03.19.08.27.05; Mon, 19 Mar 2018 08:27:19 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=iOlA65vr; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755848AbeCSPZR (ORCPT + 99 others); Mon, 19 Mar 2018 11:25:17 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:41782 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755842AbeCSPZK (ORCPT ); Mon, 19 Mar 2018 11:25:10 -0400 Received: by mail-pl0-f66.google.com with SMTP id b7-v6so6340389plr.8 for ; Mon, 19 Mar 2018 08:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IdaycAEsutTIBnqIrOI+kPzjQzA1AIcJvluleI6YrvY=; b=iOlA65vrYZj7b4DGsaKTb4C1WqOW9ncVZgCJIQ4RcI11Ej8fQdJw3v0X8PFvLS+yGG JizlL1EDRdgbwQwRns1IDGogqD8eeHgiJF7f/476Q2GDhYiuyMzE+9IUwUmopke36oIH DQ1FrJ6r3s5BPk+LjQancueUCiUc91Yd91JVeuwCVe1c9n3ceKnFJO7adztnlukxZaBZ D/bbyWr886cv9vjRmTQ8iMjMkirhTcRrNJCMgMrsqr81C/cXOPgQ6p0riIkZv+BCnmpi FXzDG9Hid2JDMBN+Sg0FztihGHqhm8tcb/RXpY08aeqCzDMsOICNg8KCKuXp1auU9oth f7yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IdaycAEsutTIBnqIrOI+kPzjQzA1AIcJvluleI6YrvY=; b=I20NTAtsrorUOVCO1tU7NwiIpiGqGWBCnFTEhym+cqFeIFun4cs96uZx+/kK/RVBs8 SwnKlZucLbgkN6f7ZTHkYEfEhkoKB0Bn3cgTbjMxDvelxaEHRMmKGrDzL5p8Gmw50K8M PJqv4JSZUizqru50LeS3V5B9tNR5Pr+HTs37i5vXem5yaT6HBrUcx0mXDh7QLBaPS+OO 0Mc3cR2fZJ3sQXoCIXAOVMf89cBPiwsneOjTBLd6jEEzywDk0CEuRBkXkN2JC199e8es 4v6zkqmh9I66DCSaMq78IEKMWfBm31HoKP1WPvu56LUjq1yHavZr7jRxwHZLOI7ymEDZ sJzw== X-Gm-Message-State: AElRT7GCoUtkrKizylbMd4UQHkHg8bQjtarK309PLx8g576WZw3q/41n DHXn/ZCNrYIbfF0cMEhi5zXQ1UcANys= X-Received: by 2002:a17:902:788e:: with SMTP id q14-v6mr13258835pll.396.1521473109742; Mon, 19 Mar 2018 08:25:09 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id k9sm486251pfc.184.2018.03.19.08.25.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Mar 2018 08:25:08 -0700 (PDT) From: Eric Dumazet To: x86 Cc: lkml , Eric Dumazet , Eric Dumazet , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Hugh Dickins Subject: [PATCH v2 2/2] x86, cpuid: allow cpuid_read() to schedule Date: Mon, 19 Mar 2018 08:25:03 -0700 Message-Id: <20180319152503.123372-2-edumazet@google.com> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: <20180319152503.123372-1-edumazet@google.com> References: <20180319152503.123372-1-edumazet@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I noticed high latencies caused by a daemon periodically reading various MSR and cpuid on all cpus. KASAN kernels would see ~10ms latencies simply reading one cpuid. Even without KASAN, sending IPI to CPU in deep sleep state or blocking hard IRQ in a a long section, then waiting for the answer can consume hundreds of usec or more. Switching to smp_call_function_single_async() and a completion allows to reschedule and not burn cpu cycles. Signed-off-by: Eric Dumazet Cc: "H. Peter Anvin" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Hugh Dickins --- 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 0931a105ffe16cde4640e759efa600b23a756d84..1d300f96df4b316dbe3392c8221467cfd8593272 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; -- 2.16.2.804.g6dcf76e118-goog