Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2771127pxb; Sat, 6 Feb 2021 07:14:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4DdNBZ1jF4DHkKUz5fxhGkcnS0sdu8sHtSxCpJDESdS4bRYnIoZJDF312ohi/1PjLo8U4 X-Received: by 2002:a17:906:f6c7:: with SMTP id jo7mr9584573ejb.178.1612624440034; Sat, 06 Feb 2021 07:14:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612624440; cv=none; d=google.com; s=arc-20160816; b=Cb7ycMthbqxMXMpYVBZzAOzHBoQzlvgXeYBffWYVsDmOA7SsDTIWIN+iYaIQe+L8Hp 19KOLGWROBiwoMn9ca9Wse7Vty2d/+IKbV0BXK6K/2/y7/e5yehK8uLtD851cuf2iitx /HYw8PX1kL8GCUurEkPWm/sKHAm5SpuVsPDVSG+aJ1aPMLWDxTzYOLHKY/0AeSM9p3nQ SJDZ0L9RGJd/ry8nNTOf9UCJfoY9z1T5YR0RHQMkUV4+gMupZujpgVveuq0X9FLPojTK OzBt5B8WeA3GoNxtmKBzpfSrU1QXsnxC2Eaim55M4GX1usdRCEl3UdzUHTBfFDVFR2RY ZXyw== 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=XAsb7dnmzbaljkH0CVEHBr6f3jyPLu6vS3k+O8s+p4o=; b=qHRsXqj8PkeMWl+xWqRzqiSDsvSxwc3mG90ptx/kl9rdweRLeicJ6MOlQMr3wGGXkF nfYYCkG91II47H/B1gwv7au5BUbfCTQhNd5LprxLneAkOxG2brAg1uixuMhvEr5oYJj2 jRX3UNeXJNYKprpR82cmfqYDh/GG5mht+DamCa/559oUQBY+g5k4stZnIMrZ31HC7GY4 qVOAjqPKqlEZXX9Z7cxHnLqPfD6KLJoeNjHwadb3qe3v+L0sQIxSz5rREt15UaUdH4H1 wm8Nv2jcb7Udb3uxRxwjsEoMFNgH0WHejgcayyCze3LFxPYFd+LPFszgO1n9RKeOFhGB KNuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PY+hsjmH; 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 ku3si7550794ejc.497.2021.02.06.07.13.34; Sat, 06 Feb 2021 07:14:00 -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=PY+hsjmH; 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 S230307AbhBFPLL (ORCPT + 99 others); Sat, 6 Feb 2021 10:11:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbhBFPKG (ORCPT ); Sat, 6 Feb 2021 10:10:06 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D9A6C0617A7 for ; Sat, 6 Feb 2021 07:08:57 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id o7so6703597pgl.1 for ; Sat, 06 Feb 2021 07:08:57 -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=XAsb7dnmzbaljkH0CVEHBr6f3jyPLu6vS3k+O8s+p4o=; b=PY+hsjmHc0QYlaZZl66yeqcQ8DYLM1uDpbS6K/WPuOzf0f7rXkxZKO7LMngF5XVg3z mQW93xf4SlMYEU+HpUFoeGTcMzS9WmHg+B40LNIDOyPn4bcWdRjRgavflvP3HzIs7KsL T6zufgjTFImAvzO5YtUcIR4rIfiW/zNdc/c63JouoaXgXfaO/ZAvnsQTxFfWFjF9auJn hoUB0xPHxS04K/NIHRXESJ+pg7x0O6HlF7DuL2onvXWB9Pya8wR80sZRTEsUkwokEYlW L1WKsBOezWh0oOATMnMp2dNQr7NK3JGCn6m2KAVmTfQyvuOstZdGoz4WUu+w3KS1jPwW rrGA== 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=XAsb7dnmzbaljkH0CVEHBr6f3jyPLu6vS3k+O8s+p4o=; b=Yd400Flv3WKIG+y01gpq8ygaelo7vStwqKlzHIOmFs4Zq4gGwFFNcayCB5WrQVSMmA 7MmnmdF7DNjJ6gUbJ+HwXMTJtF5Q5uT4+ymnawEoeq/5HGOuYC5h5xVq3eRazI0z48CB 9ZLM3iBj39xwn3YiefzV8dHMjZfONz8FX2a5Tv6wn6u+yCRl8yMJZ8jxewvoYyt84Mcp t1ze79e/ugh9fHpLftOgB2TSHWZxrORaRax6nJVjqla5T+jWAHH0+Vb3tVt2xJyFT+o6 +R58DiTmBT55txQJaAH5Ltg4eeYuMitaTCSKT05RfC0NciQi8K+im80DFoV7xdSb7vkg BUIA== X-Gm-Message-State: AOAM53232rFgcmnGf2RMSxNsUCZrX5yKnmOTy5Yi20uZtxSIYhRg+2x2 DxwspGEhSjUEvM0RV8HuSuj3f6rzxmoRcpc3 X-Received: by 2002:a62:76d3:0:b029:1d9:8e88:9276 with SMTP id r202-20020a6276d30000b02901d98e889276mr4555762pfc.71.1612624136614; Sat, 06 Feb 2021 07:08:56 -0800 (PST) Received: from localhost ([45.137.216.202]) by smtp.gmail.com with ESMTPSA id o14sm14887602pgr.44.2021.02.06.07.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Feb 2021 07:08:55 -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 5/8] perf cs-etm: Support PID tracing in config Date: Sat, 6 Feb 2021 23:08:30 +0800 Message-Id: <20210206150833.42120-6-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 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 --- 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 c25c878fd06c..fa6f91a7c8a1 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; } @@ -489,7 +524,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; } -- 2.25.1