From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 6BB09C55ABD for ; Mon, 16 Nov 2020 09:47:16 +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 DC43F2225B for ; Mon, 16 Nov 2020 09:47:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1kK+4GbA"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pyqol+xx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC43F2225B 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6jG3PkFLcCDy15m/ezp5dasvvo22DaoEoKX7OEsL0SU=; b=1kK+4GbAwk9XZsh0GF3XaaZIY e7XvoSS5LKJGQplgY6zvcY+sNJjOWNGBxFryJEeFgjDW/R3u9jcUwP/nGvVkt6mHMYeONjfpj6l/j ii5L+LWp0QqJnMxk/AjOPCvGuwje2mXJhPStG8Hz+TL6OFyZ/aWUBjseoxsOPyynX4M4oBXJzgyqN UbDQnqf/ag6if/tS7qxnktQL3aR7J7wef1Vcnt2gXyfo1mIHI3gtBbQYeoYxUMZYRp/r7Yhh1HyBs SU4K8MtF8ZAowvQIlAkqCHokIKQc9UOk42PUZoNfDYz8Hh3Zznykl1dkLmuBC9sjO4tEmLXLqOZ77 mtKfRtL0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1keb5y-000522-S7; Mon, 16 Nov 2020 09:46:46 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1keb5v-0004zP-Fy for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 09:46:44 +0000 Received: by mail-pf1-x441.google.com with SMTP id q5so13610030pfk.6 for ; Mon, 16 Nov 2020 01:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zT6D3iqWoeILJpJ/yhH+Qf5VLKHlN0jMaybGwXaw4C4=; b=pyqol+xx8IyAm5PV0bLn4PG1M5liNPEMBPNkBqjRu+pLNJSinDE5kIJdPnfCI9ERP/ xlUvjpkrdkGoCWvw8XC0YdP0NU3qcDwf8/gczpOb/RJFQxh0yW4ZqYjvQt2YTilK9RFf elWTiIRYevP2OVP5BCioBLRM57L6AypIamFTeyt5VZ8v+9rKejdUn8nxVTgMmrpAGekX 2Xa73C4e2WKLs+eAkqSR+k3jgX2q0rh2eg2TzX4cqS4mAhA/kyXgp/G9lMdbYu2PpJSS HZ7R6kjnpJviofEblL1P/TOImUo4SoI2jvGgk+VIvGJBEDMF+bW2RPPWj9TVvuSjtDBM 8kLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zT6D3iqWoeILJpJ/yhH+Qf5VLKHlN0jMaybGwXaw4C4=; b=Xk66hK5h+f0HIWA16hXwqRFbzH0yq3uwzVK7WI4Hq/9J11liRjtq96u7vaUMLSTush Lz+x9pNzvWXK1vmsjwjnNrpS5PcdOwKtjnL+xj3T+fzTVtBk0QF+EqEaQoqpWNDaGq+Q 2k9wdOMLH0zizrrNnykLVGmrHxiwD+XgAITb5j6evhmxwk0WLGDyDFQ4PBYUINRnx+oa drNg6Kk78T8xNikmYHOU+bUwGTfNNqq/0fAIIRhApe6U4OIwR2vIEzXLAbULbmG9Zrga zBUurMz64ArzoMSL4q2IGJGQpemifA2TP92pmR1KR4NuFEjaVXWF1KlUNz/D/RqLoNFT mWDw== X-Gm-Message-State: AOAM53146XJBUnEK3XzSI5tqM9YShP3rHIMsTLD5DpFrMbJ2IUBnTqXF 2dE/YdhYM4/4XMnoqz+05P44QA== X-Google-Smtp-Source: ABdhPJwSty03iInhZLPhCPMn5oUzlLl/o2ZwW2XGl6rhmaiVG96mMdt1BzD78k/EMc7e4BHR8Byj6A== X-Received: by 2002:a17:90b:19d8:: with SMTP id nm24mr15122311pjb.144.1605519999513; Mon, 16 Nov 2020 01:46:39 -0800 (PST) Received: from leoy-ThinkPad-X240s ([103.127.239.100]) by smtp.gmail.com with ESMTPSA id t9sm1955638pjq.46.2020.11.16.01.46.36 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Nov 2020 01:46:38 -0800 (PST) Date: Mon, 16 Nov 2020 17:46:34 +0800 From: Leo Yan To: Suzuki K Poulose Subject: Re: [PATCH 3/3] rfc: perf: cs_etm: Detect pid in VMID for kernel running at EL2 Message-ID: <20201116094634.GA31795@leoy-ThinkPad-X240s> References: <20201110183313.1823760-1-suzuki.poulose@arm.com> <20201110183313.1823760-4-suzuki.poulose@arm.com> <20201113001105.GA22708@leoy-ThinkPad-X240s> <7e45fd42-0869-cd4f-1eaf-5d48e4464482@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7e45fd42-0869-cd4f-1eaf-5d48e4464482@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201116_044643_604276_4AFBD2F1 X-CRM114-Status: GOOD ( 36.52 ) 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 , "mathieu.poirier@linaro.org" , Anshuman Khandual , "coresight@lists.linaro.org" , "linux-arm-kernel@lists.infradead.org" , "mike.leach@linaro.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Suzuki, On Fri, Nov 13, 2020 at 09:47:42AM +0000, Suzuki Kuruppassery Poulose wrote: [...] > > Rather than heuristic method, I think we can use metadata to store > > "pid" entry in the function cs_etm_get_metadata(), so that in the > > record phase, the "pid" is stored into perf data file. > > True, that is a good idea. That makes it future proof. > > > > > When decode the trace data, we can retrieve "pid" value from the > > metadata, and can base on the "pid" value to make decision for using > > context_id or VMID. > > > > > The metadata can be accessed by referring > > cs_etm_queue::cs_etm_auxtrace::metadata; but the file > > util/cs-etm-decoder/cs-etm-decoder.c cannot directly access the > > metadata structure due to "cs_etm_queue" and "cs_etm_auxtrace" both > > are defined in util/cs-etm.c. It's better to introduce a helper > > function in util/cs-etm.c to retrieve "pid" value, like: > > > > u64 cs_etm__etmq_get_pid_type(struct cs_etm_queue *etmq); > > I am not an expert in that side, how it interacts with the OpenCSD. > thus left this patch as an RFC. > > I appreciate your feedback and thoughts. If you feel like you could > cleanup and implement this, please feel free to do so. Otherwise, I > might try it out whenever I have some spare cycles to understand > this side of the code (and this might be delayed). Below is the drafted patch for support PID format in the metadata and I tested for "perf record" and "perf script" command and can work as expected. P.s. I uploaded the patches into the github [1] and gave some minor refactoring for your last patch "perf cs-etm: Detect pid in VMID for kernel running at EL2". Please review and consider to consolidate the changes if look good for you. Thanks, ---8<--- >From ba70531217c51f2b4115965bd7e4b7b51770a626 Mon Sep 17 00:00:00 2001 From: Leo Yan Date: Sat, 14 Nov 2020 09:47:12 +0800 Subject: [PATCH] perf cs-etm: Add PID format into metadata It's possible for CoreSight to trace PID in either CONTEXTIDR_EL1 or CONTEXTIDR_EL2, the PID format info can be used to distinguish the PID is traced in which register. This patch saves PID format value into the metadata when record the trace data; during the decoding phase, it provides a helper function cs_etm__get_pid_fmt() for easier retrieving PID format from metadata. Signed-off-by: Leo Yan --- tools/perf/arch/arm/util/cs-etm.c | 21 +++++++++++++++++++++ tools/perf/util/cs-etm.c | 21 +++++++++++++++++++++ tools/perf/util/cs-etm.h | 3 +++ 3 files changed, 45 insertions(+) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index e6207ce7cc85..837eebe30a90 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -606,6 +606,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)) { @@ -634,6 +635,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 { @@ -651,6 +662,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 a2a369e2fbb6..ffd91c8dadf0 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -156,6 +156,25 @@ 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 = (int)metadata[CS_ETM_PID_FMT]; + else + *pid_fmt = (int)metadata[CS_ETMV4_PID_FMT]; + + return 0; +} + void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, u8 trace_chan_id) { @@ -2447,6 +2466,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 +2479,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..98801040175f 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, }; @@ -173,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); -- 2.17.1 [1] https://github.com/Leo-Yan/linux/tree/perf_cs_etm_pid_tracing_vhe_for_suzuki [2] https://github.com/Leo-Yan/linux/commit/302600d5676c45ebfa8a221b2d5fa4172ff42a91 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel