Commit 95c6fe97 authored by Leo Yan's avatar Leo Yan Committed by Arnaldo Carvalho de Melo

perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata

If packet processing wants to know the packet is bound with which ETM
version, it needs to access metadata to decide that based on metadata
magic number; but we cannot simply to use CPU logic ID number as index
to access metadata sequential array, especially when system have
hotplugged off CPUs, the metadata array are only allocated for online
CPUs but not offline CPUs, so the CPU logic number doesn't match with
its index in the array.

This patch is to change tuple from traceID-CPU# to traceID-metadata,
thus it can use the tuple to retrieve metadata pointer according to
traceID.

For safe accessing metadata fields, this patch provides helper function
cs_etm__get_cpu() which is used to return CPU number according to
traceID; cs_etm_decoder__buffer_packet() is the first consumer for this
helper function.
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-6-leo.yan@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 47106e74
...@@ -305,14 +305,12 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, ...@@ -305,14 +305,12 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
enum cs_etm_sample_type sample_type) enum cs_etm_sample_type sample_type)
{ {
u32 et = 0; u32 et = 0;
struct int_node *inode = NULL; int cpu;
if (decoder->packet_count >= MAX_BUFFER - 1) if (decoder->packet_count >= MAX_BUFFER - 1)
return OCSD_RESP_FATAL_SYS_ERR; return OCSD_RESP_FATAL_SYS_ERR;
/* Search the RB tree for the cpu associated with this traceID */ if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0)
inode = intlist__find(traceid_list, trace_chan_id);
if (!inode)
return OCSD_RESP_FATAL_SYS_ERR; return OCSD_RESP_FATAL_SYS_ERR;
et = decoder->tail; et = decoder->tail;
...@@ -322,7 +320,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, ...@@ -322,7 +320,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
decoder->packet_buffer[et].sample_type = sample_type; decoder->packet_buffer[et].sample_type = sample_type;
decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN; decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN;
decoder->packet_buffer[et].cpu = *((int *)inode->priv); decoder->packet_buffer[et].cpu = cpu;
decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR;
decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR;
decoder->packet_buffer[et].instr_count = 0; decoder->packet_buffer[et].instr_count = 0;
......
...@@ -97,6 +97,20 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr) ...@@ -97,6 +97,20 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr)
return CS_ETM_PROTO_ETMV3; return CS_ETM_PROTO_ETMV3;
} }
int cs_etm__get_cpu(u8 trace_chan_id, int *cpu)
{
struct int_node *inode;
u64 *metadata;
inode = intlist__find(traceid_list, trace_chan_id);
if (!inode)
return -EINVAL;
metadata = inode->priv;
*cpu = (int)metadata[CS_ETM_CPU];
return 0;
}
static void cs_etm__packet_dump(const char *pkt_string) static void cs_etm__packet_dump(const char *pkt_string)
{ {
const char *color = PERF_COLOR_BLUE; const char *color = PERF_COLOR_BLUE;
...@@ -252,7 +266,7 @@ static void cs_etm__free(struct perf_session *session) ...@@ -252,7 +266,7 @@ static void cs_etm__free(struct perf_session *session)
cs_etm__free_events(session); cs_etm__free_events(session);
session->auxtrace = NULL; session->auxtrace = NULL;
/* First remove all traceID/CPU# nodes for the RB tree */ /* First remove all traceID/metadata nodes for the RB tree */
intlist__for_each_entry_safe(inode, tmp, traceid_list) intlist__for_each_entry_safe(inode, tmp, traceid_list)
intlist__remove(traceid_list, inode); intlist__remove(traceid_list, inode);
/* Then the RB tree itself */ /* Then the RB tree itself */
...@@ -1519,9 +1533,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, ...@@ -1519,9 +1533,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
0xffffffff); 0xffffffff);
/* /*
* Create an RB tree for traceID-CPU# tuple. Since the conversion has * Create an RB tree for traceID-metadata tuple. Since the conversion
* to be made for each packet that gets decoded, optimizing access in * has to be made for each packet that gets decoded, optimizing access
* anything other than a sequential array is worth doing. * in anything other than a sequential array is worth doing.
*/ */
traceid_list = intlist__new(NULL); traceid_list = intlist__new(NULL);
if (!traceid_list) { if (!traceid_list) {
...@@ -1587,8 +1601,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, ...@@ -1587,8 +1601,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
err = -EINVAL; err = -EINVAL;
goto err_free_metadata; goto err_free_metadata;
} }
/* All good, associate the traceID with the CPU# */ /* All good, associate the traceID with the metadata pointer */
inode->priv = &metadata[j][CS_ETM_CPU]; inode->priv = metadata[j];
} }
/* /*
......
...@@ -53,7 +53,7 @@ enum { ...@@ -53,7 +53,7 @@ enum {
CS_ETMV4_PRIV_MAX, CS_ETMV4_PRIV_MAX,
}; };
/* RB tree for quick conversion between traceID and CPUs */ /* RB tree for quick conversion between traceID and metadata pointers */
struct intlist *traceid_list; struct intlist *traceid_list;
#define KiB(x) ((x) * 1024) #define KiB(x) ((x) * 1024)
...@@ -69,6 +69,7 @@ static const u64 __perf_cs_etmv4_magic = 0x4040404040404040ULL; ...@@ -69,6 +69,7 @@ static const u64 __perf_cs_etmv4_magic = 0x4040404040404040ULL;
#ifdef HAVE_CSTRACE_SUPPORT #ifdef HAVE_CSTRACE_SUPPORT
int cs_etm__process_auxtrace_info(union perf_event *event, int cs_etm__process_auxtrace_info(union perf_event *event,
struct perf_session *session); struct perf_session *session);
int cs_etm__get_cpu(u8 trace_chan_id, int *cpu);
#else #else
static inline int static inline int
cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
...@@ -76,6 +77,12 @@ cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, ...@@ -76,6 +77,12 @@ cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
{ {
return -1; return -1;
} }
static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused,
int *cpu __maybe_unused)
{
return -1;
}
#endif #endif
#endif #endif
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