Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1528077pxy; Fri, 23 Apr 2021 10:07:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZTLHWcYx0J4eXMJYW+JffM6kPcPFW0tkyODFhklK4u4PzEKSLW3Dxm19AgRnmX7v+wGPD X-Received: by 2002:a05:6402:3495:: with SMTP id v21mr5647118edc.117.1619197644697; Fri, 23 Apr 2021 10:07:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619197644; cv=none; d=google.com; s=arc-20160816; b=qmXOkH+0XWnpN9TIoZ3mgouTAccKSlt/rN18TIc/hAkF/bkvSE4LRpiJTnA63jOqXr BgGudcgJEk+TGDo+7aE0uvm/nvlwEOa+oyOsiS3quywzytlxX/+qdOlp7LrC0ulOHEY5 losOXtHfG8VkIUCi+4IBU586GeEWe1x+OKc+0V/oABgKm0wEmfLNIyYBL2RF6P2ac7vF cWn0yWr/IvIRlSvnnz3vxbrglH3fFcG/z9zSIZa/Lf8cxdXRhaYySkqT3Vt8Ag0+3Y3t lkWHiPPKQGe+yxXdvLsmxLu956wPhYcBAEvsoibd8ynXRo8MR7k+OoyU+srKcMOBm64A zleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=Scw7Z57rdAZa2hiqBu8RC+dLrEZpg3DOUeAN5WDTx40=; b=0QJ3TFvjd8ffgPOY48z3x3szp6UU4y4CStGjNCn9LdTnKZKSkuLPnpMwAGSh80u5Y9 ggOhp81713Nyfz1lqA6KtDh/dpOUeVxSLX30sTp/RQJpS8H3pLvaFlBAMcsPRwQU+VYp pgZG7NHwt/arr7jA3rNUbXNZf7gshGiAFPduQenQ3C/7K7NxfFD0kaBe0HgMv4zczgG6 ry8wKPWyNZ6DhC6vVHCNshC+N0pYvfA2cem7xTXddWwcVZOfIUUzk+UNUZ3XFAOa4paH gQigJZykeA4pk6jpZo+w6WIFgiBFstEO2JmLyxkFwXPuLTSt+iCytFZoxmXeXWyWgTAJ Rqsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k23si5728476edx.591.2021.04.23.10.07.01; Fri, 23 Apr 2021 10:07:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243167AbhDWRGl (ORCPT + 99 others); Fri, 23 Apr 2021 13:06:41 -0400 Received: from mail-lj1-f175.google.com ([209.85.208.175]:44584 "EHLO mail-lj1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhDWRGk (ORCPT ); Fri, 23 Apr 2021 13:06:40 -0400 Received: by mail-lj1-f175.google.com with SMTP id a25so43143908ljm.11 for ; Fri, 23 Apr 2021 10:06:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Scw7Z57rdAZa2hiqBu8RC+dLrEZpg3DOUeAN5WDTx40=; b=Jm6GZCbiNgZ4/GhUVJ0hq2PdhhB29uKJ5z5S66fS5gShijkR3C4F7xQiiQJfGHJnHD lbwgapj1lgy+jzxczVW2BJQCPl8XWucYTCGjmO4cZhfe7cI+Eui55YEXq4FJlxEXy+TF Zh9xuUUCDz4Sep1MCpCI0+g8lB3NfJTYo7K82bfBB28ChqP9YLXthuzcGDqKVkTFRf1v lFWGtDYUQQ4cUr0kyKG0gYj9YqySasJBJuDM2EBOfBJiKbtzF7qo84weYgLUYUN0KtVR DRMQWA5kCY5ls6I0VQQdRDUBrl4xfpRvTFcWxwvxWr6bsoOT7/Pc79vDZFIu5WA/bRWx bPkA== X-Gm-Message-State: AOAM532ZGjS84rFa4ox+gX7Am9JKNQDjBTmxaJgSDsAu4orvGZSGb4Tl sNv/lLE+1BX1QvKXfDnT+NqAlDfE4hJeuKMRHQE= X-Received: by 2002:a05:651c:30b:: with SMTP id a11mr3385392ljp.52.1619197562455; Fri, 23 Apr 2021 10:06:02 -0700 (PDT) MIME-Version: 1.0 References: <1618470001-7239-1-git-send-email-lirongqing@baidu.com> In-Reply-To: From: Namhyung Kim Date: Sat, 24 Apr 2021 02:05:51 +0900 Message-ID: Subject: Re: [PATCH][resend] perf x86 kvm-stat: support to analyze kvm msr To: "Li,Rongqing" Cc: "linux-kernel@vger.kernel.org" , "jolsa@redhat.com" , "alexander.shishkin@linux.intel.com" , "mark.rutland@arm.com" , "acme@kernel.org" , "mingo@redhat.com" , "peterz@infradead.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Apr 22, 2021 at 11:33 AM Li,Rongqing wrote: > > Subject: [PATCH][resend] perf x86 kvm-stat: support to analyze kvm msr > > > > From: Lei Zhao > > > > usage: > > - kvm stat > > run a command and gather performance counter statistics > > > > - show the result: > > perf kvm stat report --event=msr > > > > See the msr events: > > > > Analyze events for all VMs, all VCPUs: > > > > MSR Access Samples Samples% Time% Min Time Max Time Avg time > > > > 0x6e0:W 67007 98.17% 98.31% 0.59us 10.69us 0.90us ( +- > > 0.10% ) > > 0x830:W 1186 1.74% 1.60% 0.53us 108.34us 0.82us ( +- > > 11.02% ) > > 0x3b:R 66 0.10% 0.09% 0.56us 1.26us 0.80us ( +- > > 3.24% ) > > > > Total Samples:68259, Total events handled time:61150.95us. > > > > Signed-off-by: Li RongQing > > Signed-off-by: Lei Zhao Acked-by: Namhyung Kim Thanks, Namhyung > > --- > > tools/perf/arch/x86/util/kvm-stat.c | 46 > > +++++++++++++++++++++++++++++++++++ > > 1 files changed, 46 insertions(+), 0 deletions(-) > > > > diff --git a/tools/perf/arch/x86/util/kvm-stat.c > > b/tools/perf/arch/x86/util/kvm-stat.c > > index 0729204..c5dd54f 100644 > > --- a/tools/perf/arch/x86/util/kvm-stat.c > > +++ b/tools/perf/arch/x86/util/kvm-stat.c > > @@ -133,11 +133,56 @@ static void ioport_event_decode_key(struct > > perf_kvm_stat *kvm __maybe_unused, > > .name = "IO Port Access" > > }; > > > > + /* The time of emulation msr is from kvm_msr to kvm_entry. */ static > > +void msr_event_get_key(struct evsel *evsel, > > + struct perf_sample *sample, > > + struct event_key *key) > > +{ > > + key->key = evsel__intval(evsel, sample, "ecx"); > > + key->info = evsel__intval(evsel, sample, "write"); } > > + > > +static bool msr_event_begin(struct evsel *evsel, > > + struct perf_sample *sample, > > + struct event_key *key) > > +{ > > + if (!strcmp(evsel->name, "kvm:kvm_msr")) { > > + msr_event_get_key(evsel, sample, key); > > + return true; > > + } > > + > > + return false; > > +} > > + > > +static bool msr_event_end(struct evsel *evsel, > > + struct perf_sample *sample __maybe_unused, > > + struct event_key *key __maybe_unused) { > > + return kvm_entry_event(evsel); > > +} > > + > > +static void msr_event_decode_key(struct perf_kvm_stat *kvm > > __maybe_unused, > > + struct event_key *key, > > + char *decode) > > +{ > > + scnprintf(decode, decode_str_len, "%#llx:%s", > > + (unsigned long long)key->key, > > + key->info ? "W" : "R"); > > +} > > + > > +static struct kvm_events_ops msr_events = { > > + .is_begin_event = msr_event_begin, > > + .is_end_event = msr_event_end, > > + .decode_key = msr_event_decode_key, > > + .name = "MSR Access" > > +}; > > + > > const char *kvm_events_tp[] = { > > "kvm:kvm_entry", > > "kvm:kvm_exit", > > "kvm:kvm_mmio", > > "kvm:kvm_pio", > > + "kvm:kvm_msr", > > NULL, > > }; > > > > @@ -145,6 +190,7 @@ struct kvm_reg_events_ops kvm_reg_events_ops[] = { > > { .name = "vmexit", .ops = &exit_events }, > > { .name = "mmio", .ops = &mmio_events }, > > { .name = "ioport", .ops = &ioport_events }, > > + { .name = "msr", .ops = &msr_events }, > > { NULL, NULL }, > > }; > > > > -- > > 1.7.1 >