From patchwork Tue Nov 10 18:33:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 11895043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4F65C388F7 for ; Tue, 10 Nov 2020 18:33:55 +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 7CE27207D3 for ; Tue, 10 Nov 2020 18:33:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YREGluiV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CE27207D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.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=Xxx3R75foXfxKb0l1VU2PMjxzJbVXa13epHcyDP3gfY=; b=YREGluiVKC+O1lAxA/6/ynQYJT ToPs9m/EAaacFYf6NkP6yM3PuwLlD944z5n26wbf7skeQD9k9qLsJJGvl9s42vIBGWNZHf8qsXQP2 ohyRiTynTbSMF27vG3hDsfhjzruSJ1twVjNAOjAuRN/MY+3mq9N+JCF+DMgf2TCBYKFjZb6JSQ9D/ 0J8xM4zO0EKESW7deHtgxZ+m+DCajaN9ZYENF8uPHCCv2uC+MNTtGEsOP+lcHFyW8FmoW9P9/2N6I gk25jwi3U8WTkR2eXgsK1FkZe5r5qEg9WZUZiTOMmHx8djgJdv0iu2TCASjoazjZuBsRN0bAUghjZ Rvr2/6eQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcYSQ-00034B-6t; Tue, 10 Nov 2020 18:33:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcYSM-00033D-QD for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 18:33:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 93E881063; Tue, 10 Nov 2020 10:33:24 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 76CD63F7BB; Tue, 10 Nov 2020 10:33:23 -0800 (PST) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 0/3] coresight: etm-perf: Fix pid tracing with VHE Date: Tue, 10 Nov 2020 18:33:10 +0000 Message-Id: <20201110183313.1823760-1-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_133327_298597_9D6DE3F9 X-CRM114-Status: GOOD ( 16.61 ) 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: al.grant@arm.com, mathieu.poirier@linaro.org, anshuman.khandual@arm.com, coresight@lists.linaro.org, Suzuki K Poulose , leo.yan@linaro.org, mike.leach@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With the Virtualization Host Extensions, the kernel can run at EL2. In this case the pid is written to CONTEXTIDR_EL2 instead of the CONTEXTIDR_EL1. Thus the normal coresight tracing will be unable to detect the PID of the thread generating the trace by looking at the CONTEXTIDR_EL1. Thus, depending on the kernel EL, we must switch to tracing the correct CONTEXTIDR register. With VHE, we must set the TRCCONFIGR.VMID and TRCCONFIGR.VMID_OPT to include the CONTEXTIDR_EL2 as the VMID in the trace. This requires the perf tool to detect the changes in the TRCCONFIGR and use the VMID / CID field for the PID. The challenge here is for the perf tool to detect the kernel behavior. Instead of the previously proposed invasive approaches, this set implements a less intrusive mechanism, by playing with the perf_event.attribute.config bits. Some facts: - The perf tool requests pid tracing and timestamp in some scenarios. (e.g, system wide, task bound (!per-thread). - The default pid tracing is via requesting "contextid" But this only works for EL1 kernel. - "contextid" tracing is useful for tracing VMs (when we get to virtualization support). So we don't want to move this around. So this patch series introduces two new format bits: - contextid_in_vmid -> Is only supported when the VMID tracing and CONTEXTIDR_EL2 both are supported. When requested the perf etm4x backend sets (TRCCONFIGR.VMID | TRCCONFIGR.VMID_OPT). As per ETMv4.4 TRM, when the core supports VHE, the CONTEXTIDR_EL2 tracing is mandatory. (See the field TRCID2.VMIDOPT) - pid -> Is an alias for the correct config to enable PID tracing on any kernel. i.e, in EL1 kernel -> pid == contextid EL2 kernel -> pid == contextid_in_vmid With this, the perf tool is also updated to request the "pid" tracing whenever available, falling back to "contextid" if it is unavailable (to support new tool running on older kernels). The perf tool will also set the TRCCONFIGR accordingly based on the config bits, allowing the decoder to output the appropriate fields. I have another patch for the perf decoder to set the TID from VMID when the cid is invalid and and the vmid is valid. But this doesn't verify if the trcconfigr.vmid_opt was set. I will leave this to Mike Leach to fix it properly. Tested on Juno (EL1 kernel) and N1SDP (El2 kernel). Feedback welcome. A tree with these patches are available here : git.gitlab.arm.com:linux-arm/linux-skp.git coresight/el2/pid Suzuki K Poulose (3): coresight: etm-perf: Add support for PID tracing for kernel at EL2 perf: cs_etm: Use pid tracing explicitly instead of contextid rfc: perf: cs_etm: Detect pid in VMID for kernel running at EL2 .../hwtracing/coresight/coresight-etm-perf.c | 14 ++++ .../coresight/coresight-etm4x-core.c | 9 +++ include/linux/coresight-pmu.h | 11 ++-- tools/include/linux/coresight-pmu.h | 11 ++-- tools/perf/arch/arm/util/cs-etm.c | 65 ++++++++++++++----- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 ++++---- 6 files changed, 101 insertions(+), 37 deletions(-)