From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFA76C432BE for ; Thu, 29 Jul 2021 13:00:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D90EF60041 for ; Thu, 29 Jul 2021 13:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237384AbhG2NA4 (ORCPT ); Thu, 29 Jul 2021 09:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237222AbhG2NAy (ORCPT ); Thu, 29 Jul 2021 09:00:54 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A7C2C061765; Thu, 29 Jul 2021 06:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=h5N7LaoEx0xFRONzbq8/zc8krUwJF4ItQdsTl0gzVm8=; b=DWV6yTn9RHEIKeoT1XxGwkxI89 TrAXhPIP0ojWhAXolTHhyQ7RVMHiFvg+CoSUfryoxINO2ZrsmzYk/5cTlnkjT6A6voEzvLsb/j51s poLcddukpUev/1hOzINAIjWJ4JB3+f81r+6vw+xsMYR10yvkWbs2d8FI+T7CYK6rNKN9uMgUGylT7 fx6RnbRIwQA819xJp38fq6xTulv7akx/H+d68Mk2B7yVP83j6rQ8fwJIjuIr72Nlql7oMP7XiyW5i cwzRw/bDbIxqpLGRpcAH27dMOEl0RifsDpjWgTWUSPRXX7FWmI7L4MdNtOlGat45N3/yeGxVuN/nm HBn/dSkQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m95cI-00H4Xv-QC; Thu, 29 Jul 2021 12:58:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4B47C300215; Thu, 29 Jul 2021 14:58:23 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 13DA7200DB821; Thu, 29 Jul 2021 14:58:23 +0200 (CEST) Date: Thu, 29 Jul 2021 14:58:23 +0200 From: Peter Zijlstra To: Like Xu Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86/pmu: Introduce pmc->is_paused to reduce the call time of perf interfaces Message-ID: References: <20210728120705.6855-1-likexu@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210728120705.6855-1-likexu@tencent.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 08:07:05PM +0800, Like Xu wrote: > From: Like Xu > > Based on our observations, after any vm-exit associated with vPMU, there > are at least two or more perf interfaces to be called for guest counter > emulation, such as perf_event_{pause, read_value, period}(), and each one > will {lock, unlock} the same perf_event_ctx. The frequency of calls becomes > more severe when guest use counters in a multiplexed manner. > > Holding a lock once and completing the KVM request operations in the perf > context would introduce a set of impractical new interfaces. So we can > further optimize the vPMU implementation by avoiding repeated calls to > these interfaces in the KVM context for at least one pattern: > > After we call perf_event_pause() once, the event will be disabled and its > internal count will be reset to 0. So there is no need to pause it again > or read its value. Once the event is paused, event period will not be > updated until the next time it's resumed or reprogrammed. And there is > also no need to call perf_event_period twice for a non-running counter, > considering the perf_event for a running counter is never paused. > > Based on this implementation, for the following common usage of > sampling 4 events using perf on a 4u8g guest: > > echo 0 > /proc/sys/kernel/watchdog > echo 25 > /proc/sys/kernel/perf_cpu_time_max_percent > echo 10000 > /proc/sys/kernel/perf_event_max_sample_rate > echo 0 > /proc/sys/kernel/perf_cpu_time_max_percent > for i in `seq 1 1 10` > do > taskset -c 0 perf record \ > -e cpu-cycles -e instructions -e branch-instructions -e cache-misses \ > /root/br_instr a > done > > the average latency of the guest NMI handler is reduced from > 37646.7 ns to 32929.3 ns (~1.14x speed up) on the Intel ICX server. > Also, in addition to collecting more samples, no loss of sampling > accuracy was observed compared to before the optimization. > > Signed-off-by: Like Xu Looks sane I suppose. Acked-by: Peter Zijlstra (Intel) What kinds of VM-exits are the most common?