From patchwork Tue Feb 2 16:38:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12062257 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.1 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 BB808C433E6 for ; Tue, 2 Feb 2021 16:40:51 +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 7787E64F72 for ; Tue, 2 Feb 2021 16:40:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7787E64F72 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=3lCIdcAE0ErQEbIgnNggK0lLsaJEy+WKvH7mgmS1Zyw=; b=dX6OuPdDDXYJ1j3MnP48Tu+vv jq/LVkgPTRwDe64zAhCBR5zz/d+i+mugZf4NS5mOuK1+y58M+x/8Cyf9gerk81ERamMenUvIm4deL agx1NODrUnHpMqbkkuvnhCRKjkgzR8q0sUKsnoPuUrzH1cIahRBIc7ihuYj7D/sN6T3bY9wpl9Z2F nzoXWIk8wt3kk0QjY/m14PIvhGQgUhAApgdMGHqu3yzKvnnjnUXi6bQILGWQ6cOG7KtcQe28ZtShv /fEP4tmpHPZ2cndfum9+audRtNP/T0fPCvDCpRfChuiO2S/WQiwRAPLcpN4mbr53ncHWBTF2oH5So qZqQNKNmQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l6yiI-0006Hh-Bu; Tue, 02 Feb 2021 16:39:38 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l6yi5-0006B6-QN for linux-arm-kernel@lists.infradead.org; Tue, 02 Feb 2021 16:39:27 +0000 Received: by mail-pf1-x435.google.com with SMTP id m6so14710178pfk.1 for ; Tue, 02 Feb 2021 08:39:25 -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=V2lSRSt7N2kcQ0+pfELKM7JZFhVM2Dwdlyux9eP2c0c=; b=sayQXgMDWznfBbxktPHzwshYZhmop5peILAxFgiQn94AIcgnL/xRLNVph3GW6XuCT3 GB0Z3A8HWWs7pWAD2gGXwIUQoLn3hB7yQxYRJP3K4vGvfAurjIWNHhTWn7a2BmuOwsGO EpPo9HRIhO2Aa61VVThHtGtr5AE3UFy6imSWxpeS3hMHXzrB9/QInfPdz7hKEkD24AwO 2wGLsOy+5p0IsgZZogeWQfxti+mhErSZAf2IZpf2A72uZnytyrmKMyqeQ1E3TDQCqHET EaGe5l4rHnIb/d+YdIE9xi4ezl+Y3Np8mufbnhR5lSrJeyuXj07GW3iAwD7BFzt3jK0q JISA== 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=V2lSRSt7N2kcQ0+pfELKM7JZFhVM2Dwdlyux9eP2c0c=; b=a8qOzfx5SeRNwHqtuF67G8jg0rjoDOG4YlpCKe9UoSXnTwIWHom2+aNXxyHKgGySuD Vzgb+Y6BMSuvmjW7KP0MhFW0DjqY6BPD2+WBny9OR3eRbMtMCIWBLO7xIFQQUccAQPd8 51IR3fMqsLo4oU7l2XRXZFRsJRwv6W4kMASFStKk5Ar6cds6Z0p9T6kxskWRpayzvtdH vOlB5RC971uDSUYNUIVZWzlYX7R/O5yL4eu+ljmxL+X1AxhF8ghUaV9pk3dwh9CjVFgD re/+PXe6XQ47BR9eB9/Ix5dBaAb5CVmSS01hOjBfrCdMCXS9zsOvitNb4q+zmKNXmHm+ 0MJw== X-Gm-Message-State: AOAM530Crp2oOm1ojMt+awd9KDzGsd/kWs+KIh8WPFhzp+tb3KVRmqe7 f7BV3zFxY2Gsjlc/HHRQ0FtIBg== X-Google-Smtp-Source: ABdhPJyS6ootz5/MUIbpCq0nnbh/qg8NapSJATnyWajH1UfDBRNOOGycEMGhBKOnWlDY9XhgE5qz6w== X-Received: by 2002:aa7:83c2:0:b029:1a5:daa9:f22f with SMTP id j2-20020aa783c20000b02901a5daa9f22fmr21612501pfn.48.1612283963844; Tue, 02 Feb 2021 08:39:23 -0800 (PST) Received: from localhost ([45.137.216.202]) by smtp.gmail.com with ESMTPSA id a37sm21936861pgm.79.2021.02.02.08.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 08:39:23 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Jonathan Corbet , 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-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] perf cs-etm: Add helper cs_etm__get_pid_fmt() Date: Wed, 3 Feb 2021 00:38:40 +0800 Message-Id: <20210202163842.134734-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210202163842.134734-1-leo.yan@linaro.org> References: <20210202163842.134734-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-20210202_113925_918428_0916B865 X-CRM114-Status: GOOD ( 19.11 ) 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 PID format. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 43 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.h | 1 + 2 files changed, 44 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a2a369e2fbb6..8194ddbd01e5 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,48 @@ 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 these two bits are set together, this means the tracing + * contains PIDs for both CONTEXTIDR_EL1 and CONTEXTIDR_EL2. + */ +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]; + + *pid_fmt = 0; + + /* 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 */ + 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);