Commit 06220bf4 authored by Leo Yan's avatar Leo Yan Committed by Arnaldo Carvalho de Melo

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: default avatarLeo Yan <leo.yan@linaro.org>
Reviewed-by: default avatarMathieu 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ca45d843
...@@ -293,6 +293,7 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) ...@@ -293,6 +293,7 @@ static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder)
decoder->packet_buffer[i].last_instr_type = 0; decoder->packet_buffer[i].last_instr_type = 0;
decoder->packet_buffer[i].last_instr_subtype = 0; decoder->packet_buffer[i].last_instr_subtype = 0;
decoder->packet_buffer[i].last_instr_cond = 0; decoder->packet_buffer[i].last_instr_cond = 0;
decoder->packet_buffer[i].flags = 0;
decoder->packet_buffer[i].cpu = INT_MIN; decoder->packet_buffer[i].cpu = INT_MIN;
} }
} }
...@@ -329,6 +330,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, ...@@ -329,6 +330,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
decoder->packet_buffer[et].last_instr_type = 0; decoder->packet_buffer[et].last_instr_type = 0;
decoder->packet_buffer[et].last_instr_subtype = 0; decoder->packet_buffer[et].last_instr_subtype = 0;
decoder->packet_buffer[et].last_instr_cond = 0; decoder->packet_buffer[et].last_instr_cond = 0;
decoder->packet_buffer[et].flags = 0;
if (decoder->packet_count == MAX_BUFFER - 1) if (decoder->packet_count == MAX_BUFFER - 1)
return OCSD_RESP_WAIT; return OCSD_RESP_WAIT;
......
...@@ -45,6 +45,7 @@ struct cs_etm_packet { ...@@ -45,6 +45,7 @@ struct cs_etm_packet {
u32 instr_count; u32 instr_count;
u32 last_instr_type; u32 last_instr_type;
u32 last_instr_subtype; u32 last_instr_subtype;
u32 flags;
u8 last_instr_cond; u8 last_instr_cond;
u8 last_instr_taken_branch; u8 last_instr_taken_branch;
u8 last_instr_size; u8 last_instr_size;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/log2.h> #include <linux/log2.h>
#include <linux/types.h> #include <linux/types.h>
#include <opencsd/ocsd_if_types.h>
#include <stdlib.h> #include <stdlib.h>
#include "auxtrace.h" #include "auxtrace.h"
...@@ -719,7 +720,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, ...@@ -719,7 +720,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
sample.stream_id = etmq->etm->instructions_id; sample.stream_id = etmq->etm->instructions_id;
sample.period = period; sample.period = period;
sample.cpu = etmq->packet->cpu; sample.cpu = etmq->packet->cpu;
sample.flags = 0; sample.flags = etmq->prev_packet->flags;
sample.insn_len = 1; sample.insn_len = 1;
sample.cpumode = event->sample.header.misc; sample.cpumode = event->sample.header.misc;
...@@ -778,7 +779,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq) ...@@ -778,7 +779,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq)
sample.stream_id = etmq->etm->branches_id; sample.stream_id = etmq->etm->branches_id;
sample.period = 1; sample.period = 1;
sample.cpu = etmq->packet->cpu; sample.cpu = etmq->packet->cpu;
sample.flags = 0; sample.flags = etmq->prev_packet->flags;
sample.cpumode = event->sample.header.misc; sample.cpumode = event->sample.header.misc;
/* /*
...@@ -1107,6 +1108,80 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq) ...@@ -1107,6 +1108,80 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq)
return 0; return 0;
} }
static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)
{
struct cs_etm_packet *packet = etmq->packet;
switch (packet->sample_type) {
case CS_ETM_RANGE:
/*
* Immediate branch instruction without neither link nor
* return flag, it's normal branch instruction within
* the function.
*/
if (packet->last_instr_type == OCSD_INSTR_BR &&
packet->last_instr_subtype == OCSD_S_INSTR_NONE) {
packet->flags = PERF_IP_FLAG_BRANCH;
if (packet->last_instr_cond)
packet->flags |= PERF_IP_FLAG_CONDITIONAL;
}
/*
* Immediate branch instruction with link (e.g. BL), this is
* branch instruction for function call.
*/
if (packet->last_instr_type == OCSD_INSTR_BR &&
packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK)
packet->flags = PERF_IP_FLAG_BRANCH |
PERF_IP_FLAG_CALL;
/*
* Indirect branch instruction with link (e.g. BLR), this is
* branch instruction for function call.
*/
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK)
packet->flags = PERF_IP_FLAG_BRANCH |
PERF_IP_FLAG_CALL;
/*
* Indirect branch instruction with subtype of
* OCSD_S_INSTR_V7_IMPLIED_RET, this is explicit hint for
* function return for A32/T32.
*/
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
packet->last_instr_subtype == OCSD_S_INSTR_V7_IMPLIED_RET)
packet->flags = PERF_IP_FLAG_BRANCH |
PERF_IP_FLAG_RETURN;
/*
* Indirect branch instruction without link (e.g. BR), usually
* this is used for function return, especially for functions
* within dynamic link lib.
*/
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
packet->last_instr_subtype == OCSD_S_INSTR_NONE)
packet->flags = PERF_IP_FLAG_BRANCH |
PERF_IP_FLAG_RETURN;
/* Return instruction for function return. */
if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT &&
packet->last_instr_subtype == OCSD_S_INSTR_V8_RET)
packet->flags = PERF_IP_FLAG_BRANCH |
PERF_IP_FLAG_RETURN;
break;
case CS_ETM_DISCONTINUITY:
case CS_ETM_EXCEPTION:
case CS_ETM_EXCEPTION_RET:
case CS_ETM_EMPTY:
default:
break;
}
return 0;
}
static int cs_etm__run_decoder(struct cs_etm_queue *etmq) static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
{ {
struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_auxtrace *etm = etmq->etm;
...@@ -1158,6 +1233,17 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) ...@@ -1158,6 +1233,17 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
*/ */
break; break;
/*
* Since packet addresses are swapped in packet
* handling within below switch() statements,
* thus setting sample flags must be called
* prior to switch() statement to use address
* information before packets swapping.
*/
err = cs_etm__set_sample_flags(etmq);
if (err < 0)
break;
switch (etmq->packet->sample_type) { switch (etmq->packet->sample_type) {
case CS_ETM_RANGE: case CS_ETM_RANGE:
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment