From patchwork Sat Feb 13 11:32:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12086655 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.3 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,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 D6EB0C433E0 for ; Sat, 13 Feb 2021 11:33:54 +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 9F2ED64E44 for ; Sat, 13 Feb 2021 11:33:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F2ED64E44 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=ySFNsZSKui54/HMBjoHv3WnZZhXgrUJbVyyvhcm9TV4=; b=O/6sgVcenSsTEf2Rubme/oAn/ y+V+RUCWKW5Kyd2j23KrBtVBZ1UmbSU48a2r4w6bvPPBTB8OCNk6/u5tTsfaziRMLHYfoIqzSknoW W79aEqgiwbpKQ98RDH9KmbWrqoEJsIBIUlNAtEiKb+BIlIqnwQDWuSoGAWqc7/Foa43i2W9Q+25J/ 6kE21603uwQLRcHVkcBABi6+9xGMmY03+4dkZnjkoPju33swvDE0LeRykoI9FiW2HUnlk26QubQhK GzB7aPcbf39e9txioEveiXBSTSW+wSNMO7nWi1nUtveah8itVTR3Mwdhgca17lcPp6i3OFnlOB1xi /NUQBBxmA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAtAU-0008GC-3A; Sat, 13 Feb 2021 11:32:54 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAtAI-0008Cf-Hr for linux-arm-kernel@lists.infradead.org; Sat, 13 Feb 2021 11:32:45 +0000 Received: by mail-pg1-x531.google.com with SMTP id n10so1347617pgl.10 for ; Sat, 13 Feb 2021 03:32:41 -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=wbm4VCOO9V7CJF9LTwRfdozS2/Id11XKl501bGe/G5M=; b=LMNe8/xsu+KocyPUZZlaujqNQrURHBKPKwwSUZGydCASFZV11Ixz7kXASAM7wNpBhv XHumekcSReCA6uK8AUWBpgOO9K1fq6AFKm6BnwgEOCfLvNkoTEYMWHGqKj4E4bXVcAMY pl9cnMa/3+RKgmq2/QDEal12P3ye0hZY5gQN0MNhqkQaqL2lzaUb2N0hWjMKKM7ILvFl 5Rkvhj8gptGys97bSVrjA/lOOZgAqfkm931Gt+Q3lKnNHnm+zzzE9afvR4mBnYX4vMEq 6FcQx1FHRAspvT3rOuPeolAJgkf9JN15DoYCbeaENoeziclKtxuCwnqcJ0CZidTSBEsK iThg== 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=wbm4VCOO9V7CJF9LTwRfdozS2/Id11XKl501bGe/G5M=; b=E59dMpNt1IsNwF3rvXHUcM5hfg7mnr68eko1WLVsR5CwwxK3PlHULbAEOezlkMbS+4 HyAyh2w7XRh+HnXWFOCr0FBXOj9cFQAIJNGOCUUcJ6qAlh69rPpAlp8WQhOZAoDWZpOC tpAuaAh6246rBXSB3Oe1Cpa2MWFbFAw52LRKBr2pE2qpn4xlD4L593aaE6XbCIXb+iJH mZ/goxmvKFlv8PMkEh6y7lSOsrt22aKNMsGj0QdTi7M6WzVlijidZdiJ6UUWhYsDhLBA 4uHjMd6RcKm9PBMXpE5NgFwAcIQ4jIChMgY1TCB3/g2OMkQbSBK2Wo7FRmtsrT3Ek+LY HhoA== X-Gm-Message-State: AOAM531HkYUx4qpbDIhdb42f1Fg0WpALj0Vv9u9yzuSeEFo6tRCKuhW0 KUAW5nz+DYO85I+weXS0XvXk3g== X-Google-Smtp-Source: ABdhPJyOao5864wErHrNCx7dSlkDpWrUUzI41GkTijV0Knck2z7s4Va/XJy2lsQHppCiQSNKwd6/8Q== X-Received: by 2002:a63:da46:: with SMTP id l6mr7414109pgj.134.1613215959443; Sat, 13 Feb 2021 03:32:39 -0800 (PST) Received: from localhost ([45.137.216.202]) by smtp.gmail.com with ESMTPSA id gl12sm10480771pjb.54.2021.02.13.03.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Feb 2021 03:32:39 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/5] perf cs-etm: Support PID tracing in config Date: Sat, 13 Feb 2021 19:32:18 +0800 Message-Id: <20210213113220.292229-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210213113220.292229-1-leo.yan@linaro.org> References: <20210213113220.292229-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-20210213_063242_772893_6181827E X-CRM114-Status: GOOD ( 20.98 ) 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 a task is exposed via VMID instead of the CONTEXTID. Add support for this in the perf tool. This patch respects user setting if user has specified any configs from "contextid", "contextid1" or "contextid2"; otherwise, it dynamically sets config based on PMU format "contextid". Cc: Mike Leach Cc: Mathieu Poirier Cc: Al Grant Signed-off-by: Suzuki K Poulose Co-developed-by: Leo Yan Signed-off-by: Leo Yan Reviewed-by: Mike Leach Reviewed-by: Mathieu Poirier --- tools/include/linux/coresight-pmu.h | 3 ++ tools/perf/arch/arm/util/cs-etm.c | 61 +++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h index 5dc47cfdcf07..4ac5c081af93 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -20,14 +20,17 @@ */ #define ETM_OPT_CYCACC 12 #define ETM_OPT_CTXTID 14 +#define ETM_OPT_CTXTID2 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 ad8421e8b651..08c329d6b2a5 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -67,6 +67,7 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, char path[PATH_MAX]; int err = -EINVAL; u32 val; + u64 contextid; ptr = container_of(itr, struct cs_etm_recording, itr); cs_etm_pmu = ptr->cs_etm_pmu; @@ -86,25 +87,59 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, goto out; } + /* User has configured for PID tracing, respects it. */ + contextid = evsel->core.attr.config & + (BIT(ETM_OPT_CTXTID) | BIT(ETM_OPT_CTXTID2)); + /* - * 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 user doesn't configure the contextid format, parse PMU format and + * enable PID tracing according to the "contextid" format bits: + * + * If bit ETM_OPT_CTXTID is set, trace CONTEXTIDR_EL1; + * If bit ETM_OPT_CTXTID2 is set, trace CONTEXTIDR_EL2. */ - val = BMVAL(val, 5, 9); - if (!val || val != 0x4) { - err = -EINVAL; - goto out; + if (!contextid) + contextid = perf_pmu__format_bits(&cs_etm_pmu->format, + "contextid"); + + if (contextid & BIT(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) { + pr_err("%s: CONTEXTIDR_EL1 isn't supported\n", + CORESIGHT_ETM_PMU_NAME); + err = -EINVAL; + goto out; + } + } + + if (contextid & BIT(ETM_OPT_CTXTID2)) { + /* + * 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) { + pr_err("%s: CONTEXTIDR_EL2 isn't supported\n", + CORESIGHT_ETM_PMU_NAME); + err = -EINVAL; + goto out; + } } /* All good, let the kernel know */ - evsel->core.attr.config |= (1 << ETM_OPT_CTXTID); + evsel->core.attr.config |= contextid; err = 0; out: - return err; } @@ -485,7 +520,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_CTXTID2)) + config |= BIT(ETM4_CFG_BIT_VMID) | + BIT(ETM4_CFG_BIT_VMID_OPT); return config; }