From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49EB916C69F for ; Mon, 22 Jul 2024 10:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643157; cv=none; b=OHrvB0pDJ/HuR/sbUbQfx4Iq0qVhu2EEwEdrJwfgsgWhMK0Ktj7KZquDj1M9Rcbqb2JN5hfjMCpWoGgO3KieOdUy/pgNH9QMn1OsmFb9gY4Uqphd89P1YboWSPwCsQkCj2pZ09C9VAntNXYblq6g1LZzZ+qclyBMWlpnFw3QqFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643157; c=relaxed/simple; bh=XeU7uc51VL1zsILLK6kLUUVloKBlqoaBEaJ7Wx1vd9E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bf/GmzOt3In+1Aa0aGfpqG7gdmBrfkhw0bcgWIpRtKgH1r6qNREq9hva94tHPscW1WFq3fSuPKG3hyYJcJO/1Qc9UqYaTYft4e2fwAapao3WCrG91J1g8n1irEOGauJXP0Ad7KqMUmz2PnbA3IGPUnpihyA2RKGLlGgi/mrJPCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Db5/22YI; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Db5/22YI" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-368313809a4so1758762f8f.0 for ; Mon, 22 Jul 2024 03:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643154; x=1722247954; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XkQSmEJS+t8PI7d2qYJdf6z1Fx7Gi/uVI/oujEUZvqI=; b=Db5/22YIDmyyFll5JMZSA2Tp+AGh6m/RbPGdFe3OQ+4pq1BjDLTOftpOMDrWz3bxE2 HLova01yXoXs6kP+t/1ZQLbU5Sfb0ZenfgLzCun33dkJwQHmh3fHhpytdpuUEcshfGwG JDfhOE1temLwM2/dTQtMT9ZLZHQ1jPcFbzmwW3O26UZxvCw9wqtVGxwbp6nJiRME7Iea 1ZbpLy6JzRlzdmodOK0ukZ43MF2QWZhV0okOOc2UrEQ3JvzF50K6pnyg1N3uWKO9u02r aQrdZdi2zKGPObi9QYYcmDQXk7fo7CBZGL0Eo76BCsOoM+Hfq8vMxzRupkyJryaRlseV t86A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643154; x=1722247954; h=content-transfer-encoding:mime-version: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=XkQSmEJS+t8PI7d2qYJdf6z1Fx7Gi/uVI/oujEUZvqI=; b=CW4h5jENSKg6SezVj0MYVA2fa5V9WtYZmGw6LKeW6lnABXLEcXBgq4mtt1l5nyEe0P WStWA89B1GOpPWgTIs6wUrZUrAs40XoM3yiy7Mor0vb0JTKPBfxf+QTn18RKxb+nkJh3 40arFYZYtG20h3efpwef0KK9bVyOMwQwNpf9oU5wHt17s04Ql+maaK6qNgWr29PC/+Ri 39FcaB/b0+N9E/iDqIP0yXH1YB/hO+YU5yefsPNHbHzlCAKtaKDXPQP+xiagFlmGT814 ChNlAurlmG7bg7x5eMLig1RMfSOJKnrmfk7PrtYRfBSYEHq9PzTjM8eRac45H/u/zdxm gJDQ== X-Forwarded-Encrypted: i=1; AJvYcCW3xjJVg4Co1f1Vep/yibQz/UiRBxNB5g9G25IxZoXtqwY8V9F+hIfcm5TULGQbZQxI7oShp6tX3pQbX+8s9Yvqv/F1wpIdNL8g8jtq X-Gm-Message-State: AOJu0YzW6ED2j+AQw4tbZW7HroFV+xd5ggCApg6jySWxzq9EfIQb/cDY 17tXEhF+aq2uK4KlG74rG0Jx4sYQUtsQazl6KnGWYRMOCLAE6bBf8lsS+8Wl4Q8= X-Google-Smtp-Source: AGHT+IHaH2YPtNhqmGIdGUn2Rz8Y3/TRQlQzrPvH5PCPU/tFrburbnXfon+bZ/y+MdEK0Yaa82czPQ== X-Received: by 2002:adf:f34c:0:b0:363:337a:3e0 with SMTP id ffacd0b85a97d-36873dc1f2dmr6268468f8f.1.1721643153600; Mon, 22 Jul 2024 03:12:33 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:12:33 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 01/17] perf: cs-etm: Create decoders after both AUX and HW_ID search passes Date: Mon, 22 Jul 2024 11:11:43 +0100 Message-Id: <20240722101202.26915-2-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark Both of these passes gather information about how to create the decoders. AUX records determine formatted/unformatted, and the HW_IDs determine the traceID/metadata mappings. Therefore it makes sense to cache the information and wait until both passes are over until creating the decoders, rather than creating them at the first HW_ID found. This will allow a simplification of the creation process where cs_etm_queue->traceid_list will exclusively used to create the decoders, rather than the current two methods depending on whether the trace is formatted or not. Previously the sample CPU from the AUX record was used to initialize the decoder CPU, but actually sample CPU =3D=3D AUX queue index in per-CPU mode, so saving the sample CPU isn't required. Similarly formatted/unformatted was used upfront to create the decoders, but now it's cached until later. Signed-off-by: James Clark Reviewed-by: Mike Leach Tested-by: Leo Yan Reviewed-by: Anshuman Khandual Tested-by: Ganapatrao Kulkarni Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- tools/perf/util/cs-etm.c | 182 ++++++++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 69 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 32818bd7cd17..f4a378cb66f6 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -97,12 +97,19 @@ struct cs_etm_traceid_queue { struct cs_etm_packet_queue packet_queue; }; =20 +enum cs_etm_format { + UNSET, + FORMATTED, + UNFORMATTED +}; + struct cs_etm_queue { struct cs_etm_auxtrace *etm; struct cs_etm_decoder *decoder; struct auxtrace_buffer *buffer; unsigned int queue_nr; u8 pending_timestamp_chan_id; + enum cs_etm_format format; u64 offset; const unsigned char *buf; size_t buf_len, buf_used; @@ -696,7 +703,7 @@ static void cs_etm__set_trace_param_ete(struct cs_etm_t= race_params *t_params, =20 static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params, struct cs_etm_auxtrace *etm, - bool formatted, + enum cs_etm_format format, int sample_cpu, int decoders) { @@ -705,7 +712,7 @@ static int cs_etm__init_trace_params(struct cs_etm_trac= e_params *t_params, u64 architecture; =20 for (t_idx =3D 0; t_idx < decoders; t_idx++) { - if (formatted) + if (format =3D=3D FORMATTED) m_idx =3D t_idx; else { m_idx =3D get_cpu_data_idx(etm, sample_cpu); @@ -738,8 +745,7 @@ static int cs_etm__init_trace_params(struct cs_etm_trac= e_params *t_params, =20 static int cs_etm__init_decoder_params(struct cs_etm_decoder_params *d_par= ams, struct cs_etm_queue *etmq, - enum cs_etm_decoder_operation mode, - bool formatted) + enum cs_etm_decoder_operation mode) { int ret =3D -EINVAL; =20 @@ -749,7 +755,7 @@ static int cs_etm__init_decoder_params(struct cs_etm_de= coder_params *d_params, d_params->packet_printer =3D cs_etm__packet_dump; d_params->operation =3D mode; d_params->data =3D etmq; - d_params->formatted =3D formatted; + d_params->formatted =3D etmq->format =3D=3D FORMATTED; d_params->fsyncs =3D false; d_params->hsyncs =3D false; d_params->frame_aligned =3D true; @@ -1041,81 +1047,34 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *= etmq, u8 trace_chan_id, return ret; } =20 -static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *et= m, - bool formatted, int sample_cpu) +static struct cs_etm_queue *cs_etm__alloc_queue(void) { - struct cs_etm_decoder_params d_params; - struct cs_etm_trace_params *t_params =3D NULL; - struct cs_etm_queue *etmq; - /* - * Each queue can only contain data from one CPU when unformatted, so onl= y one decoder is - * needed. - */ - int decoders =3D formatted ? etm->num_cpu : 1; - - etmq =3D zalloc(sizeof(*etmq)); + struct cs_etm_queue *etmq =3D zalloc(sizeof(*etmq)); if (!etmq) return NULL; =20 etmq->traceid_queues_list =3D intlist__new(NULL); if (!etmq->traceid_queues_list) - goto out_free; - - /* Use metadata to fill in trace parameters for trace decoder */ - t_params =3D zalloc(sizeof(*t_params) * decoders); - - if (!t_params) - goto out_free; - - if (cs_etm__init_trace_params(t_params, etm, formatted, sample_cpu, decod= ers)) - goto out_free; - - /* Set decoder parameters to decode trace packets */ - if (cs_etm__init_decoder_params(&d_params, etmq, - dump_trace ? CS_ETM_OPERATION_PRINT : - CS_ETM_OPERATION_DECODE, - formatted)) - goto out_free; - - etmq->decoder =3D cs_etm_decoder__new(decoders, &d_params, - t_params); - - if (!etmq->decoder) - goto out_free; - - /* - * Register a function to handle all memory accesses required by - * the trace decoder library. - */ - if (cs_etm_decoder__add_mem_access_cb(etmq->decoder, - 0x0L, ((u64) -1L), - cs_etm__mem_access)) - goto out_free_decoder; + free(etmq); =20 - zfree(&t_params); return etmq; - -out_free_decoder: - cs_etm_decoder__free(etmq->decoder); -out_free: - intlist__delete(etmq->traceid_queues_list); - free(etmq); - - return NULL; } =20 static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, struct auxtrace_queue *queue, - unsigned int queue_nr, - bool formatted, - int sample_cpu) + unsigned int queue_nr, enum cs_etm_format format) { struct cs_etm_queue *etmq =3D queue->priv; =20 + if (etmq && format !=3D etmq->format) { + pr_err("CS_ETM: mixed formatted and unformatted trace not supported\n"); + return -EINVAL; + } + if (list_empty(&queue->head) || etmq) return 0; =20 - etmq =3D cs_etm__alloc_queue(etm, formatted, sample_cpu); + etmq =3D cs_etm__alloc_queue(); =20 if (!etmq) return -ENOMEM; @@ -1123,7 +1082,9 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace= *etm, queue->priv =3D etmq; etmq->etm =3D etm; etmq->queue_nr =3D queue_nr; + queue->cpu =3D queue_nr; /* Placeholder, may be reset to -1 in per-thread= mode */ etmq->offset =3D 0; + etmq->format =3D format; =20 return 0; } @@ -2843,7 +2804,7 @@ static int cs_etm__process_auxtrace_event(struct perf= _session *session, * formatted in piped mode (true). */ err =3D cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], - idx, true, -1); + idx, FORMATTED); if (err) return err; =20 @@ -2964,7 +2925,7 @@ static int cs_etm__queue_aux_fragment(struct perf_ses= sion *session, off_t file_o union perf_event auxtrace_fragment; __u64 aux_offset, aux_size; __u32 idx; - bool formatted; + enum cs_etm_format format; =20 struct cs_etm_auxtrace *etm =3D container_of(session->auxtrace, struct cs_etm_auxtrace, @@ -3047,9 +3008,10 @@ static int cs_etm__queue_aux_fragment(struct perf_se= ssion *session, off_t file_o return err; =20 idx =3D auxtrace_event->idx; - formatted =3D !(aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW); - return cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], - idx, formatted, sample->cpu); + format =3D (aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW) ? + UNFORMATTED : FORMATTED; + + return cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], idx, form= at); } =20 /* Wasn't inside this buffer, but there were no parse errors. 1 =3D=3D 'n= ot found' */ @@ -3233,6 +3195,84 @@ static int cs_etm__clear_unused_trace_ids_metadata(i= nt num_cpu, u64 **metadata) return 0; } =20 +/* + * Use the data gathered by the peeks for HW_ID (trace ID mappings) and AUX + * (formatted or not) packets to create the decoders. + */ +static int cs_etm__create_queue_decoders(struct cs_etm_queue *etmq) +{ + struct cs_etm_decoder_params d_params; + + /* + * Each queue can only contain data from one CPU when unformatted, so onl= y one decoder is + * needed. + */ + int decoders =3D etmq->format =3D=3D FORMATTED ? etmq->etm->num_cpu : 1; + + /* Use metadata to fill in trace parameters for trace decoder */ + struct cs_etm_trace_params *t_params =3D zalloc(sizeof(*t_params) * deco= ders); + + if (!t_params) + goto out_free; + + if (cs_etm__init_trace_params(t_params, etmq->etm, etmq->format, + etmq->queue_nr, decoders)) + goto out_free; + + /* Set decoder parameters to decode trace packets */ + if (cs_etm__init_decoder_params(&d_params, etmq, + dump_trace ? CS_ETM_OPERATION_PRINT : + CS_ETM_OPERATION_DECODE)) + goto out_free; + + etmq->decoder =3D cs_etm_decoder__new(decoders, &d_params, + t_params); + + if (!etmq->decoder) + goto out_free; + + /* + * Register a function to handle all memory accesses required by + * the trace decoder library. + */ + if (cs_etm_decoder__add_mem_access_cb(etmq->decoder, + 0x0L, ((u64) -1L), + cs_etm__mem_access)) + goto out_free_decoder; + + zfree(&t_params); + return 0; + +out_free_decoder: + cs_etm_decoder__free(etmq->decoder); +out_free: + zfree(&t_params); + return -EINVAL; +} + +static int cs_etm__create_decoders(struct cs_etm_auxtrace *etm) +{ + struct auxtrace_queues *queues =3D &etm->queues; + + for (unsigned int i =3D 0; i < queues->nr_queues; i++) { + bool empty =3D list_empty(&queues->queue_array[i].head); + struct cs_etm_queue *etmq =3D queues->queue_array[i].priv; + int ret; + + /* + * Don't create decoders for empty queues, mainly because + * etmq->format is unknown for empty queues. + */ + if (empty) + continue; + + ret =3D cs_etm__create_queue_decoders(etmq); + if (ret) + return ret; + } + return 0; +} + int cs_etm__process_auxtrace_info_full(union perf_event *event, struct perf_session *session) { @@ -3396,6 +3436,10 @@ int cs_etm__process_auxtrace_info_full(union perf_ev= ent *event, if (err) goto err_free_queues; =20 + err =3D cs_etm__queue_aux_records(session); + if (err) + goto err_free_queues; + /* * Map Trace ID values to CPU metadata. * @@ -3418,7 +3462,7 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, * flags if present. */ =20 - /* first scan for AUX_OUTPUT_HW_ID records to map trace ID values to CPU = metadata */ + /* Scan for AUX_OUTPUT_HW_ID records to map trace ID values to CPU metada= ta */ aux_hw_id_found =3D 0; err =3D perf_session__peek_events(session, session->header.data_offset, session->header.data_size, @@ -3436,7 +3480,7 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, if (err) goto err_free_queues; =20 - err =3D cs_etm__queue_aux_records(session); + err =3D cs_etm__create_decoders(etm); if (err) goto err_free_queues; =20 --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7356416C862 for ; Mon, 22 Jul 2024 10:12:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643163; cv=none; b=FjQXIac/zHFDok+NmCTPoFOcmVgJqn6xNZh6PjA2XCX6SzYePEzdJ8zqeY37SUkZ6ZcsA8aEmFOACfDhpbxlSt4uwpjeFw0BLTqVWmoM/1oNVqV88ayFSe4dn5RBc6XRRSn89S1lDhdXWu/6qqBsNzC0CWAe4jYbr5OQXTLDz6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643163; c=relaxed/simple; bh=eRIR9xQeEVs7k6Eqc3JsCa1Z9aGiRv7GF7Hc8wdGC+M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EGjmZR0iXYXc/BC4ev5IP7oe5vchbMMkI0xTtlwUKHlRfCZewXw/SeiEH5/IfKtXr9eCVnjCnoD1cGce1CC5IsJ+kPsm8vHc6rJ4glwwYrnR6X8f45bbCSjQiJYagka5h72YbcXYv5b0AA6deItANfqWEvn4hLy7baw5/jbA5fg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=YRH/OQvq; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YRH/OQvq" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-42660b8dd27so28647975e9.3 for ; Mon, 22 Jul 2024 03:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643159; x=1722247959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9iPuIpPcZYNo1rwaMPAEpkXxIdxba4+Bjx0lIMzmeIc=; b=YRH/OQvqzRrg0IzLbsmrg5a4BOzyfe1N8Ed+f2Jj0eNxp0ZtMSvzgb6fIkOYIrugNq UhYJH3+jJj5zg1LcDBSSgUEV6y4TnGGcPVzyAng7F+Yb4h6xEGBYFuL8ipGoaEY+zMQ5 L9Nxno4Tdn5qwB1m4+dpgTyd1ZOgR/Hg9/yR0+YUkDFUw+7Gk4+rCR+kg6oOYqk/DbgO 4V5pdNndzjfx7KZf7LAkUDLIHEhpuTeYQP1k81Z93SaOJYd5bUkw/lVqfcL8hXuDqKrF 0vxx2/7NY6E3w9WFESAG/eDPz6btG66TsRx3X8evgfFmYbwo82r+RMFYUNjrtb7ByvRc Z/hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643159; x=1722247959; h=content-transfer-encoding:mime-version: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=9iPuIpPcZYNo1rwaMPAEpkXxIdxba4+Bjx0lIMzmeIc=; b=X8jT0jw1cnqLyn0EPwB3V0cx4r03R3C5rtxpYdUkpjF5IBbcN6xPem0pVjML0bcLUz PK2duz08WFjjpSFEBSS+rSp0CxQyKIG/Mbd1S6JFMdX1Uq/UhFNJi/WH/ObtKRs7OpVU CfBZ28jMYVFs+q4fwSfQ6BSkF4M2Evkh0HfjVq9bjMlipFGgRPFXUVSVO4vw86Noqd3R uvI4XbYXsH2WBO7Wi2JBYcY8+5ZAh6njT4HbA8nVd49pnMrqZWG6Z3A8JPal+APPa3Hk LfbxJ5IFg8bf0U/U0I0ORoERNKs/4Z2k/Hh7mgv1nGvef6uURt5MQNfS+bJKYNicwbbv VStg== X-Forwarded-Encrypted: i=1; AJvYcCV9/GFqYh6uW74unuVWPELZu8AvLnf8khyrGibgtgz95IR7M/0jhNhXCGwXESWe5Pv6Nrq1sbZKq9msUzQLRi/hGNnQAzZq8tUm68/N X-Gm-Message-State: AOJu0YwJUsGQk0t5a0dP9TXu0MlYu5TkMhH0aQCdPZvNQ+cN0I7HKbct q9k1RhiMllbHoIkEvu/5g3qXojLzJc7LShHGg/U+ywC3W50aqKEul9SsPeq9ZXo= X-Google-Smtp-Source: AGHT+IGw+Bsobx4Q6K3W0hODu0TR/LMn3n+Zqc9bqXkYfhbaSKdbCE9B0lHsuQkqXoS1KOQLpUhcbQ== X-Received: by 2002:a05:600c:3b03:b0:425:7bbf:fd07 with SMTP id 5b1f17b1804b1-427dc515239mr42580625e9.5.1721643158547; Mon, 22 Jul 2024 03:12:38 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:12:38 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 02/17] perf: cs-etm: Allocate queues for all CPUs Date: Mon, 22 Jul 2024 11:11:44 +0100 Message-Id: <20240722101202.26915-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark Make cs_etm__setup_queue() setup a queue even if it's empty, and pre-allocate queues based on the max CPU that was recorded. In per-CPU mode aux queues are indexed based on CPU ID even if all CPUs aren't recorded, sparse queue arrays aren't used. This will allow HW_IDs to be saved even if no aux data was received in that queue without having to call cs_etm__setup_queue() from two different places. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- tools/perf/util/cs-etm.c | 53 +++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index f4a378cb66f6..0fa7dd328783 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1062,16 +1062,11 @@ static struct cs_etm_queue *cs_etm__alloc_queue(voi= d) =20 static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, struct auxtrace_queue *queue, - unsigned int queue_nr, enum cs_etm_format format) + unsigned int queue_nr) { struct cs_etm_queue *etmq =3D queue->priv; =20 - if (etmq && format !=3D etmq->format) { - pr_err("CS_ETM: mixed formatted and unformatted trace not supported\n"); - return -EINVAL; - } - - if (list_empty(&queue->head) || etmq) + if (etmq) return 0; =20 etmq =3D cs_etm__alloc_queue(); @@ -1084,7 +1079,6 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace= *etm, etmq->queue_nr =3D queue_nr; queue->cpu =3D queue_nr; /* Placeholder, may be reset to -1 in per-thread= mode */ etmq->offset =3D 0; - etmq->format =3D format; =20 return 0; } @@ -2797,17 +2791,6 @@ static int cs_etm__process_auxtrace_event(struct per= f_session *session, if (err) return err; =20 - /* - * Knowing if the trace is formatted or not requires a lookup of - * the aux record so only works in non-piped mode where data is - * queued in cs_etm__queue_aux_records(). Always assume - * formatted in piped mode (true). - */ - err =3D cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], - idx, FORMATTED); - if (err) - return err; - if (dump_trace) if (auxtrace_buffer__get_data(buffer, fd)) { cs_etm__dump_event(etm->queues.queue_array[idx].priv, buffer); @@ -2924,7 +2907,6 @@ static int cs_etm__queue_aux_fragment(struct perf_ses= sion *session, off_t file_o struct perf_record_auxtrace *auxtrace_event; union perf_event auxtrace_fragment; __u64 aux_offset, aux_size; - __u32 idx; enum cs_etm_format format; =20 struct cs_etm_auxtrace *etm =3D container_of(session->auxtrace, @@ -2991,6 +2973,8 @@ static int cs_etm__queue_aux_fragment(struct perf_ses= sion *session, off_t file_o =20 if (aux_offset >=3D auxtrace_event->offset && aux_offset + aux_size <=3D auxtrace_event->offset + auxtrace_event->s= ize) { + struct cs_etm_queue *etmq =3D etm->queues.queue_array[auxtrace_event->id= x].priv; + /* * If this AUX event was inside this buffer somewhere, create a new auxt= race event * based on the sizes of the aux event, and queue that fragment. @@ -3007,11 +2991,14 @@ static int cs_etm__queue_aux_fragment(struct perf_s= ession *session, off_t file_o if (err) return err; =20 - idx =3D auxtrace_event->idx; format =3D (aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW) ? UNFORMATTED : FORMATTED; - - return cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], idx, form= at); + if (etmq->format !=3D UNSET && format !=3D etmq->format) { + pr_err("CS_ETM: mixed formatted and unformatted trace not supported\n"); + return -EINVAL; + } + etmq->format =3D format; + return 0; } =20 /* Wasn't inside this buffer, but there were no parse errors. 1 =3D=3D 'n= ot found' */ @@ -3263,6 +3250,7 @@ static int cs_etm__create_decoders(struct cs_etm_auxt= race *etm) * Don't create decoders for empty queues, mainly because * etmq->format is unknown for empty queues. */ + assert(empty =3D=3D (etmq->format =3D=3D UNSET)); if (empty) continue; =20 @@ -3282,10 +3270,10 @@ int cs_etm__process_auxtrace_info_full(union perf_e= vent *event, int event_header_size =3D sizeof(struct perf_event_header); int total_size =3D auxtrace_info->header.size; int priv_size =3D 0; - int num_cpu; + int num_cpu, max_cpu =3D 0; int err =3D 0; int aux_hw_id_found; - int i, j; + int i; u64 *ptr =3D NULL; u64 **metadata =3D NULL; =20 @@ -3316,7 +3304,7 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, * required by the trace decoder to properly decode the trace due * to its highly compressed nature. */ - for (j =3D 0; j < num_cpu; j++) { + for (int j =3D 0; j < num_cpu; j++) { if (ptr[i] =3D=3D __perf_cs_etmv3_magic) { metadata[j] =3D cs_etm__create_meta_blk(ptr, &i, @@ -3340,6 +3328,9 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, err =3D -ENOMEM; goto err_free_metadata; } + + if ((int) metadata[j][CS_ETM_CPU] > max_cpu) + max_cpu =3D metadata[j][CS_ETM_CPU]; } =20 /* @@ -3369,10 +3360,16 @@ int cs_etm__process_auxtrace_info_full(union perf_e= vent *event, */ etm->pid_fmt =3D cs_etm__init_pid_fmt(metadata[0]); =20 - err =3D auxtrace_queues__init(&etm->queues); + err =3D auxtrace_queues__init_nr(&etm->queues, max_cpu + 1); if (err) goto err_free_etm; =20 + for (unsigned int j =3D 0; j < etm->queues.nr_queues; ++j) { + err =3D cs_etm__setup_queue(etm, &etm->queues.queue_array[j], j); + if (err) + goto err_free_queues; + } + if (session->itrace_synth_opts->set) { etm->synth_opts =3D *session->itrace_synth_opts; } else { @@ -3494,7 +3491,7 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, zfree(&etm); err_free_metadata: /* No need to check @metadata[j], free(NULL) is supported */ - for (j =3D 0; j < num_cpu; j++) + for (int j =3D 0; j < num_cpu; j++) zfree(&metadata[j]); zfree(&metadata); err_free_traceid_list: --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72B0916C87A for ; Mon, 22 Jul 2024 10:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643167; cv=none; b=I8+BLqpvXf82AgjP+3v+1P/0F+sSX+z0v+KaYfA35QK7UxOB+KV2HCXbdV6n/fMKugp7jK60u2JGBP0OaGBe7NgbbDTZsfBckvM8Nhg8uEk/ygvWSxS/nUu1WZfeKhGEMnC4RITvj5FEwYAmKuWPWrp8cA7UON9Wt868QYtzofk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643167; c=relaxed/simple; bh=aOrTfh04jzTSySBjyrhgsHcObtErxSadvHnZV7ok1qY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cy1tVegIVt23kel8pgZNtqD5WNiO1yvSxCYyLtXIZXGpRHXBQKwBZsUPcgKqfBxY5Qaiyw3hZLQYQ7H0fLF5ZHlbCKgmbbz9jahX9401lv4ujSXlbPew0bO1Rv5wMlZB9hRG3HQXoTQKSmDMZvskgixw5UF9tKXgMYf4AYwN2W4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MEu0+mTY; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MEu0+mTY" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2ebed33cb65so47178631fa.2 for ; Mon, 22 Jul 2024 03:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643164; x=1722247964; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UyTZOlcer76A5XhM3hkLaXI/Rj6pzVBUq9WV2j3LO94=; b=MEu0+mTYT7MKXLx6SZR8klqDavqkbxdGx+iu/TGnikGGWebKLh+D1NTAu6Mzyi4bqc t5T5KakL7GZsjBom7TEOoqVEBhdm6uM4gCHfds8gAGx++3ZjHu2oWUrIqE0Oj7YCm3vg UPx9lMJc/0b7oczAynRtj3p4O9rS8ognKVBDfjrbJ4dUpqeHStSAe9DuqSK6M5HzlcGS +VZp6rctFtOVo+xxKA5/Y3lXhOmI5OKvrL0gazx3MuBlC8bE/dIvz6F91usI6fv/70gx O3pbEHQaZjsYoKzyegFixccXB6LqjQj8hnPr6kKBj6aibybRcLZ+WSfriCtg2Y8aWQTp bthQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643164; x=1722247964; h=content-transfer-encoding:mime-version: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=UyTZOlcer76A5XhM3hkLaXI/Rj6pzVBUq9WV2j3LO94=; b=FUSVZCG56b7UCBGinBXg/0bZo3Qx+9ysmBp6Fmu91h9k8dx5EEN3JDSQYThELorunS tMmmSTx7Ob47uAWb2PXYYWUmB0pl2wZ5DhcjSfJwxT0Tc0kevv65N3tpo+ZHSNX0ZFam zLy3NLdytcoyrt/OeoRdR5x//qaABPspVK++vG8TDTE4+ZakA9gcPdV+PXuUgAOGuKEk 9d2UF7TwY8vHNzUOdJ8p6JPj9eRtjsjvREbZLeoD2i7y+2jQg2tJYGa+Vpbs08EPNoUe wxe1pf+aw2d7AVF+xUcSlMODj3gtNSW0OeaDRH3GAw8wp8DA8sp4q4694IZUawGw5TYN 0a2g== X-Forwarded-Encrypted: i=1; AJvYcCVjdXX3Sw0vv+tQJ/sFTXHI1ANL11XbjCYkO2quiiaXKmacMiXF6H1OQX0+b6UMIvcM/0PSyTnRvSfoaVn2wcEmuCwGNP8rQCIeqiXv X-Gm-Message-State: AOJu0YxPB6ThhhD/nKbG4k3BMtqHJHmZompdMuBlmVnPXRColifT9aE+ +xBCQM3NKG9TpPGfH3R9FSHNEdcC+lJbos6TJDxT5sGp8PoI8iL04MR99rihPHo= X-Google-Smtp-Source: AGHT+IGyjiAwryu3AnjZbAxpppbaIgxNg73NMwKF89fMqqgChymsS5YVk+KH7/cyTezhX+t3JK+TMQ== X-Received: by 2002:a2e:b016:0:b0:2ef:22a4:6415 with SMTP id 38308e7fff4ca-2ef22a464f8mr39298431fa.28.1721643163559; Mon, 22 Jul 2024 03:12:43 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:12:43 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 03/17] perf: cs-etm: Move traceid_list to each queue Date: Mon, 22 Jul 2024 11:11:45 +0100 Message-Id: <20240722101202.26915-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark The global list won't work for per-sink trace ID allocations, so put a list in each queue where the IDs will be unique to that queue. To keep the same behavior as before, for version 0 of the HW_ID packets, copy all the HW_ID mappings into all queues. This change doesn't effect the decoders, only trace ID lookups on the Perf side. The decoders are still created with global mappings which will be fixed in a later commit. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 28 ++- tools/perf/util/cs-etm.c | 215 +++++++++++------- tools/perf/util/cs-etm.h | 2 +- 3 files changed, 147 insertions(+), 98 deletions(-) diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.c index e917985bbbe6..0c9c48cedbf1 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -388,7 +388,8 @@ cs_etm_decoder__reset_timestamp(struct cs_etm_packet_qu= eue *packet_queue) } =20 static ocsd_datapath_resp_t -cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue, +cs_etm_decoder__buffer_packet(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *packet_queue, const u8 trace_chan_id, enum cs_etm_sample_type sample_type) { @@ -398,7 +399,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_packet_queu= e *packet_queue, if (packet_queue->packet_count >=3D CS_ETM_PACKET_MAX_BUFFER - 1) return OCSD_RESP_FATAL_SYS_ERR; =20 - if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0) + if (cs_etm__get_cpu(etmq, trace_chan_id, &cpu) < 0) return OCSD_RESP_FATAL_SYS_ERR; =20 et =3D packet_queue->tail; @@ -436,7 +437,7 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq, int ret =3D 0; struct cs_etm_packet *packet; =20 - ret =3D cs_etm_decoder__buffer_packet(packet_queue, trace_chan_id, + ret =3D cs_etm_decoder__buffer_packet(etmq, packet_queue, trace_chan_id, CS_ETM_RANGE); if (ret !=3D OCSD_RESP_CONT && ret !=3D OCSD_RESP_WAIT) return ret; @@ -496,7 +497,8 @@ cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq, } =20 static ocsd_datapath_resp_t -cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue, +cs_etm_decoder__buffer_discontinuity(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *queue, const uint8_t trace_chan_id) { /* @@ -504,18 +506,19 @@ cs_etm_decoder__buffer_discontinuity(struct cs_etm_pa= cket_queue *queue, * reset time statistics. */ cs_etm_decoder__reset_timestamp(queue); - return cs_etm_decoder__buffer_packet(queue, trace_chan_id, + return cs_etm_decoder__buffer_packet(etmq, queue, trace_chan_id, CS_ETM_DISCONTINUITY); } =20 static ocsd_datapath_resp_t -cs_etm_decoder__buffer_exception(struct cs_etm_packet_queue *queue, +cs_etm_decoder__buffer_exception(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *queue, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { int ret =3D 0; struct cs_etm_packet *packet; =20 - ret =3D cs_etm_decoder__buffer_packet(queue, trace_chan_id, + ret =3D cs_etm_decoder__buffer_packet(etmq, queue, trace_chan_id, CS_ETM_EXCEPTION); if (ret !=3D OCSD_RESP_CONT && ret !=3D OCSD_RESP_WAIT) return ret; @@ -527,10 +530,11 @@ cs_etm_decoder__buffer_exception(struct cs_etm_packet= _queue *queue, } =20 static ocsd_datapath_resp_t -cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue, +cs_etm_decoder__buffer_exception_ret(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *queue, const uint8_t trace_chan_id) { - return cs_etm_decoder__buffer_packet(queue, trace_chan_id, + return cs_etm_decoder__buffer_packet(etmq, queue, trace_chan_id, CS_ETM_EXCEPTION_RET); } =20 @@ -599,7 +603,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_e= lem_printer( case OCSD_GEN_TRC_ELEM_EO_TRACE: case OCSD_GEN_TRC_ELEM_NO_SYNC: case OCSD_GEN_TRC_ELEM_TRACE_ON: - resp =3D cs_etm_decoder__buffer_discontinuity(packet_queue, + resp =3D cs_etm_decoder__buffer_discontinuity(etmq, packet_queue, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_INSTR_RANGE: @@ -607,11 +611,11 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace= _elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: - resp =3D cs_etm_decoder__buffer_exception(packet_queue, elem, + resp =3D cs_etm_decoder__buffer_exception(etmq, packet_queue, elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: - resp =3D cs_etm_decoder__buffer_exception_ret(packet_queue, + resp =3D cs_etm_decoder__buffer_exception_ret(etmq, packet_queue, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_TIMESTAMP: diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 0fa7dd328783..582526d9676f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -116,16 +116,18 @@ struct cs_etm_queue { /* Conversion between traceID and index in traceid_queues array */ struct intlist *traceid_queues_list; struct cs_etm_traceid_queue **traceid_queues; + /* Conversion between traceID and metadata pointers */ + struct intlist *traceid_list; }; =20 -/* RB tree for quick conversion between traceID and metadata pointers */ -static struct intlist *traceid_list; - static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm); static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, pid_t tid); static int cs_etm__get_data_block(struct cs_etm_queue *etmq); static int cs_etm__decode_data_block(struct cs_etm_queue *etmq); +static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metad= ata); +static u64 *get_cpu_data(struct cs_etm_auxtrace *etm, int cpu); +static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metada= ta); =20 /* PTMs ETMIDR [11:8] set to b0011 */ #define ETMIDR_PTM_VERSION 0x00000300 @@ -151,12 +153,12 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr) return CS_ETM_PROTO_ETMV3; } =20 -static int cs_etm__get_magic(u8 trace_chan_id, u64 *magic) +static int cs_etm__get_magic(struct cs_etm_queue *etmq, u8 trace_chan_id, = u64 *magic) { struct int_node *inode; u64 *metadata; =20 - inode =3D intlist__find(traceid_list, trace_chan_id); + inode =3D intlist__find(etmq->traceid_list, trace_chan_id); if (!inode) return -EINVAL; =20 @@ -165,12 +167,12 @@ static int cs_etm__get_magic(u8 trace_chan_id, u64 *m= agic) return 0; } =20 -int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) +int cs_etm__get_cpu(struct cs_etm_queue *etmq, u8 trace_chan_id, int *cpu) { struct int_node *inode; u64 *metadata; =20 - inode =3D intlist__find(traceid_list, trace_chan_id); + inode =3D intlist__find(etmq->traceid_list, trace_chan_id); if (!inode) return -EINVAL; =20 @@ -222,30 +224,108 @@ enum cs_etm_pid_fmt cs_etm__get_pid_fmt(struct cs_et= m_queue *etmq) return etmq->etm->pid_fmt; } =20 -static int cs_etm__map_trace_id(u8 trace_chan_id, u64 *cpu_metadata) +static int cs_etm__insert_trace_id_node(struct cs_etm_queue *etmq, + u8 trace_chan_id, u64 *cpu_metadata) { - struct int_node *inode; - /* Get an RB node for this CPU */ - inode =3D intlist__findnew(traceid_list, trace_chan_id); + struct int_node *inode =3D intlist__findnew(etmq->traceid_list, trace_cha= n_id); =20 /* Something went wrong, no need to continue */ if (!inode) return -ENOMEM; =20 + /* Disallow re-mapping a different traceID to metadata pair. */ + if (inode->priv) { + u64 *curr_cpu_data =3D inode->priv; + u8 curr_chan_id; + int err; + + if (curr_cpu_data[CS_ETM_CPU] !=3D cpu_metadata[CS_ETM_CPU]) { + pr_err("CS_ETM: map mismatch between HW_ID packet CPU and Trace ID\n"); + return -EINVAL; + } + + /* check that the mapped ID matches */ + err =3D cs_etm__metadata_get_trace_id(&curr_chan_id, curr_cpu_data); + if (err) + return err; + + if (curr_chan_id !=3D trace_chan_id) { + pr_err("CS_ETM: mismatch between CPU trace ID and HW_ID packet ID\n"); + return -EINVAL; + } + + /* Skip re-adding the same mappings if everything matched */ + return 0; + } + + /* Not one we've seen before, associate the traceID with the metadata poi= nter */ + inode->priv =3D cpu_metadata; + + return 0; +} + +static struct cs_etm_queue *cs_etm__get_queue(struct cs_etm_auxtrace *etm,= int cpu) +{ + if (etm->per_thread_decoding) + return etm->queues.queue_array[0].priv; + else + return etm->queues.queue_array[cpu].priv; +} + +static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_c= han_id, + u64 *cpu_metadata) +{ + struct cs_etm_queue *etmq; + /* - * The node for that CPU should not be taken. - * Back out if that's the case. + * If the queue is unformatted then only save one mapping in the + * queue associated with that CPU so only one decoder is made. */ - if (inode->priv) - return -EINVAL; + etmq =3D cs_etm__get_queue(etm, cpu_metadata[CS_ETM_CPU]); + if (etmq->format =3D=3D UNFORMATTED) + return cs_etm__insert_trace_id_node(etmq, trace_chan_id, + cpu_metadata); =20 - /* All good, associate the traceID with the metadata pointer */ - inode->priv =3D cpu_metadata; + /* + * Otherwise, version 0 trace IDs are global so save them into every + * queue. + */ + for (unsigned int i =3D 0; i < etm->queues.nr_queues; ++i) { + int ret; + + etmq =3D etm->queues.queue_array[i].priv; + ret =3D cs_etm__insert_trace_id_node(etmq, trace_chan_id, + cpu_metadata); + if (ret) + return ret; + } =20 return 0; } =20 +static int cs_etm__process_trace_id_v0(struct cs_etm_auxtrace *etm, int cp= u, + u64 hw_id) +{ + int err; + u64 *cpu_data; + u8 trace_chan_id =3D FIELD_GET(CS_AUX_HW_ID_TRACE_ID_MASK, hw_id); + + cpu_data =3D get_cpu_data(etm, cpu); + if (cpu_data =3D=3D NULL) + return -EINVAL; + + err =3D cs_etm__map_trace_id_v0(etm, trace_chan_id, cpu_data); + if (err) + return err; + + /* + * if we are picking up the association from the packet, need to plug + * the correct trace ID into the metadata for setting up decoders later. + */ + return cs_etm__metadata_set_trace_id(trace_chan_id, cpu_data); +} + static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metad= ata) { u64 cs_etm_magic =3D cpu_metadata[CS_ETM_MAGIC]; @@ -329,17 +409,13 @@ static int cs_etm__process_aux_output_hw_id(struct pe= rf_session *session, { struct cs_etm_auxtrace *etm; struct perf_sample sample; - struct int_node *inode; struct evsel *evsel; - u64 *cpu_data; u64 hw_id; int cpu, version, err; - u8 trace_chan_id, curr_chan_id; =20 /* extract and parse the HW ID */ hw_id =3D event->aux_output_hw_id.hw_id; version =3D FIELD_GET(CS_AUX_HW_ID_VERSION_MASK, hw_id); - trace_chan_id =3D FIELD_GET(CS_AUX_HW_ID_TRACE_ID_MASK, hw_id); =20 /* check that we can handle this version */ if (version > CS_AUX_HW_ID_CURR_VERSION) { @@ -367,43 +443,7 @@ static int cs_etm__process_aux_output_hw_id(struct per= f_session *session, return -EINVAL; } =20 - /* See if the ID is mapped to a CPU, and it matches the current CPU */ - inode =3D intlist__find(traceid_list, trace_chan_id); - if (inode) { - cpu_data =3D inode->priv; - if ((int)cpu_data[CS_ETM_CPU] !=3D cpu) { - pr_err("CS_ETM: map mismatch between HW_ID packet CPU and Trace ID\n"); - return -EINVAL; - } - - /* check that the mapped ID matches */ - err =3D cs_etm__metadata_get_trace_id(&curr_chan_id, cpu_data); - if (err) - return err; - if (curr_chan_id !=3D trace_chan_id) { - pr_err("CS_ETM: mismatch between CPU trace ID and HW_ID packet ID\n"); - return -EINVAL; - } - - /* mapped and matched - return OK */ - return 0; - } - - cpu_data =3D get_cpu_data(etm, cpu); - if (cpu_data =3D=3D NULL) - return err; - - /* not one we've seen before - lets map it */ - err =3D cs_etm__map_trace_id(trace_chan_id, cpu_data); - if (err) - return err; - - /* - * if we are picking up the association from the packet, need to plug - * the correct trace ID into the metadata for setting up decoders later. - */ - err =3D cs_etm__metadata_set_trace_id(trace_chan_id, cpu_data); - return err; + return cs_etm__process_trace_id_v0(etm, cpu, hw_id); } =20 void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, @@ -856,6 +896,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_q= ueue *etmq) =20 static void cs_etm__free_queue(void *priv) { + struct int_node *inode, *tmp; struct cs_etm_queue *etmq =3D priv; =20 if (!etmq) @@ -863,6 +904,14 @@ static void cs_etm__free_queue(void *priv) =20 cs_etm_decoder__free(etmq->decoder); cs_etm__free_traceid_queues(etmq); + + /* First remove all traceID/metadata nodes for the RB tree */ + intlist__for_each_entry_safe(inode, tmp, etmq->traceid_list) + intlist__remove(etmq->traceid_list, inode); + + /* Then the RB tree itself */ + intlist__delete(etmq->traceid_list); + free(etmq); } =20 @@ -885,19 +934,12 @@ static void cs_etm__free_events(struct perf_session *= session) static void cs_etm__free(struct perf_session *session) { int i; - struct int_node *inode, *tmp; struct cs_etm_auxtrace *aux =3D container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace); cs_etm__free_events(session); session->auxtrace =3D NULL; =20 - /* First remove all traceID/metadata nodes for the RB tree */ - intlist__for_each_entry_safe(inode, tmp, traceid_list) - intlist__remove(traceid_list, inode); - /* Then the RB tree itself */ - intlist__delete(traceid_list); - for (i =3D 0; i < aux->num_cpu; i++) zfree(&aux->metadata[i]); =20 @@ -1055,9 +1097,24 @@ static struct cs_etm_queue *cs_etm__alloc_queue(void) =20 etmq->traceid_queues_list =3D intlist__new(NULL); if (!etmq->traceid_queues_list) - free(etmq); + goto out_free; + + /* + * Create an RB tree for traceID-metadata tuple. Since the conversion + * has to be made for each packet that gets decoded, optimizing access + * in anything other than a sequential array is worth doing. + */ + etmq->traceid_list =3D intlist__new(NULL); + if (!etmq->traceid_list) + goto out_free; =20 return etmq; + +out_free: + intlist__delete(etmq->traceid_queues_list); + free(etmq); + + return NULL; } =20 static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, @@ -2207,7 +2264,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_que= ue *etmq, PERF_IP_FLAG_TRACE_END; break; case CS_ETM_EXCEPTION: - ret =3D cs_etm__get_magic(packet->trace_chan_id, &magic); + ret =3D cs_etm__get_magic(etmq, packet->trace_chan_id, &magic); if (ret) return ret; =20 @@ -3124,7 +3181,8 @@ static bool cs_etm__has_virtual_ts(u64 **metadata, in= t num_cpu) } =20 /* map trace ids to correct metadata block, from information in metadata */ -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm, int= num_cpu, + u64 **metadata) { u64 cs_etm_magic; u8 trace_chan_id; @@ -3146,7 +3204,7 @@ static int cs_etm__map_trace_ids_metadata(int num_cpu= , u64 **metadata) /* unknown magic number */ return -EINVAL; } - err =3D cs_etm__map_trace_id(trace_chan_id, metadata[i]); + err =3D cs_etm__map_trace_id_v0(etm, trace_chan_id, metadata[i]); if (err) return err; } @@ -3277,23 +3335,12 @@ int cs_etm__process_auxtrace_info_full(union perf_e= vent *event, u64 *ptr =3D NULL; u64 **metadata =3D NULL; =20 - /* - * Create an RB tree for traceID-metadata tuple. Since the conversion - * has to be made for each packet that gets decoded, optimizing access - * in anything other than a sequential array is worth doing. - */ - traceid_list =3D intlist__new(NULL); - if (!traceid_list) - return -ENOMEM; - /* First the global part */ ptr =3D (u64 *) auxtrace_info->priv; num_cpu =3D ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; metadata =3D zalloc(sizeof(*metadata) * num_cpu); - if (!metadata) { - err =3D -ENOMEM; - goto err_free_traceid_list; - } + if (!metadata) + return -ENOMEM; =20 /* Start parsing after the common part of the header */ i =3D CS_HEADER_VERSION_MAX; @@ -3472,7 +3519,7 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, err =3D cs_etm__clear_unused_trace_ids_metadata(num_cpu, metadata); /* otherwise, this is a file with metadata values only, map from metadata= */ else - err =3D cs_etm__map_trace_ids_metadata(num_cpu, metadata); + err =3D cs_etm__map_trace_ids_metadata(etm, num_cpu, metadata); =20 if (err) goto err_free_queues; @@ -3494,7 +3541,5 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, for (int j =3D 0; j < num_cpu; j++) zfree(&metadata[j]); zfree(&metadata); -err_free_traceid_list: - intlist__delete(traceid_list); return err; } diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 4696267a32f0..f4f69f7cc0f3 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -252,7 +252,7 @@ enum cs_etm_pid_fmt { =20 #ifdef HAVE_CSTRACE_SUPPORT #include -int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); +int cs_etm__get_cpu(struct cs_etm_queue *etmq, u8 trace_chan_id, int *cpu); enum cs_etm_pid_fmt cs_etm__get_pid_fmt(struct cs_etm_queue *etmq); int cs_etm__etmq_set_tid_el(struct cs_etm_queue *etmq, pid_t tid, u8 trace_chan_id, ocsd_ex_level el); --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7FA16C6B8 for ; Mon, 22 Jul 2024 10:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643173; cv=none; b=fxTVKoxCQaQZCzAIRzIpRbdVryNVzo3188YiWiWQ4agNK+uTsij36fu5lja3MxkLZFvY9hcyISqYICnaXrQSdHgZHiNdKI1vDvKxpCGGc88l15I2RPa2fKYFhzUozoXuvCo3yJRnWylw79TN2abmVYPO2V3uqYzBRKDcwsizfY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643173; c=relaxed/simple; bh=hZm5v4lUy7L9nPRGtRckJOpExDj6bJxmcmYJyyQH1qw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZTd38TRf19dP1+4pyjhVfUE6EJXJM4Jy4fWikYkxZaA2IEg7EJI0yAmQsyomufFF1w+ujUP6DZejYTQZK0Ab9w8mGVH4BievzP1yz+VfvJBl4FMAN1TlB4oeZouq3cTn4h0zPADDV4xBHY3txX9FkbiqH6T8kMgKMEBOXmJlyZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=HELdd4Bf; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HELdd4Bf" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4257d5fc9b7so34618765e9.2 for ; Mon, 22 Jul 2024 03:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643169; x=1722247969; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n9JfofHwzEwCTe8hXQsxnVoSXqGVi/oRZgdmMy1CG2M=; b=HELdd4Bf5UcPlxANKWMlqtPyM1CO7f1OQ+Pd2OxeKPUf3Hclh1r3F8vIpptvebw6HO Qwj7H5WYj/9pRcfXqs0FztPlP4tZ+GzVzCbk9rv5ScTjUQ/xHMG2J0jkMuxE17jJL6Zf lgcbTYILyz2X8GpcXSa0GYhSTRWTOlCicLQ60SSMibDsMo9cjB4GGV5IMhA7yGvXwI8q 2Jc+H/jk93O8hVXnKQtAqV2/ym28cejP5l/4IzzmuhZn/zucBnoGfI1umWl3GvbZ1bIr 51YXdMpqmny5ZY8WiVx58Z+OUtFbkwZvvvfqrB3hxddUw6RMdHOONRM1Sj2/fmZmefYA 7Srg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643169; x=1722247969; h=content-transfer-encoding:mime-version: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=n9JfofHwzEwCTe8hXQsxnVoSXqGVi/oRZgdmMy1CG2M=; b=bRAl1lRO2fBb1V31H5G0scHRAj7f5s9DKDTqxDhtlLygFWd9l0Nl+U3Y4H9OYMW8Ut uwjQIOWAT7dUvAZoR+QhmDifksh+ANQKKt5B0yl0NHDKUKBTz1JglwKJVqLcxrkae/O2 nJM53m3zYiAVIX16qFMqJP8bPsT1cN5jyz/35J5TwPc95nX4ic56HZhW2WX7WOk5NSEh ObXwIUFFb9woVuJVdpuAW6KW7sWOIhUFfGcdd/Y0UKGVws1tSy4tbgQbnyLMnSQyVivn ARwMuKZ0250f/7oHhfYAIhs8LHBpNaWFyIugeBSrZzo+IJIIjV+YmfO6maZtXYa2Brag q+ZA== X-Forwarded-Encrypted: i=1; AJvYcCUIdZMt5apEtnIT9B0MoAFhmllr1LJt9akovNcM8Q6qpZBl7vB9yVG5aXvS/tmMXOtpCDbksKqk8MAfLH9ymfoSaHINY7muh8esS4XC X-Gm-Message-State: AOJu0YwpXevObYIBBeTEpr1LxaPllr1qSEpgqgbasOR7EkBsuKnrV5yq dz2Cl7lRrAwuJye0ARwS+luYIzdlXMewOrEn+jGSxNmFRqfk/B4d0j+3kaR4OLc= X-Google-Smtp-Source: AGHT+IE9zBak+hMpn3Ph0jYBO/9Gn+nFW62YOmSwj9wIWutOez5hmKoEHjtWh+xuqmKU2HEAtYBw+Q== X-Received: by 2002:a05:600c:3582:b0:426:6bf9:608d with SMTP id 5b1f17b1804b1-427dc52050dmr42436115e9.12.1721643168649; Mon, 22 Jul 2024 03:12:48 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:12:48 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 04/17] perf: cs-etm: Create decoders based on the trace ID mappings Date: Mon, 22 Jul 2024 11:11:46 +0100 Message-Id: <20240722101202.26915-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark Now that each queue has a unique set of trace ID mappings, use this list to create the decoders. In unformatted mode just add a single mapping so only one decoder is made. Previously each queue would have a decoder created for each traced CPU on the system but this won't work anymore because CPUs can have overlapping trace IDs. This also means that the CORESIGHT_TRACE_ID_UNUSED_FLAG isn't needed any more. If mappings aren't added then decoders aren't created, rather than needing a flag to suppress creation. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- tools/perf/arch/arm/util/cs-etm.c | 8 +- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 - tools/perf/util/cs-etm.c | 155 ++++++------------ tools/perf/util/cs-etm.h | 10 -- 4 files changed, 55 insertions(+), 122 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index da6231367993..b0118546cd4d 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -654,8 +654,7 @@ static void cs_etm_save_etmv4_header(__u64 data[], stru= ct auxtrace_record *itr, /* Get trace configuration register */ data[CS_ETMV4_TRCCONFIGR] =3D cs_etmv4_get_config(itr); /* traceID set to legacy version, in case new perf running on older syste= m */ - data[CS_ETMV4_TRCTRACEIDR] =3D cs_etm_get_legacy_trace_id(cpu) | - CORESIGHT_TRACE_ID_UNUSED_FLAG; + data[CS_ETMV4_TRCTRACEIDR] =3D cs_etm_get_legacy_trace_id(cpu); =20 /* Get read-only information from sysFS */ cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0], @@ -687,7 +686,7 @@ static void cs_etm_save_ete_header(__u64 data[], struct= auxtrace_record *itr, st /* Get trace configuration register */ data[CS_ETE_TRCCONFIGR] =3D cs_etmv4_get_config(itr); /* traceID set to legacy version, in case new perf running on older syste= m */ - data[CS_ETE_TRCTRACEIDR] =3D cs_etm_get_legacy_trace_id(cpu) | CORESIGHT_= TRACE_ID_UNUSED_FLAG; + data[CS_ETE_TRCTRACEIDR] =3D cs_etm_get_legacy_trace_id(cpu); =20 /* Get read-only information from sysFS */ cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR0], &data[CS_= ETE_TRCIDR0]); @@ -743,8 +742,7 @@ static void cs_etm_get_metadata(struct perf_cpu cpu, u3= 2 *offset, /* Get configuration register */ info->priv[*offset + CS_ETM_ETMCR] =3D cs_etm_get_config(itr); /* traceID set to legacy value in case new perf running on old system */ - info->priv[*offset + CS_ETM_ETMTRACEIDR] =3D cs_etm_get_legacy_trace_id(= cpu) | - CORESIGHT_TRACE_ID_UNUSED_FLAG; + info->priv[*offset + CS_ETM_ETMTRACEIDR] =3D cs_etm_get_legacy_trace_id(= cpu); /* Get read-only information from sysFS */ cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMCCER], &info->priv[*offset + CS_ETM_ETMCCER]); diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.c index 0c9c48cedbf1..d49c3e9c7c21 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -684,10 +684,6 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decod= er_params *d_params, return -1; } =20 - /* if the CPU has no trace ID associated, no decoder needed */ - if (csid =3D=3D CORESIGHT_TRACE_ID_UNUSED_VAL) - return 0; - if (d_params->operation =3D=3D CS_ETM_OPERATION_DECODE) { if (ocsd_dt_create_decoder(decoder->dcd_tree, decoder->decoder_name, diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 582526d9676f..7cce58dca33c 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -348,7 +348,6 @@ static int cs_etm__metadata_get_trace_id(u8 *trace_chan= _id, u64 *cpu_metadata) =20 /* * update metadata trace ID from the value found in the AUX_HW_INFO packet. - * This will also clear the CORESIGHT_TRACE_ID_UNUSED_FLAG flag if present. */ static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metada= ta) { @@ -700,80 +699,58 @@ static void cs_etm__packet_dump(const char *pkt_strin= g) } =20 static void cs_etm__set_trace_param_etmv3(struct cs_etm_trace_params *t_pa= rams, - struct cs_etm_auxtrace *etm, int t_idx, - int m_idx, u32 etmidr) + u64 *metadata, u32 etmidr) { - u64 **metadata =3D etm->metadata; - - t_params[t_idx].protocol =3D cs_etm__get_v7_protocol_version(etmidr); - t_params[t_idx].etmv3.reg_ctrl =3D metadata[m_idx][CS_ETM_ETMCR]; - t_params[t_idx].etmv3.reg_trc_id =3D metadata[m_idx][CS_ETM_ETMTRACEIDR]; + t_params->protocol =3D cs_etm__get_v7_protocol_version(etmidr); + t_params->etmv3.reg_ctrl =3D metadata[CS_ETM_ETMCR]; + t_params->etmv3.reg_trc_id =3D metadata[CS_ETM_ETMTRACEIDR]; } =20 static void cs_etm__set_trace_param_etmv4(struct cs_etm_trace_params *t_pa= rams, - struct cs_etm_auxtrace *etm, int t_idx, - int m_idx) + u64 *metadata) { - u64 **metadata =3D etm->metadata; - - t_params[t_idx].protocol =3D CS_ETM_PROTO_ETMV4i; - t_params[t_idx].etmv4.reg_idr0 =3D metadata[m_idx][CS_ETMV4_TRCIDR0]; - t_params[t_idx].etmv4.reg_idr1 =3D metadata[m_idx][CS_ETMV4_TRCIDR1]; - t_params[t_idx].etmv4.reg_idr2 =3D metadata[m_idx][CS_ETMV4_TRCIDR2]; - t_params[t_idx].etmv4.reg_idr8 =3D metadata[m_idx][CS_ETMV4_TRCIDR8]; - t_params[t_idx].etmv4.reg_configr =3D metadata[m_idx][CS_ETMV4_TRCCONFIGR= ]; - t_params[t_idx].etmv4.reg_traceidr =3D metadata[m_idx][CS_ETMV4_TRCTRACEI= DR]; + t_params->protocol =3D CS_ETM_PROTO_ETMV4i; + t_params->etmv4.reg_idr0 =3D metadata[CS_ETMV4_TRCIDR0]; + t_params->etmv4.reg_idr1 =3D metadata[CS_ETMV4_TRCIDR1]; + t_params->etmv4.reg_idr2 =3D metadata[CS_ETMV4_TRCIDR2]; + t_params->etmv4.reg_idr8 =3D metadata[CS_ETMV4_TRCIDR8]; + t_params->etmv4.reg_configr =3D metadata[CS_ETMV4_TRCCONFIGR]; + t_params->etmv4.reg_traceidr =3D metadata[CS_ETMV4_TRCTRACEIDR]; } =20 static void cs_etm__set_trace_param_ete(struct cs_etm_trace_params *t_para= ms, - struct cs_etm_auxtrace *etm, int t_idx, - int m_idx) + u64 *metadata) { - u64 **metadata =3D etm->metadata; - - t_params[t_idx].protocol =3D CS_ETM_PROTO_ETE; - t_params[t_idx].ete.reg_idr0 =3D metadata[m_idx][CS_ETE_TRCIDR0]; - t_params[t_idx].ete.reg_idr1 =3D metadata[m_idx][CS_ETE_TRCIDR1]; - t_params[t_idx].ete.reg_idr2 =3D metadata[m_idx][CS_ETE_TRCIDR2]; - t_params[t_idx].ete.reg_idr8 =3D metadata[m_idx][CS_ETE_TRCIDR8]; - t_params[t_idx].ete.reg_configr =3D metadata[m_idx][CS_ETE_TRCCONFIGR]; - t_params[t_idx].ete.reg_traceidr =3D metadata[m_idx][CS_ETE_TRCTRACEIDR]; - t_params[t_idx].ete.reg_devarch =3D metadata[m_idx][CS_ETE_TRCDEVARCH]; + t_params->protocol =3D CS_ETM_PROTO_ETE; + t_params->ete.reg_idr0 =3D metadata[CS_ETE_TRCIDR0]; + t_params->ete.reg_idr1 =3D metadata[CS_ETE_TRCIDR1]; + t_params->ete.reg_idr2 =3D metadata[CS_ETE_TRCIDR2]; + t_params->ete.reg_idr8 =3D metadata[CS_ETE_TRCIDR8]; + t_params->ete.reg_configr =3D metadata[CS_ETE_TRCCONFIGR]; + t_params->ete.reg_traceidr =3D metadata[CS_ETE_TRCTRACEIDR]; + t_params->ete.reg_devarch =3D metadata[CS_ETE_TRCDEVARCH]; } =20 static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params, - struct cs_etm_auxtrace *etm, - enum cs_etm_format format, - int sample_cpu, - int decoders) -{ - int t_idx, m_idx; - u32 etmidr; - u64 architecture; - - for (t_idx =3D 0; t_idx < decoders; t_idx++) { - if (format =3D=3D FORMATTED) - m_idx =3D t_idx; - else { - m_idx =3D get_cpu_data_idx(etm, sample_cpu); - if (m_idx =3D=3D -1) { - pr_warning("CS_ETM: unknown CPU, falling back to first metadata\n"); - m_idx =3D 0; - } - } + struct cs_etm_queue *etmq) +{ + struct int_node *inode; =20 - architecture =3D etm->metadata[m_idx][CS_ETM_MAGIC]; + intlist__for_each_entry(inode, etmq->traceid_list) { + u64 *metadata =3D inode->priv; + u64 architecture =3D metadata[CS_ETM_MAGIC]; + u32 etmidr; =20 switch (architecture) { case __perf_cs_etmv3_magic: - etmidr =3D etm->metadata[m_idx][CS_ETM_ETMIDR]; - cs_etm__set_trace_param_etmv3(t_params, etm, t_idx, m_idx, etmidr); + etmidr =3D metadata[CS_ETM_ETMIDR]; + cs_etm__set_trace_param_etmv3(t_params++, metadata, etmidr); break; case __perf_cs_etmv4_magic: - cs_etm__set_trace_param_etmv4(t_params, etm, t_idx, m_idx); + cs_etm__set_trace_param_etmv4(t_params++, metadata); break; case __perf_cs_ete_magic: - cs_etm__set_trace_param_ete(t_params, etm, t_idx, m_idx); + cs_etm__set_trace_param_ete(t_params++, metadata); break; default: return -EINVAL; @@ -3211,35 +3188,6 @@ static int cs_etm__map_trace_ids_metadata(struct cs_= etm_auxtrace *etm, int num_c return 0; } =20 -/* - * If we found AUX_HW_ID packets, then set any metadata marked as unused t= o the - * unused value to reduce the number of unneeded decoders created. - */ -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **meta= data) -{ - u64 cs_etm_magic; - int i; - - for (i =3D 0; i < num_cpu; i++) { - cs_etm_magic =3D metadata[i][CS_ETM_MAGIC]; - switch (cs_etm_magic) { - case __perf_cs_etmv3_magic: - if (metadata[i][CS_ETM_ETMTRACEIDR] & CORESIGHT_TRACE_ID_UNUSED_FLAG) - metadata[i][CS_ETM_ETMTRACEIDR] =3D CORESIGHT_TRACE_ID_UNUSED_VAL; - break; - case __perf_cs_etmv4_magic: - case __perf_cs_ete_magic: - if (metadata[i][CS_ETMV4_TRCTRACEIDR] & CORESIGHT_TRACE_ID_UNUSED_FLAG) - metadata[i][CS_ETMV4_TRCTRACEIDR] =3D CORESIGHT_TRACE_ID_UNUSED_VAL; - break; - default: - /* unknown magic number */ - return -EINVAL; - } - } - return 0; -} - /* * Use the data gathered by the peeks for HW_ID (trace ID mappings) and AUX * (formatted or not) packets to create the decoders. @@ -3247,21 +3195,26 @@ static int cs_etm__clear_unused_trace_ids_metadata(= int num_cpu, u64 **metadata) static int cs_etm__create_queue_decoders(struct cs_etm_queue *etmq) { struct cs_etm_decoder_params d_params; + struct cs_etm_trace_params *t_params; + int decoders =3D intlist__nr_entries(etmq->traceid_list); + + if (decoders =3D=3D 0) + return 0; =20 /* * Each queue can only contain data from one CPU when unformatted, so onl= y one decoder is * needed. */ - int decoders =3D etmq->format =3D=3D FORMATTED ? etmq->etm->num_cpu : 1; + if (etmq->format =3D=3D UNFORMATTED) + assert(decoders =3D=3D 1); =20 /* Use metadata to fill in trace parameters for trace decoder */ - struct cs_etm_trace_params *t_params =3D zalloc(sizeof(*t_params) * deco= ders); + t_params =3D zalloc(sizeof(*t_params) * decoders); =20 if (!t_params) goto out_free; =20 - if (cs_etm__init_trace_params(t_params, etmq->etm, etmq->format, - etmq->queue_nr, decoders)) + if (cs_etm__init_trace_params(t_params, etmq)) goto out_free; =20 /* Set decoder parameters to decode trace packets */ @@ -3487,9 +3440,9 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, /* * Map Trace ID values to CPU metadata. * - * Trace metadata will always contain Trace ID values from the legacy alg= orithm. If the - * files has been recorded by a "new" perf updated to handle AUX_HW_ID th= en the metadata - * ID value will also have the CORESIGHT_TRACE_ID_UNUSED_FLAG set. + * Trace metadata will always contain Trace ID values from the legacy alg= orithm + * in case it's read by a version of Perf that doesn't know about HW_ID p= ackets + * or the kernel doesn't emit them. * * The updated kernel drivers that use AUX_HW_ID to sent Trace IDs will a= ttempt to use * the same IDs as the old algorithm as far as is possible, unless there = are clashes @@ -3498,12 +3451,11 @@ int cs_etm__process_auxtrace_info_full(union perf_e= vent *event, * * For a perf able to interpret AUX_HW_ID packets we first check for the = presence of * those packets. If they are there then the values will be mapped and pl= ugged into - * the metadata. We then set any remaining metadata values with the used = flag to a - * value CORESIGHT_TRACE_ID_UNUSED_VAL - which indicates no decoder is re= quired. + * the metadata and decoders are only created for each mapping received. * * If no AUX_HW_ID packets are present - which means a file recorded on a= n old kernel - * then we map Trace ID values to CPU directly from the metadata - cleari= ng any unused - * flags if present. + * then we map Trace ID values to CPU directly from the metadata and crea= te decoders + * for all mappings. */ =20 /* Scan for AUX_OUTPUT_HW_ID records to map trace ID values to CPU metada= ta */ @@ -3514,15 +3466,12 @@ int cs_etm__process_auxtrace_info_full(union perf_e= vent *event, if (err) goto err_free_queues; =20 - /* if HW ID found then clear any unused metadata ID values */ - if (aux_hw_id_found) - err =3D cs_etm__clear_unused_trace_ids_metadata(num_cpu, metadata); - /* otherwise, this is a file with metadata values only, map from metadata= */ - else + /* if no HW ID found this is a file with metadata values only, map from m= etadata */ + if (!aux_hw_id_found) { err =3D cs_etm__map_trace_ids_metadata(etm, num_cpu, metadata); - - if (err) - goto err_free_queues; + if (err) + goto err_free_queues; + } =20 err =3D cs_etm__create_decoders(etm); if (err) diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index f4f69f7cc0f3..a8caeea720aa 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -230,16 +230,6 @@ struct cs_etm_packet_queue { /* CoreSight trace ID is currently the bottom 7 bits of the value */ #define CORESIGHT_TRACE_ID_VAL_MASK GENMASK(6, 0) =20 -/* - * 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) - -/* Value to set for unused trace ID values */ -#define CORESIGHT_TRACE_ID_UNUSED_VAL 0x7F - int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); void cs_etm_get_default_config(const struct perf_pmu *pmu, struct perf_eve= nt_attr *attr); --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24E5116C864 for ; Mon, 22 Jul 2024 10:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643176; cv=none; b=RwBFODox6OK6VGUzA5F1We2imOYGfDNozbEt5lbZE7axlKRU5EkJZ/lygD7hWGUI3AiJQ55IwfWMWsRwWiyub7bsQ/wxlzBrGT57zXE0mxjLTZTX7AHgyowW1C3VXdT7cCNB05kWi8Y2k9MRL0Z7hgLAgCaYEoginKVtK1jAnLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643176; c=relaxed/simple; bh=nFFI9RKICO7tZQAb/+UsQYDgk3RpA4xkmXJTM26/t0k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pm6g8xWDxo+CWbLfcUMdd26J4PvNdWmw184TrwEVLYDg92DDbmvSLafnQ69LhCbKFYSgFraeuTEeF82AMZOM2oLIBwcZiQGttNad4CFOAAIlngORvYhESKHx79bhVAxsZSl0/2rS7ZqjGYH7hNNuKwVU06HCyV8jzYQ86tuOtAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ZYk+9vfW; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ZYk+9vfW" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-426526d30aaso30955715e9.0 for ; Mon, 22 Jul 2024 03:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643173; x=1722247973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PBWFBM+gp3e/C9sPG7aaILEvO32vZCwGZx3iasW4K4Q=; b=ZYk+9vfW70TrHJT++buTGw65uA45+55wFkvT8C7HvjCZgzIst6c5V8d2mHPZOvlSsi MJVlX0nXaV2YZfz346HkmlXZ5gbZ/3sQroEKpbA/ARDyGRmdHqvdTe8OLPRRwspVRT2H /4P4p8/2DVAtuYtIQRGX6sup3xh7wgRbeG/QoHyxKm0nr/lXB7FXGRrUCf/S6NwjEn9K ZcdCA8FJuvQ1UYV4OCKejlsca3fDiSH3pOdbAm8jkz7p7fCP3pNn5EgDFQEHZLiHty8h HbtDeF3HFCWz04Lf6uv2IqlJkoosyMv0KdSfv0vIfePHvi5C4YygTJGDA0AUtYlmAXW6 83NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643173; x=1722247973; h=content-transfer-encoding:mime-version: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=PBWFBM+gp3e/C9sPG7aaILEvO32vZCwGZx3iasW4K4Q=; b=IVlKqiIzrbVqxAzscPj8fCFZas9+8VCF4IHcen/Ddm0HgaCb195i1nprpH7X0uGfFH l4wH2d17oWklRhUkIQ9lRL9aTDZOb7AFD9nmrlpx0ScSUrlydiJxpoXtrsC70GoyuYkU 3wA9gfHxqH4N6HzA1vD75ljC9EV5K4wTy+EQyQHj/xuG1X1Was8CuU+X5Z10GcxqsL3u 462ipRMSoQW6iWE9y7G53vxPFCY0cohr9OpcDH+tGlE0hyHGGBolcmo1SWsddRVWZ2sF P/gxeZncTy5Srjk5KPc7GlgK001LsrxdCetQLTslgd+mkYu3bBkQ/y2PAigfn8p9jOuL q+hw== X-Forwarded-Encrypted: i=1; AJvYcCV/BNAAkQ6KJDKLJ7drauNkzIBAcDlh48zqHjM3yU7ewX5aagCt9M33TKvsAJDRv7UWnH/8EWtefD1RsT3LAI2hsQWuYZYtisV7GExs X-Gm-Message-State: AOJu0YyN3YW0iEeq20gwpTNcjFig6dXA1vbhdemJ+kqVRZArkMlCL8Cj 97dUsPc8oaLX/WU13lJy9kWxSC6sUOTV8DK9wZloPw8yqnBOCxCUFsbmWJ5zpiU= X-Google-Smtp-Source: AGHT+IGYIdyL3I1JnwUVfQo4oAyFcYwPdf4bNyN/KdL9IsI3rZiBMwNwH2ZruyyHUHfolR/1azJbfQ== X-Received: by 2002:a05:600c:4751:b0:426:62c6:4341 with SMTP id 5b1f17b1804b1-427dc52e886mr46427815e9.20.1721643173518; Mon, 22 Jul 2024 03:12:53 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:12:53 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 05/17] perf: cs-etm: Only save valid trace IDs into files Date: Mon, 22 Jul 2024 11:11:47 +0100 Message-Id: <20240722101202.26915-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark This isn't a bug because Perf always masks with CORESIGHT_TRACE_ID_VAL_MASK before using these values, but to avoid it looking like it could be, make an effort to not save bad values. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- tools/perf/arch/arm/util/cs-etm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index b0118546cd4d..14b8afabce3a 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -643,7 +643,8 @@ static bool cs_etm_is_ete(struct perf_pmu *cs_etm_pmu, = struct perf_cpu cpu) =20 static __u64 cs_etm_get_legacy_trace_id(struct perf_cpu cpu) { - return CORESIGHT_LEGACY_CPU_TRACE_ID(cpu.cpu); + /* Wrap at 48 so that invalid trace IDs aren't saved into files. */ + return CORESIGHT_LEGACY_CPU_TRACE_ID(cpu.cpu % 48); } =20 static void cs_etm_save_etmv4_header(__u64 data[], struct auxtrace_record = *itr, struct perf_cpu cpu) --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D832A16C859 for ; Mon, 22 Jul 2024 10:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643181; cv=none; b=YduZ13Yg21H4XGotPxiCJQZECyCpOP8lZ2RSq2rlfHo4DP/uxs6UtIbQTwkHBB8mJ8MY6IU+jEVRTrNRwT3KhyhZa2hqd0N+HE0LWTBHlVJIc5FsYQhdrshKIYlzmrKOJmHGaMVTzQ+EwwSrJALqmgLrAA/3+yfQZfUMXxIhuB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643181; c=relaxed/simple; bh=XT39TjSxiIsMmcR7UhloJZYE5dtXfwwNZEtdfRmWDVk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j+PBL1GewgzgiodyV4oybcG+O6a37zh8cQevA+7FBD+DfjA8OZPrKVWrtEg+vL7HRm83wwnF22565qLn05TrI03yGFzM5HqwvGQlfVsnzkQEQCbXIUREdyYCN+JlPAw9fq6+FyQlSK7N6qRJgn+/lAZEbRCpvjshWdQzjd2KR2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TBngjdtK; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TBngjdtK" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42793fc0a6dso29267165e9.0 for ; Mon, 22 Jul 2024 03:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643178; x=1722247978; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U+T7+pXiF7yMfs8Ra5yXYj2ssuWqnilsrImn3ybG45I=; b=TBngjdtKa00dYVeCNBiGp3+4VW6pjeolvouKGTObcrzf7WB6MRc+aOD75HRDnbo34i wRKmpbmbpgx6rCgkDgVVUFJUvAlB4t88mEJL01sc7zyugvMfoWbYQdIQR+ETrh0wy241 YC4U7P/kQIc9hTjlxLA3HXkamxucwJB0HI3n8MQuHr67ix45yl7svFrkvucdJ8AqugDM 9PJdmmAsSe7lJncTBsEZYUW21AAiSyxmtkfhikGLUhA4Sa6bX7hmoRBhGaoSYk4EUCOF vKtSUyQPhflXty3LsdLQWz6yAXLhiPxokn80/0UWFk+Zz+uxx/T4gas3eAyPBmStAwRa ny7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643178; x=1722247978; h=content-transfer-encoding:mime-version: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=U+T7+pXiF7yMfs8Ra5yXYj2ssuWqnilsrImn3ybG45I=; b=fVw45BQUF+dAWfbVs2FeezeTN49/BoZ8ljo9kgvQ5qZy+IhdfUlGytfMU4+4GCQxeb VY/jbB59gpAVDmHGlDS26G91vxpHw1shPqIuOkskLi7vw9CwjSMyCJbWdpSdNRvgUMPl g+4njJL+9pilhS9Mjl7i3yubFbfPSiRpD2eDriuUfGlGvIVGvDryXsAWJuQj8ddYd09/ myTUOpB4SEpvMhDTydWNPy545lOu5f1yralKln1sXjG8xsVsYQPDbudJPj+aAQDY6yOe IqY/DWoLZT/Npd9miS5lD7QtOwzqoZ7LIGvy1oSC+t1osyraeQNwlKPRdUr8+wuX8QMj nsAw== X-Forwarded-Encrypted: i=1; AJvYcCWs1S19RdQjJAySoXYqIMmhiiDr/IQGXDV9qQHEN5iAftGx3OhhlIzMZ2i5Iq7OkV9P3Cb2zAs2s9cEhLqtBUIYt0TNQbRdzCVudfvC X-Gm-Message-State: AOJu0YwrNMAsk80zQHwtQwBI4X8bof7oIcWdwZPQ3QH6nwLteU4xIxay CUgYavKmKl4T1hdmtEz/r4yqMRcs++yYs+zOMDqVfXcztQ25QR190Sl+xcm9OkQ= X-Google-Smtp-Source: AGHT+IHyNXXfk/HrfhveqJ02cNHdCkruCeq4FRjg04KZTngcUohmX3j/WQtGWJDIrrIRKyBl7EzFjA== X-Received: by 2002:a05:600c:1906:b0:426:6379:3b56 with SMTP id 5b1f17b1804b1-427dc529091mr40404035e9.15.1721643178308; Mon, 22 Jul 2024 03:12:58 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:12:58 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 06/17] perf: cs-etm: Support version 0.1 of HW_ID packets Date: Mon, 22 Jul 2024 11:11:48 +0100 Message-Id: <20240722101202.26915-7-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark v0.1 HW_ID packets have a new field that describes which sink each CPU writes to. Use the sink ID to link trace ID maps to each other so that mappings are shared wherever the sink is shared. Also update the error message to show that overlapping IDs aren't an error in per-thread mode, just not supported. In the future we can use the CPU ID from the AUX records, or watch for changing sink IDs on HW_ID packets to use the correct decoders. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- tools/include/linux/coresight-pmu.h | 17 +++-- tools/perf/util/cs-etm.c | 100 +++++++++++++++++++++++++--- 2 files changed, 103 insertions(+), 14 deletions(-) diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/core= sight-pmu.h index 51ac441a37c3..89b0ac0014b0 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -49,12 +49,21 @@ * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. * Used to associate a CPU with the CoreSight Trace ID. * [07:00] - Trace ID - uses 8 bits to make value easy to read in file. - * [59:08] - Unused (SBZ) - * [63:60] - Version + * [39:08] - Sink ID - as reported in /sys/bus/event_source/devices/cs_etm= /sinks/ + * Added in minor version 1. + * [55:40] - Unused (SBZ) + * [59:56] - Minor Version - previously existing fields are compatible with + * all minor versions. + * [63:60] - Major Version - previously existing fields mean different thi= ngs + * in new major versions. */ #define CS_AUX_HW_ID_TRACE_ID_MASK GENMASK_ULL(7, 0) -#define CS_AUX_HW_ID_VERSION_MASK GENMASK_ULL(63, 60) +#define CS_AUX_HW_ID_SINK_ID_MASK GENMASK_ULL(39, 8) =20 -#define CS_AUX_HW_ID_CURR_VERSION 0 +#define CS_AUX_HW_ID_MINOR_VERSION_MASK GENMASK_ULL(59, 56) +#define CS_AUX_HW_ID_MAJOR_VERSION_MASK GENMASK_ULL(63, 60) + +#define CS_AUX_HW_ID_MAJOR_VERSION 0 +#define CS_AUX_HW_ID_MINOR_VERSION 1 =20 #endif diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 7cce58dca33c..b11b0cae608e 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -118,6 +118,12 @@ struct cs_etm_queue { struct cs_etm_traceid_queue **traceid_queues; /* Conversion between traceID and metadata pointers */ struct intlist *traceid_list; + /* + * Same as traceid_list, but traceid_list may be a reference to another + * queue's which has a matching sink ID. + */ + struct intlist *own_traceid_list; + u32 sink_id; }; =20 static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm); @@ -142,6 +148,7 @@ static int cs_etm__metadata_set_trace_id(u8 trace_chan_= id, u64 *cpu_metadata); (queue_nr << 16 | trace_chan_id) #define TO_QUEUE_NR(cs_queue_nr) (cs_queue_nr >> 16) #define TO_TRACE_CHAN_ID(cs_queue_nr) (cs_queue_nr & 0x0000ffff) +#define SINK_UNSET ((u32) -1) =20 static u32 cs_etm__get_v7_protocol_version(u32 etmidr) { @@ -241,7 +248,16 @@ static int cs_etm__insert_trace_id_node(struct cs_etm_= queue *etmq, int err; =20 if (curr_cpu_data[CS_ETM_CPU] !=3D cpu_metadata[CS_ETM_CPU]) { - pr_err("CS_ETM: map mismatch between HW_ID packet CPU and Trace ID\n"); + /* + * With > CORESIGHT_TRACE_IDS_MAX ETMs, overlapping IDs + * are expected (but not supported) in per-thread mode, + * rather than signifying an error. + */ + if (etmq->etm->per_thread_decoding) + pr_err("CS_ETM: overlapping Trace IDs aren't currently supported in pe= r-thread mode\n"); + else + pr_err("CS_ETM: map mismatch between HW_ID packet CPU and Trace ID\n"); + return -EINVAL; } =20 @@ -326,6 +342,64 @@ static int cs_etm__process_trace_id_v0(struct cs_etm_a= uxtrace *etm, int cpu, return cs_etm__metadata_set_trace_id(trace_chan_id, cpu_data); } =20 +static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int = cpu, + u64 hw_id) +{ + struct cs_etm_queue *etmq =3D cs_etm__get_queue(etm, cpu); + int ret; + u64 *cpu_data; + u32 sink_id =3D FIELD_GET(CS_AUX_HW_ID_SINK_ID_MASK, hw_id); + u8 trace_id =3D FIELD_GET(CS_AUX_HW_ID_TRACE_ID_MASK, hw_id); + + /* + * Check sink id hasn't changed in per-cpu mode. In per-thread mode, + * let it pass for now until an actual overlapping trace ID is hit. In + * most cases IDs won't overlap even if the sink changes. + */ + if (!etmq->etm->per_thread_decoding && etmq->sink_id !=3D SINK_UNSET && + etmq->sink_id !=3D sink_id) { + pr_err("CS_ETM: mismatch between sink IDs\n"); + return -EINVAL; + } + + etmq->sink_id =3D sink_id; + + /* Find which other queues use this sink and link their ID maps */ + for (unsigned int i =3D 0; i < etm->queues.nr_queues; ++i) { + struct cs_etm_queue *other_etmq =3D etm->queues.queue_array[i].priv; + + /* Different sinks, skip */ + if (other_etmq->sink_id !=3D etmq->sink_id) + continue; + + /* Already linked, skip */ + if (other_etmq->traceid_list =3D=3D etmq->traceid_list) + continue; + + /* At the point of first linking, this one should be empty */ + if (!intlist__empty(etmq->traceid_list)) { + pr_err("CS_ETM: Can't link populated trace ID lists\n"); + return -EINVAL; + } + + etmq->own_traceid_list =3D NULL; + intlist__delete(etmq->traceid_list); + etmq->traceid_list =3D other_etmq->traceid_list; + break; + } + + cpu_data =3D get_cpu_data(etm, cpu); + ret =3D cs_etm__insert_trace_id_node(etmq, trace_id, cpu_data); + if (ret) + return ret; + + ret =3D cs_etm__metadata_set_trace_id(trace_id, cpu_data); + if (ret) + return ret; + + return 0; +} + static int cs_etm__metadata_get_trace_id(u8 *trace_chan_id, u64 *cpu_metad= ata) { u64 cs_etm_magic =3D cpu_metadata[CS_ETM_MAGIC]; @@ -414,10 +488,10 @@ static int cs_etm__process_aux_output_hw_id(struct pe= rf_session *session, =20 /* extract and parse the HW ID */ hw_id =3D event->aux_output_hw_id.hw_id; - version =3D FIELD_GET(CS_AUX_HW_ID_VERSION_MASK, hw_id); + version =3D FIELD_GET(CS_AUX_HW_ID_MAJOR_VERSION_MASK, hw_id); =20 /* check that we can handle this version */ - if (version > CS_AUX_HW_ID_CURR_VERSION) { + if (version > CS_AUX_HW_ID_MAJOR_VERSION) { pr_err("CS ETM Trace: PERF_RECORD_AUX_OUTPUT_HW_ID version %d not suppor= ted. Please update Perf.\n", version); return -EINVAL; @@ -442,7 +516,10 @@ static int cs_etm__process_aux_output_hw_id(struct per= f_session *session, return -EINVAL; } =20 - return cs_etm__process_trace_id_v0(etm, cpu, hw_id); + if (FIELD_GET(CS_AUX_HW_ID_MINOR_VERSION_MASK, hw_id) =3D=3D 0) + return cs_etm__process_trace_id_v0(etm, cpu, hw_id); + + return cs_etm__process_trace_id_v0_1(etm, cpu, hw_id); } =20 void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, @@ -882,12 +959,14 @@ static void cs_etm__free_queue(void *priv) cs_etm_decoder__free(etmq->decoder); cs_etm__free_traceid_queues(etmq); =20 - /* First remove all traceID/metadata nodes for the RB tree */ - intlist__for_each_entry_safe(inode, tmp, etmq->traceid_list) - intlist__remove(etmq->traceid_list, inode); + if (etmq->own_traceid_list) { + /* First remove all traceID/metadata nodes for the RB tree */ + intlist__for_each_entry_safe(inode, tmp, etmq->own_traceid_list) + intlist__remove(etmq->own_traceid_list, inode); =20 - /* Then the RB tree itself */ - intlist__delete(etmq->traceid_list); + /* Then the RB tree itself */ + intlist__delete(etmq->own_traceid_list); + } =20 free(etmq); } @@ -1081,7 +1160,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(void) * has to be made for each packet that gets decoded, optimizing access * in anything other than a sequential array is worth doing. */ - etmq->traceid_list =3D intlist__new(NULL); + etmq->traceid_list =3D etmq->own_traceid_list =3D intlist__new(NULL); if (!etmq->traceid_list) goto out_free; =20 @@ -1113,6 +1192,7 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace= *etm, etmq->queue_nr =3D queue_nr; queue->cpu =3D queue_nr; /* Placeholder, may be reset to -1 in per-thread= mode */ etmq->offset =3D 0; + etmq->sink_id =3D SINK_UNSET; =20 return 0; } --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19F6316D4CB for ; Mon, 22 Jul 2024 10:13:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643186; cv=none; b=fZs4q74O1uFXwEo0sR24CBobQLCYZsAG3VCtZcbV8qIeUqjv8dBNuHtEyF0aUvy0PoCdD4R/PVDPetH8UfcnLI4x50tyeXG7f3jh+RTPveOUV5nmODUq1fF+YHwTagPzWG9+92ljhQ+gVIq5pUPCWbqaEjDZHw6znjabTzjXnKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643186; c=relaxed/simple; bh=HZ25YlbVFoFr5t4xgKqcTOie+si0xupMEcbp2D/SGlY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HpEcnGkF0xF6aEGyHDhGoA0O+l6m+bo5t0SA5skTIZWU5PLLMKm+Q93XGE66gunK64drV/ehcMW48VWM0r7VQimG8r8afOLFAZg/F3CRax71etCjYoY3mwL82i1iiPY6V5FNct7ScH2ce5XDvcQ7w/Gc9ELEC3cPJ8GaiX/4WSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=X63YxQjr; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="X63YxQjr" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2ef2cb7d562so12975361fa.3 for ; Mon, 22 Jul 2024 03:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643183; x=1722247983; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=22WWYz2tUVGtuasGpu3eN+nV++HsU5p2cQus0dyDbEs=; b=X63YxQjrWeJVaglm3si75C5ZH6zjeHxKrq/dnCGPKmvuu/x30cWZpXbLnFnoFcEMm5 8grVh7Xc1GCgXAqDKiU0fkRayj+n4VWzhnYhdJ1AUDibdrJbBD5a6HyJnp2YC8PLYgFW ebjTMbg+pHAmSnl3o+c9YDA7KkwCDhiO2DZKgQI/tFyeBelqHj0Q2p33dboJbPt19nSS mdt2r3bGfkv2ERUNgGe8xrpBNxzuwNUzjoXGBcn/7CxVUiJfN7eDCYiLqoz5oJkcICaF RsBtDiMBq7/6+bGgyxkp2FnVIiQlpHYH1z4Nd4UbdQl5M1rSA3gw1wkLGOpNz47F/J7l h3yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643183; x=1722247983; h=content-transfer-encoding:mime-version: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=22WWYz2tUVGtuasGpu3eN+nV++HsU5p2cQus0dyDbEs=; b=g135TH1d9jwpEnM1n20gOXaAwY5RJdtkRW3EkUtE5bgRVN/tzVMyjLzOC5SC5BTrwJ a//E4sfNd4Z2S0pBmUpj/Vd8F4svCcl+ZjfJVh6xLI81UAsKxD270ptQa5fF3QBQ5nAg yIM6rg2vNL8ne34Ao0eHVFpfL+0oHtuR7r1Nd9YeqlBKZRzvdmMFqH2Bc1dDhpzsdC6E Fzb8XYeCCQQBORMqX2cbLy+pHHTHpM7/E1xhCFdLk/3tF+j/AsT53C5k4hs9vfDgBpcp s6J/YJ1z/3s1fWel3KnTVGgXo2t+chn1uZBCeh9UaEr0FQispMIuUsPEYSTxFYWv3HXe CimA== X-Forwarded-Encrypted: i=1; AJvYcCUBb/nYpd7TCVang9DNy2st1u3INJkvRQs6AgkJ7RWsNFXDrJ8hy6QUA5Nb1cGC4RPFCzul6opSJZD9BZq6rcjW2g585m2tNT7bJUQM X-Gm-Message-State: AOJu0YzdUT5XVY9reWJAg6diuPpAecXMCtO5/JtdlZ9Sv0QrF9F5ETLh eQOqrIRBT55c4ADdYavdnvhNCuYD+k6kfaQ1VufyA5/rnSjAZtmxOIwp1RlBEgA= X-Google-Smtp-Source: AGHT+IGUJY+LiEZGDA07U+K/qkfthMc8al4V942XRBG+OJuyhgexjuNQfTeA3mz1e0/Ia/+b/eMfWw== X-Received: by 2002:a2e:8059:0:b0:2ef:24e0:6338 with SMTP id 38308e7fff4ca-2ef24e06429mr37487261fa.27.1721643183124; Mon, 22 Jul 2024 03:13:03 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:02 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 07/17] perf: cs-etm: Print queue number in raw trace dump Date: Mon, 22 Jul 2024 11:11:49 +0100 Message-Id: <20240722101202.26915-8-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark Now that we have overlapping trace IDs it's also useful to know what the queue number is to be able to distinguish the source of the trace so print it inline. Hide it behind the -v option because it might not be obvious to users what the queue number is. Signed-off-by: James Clark Signed-off-by: James Clark Acked-by: Suzuki K Poulose Reviewed-by: Mike Leach --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 ++-- tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 2 +- tools/perf/util/cs-etm.c | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.c index d49c3e9c7c21..b78ef0262135 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -41,7 +41,7 @@ const u32 INSTR_PER_NS =3D 10; =20 struct cs_etm_decoder { void *data; - void (*packet_printer)(const char *msg); + void (*packet_printer)(const char *msg, void *data); bool suppress_printing; dcd_tree_handle_t dcd_tree; cs_etm_mem_cb_type mem_access; @@ -202,7 +202,7 @@ static void cs_etm_decoder__print_str_cb(const void *p_= context, const struct cs_etm_decoder *decoder =3D p_context; =20 if (p_context && str_len && !decoder->suppress_printing) - decoder->packet_printer(msg); + decoder->packet_printer(msg, decoder->data); } =20 static int diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.h index 272c2efe78ee..12c782fa6db2 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -60,7 +60,7 @@ struct cs_etm_trace_params { =20 struct cs_etm_decoder_params { int operation; - void (*packet_printer)(const char *msg); + void (*packet_printer)(const char *msg, void *data); cs_etm_mem_cb_type mem_acc_cb; bool formatted; bool fsyncs; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index b11b0cae608e..6298a5c7a651 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -762,15 +762,22 @@ static void cs_etm__packet_swap(struct cs_etm_auxtrac= e *etm, } } =20 -static void cs_etm__packet_dump(const char *pkt_string) +static void cs_etm__packet_dump(const char *pkt_string, void *data) { const char *color =3D PERF_COLOR_BLUE; int len =3D strlen(pkt_string); + struct cs_etm_queue *etmq =3D data; + char queue_nr[64]; + + if (verbose) + snprintf(queue_nr, sizeof(queue_nr), "Qnr:%d; ", etmq->queue_nr); + else + queue_nr[0] =3D '\0'; =20 if (len && (pkt_string[len-1] =3D=3D '\n')) - color_fprintf(stdout, color, " %s", pkt_string); + color_fprintf(stdout, color, " %s%s", queue_nr, pkt_string); else - color_fprintf(stdout, color, " %s\n", pkt_string); + color_fprintf(stdout, color, " %s%s\n", queue_nr, pkt_string); =20 fflush(stdout); } --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C50316D4E9 for ; Mon, 22 Jul 2024 10:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643191; cv=none; b=QzxNMyvb3LqpI93BS0mIw6zT8HAqiyTgmFyWWG31xGsZJ/h7E6gGB629waF6pIaoetvYjsxnK5x8ePmnvLmrKmFCUn9fuhzuExlgq4Ew7to2H+Am2HdFeYB7fD2PIIS/41Blz+FQbR60L1eQ/WeMZm44vJGHr6TdgR1btTVHaXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643191; c=relaxed/simple; bh=Rmx9udRvRCv0Ng1SFnELTkKSgQvIMsfgbQtlWF36fnk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LxAtIWYblbV6h8BrWbETmjqQihqWK/gBRj8WSuCq6IXxmYonztBsPsQt8AFLrxtNlWAaL1fdTcaYZYgaJmfm++aJ6YRFn9eTYOnPXw4lObGwNhUqzniPCMvdfKjlxdvA5ugCdh4Aw7Gq4rDumuQ149M3YMaYnQoQKCoiaXlEXx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=BmfyZEzC; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BmfyZEzC" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4266f344091so29867285e9.0 for ; Mon, 22 Jul 2024 03:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643188; x=1722247988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sPkIquw077gYIEvctFCCllwMLWJh43EU4ppM2MPUVYk=; b=BmfyZEzCdg1doVGaUlA3QseTK8BWzyDlbinbMWNvENfS1XuV9FQvvSttYGroFT2UTJ uWxOPHAxZWQzyhf/1G5sdUzqrW+YGmW+U9+STytogMyuKLw2TV7UTot7nCZOw+R4R+XV pnWhdBn1J3kSxBKPj3K8z4Mbd3glRciPiczK8Sm7+3r9Kj7ks7aSyjwMTV6M93VMEhIs yVlnDizHgkt7Ij1meNrD/MbIXbkGnqbIGWUj0Si5XBqfhZxOvurQiUn7s5kc/KptpbXl o70UkHj19fe3FNkqjCaJyJmPQW7y5zNb5k26vAuqIATJAOHW1X5fjev4P674WQLnulWS uonQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643188; x=1722247988; h=content-transfer-encoding:mime-version: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=sPkIquw077gYIEvctFCCllwMLWJh43EU4ppM2MPUVYk=; b=WiJ0MNP8skOmODqGctIFE2wAcDR+CRAXUXKSiSu+iumnKbmp10Cgofs0CruLYR9kio zTKX5pE8wnMxwNIqb/aQIG2V1ALCxUoarNCXT+ozFKQ97eMYMXyr+TCMGCuGDSDMVMHP lhdLWDF17XJOH5x95k0041ysHbz8RsD2Cz+1RHpDvx5kQqoehU8DI5KYG9AfZYRRBI8D +7ArlAncO/K6IMw+G882aYlXAwKabcYkUjJHotKk6Z5OqzhDwlgaU87Qg00D377ffSzK nxybtpKWig0DL4MYQ0+QC1SEIWEeeWjxTvASPVcKbAwDGpUNrM+oWunevUO9eL//gvng 7UmA== X-Forwarded-Encrypted: i=1; AJvYcCWkIWkSxmoDoA6WXChhjOZ1O0LXldpKnuold24aqE27Y8tL/PTau8X3c+t7Z3OT/K2r6L4Puf6IictU+gnT+y5fxxza7qhADf+NjU5b X-Gm-Message-State: AOJu0YxlDXH4RGWFLaWGtPzYxwX2GPPq8td1VkPxNb+fXwNmR1dfCGmQ CdSyYM9+Y6Hcd6h6U2GoVFEtGMqbZaawpkXJt9RKJUu5GdQyta1HDzCu3tZnH/I= X-Google-Smtp-Source: AGHT+IECJrbMk+SVuzf8P8M9gfHzpogypG1Je+ADnodsc8mmHRR3JgaHvZvv6i1KdtxQ2O7FGguNRw== X-Received: by 2002:a05:600c:524b:b0:426:6b85:bafb with SMTP id 5b1f17b1804b1-427dc529177mr44503555e9.20.1721643187954; Mon, 22 Jul 2024 03:13:07 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:07 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 08/17] perf: cs-etm: Add runtime version check for OpenCSD Date: Mon, 22 Jul 2024 11:11:50 +0100 Message-Id: <20240722101202.26915-9-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark OpenCSD is dynamically linked so although there is a build time check, at runtime the user might still have the wrong version. To avoid hard to debug errors, add a runtime version check. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- tools/build/feature/test-libopencsd.c | 4 ++-- tools/perf/Makefile.config | 2 +- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 13 +++++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + tools/perf/util/cs-etm-decoder/cs-etm-min-version.h | 13 +++++++++++++ tools/perf/util/cs-etm.c | 3 +++ 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tools/perf/util/cs-etm-decoder/cs-etm-min-version.h diff --git a/tools/build/feature/test-libopencsd.c b/tools/build/feature/te= st-libopencsd.c index 4cfcef9da3e4..d092a0c662f4 100644 --- a/tools/build/feature/test-libopencsd.c +++ b/tools/build/feature/test-libopencsd.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include "cs-etm-decoder/cs-etm-min-version.h" =20 /* * Check OpenCSD library version is sufficient to provide required features */ -#define OCSD_MIN_VER ((1 << 16) | (2 << 8) | (1)) #if !defined(OCSD_VER_NUM) || (OCSD_VER_NUM < OCSD_MIN_VER) -#error "OpenCSD >=3D 1.2.1 is required" +#error "OpenCSD minimum version (OCSD_MIN_VER) not met." #endif =20 int main(void) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 7f1e016a9253..2d21be42820e 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -141,7 +141,7 @@ endif ifdef CSLIBS LIBOPENCSD_LDFLAGS :=3D -L$(CSLIBS) endif -FEATURE_CHECK_CFLAGS-libopencsd :=3D $(LIBOPENCSD_CFLAGS) +FEATURE_CHECK_CFLAGS-libopencsd :=3D $(LIBOPENCSD_CFLAGS) -I$(src-perf)/ut= il FEATURE_CHECK_LDFLAGS-libopencsd :=3D $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS) =20 # for linking with debug library, run like: diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.c index b78ef0262135..5e1b4503aab1 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -16,6 +16,7 @@ =20 #include "cs-etm.h" #include "cs-etm-decoder.h" +#include "cs-etm-min-version.h" #include "debug.h" #include "intlist.h" =20 @@ -835,3 +836,15 @@ const char *cs_etm_decoder__get_name(struct cs_etm_dec= oder *decoder) { return decoder->decoder_name; } + +int cs_etm_decoder__check_ver(void) +{ + if (ocsd_get_version() < OCSD_MIN_VER) { + pr_err("OpenCSD >=3D %d.%d.%d is required\n", OCSD_MIN_MAJOR, + OCSD_MIN_MINOR, + OCSD_MIN_PATCH); + return -EINVAL; + } + + return 0; +} diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/u= til/cs-etm-decoder/cs-etm-decoder.h index 12c782fa6db2..2ec426ee16dc 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -107,5 +107,6 @@ int cs_etm_decoder__get_packet(struct cs_etm_packet_que= ue *packet_queue, =20 int cs_etm_decoder__reset(struct cs_etm_decoder *decoder); const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder); +int cs_etm_decoder__check_ver(void); =20 #endif /* INCLUDE__CS_ETM_DECODER_H__ */ diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-min-version.h b/tools/pe= rf/util/cs-etm-decoder/cs-etm-min-version.h new file mode 100644 index 000000000000..c69597e9d0af --- /dev/null +++ b/tools/perf/util/cs-etm-decoder/cs-etm-min-version.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef INCLUDE__CS_ETM_MIN_VERSION_H__ +#define INCLUDE__CS_ETM_MIN_VERSION_H__ + +#define OCSD_MIN_MAJOR 1 +#define OCSD_MIN_MINOR 2 +#define OCSD_MIN_PATCH 1 + +#define OCSD_MIN_VER ((OCSD_MIN_MAJOR << 16) | \ + (OCSD_MIN_MINOR << 8) | \ + (OCSD_MIN_PATCH)) + +#endif /* INCLUDE__CS_ETM_MIN_VERSION_H__ */ diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 6298a5c7a651..3b4a5d5ca25b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -3375,6 +3375,9 @@ int cs_etm__process_auxtrace_info_full(union perf_eve= nt *event, u64 *ptr =3D NULL; u64 **metadata =3D NULL; =20 + if (cs_etm_decoder__check_ver()) + return -EINVAL; + /* First the global part */ ptr =3D (u64 *) auxtrace_info->priv; num_cpu =3D ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A13516D9A4 for ; Mon, 22 Jul 2024 10:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643196; cv=none; b=jvklz+ugaXNuKKpahFjkKtSwQK+HEi8m45Sp2u1DD/kxL40mcDSJFUMtg7k/q0TrmXfPBXWt7e6bxeN9mmKIFVdJYiAhcAGVi3NGdZmVKioi2NhhkNj3VNUpulb9GgyXT0Z0DDV/Z7v3ljrkN5oK3X0WEBG7c1Y+2OMjxnITnb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643196; c=relaxed/simple; bh=wVHh6zOEtD5JgYpRaWP8ByjQrHdnbNe5JxysK+W/6X8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AmQ2kcd6vDpY7dVhPh2qK6gWYq268YZjzTHTcgjcpLTn4qp3o9gsjUMXysTKh7+1OYhAzXyzORZa4hk8nL5cZ4fjJbpwICxvmjLSFm9dZX1dOgUQn5PehiWJzkbstdSeo1/TKDL5kxx2uQn33o2zw3XqlDjfWPhSHYs0LA2hV1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=wFdzV8iL; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wFdzV8iL" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-427db004e36so15966635e9.3 for ; Mon, 22 Jul 2024 03:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643193; x=1722247993; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CtaJjK7rrgJVkNfrm1RPI3wUUBorSunZ8bK+jPbC78c=; b=wFdzV8iLaDLWXZvF0L2CFYTvhfkZ6kbUNXf7GltKzu+n3n55gHaz+rNpTfEH0PE+ZD K5gzH5olc1CTPHoHakwFZ0cmH8HlpLGQAROfHIeHHxpovh9V6dBa8kSalxofDPaIZWPF B9m00vZD3scaZlTDi+dTZawWSGks7de6TtrDas8PcKu3VcO+77zpCUuF/0X0hrDD7aHj FywkTJf4qfNRESbmfg9ehjli6PxAEwdws2Re6+ijtW4ISxg2Kl3s1WNQgmQWDW+JK1QI q/J4I3jQVpvffZJdpTGSrFcatdeAMC9P4dIt4RAXRVBcKUh1y+hf05wC65JGxJynePio kWgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643193; x=1722247993; h=content-transfer-encoding:mime-version: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=CtaJjK7rrgJVkNfrm1RPI3wUUBorSunZ8bK+jPbC78c=; b=I1NXyDUHd63lnhsgIPorsQeIX2ogOGPKnrZADhdMLQTWUDIK/fOOYJnIJXO78b93+q 5nq8VBO1xG8UYtIwwdprGJboQ2CuD7yNYGGr6qUx8m+yZBjnHSZ7TLr7/NVdhk07sj13 e7SQzJa6dTopoNth3i/NUHhN0EGXtXjnHjtfSMxPcP/z0zArQX5C68eAjBUBn1Yn5xD+ n3c94Fvw70hDT6X1U9OjKHPKUuxnjGZCWtN/q1ywQ728W2K+LR+IoTU3uvPlaiBgNxB8 iJroFt3Tb+jzSVXSiZJQeHTbjZqoTZan1vVyHftSG/TAiQOxcSh4McjNLin8U2LSIe6b NLbg== X-Forwarded-Encrypted: i=1; AJvYcCW656rvERVn2zhgbumMNR4ouVW9XzwGJP1USnCMZ/3e4BrzQ/nDPg063CI84CEtH/Luyf/5Su1P04BdiFOXWs5hdQPOtnXMmQF02TdX X-Gm-Message-State: AOJu0YySviPc9J9l3TV613X28+r0USke3fe/O9eKLvcC8KuF6tu83/7P XHddI0ETl02Zv/ABGyY6DWGF3ftG+fopr36swmpsU+pcXlV4MRSfHKgNe1BqCzg= X-Google-Smtp-Source: AGHT+IGdhd7RpxJePLbZIYhR6xs+qj7oZ8Lfr0TNgtXBBhZbnw2zVwMKW7uEaoI3NiSjTwpc8kM/Ag== X-Received: by 2002:a05:600c:5493:b0:426:6ea2:31af with SMTP id 5b1f17b1804b1-427dc5753a9mr33453755e9.37.1721643192769; Mon, 22 Jul 2024 03:13:12 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:12 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 09/17] coresight: Remove unused ETM Perf stubs Date: Mon, 22 Jul 2024 11:11:51 +0100 Message-Id: <20240722101202.26915-10-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark This file is never included anywhere if CONFIG_CORESIGHT is not set so they are unused and aren't currently compile tested with any config so remove them. Reviewed-by: Anshuman Khandual Reviewed-by: Mike Leach Signed-off-by: James Clark Tested-by: Leo Yan Tested-by: Ganapatrao Kulkarni Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-etm-perf.h | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwt= racing/coresight/coresight-etm-perf.h index bebbadee2ceb..744531158d6b 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -62,7 +62,6 @@ struct etm_event_data { struct list_head * __percpu *path; }; =20 -#if IS_ENABLED(CONFIG_CORESIGHT) int etm_perf_symlink(struct coresight_device *csdev, bool link); int etm_perf_add_symlink_sink(struct coresight_device *csdev); void etm_perf_del_symlink_sink(struct coresight_device *csdev); @@ -77,23 +76,6 @@ static inline void *etm_perf_sink_config(struct perf_out= put_handle *handle) int etm_perf_add_symlink_cscfg(struct device *dev, struct cscfg_config_desc *config_desc); void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *config_desc); -#else -static inline int etm_perf_symlink(struct coresight_device *csdev, bool li= nk) -{ return -EINVAL; } -int etm_perf_add_symlink_sink(struct coresight_device *csdev) -{ return -EINVAL; } -void etm_perf_del_symlink_sink(struct coresight_device *csdev) {} -static inline void *etm_perf_sink_config(struct perf_output_handle *handle) -{ - return NULL; -} -int etm_perf_add_symlink_cscfg(struct device *dev, - struct cscfg_config_desc *config_desc) -{ return -EINVAL; } -void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *config_desc) {} - -#endif /* CONFIG_CORESIGHT */ - int __init etm_perf_init(void); void etm_perf_exit(void); =20 --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3573A16D9C6 for ; Mon, 22 Jul 2024 10:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643200; cv=none; b=Kb3IPKrq5mNMQ84GDekTAXB7n+m/461oLjmb9vS7btDwJvgfahLNFbsM4KYYNW/ov26z2HtTHBPgq0ehAMfqlgOxcDIM1P5W3B3wrIM2Faul/bMwGIbwxzqnGkXi0Ss7JSySlIl2ayzOmmpr5DDTFxLOB9K5GwqrFwOewY08Q0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643200; c=relaxed/simple; bh=NJv4Ip/0MGeUDqPRCBtTePKyAhBC1HwlgSVGeLozqqE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GHqUMKjmywGtgUcTmZcrQkhC+n5d7Nkr7nS9fXoQoWxxrQ/rvMjbhyFGlZzJsWVZy5W+Hrxo/OtsOP1rkFuUoEnDGQIv1Iz1U5S8ylyZztpk0pMawzQp4Tp4P20ANTsnGJYaOTi/IbsMedYLSYyP8L/s80F0bKpy8SBJ7ocGpyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=crRQF7Ct; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="crRQF7Ct" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-427cede1e86so28794685e9.0 for ; Mon, 22 Jul 2024 03:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643197; x=1722247997; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9CvKA9Oo8oUAGLDUMUBH2byBqwwnuDLfYbLv1IHZER0=; b=crRQF7CtbV82vfsxE3bSUfs20cH3fmGVf295mQ1iNhPA426ELPz18fSpu1HgUNpMTx 4hZGUjHf+UAaGpMJDnmtGxSRuCDDkygyn8EeuTuPC8N94qkS2I6fHbp0HQ3IgclpOoEQ RotcYcaYTvqcwsnPZCrWLWk1gxSa+OGSo/lKreDqZmRS64kKaaxIPvN5a+Jb2MCVPRyW LtKPfTBlWI9UZk1ALE8FXKMpooT9y+qSQJSclB7MH+KH3LPO8pPKKwoCVxb8mlu+Bj+S idmqzf3D5Me4l1MNzwwruTZPSgzVN1QGNXpgH4deNeWoIm+fZN3RCyGmiUd+rqO6/y1V Dhww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643197; x=1722247997; h=content-transfer-encoding:mime-version: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=9CvKA9Oo8oUAGLDUMUBH2byBqwwnuDLfYbLv1IHZER0=; b=e6BIZ2whGs2QiU2FQu4HGeO2w6aQ4zC+BpkKxkNoFyYb36kWBthnl42yDNTeKGfwV9 aYldP0r/u1UDrXc9L8wraQETa0Fr+5g9PTrkYwKXa8KuS2tY0e9cz7D4GsUUF4KCUamJ Kj1nDHaA0tbnmR3vyYUnE7wZYl7rYHoIFgR5/dKIZv73A4CdHDTf07hnUm8h2miP3MJs E3SeE/ToT/lGQ8OdPZfAB6VOcr/UVeYwbjRxewxuGTLCEReqXKS1G22SzN2MhRZjcEGd m6B/eMUsIHnZ/RffkRLPf09Uo2/O/C2F8NYUNRJ0Ql8Y4BPw/2BZWwBp89gr0pBtlMO2 SD7A== X-Forwarded-Encrypted: i=1; AJvYcCUqFD3ROh7jt+6LhT6t17alQSrG985vF6leCJI/yrq76qpJzLRE2x84lTHnhwAnuyGi+OXg3WVNN2TpVSfm8ITrwnRJukPdCJbLthkM X-Gm-Message-State: AOJu0Yy7K1MADfGplbRlqx1O5q4dAonuVf+ht1seTJY655Xflow5Zytu fGhMc712MmOJVoESZ/chMk3C8wIp0AnV1lNQ+qYVfKndSeulUMQAlVhn378fZlw= X-Google-Smtp-Source: AGHT+IF7qS/l5dBLpir4Vw8LPazyz0x8s3+xWgLLeI6+jb9MqA3mHfayIPDgC0IjLcyLxDckxJt5aw== X-Received: by 2002:a05:600c:35d4:b0:426:593c:9361 with SMTP id 5b1f17b1804b1-427dc569cb0mr43200815e9.26.1721643197578; Mon, 22 Jul 2024 03:13:17 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:17 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 10/17] coresight: Clarify comments around the PID of the sink owner Date: Mon, 22 Jul 2024 11:11:52 +0100 Message-Id: <20240722101202.26915-11-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark "Process being monitored" and "pid of the process to monitor" imply that this would be the same PID if there were two sessions targeting the same process. But this is actually the PID of the process that did the Perf event open call, rather than the target of the session. So update the comments to make this clearer. Reviewed-by: Anshuman Khandual Reviewed-by: Mike Leach Signed-off-by: James Clark Tested-by: Leo Yan Tested-by: Ganapatrao Kulkarni Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++-- drivers/hwtracing/coresight/coresight-tmc.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtr= acing/coresight/coresight-tmc-etr.c index e75428fa1592..8962fc27d04f 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -36,7 +36,8 @@ struct etr_buf_hw { * etr_perf_buffer - Perf buffer used for ETR * @drvdata - The ETR drvdaga this buffer has been allocated for. * @etr_buf - Actual buffer used by the ETR - * @pid - The PID this etr_perf_buffer belongs to. + * @pid - The PID of the session owner that etr_perf_buffer + * belongs to. * @snaphost - Perf session mode * @nr_pages - Number of pages in the ring buffer. * @pages - Array of Pages in the ring buffer. @@ -1662,7 +1663,7 @@ static int tmc_enable_etr_sink_perf(struct coresight_= device *csdev, void *data) goto unlock_out; } =20 - /* Get a handle on the pid of the process to monitor */ + /* Get a handle on the pid of the session owner */ pid =3D etr_perf->pid; =20 /* Do not proceed if this device is associated with another session */ diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracin= g/coresight/coresight-tmc.h index c77763b49de0..2671926be62a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -171,8 +171,9 @@ struct etr_buf { * @csdev: component vitals needed by the framework. * @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. - * @pid: Process ID of the process being monitored by the session - * that is using this component. + * @pid: Process ID of the process that owns the session that is using + * this component. For example this would be the pid of the Perf + * process. * @buf: Snapshot of the trace data for ETF/ETB. * @etr_buf: details of buffer used in TMC-ETR * @len: size of the available trace for ETF/ETB. --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1570516DC01 for ; Mon, 22 Jul 2024 10:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643207; cv=none; b=NyZVtAVqrGg68Igh5G436xhGH42czD7hgOyJte98a8gBRyPMEaS8Ptw4D6evZ8uyYJgtabJ8Ul1LqP1ohOMAAZySorkemBjl4O32JHJDnV4lB3ZIJ25nq1MTj9rTlK5+AV+aafSQ9wK8YGHdSGgc/+gZ/z9fwDkWU8Xsgm2Sga0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643207; c=relaxed/simple; bh=pfTg193U03VQHBc5Y92Ek7wGOxzx6knrjLyWX8sWCXU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q1xD2iyclg7AnVV/hktOhjyyzCj0B/sw0LzWa6gyNJtXAtFaO5YQXBmNAS1dxq9k2nLaEH80E0qiRykmSnNJUCCV9B8U/ZOwMZA3aF09RBJ5FCh12sFdK/cwyKjUqbYHeyNWQjjacbCGeuPA7oLDdhSQW2SJJBs+7bHlR2fmNws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UltkTRvY; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UltkTRvY" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4266ed6c691so27083195e9.3 for ; Mon, 22 Jul 2024 03:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643202; x=1722248002; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ob3o88R/yxUBwonSp9vzDZCeFMZAfTzy7u2JCgClFSk=; b=UltkTRvYoPweB+lBm1Nc6gJvL9IwFYxxQSEQ2ihtZlq5wCvIDokdk/a9nMVW1H2pdW xHD2vmHt4Hn5EICc5S04x7nBrax2Uv8Fmgn6v1tAvtnV2LtrksbxtCYLTUyiYSslst5C X0tfk1v19ufyGILO6pmqi2k2FVqgCntRjnWuZTdSXDNaeGrjA/kTNYDo8l9zNhHGFlaX dSQrp/YcgKTjpIh5eh5qL0QPLMKvmB4KG3QkHcCT14IY1HVpuoqtGY61kKuNE7go9Qx5 b4xrDto743DFthLWHiqk2cJa8jBwykioB2SnMdonK7ZwwMbrRVZQC6tZ9giQQZHJR/L0 37LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643202; x=1722248002; h=content-transfer-encoding:mime-version: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=ob3o88R/yxUBwonSp9vzDZCeFMZAfTzy7u2JCgClFSk=; b=iYBSQO+NSxKZPDyeZ5WZ8YYSrT09MpJnluiNpg20TyPh/Q1HFw6vvfaKrbI0BBcoTM CYFXaApFTYRyzMWVSFxbU2JuXPSg7cGlGrJRF14Bt5q4VDapRFt+QOjF1WdWtiztrdcc zipEUzWJcSw99Vl/fIpZ9bO8tkNGog4yfTCpFyNWmzFunb8ZPgRpz8d8G09tc0ZBNHvD GPVMBuiduDoBvoaYYbGxuG9ZDdH1/ynFEBJbMt5vJu+hYYQ56K+WlZPSGZ6iWYXISkzs SyGthlk+yPCnRvfh1QZ18+HJWBA+A6sDvzJH1KqEa2msm/HF0t4nlfUiakDMb6Eqrna7 uP6Q== X-Forwarded-Encrypted: i=1; AJvYcCVzdE3AjmmrdGs34ylSfzmgrrJZ7CC0omyY5tSiSQ12sVaDkS6Fa3/NVu2ZKEKwT23yOtruLJHkW0UGFsGJB1GYdGpvWouWNIrj5C41 X-Gm-Message-State: AOJu0YyIAMXN91KBX0IyBbQH2G9nWGgWcMBxZixrFzdxD4aia7HGg6l2 rVc9HidOaetkSOYEzxogre0yhmk72+YsuadYfnIfN+6X+Q/Wkz2iJzjxPd8ucFg= X-Google-Smtp-Source: AGHT+IFnRlQjxIzplZP9hmspE1klaaY7FAnTuoO73aRSdCaRY/lNjrX74jyuwVgqrmifZPXhzx+e5A== X-Received: by 2002:a05:600c:4f4e:b0:427:b995:5bd0 with SMTP id 5b1f17b1804b1-427daa61cbfmr47929775e9.23.1721643202485; Mon, 22 Jul 2024 03:13:22 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:22 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 11/17] coresight: Move struct coresight_trace_id_map to common header Date: Mon, 22 Jul 2024 11:11:53 +0100 Message-Id: <20240722101202.26915-12-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark The trace ID maps will need to be created and stored by the core and Perf code so move the definition up to the common header. Reviewed-by: Anshuman Khandual Reviewed-by: Mike Leach Signed-off-by: James Clark Tested-by: Leo Yan Tested-by: Ganapatrao Kulkarni Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-trace-id.c | 1 + .../hwtracing/coresight/coresight-trace-id.h | 19 ------------------- include/linux/coresight.h | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c index af5b4ef59cea..19005b5b4dc4 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -3,6 +3,7 @@ * Copyright (c) 2022, Linaro Limited, All rights reserved. * Author: Mike Leach */ +#include #include #include #include diff --git a/drivers/hwtracing/coresight/coresight-trace-id.h b/drivers/hwt= racing/coresight/coresight-trace-id.h index 3797777d367e..49438a96fcc6 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.h +++ b/drivers/hwtracing/coresight/coresight-trace-id.h @@ -32,10 +32,6 @@ #include #include =20 - -/* architecturally we have 128 IDs some of which are reserved */ -#define CORESIGHT_TRACE_IDS_MAX 128 - /* ID 0 is reserved */ #define CORESIGHT_TRACE_ID_RES_0 0 =20 @@ -46,21 +42,6 @@ #define IS_VALID_CS_TRACE_ID(id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) =20 -/** - * Trace ID map. - * - * @used_ids: Bitmap to register available (bit =3D 0) and in use (bit =3D= 1) IDs. - * Initialised so that the reserved IDs are permanently marked as - * in use. - * @pend_rel_ids: CPU IDs that have been released by the trace source but = not - * yet marked as available, to allow re-allocation to the same - * CPU during a perf session. - */ -struct coresight_trace_id_map { - DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); - DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); -}; - /* Allocate and release IDs for a single default trace ID map */ =20 /** diff --git a/include/linux/coresight.h b/include/linux/coresight.h index f09ace92176e..c16c61a8411d 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -218,6 +218,24 @@ struct coresight_sysfs_link { const char *target_name; }; =20 +/* architecturally we have 128 IDs some of which are reserved */ +#define CORESIGHT_TRACE_IDS_MAX 128 + +/** + * Trace ID map. + * + * @used_ids: Bitmap to register available (bit =3D 0) and in use (bit =3D= 1) IDs. + * Initialised so that the reserved IDs are permanently marked as + * in use. + * @pend_rel_ids: CPU IDs that have been released by the trace source but = not + * yet marked as available, to allow re-allocation to the same + * CPU during a perf session. + */ +struct coresight_trace_id_map { + DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); + DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); +}; + /** * struct coresight_device - representation of a device as used by the fra= mework * @pdata: Platform data with device connections associated to this device. --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FFB716DC0F for ; Mon, 22 Jul 2024 10:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643210; cv=none; b=E4D5xYXq10J7edzybsJ8pUu86shTM/cMDa/WHqpYHpSxhWHhHB/GhNO/DtMcdkEJ9muH7Rr4RoWg+KOSQh632OfFZU8Z0XDkRRisxAN4cVi04iC2lKvusnRFQCcU4dC/sQRa/NbfYtK1wvwVP8n8isBrA03tJo4WBPYVXHbWuNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643210; c=relaxed/simple; bh=8R5OmeoGLlv5vqwVm9o4il46zprkK1aLP1TxCFBpp4w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UGWQ660BEesbhdPeHRArq/+mxFDQwaij1l0ad1rweQ2KP/aDySYAvFXtZo9IfAxa0M2VzcfVfYK7toU5L8hG0PDkn30nuO0tDz6i/rXGgHlt9J8+HFi56ZarsOXG//SzDwo30DKprqx8gwlRIHF4/oMesbprQfSUt49myhJHVkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=TJISrhqz; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TJISrhqz" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-52efd08e6d9so2107627e87.1 for ; Mon, 22 Jul 2024 03:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643207; x=1722248007; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d6Zkl3RZ0YZqXGz3k9BNGR/j5j9H7UAlIZzg0Q8iJLg=; b=TJISrhqzA+6QJcgHbb2fdtCWIlgcEh1HKDjJlvqM9P4X6kdVHi9KarReB8KMesXMyn 4JKet8HpmjC8Hwh0DYaljF7aQQa/MmJmaJ7yMk1C58adwwypNs1zqe+Nm4ll9+asTw6s ZNNtFvlVeZAWQcxzpLAGPoMMfuXmMeRna81NI5npH7bPac/wEyTH35vMI1pNt23DEQnU lohEYG8wrAZuh33lyaDaDYOfRNpILzhQ+pHgw0etsF6dYWjGg6hylk6yefuQ78NfDMax t1BgDoxDJpABdt0AGAbet5pfdDI9bZM8RnbBzVjtIfWyqIJ89oDrsEfyDUlx3o6B3SXa 8k5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643207; x=1722248007; h=content-transfer-encoding:mime-version: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=d6Zkl3RZ0YZqXGz3k9BNGR/j5j9H7UAlIZzg0Q8iJLg=; b=lACI85OQVWsu4a0g3iz/DmzPJXw3V1ypn0KoWejEPP/ai8aDbJMckrSpEtUQ6VmQNY yN9OygxQljStlLyMIy51nGScNvc5L5UYg6jZ+trSuRL4JQbscWJXsRc53KiQUimG1iza OGO0mI4PmJ2R7YoLdqIGDjLFZmOvz8Q9OCS5qMSa9rvJLSG2ohe5AbtofZhR2Gk5CYiJ Edrn/Ua3mDAHvlEviMLFAqmT3pBmK6fkuX3kN5Gl8NbUprzu66xeXVpMW6X3Mf6Sy9JK JstCuj5urKKQLIvtE+Nkmd9h1rMQDlvYz1P+jN1gSYyaEg+KzfUuN1iRaWBu9QfLu1C5 3Yjg== X-Forwarded-Encrypted: i=1; AJvYcCWejTiOc1/9hAcn791Q7f7jOjoHo/RceP2P9tKclXkOngTghjwfcFxXKXXhSovb21eDf8CrrOCL+fQg6hdeJzcs4SVK7gUAJCep/i3/ X-Gm-Message-State: AOJu0YyhpQW4Miixr1WQHAlbAwoYwBIsW9AJJfcVvfHYC+muddhBjJms xR+istnZsXqujn2skARoVJv0lwwpU3lb3RbsWRiWN+qO5Yx2ihWIPiQgDg33Yc8= X-Google-Smtp-Source: AGHT+IHtzUnS25hXmocvsE039YvTk03X0Hq/y0ReZ7EbenrUSY/BqUT58J9l2FysaxuwFgPpAsPnJw== X-Received: by 2002:a05:6512:3409:b0:52c:dac3:392b with SMTP id 2adb3069b0e04-52efb7c592emr3426436e87.33.1721643207351; Mon, 22 Jul 2024 03:13:27 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:27 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 12/17] coresight: Expose map arguments in trace ID API Date: Mon, 22 Jul 2024 11:11:54 +0100 Message-Id: <20240722101202.26915-13-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark The trace ID API is currently hard coded to always use the global map. Add public versions that allow the map to be passed in so that Perf mode can use per-sink maps. Keep the non-map versions so that sysfs mode can continue to use the default global map. System ID functions are unchanged because they will always use the default map. Signed-off-by: James Clark Reviewed-by: Mike Leach Tested-by: Leo Yan Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-trace-id.c | 36 ++++++++++++++----- .../hwtracing/coresight/coresight-trace-id.h | 20 +++++++++-- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c index 19005b5b4dc4..5561989a03fa 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -12,7 +12,7 @@ =20 #include "coresight-trace-id.h" =20 -/* Default trace ID map. Used on systems that don't require per sink mappi= ngs */ +/* Default trace ID map. Used in sysfs mode and for system sources */ static struct coresight_trace_id_map id_map_default; =20 /* maintain a record of the mapping of IDs and pending releases per cpu */ @@ -47,7 +47,7 @@ static void coresight_trace_id_dump_table(struct coresigh= t_trace_id_map *id_map, #endif =20 /* unlocked read of current trace ID value for given CPU */ -static int _coresight_trace_id_read_cpu_id(int cpu) +static int _coresight_trace_id_read_cpu_id(int cpu, struct coresight_trace= _id_map *id_map) { return atomic_read(&per_cpu(cpu_id, cpu)); } @@ -152,7 +152,7 @@ static void coresight_trace_id_release_all_pending(void) DUMP_ID_MAP(id_map); } =20 -static int coresight_trace_id_map_get_cpu_id(int cpu, struct coresight_tra= ce_id_map *id_map) +static int _coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_= id_map *id_map) { unsigned long flags; int id; @@ -160,7 +160,7 @@ static int coresight_trace_id_map_get_cpu_id(int cpu, s= truct coresight_trace_id_ spin_lock_irqsave(&id_map_lock, flags); =20 /* check for existing allocation for this CPU */ - id =3D _coresight_trace_id_read_cpu_id(cpu); + id =3D _coresight_trace_id_read_cpu_id(cpu, id_map); if (id) goto get_cpu_id_clr_pend; =20 @@ -196,13 +196,13 @@ static int coresight_trace_id_map_get_cpu_id(int cpu,= struct coresight_trace_id_ return id; } =20 -static void coresight_trace_id_map_put_cpu_id(int cpu, struct coresight_tr= ace_id_map *id_map) +static void _coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace= _id_map *id_map) { unsigned long flags; int id; =20 /* check for existing allocation for this CPU */ - id =3D _coresight_trace_id_read_cpu_id(cpu); + id =3D _coresight_trace_id_read_cpu_id(cpu, id_map); if (!id) return; =20 @@ -254,22 +254,40 @@ static void coresight_trace_id_map_put_system_id(stru= ct coresight_trace_id_map * =20 int coresight_trace_id_get_cpu_id(int cpu) { - return coresight_trace_id_map_get_cpu_id(cpu, &id_map_default); + return _coresight_trace_id_get_cpu_id(cpu, &id_map_default); } EXPORT_SYMBOL_GPL(coresight_trace_id_get_cpu_id); =20 +int coresight_trace_id_get_cpu_id_map(int cpu, struct coresight_trace_id_m= ap *id_map) +{ + return _coresight_trace_id_get_cpu_id(cpu, id_map); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_get_cpu_id_map); + void coresight_trace_id_put_cpu_id(int cpu) { - coresight_trace_id_map_put_cpu_id(cpu, &id_map_default); + _coresight_trace_id_put_cpu_id(cpu, &id_map_default); } EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id); =20 +void coresight_trace_id_put_cpu_id_map(int cpu, struct coresight_trace_id_= map *id_map) +{ + _coresight_trace_id_put_cpu_id(cpu, id_map); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_put_cpu_id_map); + int coresight_trace_id_read_cpu_id(int cpu) { - return _coresight_trace_id_read_cpu_id(cpu); + return _coresight_trace_id_read_cpu_id(cpu, &id_map_default); } EXPORT_SYMBOL_GPL(coresight_trace_id_read_cpu_id); =20 +int coresight_trace_id_read_cpu_id_map(int cpu, struct coresight_trace_id_= map *id_map) +{ + return _coresight_trace_id_read_cpu_id(cpu, id_map); +} +EXPORT_SYMBOL_GPL(coresight_trace_id_read_cpu_id_map); + int coresight_trace_id_get_system_id(void) { return coresight_trace_id_map_get_system_id(&id_map_default); diff --git a/drivers/hwtracing/coresight/coresight-trace-id.h b/drivers/hwt= racing/coresight/coresight-trace-id.h index 49438a96fcc6..840babdd0794 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.h +++ b/drivers/hwtracing/coresight/coresight-trace-id.h @@ -42,8 +42,6 @@ #define IS_VALID_CS_TRACE_ID(id) \ ((id > CORESIGHT_TRACE_ID_RES_0) && (id < CORESIGHT_TRACE_ID_RES_TOP)) =20 -/* Allocate and release IDs for a single default trace ID map */ - /** * Read and optionally allocate a CoreSight trace ID and associate with a = CPU. * @@ -59,6 +57,12 @@ */ int coresight_trace_id_get_cpu_id(int cpu); =20 +/** + * Version of coresight_trace_id_get_cpu_id() that allows the ID map to op= erate + * on to be provided. + */ +int coresight_trace_id_get_cpu_id_map(int cpu, struct coresight_trace_id_m= ap *id_map); + /** * Release an allocated trace ID associated with the CPU. * @@ -72,6 +76,12 @@ int coresight_trace_id_get_cpu_id(int cpu); */ void coresight_trace_id_put_cpu_id(int cpu); =20 +/** + * Version of coresight_trace_id_put_cpu_id() that allows the ID map to op= erate + * on to be provided. + */ +void coresight_trace_id_put_cpu_id_map(int cpu, struct coresight_trace_id_= map *id_map); + /** * Read the current allocated CoreSight Trace ID value for the CPU. * @@ -92,6 +102,12 @@ void coresight_trace_id_put_cpu_id(int cpu); */ int coresight_trace_id_read_cpu_id(int cpu); =20 +/** + * Version of coresight_trace_id_read_cpu_id() that allows the ID map to o= perate + * on to be provided. + */ +int coresight_trace_id_read_cpu_id_map(int cpu, struct coresight_trace_id_= map *id_map); + /** * Allocate a CoreSight trace ID for a system component. * --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED15716DC1B for ; Mon, 22 Jul 2024 10:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643215; cv=none; b=NQ7aFXMwVopijWHTmWBydb+sRTyeAG6iNZ+k4n8VX4mhKKWed4TJgqUuzRO6JAwGSGyV/TzppjhqQGC8JOOMnX+PTB44OAaJZ+tUbtuA9Zi19CAB7OD/86qbK4Uy78k1r17NEkUR/7Q0PhyfREU54tAEhqNhh7fQ0V5+ELAuwAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643215; c=relaxed/simple; bh=ItH9f426qXV+5rIZSG9tiSgqcCYNUSF0NPfya/+tqmc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nBAtuzW2cCRIFzYsBCRn0sdmrX32l2ISsPu+SSM+XFkCwRKXYxZt1EoAYwnBytkz8hjcFhfw/y7UCSJ+Vzpf0AV2PL48GwB/9tOvYT4SDvXyWafHb7PUoftE9IDxw3gT3lk+MpjXC+QQVBZ1ldmokbGHXRiW2YZcyPshzsQWB+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=aLZ54Yaf; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aLZ54Yaf" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2ebe40673e8so51756621fa.3 for ; Mon, 22 Jul 2024 03:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643212; x=1722248012; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gac0SAR3KAIOUnKehRmkrRiaYS0y2TNr3epiBL0LQk8=; b=aLZ54YafX1paBdvvDhiozd5QD4RCMDtEZxQuSfC1iieNR178jtOhM28ohmLBABpPIf HmDBM67kJqCZxEbie4tEAGeZBK1jcJzV63eA2k/ECg5SXzs5YWym9fBbbrcFDlKs08bC tVcN08SNbTpZnhHUDlFq1mQSHJvGBYTlgVXwG9Z3TPDM2rUXO2YqWcDwpe5kDDIcxReq mTKsRzR7FMRaDqWMvWx8xZTgV2kLrZ9wCOfU9nYY6ftalwZHKfRbe25V8zfuOEZqGb9F vO0u8Vm2ERY71qQEoGT2Zr10PoE3HcagCn/Is9fZY5+9j33H8sFx/Fm7vEUmA6mHNECG KCIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643212; x=1722248012; h=content-transfer-encoding:mime-version: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=gac0SAR3KAIOUnKehRmkrRiaYS0y2TNr3epiBL0LQk8=; b=q/fnEDiR8MUizlk/HuWRuaPr67rv52pDeYBzAv/hfgDLtDFkQ+VXpPQfKMkC+/QeZB 8KJRSfO5qm0xsdqWBk5zHcP+ufzKE/E1RFM4Ml1qWg5cHQ1bA5V2OsPIZnoiF2FJ3a+K KMcZ+7ZfMsNhPXScOsz1GlmN5yBvuhYPiEoba/28cNPDDpaqNfXiKgn3uxO1jsXXlLWh jVjvVeACyIVgeUQZaIkHxyle8zUbyVEdJd8LGZ7Tr3K5JrP7l3MfVPpZsYdGEn2q3OtO 3ESPd3jxJqUYBoYx55GXCnbNgvwBb+PQ4I9FJJScjgecY0Nb9oFsm4Mue9eeWLW1zzXh 1piw== X-Forwarded-Encrypted: i=1; AJvYcCVhHZ6EI4rywOpPqM4mNtJNFPc28KIEmgJP0Tdsil/Dr8fyKEfJXy8luAmS7OwatUrni9cOHvl/bVh/+PAi5PYYSKYWw5/Q9O3jDImD X-Gm-Message-State: AOJu0Yz0uESigs2cqV4ZjR2NK4J+U6gGPACio3KuKwDkB9b0wr/6rieb ADgdscW5FdXZZ3fH3q/BmGvL+RDufGgc/dLfdu9SHOXXSOsgAAvlYkMvXPl4ADY= X-Google-Smtp-Source: AGHT+IGTZQIhy3gNPKPI7DGy65qUrKCQGhBq5C4l1bUGJPNsWt1iC1rZkJ6h0IJVzpzgCf+Q3zsCVw== X-Received: by 2002:a2e:92d5:0:b0:2ef:2cbc:9074 with SMTP id 38308e7fff4ca-2ef2cbc91c3mr21432381fa.21.1721643212217; Mon, 22 Jul 2024 03:13:32 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:31 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 13/17] coresight: Make CPU id map a property of a trace ID map Date: Mon, 22 Jul 2024 11:11:55 +0100 Message-Id: <20240722101202.26915-14-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark The global CPU ID mappings won't work for per-sink ID maps so move it to the ID map struct. coresight_trace_id_release_all_pending() is hard coded to operate on the default map, but once Perf sessions use their own maps the pending release mechanism will be deleted. So it doesn't need to be extended to accept a trace ID map argument at this point. Signed-off-by: James Clark Reviewed-by: Mike Leach Tested-by: Leo Yan Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-trace-id.c | 16 +++++++++------- include/linux/coresight.h | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c index 5561989a03fa..8a777c0af6ea 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -13,10 +13,12 @@ #include "coresight-trace-id.h" =20 /* Default trace ID map. Used in sysfs mode and for system sources */ -static struct coresight_trace_id_map id_map_default; +static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) =3D ATOMIC_INIT(0); +static struct coresight_trace_id_map id_map_default =3D { + .cpu_map =3D &id_map_default_cpu_ids +}; =20 -/* maintain a record of the mapping of IDs and pending releases per cpu */ -static DEFINE_PER_CPU(atomic_t, cpu_id) =3D ATOMIC_INIT(0); +/* maintain a record of the pending releases per cpu */ static cpumask_t cpu_id_release_pending; =20 /* perf session active counter */ @@ -49,7 +51,7 @@ static void coresight_trace_id_dump_table(struct coresigh= t_trace_id_map *id_map, /* unlocked read of current trace ID value for given CPU */ static int _coresight_trace_id_read_cpu_id(int cpu, struct coresight_trace= _id_map *id_map) { - return atomic_read(&per_cpu(cpu_id, cpu)); + return atomic_read(per_cpu_ptr(id_map->cpu_map, cpu)); } =20 /* look for next available odd ID, return 0 if none found */ @@ -145,7 +147,7 @@ static void coresight_trace_id_release_all_pending(void) clear_bit(bit, id_map->pend_rel_ids); } for_each_cpu(cpu, &cpu_id_release_pending) { - atomic_set(&per_cpu(cpu_id, cpu), 0); + atomic_set(per_cpu_ptr(id_map_default.cpu_map, cpu), 0); cpumask_clear_cpu(cpu, &cpu_id_release_pending); } spin_unlock_irqrestore(&id_map_lock, flags); @@ -181,7 +183,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, stru= ct coresight_trace_id_map goto get_cpu_id_out_unlock; =20 /* allocate the new id to the cpu */ - atomic_set(&per_cpu(cpu_id, cpu), id); + atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), id); =20 get_cpu_id_clr_pend: /* we are (re)using this ID - so ensure it is not marked for release */ @@ -215,7 +217,7 @@ static void _coresight_trace_id_put_cpu_id(int cpu, str= uct coresight_trace_id_ma } else { /* otherwise clear id */ coresight_trace_id_free(id, id_map); - atomic_set(&per_cpu(cpu_id, cpu), 0); + atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); } =20 spin_unlock_irqrestore(&id_map_lock, flags); diff --git a/include/linux/coresight.h b/include/linux/coresight.h index c16c61a8411d..7d62b88bfb5c 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -234,6 +234,7 @@ struct coresight_sysfs_link { struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); + atomic_t __percpu *cpu_map; }; =20 /** --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C372716DEA5 for ; Mon, 22 Jul 2024 10:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643221; cv=none; b=S4JbByOhQQ4ZBBoBRE572F7OSzxtQfQCpNPuy48LU/KeZeRcE7TUHTQR5M44eF5tG2wJ8EnjJEbsgPGDTCwcHaKsMIw8m7zE/6IovtI/D2lEVAYAsvM+3ZzmhLaWliqRAanwSe2AyZHEHXYUg2k6EmfnqIAcUXlrUhxvxPBrk3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643221; c=relaxed/simple; bh=6do9iD1hzuzJZkgd9rR94ZmZdTam17o0g+ay3Mw96Z0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OsxtynigPS2o3KHxolR/u1jedaw7t8hf1KPjEzbRDggC8T6UGvaXsbpgjlqYZgJYtDYjI6ZDj1B6R91IojlpkwdddGCsgEuy/5nWjwGhZocnE0Itn6xfi0tlW4UHc0uy+AJNKiRS38hViB3PZHH1+vok6ofMQyPa7BmnDBdQRIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=bbcc6ERH; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bbcc6ERH" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so20018865e9.1 for ; Mon, 22 Jul 2024 03:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643217; x=1722248017; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mBt9A8JUvpx5S4qN1mTD6aFGgsPJSGMw85lMgII9V70=; b=bbcc6ERHJIFXbKQUn5q6I1j4+sToyUbU2S8h91NsH50oxaSnMZY33jYXldh2wzqO0g IjrbiKBxATGmz2/wU4zLx5QaWDzPrMyDGw9yRTRIXw0zWG7wfTqDdu2X2peqf1+R/R93 8IkMWj1loSFhQ8pB+bUWP/T0vbZ4xoveqONg+yqQVGtvxAzGrpL3ZAO4ax+eq4ohgMIo GDarFECRtv5gBGFfbTMhvZQ/IaFVNtcoKNbAoPEjwW6sb3+vCyD5DtZ/tlFxzOuQ3t+E Ks0ZQ+ML8GUSetOU95Glt61tEimdaHlxnpZPbKOKh3YuKkDylrc0g+5OsN1PrYf+M92W +8jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643217; x=1722248017; h=content-transfer-encoding:mime-version: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=mBt9A8JUvpx5S4qN1mTD6aFGgsPJSGMw85lMgII9V70=; b=BJgIqDlRgX5pvs1W4IsIF4HgWk2qiXRlPnkG8N6TC5abJF9DAsBGJtp14mWRHd5IjK nL8JQX7VKxNaPpPzTHba5MSkIITV9n/iPnroaYL6IZwphLIRJhzOMCXXS3kChf3CUfAp wCzGTSdVHqT1SH7CIjvgbscTy87O5xnd5d1VrN0LSE9vPWPDsmp9Ge37cWvXP7BEhrrw cAA242IWMvJYP4lWECr/FQptjKRLKfNOQIUHexHlaan7F1h8Z7APcV37EV1p4DoKGu0Y VCwLfgjqwClSBTuzclK0yeFIa3Xhfy5bVFe9V9juc8reYCR9TWeWPel5Er2/aK4XOtcU 7VkA== X-Forwarded-Encrypted: i=1; AJvYcCX0U4TQVryQ0PfBSGwp6Kk5mnIJu0r7mUSCmu3T+wAsFmktxclxoiQ3zobbdBpie67PSfg0sAMWYiRNlMDi1652OmR6uq/nioce7zBq X-Gm-Message-State: AOJu0YxcrKRWrMz6HbqpOq9NwmCaBXahFbxLGkMvMnTlV3Kdco/nyso+ mvlS7vI4xjjy+19NZ4a24wmZmhkUibUQKtm2WWPszZ4VS9QUBUyAh/FQIeigvss= X-Google-Smtp-Source: AGHT+IHcrqvVgg/Lg0aRVClihNOrsMFtQPctmfO4ei6IhKRI3c3ConTrfogJF6uBS81bDBR1KaZB6w== X-Received: by 2002:a05:600c:524e:b0:426:676a:c4d1 with SMTP id 5b1f17b1804b1-427da7fd738mr49640265e9.8.1721643217075; Mon, 22 Jul 2024 03:13:37 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:36 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 14/17] coresight: Use per-sink trace ID maps for Perf sessions Date: Mon, 22 Jul 2024 11:11:56 +0100 Message-Id: <20240722101202.26915-15-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark This will allow sessions with more than CORESIGHT_TRACE_IDS_MAX ETMs as long as there are fewer than that many ETMs connected to each sink. Each sink owns its own trace ID map, and any Perf session connecting to that sink will allocate from it, even if the sink is currently in use by other users. This is similar to the existing behavior where the dynamic trace IDs are constant as long as there is any concurrent Perf session active. It's not completely optimal because slightly more IDs will be used than necessary, but the optimal solution involves tracking the PIDs of each session and allocating ID maps based on the session owner. This is difficult to do with the combination of per-thread and per-cpu modes and some scheduling issues. The complexity of this isn't likely to worth it because even with multiple users they'd just see a difference in the ordering of ID allocations rather than hitting any limits (unless the hardware does have too many ETMs connected to one sink). Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-core.c | 10 ++++++++++ drivers/hwtracing/coresight/coresight-dummy.c | 3 ++- drivers/hwtracing/coresight/coresight-etm-perf.c | 15 ++++++++++----- .../hwtracing/coresight/coresight-etm3x-core.c | 9 +++++---- .../hwtracing/coresight/coresight-etm4x-core.c | 9 +++++---- drivers/hwtracing/coresight/coresight-stm.c | 3 ++- drivers/hwtracing/coresight/coresight-sysfs.c | 3 ++- drivers/hwtracing/coresight/coresight-tpdm.c | 3 ++- include/linux/coresight.h | 3 ++- 9 files changed, 40 insertions(+), 18 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index 9fc6f6b863e0..faf560ba8d64 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -902,6 +902,7 @@ static void coresight_device_release(struct device *dev) struct coresight_device *csdev =3D to_coresight_device(dev); =20 fwnode_handle_put(csdev->dev.fwnode); + free_percpu(csdev->perf_sink_id_map.cpu_map); kfree(csdev); } =20 @@ -1159,6 +1160,15 @@ struct coresight_device *coresight_register(struct c= oresight_desc *desc) csdev->dev.fwnode =3D fwnode_handle_get(dev_fwnode(desc->dev)); dev_set_name(&csdev->dev, "%s", desc->name); =20 + if (csdev->type =3D=3D CORESIGHT_DEV_TYPE_SINK || + csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) { + csdev->perf_sink_id_map.cpu_map =3D alloc_percpu(atomic_t); + if (!csdev->perf_sink_id_map.cpu_map) { + kfree(csdev); + ret =3D -ENOMEM; + goto err_out; + } + } /* * Make sure the device registration and the connection fixup * are synchronised, so that we don't see uninitialised devices diff --git a/drivers/hwtracing/coresight/coresight-dummy.c b/drivers/hwtrac= ing/coresight/coresight-dummy.c index ac70c0b491be..1f1b9ad160f6 100644 --- a/drivers/hwtracing/coresight/coresight-dummy.c +++ b/drivers/hwtracing/coresight/coresight-dummy.c @@ -21,7 +21,8 @@ DEFINE_CORESIGHT_DEVLIST(source_devs, "dummy_source"); DEFINE_CORESIGHT_DEVLIST(sink_devs, "dummy_sink"); =20 static int dummy_source_enable(struct coresight_device *csdev, - struct perf_event *event, enum cs_mode mode) + struct perf_event *event, enum cs_mode mode, + __maybe_unused struct coresight_trace_id_map *id_map) { dev_dbg(csdev->dev.parent, "Dummy source enabled\n"); =20 diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index c0c60e6a1703..7fb55dafb639 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -229,10 +229,13 @@ static void free_event_data(struct work_struct *work) struct list_head **ppath; =20 ppath =3D etm_event_cpu_path_ptr(event_data, cpu); - if (!(IS_ERR_OR_NULL(*ppath))) + if (!(IS_ERR_OR_NULL(*ppath))) { + struct coresight_device *sink =3D coresight_get_sink(*ppath); + + coresight_trace_id_put_cpu_id_map(cpu, &sink->perf_sink_id_map); coresight_release_path(*ppath); + } *ppath =3D NULL; - coresight_trace_id_put_cpu_id(cpu); } =20 /* mark perf event as done for trace id allocator */ @@ -401,7 +404,7 @@ static void *etm_setup_aux(struct perf_event *event, vo= id **pages, } =20 /* ensure we can allocate a trace ID for this CPU */ - trace_id =3D coresight_trace_id_get_cpu_id(cpu); + trace_id =3D coresight_trace_id_get_cpu_id_map(cpu, &sink->perf_sink_id_= map); if (!IS_VALID_CS_TRACE_ID(trace_id)) { cpumask_clear_cpu(cpu, mask); coresight_release_path(path); @@ -495,7 +498,8 @@ static void etm_event_start(struct perf_event *event, i= nt flags) goto fail_end_stop; =20 /* Finally enable the tracer */ - if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF)) + if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF, + &sink->perf_sink_id_map)) goto fail_disable_path; =20 /* @@ -507,7 +511,8 @@ static void etm_event_start(struct perf_event *event, i= nt flags) hw_id =3D FIELD_PREP(CS_AUX_HW_ID_VERSION_MASK, CS_AUX_HW_ID_CURR_VERSION); hw_id |=3D FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, - coresight_trace_id_read_cpu_id(cpu)); + coresight_trace_id_read_cpu_id_map(cpu, + &sink->perf_sink_id_map)); perf_report_aux_output_id(event, hw_id); } =20 diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/h= wtracing/coresight/coresight-etm3x-core.c index 8b362605d242..c103f4c70f5d 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -481,7 +481,8 @@ void etm_release_trace_id(struct etm_drvdata *drvdata) } =20 static int etm_enable_perf(struct coresight_device *csdev, - struct perf_event *event) + struct perf_event *event, + struct coresight_trace_id_map *id_map) { struct etm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); int trace_id; @@ -500,7 +501,7 @@ static int etm_enable_perf(struct coresight_device *csd= ev, * with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =3D coresight_trace_id_read_cpu_id(drvdata->cpu); + trace_id =3D coresight_trace_id_read_cpu_id_map(drvdata->cpu, id_map); if (!IS_VALID_CS_TRACE_ID(trace_id)) { dev_err(&drvdata->csdev->dev, "Failed to set trace ID for %s on CPU%d\n", dev_name(&drvdata->csdev->dev), drvdata->cpu); @@ -553,7 +554,7 @@ static int etm_enable_sysfs(struct coresight_device *cs= dev) } =20 static int etm_enable(struct coresight_device *csdev, struct perf_event *e= vent, - enum cs_mode mode) + enum cs_mode mode, struct coresight_trace_id_map *id_map) { int ret; struct etm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); @@ -568,7 +569,7 @@ static int etm_enable(struct coresight_device *csdev, s= truct perf_event *event, ret =3D etm_enable_sysfs(csdev); break; case CS_MODE_PERF: - ret =3D etm_enable_perf(csdev, event); + ret =3D etm_enable_perf(csdev, event, id_map); break; default: ret =3D -EINVAL; diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/h= wtracing/coresight/coresight-etm4x-core.c index bf01f01964cf..66d44a404ad0 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -752,7 +752,8 @@ static int etm4_parse_event_config(struct coresight_dev= ice *csdev, } =20 static int etm4_enable_perf(struct coresight_device *csdev, - struct perf_event *event) + struct perf_event *event, + struct coresight_trace_id_map *id_map) { int ret =3D 0, trace_id; struct etmv4_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); @@ -775,7 +776,7 @@ static int etm4_enable_perf(struct coresight_device *cs= dev, * with perf locks - we know the ID cannot change until perf shuts down * the session */ - trace_id =3D coresight_trace_id_read_cpu_id(drvdata->cpu); + trace_id =3D coresight_trace_id_read_cpu_id_map(drvdata->cpu, id_map); if (!IS_VALID_CS_TRACE_ID(trace_id)) { dev_err(&drvdata->csdev->dev, "Failed to set trace ID for %s on CPU%d\n", dev_name(&drvdata->csdev->dev), drvdata->cpu); @@ -837,7 +838,7 @@ static int etm4_enable_sysfs(struct coresight_device *c= sdev) } =20 static int etm4_enable(struct coresight_device *csdev, struct perf_event *= event, - enum cs_mode mode) + enum cs_mode mode, struct coresight_trace_id_map *id_map) { int ret; =20 @@ -851,7 +852,7 @@ static int etm4_enable(struct coresight_device *csdev, = struct perf_event *event, ret =3D etm4_enable_sysfs(csdev); break; case CS_MODE_PERF: - ret =3D etm4_enable_perf(csdev, event); + ret =3D etm4_enable_perf(csdev, event, id_map); break; default: ret =3D -EINVAL; diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracin= g/coresight/coresight-stm.c index 117dbb484543..cb3e04755c99 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -194,7 +194,8 @@ static void stm_enable_hw(struct stm_drvdata *drvdata) } =20 static int stm_enable(struct coresight_device *csdev, struct perf_event *e= vent, - enum cs_mode mode) + enum cs_mode mode, + __maybe_unused struct coresight_trace_id_map *trace_id) { struct stm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); =20 diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtrac= ing/coresight/coresight-sysfs.c index 1e67cc7758d7..a01c9e54e2ed 100644 --- a/drivers/hwtracing/coresight/coresight-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-sysfs.c @@ -9,6 +9,7 @@ #include =20 #include "coresight-priv.h" +#include "coresight-trace-id.h" =20 /* * Use IDR to map the hash of the source's device name @@ -63,7 +64,7 @@ static int coresight_enable_source_sysfs(struct coresight= _device *csdev, */ lockdep_assert_held(&coresight_mutex); if (coresight_get_mode(csdev) !=3D CS_MODE_SYSFS) { - ret =3D source_ops(csdev)->enable(csdev, data, mode); + ret =3D source_ops(csdev)->enable(csdev, data, mode, NULL); if (ret) return ret; } diff --git a/drivers/hwtracing/coresight/coresight-tpdm.c b/drivers/hwtraci= ng/coresight/coresight-tpdm.c index 0726f8842552..0a5e20cf23e8 100644 --- a/drivers/hwtracing/coresight/coresight-tpdm.c +++ b/drivers/hwtracing/coresight/coresight-tpdm.c @@ -439,7 +439,8 @@ static void __tpdm_enable(struct tpdm_drvdata *drvdata) } =20 static int tpdm_enable(struct coresight_device *csdev, struct perf_event *= event, - enum cs_mode mode) + enum cs_mode mode, + __maybe_unused struct coresight_trace_id_map *id_map) { struct tpdm_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); =20 diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 7d62b88bfb5c..9c3067e2e38b 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -290,6 +290,7 @@ struct coresight_device { bool sysfs_sink_activated; struct dev_ext_attribute *ea; struct coresight_device *def_sink; + struct coresight_trace_id_map perf_sink_id_map; /* sysfs links between components */ int nr_links; bool has_conns_grp; @@ -384,7 +385,7 @@ struct coresight_ops_link { struct coresight_ops_source { int (*cpu_id)(struct coresight_device *csdev); int (*enable)(struct coresight_device *csdev, struct perf_event *event, - enum cs_mode mode); + enum cs_mode mode, struct coresight_trace_id_map *id_map); void (*disable)(struct coresight_device *csdev, struct perf_event *event); }; --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96C2116DEAF for ; Mon, 22 Jul 2024 10:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643225; cv=none; b=s54F5RFsRM0ayhnAXsSrllr5d+RNBnfwQ9FX/HxdN8tJ6CftTl1ORDRQ6xLpqrPYnFF7O2JUYz/2ZRV07rLXC2lKi41pZTYMhQJLOtjtEAj1QunpWxkHKLdRufurOxLYGvdVeWEgeoDZDNnR1WGeYsmATio5RlYvail/yLMecoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643225; c=relaxed/simple; bh=K7UMVr+Mb2yQooqK7gzXDOwZNrewkjFmCowy8ExaG+4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WDAFLtbpsRPEalOj2i/EhYCJEOm81jn7h6+e/N4+C5LWcuXjYBx8MZ3Ze/uqA68do64V81zY05CPBg9CJ7plY9FSP4nkoTfK/26kz+EavWQYyRV6Cs+WawDYuGUTwD8rksNjQQ2lRVg32kXQrt+fy5Pnd35yyTZ4FCuY4IHqmaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rc+/egzi; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rc+/egzi" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2ef1c12ae23so18480411fa.0 for ; Mon, 22 Jul 2024 03:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643222; x=1722248022; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dsMCqr8T/iQ+uuTbOOHukf9tVZI/Fi7NUej0XAYkU4g=; b=rc+/egzit6BngmDKes4O4EJXUudiR3BZ6NpY4P95SDkBBmaa1+eTk/I9h8gj/ijgaa 24luTCLJEgV+GAhezJDOS1mqHvyrZF5LpQiPXkAwsdA5yWky0OtjNDN9qMr/q+4gsYVl x9GbhFVkllHFeMJpFoomwhYCfVqba18N87SMvJoJXX6KURAXAItM7l+F2LSxVkChrrMn GHQXdOqssJQx8aTU2C+rWdCk+yjVSwWXZi13ZBVv0bWw75ufRK8tLsPVJ5uEBY1bxAZm Ge7AniMp2Xh2EPj5oEPR38uGUe5lnrNfFvhpjJPJnYpeJfBJe3BExD0xt8QxYZeBXSgm g+yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643222; x=1722248022; h=content-transfer-encoding:mime-version: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=dsMCqr8T/iQ+uuTbOOHukf9tVZI/Fi7NUej0XAYkU4g=; b=qhIj5wCvwOg8vscLTAXG/+zZOSClmB6KNhvMgLeJgHJory9djN/lzuI8Gt5h8VgEv1 rkwsA7PnvbSKSoEW+MSgNAxL2xIK7/3UNNc9OHJVcVTRz50GxGmHi0TMHMu7/yiCZfcG uzFWQ78dj2yT8kuLGPtjjT+MqEoXcLuOv6nUpl1LfCZR6L0zQ2PrzScy9ORr2DypNOWA RuF9WgHuz+CNMKjRdBQ8oPiNmdyWWR9C9y06phNY4JZqVSjOnioUYhqMMcAPy4YZOZHA WOJdvkcwtTk/eg/P1MedC9rdvu40jA2PnMrCwgtM6kAmztHufMjZHZ3UMG038DWeejDG +4zw== X-Forwarded-Encrypted: i=1; AJvYcCXA80dx+i+O6VaJF7LJflIaikUvJ9PR5ErQSr2u3yDzXBOAetzH6AHjHrd4PbaKKsthMnWOV94DYPMDJ3vWF03rnCbZSWjMP65CmMAN X-Gm-Message-State: AOJu0Yx2nJGeqs9T8nuvn2oYiE84zaT7bZKqoGRCfMmHkHxR0uPYD0ft fJdzQL0RFhAvXfYm9UewGo9kl9VwjVBy++dvA377BcKhQABuzISkXDo1PZBrebU= X-Google-Smtp-Source: AGHT+IG0+HTTZyt6B1wjcPhyso/9PPXNw3Zz5eazwlaGyZ8sJpY8m+dE74ZSt2EZzuVAZPlRLLGtUA== X-Received: by 2002:a2e:8395:0:b0:2ef:2c20:e064 with SMTP id 38308e7fff4ca-2ef2c20e206mr23408401fa.12.1721643221951; Mon, 22 Jul 2024 03:13:41 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:41 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 15/17] coresight: Remove pending trace ID release mechanism Date: Mon, 22 Jul 2024 11:11:57 +0100 Message-Id: <20240722101202.26915-16-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark Pending the release of IDs was a way of managing concurrent sysfs and Perf sessions in a single global ID map. Perf may have finished while sysfs hadn't, and Perf shouldn't release the IDs in use by sysfs and vice versa. Now that Perf uses its own exclusive ID maps, pending release doesn't result in any different behavior than just releasing all IDs when the last Perf session finishes. As part of the per-sink trace ID change, we would have still had to make the pending mechanism work on a per-sink basis, due to the overlapping ID allocations, so instead of making that more complicated, just remove it. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-etm-perf.c | 18 +++-- .../hwtracing/coresight/coresight-trace-id.c | 67 +++++-------------- .../hwtracing/coresight/coresight-trace-id.h | 31 ++++----- include/linux/coresight.h | 6 +- 4 files changed, 43 insertions(+), 79 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index 7fb55dafb639..70c99f0409b2 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -232,15 +232,21 @@ static void free_event_data(struct work_struct *work) if (!(IS_ERR_OR_NULL(*ppath))) { struct coresight_device *sink =3D coresight_get_sink(*ppath); =20 - coresight_trace_id_put_cpu_id_map(cpu, &sink->perf_sink_id_map); + /* + * Mark perf event as done for trace id allocator, but don't call + * coresight_trace_id_put_cpu_id_map() on individual IDs. Perf sessions + * never free trace IDs to ensure that the ID associated with a CPU + * cannot change during their and other's concurrent sessions. Instead, + * a refcount is used so that the last event to call + * coresight_trace_id_perf_stop() frees all IDs. + */ + coresight_trace_id_perf_stop(&sink->perf_sink_id_map); + coresight_release_path(*ppath); } *ppath =3D NULL; } =20 - /* mark perf event as done for trace id allocator */ - coresight_trace_id_perf_stop(); - free_percpu(event_data->path); kfree(event_data); } @@ -328,9 +334,6 @@ static void *etm_setup_aux(struct perf_event *event, vo= id **pages, sink =3D user_sink =3D coresight_get_sink_by_id(id); } =20 - /* tell the trace ID allocator that a perf event is starting up */ - coresight_trace_id_perf_start(); - /* check if user wants a coresight configuration selected */ cfg_hash =3D (u32)((event->attr.config2 & GENMASK_ULL(63, 32)) >> 32); if (cfg_hash) { @@ -411,6 +414,7 @@ static void *etm_setup_aux(struct perf_event *event, vo= id **pages, continue; } =20 + coresight_trace_id_perf_start(&sink->perf_sink_id_map); *etm_event_cpu_path_ptr(event_data, cpu) =3D path; } =20 diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c index 8a777c0af6ea..bddaed3e5cf8 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -18,12 +18,6 @@ static struct coresight_trace_id_map id_map_default =3D { .cpu_map =3D &id_map_default_cpu_ids }; =20 -/* maintain a record of the pending releases per cpu */ -static cpumask_t cpu_id_release_pending; - -/* perf session active counter */ -static atomic_t perf_cs_etm_session_active =3D ATOMIC_INIT(0); - /* lock to protect id_map and cpu data */ static DEFINE_SPINLOCK(id_map_lock); =20 @@ -35,7 +29,6 @@ static void coresight_trace_id_dump_table(struct coresigh= t_trace_id_map *id_map, { pr_debug("%s id_map::\n", func_name); pr_debug("Used =3D %*pb\n", CORESIGHT_TRACE_IDS_MAX, id_map->used_ids); - pr_debug("Pend =3D %*pb\n", CORESIGHT_TRACE_IDS_MAX, id_map->pend_rel_ids= ); } #define DUMP_ID_MAP(map) coresight_trace_id_dump_table(map, __func__) #define DUMP_ID_CPU(cpu, id) pr_debug("%s called; cpu=3D%d, id=3D%d\n", _= _func__, cpu, id) @@ -122,34 +115,18 @@ static void coresight_trace_id_free(int id, struct co= resight_trace_id_map *id_ma clear_bit(id, id_map->used_ids); } =20 -static void coresight_trace_id_set_pend_rel(int id, struct coresight_trace= _id_map *id_map) -{ - if (WARN(!IS_VALID_CS_TRACE_ID(id), "Invalid Trace ID %d\n", id)) - return; - set_bit(id, id_map->pend_rel_ids); -} - /* - * release all pending IDs for all current maps & clear CPU associations - * - * This currently operates on the default id map, but may be extended to - * operate on all registered id maps if per sink id maps are used. + * Release all IDs and clear CPU associations. */ -static void coresight_trace_id_release_all_pending(void) +static void coresight_trace_id_release_all(struct coresight_trace_id_map *= id_map) { - struct coresight_trace_id_map *id_map =3D &id_map_default; unsigned long flags; - int cpu, bit; + int cpu; =20 spin_lock_irqsave(&id_map_lock, flags); - for_each_set_bit(bit, id_map->pend_rel_ids, CORESIGHT_TRACE_ID_RES_TOP) { - clear_bit(bit, id_map->used_ids); - clear_bit(bit, id_map->pend_rel_ids); - } - for_each_cpu(cpu, &cpu_id_release_pending) { - atomic_set(per_cpu_ptr(id_map_default.cpu_map, cpu), 0); - cpumask_clear_cpu(cpu, &cpu_id_release_pending); - } + bitmap_zero(id_map->used_ids, CORESIGHT_TRACE_IDS_MAX); + for_each_possible_cpu(cpu) + atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); spin_unlock_irqrestore(&id_map_lock, flags); DUMP_ID_MAP(id_map); } @@ -164,7 +141,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, stru= ct coresight_trace_id_map /* check for existing allocation for this CPU */ id =3D _coresight_trace_id_read_cpu_id(cpu, id_map); if (id) - goto get_cpu_id_clr_pend; + goto get_cpu_id_out_unlock; =20 /* * Find a new ID. @@ -185,11 +162,6 @@ static int _coresight_trace_id_get_cpu_id(int cpu, str= uct coresight_trace_id_map /* allocate the new id to the cpu */ atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), id); =20 -get_cpu_id_clr_pend: - /* we are (re)using this ID - so ensure it is not marked for release */ - cpumask_clear_cpu(cpu, &cpu_id_release_pending); - clear_bit(id, id_map->pend_rel_ids); - get_cpu_id_out_unlock: spin_unlock_irqrestore(&id_map_lock, flags); =20 @@ -210,15 +182,8 @@ static void _coresight_trace_id_put_cpu_id(int cpu, st= ruct coresight_trace_id_ma =20 spin_lock_irqsave(&id_map_lock, flags); =20 - if (atomic_read(&perf_cs_etm_session_active)) { - /* set release at pending if perf still active */ - coresight_trace_id_set_pend_rel(id, id_map); - cpumask_set_cpu(cpu, &cpu_id_release_pending); - } else { - /* otherwise clear id */ - coresight_trace_id_free(id, id_map); - atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); - } + coresight_trace_id_free(id, id_map); + atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); =20 spin_unlock_irqrestore(&id_map_lock, flags); DUMP_ID_CPU(cpu, id); @@ -302,17 +267,17 @@ void coresight_trace_id_put_system_id(int id) } EXPORT_SYMBOL_GPL(coresight_trace_id_put_system_id); =20 -void coresight_trace_id_perf_start(void) +void coresight_trace_id_perf_start(struct coresight_trace_id_map *id_map) { - atomic_inc(&perf_cs_etm_session_active); - PERF_SESSION(atomic_read(&perf_cs_etm_session_active)); + atomic_inc(&id_map->perf_cs_etm_session_active); + PERF_SESSION(atomic_read(&id_map->perf_cs_etm_session_active)); } EXPORT_SYMBOL_GPL(coresight_trace_id_perf_start); =20 -void coresight_trace_id_perf_stop(void) +void coresight_trace_id_perf_stop(struct coresight_trace_id_map *id_map) { - if (!atomic_dec_return(&perf_cs_etm_session_active)) - coresight_trace_id_release_all_pending(); - PERF_SESSION(atomic_read(&perf_cs_etm_session_active)); + if (!atomic_dec_return(&id_map->perf_cs_etm_session_active)) + coresight_trace_id_release_all(id_map); + PERF_SESSION(atomic_read(&id_map->perf_cs_etm_session_active)); } EXPORT_SYMBOL_GPL(coresight_trace_id_perf_stop); diff --git a/drivers/hwtracing/coresight/coresight-trace-id.h b/drivers/hwt= racing/coresight/coresight-trace-id.h index 840babdd0794..9aae50a553ca 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.h +++ b/drivers/hwtracing/coresight/coresight-trace-id.h @@ -17,9 +17,10 @@ * released when done. * * In order to ensure that a consistent cpu / ID matching is maintained - * throughout a perf cs_etm event session - a session in progress flag will - * be maintained, and released IDs not cleared until the perf session is - * complete. This allows the same CPU to be re-allocated its prior ID. + * throughout a perf cs_etm event session - a session in progress flag wil= l be + * maintained for each sink, and IDs are cleared when all the perf sessions + * complete. This allows the same CPU to be re-allocated its prior ID when + * events are scheduled in and out. * * * Trace ID maps will be created and initialised to prevent architecturally @@ -66,11 +67,7 @@ int coresight_trace_id_get_cpu_id_map(int cpu, struct co= resight_trace_id_map *id /** * Release an allocated trace ID associated with the CPU. * - * This will release the CoreSight trace ID associated with the CPU, - * unless a perf session is in operation. - * - * If a perf session is in operation then the ID will be marked as pending - * release. + * This will release the CoreSight trace ID associated with the CPU. * * @cpu: The CPU index to release the associated trace ID. */ @@ -133,21 +130,21 @@ void coresight_trace_id_put_system_id(int id); /** * Notify the Trace ID allocator that a perf session is starting. * - * Increase the perf session reference count - called by perf when setting= up - * a trace event. + * Increase the perf session reference count - called by perf when setting= up a + * trace event. * - * This reference count is used by the ID allocator to ensure that trace I= Ds - * associated with a CPU cannot change or be released during a perf sessio= n. + * Perf sessions never free trace IDs to ensure that the ID associated wit= h a + * CPU cannot change during their and other's concurrent sessions. Instead, + * this refcount is used so that the last event to finish always frees all= IDs. */ -void coresight_trace_id_perf_start(void); +void coresight_trace_id_perf_start(struct coresight_trace_id_map *id_map); =20 /** * Notify the ID allocator that a perf session is stopping. * - * Decrease the perf session reference count. - * if this causes the count to go to zero, then all Trace IDs marked as pe= nding - * release, will be released. + * Decrease the perf session reference count. If this causes the count to = go to + * zero, then all Trace IDs will be released. */ -void coresight_trace_id_perf_stop(void); +void coresight_trace_id_perf_stop(struct coresight_trace_id_map *id_map); =20 #endif /* _CORESIGHT_TRACE_ID_H */ diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 9c3067e2e38b..197949fd2c35 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -227,14 +227,12 @@ struct coresight_sysfs_link { * @used_ids: Bitmap to register available (bit =3D 0) and in use (bit =3D= 1) IDs. * Initialised so that the reserved IDs are permanently marked as * in use. - * @pend_rel_ids: CPU IDs that have been released by the trace source but = not - * yet marked as available, to allow re-allocation to the same - * CPU during a perf session. + * @perf_cs_etm_session_active: Number of Perf sessions using this ID map. */ struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); - DECLARE_BITMAP(pend_rel_ids, CORESIGHT_TRACE_IDS_MAX); atomic_t __percpu *cpu_map; + atomic_t perf_cs_etm_session_active; }; =20 /** --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DB8E16CD3F for ; Mon, 22 Jul 2024 10:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643230; cv=none; b=GpwlYGNaNuR9HB0G3mcVJiE5Mz40NTbxtSYc4VWMcjG2eFW4oXQbhBTLvjVTZnMbuGBtQaX6seIWO5y9rU3uZk4fBriLuZVGb3ownJ0nEFlS5615yHCDWMMZNhVL91h+B/ae1S8PENCXEFk9bgADdj4CGDNmkAbJJM/t4f7S9iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643230; c=relaxed/simple; bh=fJ/zk4sI5hDeFJ8JK7nyxy+JEwWUtC1QD5z/TV3AQkg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A4CZmwe2+f9druB1mP/GacSp0qcY9bAVk8Xd0tdKoFxveu2fJF3Dn3v9FWmmpzAh6YnXvDmNRTf/2ESpdL2vrECkqyPAASnlDxo2YReU73TLe2NHjbRU/iDqS8fiafKy2PbGEsBsyDHYDFB1FbItZNUieOZjSx3aDkwDbd/mSkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=oB5gEgPK; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oB5gEgPK" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4266ea6a488so34693465e9.1 for ; Mon, 22 Jul 2024 03:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643227; x=1722248027; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KDPT+SohkS2L9e6jRwH/Ybo4YFVpFyjtzqXPW1x2dY8=; b=oB5gEgPKgkN9YKqG005Oe7l5L/ffNb49U+pDEKTj6XaFjit+5yrW1cnHFU86FmKBbx 2yCgyfAByydz7sl/LA/JB6T/Wbas1SNFXAaveiNF0mh/g+fBCr+XFotxAoBG9YDKrUet 97LRHnZEJwgaOa2+Y6aA7kOvW58zkgjXMLQT6Pmdjy7g13xH7XUFkyYK+egK7a1/6Zf+ zoB4/J95hlRec/A4HU4OYj2iIthOvMeFfboUOkBHLMZSyaV4xX0fKuHZx5hOWlRQp6zE fjxnWNHaNjQv0tn/gvPR7m5v64UHB5Axhq2T4iCQnEN+sO+PuFtq/pO3lwYR3S2K3PYK Mn1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643227; x=1722248027; h=content-transfer-encoding:mime-version: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=KDPT+SohkS2L9e6jRwH/Ybo4YFVpFyjtzqXPW1x2dY8=; b=wOBchiVgbUwyKv9YEARaaIor3msaJb+scQwKzvxE46KUZvPruvBz4XQH9jxrpPKaIu lUpVgQ31Rndg6gy8wlMVbpz/uOwW3ppuIHwfwHxvTlY59t3Q06dWsz3RrUILfK+pj83L GDgekYn9xd3z7A53lQCshWindi1Nbmp0gFOr0/JGuC5+XLCKBcPnN0rESI2pB2DXlAoQ t/F7CII+vQamKltEcBTISQ9cI6JmRIz8hSEqh6ZOX4763/zo21OlsOQLJMBW2IIjW6qn Thx1hN82+aCHuThJW27XUflUMe/J2rjNdjm88pnhUIsMSpxB9q/xQVRQCHh9AIv2gXrN cgSw== X-Forwarded-Encrypted: i=1; AJvYcCUl1RMRstwgFeefX1JlHBqQjFd2EyVpCnKFtWoLlQJiSGPtAY5VW4fNJZqtGXLiTLPoDuQDlb7ua671RShqnHYqkLfFdCsxzrVyEX4O X-Gm-Message-State: AOJu0YyNsmDpZD6+DZ8NxvGgAqHctw7yxNB7Yatkhr1ap6gN098lANcX gCOeb8gL9Z+T5jzMrdXfeSvJkCm4nMNVXE002iLCQcPpcUjjL8HDrdU41K6yAFg= X-Google-Smtp-Source: AGHT+IEF/yoLSdvMIE/olXGPCBno7lcjbtysDOgtFqxYSK5IvP4v88qAJ20p7sXbE3UZY9M3aUZyrA== X-Received: by 2002:a05:600c:4fd3:b0:424:aa35:9fb9 with SMTP id 5b1f17b1804b1-427dc515d0bmr48796895e9.2.1721643226834; Mon, 22 Jul 2024 03:13:46 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:46 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , Leo Yan , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 16/17] coresight: Emit sink ID in the HW_ID packets Date: Mon, 22 Jul 2024 11:11:58 +0100 Message-Id: <20240722101202.26915-17-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark For Perf to be able to decode when per-sink trace IDs are used, emit the sink that's being written to for each ETM. Perf currently errors out if it sees a newer packet version so instead of bumping it, add a new minor version field. This can be used to signify new versions that have backwards compatible fields. Considering this change is only for high core count machines, it doesn't make sense to make a breaking change for everyone. Signed-off-by: James Clark Tested-by: Leo Yan Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-core.c | 26 ++++++++++--------- .../hwtracing/coresight/coresight-etm-perf.c | 16 ++++++++---- drivers/hwtracing/coresight/coresight-priv.h | 1 + include/linux/coresight-pmu.h | 17 +++++++++--- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index faf560ba8d64..c427e9344a84 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -487,23 +487,25 @@ struct coresight_device *coresight_get_sink(struct li= st_head *path) return csdev; } =20 +u32 coresight_get_sink_id(struct coresight_device *csdev) +{ + if (!csdev->ea) + return 0; + + /* + * See function etm_perf_add_symlink_sink() to know where + * this comes from. + */ + return (u32) (unsigned long) csdev->ea->var; +} + static int coresight_sink_by_id(struct device *dev, const void *data) { struct coresight_device *csdev =3D to_coresight_device(dev); - unsigned long hash; =20 if (csdev->type =3D=3D CORESIGHT_DEV_TYPE_SINK || - csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) { - - if (!csdev->ea) - return 0; - /* - * See function etm_perf_add_symlink_sink() to know where - * this comes from. - */ - hash =3D (unsigned long)csdev->ea->var; - - if ((u32)hash =3D=3D *(u32 *)data) + csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) { + if (coresight_get_sink_id(csdev) =3D=3D *(u32 *)data) return 1; } =20 diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwt= racing/coresight/coresight-etm-perf.c index 70c99f0409b2..ad6a8f4b70b6 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -460,6 +460,7 @@ static void etm_event_start(struct perf_event *event, i= nt flags) struct coresight_device *sink, *csdev =3D per_cpu(csdev_src, cpu); struct list_head *path; u64 hw_id; + u8 trace_id; =20 if (!csdev) goto fail; @@ -512,11 +513,16 @@ static void etm_event_start(struct perf_event *event,= int flags) */ if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) { cpumask_set_cpu(cpu, &event_data->aux_hwid_done); - hw_id =3D FIELD_PREP(CS_AUX_HW_ID_VERSION_MASK, - CS_AUX_HW_ID_CURR_VERSION); - hw_id |=3D FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, - coresight_trace_id_read_cpu_id_map(cpu, - &sink->perf_sink_id_map)); + + trace_id =3D coresight_trace_id_read_cpu_id_map(cpu, &sink->perf_sink_id= _map); + + hw_id =3D FIELD_PREP(CS_AUX_HW_ID_MAJOR_VERSION_MASK, + CS_AUX_HW_ID_MAJOR_VERSION); + hw_id |=3D FIELD_PREP(CS_AUX_HW_ID_MINOR_VERSION_MASK, + CS_AUX_HW_ID_MINOR_VERSION); + hw_id |=3D FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, trace_id); + hw_id |=3D FIELD_PREP(CS_AUX_HW_ID_SINK_ID_MASK, coresight_get_sink_id(s= ink)); + perf_report_aux_output_id(event, hw_id); } =20 diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtraci= ng/coresight/coresight-priv.h index 61a46d3bdcc8..05f891ca6b5c 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -148,6 +148,7 @@ int coresight_make_links(struct coresight_device *orig, struct coresight_device *target); void coresight_remove_links(struct coresight_device *orig, struct coresight_connection *conn); +u32 coresight_get_sink_id(struct coresight_device *csdev); =20 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X) extern int etm_readl_cp14(u32 off, unsigned int *val); diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index 51ac441a37c3..89b0ac0014b0 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -49,12 +49,21 @@ * Interpretation of the PERF_RECORD_AUX_OUTPUT_HW_ID payload. * Used to associate a CPU with the CoreSight Trace ID. * [07:00] - Trace ID - uses 8 bits to make value easy to read in file. - * [59:08] - Unused (SBZ) - * [63:60] - Version + * [39:08] - Sink ID - as reported in /sys/bus/event_source/devices/cs_etm= /sinks/ + * Added in minor version 1. + * [55:40] - Unused (SBZ) + * [59:56] - Minor Version - previously existing fields are compatible with + * all minor versions. + * [63:60] - Major Version - previously existing fields mean different thi= ngs + * in new major versions. */ #define CS_AUX_HW_ID_TRACE_ID_MASK GENMASK_ULL(7, 0) -#define CS_AUX_HW_ID_VERSION_MASK GENMASK_ULL(63, 60) +#define CS_AUX_HW_ID_SINK_ID_MASK GENMASK_ULL(39, 8) =20 -#define CS_AUX_HW_ID_CURR_VERSION 0 +#define CS_AUX_HW_ID_MINOR_VERSION_MASK GENMASK_ULL(59, 56) +#define CS_AUX_HW_ID_MAJOR_VERSION_MASK GENMASK_ULL(63, 60) + +#define CS_AUX_HW_ID_MAJOR_VERSION 0 +#define CS_AUX_HW_ID_MINOR_VERSION 1 =20 #endif --=20 2.34.1 From nobody Wed Dec 17 19:18:25 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B88116E872 for ; Mon, 22 Jul 2024 10:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643235; cv=none; b=TgdEbp3Z+jCCmBOosNEshWn6mAHfUS7+GbvhzN7Olu79MSCPad6tTbs9eEyQuyWXA3ysVzzQqvy4fWWCljfbZ4GHYJ2SxQgWaS+ddBgWoUxK8AIAcAd/WUdNYV3I3sSlO25FGHtBpQOMTDzapapAjxKKdZUhv8ZYAueQEir3uvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721643235; c=relaxed/simple; bh=jrx2xOG+BGl3DXknE6CcRbBSOPc6efmotOncGu9ZjVg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lB8axKT8OZlHL3GZc8MAgmD9mB0IBKEqyN4bXf+L2HzNj+99dX8wehg6eBMAdA6Ui+wOFKnKUeWEDYWy3UXOts+6/D1SNoYZN9eQ4x8yo7SElaTRQ7TcxebnkLy5Hcp6faqkpKAz11sk0/PxrqQ01CGdHnhHLnRsFvwRgr16D1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=KzUpwofy; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KzUpwofy" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-426636ef8c9so28667735e9.2 for ; Mon, 22 Jul 2024 03:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643231; x=1722248031; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j+BH4X7qQ4KNzfIEiAndweOYoOD6xkKc0EkDm+LBpWo=; b=KzUpwofyDg6q7WgXqy1Ry12hYuU656Ibr45vZmjk1yKbOgq3RbA5RT67If+R76Acaj uLbuakJDvVnDPltMu0PsKc8mGidNncnPffKMslaSYvqnhhC5LhwzTxlQ7xGZ67D0wWXe NOs3Z+uC9gnVpeQI6yqG8umD4tEi4v93Q9WbKVxpeJUmRuU7N6A/8NBIj/nLQAnML/2K KPR4lbaaAUgpuvy8uxpC8R2i4Zgch/fyaRmsbqZmyDFStCZRdEionp5nZMkDQPNoFP54 oN70drZ916xLDeK/OzHFXFdiAwJoYfBFWYsFKWlAIESuem3rjdunprJaulWqmEGegkwI tQrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643231; x=1722248031; h=content-transfer-encoding:mime-version: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=j+BH4X7qQ4KNzfIEiAndweOYoOD6xkKc0EkDm+LBpWo=; b=ZdFxIxUOGI2XS26rwBJqCAXdtkjc46PEwSkavfKL6OHdYWErGLN3cnQZIxCxHu83FN YsQOqlorpJ49msGOwKTaCWbb/lnze12d4noCmVzU2paGRCgjl0VQnM+CnBEui2oKdyjY IaUGXBJBLwqq8UADiNrr7KpxkaPBlchxaR7YP6iTRw6Lp0eQZ/pIkJK1AJER/eA83MAN ZuXomV0DeaL31lyvYWLOnkPSsQEHgmU4U3TPWTTZkEjJd5tLpjthsTMMbo0x/6N/2c/c joGRYjcTW2CUnVYCm2QpbqAdWrZ3kHakWAe6dXB+EoFuF+IPcbulKsdPc7eGoSbWKVOA MdRw== X-Forwarded-Encrypted: i=1; AJvYcCUwoy3VGT37+sq8c5wW8zf/EZGSgmI6I1JCtp0dwDLSUvtDYa/4p+mIzq9B66iNEj2Sd2vYrJ95AhyOAKV8lAMLaEu9Iod8qsDJ7DQi X-Gm-Message-State: AOJu0YxgGmoFBGNkfvt7AtasiE0GRfvxyRhayYvd65zk6lvinn6dUnR3 5smED8mr1OFX/2sxnNtJXI4Mp8do/eQHWTJPk/Bl78AoII+L9EKApNglg87qk9g= X-Google-Smtp-Source: AGHT+IGEih7x54xnRim+kyshwE4WvvKfQZnB7WzqI+VTII9cpDdOreaV8/bNOtGb2AVj31TH/u3YHA== X-Received: by 2002:a05:600c:45ce:b0:426:549c:294c with SMTP id 5b1f17b1804b1-427dc57aaacmr39518275e9.35.1721643231649; Mon, 22 Jul 2024 03:13:51 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:51 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 17/17] coresight: Make trace ID map spinlock local to the map Date: Mon, 22 Jul 2024 11:11:59 +0100 Message-Id: <20240722101202.26915-18-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Clark Reduce contention on the lock by replacing the global lock with one for each map. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark Acked-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-core.c | 1 + .../hwtracing/coresight/coresight-trace-id.c | 26 +++++++++---------- include/linux/coresight.h | 1 + 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtraci= ng/coresight/coresight-core.c index c427e9344a84..ea38ecf26fcb 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1164,6 +1164,7 @@ struct coresight_device *coresight_register(struct co= resight_desc *desc) =20 if (csdev->type =3D=3D CORESIGHT_DEV_TYPE_SINK || csdev->type =3D=3D CORESIGHT_DEV_TYPE_LINKSINK) { + spin_lock_init(&csdev->perf_sink_id_map.lock); csdev->perf_sink_id_map.cpu_map =3D alloc_percpu(atomic_t); if (!csdev->perf_sink_id_map.cpu_map) { kfree(csdev); diff --git a/drivers/hwtracing/coresight/coresight-trace-id.c b/drivers/hwt= racing/coresight/coresight-trace-id.c index bddaed3e5cf8..d98e12cb30ec 100644 --- a/drivers/hwtracing/coresight/coresight-trace-id.c +++ b/drivers/hwtracing/coresight/coresight-trace-id.c @@ -15,12 +15,10 @@ /* Default trace ID map. Used in sysfs mode and for system sources */ static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) =3D ATOMIC_INIT(0); static struct coresight_trace_id_map id_map_default =3D { - .cpu_map =3D &id_map_default_cpu_ids + .cpu_map =3D &id_map_default_cpu_ids, + .lock =3D __SPIN_LOCK_UNLOCKED(id_map_default.lock) }; =20 -/* lock to protect id_map and cpu data */ -static DEFINE_SPINLOCK(id_map_lock); - /* #define TRACE_ID_DEBUG 1 */ #if defined(TRACE_ID_DEBUG) || defined(CONFIG_COMPILE_TEST) =20 @@ -123,11 +121,11 @@ static void coresight_trace_id_release_all(struct cor= esight_trace_id_map *id_map unsigned long flags; int cpu; =20 - spin_lock_irqsave(&id_map_lock, flags); + spin_lock_irqsave(&id_map->lock, flags); bitmap_zero(id_map->used_ids, CORESIGHT_TRACE_IDS_MAX); for_each_possible_cpu(cpu) atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); - spin_unlock_irqrestore(&id_map_lock, flags); + spin_unlock_irqrestore(&id_map->lock, flags); DUMP_ID_MAP(id_map); } =20 @@ -136,7 +134,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, stru= ct coresight_trace_id_map unsigned long flags; int id; =20 - spin_lock_irqsave(&id_map_lock, flags); + spin_lock_irqsave(&id_map->lock, flags); =20 /* check for existing allocation for this CPU */ id =3D _coresight_trace_id_read_cpu_id(cpu, id_map); @@ -163,7 +161,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, stru= ct coresight_trace_id_map atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), id); =20 get_cpu_id_out_unlock: - spin_unlock_irqrestore(&id_map_lock, flags); + spin_unlock_irqrestore(&id_map->lock, flags); =20 DUMP_ID_CPU(cpu, id); DUMP_ID_MAP(id_map); @@ -180,12 +178,12 @@ static void _coresight_trace_id_put_cpu_id(int cpu, s= truct coresight_trace_id_ma if (!id) return; =20 - spin_lock_irqsave(&id_map_lock, flags); + spin_lock_irqsave(&id_map->lock, flags); =20 coresight_trace_id_free(id, id_map); atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0); =20 - spin_unlock_irqrestore(&id_map_lock, flags); + spin_unlock_irqrestore(&id_map->lock, flags); DUMP_ID_CPU(cpu, id); DUMP_ID_MAP(id_map); } @@ -195,10 +193,10 @@ static int coresight_trace_id_map_get_system_id(struc= t coresight_trace_id_map *i unsigned long flags; int id; =20 - spin_lock_irqsave(&id_map_lock, flags); + spin_lock_irqsave(&id_map->lock, flags); /* prefer odd IDs for system components to avoid legacy CPU IDS */ id =3D coresight_trace_id_alloc_new_id(id_map, 0, true); - spin_unlock_irqrestore(&id_map_lock, flags); + spin_unlock_irqrestore(&id_map->lock, flags); =20 DUMP_ID(id); DUMP_ID_MAP(id_map); @@ -209,9 +207,9 @@ static void coresight_trace_id_map_put_system_id(struct= coresight_trace_id_map * { unsigned long flags; =20 - spin_lock_irqsave(&id_map_lock, flags); + spin_lock_irqsave(&id_map->lock, flags); coresight_trace_id_free(id, id_map); - spin_unlock_irqrestore(&id_map_lock, flags); + spin_unlock_irqrestore(&id_map->lock, flags); =20 DUMP_ID(id); DUMP_ID_MAP(id_map); diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 197949fd2c35..c13342594278 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -233,6 +233,7 @@ struct coresight_trace_id_map { DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX); atomic_t __percpu *cpu_map; atomic_t perf_cs_etm_session_active; + spinlock_t lock; }; =20 /** --=20 2.34.1