Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2770788pxb; Sat, 6 Feb 2021 07:13:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTqkcdnnNr61ecih7C37eeNov7pVctiwDN0MXzsczGYT7v7nwFV52rQW4EQAERfBeMdHh3 X-Received: by 2002:a05:6402:19bd:: with SMTP id o29mr8710757edz.161.1612624407516; Sat, 06 Feb 2021 07:13:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612624407; cv=none; d=google.com; s=arc-20160816; b=0R6nDUMvcAgPs9HQEZXyri1L/wrLWP9JtbDiBK+n8+G34nIL4riQ6GGfFWL1TQJC9A 3lRjsSC4klrzw8YCPHhTHFYhNVO/gz48Rzu56Y1jkRtE/LltbKKqrFgRfWEk9v6A5GZ/ VsJ2DMkavYnd8JXumYishk5NeQ68Vb2jpLhywfktZsaxjJgj5nYJIgTn1yog/THO+OOr Y47Z0iIx9HPBnlIA+cnQrDQmBv4+YKY7yNe7OYiWmzpSWz29ELeqeLU0+9x6xjX6iRif 3ejiSsDTzeJLBsMNE47s6jbDcJQamivdR9zEY8CucEmeARvqC6/+k4mFrmdPDw5jaksj Cbuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ky9/mb+HYy0WWl4mxlZ9J0RrhFZHwnjADbosyVIjsYk=; b=uuZyUpFg8BE6ciMmWv0NSRJZVRrfeijqTHQdC7vPn+m/KVPcCYVikbd+XPqqreltbz NEC+2mDhS+sfM8VzSwzECL717KsW64GUScApO/aQnH8Gc1A0Rd0TieTY4X9dPy8R4bfs 7hbnmoEKzAj81IJJrtgqk6cdehjWJP+zW6MNtZ4Pu0Ji47RR6txEuERkntXt3NI69ttI SHekpS2lxlB+5eyIknGL67Dsm4cHxuPwYSTJZFlrEd8XETZfaoehe3eEhJkOfXbyadAw xbdKrpINmBXFWbGU68B/BZliomRMvzIREp/7g88IBZazal5OrpIj9JyVtCLpCm9syVB9 6CUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HlpA5GEV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si6457512edd.539.2021.02.06.07.13.03; Sat, 06 Feb 2021 07:13:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HlpA5GEV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230326AbhBFPLZ (ORCPT + 99 others); Sat, 6 Feb 2021 10:11:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbhBFPKG (ORCPT ); Sat, 6 Feb 2021 10:10:06 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F857C0617AA for ; Sat, 6 Feb 2021 07:09:00 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id t25so6698933pga.2 for ; Sat, 06 Feb 2021 07:09:00 -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=Ky9/mb+HYy0WWl4mxlZ9J0RrhFZHwnjADbosyVIjsYk=; b=HlpA5GEVcrMJGPrmuM6bPK1RvfP8Fk+fycR62dEsBdXF53pY6j+1Sb5/XS92AH5O5J JS31C7oNrg1+xshAkDnrCGXJVOL6dSue/ewTIRfCfrblnpreLzYx+804qZRIXHvvSmH4 RPCaFIT9MIqlND2oO9WkqTnC1v7N+qfHQLJlTC5lqg6r9XDlpi6ytLo5mQtmCtUWRmLf pJYj0lks3nNgc3rGpLArT1S5IA2koPGBxqL2Gm1n25i1LxDNZNlckpZ9rrVw11WTSLbh ZLXwCx8ixCFAHdWz4GgAYkIrAejnUTJxIqDUd2PWa4KetiujY3DB3hVuN+0d7XGqM2DM +g3g== 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=Ky9/mb+HYy0WWl4mxlZ9J0RrhFZHwnjADbosyVIjsYk=; b=ly5dsWbU6OHklQ7jJk7RR6FBgUGsrqW3b65fn92kKBJXuTuLwdzEUfO/Y5DIA3hSqD L+l+xTI4SKY3Jpk7jrnjpIwgqCMEpOqD47YfetuJStnzDBQYBVknUwTCGo/Sguq8GGAB WMumxE1S0NFKb+1VcdWFNEupiFi1D1sszw+mzMXkl+Ln2Hev8CO9uDOpS+SySw/lMheg WhUpls6xLk7osdyqEIO3FzS8DGakzu4T0drAARn+wwRTwlIC0PJODcO5EGBh9iHG2CH4 MtyDBVpc4uXyKFblTcwtGQPKrnhnCHf31/TYBu6V8kuhL0uXs3DbV4r7A8YGIDo+CmOa T9/Q== X-Gm-Message-State: AOAM530EYTmM3wYHJC/5lclwiPfBddQed1DiHGPtD7AFmXM2oMWlBW9o 1xbKACggfEKn8M895NF7aSyfrg== X-Received: by 2002:aa7:91cf:0:b029:1cb:1c6f:b77d with SMTP id z15-20020aa791cf0000b02901cb1c6fb77dmr9817288pfa.74.1612624139977; Sat, 06 Feb 2021 07:08:59 -0800 (PST) Received: from localhost ([45.137.216.202]) by smtp.gmail.com with ESMTPSA id t1sm3560253pfl.194.2021.02.06.07.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Feb 2021 07:08:59 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Jonathan Corbet , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Daniel Kiss , Denis Nikitin , Al Grant , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v3 6/8] perf cs-etm: Add helper cs_etm__get_pid_fmt() Date: Sat, 6 Feb 2021 23:08:31 +0800 Message-Id: <20210206150833.42120-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210206150833.42120-1-leo.yan@linaro.org> References: <20210206150833.42120-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds helper function cs_etm__get_pid_fmt(), by passing parameter "traceID", it returns the PID format. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 42 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.h | 1 + 2 files changed, 43 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a2a369e2fbb6..b9c1d329a7f1 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -156,6 +157,47 @@ int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) return 0; } +/* + * The returned PID format is presented by two bits: + * + * Bit ETM_OPT_CTXTID: CONTEXTIDR or CONTEXTIDR_EL1 is traced; + * Bit ETM_OPT_CTXTID2: CONTEXTIDR_EL2 is traced. + * + * It's possible that the two bits ETM_OPT_CTXTID and ETM_OPT_CTXTID2 + * are enabled at the same time when the session runs on an EL2 kernel. + * This means the CONTEXTIDR_EL1 and CONTEXTIDR_EL2 both will be + * recorded in the trace data, the tool will selectively use + * CONTEXTIDR_EL2 as PID. + */ +int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt) +{ + struct int_node *inode; + u64 *metadata, val; + + inode = intlist__find(traceid_list, trace_chan_id); + if (!inode) + return -EINVAL; + + metadata = inode->priv; + + if (metadata[CS_ETM_MAGIC] == __perf_cs_etmv3_magic) { + val = metadata[CS_ETM_ETMCR]; + /* CONTEXTIDR is traced */ + if (val & BIT(ETM_OPT_CTXTID)) + *pid_fmt = BIT(ETM_OPT_CTXTID); + } else { + val = metadata[CS_ETMV4_TRCCONFIGR]; + /* CONTEXTIDR_EL2 is traced */ + if (val & (BIT(ETM4_CFG_BIT_VMID) | BIT(ETM4_CFG_BIT_VMID_OPT))) + *pid_fmt = BIT(ETM_OPT_CTXTID2); + /* CONTEXTIDR_EL1 is traced */ + else if (val & BIT(ETM4_CFG_BIT_CTXTID)) + *pid_fmt = BIT(ETM_OPT_CTXTID); + } + + 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 4ad925d6d799..7cc3bba0017d 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -173,6 +173,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.25.1