1 // SPDX-License-Identifier: GPL-2.0
3 * Arm Statistical Profiling Extensions (SPE) support
4 * Copyright (c) 2017-2018, Arm Ltd.
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/bitops.h>
14 #include <linux/log2.h>
27 #include "arm-spe-pkt-decoder.h"
30 struct auxtrace auxtrace
;
31 struct auxtrace_queues queues
;
32 struct auxtrace_heap heap
;
34 struct perf_session
*session
;
35 struct machine
*machine
;
39 struct arm_spe_queue
{
41 unsigned int queue_nr
;
42 struct auxtrace_buffer
*buffer
;
50 static void arm_spe_dump(struct arm_spe
*spe __maybe_unused
,
51 unsigned char *buf
, size_t len
)
53 struct arm_spe_pkt packet
;
56 char desc
[ARM_SPE_PKT_DESC_MAX
];
57 const char *color
= PERF_COLOR_BLUE
;
59 color_fprintf(stdout
, color
,
60 ". ... ARM SPE data: size %zu bytes\n",
64 ret
= arm_spe_get_packet(buf
, len
, &packet
);
70 color_fprintf(stdout
, color
, " %08x: ", pos
);
71 for (i
= 0; i
< pkt_len
; i
++)
72 color_fprintf(stdout
, color
, " %02x", buf
[i
]);
74 color_fprintf(stdout
, color
, " ");
76 ret
= arm_spe_pkt_desc(&packet
, desc
,
77 ARM_SPE_PKT_DESC_MAX
);
79 color_fprintf(stdout
, color
, " %s\n", desc
);
81 color_fprintf(stdout
, color
, " Bad packet!\n");
89 static void arm_spe_dump_event(struct arm_spe
*spe
, unsigned char *buf
,
93 arm_spe_dump(spe
, buf
, len
);
96 static int arm_spe_process_event(struct perf_session
*session __maybe_unused
,
97 union perf_event
*event __maybe_unused
,
98 struct perf_sample
*sample __maybe_unused
,
99 struct perf_tool
*tool __maybe_unused
)
104 static int arm_spe_process_auxtrace_event(struct perf_session
*session
,
105 union perf_event
*event
,
106 struct perf_tool
*tool __maybe_unused
)
108 struct arm_spe
*spe
= container_of(session
->auxtrace
, struct arm_spe
,
110 struct auxtrace_buffer
*buffer
;
112 int fd
= perf_data__fd(session
->data
);
115 if (perf_data__is_pipe(session
->data
)) {
118 data_offset
= lseek(fd
, 0, SEEK_CUR
);
119 if (data_offset
== -1)
123 err
= auxtrace_queues__add_event(&spe
->queues
, session
, event
,
124 data_offset
, &buffer
);
128 /* Dump here now we have copied a piped trace out of the pipe */
130 if (auxtrace_buffer__get_data(buffer
, fd
)) {
131 arm_spe_dump_event(spe
, buffer
->data
,
133 auxtrace_buffer__put_data(buffer
);
140 static int arm_spe_flush(struct perf_session
*session __maybe_unused
,
141 struct perf_tool
*tool __maybe_unused
)
146 static void arm_spe_free_queue(void *priv
)
148 struct arm_spe_queue
*speq
= priv
;
155 static void arm_spe_free_events(struct perf_session
*session
)
157 struct arm_spe
*spe
= container_of(session
->auxtrace
, struct arm_spe
,
159 struct auxtrace_queues
*queues
= &spe
->queues
;
162 for (i
= 0; i
< queues
->nr_queues
; i
++) {
163 arm_spe_free_queue(queues
->queue_array
[i
].priv
);
164 queues
->queue_array
[i
].priv
= NULL
;
166 auxtrace_queues__free(queues
);
169 static void arm_spe_free(struct perf_session
*session
)
171 struct arm_spe
*spe
= container_of(session
->auxtrace
, struct arm_spe
,
174 auxtrace_heap__free(&spe
->heap
);
175 arm_spe_free_events(session
);
176 session
->auxtrace
= NULL
;
180 static const char * const arm_spe_info_fmts
[] = {
181 [ARM_SPE_PMU_TYPE
] = " PMU Type %"PRId64
"\n",
184 static void arm_spe_print_info(u64
*arr
)
189 fprintf(stdout
, arm_spe_info_fmts
[ARM_SPE_PMU_TYPE
], arr
[ARM_SPE_PMU_TYPE
]);
192 int arm_spe_process_auxtrace_info(union perf_event
*event
,
193 struct perf_session
*session
)
195 struct auxtrace_info_event
*auxtrace_info
= &event
->auxtrace_info
;
196 size_t min_sz
= sizeof(u64
) * ARM_SPE_PMU_TYPE
;
200 if (auxtrace_info
->header
.size
< sizeof(struct auxtrace_info_event
) +
204 spe
= zalloc(sizeof(struct arm_spe
));
208 err
= auxtrace_queues__init(&spe
->queues
);
212 spe
->session
= session
;
213 spe
->machine
= &session
->machines
.host
; /* No kvm support */
214 spe
->auxtrace_type
= auxtrace_info
->type
;
215 spe
->pmu_type
= auxtrace_info
->priv
[ARM_SPE_PMU_TYPE
];
217 spe
->auxtrace
.process_event
= arm_spe_process_event
;
218 spe
->auxtrace
.process_auxtrace_event
= arm_spe_process_auxtrace_event
;
219 spe
->auxtrace
.flush_events
= arm_spe_flush
;
220 spe
->auxtrace
.free_events
= arm_spe_free_events
;
221 spe
->auxtrace
.free
= arm_spe_free
;
222 session
->auxtrace
= &spe
->auxtrace
;
224 arm_spe_print_info(&auxtrace_info
->priv
[0]);