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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 DACE3C433E9 for ; Sat, 9 Jan 2021 07:45:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9FF623A9D for ; Sat, 9 Jan 2021 07:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726685AbhAIHpm (ORCPT ); Sat, 9 Jan 2021 02:45:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbhAIHpk (ORCPT ); Sat, 9 Jan 2021 02:45:40 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B3C2C061757 for ; Fri, 8 Jan 2021 23:45:00 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id i7so9147286pgc.8 for ; Fri, 08 Jan 2021 23:45: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=nQMCubmgzlrRTa03+kmNvTwcrwNhs1nXf3jbRihBgmo=; b=JPQAm8mKkZrg0ceXulqBGIaytFxCQsnVgLuM6fuf2yKXNydlAgB1ORNGeDTtV6oIno 9Hi/KbJ4PBf332SxeI624u1oirZIHqJmRSVgyaHl+BBXrdJ31L6cPGfjCBdpaoawGbB6 y9uSL/y9E4WyBKE1iXJKoXvYaLPuR8EfS4IDpU0DwBLIMtr8HzSlHxKv6E26BF+IhNEG NBhY4THkePFvw7ceywId+66QiJy36rnaXz3Zjm7YBm8BIbKM59HxqGuM25qBJ31viZYP ZQFtREygT/82YmF7d5dNOexb6baO+YyMaofc6iARj3qm5ox8ICWyizMYQN7b8803TxgQ dQQw== 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=nQMCubmgzlrRTa03+kmNvTwcrwNhs1nXf3jbRihBgmo=; b=eapt6g9UhWgSzzQm1u2k0fI0FrNxv21RDFfXcO8GvR5Knt+DOQjTyzqcVPhR6PPnKu YBJXQSMAFzaNEGNhJ8/sZaJIqQ1KBzc3OyypO4ZFZjJNL+nTnhz6BVVvfqZGGqr4sSzS e/v5IGfc3tDEwseBz9LldtKCfAiaUEwy2Vt6HPDDCQ4xgTZ52l+GcUJs+loTEnaN+cHr cHELw0GcNM0tggzcjYY2ljmW2z076LvAsDX+2q53S47b/mQ+OLJm3Ng1ndkxgRxY4qV4 aLtVe4hW5NNerxrcxiXuoWRJm5QyRYDLKjopod9B0SiuDjYXPUGk1mmJGAuEA0jrqWc4 ia9g== X-Gm-Message-State: AOAM530Y5QaMHBLeLutSTCJs3QFBVUa4DuZnjDmX0dc9/Gj4lrkrop2g SovZjGIc0dR3+vNapRDI0kVyfw== X-Google-Smtp-Source: ABdhPJw7tGBumAzkMbsznaxaXFQcycez6QVQ8esQCZu5MaJ/vujTzQ+/xlrWfTsfrdeSDOgpzQi07Q== X-Received: by 2002:a65:690e:: with SMTP id s14mr10637219pgq.302.1610178300076; Fri, 08 Jan 2021 23:45:00 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id f64sm11488855pfb.146.2021.01.08.23.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:44:59 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , 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-kernel@vger.kernel.org Cc: Al Grant , Leo Yan Subject: [PATCH v1 2/7] perf cs_etm: Use pid tracing explicitly instead of contextid Date: Sat, 9 Jan 2021 15:44:30 +0800 Message-Id: <20210109074435.626855-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-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 the task is exposed via VMID instead of the CONTEXTID. Add support for this in the perf tool. By default the perf tool requests contextid and timestamp for task bound events. Instead of hard coding contextid, switch to "pid" config exposed by the kernel. While at it, define new independent macros (rather than using the "config" bits) for requesting the "pid" and "timestamp" for cs_etm_set_option(), since the PID config is now dynamic depending on the kernel exception level. Cc: Mike Leach Cc: Mathieu Poirier Cc: Al Grant Signed-off-by: Suzuki K Poulose Signed-off-by: Leo Yan --- tools/include/linux/coresight-pmu.h | 11 +++-- tools/perf/arch/arm/util/cs-etm.c | 68 ++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h index b0e35eec6499..927c6285ce5d 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -11,16 +11,19 @@ #define CORESIGHT_ETM_PMU_SEED 0x10 /* ETMv3.5/PTM's ETMCR config bit */ -#define ETM_OPT_CYCACC 12 -#define ETM_OPT_CTXTID 14 -#define ETM_OPT_TS 28 -#define ETM_OPT_RETSTK 29 +#define ETM_OPT_CYCACC 12 +#define ETM_OPT_CTXTID 14 +#define ETM_OPT_CTXTID_IN_VMID 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 cad7bf783413..fad7b6e13ccc 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -59,14 +59,15 @@ static const char *metadata_etmv4_ro[CS_ETMV4_PRIV_MAX] = { static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu); -static int cs_etm_set_context_id(struct auxtrace_record *itr, - struct evsel *evsel, int cpu) +static int cs_etm_set_pid(struct auxtrace_record *itr, + struct evsel *evsel, int cpu) { struct cs_etm_recording *ptr; struct perf_pmu *cs_etm_pmu; char path[PATH_MAX]; int err = -EINVAL; u32 val; + u64 pid_fmt; ptr = container_of(itr, struct cs_etm_recording, itr); cs_etm_pmu = ptr->cs_etm_pmu; @@ -86,21 +87,50 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, goto out; } + pid_fmt = perf_pmu__format_bits(&cs_etm_pmu->format, "pid"); /* - * 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 the kernel doesn't support the "pid" format (older kernel), + * fall back to using the CTXTID. */ - val = BMVAL(val, 5, 9); - if (!val || val != 0x4) { + if (!pid_fmt) + pid_fmt = 1ULL << ETM_OPT_CTXTID; + + switch (pid_fmt) { + case (1ULL << 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) { + err = -EINVAL; + goto out; + } + break; + case (1ULL << ETM_OPT_CTXTID_IN_VMID): + /* + * 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) { + err = -EINVAL; + goto out; + } + break; + default: err = -EINVAL; goto out; } + /* All good, let the kernel know */ - evsel->core.attr.config |= (1 << ETM_OPT_CTXTID); + evsel->core.attr.config |= pid_fmt; err = 0; out: @@ -156,6 +186,10 @@ static int cs_etm_set_timestamp(struct auxtrace_record *itr, return err; } +#define ETM_SET_OPT_PID (1 << 0) +#define ETM_SET_OPT_TS (1 << 1) +#define ETM_SET_OPT_MASK (ETM_SET_OPT_PID | ETM_SET_OPT_TS) + static int cs_etm_set_option(struct auxtrace_record *itr, struct evsel *evsel, u32 option) { @@ -169,17 +203,17 @@ static int cs_etm_set_option(struct auxtrace_record *itr, !cpu_map__has(online_cpus, i)) continue; - if (option & ETM_OPT_CTXTID) { - err = cs_etm_set_context_id(itr, evsel, i); + if (option & ETM_SET_OPT_PID) { + err = cs_etm_set_pid(itr, evsel, i); if (err) goto out; } - if (option & ETM_OPT_TS) { + if (option & ETM_SET_OPT_TS) { err = cs_etm_set_timestamp(itr, evsel, i); if (err) goto out; } - if (option & ~(ETM_OPT_CTXTID | ETM_OPT_TS)) + if (option & ~(ETM_SET_OPT_MASK)) /* Nothing else is currently supported */ goto out; } @@ -406,7 +440,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evsel__set_sample_bit(cs_etm_evsel, CPU); err = cs_etm_set_option(itr, cs_etm_evsel, - ETM_OPT_CTXTID | ETM_OPT_TS); + ETM_SET_OPT_PID | ETM_SET_OPT_TS); if (err) goto out; } @@ -485,7 +519,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_CTXTID_IN_VMID)) + config |= BIT(ETM4_CFG_BIT_VMID) | + BIT(ETM4_CFG_BIT_VMID_OPT); return config; } -- 2.25.1 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=-17.0 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=unavailable 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 D0251C433DB for ; Sat, 9 Jan 2021 07:46:53 +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 60AD023A5B for ; Sat, 9 Jan 2021 07:46:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60AD023A5B 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=fcgCqzopleqyiXTViLaCC2TDqYqU9E+A77CskDUz2SU=; b=hbTFF4FEfYiNgsyyrN5gDSS+t 7S8OUEb8UFJxhGGnhk+O18XwUU4JZAyExETLQ7B4DhFvTdc1AJrn1X2IkKtCW6B0iZnEjd+egl7Va 3FaLZVWvXgTuS396kbPKxqtCy2Mg6lygBysymMOAm02e5GhAvtAsIwpQ1dfbOAfqbfkGsbjv+kIsi rPGhuOpwkJYuixelBjlJJccWwtLAvTfawf2wmh9aAOHoWqFqdAmMf3O/DyAwLialBM3GDbdRw9E4x vAcsGd8QIQnnURYTi11FtHN6yTkBaXPwwip6IywGN1tIvKGQdZQg6h8wHjkxKw4wDgc0zw36bXcK3 Nta+TLsjA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vt-0008WO-Fj; Sat, 09 Jan 2021 07:45:09 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ky8vl-0008Tl-Ob for linux-arm-kernel@lists.infradead.org; Sat, 09 Jan 2021 07:45:04 +0000 Received: by mail-pf1-x434.google.com with SMTP id h10so7725433pfo.9 for ; Fri, 08 Jan 2021 23:45:01 -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=nQMCubmgzlrRTa03+kmNvTwcrwNhs1nXf3jbRihBgmo=; b=JPQAm8mKkZrg0ceXulqBGIaytFxCQsnVgLuM6fuf2yKXNydlAgB1ORNGeDTtV6oIno 9Hi/KbJ4PBf332SxeI624u1oirZIHqJmRSVgyaHl+BBXrdJ31L6cPGfjCBdpaoawGbB6 y9uSL/y9E4WyBKE1iXJKoXvYaLPuR8EfS4IDpU0DwBLIMtr8HzSlHxKv6E26BF+IhNEG NBhY4THkePFvw7ceywId+66QiJy36rnaXz3Zjm7YBm8BIbKM59HxqGuM25qBJ31viZYP ZQFtREygT/82YmF7d5dNOexb6baO+YyMaofc6iARj3qm5ox8ICWyizMYQN7b8803TxgQ dQQw== 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=nQMCubmgzlrRTa03+kmNvTwcrwNhs1nXf3jbRihBgmo=; b=lyN6q/fq0oCx3+rvFCu9e9ZrPV5zAmPnPtKbScj1E3N4v3PFID0vbXVhQKsuSMqMKu TftvW2rKeZ++5TMNknZMIPFZy9lnMRpJ6+bLGmL0wdkL3Q5tJ1vrj0u/DDqLJW683lD/ Vhj81IZ81+bUcaS0e4DFD1rFNBLmu4awT+n/X7gsNv2JJN7ZgXJ2hV0qTX8m3PqMxyYP hLByalSGNN2hUMaM6hU1f2XcWfgQGnpi+dp1V1n8SAUqtmmPFcMHduwEl8JZZqhyvonn w8lLonFNQlJRMpUXcuJOLGRgiMxH0gp9adIao8pJNQZPgFLB8TR3AzRyIp4WX7jNnrcO Px3A== X-Gm-Message-State: AOAM532e6ppYzatvhIunthXaQt2Fbenb2Q9axNE9M9BUoK4VAFziYQcw HN40mZAMxXrmtbVbBNFrLS+T0Q== X-Google-Smtp-Source: ABdhPJw7tGBumAzkMbsznaxaXFQcycez6QVQ8esQCZu5MaJ/vujTzQ+/xlrWfTsfrdeSDOgpzQi07Q== X-Received: by 2002:a65:690e:: with SMTP id s14mr10637219pgq.302.1610178300076; Fri, 08 Jan 2021 23:45:00 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id f64sm11488855pfb.146.2021.01.08.23.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 23:44:59 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , 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-kernel@vger.kernel.org Subject: [PATCH v1 2/7] perf cs_etm: Use pid tracing explicitly instead of contextid Date: Sat, 9 Jan 2021 15:44:30 +0800 Message-Id: <20210109074435.626855-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109074435.626855-1-leo.yan@linaro.org> References: <20210109074435.626855-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-20210109_024501_948899_31A4D144 X-CRM114-Status: GOOD ( 23.65 ) 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 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 From: Suzuki K Poulose If the kernel is running at EL2, the pid of the task is exposed via VMID instead of the CONTEXTID. Add support for this in the perf tool. By default the perf tool requests contextid and timestamp for task bound events. Instead of hard coding contextid, switch to "pid" config exposed by the kernel. While at it, define new independent macros (rather than using the "config" bits) for requesting the "pid" and "timestamp" for cs_etm_set_option(), since the PID config is now dynamic depending on the kernel exception level. Cc: Mike Leach Cc: Mathieu Poirier Cc: Al Grant Signed-off-by: Suzuki K Poulose Signed-off-by: Leo Yan --- tools/include/linux/coresight-pmu.h | 11 +++-- tools/perf/arch/arm/util/cs-etm.c | 68 ++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h index b0e35eec6499..927c6285ce5d 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -11,16 +11,19 @@ #define CORESIGHT_ETM_PMU_SEED 0x10 /* ETMv3.5/PTM's ETMCR config bit */ -#define ETM_OPT_CYCACC 12 -#define ETM_OPT_CTXTID 14 -#define ETM_OPT_TS 28 -#define ETM_OPT_RETSTK 29 +#define ETM_OPT_CYCACC 12 +#define ETM_OPT_CTXTID 14 +#define ETM_OPT_CTXTID_IN_VMID 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 cad7bf783413..fad7b6e13ccc 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -59,14 +59,15 @@ static const char *metadata_etmv4_ro[CS_ETMV4_PRIV_MAX] = { static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu); -static int cs_etm_set_context_id(struct auxtrace_record *itr, - struct evsel *evsel, int cpu) +static int cs_etm_set_pid(struct auxtrace_record *itr, + struct evsel *evsel, int cpu) { struct cs_etm_recording *ptr; struct perf_pmu *cs_etm_pmu; char path[PATH_MAX]; int err = -EINVAL; u32 val; + u64 pid_fmt; ptr = container_of(itr, struct cs_etm_recording, itr); cs_etm_pmu = ptr->cs_etm_pmu; @@ -86,21 +87,50 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, goto out; } + pid_fmt = perf_pmu__format_bits(&cs_etm_pmu->format, "pid"); /* - * 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 the kernel doesn't support the "pid" format (older kernel), + * fall back to using the CTXTID. */ - val = BMVAL(val, 5, 9); - if (!val || val != 0x4) { + if (!pid_fmt) + pid_fmt = 1ULL << ETM_OPT_CTXTID; + + switch (pid_fmt) { + case (1ULL << 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) { + err = -EINVAL; + goto out; + } + break; + case (1ULL << ETM_OPT_CTXTID_IN_VMID): + /* + * 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) { + err = -EINVAL; + goto out; + } + break; + default: err = -EINVAL; goto out; } + /* All good, let the kernel know */ - evsel->core.attr.config |= (1 << ETM_OPT_CTXTID); + evsel->core.attr.config |= pid_fmt; err = 0; out: @@ -156,6 +186,10 @@ static int cs_etm_set_timestamp(struct auxtrace_record *itr, return err; } +#define ETM_SET_OPT_PID (1 << 0) +#define ETM_SET_OPT_TS (1 << 1) +#define ETM_SET_OPT_MASK (ETM_SET_OPT_PID | ETM_SET_OPT_TS) + static int cs_etm_set_option(struct auxtrace_record *itr, struct evsel *evsel, u32 option) { @@ -169,17 +203,17 @@ static int cs_etm_set_option(struct auxtrace_record *itr, !cpu_map__has(online_cpus, i)) continue; - if (option & ETM_OPT_CTXTID) { - err = cs_etm_set_context_id(itr, evsel, i); + if (option & ETM_SET_OPT_PID) { + err = cs_etm_set_pid(itr, evsel, i); if (err) goto out; } - if (option & ETM_OPT_TS) { + if (option & ETM_SET_OPT_TS) { err = cs_etm_set_timestamp(itr, evsel, i); if (err) goto out; } - if (option & ~(ETM_OPT_CTXTID | ETM_OPT_TS)) + if (option & ~(ETM_SET_OPT_MASK)) /* Nothing else is currently supported */ goto out; } @@ -406,7 +440,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evsel__set_sample_bit(cs_etm_evsel, CPU); err = cs_etm_set_option(itr, cs_etm_evsel, - ETM_OPT_CTXTID | ETM_OPT_TS); + ETM_SET_OPT_PID | ETM_SET_OPT_TS); if (err) goto out; } @@ -485,7 +519,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_CTXTID_IN_VMID)) + config |= BIT(ETM4_CFG_BIT_VMID) | + BIT(ETM4_CFG_BIT_VMID_OPT); return config; } -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel