From patchwork Sat Jan 9 07:44:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007967 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 CCB74C433E0 for ; Sat, 9 Jan 2021 07:46:56 +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 8A24023A5B for ; Sat, 9 Jan 2021 07:46:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A24023A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=DbC17SMuBV4XqwTz8p6DLBAhT3ewYeVcAukQOXS/iZY=; b=1hjZuIqgdFf/MGDF7P9y6IVux n8Wt4oUBQd3D3ynPHxzqKkTElXkOh5WBNfzgKVA9I0wE4yj1WH+rw/UI3WaK2wXdF8hbBbSyfmlVU JUFV6cN21ubRyDultAnZr4Bvf3bLrrYpKWqo3do3LYo58GF3xgevq8lPatswj4lxd+vHrpx5h+gFW keduVU/883WypoIddzcoseJ7dA8BgFAnjCleQPanc7NGuY4rrP+EzZ3mWnMVdzY91e9F8jc2Y9H0p AdX7eBujmY4ZNexdnhA124WtuNRLh8fxOQm2aBXe8VUJAd+MuNT+wWpwqrTsy9oB0AwsMl3uV/HgS MFM9tnIag==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vq-0008Vq-5j; Sat, 09 Jan 2021 07:45:06 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vk-0008T9-JQ for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:01 +0000 Received: by mail-pf1-x434.google.com with SMTP id a188so7714822pfa.11 for ; Fri, 08 Jan 2021 23:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7zZpchzzFQSS1Vz9GJY3gB220lxq3Yt0vtCHbysiOHQ=; b=jIo67qTe9UoiSzFzGjMmxFWfWYZeDYurdIhM7bgcMvL7AsNyEB8C80jmQ72a6Cr7vK VTqG2b/YQYIQIYAJGcFQ8TquHRtFCw3KZxhs8rWNe5Cr6XxJmhzXjZJKxXnShm9s7LLV sE4ZOY44TiNjwWG2pXRhTG/sUrzs+cyqd9f9GdcjYKSYTp6sDPTZhYWy2vRFSxUkjYBO 1ypqeXT45/mkl92o2POYETee4AIp2VLZOEOsfoDFyD2ME7FKippIsHYHPzOFbGHR/Ukw 2Arjb7FS06fGzDUHiwgY4CK95LEPxJg7yEjQYJMyyOn0imzZqE2j+zLW8cLRfgZA1p2+ /+Aw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=7zZpchzzFQSS1Vz9GJY3gB220lxq3Yt0vtCHbysiOHQ=; b=OT3pXZKWqLimfslEpE2Mts4F8hHALJqI2GFzZEdgdYSGa0BuLSQR3eooIo3cL4wt1y DwmTb8mc9DA0jwu2Jjj4fjtCLOL2SdVyqEgTw5512PbVivNctOaEc1adkIaU5QDxpm9e X1NkxXfDzgcXzWlcyR7HLhhBX8nE9SqujOj3bosrX2hwDmAnMJwRJhjemQIUQiH1RFO4 vbwg6fHDvbwxmAXetw6Yl6HVGj2dyyjclJoY+XDqn1iPm//CN/XuyzuGvCxhu6wfRUGF p6dZqRsjNZd0y9pVPILXSZzaJ3oBUGK15v4yh1Cl/j6g671YSuaEsBShdZGzZVo2orDO uVvg== X-Gm-Message-State: AOAM531sAt+rgL2ZAZuM3Wqn055CVb3NvqyPN+voUOSSTWc79vAmimyi 10Sy+He+/eRPzyig9Pi2pga+9Q== X-Google-Smtp-Source: ABdhPJye7bbjVsAsKI7rUhlG/B48m4Qh7XWyo2LWTCvgEt9a7/rFmB+5v3pVnD4NQ4KmJxzyZDJgOA== X-Received: by 2002:a63:f010:: with SMTP id k16mr10775149pgh.28.1610178296722; Fri, 08 Jan 2021 23:44:56 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id e29sm11530149pfj.174.2021.01.08.23.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:44:56 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/7] coresight: etm-perf: Add support for PID tracing for kernel at EL2 Date: Sat, 9 Jan 2021 15:44:29 +0800 Message-Id: <20210109074435.626855-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024500_683723_25060988 X-CRM114-Status: GOOD ( 20.34 ) 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 , Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Suzuki K Poulose When the kernel is running at EL2, the PID is stored in CONTEXTIDR_EL2. So, tracing CONTEXTIDR_EL1 doesn't give us the pid of the process. Thus we should trace the VMID with VMIDOPT set to trace CONTEXTIDR_EL2 instead of CONTEXTIDR_EL1. Given that we have an existing config option "contextid" and this will be useful for tracing virtual machines (when we get to support virtualization). So instead, this patch adds a new option, contextid_in_vmid as a separate config. Thus on an EL2 kernel, we will have two options available for the perf tool. However, to make it easier for the user to do pid tracing, we add a new format which will default to "contextid" (on EL1 kernel) or "contextid_in_vmid" (on EL2 kernel). So that the user doesn't have to bother which EL the kernel is running. i.e, perf record -e cs_etm/pid/u -- will always do the "pid" tracing, independent of the kernel EL. Also, the perf tool will be updated to automatically select "pid" config instead of the "contextid" for system wide/CPU wide mode. Cc: Mathieu Poirier Cc: Al Grant Cc: Mike Leach Signed-off-by: Suzuki K Poulose Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-etm-perf.c | 14 ++++++++++++++ drivers/hwtracing/coresight/coresight-etm4x-core.c | 9 +++++++++ include/linux/coresight-pmu.h | 11 +++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index bdc34ca449f7..f763def145e4 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -30,14 +30,28 @@ static DEFINE_PER_CPU(struct coresight_device *, csdev_src); /* ETMv3.5/PTM's ETMCR is 'config' */ PMU_FORMAT_ATTR(cycacc, "config:" __stringify(ETM_OPT_CYCACC)); PMU_FORMAT_ATTR(contextid, "config:" __stringify(ETM_OPT_CTXTID)); +PMU_FORMAT_ATTR(contextid_in_vmid, "config:" __stringify(ETM_OPT_CTXTID_IN_VMID)); PMU_FORMAT_ATTR(timestamp, "config:" __stringify(ETM_OPT_TS)); PMU_FORMAT_ATTR(retstack, "config:" __stringify(ETM_OPT_RETSTK)); /* Sink ID - same for all ETMs */ PMU_FORMAT_ATTR(sinkid, "config2:0-31"); +static ssize_t format_attr_pid_show(struct device *dev, + struct device_attribute *attr, + char *page) +{ + int pid_fmt = is_kernel_in_hyp_mode() ? ETM_OPT_CTXTID_IN_VMID : ETM_OPT_CTXTID; + + return sprintf(page, "config:%d\n", pid_fmt); +} + +struct device_attribute format_attr_pid = __ATTR(pid, 0444, format_attr_pid_show, NULL); + static struct attribute *etm_config_formats_attr[] = { &format_attr_cycacc.attr, &format_attr_contextid.attr, + &format_attr_contextid_in_vmid.attr, + &format_attr_pid.attr, &format_attr_timestamp.attr, &format_attr_retstack.attr, &format_attr_sinkid.attr, diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index b20b6ff17cf6..8b7c7a8b2874 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -477,6 +477,15 @@ static int etm4_parse_event_config(struct etmv4_drvdata *drvdata, /* bit[6], Context ID tracing bit */ config->cfg |= BIT(ETM4_CFG_BIT_CTXTID); + /* Do not enable VMID tracing if we are not running in EL2 */ + if (attr->config & BIT(ETM_OPT_CTXTID_IN_VMID)) { + if (!is_kernel_in_hyp_mode()) { + ret = -EINVAL; + goto out; + } + config->cfg |= BIT(ETM4_CFG_BIT_VMID) | BIT(ETM4_CFG_BIT_VMID_OPT); + } + /* return stack - enable if selected and supported */ if ((attr->config & BIT(ETM_OPT_RETSTK)) && drvdata->retstack) /* bit[12], Return stack enable bit */ diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index b0e35eec6499..927c6285ce5d 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -11,16 +11,19 @@ #define CORESIGHT_ETM_PMU_SEED 0x10 /* ETMv3.5/PTM's ETMCR config bit */ -#define ETM_OPT_CYCACC 12 -#define ETM_OPT_CTXTID 14 -#define ETM_OPT_TS 28 -#define ETM_OPT_RETSTK 29 +#define ETM_OPT_CYCACC 12 +#define ETM_OPT_CTXTID 14 +#define ETM_OPT_CTXTID_IN_VMID 15 +#define ETM_OPT_TS 28 +#define ETM_OPT_RETSTK 29 /* ETMv4 CONFIGR programming bits for the ETM OPTs */ #define ETM4_CFG_BIT_CYCACC 4 #define ETM4_CFG_BIT_CTXTID 6 +#define ETM4_CFG_BIT_VMID 7 #define ETM4_CFG_BIT_TS 11 #define ETM4_CFG_BIT_RETSTK 12 +#define ETM4_CFG_BIT_VMID_OPT 15 static inline int coresight_get_trace_id(int cpu) { From patchwork Sat Jan 9 07:44:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007965 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 D0251C433DB for ; Sat, 9 Jan 2021 07:46:53 +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 60AD023A5B for ; Sat, 9 Jan 2021 07:46:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60AD023A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=fcgCqzopleqyiXTViLaCC2TDqYqU9E+A77CskDUz2SU=; b=hbTFF4FEfYiNgsyyrN5gDSS+t 7S8OUEb8UFJxhGGnhk+O18XwUU4JZAyExETLQ7B4DhFvTdc1AJrn1X2IkKtCW6B0iZnEjd+egl7Va 3FaLZVWvXgTuS396kbPKxqtCy2Mg6lygBysymMOAm02e5GhAvtAsIwpQ1dfbOAfqbfkGsbjv+kIsi rPGhuOpwkJYuixelBjlJJccWwtLAvTfawf2wmh9aAOHoWqFqdAmMf3O/DyAwLialBM3GDbdRw9E4x vAcsGd8QIQnnURYTi11FtHN6yTkBaXPwwip6IywGN1tIvKGQdZQg6h8wHjkxKw4wDgc0zw36bXcK3 Nta+TLsjA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vt-0008WO-Fj; Sat, 09 Jan 2021 07:45:09 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vl-0008Tl-Ob for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:04 +0000 Received: by mail-pf1-x434.google.com with SMTP id h10so7725433pfo.9 for ; Fri, 08 Jan 2021 23:45:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nQMCubmgzlrRTa03+kmNvTwcrwNhs1nXf3jbRihBgmo=; b=JPQAm8mKkZrg0ceXulqBGIaytFxCQsnVgLuM6fuf2yKXNydlAgB1ORNGeDTtV6oIno 9Hi/KbJ4PBf332SxeI624u1oirZIHqJmRSVgyaHl+BBXrdJ31L6cPGfjCBdpaoawGbB6 y9uSL/y9E4WyBKE1iXJKoXvYaLPuR8EfS4IDpU0DwBLIMtr8HzSlHxKv6E26BF+IhNEG NBhY4THkePFvw7ceywId+66QiJy36rnaXz3Zjm7YBm8BIbKM59HxqGuM25qBJ31viZYP ZQFtREygT/82YmF7d5dNOexb6baO+YyMaofc6iARj3qm5ox8ICWyizMYQN7b8803TxgQ dQQw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=nQMCubmgzlrRTa03+kmNvTwcrwNhs1nXf3jbRihBgmo=; b=lyN6q/fq0oCx3+rvFCu9e9ZrPV5zAmPnPtKbScj1E3N4v3PFID0vbXVhQKsuSMqMKu TftvW2rKeZ++5TMNknZMIPFZy9lnMRpJ6+bLGmL0wdkL3Q5tJ1vrj0u/DDqLJW683lD/ Vhj81IZ81+bUcaS0e4DFD1rFNBLmu4awT+n/X7gsNv2JJN7ZgXJ2hV0qTX8m3PqMxyYP hLByalSGNN2hUMaM6hU1f2XcWfgQGnpi+dp1V1n8SAUqtmmPFcMHduwEl8JZZqhyvonn w8lLonFNQlJRMpUXcuJOLGRgiMxH0gp9adIao8pJNQZPgFLB8TR3AzRyIp4WX7jNnrcO Px3A== X-Gm-Message-State: AOAM532e6ppYzatvhIunthXaQt2Fbenb2Q9axNE9M9BUoK4VAFziYQcw HN40mZAMxXrmtbVbBNFrLS+T0Q== X-Google-Smtp-Source: ABdhPJw7tGBumAzkMbsznaxaXFQcycez6QVQ8esQCZu5MaJ/vujTzQ+/xlrWfTsfrdeSDOgpzQi07Q== X-Received: by 2002:a65:690e:: with SMTP id s14mr10637219pgq.302.1610178300076; Fri, 08 Jan 2021 23:45:00 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id f64sm11488855pfb.146.2021.01.08.23.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:44:59 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/7] perf cs_etm: Use pid tracing explicitly instead of contextid Date: Sat, 9 Jan 2021 15:44:30 +0800 Message-Id: <20210109074435.626855-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024501_948899_31A4D144 X-CRM114-Status: GOOD ( 23.65 ) 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 , Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Suzuki K Poulose If the kernel is running at EL2, the pid of the task is exposed via VMID instead of the CONTEXTID. Add support for this in the perf tool. By default the perf tool requests contextid and timestamp for task bound events. Instead of hard coding contextid, switch to "pid" config exposed by the kernel. While at it, define new independent macros (rather than using the "config" bits) for requesting the "pid" and "timestamp" for cs_etm_set_option(), since the PID config is now dynamic depending on the kernel exception level. Cc: Mike Leach Cc: Mathieu Poirier Cc: Al Grant Signed-off-by: Suzuki K Poulose Signed-off-by: Leo Yan --- tools/include/linux/coresight-pmu.h | 11 +++-- tools/perf/arch/arm/util/cs-etm.c | 68 ++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h index b0e35eec6499..927c6285ce5d 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -11,16 +11,19 @@ #define CORESIGHT_ETM_PMU_SEED 0x10 /* ETMv3.5/PTM's ETMCR config bit */ -#define ETM_OPT_CYCACC 12 -#define ETM_OPT_CTXTID 14 -#define ETM_OPT_TS 28 -#define ETM_OPT_RETSTK 29 +#define ETM_OPT_CYCACC 12 +#define ETM_OPT_CTXTID 14 +#define ETM_OPT_CTXTID_IN_VMID 15 +#define ETM_OPT_TS 28 +#define ETM_OPT_RETSTK 29 /* ETMv4 CONFIGR programming bits for the ETM OPTs */ #define ETM4_CFG_BIT_CYCACC 4 #define ETM4_CFG_BIT_CTXTID 6 +#define ETM4_CFG_BIT_VMID 7 #define ETM4_CFG_BIT_TS 11 #define ETM4_CFG_BIT_RETSTK 12 +#define ETM4_CFG_BIT_VMID_OPT 15 static inline int coresight_get_trace_id(int cpu) { diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index cad7bf783413..fad7b6e13ccc 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -59,14 +59,15 @@ static const char *metadata_etmv4_ro[CS_ETMV4_PRIV_MAX] = { static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu); -static int cs_etm_set_context_id(struct auxtrace_record *itr, - struct evsel *evsel, int cpu) +static int cs_etm_set_pid(struct auxtrace_record *itr, + struct evsel *evsel, int cpu) { struct cs_etm_recording *ptr; struct perf_pmu *cs_etm_pmu; char path[PATH_MAX]; int err = -EINVAL; u32 val; + u64 pid_fmt; ptr = container_of(itr, struct cs_etm_recording, itr); cs_etm_pmu = ptr->cs_etm_pmu; @@ -86,21 +87,50 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, goto out; } + pid_fmt = perf_pmu__format_bits(&cs_etm_pmu->format, "pid"); /* - * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID tracing - * is supported: - * 0b00000 Context ID tracing is not supported. - * 0b00100 Maximum of 32-bit Context ID size. - * All other values are reserved. + * If the kernel doesn't support the "pid" format (older kernel), + * fall back to using the CTXTID. */ - val = BMVAL(val, 5, 9); - if (!val || val != 0x4) { + if (!pid_fmt) + pid_fmt = 1ULL << ETM_OPT_CTXTID; + + switch (pid_fmt) { + case (1ULL << ETM_OPT_CTXTID): + /* + * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID + * tracing is supported: + * 0b00000 Context ID tracing is not supported. + * 0b00100 Maximum of 32-bit Context ID size. + * All other values are reserved. + */ + val = BMVAL(val, 5, 9); + if (!val || val != 0x4) { + err = -EINVAL; + goto out; + } + break; + case (1ULL << ETM_OPT_CTXTID_IN_VMID): + /* + * TRCIDR2.VMIDOPT[30:29] != 0 and + * TRCIDR2.VMIDSIZE[14:10] == 0b00100 (32bit virtual contextid) + * We can't support CONTEXTIDR in VMID if the size of the + * virtual context id is < 32bit. + * Any value of VMIDSIZE >= 4 (i.e, > 32bit) is fine for us. + */ + if (!BMVAL(val, 29, 30) || BMVAL(val, 10, 14) < 4) { + err = -EINVAL; + goto out; + } + break; + default: err = -EINVAL; goto out; } + /* All good, let the kernel know */ - evsel->core.attr.config |= (1 << ETM_OPT_CTXTID); + evsel->core.attr.config |= pid_fmt; err = 0; out: @@ -156,6 +186,10 @@ static int cs_etm_set_timestamp(struct auxtrace_record *itr, return err; } +#define ETM_SET_OPT_PID (1 << 0) +#define ETM_SET_OPT_TS (1 << 1) +#define ETM_SET_OPT_MASK (ETM_SET_OPT_PID | ETM_SET_OPT_TS) + static int cs_etm_set_option(struct auxtrace_record *itr, struct evsel *evsel, u32 option) { @@ -169,17 +203,17 @@ static int cs_etm_set_option(struct auxtrace_record *itr, !cpu_map__has(online_cpus, i)) continue; - if (option & ETM_OPT_CTXTID) { - err = cs_etm_set_context_id(itr, evsel, i); + if (option & ETM_SET_OPT_PID) { + err = cs_etm_set_pid(itr, evsel, i); if (err) goto out; } - if (option & ETM_OPT_TS) { + if (option & ETM_SET_OPT_TS) { err = cs_etm_set_timestamp(itr, evsel, i); if (err) goto out; } - if (option & ~(ETM_OPT_CTXTID | ETM_OPT_TS)) + if (option & ~(ETM_SET_OPT_MASK)) /* Nothing else is currently supported */ goto out; } @@ -406,7 +440,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evsel__set_sample_bit(cs_etm_evsel, CPU); err = cs_etm_set_option(itr, cs_etm_evsel, - ETM_OPT_CTXTID | ETM_OPT_TS); + ETM_SET_OPT_PID | ETM_SET_OPT_TS); if (err) goto out; } @@ -485,7 +519,9 @@ static u64 cs_etmv4_get_config(struct auxtrace_record *itr) config |= BIT(ETM4_CFG_BIT_TS); if (config_opts & BIT(ETM_OPT_RETSTK)) config |= BIT(ETM4_CFG_BIT_RETSTK); - + if (config_opts & BIT(ETM_OPT_CTXTID_IN_VMID)) + config |= BIT(ETM4_CFG_BIT_VMID) | + BIT(ETM4_CFG_BIT_VMID_OPT); return config; } From patchwork Sat Jan 9 07:44:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007971 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 360BEC433E9 for ; Sat, 9 Jan 2021 07:47:02 +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 D6C3523A5B for ; Sat, 9 Jan 2021 07:47:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6C3523A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=PQZXiwQVk13gbhIMR8Jt7c2RPCdBwTeN4WuHj19ofuE=; b=ISZUazgqudBqBWFt38ytqhtOp A1hx9ViwvrFq8YrY1yBf/k26v7Mnmc4P15ptb041OhWR9qhDqhXtY+9g9TIIMDUj34+xuBOhT2qLM O6afuAER82w2sax9+LWu3c+eUi2rUQ2ZcY3IChMx1xh9MDzvUdRG6pnv8DltfapxlTOlSZ2v/otOx hc8JB97nkRVMiUzhaP/Tu2CYrpvJj55sGnNtdiGrj0n2E6ZOwEI3Iu9OrFW1mC0FIZAsrF0D67ZXu hs7aNNe0B4/wZxBRsdgFupPfFkXdvkBBaZWmmiBkd9+cDAaLZ4EfiqHGiSPhJFlCyUKaR9JbGRjQT j2vfVFBRA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vz-00006z-Tn; Sat, 09 Jan 2021 07:45:15 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vp-0008V2-E6 for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:08 +0000 Received: by mail-pl1-x62a.google.com with SMTP id v3so6874396plz.13 for ; Fri, 08 Jan 2021 23:45:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ur+i5mnXVMoiLpNfSuPbVvw5IIiW/Rm/SXsCiDAi43M=; b=DR0seVr8sXp6H3nk/nzWCyYbPkQz/Tq3x6qlgDrW+0tLUk6RgRd8089mjP2r+xAcuh 5Q0opjHzngmvlXI9NttaXeb28QUUY3UtDHRpyM1Oxfyvtje8fpGw2CBXlCnqcNYWY0jW hdj+zKqGJv655lAVyKqOmcBuvRDzxK173X+w3+OHo/8XkYoDC8Cxw0WdelDW2ErM6sym Fkf5wNSmCk5Hsfz9+TyVjx+YU6MPbmR7gXvpiKM6PcUu+lzTN8h8SCE5mH0jaxYmbcsu nadx/gLunFxRhE9qbPrlRhUJvXQMWBr6GjQiilQtaFSQnnI7QZMel69qRGIdbRKqsPCL wi6A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ur+i5mnXVMoiLpNfSuPbVvw5IIiW/Rm/SXsCiDAi43M=; b=RS0Fdgpq3Tpu8GdU8bApKsnPNxjN7ZF8PZkAJBqZsBtuFbBO6U+8Tqs46N6DAdrdOI vSiIJzFxZRWDpuY55LF+6zdanVLLQPzUG7RDTP42kVfBZWbLVptKGEdlTmSBZifz5GD3 iSbes8msoZrJBZjDOFf+j9Yrhl9bIxWA8eFr5WIfiNyzrOuvx8Tav4rIcm2z58/9L3yt HYQcGBcyxqBhRbhychZ0D9tNmI4ZYPo5evA2HoYAukF/krYTpXzcFVfEt8wgElzA2DJK UUk3EerXF5Bk5etyjjGvdhDTwH01b/gFkZyyDBjhtd67FQniwaAzwhnnmJHFhX6Qw5tm GNkA== X-Gm-Message-State: AOAM532ysM+1vBpl7/fBBA2h9M3y9WLHtnlxom8ndLH4Y+y9myv1tU9l YV0J3kvBXnUgeTPa7xNkenB+bw== X-Google-Smtp-Source: ABdhPJwMeGp+OT+EQHGNAS2ppjZBBcNAneyegbBDDUcJJFrAzQIDYJ4KXHZGH97MQZ+yfsIyw5wGgQ== X-Received: by 2002:a17:90a:31c3:: with SMTP id j3mr7483579pjf.25.1610178303366; Fri, 08 Jan 2021 23:45:03 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id t22sm12873711pgm.18.2021.01.08.23.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:45:02 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/7] perf cs-etm: Calculate per CPU metadata array size Date: Sat, 9 Jan 2021 15:44:31 +0800 Message-Id: <20210109074435.626855-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024505_534871_2C8D8B48 X-CRM114-Status: GOOD ( 17.64 ) 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: Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The metadata array can be extended over time and the tool, if using the predefined macro (like CS_ETMV4_PRIV_MAX for ETMv4) as metadata array size to copy data, it can cause compatible issue within different versions of perf tool. E.g. we recorded a data file with an old version tool, afterwards if use the new version perf tool to parse the file, since the metadata array has been extended and the macro CS_ETMV4_PRIV_MAX has been altered, if use it to parse the perf data with old format, this will lead to mismatch. To maintain backward compatibility, this patch calculates per CPU metadata array size on the runtime, the calculation is based on the info stored in the data file so that it's reliable. Signed-off-by: Leo Yan Acked-by: Suzuki K Poulose --- tools/perf/util/cs-etm.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a2a369e2fbb6..5e284725dceb 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2497,6 +2497,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, int i, j, k; u64 *ptr, *hdr = NULL; u64 **metadata = NULL; + int metadata_cpu_array_size; /* * sizeof(auxtrace_info_event::type) + @@ -2544,6 +2545,19 @@ int cs_etm__process_auxtrace_info(union perf_event *event, goto err_free_traceid_list; } + /* + * The metadata is a two dimensional array, the first dimension uses CPU + * number as index and the second dimension is the metadata array per + * CPU. Since the metadata array can be extended over time, the + * predefined macros (CS_ETM_PRIV_MAX or CS_ETMV4_PRIV_MAX) might + * mismatch within different versions of tool, this can lead to copy + * wrong data. To maintain backward compatibility, calculate CPU's + * metadata array size on the runtime. + */ + metadata_cpu_array_size = + (auxtrace_info->header.size - + sizeof(struct perf_record_auxtrace_info)) / num_cpu / sizeof(u64); + /* * The metadata is stored in the auxtrace_info section and encodes * the configuration of the ARM embedded trace macrocell which is @@ -2558,12 +2572,12 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = -ENOMEM; goto err_free_metadata; } - for (k = 0; k < CS_ETM_PRIV_MAX; k++) + for (k = 0; k < metadata_cpu_array_size; k++) metadata[j][k] = ptr[i + k]; /* The traceID is our handle */ idx = metadata[j][CS_ETM_ETMTRACEIDR]; - i += CS_ETM_PRIV_MAX; + i += metadata_cpu_array_size; } else if (ptr[i] == __perf_cs_etmv4_magic) { metadata[j] = zalloc(sizeof(*metadata[j]) * CS_ETMV4_PRIV_MAX); @@ -2571,12 +2585,12 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err = -ENOMEM; goto err_free_metadata; } - for (k = 0; k < CS_ETMV4_PRIV_MAX; k++) + for (k = 0; k < metadata_cpu_array_size; k++) metadata[j][k] = ptr[i + k]; /* The traceID is our handle */ idx = metadata[j][CS_ETMV4_TRCTRACEIDR]; - i += CS_ETMV4_PRIV_MAX; + i += metadata_cpu_array_size; } /* Get an RB node for this CPU */ From patchwork Sat Jan 9 07:44:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007973 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 E6ADAC43381 for ; Sat, 9 Jan 2021 07:47:02 +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 9E46B23A5B for ; Sat, 9 Jan 2021 07:47:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E46B23A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=PLvyOjOxa/ZhLspiQ+uSnzJpVrjMQaJ9kFWp9cQROzo=; b=NOSow24p4yzsBSV6ObkSe/lTO JtS3aI/EwPyTkbIqZWxfNgIjzVwvPzHTaMuX409h4MDDTmZfxDYYC+2iSYmGecnSH2rAbnF8AbHF0 hSFfjCoKSpIGXePcOfW2B+RRbpgcF29V5C+Ldi6msm4Vgz56UqKWoI/GxCBsJvUutQNbfkPvq7BvH IIQX+fxe/bN5LWQSUYnm4jQjj/m3Pey5PS0QJZXoSfrDXyVu9sObDAUqWTCVfifta9lP52FgRVaKA krVkcAneuMgkyBnsOn+kApqTXM9jot+bVZPW9yWFyjbNDD3t9RKKh4XIEpXbNw1s2Shc+FwZX2rhL PRNyAqhGw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8w5-00009T-Rx; Sat, 09 Jan 2021 07:45:21 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vs-0008WB-TF for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:11 +0000 Received: by mail-pf1-x431.google.com with SMTP id a188so7715002pfa.11 for ; Fri, 08 Jan 2021 23:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aBb9CTdjrCaMFSuv37sDBP44Tr8vgCGxsAMBQeMmvPk=; b=wUib81WgxJb23ACV58kgLXqy7B3iiG1FXO6+uepjDpylx5t7XtWXJaRyx1UWQ8tFFS JWFyGkXaymuJVJARpo1G2ArFT5JNrDgfTXm3YyCwNzffNXX/EDG2KOFeic4bx9a8lULU zV2YhLnDLqYIEaOcjlHJ10/azV1tul+3iWZIYDpU8k7JrOoNgR+QJI762BmMeNVKxaTd 7eoWGDwW1ws7O1gzaOQgAqvLepYiWyFaAd8olKZISQBszjDUKtpYYYS1cTIjc/QZMJ90 lGfz/5D0VihsvKUPtPzzjd3utUcgrVN+fM+M7uKitCBiCnbqpHH1YzKlk9UQycwJ29ZZ CW3A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=aBb9CTdjrCaMFSuv37sDBP44Tr8vgCGxsAMBQeMmvPk=; b=Wwvw/GVHMoBx2AsHlLTsATs6A4OSXl6zscNw0WAMa7w8v2KdRVleY6ZCntyJnUgbpf XN2kRKH+CL4/3+GHFMy/jp45jBVFLI2VoQa6BIuwgPOdsr8CYyaqwWQlwbHu86/vYUDc YESxHz8YH9jtcLszFAYfatBKYGv8mjm3+yOxq4PjJEuunFKcVTMlF97ViDfPZ3yKq0kI dieH8D5hz+7WCmddcmTKXC05sfDNz7PwDfzi9faatwxdDCtsUobbTSTKWQCzwW9oSLps n3ReZoiv4kSejl7Sc20svt9cD8D1uvF0T9Zyvt4goNVOMFkgJp6c3pPUOoMpIt32dcyh L/3g== X-Gm-Message-State: AOAM531QlL9KXdm1wuyO7OofRrHBwxAridMmfzxbW2lnrwY7yI3lP2CK 41X8wVJsjOVS7xJ2sMex5PILKg== X-Google-Smtp-Source: ABdhPJzwdpapP0aNr8+muZOEh1vXlCI2en4/FOpH/5RUlCRozju4tXOh05m2lyzRedQacz4+gVR4YA== X-Received: by 2002:a63:5942:: with SMTP id j2mr10550010pgm.33.1610178306716; Fri, 08 Jan 2021 23:45:06 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id 73sm11721257pga.26.2021.01.08.23.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:45:06 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/7] perf cs-etm: Add PID format into metadata Date: Sat, 9 Jan 2021 15:44:32 +0800 Message-Id: <20210109074435.626855-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024509_037995_3F316FD2 X-CRM114-Status: GOOD ( 16.18 ) 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: Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It's possible for CoreSight to trace PID in either CONTEXTIDR_EL1 or CONTEXTIDR_EL2, the PID format info is used to distinguish the PID is traced in which register. This patch saves PID format into the metadata when record. Signed-off-by: Leo Yan --- tools/perf/arch/arm/util/cs-etm.c | 21 +++++++++++++++++++++ tools/perf/util/cs-etm.c | 2 ++ tools/perf/util/cs-etm.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index fad7b6e13ccc..ee78df3b1b07 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -613,6 +613,7 @@ static void cs_etm_get_metadata(int cpu, u32 *offset, struct cs_etm_recording *ptr = container_of(itr, struct cs_etm_recording, itr); struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; + u64 pid_fmt; /* first see what kind of tracer this cpu is affined to */ if (cs_etm_is_etmv4(itr, cpu)) { @@ -641,6 +642,16 @@ static void cs_etm_get_metadata(int cpu, u32 *offset, metadata_etmv4_ro [CS_ETMV4_TRCAUTHSTATUS]); + /* + * The PID format will be used when decode the trace data; + * based on it the decoder will make decision for setting + * sample's PID as context_id or VMID. + */ + pid_fmt = perf_pmu__format_bits(&cs_etm_pmu->format, "pid"); + if (!pid_fmt) + pid_fmt = 1ULL << ETM_OPT_CTXTID; + info->priv[*offset + CS_ETMV4_PID_FMT] = pid_fmt; + /* How much space was used */ increment = CS_ETMV4_PRIV_MAX; } else { @@ -658,6 +669,16 @@ static void cs_etm_get_metadata(int cpu, u32 *offset, cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMIDR]); + /* + * The PID format will be used when decode the trace data; + * based on it the decoder will make decision for setting + * sample's PID as context_id or VMID. + */ + pid_fmt = perf_pmu__format_bits(&cs_etm_pmu->format, "pid"); + if (!pid_fmt) + pid_fmt = 1ULL << ETM_OPT_CTXTID; + info->priv[*offset + CS_ETM_PID_FMT] = pid_fmt; + /* How much space was used */ increment = CS_ETM_PRIV_MAX; } diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 5e284725dceb..763085db29ae 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2447,6 +2447,7 @@ static const char * const cs_etm_priv_fmts[] = { [CS_ETM_ETMTRACEIDR] = " ETMTRACEIDR %llx\n", [CS_ETM_ETMCCER] = " ETMCCER %llx\n", [CS_ETM_ETMIDR] = " ETMIDR %llx\n", + [CS_ETM_PID_FMT] = " PID Format %llx\n", }; static const char * const cs_etmv4_priv_fmts[] = { @@ -2459,6 +2460,7 @@ static const char * const cs_etmv4_priv_fmts[] = { [CS_ETMV4_TRCIDR2] = " TRCIDR2 %llx\n", [CS_ETMV4_TRCIDR8] = " TRCIDR8 %llx\n", [CS_ETMV4_TRCAUTHSTATUS] = " TRCAUTHSTATUS %llx\n", + [CS_ETMV4_PID_FMT] = " PID Format %llx\n", }; static void cs_etm__print_auxtrace_info(__u64 *val, int num) diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 4ad925d6d799..8cbbea6100a1 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -38,6 +38,7 @@ enum { /* RO, taken from sysFS */ CS_ETM_ETMCCER, CS_ETM_ETMIDR, + CS_ETM_PID_FMT, CS_ETM_PRIV_MAX, }; @@ -52,6 +53,7 @@ enum { CS_ETMV4_TRCIDR2, CS_ETMV4_TRCIDR8, CS_ETMV4_TRCAUTHSTATUS, + CS_ETMV4_PID_FMT, CS_ETMV4_PRIV_MAX, }; From patchwork Sat Jan 9 07:44:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007975 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 E2407C433E0 for ; Sat, 9 Jan 2021 07:47:03 +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 9D54723A5B for ; Sat, 9 Jan 2021 07:47:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D54723A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=2VIYCf+eVvty4xQlzm8X9UZl4I6+ThZfuTp6dZc9N6o=; b=GoNXeI1Sdwrlxagxhc9X0Allb J4yliu6dmTzYrvcNRdccsAdKywcYvzyVnh1xiDTfoi65tnLMrmuMc9/R9tXqXFNh6H2HTexro9vVz HGX3QI23eHmXe0fBqAjG1xshoci70ToEKTGwOy7ZZT0wBuMWMe6aBwb17NWrn1X73V8UTtz4/pvoM fZjIwESJWnmypDUiHCTj2dNNKVzHXYN7pLxEihyjBHBdFFcQGUpPVH7GIt//9zN6v1DeHZh+pRgia cZDKjXTg5xtGU7dtKZQmKDzPrbwa3B1Mfnf5mpLQ6RD3T/5+vubTSntI7YbBqrgPiO5Nub8z2ZmKK RHOxLvdXg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8wA-0000Ag-Ar; Sat, 09 Jan 2021 07:45:26 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vw-00005R-5A for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:13 +0000 Received: by mail-pf1-x433.google.com with SMTP id m6so2171620pfk.1 for ; Fri, 08 Jan 2021 23:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dF/EKdBMWNZukrtDgFeRBaQSiWHOXzvDtMysige8IMM=; b=diKFo4VOSz5+2ldh4AfV1QZNz/cCXen4m7HA5tvmSsq+HrOil8gfH0w8gHxF1twJfe IEOxH4puKJ1c6kSiYkGWx+ra4zzfWZL54en3bx4p6md+/8Y8kiJ7QoIljUr3oX1Rtx7O VN3WF1B4dDobQbkF5VndZgrDzY1fmvghrPP6kYXem/5i+YAms7GKVMGpgfUy12ZMlVIS mj+86A1oFjvDzvvEI3uVsoo3asL0cqOFzbSMibpcXxfC2Mm5qCZ3mNt5nYtLOkFWCnkx PCzpHesTIcCIFOtKJHEXOWf/Lt7Itjdip+3AydoGHH0jC1fvXzAQ6dj+vjdMl+Po0LRR Pbbg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=dF/EKdBMWNZukrtDgFeRBaQSiWHOXzvDtMysige8IMM=; b=dDouSroLzaNdZN/i7v6KE1tgTfYcWlgUuzMcrvbpyZZvj4Wg/eesAkOxL2QxuSZzlD GeMF0Ll7ZKGhwGc/TuOvYeVTrO40Iia0hCJ7LdUwS6mfigPL0+l0JmF8IdQkZLh5Zaj2 VJuUPMiAeKVjSrxoyzB3e9DTU1Wsp52WcRbfBpS+5hdfmeWR2ByVCaQc0iHci0ZpRRMJ AilgUo+fd1OJduUxY4tXsNYApTTAWNKyMbzl3COhONFjUFDsBlwsx1cBgLdSV3AA2syq 9aK5z6NDook/TyYUVqpuS/33cZn0PWsVOkXrtZNellz1Q5hCCaGzqM+lYDoEJDCslz3Q SZcg== X-Gm-Message-State: AOAM532iMNGBfjdLxyj8wqjh97x5tST6AeHAqIWXI8TIqqNo49Z8OXbW 1KbX/M2//vZ8C1DYTBMug2lzLA== X-Google-Smtp-Source: ABdhPJwKygRbWFTzLd1YAagyLsompFy5xCkGW8uIHWnEVp+Hs8y/4Y5lV3jiD9y1P8B4j0p+C4TLaw== X-Received: by 2002:a65:648c:: with SMTP id e12mr10782768pgv.123.1610178310055; Fri, 08 Jan 2021 23:45:10 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id ay21sm7330832pjb.1.2021.01.08.23.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:45:09 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/7] perf cs-etm: Fixup PID_FMT when it is zero Date: Sat, 9 Jan 2021 15:44:33 +0800 Message-Id: <20210109074435.626855-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024512_229737_42A9FAC1 X-CRM114-Status: GOOD ( 15.30 ) 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: Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the metadata item CS_ETM_PID_FMT/CS_ETMV4_PID_FMT is zero, this means the perf data file is recorded with old version tool and the tool has not extended to support the item. For this case, this patch fixes up PID_FMT entry to set the value as BIT(ETM_OPT_CTXTID), this info will be delivered to the decoder to extract PID from packet's field "context_id". Signed-off-by: Leo Yan Acked-by: Suzuki K Poulose --- tools/perf/util/cs-etm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 763085db29ae..8c125134a756 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -2577,6 +2578,15 @@ int cs_etm__process_auxtrace_info(union perf_event *event, for (k = 0; k < metadata_cpu_array_size; k++) metadata[j][k] = ptr[i + k]; + /* + * If the data in CS_ETM_PID_FMT is zero, means the + * information isn't stored in the data file, this is + * because the old perf tool hasn't yet supported + * CS_ETM_PID_FMT. Fixup the item to option "CTXTID". + */ + if (!metadata[j][CS_ETM_PID_FMT]) + metadata[j][CS_ETM_PID_FMT] = BIT(ETM_OPT_CTXTID); + /* The traceID is our handle */ idx = metadata[j][CS_ETM_ETMTRACEIDR]; i += metadata_cpu_array_size; @@ -2590,6 +2600,15 @@ int cs_etm__process_auxtrace_info(union perf_event *event, for (k = 0; k < metadata_cpu_array_size; k++) metadata[j][k] = ptr[i + k]; + /* + * If the data in CS_ETMV4_PID_FMT is zero, means the + * information isn't stored in the data file, this is + * because the old perf tool hasn't yet supported + * CS_ETMV4_PID_FMT. Fixup the item to option "CTXTID". + */ + if (!metadata[j][CS_ETMV4_PID_FMT]) + metadata[j][CS_ETMV4_PID_FMT] = BIT(ETM_OPT_CTXTID); + /* The traceID is our handle */ idx = metadata[j][CS_ETMV4_TRCTRACEIDR]; i += metadata_cpu_array_size; From patchwork Sat Jan 9 07:44:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007977 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 0EE1DC433DB for ; Sat, 9 Jan 2021 07:47:12 +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 A3B0423A5B for ; Sat, 9 Jan 2021 07:47:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3B0423A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=GimDcF0a/HkbvhV7Zcr2ZjQdQBvtlo/UgH2E9y5uzH0=; b=uz9pp9K5eZkg6ZRgjyPH8AyYy ZR4Z66A6SIq1+mDNhOpR1sTVCLwPk7PJgheAKZ2Ton18kFvEa/3vNRBldO1EU581dgQuxwwHpu1wK LbjgKJkm1pWoxzM3xnMTXAEsQgbbGallDtXY+a5GEZyJvecyLME/rmqeaIU4HKHtUP51RJ3N17CTU c83HwrVG7MnLclKfD/ojFoM+SislPChkUYFZ2WNTVdJ5yjKKs/jTwFA+bFeKxq7DNVqJDl57smsLY 3IAskObJl8kiuyWvbVXp5ndgFGT+5VD/onao1HnXqUedIxW0q8AHr2uTZQvxUdnWEjT8jb3/KYzCM qV5QURDUg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8wF-0000CE-8v; Sat, 09 Jan 2021 07:45:31 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vz-00006a-Fj for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:17 +0000 Received: by mail-pl1-x635.google.com with SMTP id j1so6902454pld.3 for ; Fri, 08 Jan 2021 23:45:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gF8wwaa/cVvmvlFINdzkMrYN3OctWp3ZZ74ZzUuB7Y4=; b=cqxRtixQocDt6H20SQxC4dCcWtSK6WR1GGxn2YQYZgpP8eN95C1neXZ2KjYHJgnu2a G649R6nxcsv3CeC4TsZVnEvjKuTNKruZ8lf6tTGJv+bQfU8WNmn2b2Q6CCKd3LbjVY2w t5/wKguOApM1ZgX2Ab15JgBtF7TyfGwfQXY1w6GlvP9zMOaPcZPjgZxZHC6YtsM29L0c iu7YhERUeE426puzBcZIdYdCzl5aP0YwKZaO5JubKZ9Osu2UhK1xO67p1qy31ftZKZyz TUScImZSB1JP0cu1Fn+FMw9ZGNq9M4k1pZHF8mBbGYu3Qlahrp0YLeS6KhGw7ITL452h 82bA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=gF8wwaa/cVvmvlFINdzkMrYN3OctWp3ZZ74ZzUuB7Y4=; b=L9tj5NuM4D/CVJcBzFYn7qUflFnCzS2JlCof0mRXBaX4/Uefou3MJVq09THpbNHoxK SV/v3b/wPGRIFsngO5L3hsKC+E2H8p7C1rZWpQdwDhJRNmVyeInU/WLc1ah1hA6t7c1B p4Ol5C4PEppqGcyrGY4V3xUIOqIfFPFurJ32k1gIxjD8X6DVcvv6hEosYychG9dlDL8K VYAvPW5bHfB1dbhc6ORLjCwqOFm4Wp1E0xMGDSRG83H8eg9AOTbe9ICysBmP1KunRMVp F/hnoqY3++jPzltgouFZxYCPb7HY3c+RNDlvDcyAQ4TBp5qpWl0SdE4qnnpxRDWkVQ8G OPDw== X-Gm-Message-State: AOAM532LfyDUt/Ck+mGgkmZC9R8j/NgOfEZBLqRn4+iD9ljkQ9avIqhM 1h0yAnjQ+fHRy9cdj7O8x5+pVw== X-Google-Smtp-Source: ABdhPJxgYDHASWS5ekABCpRPD0n++0E+SuyZ8clpRqHh2VNtV+fe44eSrdVzOb7bQHO5EUYKol4BkA== X-Received: by 2002:a17:90a:7844:: with SMTP id y4mr7738077pjl.68.1610178313429; Fri, 08 Jan 2021 23:45:13 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id p21sm11056872pfn.15.2021.01.08.23.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:45:12 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 6/7] perf cs-etm: Add helper cs_etm__get_pid_fmt() Date: Sat, 9 Jan 2021 15:44:34 +0800 Message-Id: <20210109074435.626855-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024515_633948_409EFF9A X-CRM114-Status: GOOD ( 13.47 ) 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: Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch adds helper function cs_etm__get_pid_fmt(), by passing parameter "traceID", it returns the corresponding PID format. Signed-off-by: Leo Yan Acked-by: Suzuki K Poulose --- tools/perf/util/cs-etm.c | 18 ++++++++++++++++++ tools/perf/util/cs-etm.h | 1 + 2 files changed, 19 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 8c125134a756..6705d39c8cee 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -157,6 +157,24 @@ int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) return 0; } +int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt) +{ + struct int_node *inode; + u64 *metadata; + + inode = intlist__find(traceid_list, trace_chan_id); + if (!inode) + return -EINVAL; + + metadata = inode->priv; + if (metadata[CS_ETM_MAGIC] == __perf_cs_etmv3_magic) + *pid_fmt = metadata[CS_ETM_PID_FMT]; + else + *pid_fmt = metadata[CS_ETMV4_PID_FMT]; + + return 0; +} + void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, u8 trace_chan_id) { diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 8cbbea6100a1..98801040175f 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -175,6 +175,7 @@ struct cs_etm_packet_queue { int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); +int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt); int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, pid_t tid, u8 trace_chan_id); bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq); From patchwork Sat Jan 9 07:44:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12007979 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 37796C433E0 for ; Sat, 9 Jan 2021 07:47:21 +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 E65E523A5B for ; Sat, 9 Jan 2021 07:47:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E65E523A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:References:In-Reply-To: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:List-Owner; bh=7ggmuqksOvrBze9zafobhoE8XqStg0wvs2E/qtEVa+o=; b=R8/Wiqz++wpFKeTkGu+GGnSAq WiCx1lASIQv18XIi8fbQAj6eSp1bvmxQ+Qv0iDCkgBnU1dAnBDOPxJM+gbNBsKPUgTCwHRqDAbFJT IaJYPHhGUKUwhup/cfSaWPxKw2FKagCKIcnwVkESWhUNoukscJJwa8Ex/sInk6hboxvZKhsap6sZI +DYIMYrrzT5JFN5v3lZtCVOk61aYLtJ4BKhpz+o/UUYFIWl5a/WsR7/bTXMvNuwniamu7JKKosaxF NMzWatdzZODpUY9gQdhi7PHjg5DooJW8uOqInq6Kh5f6R8quRyr7aoMVHrseo9hlsAyU2Hl1sCc8o OHmLITozA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8wL-0000Ev-GX; Sat, 09 Jan 2021 07:45:37 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8w2-00007l-RP for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:21 +0000 Received: by mail-pg1-x529.google.com with SMTP id p18so9125512pgm.11 for ; Fri, 08 Jan 2021 23:45:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F4OzOyv70Lhfq12F8FRvsAetz6bosZ6Up6z1SXm5NbU=; b=MRKGhr7eJRhmN9fkZMr5AF257GyyH9ZLwPvc2vQugCAUazcmLqVQ3BNC0WfQYhVoxO MIboq621Ct6wqDKEwP7FcQ1yyhaiMucScDXrCrj5u/iqTjYavcolW9JmwyJpozWMcUI0 jF05XNu/Kn9sVBegFg8OwfpiqpD/0NM/Z+4NDkPY82IpHycPffb8SQmp8FUFc4Zzi/g3 rNUCqk+DhGVOgjdwDPAQmBc8eyXY4vyZ0DakLKlBpP6SmWns+dhHNIZLau2ZKGMfJGEa uyhNCuxvErESioUpTVp+N+62vEFBNIHdCRegnL9xVuE8A0mFR+SyoifduoZqiTSb7yDl 1KcQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=F4OzOyv70Lhfq12F8FRvsAetz6bosZ6Up6z1SXm5NbU=; b=a+dWxmY8n5lwcJp3dLMReKKvFk8C5PszHqcSbkBhGv6dHwDYlaiIGScuvkgQY/bPmS /3pk2vzxP4CCzh+1n2u53f8zf7ij9gPwGCcipXJvd7NKV1hItjTCOB1XipGEnroLXCvb dOrPuQfVi2rBkRBt8w1R/qwyoGJu8ZmdkTllQsIz+g07yuEoZtNzp8v3yvr9xlKQC+eM YuF2JG/rHxlrx9EIe/nQjTxcexnTzeEK9f1+mIa3v0CUYEjypco8ReozR6e4og4pxbIS ZJdrkWgFseqEAYCW6knxkAm+z/3FSLfg5On1UtQnlr/UA4AXc2OXWngGq4qfMhnliiNR KeRQ== X-Gm-Message-State: AOAM533HMRNI0yBxz85/d2Lu9aTsSUdJgvhP0NmRyZxkcbM1tq2gsos6 2AcLxkWAuSBTEUoYwJNhIngxYw== X-Google-Smtp-Source: ABdhPJz059312bIOdjut/wKwfTvxECETX2CJluKIS2sy1Xom9WVZzFYE0xFijueYYkOXpr612t5kBg== X-Received: by 2002:a62:1b06:0:b029:19d:d05d:f67a with SMTP id b6-20020a621b060000b029019dd05df67amr10514616pfb.78.1610178316718; Fri, 08 Jan 2021 23:45:16 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id o190sm11602324pga.2.2021.01.08.23.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:45:16 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 7/7] perf cs-etm: Detect pid in VMID for kernel running at EL2 Date: Sat, 9 Jan 2021 15:44:35 +0800 Message-Id: <20210109074435.626855-8-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_024519_517532_C9D78CC7 X-CRM114-Status: GOOD ( 17.08 ) 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 , Leo Yan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Suzuki K Poulose The pid of the task could be traced as VMID when the kernel is running at EL2. Teach the decoder to look for vmid when the context_id is invalid but we have a valid VMID. Cc: Mike Leach Cc: Mathieu Poirier Cc: Al Grant Co-developed-by: Leo Yan Signed-off-by: Suzuki K Poulose Signed-off-by: Leo Yan --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index cd007cc9c283..9e81169dfa76 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -6,6 +6,7 @@ * Author: Mathieu Poirier */ +#include #include #include #include @@ -500,13 +501,36 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { - pid_t tid; + pid_t tid = -1; + u64 pid_fmt; + int ret; - /* Ignore PE_CONTEXT packets that don't have a valid contextID */ - if (!elem->context.ctxt_id_valid) + ret = cs_etm__get_pid_fmt(trace_chan_id, &pid_fmt); + if (ret) + return OCSD_RESP_FATAL_SYS_ERR; + + /* + * Process the PE_CONTEXT packets if we have a valid + * contextID or VMID. + * If the kernel is running at EL2, the PID is traced + * in contextidr_el2 as VMID. + */ + switch (pid_fmt) { + case BIT(ETM_OPT_CTXTID): + if (elem->context.ctxt_id_valid) + tid = elem->context.context_id; + break; + case BIT(ETM_OPT_CTXTID_IN_VMID): + if (elem->context.vmid_valid) + tid = elem->context.vmid; + break; + default: + break; + } + + if (tid == -1) return OCSD_RESP_CONT; - tid = elem->context.context_id; if (cs_etm__etmq_set_tid(etmq, tid, trace_chan_id)) return OCSD_RESP_FATAL_SYS_ERR;