Skip to content

Commit 675f302

Browse files
mathieupoirieracmel
authored andcommitted
perf cs-etm: Add notion of time to decoding code
This patch deals with timestamp packets received from the decoding library in order to give the front end packet processing loop a handle on the time instruction conveyed by range packets have been executed at. Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Tested-by: Leo Yan <leo.yan@linaro.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190524173508.29044-17-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0a6be30 commit 675f302

3 files changed

Lines changed: 143 additions & 4 deletions

File tree

‎tools/perf/util/cs-etm-decoder/cs-etm-decoder.c‎

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,75 @@ cs_etm_decoder__create_etm_packet_printer(struct cs_etm_trace_params *t_params,
269269
trace_config);
270270
}
271271

272+
static ocsd_datapath_resp_t
273+
cs_etm_decoder__do_soft_timestamp(struct cs_etm_queue *etmq,
274+
struct cs_etm_packet_queue *packet_queue,
275+
const uint8_t trace_chan_id)
276+
{
277+
/* No timestamp packet has been received, nothing to do */
278+
if (!packet_queue->timestamp)
279+
return OCSD_RESP_CONT;
280+
281+
packet_queue->timestamp = packet_queue->next_timestamp;
282+
283+
/* Estimate the timestamp for the next range packet */
284+
packet_queue->next_timestamp += packet_queue->instr_count;
285+
packet_queue->instr_count = 0;
286+
287+
/* Tell the front end which traceid_queue needs attention */
288+
cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
289+
290+
return OCSD_RESP_WAIT;
291+
}
292+
293+
static ocsd_datapath_resp_t
294+
cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
295+
const ocsd_generic_trace_elem *elem,
296+
const uint8_t trace_chan_id)
297+
{
298+
struct cs_etm_packet_queue *packet_queue;
299+
300+
/* First get the packet queue for this traceID */
301+
packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id);
302+
if (!packet_queue)
303+
return OCSD_RESP_FATAL_SYS_ERR;
304+
305+
/*
306+
* We've seen a timestamp packet before - simply record the new value.
307+
* Function do_soft_timestamp() will report the value to the front end,
308+
* hence asking the decoder to keep decoding rather than stopping.
309+
*/
310+
if (packet_queue->timestamp) {
311+
packet_queue->next_timestamp = elem->timestamp;
312+
return OCSD_RESP_CONT;
313+
}
314+
315+
/*
316+
* This is the first timestamp we've seen since the beginning of traces
317+
* or a discontinuity. Since timestamps packets are generated *after*
318+
* range packets have been generated, we need to estimate the time at
319+
* which instructions started by substracting the number of instructions
320+
* executed to the timestamp.
321+
*/
322+
packet_queue->timestamp = elem->timestamp - packet_queue->instr_count;
323+
packet_queue->next_timestamp = elem->timestamp;
324+
packet_queue->instr_count = 0;
325+
326+
/* Tell the front end which traceid_queue needs attention */
327+
cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id);
328+
329+
/* Halt processing until we are being told to proceed */
330+
return OCSD_RESP_WAIT;
331+
}
332+
333+
static void
334+
cs_etm_decoder__reset_timestamp(struct cs_etm_packet_queue *packet_queue)
335+
{
336+
packet_queue->timestamp = 0;
337+
packet_queue->next_timestamp = 0;
338+
packet_queue->instr_count = 0;
339+
}
340+
272341
static ocsd_datapath_resp_t
273342
cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue,
274343
const u8 trace_chan_id,
@@ -310,7 +379,8 @@ cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue,
310379
}
311380

312381
static ocsd_datapath_resp_t
313-
cs_etm_decoder__buffer_range(struct cs_etm_packet_queue *packet_queue,
382+
cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq,
383+
struct cs_etm_packet_queue *packet_queue,
314384
const ocsd_generic_trace_elem *elem,
315385
const uint8_t trace_chan_id)
316386
{
@@ -365,13 +435,35 @@ cs_etm_decoder__buffer_range(struct cs_etm_packet_queue *packet_queue,
365435

366436
packet->last_instr_size = elem->last_instr_sz;
367437

438+
/* per-thread scenario, no need to generate a timestamp */
439+
if (cs_etm__etmq_is_timeless(etmq))
440+
goto out;
441+
442+
/*
443+
* The packet queue is full and we haven't seen a timestamp (had we
444+
* seen one the packet queue wouldn't be full). Let the front end
445+
* deal with it.
446+
*/
447+
if (ret == OCSD_RESP_WAIT)
448+
goto out;
449+
450+
packet_queue->instr_count += elem->num_instr_range;
451+
/* Tell the front end we have a new timestamp to process */
452+
ret = cs_etm_decoder__do_soft_timestamp(etmq, packet_queue,
453+
trace_chan_id);
454+
out:
368455
return ret;
369456
}
370457

371458
static ocsd_datapath_resp_t
372459
cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue,
373460
const uint8_t trace_chan_id)
374461
{
462+
/*
463+
* Something happened and who knows when we'll get new traces so
464+
* reset time statistics.
465+
*/
466+
cs_etm_decoder__reset_timestamp(queue);
375467
return cs_etm_decoder__buffer_packet(queue, trace_chan_id,
376468
CS_ETM_DISCONTINUITY);
377469
}
@@ -404,6 +496,7 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue,
404496

405497
static ocsd_datapath_resp_t
406498
cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
499+
struct cs_etm_packet_queue *packet_queue,
407500
const ocsd_generic_trace_elem *elem,
408501
const uint8_t trace_chan_id)
409502
{
@@ -417,6 +510,12 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
417510
if (cs_etm__etmq_set_tid(etmq, tid, trace_chan_id))
418511
return OCSD_RESP_FATAL_SYS_ERR;
419512

513+
/*
514+
* A timestamp is generated after a PE_CONTEXT element so make sure
515+
* to rely on that coming one.
516+
*/
517+
cs_etm_decoder__reset_timestamp(packet_queue);
518+
420519
return OCSD_RESP_CONT;
421520
}
422521

@@ -446,7 +545,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
446545
trace_chan_id);
447546
break;
448547
case OCSD_GEN_TRC_ELEM_INSTR_RANGE:
449-
resp = cs_etm_decoder__buffer_range(packet_queue, elem,
548+
resp = cs_etm_decoder__buffer_range(etmq, packet_queue, elem,
450549
trace_chan_id);
451550
break;
452551
case OCSD_GEN_TRC_ELEM_EXCEPTION:
@@ -457,11 +556,15 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer(
457556
resp = cs_etm_decoder__buffer_exception_ret(packet_queue,
458557
trace_chan_id);
459558
break;
559+
case OCSD_GEN_TRC_ELEM_TIMESTAMP:
560+
resp = cs_etm_decoder__do_hard_timestamp(etmq, elem,
561+
trace_chan_id);
562+
break;
460563
case OCSD_GEN_TRC_ELEM_PE_CONTEXT:
461-
resp = cs_etm_decoder__set_tid(etmq, elem, trace_chan_id);
564+
resp = cs_etm_decoder__set_tid(etmq, packet_queue,
565+
elem, trace_chan_id);
462566
break;
463567
case OCSD_GEN_TRC_ELEM_ADDR_NACC:
464-
case OCSD_GEN_TRC_ELEM_TIMESTAMP:
465568
case OCSD_GEN_TRC_ELEM_CYCLE_COUNT:
466569
case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN:
467570
case OCSD_GEN_TRC_ELEM_EVENT:

‎tools/perf/util/cs-etm.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct cs_etm_queue {
8080
struct cs_etm_decoder *decoder;
8181
struct auxtrace_buffer *buffer;
8282
unsigned int queue_nr;
83+
u8 pending_timestamp;
8384
u64 offset;
8485
const unsigned char *buf;
8586
size_t buf_len, buf_used;
@@ -133,6 +134,19 @@ int cs_etm__get_cpu(u8 trace_chan_id, int *cpu)
133134
return 0;
134135
}
135136

137+
void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
138+
u8 trace_chan_id)
139+
{
140+
/*
141+
* Wnen a timestamp packet is encountered the backend code
142+
* is stopped so that the front end has time to process packets
143+
* that were accumulated in the traceID queue. Since there can
144+
* be more than one channel per cs_etm_queue, we need to specify
145+
* what traceID queue needs servicing.
146+
*/
147+
etmq->pending_timestamp = trace_chan_id;
148+
}
149+
136150
static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue)
137151
{
138152
int i;
@@ -942,6 +956,11 @@ int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq,
942956
return 0;
943957
}
944958

959+
bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq)
960+
{
961+
return !!etmq->etm->timeless_decoding;
962+
}
963+
945964
static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
946965
struct cs_etm_traceid_queue *tidq,
947966
u64 addr, u64 period)

‎tools/perf/util/cs-etm.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ struct cs_etm_packet_queue {
150150
u32 packet_count;
151151
u32 head;
152152
u32 tail;
153+
u32 instr_count;
154+
u64 timestamp;
155+
u64 next_timestamp;
153156
struct cs_etm_packet packet_buffer[CS_ETM_PACKET_MAX_BUFFER];
154157
};
155158

@@ -183,6 +186,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
183186
int cs_etm__get_cpu(u8 trace_chan_id, int *cpu);
184187
int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq,
185188
pid_t tid, u8 trace_chan_id);
189+
bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq);
190+
void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
191+
u8 trace_chan_id);
186192
struct cs_etm_packet_queue
187193
*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id);
188194
#else
@@ -207,6 +213,17 @@ static inline int cs_etm__etmq_set_tid(
207213
return -1;
208214
}
209215

216+
static inline bool cs_etm__etmq_is_timeless(
217+
struct cs_etm_queue *etmq __maybe_unused)
218+
{
219+
/* What else to return? */
220+
return true;
221+
}
222+
223+
static inline void cs_etm__etmq_set_traceid_queue_timestamp(
224+
struct cs_etm_queue *etmq __maybe_unused,
225+
u8 trace_chan_id __maybe_unused) {}
226+
210227
static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue(
211228
struct cs_etm_queue *etmq __maybe_unused,
212229
u8 trace_chan_id __maybe_unused)

0 commit comments

Comments
 (0)