Skip to content

Commit f7ba2ee

Browse files
Leo Yangregkh
authored andcommitted
perf cs-etm: Swap packets for instruction samples
[ Upstream commit d017515 ] If use option '--itrace=iNNN' with Arm CoreSight trace data, perf tool fails inject instruction samples; the root cause is the packets are only swapped for branch samples and last branches but not for instruction samples, so the new coming packets cannot be properly handled for only synthesizing instruction samples. To fix this issue, this patch refactors the code with a new function cs_etm__packet_swap() which is used to swap packets and adds the condition for instruction samples. Signed-off-by: Leo Yan <leo.yan@linaro.org> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Mike Leach <mike.leach@linaro.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Robert Walker <robert.walker@arm.com> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: coresight ml <coresight@lists.linaro.org> Cc: linux-arm-kernel@lists.infradead.org Link: http://lore.kernel.org/lkml/20200219021811.20067-2-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent fc1d08a commit f7ba2ee

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

tools/perf/util/cs-etm.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,23 @@ struct cs_etm_packet_queue
363363
return NULL;
364364
}
365365

366+
static void cs_etm__packet_swap(struct cs_etm_auxtrace *etm,
367+
struct cs_etm_traceid_queue *tidq)
368+
{
369+
struct cs_etm_packet *tmp;
370+
371+
if (etm->sample_branches || etm->synth_opts.last_branch ||
372+
etm->sample_instructions) {
373+
/*
374+
* Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
375+
* the next incoming packet.
376+
*/
377+
tmp = tidq->packet;
378+
tidq->packet = tidq->prev_packet;
379+
tidq->prev_packet = tmp;
380+
}
381+
}
382+
366383
static void cs_etm__packet_dump(const char *pkt_string)
367384
{
368385
const char *color = PERF_COLOR_BLUE;
@@ -1340,7 +1357,6 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
13401357
struct cs_etm_traceid_queue *tidq)
13411358
{
13421359
struct cs_etm_auxtrace *etm = etmq->etm;
1343-
struct cs_etm_packet *tmp;
13441360
int ret;
13451361
u8 trace_chan_id = tidq->trace_chan_id;
13461362
u64 instrs_executed = tidq->packet->instr_count;
@@ -1404,15 +1420,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
14041420
}
14051421
}
14061422

1407-
if (etm->sample_branches || etm->synth_opts.last_branch) {
1408-
/*
1409-
* Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
1410-
* the next incoming packet.
1411-
*/
1412-
tmp = tidq->packet;
1413-
tidq->packet = tidq->prev_packet;
1414-
tidq->prev_packet = tmp;
1415-
}
1423+
cs_etm__packet_swap(etm, tidq);
14161424

14171425
return 0;
14181426
}
@@ -1441,7 +1449,6 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
14411449
{
14421450
int err = 0;
14431451
struct cs_etm_auxtrace *etm = etmq->etm;
1444-
struct cs_etm_packet *tmp;
14451452

14461453
/* Handle start tracing packet */
14471454
if (tidq->prev_packet->sample_type == CS_ETM_EMPTY)
@@ -1476,15 +1483,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
14761483
}
14771484

14781485
swap_packet:
1479-
if (etm->sample_branches || etm->synth_opts.last_branch) {
1480-
/*
1481-
* Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for
1482-
* the next incoming packet.
1483-
*/
1484-
tmp = tidq->packet;
1485-
tidq->packet = tidq->prev_packet;
1486-
tidq->prev_packet = tmp;
1487-
}
1486+
cs_etm__packet_swap(etm, tidq);
14881487

14891488
return err;
14901489
}

0 commit comments

Comments
 (0)