From patchwork Mon Apr 20 15:02:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Kumar X-Patchwork-Id: 462799 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2C9DE14007F for ; Tue, 21 Apr 2015 01:07:36 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 121F41A1AB9 for ; Tue, 21 Apr 2015 01:07:36 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from e28smtp07.in.ibm.com (e28smtp07.in.ibm.com [122.248.162.7]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4661D1A0C9F for ; Tue, 21 Apr 2015 01:03:44 +1000 (AEST) Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Apr 2015 20:33:42 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Apr 2015 20:33:40 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id C94D21258056 for ; Mon, 20 Apr 2015 20:35:35 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay03.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3KF3dCp590092 for ; Mon, 20 Apr 2015 20:33:39 +0530 Received: from d28av03.in.ibm.com (localhost [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3KEeUqA016697 for ; Mon, 20 Apr 2015 20:10:31 +0530 Received: from localhost.in.ibm.com ([9.124.35.27]) by d28av03.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3KEdY8A011987; Mon, 20 Apr 2015 20:10:29 +0530 From: Hemant Kumar To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 3/5] perf/kvm: KVM exit events analysis Date: Mon, 20 Apr 2015 20:32:13 +0530 Message-Id: <1429542135-10632-4-git-send-email-hemant@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1429542135-10632-1-git-send-email-hemant@linux.vnet.ibm.com> References: <1429542135-10632-1-git-send-email-hemant@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15042015-0025-0000-0000-0000045D137C Cc: maddy@linux.vnet.ibm.com, srikar@linux.vnet.ibm.com, peterz@infradead.org, linux-kernel@vger.kernel.org, acme@kernel.org, paulus@samba.org, warrier@linux.vnet.ibm.com, Hemant Kumar , mingo@kernel.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Srikar Dronamraju This patch adds KVM exit event analysis support to perf for powerpc. - 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 - Show the results : perf kvm stat report The results show the number of exits (from the guest context to host/hypervisor context) grouped into 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". 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 --- arch/powerpc/include/uapi/asm/kvm_perf.h | 15 +++++++++++++++ tools/perf/arch/powerpc/Makefile | 1 + tools/perf/arch/powerpc/util/Build | 1 + tools/perf/arch/powerpc/util/kvm-stat.c | 33 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 arch/powerpc/include/uapi/asm/kvm_perf.h create mode 100644 tools/perf/arch/powerpc/util/kvm-stat.c diff --git a/arch/powerpc/include/uapi/asm/kvm_perf.h b/arch/powerpc/include/uapi/asm/kvm_perf.h new file mode 100644 index 0000000..30fa670 --- /dev/null +++ b/arch/powerpc/include/uapi/asm/kvm_perf.h @@ -0,0 +1,15 @@ +#ifndef _ASM_POWERPC_KVM_PERF_H +#define _ASM_POWERPC_KVM_PERF_H + +#include +#include + +#define DECODE_STR_LEN 20 + +#define VCPU_ID "vcpu_id" + +#define KVM_ENTRY_TRACE "kvm_hv:kvm_guest_enter" +#define KVM_EXIT_TRACE "kvm_hv:kvm_guest_exit" +#define KVM_EXIT_REASON "trap" + +#endif /* _ASM_POWERPC_KVM_PERF_H */ 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 0af6e9b..dd47b5e 100644 --- a/tools/perf/arch/powerpc/util/Build +++ b/tools/perf/arch/powerpc/util/Build @@ -1,4 +1,5 @@ libperf-y += header.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..62cdcc1 --- /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; +}