From patchwork Mon Sep 14 09:17:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11773379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E020618 for ; Mon, 14 Sep 2020 09:17:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37C2B206B2 for ; Mon, 14 Sep 2020 09:17:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OlGP+CTH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rBPjWRE4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37C2B206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=rk550xLFVkkarozR37vqYJe83y9bVxWzs/ZajA1r/5o=; b=OlGP+CTHFTLJwGF46tCx2UZ6++ cm4yAmjXKrCeq9WOLsaQgYSHW4EhFdycArHRQ+Hy+PXws89t+98wR5LKI08FMrG6WxRWehZRpD97P s5UBIkhYZbkHXz+1Ug7ACJG+h9zahtYZeMTFhs3QrEomFQIVuceN0NAsA5IRuu9X3xmH7bZ/iCVT8 DtZxzoxDezZEET1FJ/s9YbEWV7UOwo96iFwebvVxA8StO/RKtARM96qTWsK7DkR5Yjj0HcjL7vzxl y3NiMZYRq/dDQHPk6CV+MmF3whazTzKc4xQduTMbedZWaOzp/ihjkiTkdzONd0TTDqJwlEyzJXp/n 5WL0Q+RA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHkc3-0003OG-Jh; Mon, 14 Sep 2020 09:17:27 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHkc0-0003NP-Q2 for linux-arm-kernel@lists.infradead.org; Mon, 14 Sep 2020 09:17:25 +0000 Received: by mail-pf1-x443.google.com with SMTP id b124so12065487pfg.13 for ; Mon, 14 Sep 2020 02:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=utf50Tjw+FCxxoCkV3mSWLhpE/pmE7sABWHJHEffG9E=; b=rBPjWRE4T5WVAF5H1I8FREaCJKQ1XUHsFzAm3F4NhBpNMshmPbnpctW4gyN/HWtX7c GBZBPIl4MT8JLlZoYFCl3F/NjGoWpq2gpC3S1CX6ss1zocxpZ1+Qp54I6Cyqp2WFeQIy GumBvNzR3uTcVsILG3JrK3wkWayq/AiGPiqHNnu2svmV7bcOhkWdaYqO8HitFNqCD09q B4BhTCNflzY3/2/Wxb6iuHvxwB2Tn3FkvKBh8RRdjxXwPu6ZMQgnfCxzvlvU8/wIV0K3 dmXkzfOe172KzIlf24SQtIertRGJQLqW7v0/rCZjwUgP2+pikkpDETf4qjFztQXc7ZML 3U4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=utf50Tjw+FCxxoCkV3mSWLhpE/pmE7sABWHJHEffG9E=; b=Anxejmqy1UVB8PF48yLNsluA18InCWwygGheKSbvZGnqQJDu/rS9o1H8Ne2VdHwBOO MHRY1X+fMAkOm6ooS5AyruuEivoSUIBXkWiyHNG/GkzTu4f2VbGxGPTuADlvOnqDn6Tx U6cKiFh2JkywvhR16mc3Rv1QWdO9dzAfuxrsEsxQhpPRkhTbdAXm+Qi0ayuC1Dx8ZQ2x cz7m+tmDUowZ2m48B46nIlVoxDoe3Cx/P9e0oycXghAttip0fsCFoGpFdo3znrmNWlk3 1PrxzsVSwyqyqDbA/sCHbxYc6A6hfNq6CcnSF1/SZ1v6WYmQ6OPLHwmljn6Z36sCvvVb QIZw== X-Gm-Message-State: AOAM530UqGjxPgy0G44spOEp34Dycou0W1w5Y/xEUOmMI1C/4w9C/AWP TRjyQbo/7l9BCNt6j5zjzZ0= X-Google-Smtp-Source: ABdhPJwibBaZ+T6FmkrldSjrpF/Vh+ImFboJDvXjdAduwV5JXUt1Cu1JFKX6iWekmrZIxEF4Gs6/FQ== X-Received: by 2002:a63:5656:: with SMTP id g22mr9831920pgm.44.1600075040800; Mon, 14 Sep 2020 02:17:20 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id p11sm8677096pjz.44.2020.09.14.02.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 02:17:19 -0700 (PDT) From: Sergey Senozhatsky To: Peter Zijlstra Subject: [PATCH] perf kvm: add kvm-stat for arm64 Date: Mon, 14 Sep 2020 18:17:13 +0900 Message-Id: <20200914091713.1485250-1-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200914_051724_854611_6A72C3CC X-CRM114-Status: GOOD ( 19.45 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [sergey.senozhatsky[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mathieu Poirier , John Garry , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Namhyung Kim , Suleiman Souhlal , Will Deacon , Leo Yan , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add initial support for perf kvm stat on arm64 platform. Example: # perf kvm stat report Analyze events for all VMs, all VCPUs: VM-EXIT Samples Samples% Time% Min Time Max Time Avg time IRQ 44110 79.55% 0.51% 0.93us 8364.85us 10.16us ( +- 8.66% ) TRAP 11337 20.45% 99.49% 1.31us 3999985.95us 7761.21us ( +- 13.23% ) Total Samples:55447, Total events handled time:88437041.52us. Signed-off-by: Sergey Senozhatsky --- tools/perf/arch/arm64/Makefile | 1 + tools/perf/arch/arm64/util/Build | 1 + .../arch/arm64/util/arm64_exception_types.h | 22 +++++++++ tools/perf/arch/arm64/util/kvm-stat.c | 46 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 tools/perf/arch/arm64/util/arm64_exception_types.h create mode 100644 tools/perf/arch/arm64/util/kvm-stat.c diff --git a/tools/perf/arch/arm64/Makefile b/tools/perf/arch/arm64/Makefile index dbef716a1913..fab3095fb5d0 100644 --- a/tools/perf/arch/arm64/Makefile +++ b/tools/perf/arch/arm64/Makefile @@ -4,6 +4,7 @@ PERF_HAVE_DWARF_REGS := 1 endif PERF_HAVE_JITDUMP := 1 PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1 +HAVE_KVM_STAT_SUPPORT := 1 # # Syscall table generation for perf diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build index 5c13438c7bd4..4cba12f4b741 100644 --- a/tools/perf/arch/arm64/util/Build +++ b/tools/perf/arch/arm64/util/Build @@ -1,6 +1,7 @@ perf-y += header.o perf-y += machine.o perf-y += perf_regs.o +perf-y += kvm-stat.o perf-$(CONFIG_DWARF) += dwarf-regs.o perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o diff --git a/tools/perf/arch/arm64/util/arm64_exception_types.h b/tools/perf/arch/arm64/util/arm64_exception_types.h new file mode 100644 index 000000000000..224774ac34c2 --- /dev/null +++ b/tools/perf/arch/arm64/util/arm64_exception_types.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARCH_PERF_ARM64_EXCEPTION_TYPES_H +#define ARCH_PERF_ARM64_EXCEPTION_TYPES_H + +/* Per asm/virt.h */ +#define HVC_STUB_ERR 0xbadca11 + +/* Per asm/kvm_asm.h */ +#define ARM_EXCEPTION_IRQ 0 +#define ARM_EXCEPTION_EL1_SERROR 1 +#define ARM_EXCEPTION_TRAP 2 +#define ARM_EXCEPTION_IL 3 +/* The hyp-stub will return this for any kvm_call_hyp() call */ +#define ARM_EXCEPTION_HYP_GONE HVC_STUB_ERR + +#define kvm_arm_exception_type \ + {ARM_EXCEPTION_IRQ, "IRQ" }, \ + {ARM_EXCEPTION_EL1_SERROR, "SERROR" }, \ + {ARM_EXCEPTION_TRAP, "TRAP" }, \ + {ARM_EXCEPTION_HYP_GONE, "HYP_GONE" } + +#endif /* ARCH_PERF_ARM64_EXCEPTION_TYPES_H */ diff --git a/tools/perf/arch/arm64/util/kvm-stat.c b/tools/perf/arch/arm64/util/kvm-stat.c new file mode 100644 index 000000000000..3c642057a0fe --- /dev/null +++ b/tools/perf/arch/arm64/util/kvm-stat.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include "../../util/evsel.h" +#include "../../util/kvm-stat.h" +#include "arm64_exception_types.h" +#include "debug.h" + +define_exit_reasons_table(arm64_exit_reasons, kvm_arm_exception_type); + +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 *vcpu_id_str = "id"; +const int decode_str_len = 20; +const char *kvm_exit_reason = "ret"; +const char *kvm_entry_trace = "kvm:kvm_entry"; +const char *kvm_exit_trace = "kvm:kvm_exit"; + +const char *kvm_events_tp[] = { + "kvm:kvm_entry", + "kvm:kvm_exit", + NULL, +}; + +struct kvm_reg_events_ops kvm_reg_events_ops[] = { + { + .name = "vmexit", + .ops = &exit_events, + }, + { 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 = arm64_exit_reasons; + kvm->exit_reasons_isa = "arm64"; + return 0; +}