From nobody Tue Feb 10 00:22:08 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 1DA6815ECC6 for ; Fri, 12 Jul 2024 10:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720779743; cv=none; b=Sa05MBvuEwg8p2Nj2fkKDeNPknjF7J9PzV5+7DqMn6EpToZEtWdZchSGU2SZzQ7VRTLbeVG5cAFZCRpr8x7AxyXrU/z3TRfpVCqMYzRtMzIPuxTkoOe0/R3q8+s0EV4zN/QHt7BbwOLzz3k2yFRIVP5Fd9s9T/BOOGrI3YVGm8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720779743; c=relaxed/simple; bh=X44tn5ZjlSvoGQKdizS38pSs8OKtXiWyeib+ACYsEso=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K9qcLNXHl5OfNR3RLW/sLMz9yVIWoGOJQoOlAWE7YjjZ2WT1iAqJIeG/bLUJa3QzOwln+h1cBp8Z2EiBbWq/o3ZQJmSqpUtZEUmEnSj6/ZRMeVQPQfSlebRpeAM+bspDMETu4aYrZxZqVYKdUK8lxxSIs/VQngAIqO+RZRVL8zI= 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=P6F2jYjV; arc=none smtp.client-ip=209.85.221.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="P6F2jYjV" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-367963ea053so1417034f8f.2 for ; Fri, 12 Jul 2024 03:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720779739; x=1721384539; 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=N+pc5donmvg/OK1Bm2RLmni0QwXbiboabjfXClFm1K0=; b=P6F2jYjVPOR0ie2qM8ziHs0MosmyBRuR7ttnECMqHmSh3pFblKKbcQA7eNs41Uz3Ma aU/0LEfPKdm/byfxh+AuNVEo2UvZQfB9VkO0YRLlypIUtRtXHpnRbqiQHe1DPbCnhCRO +LEGL0MQdD+w7J4VTDTgDLXwRUH1fEem+zHhBz7kLQIosh7AXjcNfPsVZr9jsOuVS4/H NeglkhIy1bjJBcrE17KkfRcdP8xzlx0ErWvLPDTvqAvibiSc3eXpEoWbHucXx24ex3TO 3JkM87r9hwYik0ARAPhXpShCNQDOeODBbgyEDzYHfaRuZS36ZSTVHU8FzAgMYR7hw/8N 7HUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720779739; x=1721384539; 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=N+pc5donmvg/OK1Bm2RLmni0QwXbiboabjfXClFm1K0=; b=p4Nz1jJtwBSfLfkVEHS11ceHEzzRSqv6jPiFHXwoUMN3KfksHfHp9H1+1kdyq3yNjU GfVga6hO5Kcp/t4S29j7qWg9GWTjiadx16o87++z29pf1BIbvpS864WfHRgJXwsbKMHB qJlZ0BR61jpG2CofZKMJK+CXivMsl4vFoUqqaYk439uwt/tkrvAaj40tR/k/1PtTOOIV vdzfelLxbSaRzTcHGQzlHYLGmYVQJVSg5EAXy9EDtzWMJszE6oyFihzN5+TgkA7DPPAg o/rEDc7/PWsPkno01Mse4QIFfx8gQadZWkWryLf1CZSpTPDPrlJ41BALMUF/FXmRtMaV yw3Q== X-Forwarded-Encrypted: i=1; AJvYcCXonf3IF1Qr8ndZQM6A22ByxS6hj4cNVx7vN85AsV6m5S/SE8t/0O/i7M708hmnrv41W9Bwgm+1OUjSVc3OdmTn3f7VToO6dY3/g1mj X-Gm-Message-State: AOJu0Yxlnnyg4Bp//zVlRJrEz47GYpvu6zd7Fvf2wLYPZV0uoXbMhCSU uHDnDvtjKQ/PhYRQBUX1LzE/W4UZIip7gZcU3J9hnF5Ggetfljpej0oXc2PjVDU= X-Google-Smtp-Source: AGHT+IHOAIOfCRod06OlcZ5ANlzMmFjjgRo8/bARChE6gnAyhunVZT4zaek6BiyD/faYihcGyWmF6g== X-Received: by 2002:adf:ce12:0:b0:366:f34d:d0b7 with SMTP id ffacd0b85a97d-367cea8f9b2mr8886266f8f.29.1720779739395; Fri, 12 Jul 2024 03:22:19 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde89164sm9911058f8f.63.2024.07.12.03.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 03:22:19 -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 v5 02/17] perf: cs-etm: Allocate queues for all CPUs Date: Fri, 12 Jul 2024 11:20:11 +0100 Message-Id: <20240712102029.3697965-3-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240712102029.3697965-1-james.clark@linaro.org> References: <20240712102029.3697965-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 Signed-off-by: James Clark Reviewed-by: Mike Leach --- tools/perf/util/cs-etm.c | 76 +++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index f09004c4ba44..1a95c4bb898f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -97,13 +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; - bool formatted; + enum cs_etm_format format; u64 offset; const unsigned char *buf; size_t buf_len, buf_used; @@ -697,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) { @@ -706,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); @@ -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 etmq->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; @@ -1056,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, bool formatted) + unsigned int queue_nr) { struct cs_etm_queue *etmq =3D queue->priv; =20 - if (etmq && formatted !=3D etmq->formatted) { - 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(); @@ -1078,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->formatted =3D formatted; =20 return 0; } @@ -2791,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, true); - 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); @@ -2918,8 +2907,7 @@ 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; - bool formatted; + enum cs_etm_format format; =20 struct cs_etm_auxtrace *etm =3D container_of(session->auxtrace, struct cs_etm_auxtrace, @@ -2985,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. @@ -3001,10 +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; - formatted =3D !(aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW); - - return cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], idx, form= atted); + format =3D (aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW) ? + UNFORMATTED : FORMATTED; + 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' */ @@ -3200,7 +3194,7 @@ static int cs_etm__create_queue_decoders(struct cs_et= m_queue *etmq) * Each queue can only contain data from one CPU when unformatted, so onl= y one decoder is * needed. */ - int decoders =3D etmq->formatted ? etmq->etm->num_cpu : 1; + int decoders =3D etmq->format =3D=3D FORMATTED ? etmq->etm->num_cpu : 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); @@ -3208,7 +3202,7 @@ static int cs_etm__create_queue_decoders(struct cs_et= m_queue *etmq) if (!t_params) goto out_free; =20 - if (cs_etm__init_trace_params(t_params, etmq->etm, etmq->formatted, + if (cs_etm__init_trace_params(t_params, etmq->etm, etmq->format, etmq->queue_nr, decoders)) goto out_free; =20 @@ -3256,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->formatted is unknown for empty queues. */ + assert(empty =3D=3D (etmq->format =3D=3D UNSET)); if (empty) continue; =20 @@ -3275,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 @@ -3309,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, @@ -3333,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 /* @@ -3362,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 { @@ -3487,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