From patchwork Thu May 21 03:55:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Kumar X-Patchwork-Id: 474766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 81FB414012C for ; Thu, 21 May 2015 13:56:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753341AbbEUD4j (ORCPT ); Wed, 20 May 2015 23:56:39 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:58530 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753248AbbEUD4M (ORCPT ); Wed, 20 May 2015 23:56:12 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 May 2015 13:56:09 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 21 May 2015 13:56:07 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 23A0B2CE8056; Thu, 21 May 2015 13:56:07 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t4L3tw7D20775088; Thu, 21 May 2015 13:56:07 +1000 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t4L3tXvo026369; Thu, 21 May 2015 13:55:34 +1000 Received: from localhost.in.ibm.com ([9.77.207.189]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t4L3tTqL025982; Thu, 21 May 2015 13:55:29 +1000 From: Hemant Kumar To: linux-kernel@vger.kernel.org Cc: maddy@linux.vnet.ibm.com, srikar@linux.vnet.ibm.com, scottwood@freescale.com, mpe@ellerman.id.au, agraf@suse.de, kvm-ppc@vger.kernel.org, paulus@samba.org, warrier@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, acme@kernel.org, mingo@redhat.com, peterz@infradead.org, Hemant Kumar Subject: [PATCH v4 1/2] perf/kvm: Port perf kvm to powerpc Date: Thu, 21 May 2015 09:25:07 +0530 Message-Id: <1432180508-5060-1-git-send-email-hemant@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.3 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15052103-0025-0000-0000-00000187788E Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org From: Srikar Dronamraju perf kvm can be used to analyze guest exit reasons. This support already exists in x86. Hence, porting it to powerpc. - To trace KVM events : perf kvm stat record If many guests are running, we can track for a specific guest by using --pid as in : perf kvm stat record --pid - To see the results : perf kvm stat report The result shows the number of exits (from the guest context to host/hypervisor context) grouped by their respective exit reasons with their frequency. This patch makes use of the guest exit reasons available in "trace_book3s.h". It records on two already available tracepoints : "kvm_hv:kvm_guest_exit" and "kvm_hv:kvm_guest_enter". Note : This patch has a dependency on the patch "kvm/powerpc: Export kvm exit reasons" which exports the KVM exit reasons through the uapi. Here is a sample o/p: # pgrep qemu 19378 60515 2 Guests are running on the host. # perf kvm stat record -a ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 4.153 MB perf.data.guest (39624 samples) ] # perf kvm stat report -p 60515 Analyze events for pid(s) 60515, all VCPUs: VM-EXIT Samples Samples% Time% Min Time Max Time Avg time H_DATA_STORAGE 5006 35.30% 0.13% 1.94us 49.46us 12.37us ( +- 0.52% ) HV_DECREMENTER 4457 31.43% 0.02% 0.72us 16.14us 1.91us ( +- 0.96% ) SYSCALL 2690 18.97% 0.10% 2.84us 528.24us 18.29us ( +- 3.75% ) RETURN_TO_HOST 1789 12.61% 99.76% 1.58us 672791.91us 27470.23us ( +- 3.00% ) EXTERNAL 240 1.69% 0.00% 0.69us 10.67us 1.33us ( +- 5.34% ) Total Samples:14182, Total events handled time:49264158.30us. Signed-off-by: Srikar Dronamraju Signed-off-by: Hemant Kumar --- Changes : - Moved the uapi related changes to arch/powerpc patchset. This patch has a dependency on : http://www.mail-archive.com/linuxppc-dev@lists.ozlabs.org/msg89485.html which exports the kvm exit reasons. tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/Build | 1 + tools/perf/arch/powerpc/util/kvm-stat.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tools/perf/arch/powerpc/util/kvm-stat.c diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile index 7fbca17..21322e0 100644 --- a/tools/perf/arch/powerpc/Makefile +++ b/tools/perf/arch/powerpc/Makefile @@ -1,3 +1,4 @@ ifndef NO_DWARF PERF_HAVE_DWARF_REGS := 1 endif +HAVE_KVM_STAT_SUPPORT := 1 diff --git a/tools/perf/arch/powerpc/util/Build b/tools/perf/arch/powerpc/util/Build index 7b8b0d1..c8fe207 100644 --- a/tools/perf/arch/powerpc/util/Build +++ b/tools/perf/arch/powerpc/util/Build @@ -1,5 +1,6 @@ libperf-y += header.o libperf-y += sym-handling.o +libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_DWARF) += skip-callchain-idx.o diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c new file mode 100644 index 0000000..24e06bf --- /dev/null +++ b/tools/perf/arch/powerpc/util/kvm-stat.c @@ -0,0 +1,33 @@ +#include "../../util/kvm-stat.h" +#include + +define_exit_reasons_table(hv_exit_reasons, kvm_trace_symbol_exit); + +static struct kvm_events_ops exit_events = { + .is_begin_event = exit_event_begin, + .is_end_event = exit_event_end, + .decode_key = exit_event_decode_key, + .name = "VM-EXIT" +}; + +const char *const kvm_events_tp[] = { + "kvm_hv:kvm_guest_exit", + "kvm_hv:kvm_guest_enter", + NULL, +}; + +struct kvm_reg_events_ops kvm_reg_events_ops[] = { + { .name = "vmexit", .ops = &exit_events }, + { NULL, NULL }, +}; + +const char * const kvm_skip_events[] = { + NULL, +}; + +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused) +{ + kvm->exit_reasons = hv_exit_reasons; + kvm->exit_reasons_isa = "HV"; + return 0; +}