Received: by 10.213.65.68 with SMTP id h4csp481809imn; Tue, 27 Mar 2018 03:12:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELvZ3dgK5QvlQ+w/18arIMKuMuJrAVOv8DVy50mIzHXngTXL05wQCWIVxOPaFRYE7W/VEBAA X-Received: by 2002:a17:902:a9c7:: with SMTP id b7-v6mr43512072plr.190.1522145532202; Tue, 27 Mar 2018 03:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522145532; cv=none; d=google.com; s=arc-20160816; b=TGouFLS++roUnQvxhF+VAqujuzMfhn89VMVXBGXSISATfrJ33hNaS0ABPmFebf5wqr CmiyX/0Q3ddxW6snhwOD4EYAlPcGgYDG2+Rtau1X17MsPTYK+qLkHwBRS6oztX5zK99r zWwsktM9Crr2i2wCaAoNGFta8LjjaxCi1dFrTa0cV0vOg9N1v1H6/F5++Vg4ptnsTqbn 0h6zzlwA7w4ubXTI7T95tgN+fbS4quUemYw9RssDyWvlkkXi4gWocU5/f+8gwabdtLz/ Ythe2EOLG8SiavjHwosHyQx6uEyOsOZrfz7cjO2LW3MKFSubVqdZ7DxaT/qK3Vqypc2C 93Xg== 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=/L0WmLxgprs4f+8d1pyCnzIXZ2VH/khThPjW3OXGw+E=; b=pvo2Zmyb8W41uUhKkrkzT6b99ZLeQ7LANHqDW6khlkjMYXQdy/BK3+BF87Ba5GkpMs Jo9NR8ccz69E7kcxiKtKQEjaiLv79l8VTFkUoVwxM69X/y/BKS+Uax2pbwbdwSWLlAVF SSZGBYe/4/TDD210Bf/4V898b/+GKpZaED3UcL2k54SsTuicvZMRuEiRCcvV03UHAoeG iomJJUU3wVPf0kC2PWTSatPHC+dhFGjV/F8Lq/C2YLEdx3Jk9OCorGap8AscInq/u7w5 RSo2JoGkO6RJtOb6YKwVI4kK1bFb7rMnRLtVy50LMKdNOnrJI5ST0bHr0opSBgBiIhCs 0ntw== 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 m77si717509pfk.56.2018.03.27.03.11.57; Tue, 27 Mar 2018 03:12:12 -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 S1752180AbeC0KKj (ORCPT + 99 others); Tue, 27 Mar 2018 06:10:39 -0400 Received: from terminus.zytor.com ([198.137.202.136]:42141 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750978AbeC0KKi (ORCPT ); Tue, 27 Mar 2018 06:10:38 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2RAA6T0609580; Tue, 27 Mar 2018 03:10:06 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2RAA5mj609575; Tue, 27 Mar 2018 03:10:05 -0700 Date: Tue, 27 Mar 2018 03:10:05 -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: mingo@kernel.org, bp@alien8.de, eric.dumazet@gmail.com, linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de, edumazet@google.com, hughd@google.com Reply-To: bp@alien8.de, mingo@kernel.org, eric.dumazet@gmail.com, hughd@google.com, linux-kernel@vger.kernel.org, hpa@zytor.com, edumazet@google.com, tglx@linutronix.de In-Reply-To: <20180323215818.127774-1-edumazet@google.com> References: <20180323215818.127774-1-edumazet@google.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cleanups] x86/msr: Allow rdmsr_safe_on_cpu() to schedule Git-Commit-ID: 07cde313b2d21f728cec2836db7cdb55476f7a26 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: 07cde313b2d21f728cec2836db7cdb55476f7a26 Gitweb: https://git.kernel.org/tip/07cde313b2d21f728cec2836db7cdb55476f7a26 Author: Eric Dumazet AuthorDate: Fri, 23 Mar 2018 14:58:17 -0700 Committer: Thomas Gleixner CommitDate: Tue, 27 Mar 2018 12:01:47 +0200 x86/msr: Allow rdmsr_safe_on_cpu() to schedule High latencies can be observed caused by a daemon periodically reading various MSR on all cpus. On KASAN enabled kernels ~10ms latencies can be observed simply reading one MSR. 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. All usage sites are in preemptible context, convert rdmsr_safe_on_cpu() to use a completion instead of busy polling. Overall daemon cpu usage was reduced by 35 %, and latencies caused by msr_read() disappeared. 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-1-edumazet@google.com --- arch/x86/lib/msr-smp.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/arch/x86/lib/msr-smp.c b/arch/x86/lib/msr-smp.c index 693cce0be82d..761ba062afda 100644 --- a/arch/x86/lib/msr-smp.c +++ b/arch/x86/lib/msr-smp.c @@ -2,6 +2,7 @@ #include #include #include +#include #include static void __rdmsr_on_cpu(void *info) @@ -143,13 +144,19 @@ void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs) } EXPORT_SYMBOL(wrmsr_on_cpus); +struct msr_info_completion { + struct msr_info msr; + struct completion done; +}; + /* These "safe" variants are slower and should be used when the target MSR may not actually exist. */ static void __rdmsr_safe_on_cpu(void *info) { - struct msr_info *rv = info; + struct msr_info_completion *rv = info; - rv->err = rdmsr_safe(rv->msr_no, &rv->reg.l, &rv->reg.h); + rv->msr.err = rdmsr_safe(rv->msr.msr_no, &rv->msr.reg.l, &rv->msr.reg.h); + complete(&rv->done); } static void __wrmsr_safe_on_cpu(void *info) @@ -161,17 +168,26 @@ static void __wrmsr_safe_on_cpu(void *info) int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) { + struct msr_info_completion rv; + call_single_data_t csd = { + .func = __rdmsr_safe_on_cpu, + .info = &rv, + }; int err; - struct msr_info rv; memset(&rv, 0, sizeof(rv)); + init_completion(&rv.done); + rv.msr.msr_no = msr_no; - rv.msr_no = msr_no; - err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1); - *l = rv.reg.l; - *h = rv.reg.h; + err = smp_call_function_single_async(cpu, &csd); + if (!err) { + wait_for_completion(&rv.done); + err = rv.msr.err; + } + *l = rv.msr.reg.l; + *h = rv.msr.reg.h; - return err ? err : rv.err; + return err; } EXPORT_SYMBOL(rdmsr_safe_on_cpu);