From: James Clark <james.clark@arm.com>
To: coresight@lists.linaro.org
Cc: Mark Rutland <mark.rutland@arm.com>,
branislav.rankov@arm.com, al.grant@arm.com, denik@chromium.org,
Mathieu Poirier <mathieu.poirier@linaro.org>,
suzuki.poulose@arm.com,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Will Deacon <will@kernel.org>, John Garry <john.garry@huawei.com>,
linux-kernel@vger.kernel.org, James Clark <james.clark@arm.com>,
Leo Yan <leo.yan@linaro.org>, Namhyung Kim <namhyung@kernel.org>,
Jiri Olsa <jolsa@redhat.com>,
linux-arm-kernel@lists.infradead.org,
Mike Leach <mike.leach@linaro.org>
Subject: [PATCH 5/7] perf cs-etm: split decode by aux records.
Date: Fri, 12 Feb 2021 16:45:11 +0200 [thread overview]
Message-ID: <20210212144513.31765-6-james.clark@arm.com> (raw)
In-Reply-To: <20210212144513.31765-1-james.clark@arm.com>
The trace data between aux records is not continuous, so the decoder
must be reset between each record to ensure that parsing happens
correctly and without any early exits.
Signed-off-by: James Clark <james.clark@arm.com>
---
tools/perf/util/cs-etm.c | 109 +++++++++++++++++++++++----------------
1 file changed, 64 insertions(+), 45 deletions(-)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 5ab037c2dabe..3026fcf50b5d 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -95,6 +95,7 @@ struct cs_etm_queue {
int aux_record_list_len;
int aux_record_list_idx;
struct perf_record_aux *aux_record_list;
+ bool timestamp_found;
};
/* RB tree for quick conversion between traceID and metadata pointers */
@@ -784,6 +785,9 @@ static int cs_etm__search_first_timestamp(struct cs_etm_queue *etmq)
unsigned int cs_queue_nr;
u8 trace_chan_id;
+ if (etmq->timestamp_found)
+ return 0;
+
/*
* We are under a CPU-wide trace scenario. As such we need to know
* when the code that generated the traces started to execute so that
@@ -792,56 +796,54 @@ static int cs_etm__search_first_timestamp(struct cs_etm_queue *etmq)
* timestamp. The timestamp is then added to the auxtrace min heap
* in order to know what nibble (of all the etmqs) to decode first.
*/
- while (1) {
- /*
- * Fetch an aux_buffer from this etmq. Bail if no more
- * blocks or an error has been encountered.
- */
- ret = cs_etm__get_data_block(etmq);
- if (ret <= 0)
- return ret;
-
- /*
- * Run decoder on the trace block. The decoder will stop when
- * encountering a timestamp, a full packet queue or the end of
- * trace for that block.
- */
- ret = cs_etm__decode_data_block(etmq);
- if (ret)
- return ret;
+ /*
+ * Fetch an aux_buffer from this etmq. Bail if no more
+ * blocks or an error has been encountered.
+ */
+ ret = cs_etm__get_data_block(etmq);
+ if (ret <= 0)
+ return ret;
- /*
- * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all
- * the timestamp calculation for us.
- */
- timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id);
+ /*
+ * Run decoder on the trace block. The decoder will stop when
+ * encountering a timestamp, a full packet queue or the end of
+ * trace for that block.
+ */
+ ret = cs_etm__decode_data_block(etmq);
+ if (ret)
+ return ret;
- /* We found a timestamp, no need to continue. */
- if (timestamp)
- break;
+ /*
+ * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all
+ * the timestamp calculation for us.
+ */
+ timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id);
+ /* We found a timestamp, no need to continue. */
+ if (timestamp) {
/*
- * We didn't find a timestamp so empty all the traceid packet
- * queues before looking for another timestamp packet, either
- * in the current data block or a new one. Packets that were
- * just decoded are useless since no timestamp has been
- * associated with them. As such simply discard them.
+ * We have a timestamp. Add it to the min heap to reflect when
+ * instructions conveyed by the range packets of this traceID queue
+ * started to execute. Once the same has been done for all the traceID
+ * queues of each etmq, redenring and decoding can start in
+ * chronological order.
+ *
+ * Note that packets decoded above are still in the traceID's packet
+ * queue and will be processed in cs_etm__process_queues().
*/
- cs_etm__clear_all_packet_queues(etmq);
+ etmq->timestamp_found = true;
+ cs_queue_nr = TO_CS_QUEUE_NR(etmq->queue_nr, trace_chan_id);
+ return auxtrace_heap__add(&etmq->etm->heap, cs_queue_nr, timestamp);
}
-
/*
- * We have a timestamp. Add it to the min heap to reflect when
- * instructions conveyed by the range packets of this traceID queue
- * started to execute. Once the same has been done for all the traceID
- * queues of each etmq, redenring and decoding can start in
- * chronological order.
- *
- * Note that packets decoded above are still in the traceID's packet
- * queue and will be processed in cs_etm__process_queues().
+ * We didn't find a timestamp so empty all the traceid packet
+ * queues before looking for another timestamp packet, either
+ * in the current data block or a new one. Packets that were
+ * just decoded are useless since no timestamp has been
+ * associated with them. As such simply discard them.
*/
- cs_queue_nr = TO_CS_QUEUE_NR(etmq->queue_nr, trace_chan_id);
- return auxtrace_heap__add(&etmq->etm->heap, cs_queue_nr, timestamp);
+ cs_etm__clear_all_packet_queues(etmq);
+ return 0;
}
static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
@@ -1645,6 +1647,13 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq)
{
int ret;
+ if (etmq->aux_record_list[etmq->aux_record_list_idx].aux_size <= 0) {
+ etmq->aux_record_list_idx++;
+ ret = cs_etm_decoder__reset(etmq->decoder);
+ if (ret)
+ return ret;
+ }
+
if (!etmq->buf_len) {
ret = cs_etm__get_trace(etmq);
if (ret <= 0)
@@ -2016,6 +2025,15 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
{
int ret = 0;
size_t processed = 0;
+ u64 decode_size;
+
+ if (etmq->aux_record_list_idx >= etmq->aux_record_list_len ||
+ etmq->aux_record_list[etmq->aux_record_list_idx].aux_size > etmq->buf_len) {
+ // Assume that aux records always equally divide up the aux buffer
+ // so aux_size should never exceed the remaining buffer to decode.
+ ret = -1;
+ goto out;
+ }
/*
* Packets are decoded and added to the decoder's packet queue
@@ -2024,10 +2042,11 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
* operations that stop processing are a timestamp packet or a full
* decoder buffer queue.
*/
+ decode_size = etmq->aux_record_list[etmq->aux_record_list_idx].aux_size;
ret = cs_etm_decoder__process_data_block(etmq->decoder,
etmq->offset,
&etmq->buf[etmq->buf_used],
- etmq->buf_len,
+ decode_size,
&processed);
if (ret)
goto out;
@@ -2035,7 +2054,7 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq)
etmq->offset += processed;
etmq->buf_used += processed;
etmq->buf_len -= processed;
-
+ etmq->aux_record_list[etmq->aux_record_list_idx].aux_size -= processed;
out:
return ret;
}
@@ -2160,7 +2179,7 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
*/
err = cs_etm__process_traceid_queue(etmq, tidq);
- } while (etmq->buf_len);
+ } while (etmq->aux_record_list[etmq->aux_record_list_idx].aux_size > 0);
if (err == 0)
/* Flush any remaining branch stack entries */
--
2.28.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-02-12 14:47 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-12 14:45 [PATCH 0/7] Split Coresight decode by aux records James Clark
2021-02-12 14:45 ` [PATCH 1/7] perf cs-etm: Split up etm queue setup function James Clark
2021-02-20 8:11 ` Leo Yan
2021-02-12 14:45 ` [PATCH 2/7] perf cs-etm: Only search timestamp in current sample's queue James Clark
2021-02-20 11:50 ` Leo Yan
2021-03-01 15:28 ` James Clark
2021-03-02 11:52 ` Leo Yan
2021-05-06 10:45 ` James Clark
2021-02-12 14:45 ` [PATCH 3/7] perf cs-etm: Save aux records in each etm queue James Clark
2021-02-27 7:10 ` Leo Yan
2021-03-01 15:43 ` James Clark
2021-03-02 12:03 ` Leo Yan
2021-02-12 14:45 ` [PATCH 4/7] perf cs-etm: don't process queues until cs_etm__flush_events James Clark
2021-02-12 14:45 ` James Clark [this message]
2021-02-12 14:45 ` [PATCH 6/7] perf cs-etm: Use existing decode code path for --dump-raw-trace James Clark
2021-02-12 14:45 ` [PATCH 7/7] perf cs-etm: Suppress printing when resetting decoder James Clark
2021-02-24 16:13 ` [PATCH 0/7] Split Coresight decode by aux records Mathieu Poirier
2021-03-01 14:05 ` James Clark
2021-04-15 20:37 ` Mathieu Poirier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210212144513.31765-6-james.clark@arm.com \
--to=james.clark@arm.com \
--cc=al.grant@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=branislav.rankov@arm.com \
--cc=coresight@lists.linaro.org \
--cc=denik@chromium.org \
--cc=john.garry@huawei.com \
--cc=jolsa@redhat.com \
--cc=leo.yan@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.poirier@linaro.org \
--cc=mike.leach@linaro.org \
--cc=namhyung@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).