Skip to content

Commit 06220bf

Browse files
Leo Yanacmel
authored andcommitted
perf cs-etm: Set sample flags for instruction range packet
The perf sample data contains flags to indicate the hardware trace data is belonging to which type branch instruction, thus this can be used to print out the human readable string. Arm CoreSight ETM sample data is missed to set flags and it is always set to zeros, this results in perf tool skips to print string for instruction types. This patch is to set branch instruction flags for instruction range packet. Signed-off-by: Leo Yan <leo.yan@linaro.org> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Robert Walker <robert.walker@arm.com> Cc: Suzuki K Poulouse <suzuki.poulose@arm.com> Cc: coresight ml <coresight@lists.linaro.org> Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190129122842.32041-3-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ca45d84 commit 06220bf

3 files changed

Lines changed: 91 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder)
293293
decoder->packet_buffer[i].last_instr_type = 0;
294294
decoder->packet_buffer[i].last_instr_subtype = 0;
295295
decoder->packet_buffer[i].last_instr_cond = 0;
296+
decoder->packet_buffer[i].flags = 0;
296297
decoder->packet_buffer[i].cpu = INT_MIN;
297298
}
298299
}
@@ -329,6 +330,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
329330
decoder->packet_buffer[et].last_instr_type = 0;
330331
decoder->packet_buffer[et].last_instr_subtype = 0;
331332
decoder->packet_buffer[et].last_instr_cond = 0;
333+
decoder->packet_buffer[et].flags = 0;
332334

333335
if (decoder->packet_count == MAX_BUFFER - 1)
334336
return OCSD_RESP_WAIT;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct cs_etm_packet {
4545
u32 instr_count;
4646
u32 last_instr_type;
4747
u32 last_instr_subtype;
48+
u32 flags;
4849
u8 last_instr_cond;
4950
u8 last_instr_taken_branch;
5051
u8 last_instr_size;

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

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/log2.h>
1313
#include <linux/types.h>
1414

15+
#include <opencsd/ocsd_if_types.h>
1516
#include <stdlib.h>
1617

1718
#include "auxtrace.h"
@@ -719,7 +720,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
719720
sample.stream_id = etmq->etm->instructions_id;
720721
sample.period = period;
721722
sample.cpu = etmq->packet->cpu;
722-
sample.flags = 0;
723+
sample.flags = etmq->prev_packet->flags;
723724
sample.insn_len = 1;
724725
sample.cpumode = event->sample.header.misc;
725726

@@ -778,7 +779,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq)
778779
sample.stream_id = etmq->etm->branches_id;
779780
sample.period = 1;
780781
sample.cpu = etmq->packet->cpu;
781-
sample.flags = 0;
782+
sample.flags = etmq->prev_packet->flags;
782783
sample.cpumode = event->sample.header.misc;
783784

784785
/*
@@ -1107,6 +1108,80 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq)
11071108
return 0;
11081109
}
11091110

1111+
static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)
1112+
{
1113+
struct cs_etm_packet *packet = etmq->packet;
1114+
1115+
switch (packet->sample_type) {
1116+
case CS_ETM_RANGE:
1117+
/*
1118+
* Immediate branch instruction without neither link nor
1119+
* return flag, it's normal branch instruction within
1120+
* the function.
1121+
*/
1122+
if (packet->last_instr_type == OCSD_INSTR_BR &&
1123+
packet->last_instr_subtype == OCSD_S_INSTR_NONE) {
1124+
packet->flags = PERF_IP_FLAG_BRANCH;
1125+
1126+
if (packet->last_instr_cond)
1127+
packet->flags |= PERF_IP_FLAG_CONDITIONAL;
1128+
}
1129+
1130+
/*
1131+
* Immediate branch instruction with link (e.g. BL), this is
1132+
* branch instruction for function call.
1133+
*/
1134+
if (packet->last_instr_type == OCSD_INSTR_BR &&
1135+
packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK)
1136+
packet->flags = PERF_IP_FLAG_BRANCH |
1137+
PERF_IP_FLAG_CALL;
1138+
1139+
/*
1140+
* Indirect branch instruction with link (e.g. BLR), this is
1141+
* branch instruction for function call.
1142+
*/
1143+
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
1144+
packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK)
1145+
packet->flags = PERF_IP_FLAG_BRANCH |
1146+
PERF_IP_FLAG_CALL;
1147+
1148+
/*
1149+
* Indirect branch instruction with subtype of
1150+
* OCSD_S_INSTR_V7_IMPLIED_RET, this is explicit hint for
1151+
* function return for A32/T32.
1152+
*/
1153+
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
1154+
packet->last_instr_subtype == OCSD_S_INSTR_V7_IMPLIED_RET)
1155+
packet->flags = PERF_IP_FLAG_BRANCH |
1156+
PERF_IP_FLAG_RETURN;
1157+
1158+
/*
1159+
* Indirect branch instruction without link (e.g. BR), usually
1160+
* this is used for function return, especially for functions
1161+
* within dynamic link lib.
1162+
*/
1163+
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
1164+
packet->last_instr_subtype == OCSD_S_INSTR_NONE)
1165+
packet->flags = PERF_IP_FLAG_BRANCH |
1166+
PERF_IP_FLAG_RETURN;
1167+
1168+
/* Return instruction for function return. */
1169+
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
1170+
packet->last_instr_subtype == OCSD_S_INSTR_V8_RET)
1171+
packet->flags = PERF_IP_FLAG_BRANCH |
1172+
PERF_IP_FLAG_RETURN;
1173+
break;
1174+
case CS_ETM_DISCONTINUITY:
1175+
case CS_ETM_EXCEPTION:
1176+
case CS_ETM_EXCEPTION_RET:
1177+
case CS_ETM_EMPTY:
1178+
default:
1179+
break;
1180+
}
1181+
1182+
return 0;
1183+
}
1184+
11101185
static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
11111186
{
11121187
struct cs_etm_auxtrace *etm = etmq->etm;
@@ -1158,6 +1233,17 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
11581233
*/
11591234
break;
11601235

1236+
/*
1237+
* Since packet addresses are swapped in packet
1238+
* handling within below switch() statements,
1239+
* thus setting sample flags must be called
1240+
* prior to switch() statement to use address
1241+
* information before packets swapping.
1242+
*/
1243+
err = cs_etm__set_sample_flags(etmq);
1244+
if (err < 0)
1245+
break;
1246+
11611247
switch (etmq->packet->sample_type) {
11621248
case CS_ETM_RANGE:
11631249
/*

0 commit comments

Comments
 (0)