Skip to content

Commit

Permalink
perf: cs-etm: Fixes issues driving the trace decoder.
Browse files Browse the repository at this point in the history
The routine in cs-etm.c that was driving trace data through the
decoder was ignoring an error return, resulting in an infinite loop.

The cs-etm routines were assuming that the trace blocks in perf.data
were contiguous trace and driving the decoder accordingly. As they cannot
be contiguous the decoder must be reset between blocks to force re-sync
and ensure that only valid trace is decoded.

Adds reset call to cs-etm-decoder.c API and appropriate call in
cs-etm.c between blocks.

Signed-off-by: Mike Leach <mike.leach@linaro.org>
  • Loading branch information
mikel-armbb authored and mathieupoirier committed May 1, 2017
1 parent 8ca6ef5 commit f78c495
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
Expand Up @@ -103,6 +103,20 @@ int cs_etm_decoder__flush(struct cs_etm_decoder *decoder)
return cs_etm_decoder__flush_packet(decoder);
}

int cs_etm_decoder__reset(struct cs_etm_decoder *decoder)
{
ocsd_datapath_resp_t dp_ret = OCSD_RESP_CONT;
dp_ret = ocsd_dt_process_data(decoder->dcd_tree,
OCSD_OP_RESET,
0,
0,
NULL,
NULL);
if(OCSD_DATA_RESP_IS_FATAL(dp_ret))
return -1;
return 0;
}

static int cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
const ocsd_generic_trace_elem *elem,
const uint8_t trace_chan_id,
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
Expand Up @@ -113,6 +113,7 @@ const struct cs_etm_state *cs_etm_decoder__process_data_block(struct cs_etm_deco
const uint8_t *,
size_t,
size_t *);
int cs_etm_decoder__reset(struct cs_etm_decoder *);

#endif /* INCLUDE__CS_ETM_DECODER_H__ */

13 changes: 10 additions & 3 deletions tools/perf/util/cs-etm.c
Expand Up @@ -989,7 +989,12 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq, u64 *timestamp)
err = cs_etm__get_trace(&buffer,etmq);
if (err <= 0)
return err;

/* cannot assume consecutive blocks in the data file are contiguous trace
as will have start/stopped. Reset the decoder to force re-sync */
err = cs_etm_decoder__reset(etmq->decoder);
if (err != 0)
return err;

do {
size_t processed = 0;
etmq->state = cs_etm_decoder__process_data_block(etmq->decoder,
Expand All @@ -1000,8 +1005,10 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq, u64 *timestamp)
err = etmq->state->err;
etmq->offset += processed;
buffer_used += processed;
if (!err)
cs_etm__sample(etmq, &cpu);
if(err)
return err;
cs_etm__sample(etmq, &cpu);

} while (!etmq->eot && (buffer.len > buffer_used));

/*
Expand Down

0 comments on commit f78c495

Please sign in to comment.