Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp536185pxb; Thu, 15 Apr 2021 00:02:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoWxHu3jqmHsU1ZVqaxRNZUd+3VH7hOKic2eZLjPxxkATFBJThHv1ZC5jKxqgQCVai8t7l X-Received: by 2002:a05:6402:c7:: with SMTP id i7mr2330855edu.33.1618470165067; Thu, 15 Apr 2021 00:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618470165; cv=none; d=google.com; s=arc-20160816; b=Yke+0akKuXRqKuu6HY7CMtJXLh0iIcL4AJBMdmSn+2LtkE2N3xTKI+sNn2keVCgGyO Cz2Urn9DeuG7eW65EnymZdYNbTX/eSb5iMGlC7O/hAhlC6uENWbVJRBGG0n/6uGQfqWz hCyWKQjhJ5Tr9RczKXjaTRh9mgLF3YNwbRzvU0h1wWz8co23IeaxcBCtaeT+HjWNuwJ+ fsctgXGGSt9Yc+x58lf1LcBsBUCW5R+ps1uFr6L1EvgpiNSyzpyAip8FqyuB8t0ptzwH o0SiNh8Jtc+elrzALLNJSz6nG082NaAP0T2Gs1GBXCiMhUHjor/WnVNnzrUxeSiA0LRy MXIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=By5knZMLaRvgEUAntd8CyDbsLBH9zZSbzNUc0zYGKm8=; b=XCLtxrUoULJXq4Y53E/scdN/iHxG25aljmihCmbSUyBi2A3lVZJojtv2Ok+HEPxDBX uw88PzDPCXtgNBbZJu3iq7/NjuyXK6pw9UJXzUEE7qHqT65cgaGP8AZ92rUFk2mOCYOM swfx+gf7sjC4QVBx7fkVirvEguqZTRJ0m3QuTWLg169MPNJ8vVWUTa7Yq/3jgnuD/kra ibDG0it/srIfMUpTbPAuvP9w5LEiV0EX/FslHPdmz2STndkP4ybB3cLU+d0Jo1VGmoEf SVFYOwOzmb0EnahgWN1oazK/doK84l8jH0IlhG/AQr96lB4zkadDQ1v5sXx3FxH9Qn0F U3fg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kl2si1579093ejc.82.2021.04.15.00.02.21; Thu, 15 Apr 2021 00:02:45 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbhDOHA2 (ORCPT + 99 others); Thu, 15 Apr 2021 03:00:28 -0400 Received: from mx313.baidu.com ([180.101.52.140]:11491 "EHLO njjs-sys-mailin07.njjs.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231217AbhDOHA1 (ORCPT ); Thu, 15 Apr 2021 03:00:27 -0400 Received: from unknown.domain.tld (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin07.njjs.baidu.com (Postfix) with ESMTP id BFF5419480054; Thu, 15 Apr 2021 15:00:01 +0800 (CST) From: Li RongQing To: linux-kernel@vger.kernel.org, namhyung@kernel.org, jolsa@redhat.com, alexander.shishkin@linux.intel.com, mark.rutland@arm.com, acme@kernel.org, mingo@redhat.com, peterz@infradead.org, lirongqing@baidu.com Subject: [PATCH][resend] perf x86 kvm-stat: support to analyze kvm msr Date: Thu, 15 Apr 2021 15:00:01 +0800 Message-Id: <1618470001-7239-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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