Skip to content

Commit 95c6fe9

Browse files
Leo Yanacmel
authored andcommitted
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: 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-6-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 47106e7 commit 95c6fe9

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,12 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
305305
enum cs_etm_sample_type sample_type)
306306
{
307307
u32 et = 0;
308-
struct int_node *inode = NULL;
308+
int cpu;
309309

310310
if (decoder->packet_count >= MAX_BUFFER - 1)
311311
return OCSD_RESP_FATAL_SYS_ERR;
312312

313-
/* Search the RB tree for the cpu associated with this traceID */
314-
inode = intlist__find(traceid_list, trace_chan_id);
315-
if (!inode)
313+
if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0)
316314
return OCSD_RESP_FATAL_SYS_ERR;
317315

318316
et = decoder->tail;
@@ -322,7 +320,7 @@ cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder,
322320

323321
decoder->packet_buffer[et].sample_type = sample_type;
324322
decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN;
325-
decoder->packet_buffer[et].cpu = *((int *)inode->priv);
323+
decoder->packet_buffer[et].cpu = cpu;
326324
decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR;
327325
decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR;
328326
decoder->packet_buffer[et].instr_count = 0;

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ static u32 cs_etm__get_v7_protocol_version(u32 etmidr)
9797
return CS_ETM_PROTO_ETMV3;
9898
}
9999

100+
int cs_etm__get_cpu(u8 trace_chan_id, int *cpu)
101+
{
102+
struct int_node *inode;
103+
u64 *metadata;
104+
105+
inode = intlist__find(traceid_list, trace_chan_id);
106+
if (!inode)
107+
return -EINVAL;
108+
109+
metadata = inode->priv;
110+
*cpu = (int)metadata[CS_ETM_CPU];
111+
return 0;
112+
}
113+
100114
static void cs_etm__packet_dump(const char *pkt_string)
101115
{
102116
const char *color = PERF_COLOR_BLUE;
@@ -252,7 +266,7 @@ static void cs_etm__free(struct perf_session *session)
252266
cs_etm__free_events(session);
253267
session->auxtrace = NULL;
254268

255-
/* First remove all traceID/CPU# nodes for the RB tree */
269+
/* First remove all traceID/metadata nodes for the RB tree */
256270
intlist__for_each_entry_safe(inode, tmp, traceid_list)
257271
intlist__remove(traceid_list, inode);
258272
/* Then the RB tree itself */
@@ -1519,9 +1533,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
15191533
0xffffffff);
15201534

15211535
/*
1522-
* Create an RB tree for traceID-CPU# tuple. Since the conversion has
1523-
* to be made for each packet that gets decoded, optimizing access in
1524-
* anything other than a sequential array is worth doing.
1536+
* Create an RB tree for traceID-metadata tuple. Since the conversion
1537+
* has to be made for each packet that gets decoded, optimizing access
1538+
* in anything other than a sequential array is worth doing.
15251539
*/
15261540
traceid_list = intlist__new(NULL);
15271541
if (!traceid_list) {
@@ -1587,8 +1601,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
15871601
err = -EINVAL;
15881602
goto err_free_metadata;
15891603
}
1590-
/* All good, associate the traceID with the CPU# */
1591-
inode->priv = &metadata[j][CS_ETM_CPU];
1604+
/* All good, associate the traceID with the metadata pointer */
1605+
inode->priv = metadata[j];
15921606
}
15931607

15941608
/*

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum {
5353
CS_ETMV4_PRIV_MAX,
5454
};
5555

56-
/* RB tree for quick conversion between traceID and CPUs */
56+
/* RB tree for quick conversion between traceID and metadata pointers */
5757
struct intlist *traceid_list;
5858

5959
#define KiB(x) ((x) * 1024)
@@ -69,13 +69,20 @@ static const u64 __perf_cs_etmv4_magic = 0x4040404040404040ULL;
6969
#ifdef HAVE_CSTRACE_SUPPORT
7070
int cs_etm__process_auxtrace_info(union perf_event *event,
7171
struct perf_session *session);
72+
int cs_etm__get_cpu(u8 trace_chan_id, int *cpu);
7273
#else
7374
static inline int
7475
cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused,
7576
struct perf_session *session __maybe_unused)
7677
{
7778
return -1;
7879
}
80+
81+
static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused,
82+
int *cpu __maybe_unused)
83+
{
84+
return -1;
85+
}
7986
#endif
8087

8188
#endif

0 commit comments

Comments
 (0)