1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(C) 2015 Linaro Limited. All rights reserved.
4 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
8 #include <linux/bits.h>
9 #include <linux/bitops.h>
10 #include <linux/compiler.h>
11 #include <linux/coresight-pmu.h>
12 #include <linux/kernel.h>
13 #include <linux/log2.h>
14 #include <linux/string.h>
15 #include <linux/types.h>
16 #include <linux/zalloc.h>
19 #include "../../util/debug.h"
20 #include "../../util/record.h"
21 #include "../../util/auxtrace.h"
22 #include "../../util/cpumap.h"
23 #include "../../util/event.h"
24 #include "../../util/evlist.h"
25 #include "../../util/evsel.h"
26 #include "../../util/evsel_config.h"
27 #include "../../util/pmu.h"
28 #include "../../util/cs-etm.h"
29 #include <internal/lib.h> // page_size
30 #include "../../util/session.h"
36 struct cs_etm_recording {
37 struct auxtrace_record itr;
38 struct perf_pmu *cs_etm_pmu;
39 struct evlist *evlist;
46 static const char *metadata_etmv3_ro[CS_ETM_PRIV_MAX] = {
47 [CS_ETM_ETMCCER] = "mgmt/etmccer",
48 [CS_ETM_ETMIDR] = "mgmt/etmidr",
51 static const char *metadata_etmv4_ro[CS_ETMV4_PRIV_MAX] = {
52 [CS_ETMV4_TRCIDR0] = "trcidr/trcidr0",
53 [CS_ETMV4_TRCIDR1] = "trcidr/trcidr1",
54 [CS_ETMV4_TRCIDR2] = "trcidr/trcidr2",
55 [CS_ETMV4_TRCIDR8] = "trcidr/trcidr8",
56 [CS_ETMV4_TRCAUTHSTATUS] = "mgmt/trcauthstatus",
59 static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu);
61 static int cs_etm_set_context_id(struct auxtrace_record *itr,
62 struct evsel *evsel, int cpu)
64 struct cs_etm_recording *ptr;
65 struct perf_pmu *cs_etm_pmu;
70 ptr = container_of(itr, struct cs_etm_recording, itr);
71 cs_etm_pmu = ptr->cs_etm_pmu;
73 if (!cs_etm_is_etmv4(itr, cpu))
76 /* Get a handle on TRCIRD2 */
77 snprintf(path, PATH_MAX, "cpu%d/%s",
78 cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2]);
79 err = perf_pmu__scan_file(cs_etm_pmu, path, "%x", &val);
81 /* There was a problem reading the file, bailing out */
83 pr_err("%s: can't read file %s\n",
84 CORESIGHT_ETM_PMU_NAME, path);
89 * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID tracing
91 * 0b00000 Context ID tracing is not supported.
92 * 0b00100 Maximum of 32-bit Context ID size.
93 * All other values are reserved.
95 val = BMVAL(val, 5, 9);
96 if (!val || val != 0x4) {
101 /* All good, let the kernel know */
102 evsel->core.attr.config |= (1 << ETM_OPT_CTXTID);
110 static int cs_etm_set_timestamp(struct auxtrace_record *itr,
111 struct evsel *evsel, int cpu)
113 struct cs_etm_recording *ptr;
114 struct perf_pmu *cs_etm_pmu;
119 ptr = container_of(itr, struct cs_etm_recording, itr);
120 cs_etm_pmu = ptr->cs_etm_pmu;
122 if (!cs_etm_is_etmv4(itr, cpu))
125 /* Get a handle on TRCIRD0 */
126 snprintf(path, PATH_MAX, "cpu%d/%s",
127 cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]);
128 err = perf_pmu__scan_file(cs_etm_pmu, path, "%x", &val);
130 /* There was a problem reading the file, bailing out */
132 pr_err("%s: can't read file %s\n",
133 CORESIGHT_ETM_PMU_NAME, path);
138 * TRCIDR0.TSSIZE, bit [28-24], indicates whether global timestamping
140 * 0b00000 Global timestamping is not implemented
141 * 0b00110 Implementation supports a maximum timestamp of 48bits.
142 * 0b01000 Implementation supports a maximum timestamp of 64bits.
144 val &= GENMASK(28, 24);
150 /* All good, let the kernel know */
151 evsel->core.attr.config |= (1 << ETM_OPT_TS);
158 static int cs_etm_set_option(struct auxtrace_record *itr,
159 struct evsel *evsel, u32 option)
161 int i, err = -EINVAL;
162 struct perf_cpu_map *event_cpus = evsel->evlist->core.cpus;
163 struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
165 /* Set option of each CPU we have */
166 for (i = 0; i < cpu__max_cpu(); i++) {
167 if (!cpu_map__has(event_cpus, i) ||
168 !cpu_map__has(online_cpus, i))
171 if (option & ETM_OPT_CTXTID) {
172 err = cs_etm_set_context_id(itr, evsel, i);
176 if (option & ETM_OPT_TS) {
177 err = cs_etm_set_timestamp(itr, evsel, i);
181 if (option & ~(ETM_OPT_CTXTID | ETM_OPT_TS))
182 /* Nothing else is currently supported */
188 perf_cpu_map__put(online_cpus);
192 static int cs_etm_parse_snapshot_options(struct auxtrace_record *itr,
193 struct record_opts *opts,
196 struct cs_etm_recording *ptr =
197 container_of(itr, struct cs_etm_recording, itr);
198 unsigned long long snapshot_size = 0;
202 snapshot_size = strtoull(str, &endptr, 0);
203 if (*endptr || snapshot_size > SIZE_MAX)
207 opts->auxtrace_snapshot_mode = true;
208 opts->auxtrace_snapshot_size = snapshot_size;
209 ptr->snapshot_size = snapshot_size;
214 static int cs_etm_set_sink_attr(struct perf_pmu *pmu,
217 char msg[BUFSIZ], path[PATH_MAX], *sink;
218 struct perf_evsel_config_term *term;
222 if (evsel->core.attr.config2 & GENMASK(31, 0))
225 list_for_each_entry(term, &evsel->config_terms, list) {
226 if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG)
229 sink = term->val.str;
230 snprintf(path, PATH_MAX, "sinks/%s", sink);
232 ret = perf_pmu__scan_file(pmu, path, "%x", &hash);
234 pr_err("failed to set sink \"%s\" on event %s with %d (%s)\n",
235 sink, perf_evsel__name(evsel), errno,
236 str_error_r(errno, msg, sizeof(msg)));
240 evsel->core.attr.config2 |= hash;
245 * No sink was provided on the command line - for _now_ treat
251 static int cs_etm_recording_options(struct auxtrace_record *itr,
252 struct evlist *evlist,
253 struct record_opts *opts)
256 struct cs_etm_recording *ptr =
257 container_of(itr, struct cs_etm_recording, itr);
258 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
259 struct evsel *evsel, *cs_etm_evsel = NULL;
260 struct perf_cpu_map *cpus = evlist->core.cpus;
261 bool privileged = perf_event_paranoid_check(-1);
264 ptr->evlist = evlist;
265 ptr->snapshot_mode = opts->auxtrace_snapshot_mode;
267 if (perf_can_record_switch_events())
268 opts->record_switch_events = true;
270 evlist__for_each_entry(evlist, evsel) {
271 if (evsel->core.attr.type == cs_etm_pmu->type) {
273 pr_err("There may be only one %s event\n",
274 CORESIGHT_ETM_PMU_NAME);
277 evsel->core.attr.freq = 0;
278 evsel->core.attr.sample_period = 1;
279 cs_etm_evsel = evsel;
280 opts->full_auxtrace = true;
284 /* no need to continue if at least one event of interest was found */
288 ret = cs_etm_set_sink_attr(cs_etm_pmu, cs_etm_evsel);
292 if (opts->use_clockid) {
293 pr_err("Cannot use clockid (-k option) with %s\n",
294 CORESIGHT_ETM_PMU_NAME);
298 /* we are in snapshot mode */
299 if (opts->auxtrace_snapshot_mode) {
301 * No size were given to '-S' or '-m,', so go with
304 if (!opts->auxtrace_snapshot_size &&
305 !opts->auxtrace_mmap_pages) {
307 opts->auxtrace_mmap_pages = MiB(4) / page_size;
309 opts->auxtrace_mmap_pages =
310 KiB(128) / page_size;
311 if (opts->mmap_pages == UINT_MAX)
312 opts->mmap_pages = KiB(256) / page_size;
314 } else if (!opts->auxtrace_mmap_pages && !privileged &&
315 opts->mmap_pages == UINT_MAX) {
316 opts->mmap_pages = KiB(256) / page_size;
320 * '-m,xyz' was specified but no snapshot size, so make the
321 * snapshot size as big as the auxtrace mmap area.
323 if (!opts->auxtrace_snapshot_size) {
324 opts->auxtrace_snapshot_size =
325 opts->auxtrace_mmap_pages * (size_t)page_size;
329 * -Sxyz was specified but no auxtrace mmap area, so make the
330 * auxtrace mmap area big enough to fit the requested snapshot
333 if (!opts->auxtrace_mmap_pages) {
334 size_t sz = opts->auxtrace_snapshot_size;
336 sz = round_up(sz, page_size) / page_size;
337 opts->auxtrace_mmap_pages = roundup_pow_of_two(sz);
340 /* Snapshost size can't be bigger than the auxtrace area */
341 if (opts->auxtrace_snapshot_size >
342 opts->auxtrace_mmap_pages * (size_t)page_size) {
343 pr_err("Snapshot size %zu must not be greater than AUX area tracing mmap size %zu\n",
344 opts->auxtrace_snapshot_size,
345 opts->auxtrace_mmap_pages * (size_t)page_size);
349 /* Something went wrong somewhere - this shouldn't happen */
350 if (!opts->auxtrace_snapshot_size ||
351 !opts->auxtrace_mmap_pages) {
352 pr_err("Failed to calculate default snapshot size and/or AUX area tracing mmap pages\n");
357 /* We are in full trace mode but '-m,xyz' wasn't specified */
358 if (opts->full_auxtrace && !opts->auxtrace_mmap_pages) {
360 opts->auxtrace_mmap_pages = MiB(4) / page_size;
362 opts->auxtrace_mmap_pages = KiB(128) / page_size;
363 if (opts->mmap_pages == UINT_MAX)
364 opts->mmap_pages = KiB(256) / page_size;
369 /* Validate auxtrace_mmap_pages provided by user */
370 if (opts->auxtrace_mmap_pages) {
371 unsigned int max_page = (KiB(128) / page_size);
372 size_t sz = opts->auxtrace_mmap_pages * (size_t)page_size;
375 opts->auxtrace_mmap_pages > max_page) {
376 opts->auxtrace_mmap_pages = max_page;
377 pr_err("auxtrace too big, truncating to %d\n",
381 if (!is_power_of_2(sz)) {
382 pr_err("Invalid mmap size for %s: must be a power of 2\n",
383 CORESIGHT_ETM_PMU_NAME);
388 if (opts->auxtrace_snapshot_mode)
389 pr_debug2("%s snapshot size: %zu\n", CORESIGHT_ETM_PMU_NAME,
390 opts->auxtrace_snapshot_size);
393 * To obtain the auxtrace buffer file descriptor, the auxtrace
394 * event must come first.
396 perf_evlist__to_front(evlist, cs_etm_evsel);
399 * In the case of per-cpu mmaps, we need the CPU on the
400 * AUX event. We also need the contextID in order to be notified
401 * when a context switch happened.
403 if (!perf_cpu_map__empty(cpus)) {
404 perf_evsel__set_sample_bit(cs_etm_evsel, CPU);
406 err = cs_etm_set_option(itr, cs_etm_evsel,
407 ETM_OPT_CTXTID | ETM_OPT_TS);
412 /* Add dummy event to keep tracking */
413 if (opts->full_auxtrace) {
414 struct evsel *tracking_evsel;
416 err = parse_events(evlist, "dummy:u", NULL);
420 tracking_evsel = evlist__last(evlist);
421 perf_evlist__set_tracking_event(evlist, tracking_evsel);
423 tracking_evsel->core.attr.freq = 0;
424 tracking_evsel->core.attr.sample_period = 1;
426 /* In per-cpu case, always need the time of mmap events etc */
427 if (!perf_cpu_map__empty(cpus))
428 perf_evsel__set_sample_bit(tracking_evsel, TIME);
435 static u64 cs_etm_get_config(struct auxtrace_record *itr)
438 struct cs_etm_recording *ptr =
439 container_of(itr, struct cs_etm_recording, itr);
440 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
441 struct evlist *evlist = ptr->evlist;
444 evlist__for_each_entry(evlist, evsel) {
445 if (evsel->core.attr.type == cs_etm_pmu->type) {
447 * Variable perf_event_attr::config is assigned to
448 * ETMv3/PTM. The bit fields have been made to match
449 * the ETMv3.5 ETRMCR register specification. See the
450 * PMU_FORMAT_ATTR() declarations in
451 * drivers/hwtracing/coresight/coresight-perf.c for
454 config = evsel->core.attr.config;
463 #define BIT(N) (1UL << (N))
466 static u64 cs_etmv4_get_config(struct auxtrace_record *itr)
472 * The perf event variable config bits represent both
473 * the command line options and register programming
474 * bits in ETMv3/PTM. For ETMv4 we must remap options
477 config_opts = cs_etm_get_config(itr);
478 if (config_opts & BIT(ETM_OPT_CYCACC))
479 config |= BIT(ETM4_CFG_BIT_CYCACC);
480 if (config_opts & BIT(ETM_OPT_CTXTID))
481 config |= BIT(ETM4_CFG_BIT_CTXTID);
482 if (config_opts & BIT(ETM_OPT_TS))
483 config |= BIT(ETM4_CFG_BIT_TS);
484 if (config_opts & BIT(ETM_OPT_RETSTK))
485 config |= BIT(ETM4_CFG_BIT_RETSTK);
491 cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused,
492 struct evlist *evlist __maybe_unused)
495 int etmv3 = 0, etmv4 = 0;
496 struct perf_cpu_map *event_cpus = evlist->core.cpus;
497 struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
499 /* cpu map is not empty, we have specific CPUs to work with */
500 if (!perf_cpu_map__empty(event_cpus)) {
501 for (i = 0; i < cpu__max_cpu(); i++) {
502 if (!cpu_map__has(event_cpus, i) ||
503 !cpu_map__has(online_cpus, i))
506 if (cs_etm_is_etmv4(itr, i))
512 /* get configuration for all CPUs in the system */
513 for (i = 0; i < cpu__max_cpu(); i++) {
514 if (!cpu_map__has(online_cpus, i))
517 if (cs_etm_is_etmv4(itr, i))
524 perf_cpu_map__put(online_cpus);
526 return (CS_ETM_HEADER_SIZE +
527 (etmv4 * CS_ETMV4_PRIV_SIZE) +
528 (etmv3 * CS_ETMV3_PRIV_SIZE));
531 static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu)
537 struct cs_etm_recording *ptr =
538 container_of(itr, struct cs_etm_recording, itr);
539 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
541 /* Take any of the RO files for ETMv4 and see if it present */
542 snprintf(path, PATH_MAX, "cpu%d/%s",
543 cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]);
544 scan = perf_pmu__scan_file(cs_etm_pmu, path, "%x", &val);
546 /* The file was read successfully, we have a winner */
553 static int cs_etm_get_ro(struct perf_pmu *pmu, int cpu, const char *path)
555 char pmu_path[PATH_MAX];
557 unsigned int val = 0;
559 /* Get RO metadata from sysfs */
560 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu, path);
562 scan = perf_pmu__scan_file(pmu, pmu_path, "%x", &val);
564 pr_err("%s: error reading: %s\n", __func__, pmu_path);
569 static void cs_etm_get_metadata(int cpu, u32 *offset,
570 struct auxtrace_record *itr,
571 struct perf_record_auxtrace_info *info)
575 struct cs_etm_recording *ptr =
576 container_of(itr, struct cs_etm_recording, itr);
577 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
579 /* first see what kind of tracer this cpu is affined to */
580 if (cs_etm_is_etmv4(itr, cpu)) {
581 magic = __perf_cs_etmv4_magic;
582 /* Get trace configuration register */
583 info->priv[*offset + CS_ETMV4_TRCCONFIGR] =
584 cs_etmv4_get_config(itr);
585 /* Get traceID from the framework */
586 info->priv[*offset + CS_ETMV4_TRCTRACEIDR] =
587 coresight_get_trace_id(cpu);
588 /* Get read-only information from sysFS */
589 info->priv[*offset + CS_ETMV4_TRCIDR0] =
590 cs_etm_get_ro(cs_etm_pmu, cpu,
591 metadata_etmv4_ro[CS_ETMV4_TRCIDR0]);
592 info->priv[*offset + CS_ETMV4_TRCIDR1] =
593 cs_etm_get_ro(cs_etm_pmu, cpu,
594 metadata_etmv4_ro[CS_ETMV4_TRCIDR1]);
595 info->priv[*offset + CS_ETMV4_TRCIDR2] =
596 cs_etm_get_ro(cs_etm_pmu, cpu,
597 metadata_etmv4_ro[CS_ETMV4_TRCIDR2]);
598 info->priv[*offset + CS_ETMV4_TRCIDR8] =
599 cs_etm_get_ro(cs_etm_pmu, cpu,
600 metadata_etmv4_ro[CS_ETMV4_TRCIDR8]);
601 info->priv[*offset + CS_ETMV4_TRCAUTHSTATUS] =
602 cs_etm_get_ro(cs_etm_pmu, cpu,
604 [CS_ETMV4_TRCAUTHSTATUS]);
606 /* How much space was used */
607 increment = CS_ETMV4_PRIV_MAX;
609 magic = __perf_cs_etmv3_magic;
610 /* Get configuration register */
611 info->priv[*offset + CS_ETM_ETMCR] = cs_etm_get_config(itr);
612 /* Get traceID from the framework */
613 info->priv[*offset + CS_ETM_ETMTRACEIDR] =
614 coresight_get_trace_id(cpu);
615 /* Get read-only information from sysFS */
616 info->priv[*offset + CS_ETM_ETMCCER] =
617 cs_etm_get_ro(cs_etm_pmu, cpu,
618 metadata_etmv3_ro[CS_ETM_ETMCCER]);
619 info->priv[*offset + CS_ETM_ETMIDR] =
620 cs_etm_get_ro(cs_etm_pmu, cpu,
621 metadata_etmv3_ro[CS_ETM_ETMIDR]);
623 /* How much space was used */
624 increment = CS_ETM_PRIV_MAX;
627 /* Build generic header portion */
628 info->priv[*offset + CS_ETM_MAGIC] = magic;
629 info->priv[*offset + CS_ETM_CPU] = cpu;
630 /* Where the next CPU entry should start from */
631 *offset += increment;
634 static int cs_etm_info_fill(struct auxtrace_record *itr,
635 struct perf_session *session,
636 struct perf_record_auxtrace_info *info,
642 struct perf_cpu_map *cpu_map;
643 struct perf_cpu_map *event_cpus = session->evlist->core.cpus;
644 struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
645 struct cs_etm_recording *ptr =
646 container_of(itr, struct cs_etm_recording, itr);
647 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
649 if (priv_size != cs_etm_info_priv_size(itr, session->evlist))
652 if (!session->evlist->core.nr_mmaps)
655 /* If the cpu_map is empty all online CPUs are involved */
656 if (perf_cpu_map__empty(event_cpus)) {
657 cpu_map = online_cpus;
659 /* Make sure all specified CPUs are online */
660 for (i = 0; i < perf_cpu_map__nr(event_cpus); i++) {
661 if (cpu_map__has(event_cpus, i) &&
662 !cpu_map__has(online_cpus, i))
666 cpu_map = event_cpus;
669 nr_cpu = perf_cpu_map__nr(cpu_map);
670 /* Get PMU type as dynamically assigned by the core */
671 type = cs_etm_pmu->type;
673 /* First fill out the session header */
674 info->type = PERF_AUXTRACE_CS_ETM;
675 info->priv[CS_HEADER_VERSION_0] = 0;
676 info->priv[CS_PMU_TYPE_CPUS] = type << 32;
677 info->priv[CS_PMU_TYPE_CPUS] |= nr_cpu;
678 info->priv[CS_ETM_SNAPSHOT] = ptr->snapshot_mode;
680 offset = CS_ETM_SNAPSHOT + 1;
682 for (i = 0; i < cpu__max_cpu() && offset < priv_size; i++)
683 if (cpu_map__has(cpu_map, i))
684 cs_etm_get_metadata(i, &offset, itr, info);
686 perf_cpu_map__put(online_cpus);
691 static int cs_etm_alloc_wrapped_array(struct cs_etm_recording *ptr, int idx)
694 int cnt = ptr->wrapped_cnt;
696 /* Make @ptr->wrapped as big as @idx */
701 * Free'ed in cs_etm_recording_free(). Using realloc() to avoid
702 * cross compilation problems where the host's system supports
703 * reallocarray() but not the target.
705 wrapped = realloc(ptr->wrapped, cnt * sizeof(bool));
709 wrapped[cnt - 1] = false;
710 ptr->wrapped_cnt = cnt;
711 ptr->wrapped = wrapped;
716 static bool cs_etm_buffer_has_wrapped(unsigned char *buffer,
717 size_t buffer_size, u64 head)
720 u64 *buf = (u64 *)buffer;
721 size_t buf_size = buffer_size;
724 * We want to look the very last 512 byte (chosen arbitrarily) in
727 watermark = buf_size - 512;
730 * @head is continuously increasing - if its value is equal or greater
731 * than the size of the ring buffer, it has wrapped around.
733 if (head >= buffer_size)
737 * The value of @head is somewhere within the size of the ring buffer.
738 * This can be that there hasn't been enough data to fill the ring
739 * buffer yet or the trace time was so long that @head has numerically
740 * wrapped around. To find we need to check if we have data at the very
741 * end of the ring buffer. We can reliably do this because mmap'ed
742 * pages are zeroed out and there is a fresh mapping with every new
746 /* @head is less than 512 byte from the end of the ring buffer */
747 if (head > watermark)
751 * Speed things up by using 64 bit transactions (see "u64 *buf" above)
757 * If we find trace data at the end of the ring buffer, @head has
758 * been there and has numerically wrapped around at least once.
760 for (i = watermark; i < buf_size; i++)
767 static int cs_etm_find_snapshot(struct auxtrace_record *itr,
768 int idx, struct auxtrace_mmap *mm,
774 struct cs_etm_recording *ptr =
775 container_of(itr, struct cs_etm_recording, itr);
778 * Allocate memory to keep track of wrapping if this is the first
779 * time we deal with this *mm.
781 if (idx >= ptr->wrapped_cnt) {
782 err = cs_etm_alloc_wrapped_array(ptr, idx);
788 * Check to see if *head has wrapped around. If it hasn't only the
789 * amount of data between *head and *old is snapshot'ed to avoid
790 * bloating the perf.data file with zeros. But as soon as *head has
791 * wrapped around the entire size of the AUX ring buffer it taken.
793 wrapped = ptr->wrapped[idx];
794 if (!wrapped && cs_etm_buffer_has_wrapped(data, mm->len, *head)) {
796 ptr->wrapped[idx] = true;
799 pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n",
800 __func__, idx, (size_t)*old, (size_t)*head, mm->len);
802 /* No wrap has occurred, we can just use *head and *old. */
807 * *head has wrapped around - adjust *head and *old to pickup the
808 * entire content of the AUX buffer.
810 if (*head >= mm->len) {
811 *old = *head - mm->len;
814 *old = *head - mm->len;
820 static int cs_etm_snapshot_start(struct auxtrace_record *itr)
822 struct cs_etm_recording *ptr =
823 container_of(itr, struct cs_etm_recording, itr);
826 evlist__for_each_entry(ptr->evlist, evsel) {
827 if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
828 return evsel__disable(evsel);
833 static int cs_etm_snapshot_finish(struct auxtrace_record *itr)
835 struct cs_etm_recording *ptr =
836 container_of(itr, struct cs_etm_recording, itr);
839 evlist__for_each_entry(ptr->evlist, evsel) {
840 if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
841 return evsel__enable(evsel);
846 static u64 cs_etm_reference(struct auxtrace_record *itr __maybe_unused)
848 return (((u64) rand() << 0) & 0x00000000FFFFFFFFull) |
849 (((u64) rand() << 32) & 0xFFFFFFFF00000000ull);
852 static void cs_etm_recording_free(struct auxtrace_record *itr)
854 struct cs_etm_recording *ptr =
855 container_of(itr, struct cs_etm_recording, itr);
857 zfree(&ptr->wrapped);
861 struct auxtrace_record *cs_etm_record_init(int *err)
863 struct perf_pmu *cs_etm_pmu;
864 struct cs_etm_recording *ptr;
866 cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME);
873 ptr = zalloc(sizeof(struct cs_etm_recording));
879 ptr->cs_etm_pmu = cs_etm_pmu;
880 ptr->itr.pmu = cs_etm_pmu;
881 ptr->itr.parse_snapshot_options = cs_etm_parse_snapshot_options;
882 ptr->itr.recording_options = cs_etm_recording_options;
883 ptr->itr.info_priv_size = cs_etm_info_priv_size;
884 ptr->itr.info_fill = cs_etm_info_fill;
885 ptr->itr.find_snapshot = cs_etm_find_snapshot;
886 ptr->itr.snapshot_start = cs_etm_snapshot_start;
887 ptr->itr.snapshot_finish = cs_etm_snapshot_finish;
888 ptr->itr.reference = cs_etm_reference;
889 ptr->itr.free = cs_etm_recording_free;
890 ptr->itr.read_finish = auxtrace_record__read_finish;