Received: by 10.213.65.68 with SMTP id h4csp736741imn; Fri, 23 Mar 2018 15:00:30 -0700 (PDT) X-Google-Smtp-Source: AG47ELubQfhsIHNsLku0Utp3U5br4XoZYp/k4DGvcdWkmdw7ZT8gFlm2hwJCyiXYzbrhrQg0Wxex X-Received: by 10.99.113.94 with SMTP id b30mr21959152pgn.196.1521842430769; Fri, 23 Mar 2018 15:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521842430; cv=none; d=google.com; s=arc-20160816; b=sXicijxtt+yICF5R1ZjXI2qoapNVGfGSw2m0URmc7DYcvW9K5cAey6WtMbbsZrK64n RbcCL8aFJe3H9UyXYfZ4OxtPRRYZA1UAdjIoCqZIYpDIXzpXNJ9alIW/khlJ84i1iyqg Tjiv29M8WnSchCZ8NulwkQL9FDGyPaAQWQHR2rbwu4sCgsu3ApHmBfo4KMVBtFXmNmVW smwK5y2Rmu0tuqP8+BCcXJLlNZot7PfmmBbn0sjxRgzRTkK0K0RMXtyeSjcK5a6+nf2i ByGvVPVEEoimSvRlrL++SMigTw/bFAUJy4Ym0XsbIWlbC/3GFwScdsZRaJHlbpLqCJLc EAog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=hsdV4dPf8Y/9hQc323cp2vUHaErIZQUZ5jsOSGDGyE0=; b=KRAldGDCwlvsj5SnpOnY2vqrnAezzhngoCzLkLW5Bqd96OBTLYVmk9IU6WEsD5NCxC jAFQaJyHgWGZBRGSuCuydzZUHFqR81GoMh7V7OyPRVfrefUVNtxjvfVscUhmwlnx/cKi dbXlBWUY4nYNgD3b4ZMJF5EEQyVSFflaOxrhYKU3HgFe5WAcryb9R4pCvZK4cXzFW4O2 X4+JDA4UdhpmTEL442q12mewTzzU4y6mj6edcNSfOBAwL+WTdo1ATgc3tm/y9KoniMnI 5+LGIsQHhROD3nbWbPl4mWcaKWkBGiJlDXBKzXY3+EqO0PdKxY5xI8XiPQxfLWsTUqzj eyfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=f/sHqc3j; 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 g7si986252pfm.106.2018.03.23.15.00.15; Fri, 23 Mar 2018 15:00: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; dkim=pass header.i=@google.com header.s=20161025 header.b=f/sHqc3j; 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 S1752077AbeCWV7Y (ORCPT + 99 others); Fri, 23 Mar 2018 17:59:24 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:46699 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751288AbeCWV7X (ORCPT ); Fri, 23 Mar 2018 17:59:23 -0400 Received: by mail-pg0-f66.google.com with SMTP id t12so3304605pgp.13 for ; Fri, 23 Mar 2018 14:59:22 -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; bh=hsdV4dPf8Y/9hQc323cp2vUHaErIZQUZ5jsOSGDGyE0=; b=f/sHqc3jKFEuHZeAuC3lymprbXGKglgqUkga7faG0GxmAxISX4VrHSv2CMuKTHUp5K EEEWJeQJc7VxL/jMIWJhUCl6eMrlscJs24wPmXsDbHchoXbwD10/1vxcwWjrcseqKDcY 4m+1MUxqNlL72iU3mDNesuVo61ZKh5/jO6rf/1+J3LBY2qMu293J0ECv3F8zeU41VGzP /rx4isz8J1FmvgDRu5Fdc2Ty3LEBs3BZ2KZjpPm9x+wQrkhO7Z8/KXGOqSFQCJ+WU9YQ jlVvVBZ+0Jzpwlau4YNdbcvR1Xoh3Muy+5MDJ1tah4pxrIsP821M7ZbBainZ8+THcy7o B7Ug== 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; bh=hsdV4dPf8Y/9hQc323cp2vUHaErIZQUZ5jsOSGDGyE0=; b=cIdB8T673p9KBahKQKZaDt2kdwdoBxUffzBjMnehoi2ORiMcwJ5auAgM8CmWDR/ePT r02WsYT0ErbrUwz1NAsyeiXqnl7qWNFB+XU2ti4lmkcSzt9w4sUb18m89jrwMVk0lMGi d4xyCyXt11A5d17qNNMZy6u0WdsW/pjzHuKkS4hMbZV0NewckAp0zNpTTxTLSmr7rKZ7 E6p9sdZN2LfgoaBdwpMUV4+dWkNic9LrXURTfAVkzo/xkSgA+aCi14b7vqoen7CkqymA +YZ9XpelfvK7s4Ss6HfoyaKxXndgpXsCcaqA+zYUJyHGTppxmNiXbKFFN52whG+A2PqM SoJg== X-Gm-Message-State: AElRT7EVO0/xCeM899bRP5FArZOH6ubsVWalT036SdhGEjytfmZaAQ3q 3WEF4RKr69sVQkPZMj4ZMqh9toOyxe0= X-Received: by 10.101.70.8 with SMTP id v8mr21622160pgq.336.1521842361812; Fri, 23 Mar 2018 14:59:21 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id q13sm17594001pgr.52.2018.03.23.14.59.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Mar 2018 14:59:20 -0700 (PDT) From: Eric Dumazet To: x86 Cc: lkml , Eric Dumazet , Eric Dumazet , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Hugh Dickins Subject: [PATCH v3 1/2] x86, msr: allow rdmsr_safe_on_cpu() to schedule Date: Fri, 23 Mar 2018 14:58:17 -0700 Message-Id: <20180323215818.127774-1-edumazet@google.com> X-Mailer: git-send-email 2.17.0.rc0.231.g781580f067-goog 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 on all cpus. KASAN kernels would see ~10ms latencies simply reading one MSR. 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. Converts 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 Cc: "H. Peter Anvin" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Hugh Dickins --- 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 693cce0be82dffb822cecd0c7e38d2821aff896c..761ba062afdaf7f7d0603ed94ed6cc3e46b37f76 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); -- 2.17.0.rc0.231.g781580f067-goog