Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2609513rwi; Tue, 1 Nov 2022 09:35:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM650KAwNwbN1iWYZOVjlRtlO4680mfH7AFVf1WpE8qOqmG75oz641bGSeosGSw8nsQet3xL X-Received: by 2002:a05:6402:1052:b0:459:2c49:1aed with SMTP id e18-20020a056402105200b004592c491aedmr19696197edu.212.1667320508982; Tue, 01 Nov 2022 09:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667320508; cv=none; d=google.com; s=arc-20160816; b=Y/nfr3U4zcZnI++PChoS4x/MX465NDdIJwyO1P5T6aCwDmjPD1Jy64Hdm4dA2rLrWU 2QkMM7SWPb2l+CA5T0dyuUIIht1TFhWJJxs9hl7AgPEYBeq5osr5R4aj6hs06apOAeoa 4w3LYMkRZRJJJSr1uLYu6JzNutY5LGYitqOFE8b1xAmOad8uzHsCFJ5+PiSDSij7DTVS 0k9yESg3EeYv5xo5Dyu7PMLjomxa6iy99v+FGLAlRM03/0IAcOd2MaekZfyOnvJedkec C7bm40U/jAy/PyvVYJ0hljJKFPpo38qDmw9LrI0nrIVel7g9/FP1SPh3Qk5gb+GzDJ2/ 4U6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=AZXktW+Z8HgOtdq+KcdLQaKYvh8MjYbaciOiUrNcWBY=; b=oMHp0fQNN1Oue8pIqA3YtdT/e+eDKa1kNLYASn0uKNi/cWveWZr+S9+AdrOVmNPtkP 5LImgZaEoUscW3q7k8QuUw0xHIJcNFi6iMlRsahwClu+RaCBXyy6Fn5y69kmMrvhZSaZ VLHarl4y1yEyKfjYstIT9CgJfq/8uA2Hv3WB1moEX/zjVC+Hbi4TXNGriurdglR+Xkkd 4TAy4hkyp4+nSM9feRkRfCmtbQ9Gt+aaudddkopHKpqaL0VKWtbnBQY3A3HPRITI9RE4 WnfBDKUUcCW2PY8jTZ8N3Nfsdhu2IQMOrzm5KiCEZouVwR/XrI33PfCrBdcdQmM/zfM4 WxhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="y/WHtqmw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a1709064fc600b00791a3dd01b1si13636975ejw.865.2022.11.01.09.34.44; Tue, 01 Nov 2022 09:35:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="y/WHtqmw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230185AbiKAQcP (ORCPT + 97 others); Tue, 1 Nov 2022 12:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230251AbiKAQbf (ORCPT ); Tue, 1 Nov 2022 12:31:35 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7BE1CB34 for ; Tue, 1 Nov 2022 09:31:34 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id r186-20020a1c44c3000000b003cf4d389c41so10319342wma.3 for ; Tue, 01 Nov 2022 09:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=AZXktW+Z8HgOtdq+KcdLQaKYvh8MjYbaciOiUrNcWBY=; b=y/WHtqmwqUSRRUWTPOeolXh5OdHRKuCOEewV8aU6izC8X5YsDPUmig+fXS/nNnJh/v f9coX6/5md87p8kd+HvQ5Um1o/jbsNOW0H7ficH0WUXkJ2VIRsNqcJcNbvTsJuoNgvln yBvsQSJLOrvmWp58rES93HnVn35A3ehSFm5fvR53CD6mz/oz/cMhpPATyr/bYsjlyRoG DxJVwtSOv5A7ixRIWk2YUKmKgyADKQwP6VP6cXLCozgncvdhFxDAth7zYHnmvo51g5zI 51KtIJ2z3rP0LGaigTo10tI9KWS5AKm9d65z8oUv+3QbHrhl/7GG4s2xvQqsh/sjMQC7 4qVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AZXktW+Z8HgOtdq+KcdLQaKYvh8MjYbaciOiUrNcWBY=; b=gTKScfz0oNLYtmhAX+ExBJhPUiRUdVdtkw8oeHnxn8x5U43EmqTaH65CkPJI4OQEp+ hsOHrntl8nukhcmc/j+vbQMVJmZleoAX887EB7Ky/Ozsk00Xp8JLdtm3UahpqKdSDii6 CdWMKvSGuZBktR2moqEdOL4EWcaDT8s1lUVi/OirUGSGoGj1cw3hO6NOXHUGjw451Yfx 5AXjFMQaXnLUAROApVHpismfWVQDn34HEyILKyR1+1wtUrBHxjXMXkIRR2ArRuhZU6A/ wBAA6SIPQ9+A0dh80IDwgfgQdK+Asz6K9U3ooZOPfoTceTSEsYmR4SlejUqbu007qaYc OwGg== X-Gm-Message-State: ACrzQf3RF4kq1tAR+r6Dt7JmrBeRypK+PSFrQJMZ/81Lh5IYWYkKVWIT cye+NhljgCdGwhzNa23Q9FPNkQ== X-Received: by 2002:a7b:c8d8:0:b0:3cf:691a:c4b3 with SMTP id f24-20020a7bc8d8000000b003cf691ac4b3mr11095235wml.120.1667320292597; Tue, 01 Nov 2022 09:31:32 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:e844:18b6:fc5:bbc9]) by smtp.gmail.com with ESMTPSA id bu15-20020a056000078f00b0022ac1be009esm8339844wrb.16.2022.11.01.09.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 09:31:32 -0700 (PDT) From: Mike Leach To: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, linux-perf-users@vger.kernel.org, leo.yan@linaro.org, quic_jinlmao@quicinc.com, Mike Leach Subject: [PATCH v5 10/14] perf: cs-etm: Update record event to use new Trace ID protocol Date: Tue, 1 Nov 2022 16:30:59 +0000 Message-Id: <20221101163103.17921-11-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221101163103.17921-1-mike.leach@linaro.org> References: <20221101163103.17921-1-mike.leach@linaro.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Trace IDs are now dynamically allocated. Previously used the static association algorithm that is no longer used. The 'cpu * 2 + seed' was outdated and broken for systems with high core counts (>46). as it did not scale and was broken for larger core counts. Trace ID will now be sent in PERF_RECORD_AUX_OUTPUT_HW_ID record. Legacy ID algorithm renamed and retained for limited backward compatibility use. Signed-off-by: Mike Leach Reviewed-by: James Clark --- tools/include/linux/coresight-pmu.h | 30 +++++++++++++++++------------ tools/perf/arch/arm/util/cs-etm.c | 21 ++++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h index db9c7c0abb6a..307f357defe9 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -10,11 +10,28 @@ #include #define CORESIGHT_ETM_PMU_NAME "cs_etm" -#define CORESIGHT_ETM_PMU_SEED 0x10 + +/* + * The legacy Trace ID system based on fixed calculation from the cpu + * number. This has been replaced by drivers using a dynamic allocation + * system - but need to retain the legacy algorithm for backward comparibility + * in certain situations:- + * a) new perf running on older systems that generate the legacy mapping + * b) older tools e.g. simpleperf in Android, that may not update at the same + * time as the kernel. + */ +#define CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) (0x10 + (cpu * 2)) /* CoreSight trace ID is currently the bottom 7 bits of the value */ #define CORESIGHT_TRACE_ID_VAL_MASK GENMASK(6, 0) +/* + * perf record will set the legacy meta data values as unused initially. + * This allows perf report to manage the decoders created when dynamic + * allocation in operation. + */ +#define CORESIGHT_TRACE_ID_UNUSED_FLAG BIT(31) + /* * Below are the definition of bit offsets for perf option, and works as * arbitrary values for all ETM versions. @@ -39,15 +56,4 @@ #define ETM4_CFG_BIT_RETSTK 12 #define ETM4_CFG_BIT_VMID_OPT 15 -static inline int coresight_get_trace_id(int cpu) -{ - /* - * A trace ID of value 0 is invalid, so let's start at some - * random value that fits in 7 bits and go from there. Since - * the common convention is to have data trace IDs be I(N) + 1, - * set instruction trace IDs as a function of the CPU number. - */ - return (CORESIGHT_ETM_PMU_SEED + (cpu * 2)); -} - #endif diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index a346d5f3dafa..c7e4b543259f 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -421,13 +421,16 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evlist__to_front(evlist, cs_etm_evsel); /* - * In the case of per-cpu mmaps, we need the CPU on the - * AUX event. We also need the contextID in order to be notified + * get the CPU on the sample - need it to associate trace ID in the + * AUX_OUTPUT_HW_ID event, and the AUX event for per-cpu mmaps. + */ + evsel__set_sample_bit(cs_etm_evsel, CPU); + + /* + * Also the case of per-cpu mmaps, need the contextID in order to be notified * when a context switch happened. */ if (!perf_cpu_map__empty(cpus)) { - evsel__set_sample_bit(cs_etm_evsel, CPU); - err = cs_etm_set_option(itr, cs_etm_evsel, BIT(ETM_OPT_CTXTID) | BIT(ETM_OPT_TS)); if (err) @@ -633,8 +636,10 @@ static void cs_etm_save_etmv4_header(__u64 data[], struct auxtrace_record *itr, /* Get trace configuration register */ data[CS_ETMV4_TRCCONFIGR] = cs_etmv4_get_config(itr); - /* Get traceID from the framework */ - data[CS_ETMV4_TRCTRACEIDR] = coresight_get_trace_id(cpu); + /* traceID set to legacy version, in case new perf running on older system */ + data[CS_ETMV4_TRCTRACEIDR] = + CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) | CORESIGHT_TRACE_ID_UNUSED_FLAG; + /* Get read-only information from sysFS */ data[CS_ETMV4_TRCIDR0] = cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]); @@ -681,9 +686,9 @@ static void cs_etm_get_metadata(int cpu, u32 *offset, magic = __perf_cs_etmv3_magic; /* Get configuration register */ info->priv[*offset + CS_ETM_ETMCR] = cs_etm_get_config(itr); - /* Get traceID from the framework */ + /* traceID set to legacy value in case new perf running on old system */ info->priv[*offset + CS_ETM_ETMTRACEIDR] = - coresight_get_trace_id(cpu); + CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) | CORESIGHT_TRACE_ID_UNUSED_FLAG; /* Get read-only information from sysFS */ info->priv[*offset + CS_ETM_ETMCCER] = cs_etm_get_ro(cs_etm_pmu, cpu, -- 2.17.1