Lines Matching +full:t +full:- +full:head

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2017-2018, Arm Ltd.
26 #include "../../../util/arm-spe.h"
54 struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu; in arm_spe_info_fill()
57 return -EINVAL; in arm_spe_info_fill()
59 if (!session->evlist->core.nr_mmaps) in arm_spe_info_fill()
60 return -EINVAL; in arm_spe_info_fill()
62 auxtrace_info->type = PERF_AUXTRACE_ARM_SPE; in arm_spe_info_fill()
63 auxtrace_info->priv[ARM_SPE_PMU_TYPE] = arm_spe_pmu->type; in arm_spe_info_fill()
84 * No size were given to '-S' or '-m,', so go with the default in arm_spe_snapshot_resolve_auxtrace_defaults()
86 if (!opts->auxtrace_snapshot_size && !opts->auxtrace_mmap_pages) { in arm_spe_snapshot_resolve_auxtrace_defaults()
88 opts->auxtrace_mmap_pages = MiB(4) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
90 opts->auxtrace_mmap_pages = KiB(128) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
91 if (opts->mmap_pages == UINT_MAX) in arm_spe_snapshot_resolve_auxtrace_defaults()
92 opts->mmap_pages = KiB(256) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
94 } else if (!opts->auxtrace_mmap_pages && !privileged && opts->mmap_pages == UINT_MAX) { in arm_spe_snapshot_resolve_auxtrace_defaults()
95 opts->mmap_pages = KiB(256) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
99 * '-m,xyz' was specified but no snapshot size, so make the snapshot size as big as the in arm_spe_snapshot_resolve_auxtrace_defaults()
102 if (!opts->auxtrace_snapshot_size) in arm_spe_snapshot_resolve_auxtrace_defaults()
103 opts->auxtrace_snapshot_size = opts->auxtrace_mmap_pages * (size_t)page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
106 * '-Sxyz' was specified but no auxtrace mmap area, so make the auxtrace mmap area big in arm_spe_snapshot_resolve_auxtrace_defaults()
109 if (!opts->auxtrace_mmap_pages) { in arm_spe_snapshot_resolve_auxtrace_defaults()
110 size_t sz = opts->auxtrace_snapshot_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
113 opts->auxtrace_mmap_pages = roundup_pow_of_two(sz); in arm_spe_snapshot_resolve_auxtrace_defaults()
125 * If kernel driver doesn't advertise a minimum, in arm_spe_pmu__sample_period()
130 pr_debug("arm_spe driver doesn't advertise a min. interval. Using 4096\n"); in arm_spe_pmu__sample_period()
140 evsel->core.attr.freq = 0; in arm_spe_setup_evsel()
141 evsel->core.attr.sample_period = arm_spe_pmu__sample_period(evsel->pmu); in arm_spe_setup_evsel()
142 evsel->needs_auxtrace_mmap = true; in arm_spe_setup_evsel()
148 evlist__to_front(evsel->evlist, evsel); in arm_spe_setup_evsel()
151 * In the case of per-cpu mmaps, sample CPU for AUX event; in arm_spe_setup_evsel()
156 evsel__set_config_if_unset(evsel->pmu, evsel, "ts_enable", 1); in arm_spe_setup_evsel()
170 bit = perf_pmu__format_bits(evsel->pmu, "pa_enable"); in arm_spe_setup_evsel()
171 if (evsel->core.attr.config & bit) in arm_spe_setup_evsel()
182 struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; in arm_spe_recording_options()
183 bool privileged = perf_event_paranoid_check(-1); in arm_spe_recording_options()
187 sper->evlist = evlist; in arm_spe_recording_options()
191 if (!strstarts(evsel->pmu_name, ARM_SPE_PMU_NAME)) { in arm_spe_recording_options()
193 evsel->pmu_name); in arm_spe_recording_options()
194 return -EINVAL; in arm_spe_recording_options()
196 opts->full_auxtrace = true; in arm_spe_recording_options()
200 if (!opts->full_auxtrace) in arm_spe_recording_options()
206 if (opts->auxtrace_snapshot_mode) { in arm_spe_recording_options()
208 * Command arguments '-Sxyz' and/or '-m,xyz' are missing, so fill those in with in arm_spe_recording_options()
211 if (!opts->auxtrace_snapshot_size || !opts->auxtrace_mmap_pages) in arm_spe_recording_options()
215 * Snapshot size can't be bigger than the auxtrace area. in arm_spe_recording_options()
217 if (opts->auxtrace_snapshot_size > opts->auxtrace_mmap_pages * (size_t)page_size) { in arm_spe_recording_options()
219 opts->auxtrace_snapshot_size, in arm_spe_recording_options()
220 opts->auxtrace_mmap_pages * (size_t)page_size); in arm_spe_recording_options()
221 return -EINVAL; in arm_spe_recording_options()
225 * Something went wrong somewhere - this shouldn't happen. in arm_spe_recording_options()
227 if (!opts->auxtrace_snapshot_size || !opts->auxtrace_mmap_pages) { in arm_spe_recording_options()
229 return -EINVAL; in arm_spe_recording_options()
233 /* We are in full trace mode but '-m,xyz' wasn't specified */ in arm_spe_recording_options()
234 if (!opts->auxtrace_mmap_pages) { in arm_spe_recording_options()
236 opts->auxtrace_mmap_pages = MiB(4) / page_size; in arm_spe_recording_options()
238 opts->auxtrace_mmap_pages = KiB(128) / page_size; in arm_spe_recording_options()
239 if (opts->mmap_pages == UINT_MAX) in arm_spe_recording_options()
240 opts->mmap_pages = KiB(256) / page_size; in arm_spe_recording_options()
245 if (opts->auxtrace_mmap_pages) { in arm_spe_recording_options()
246 size_t sz = opts->auxtrace_mmap_pages * (size_t)page_size; in arm_spe_recording_options()
252 return -EINVAL; in arm_spe_recording_options()
256 if (opts->auxtrace_snapshot_mode) in arm_spe_recording_options()
258 opts->auxtrace_snapshot_size); in arm_spe_recording_options()
273 tracking_evsel->core.attr.freq = 0; in arm_spe_recording_options()
274 tracking_evsel->core.attr.sample_period = 1; in arm_spe_recording_options()
276 /* In per-cpu case, always need the time of mmap events etc */ in arm_spe_recording_options()
283 tracking_evsel->core.attr.context_switch = 1; in arm_spe_recording_options()
299 return -1; in arm_spe_parse_snapshot_options()
302 opts->auxtrace_snapshot_mode = true; in arm_spe_parse_snapshot_options()
303 opts->auxtrace_snapshot_size = snapshot_size; in arm_spe_parse_snapshot_options()
313 int ret = -EINVAL; in arm_spe_snapshot_start()
315 evlist__for_each_entry(ptr->evlist, evsel) { in arm_spe_snapshot_start()
330 int ret = -EINVAL; in arm_spe_snapshot_finish()
332 evlist__for_each_entry(ptr->evlist, evsel) { in arm_spe_snapshot_finish()
345 int cnt = ptr->wrapped_cnt, new_cnt, i; in arm_spe_alloc_wrapped_array()
354 * Make ptr->wrapped as big as idx. in arm_spe_alloc_wrapped_array()
361 wrapped = reallocarray(ptr->wrapped, new_cnt, sizeof(bool)); in arm_spe_alloc_wrapped_array()
363 return -ENOMEM; in arm_spe_alloc_wrapped_array()
371 ptr->wrapped_cnt = new_cnt; in arm_spe_alloc_wrapped_array()
372 ptr->wrapped = wrapped; in arm_spe_alloc_wrapped_array()
378 size_t buffer_size, u64 head) in arm_spe_buffer_has_wrapped() argument
385 * Defensively handle the case where head might be continually increasing - if its value is in arm_spe_buffer_has_wrapped()
387 * wrapped around. Otherwise, continue to detect if head might have wrapped. in arm_spe_buffer_has_wrapped()
389 if (head >= buffer_size) in arm_spe_buffer_has_wrapped()
395 watermark = buf_size - 512; in arm_spe_buffer_has_wrapped()
398 * The value of head is somewhere within the size of the ring buffer. This can be that there in arm_spe_buffer_has_wrapped()
399 * hasn't been enough data to fill the ring buffer yet or the trace time was so long that in arm_spe_buffer_has_wrapped()
400 * head has numerically wrapped around. To find we need to check if we have data at the in arm_spe_buffer_has_wrapped()
406 * head is less than 512 byte from the end of the ring buffer. in arm_spe_buffer_has_wrapped()
408 if (head > watermark) in arm_spe_buffer_has_wrapped()
409 watermark = head; in arm_spe_buffer_has_wrapped()
418 * If we find trace data at the end of the ring buffer, head has been there and has in arm_spe_buffer_has_wrapped()
430 u64 *head, u64 *old) in arm_spe_find_snapshot() argument
441 if (idx >= ptr->wrapped_cnt) { in arm_spe_find_snapshot()
448 * Check to see if *head has wrapped around. If it hasn't only the in arm_spe_find_snapshot()
449 * amount of data between *head and *old is snapshot'ed to avoid in arm_spe_find_snapshot()
450 * bloating the perf.data file with zeros. But as soon as *head has in arm_spe_find_snapshot()
453 wrapped = ptr->wrapped[idx]; in arm_spe_find_snapshot()
454 if (!wrapped && arm_spe_buffer_has_wrapped(data, mm->len, *head)) { in arm_spe_find_snapshot()
456 ptr->wrapped[idx] = true; in arm_spe_find_snapshot()
459 pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n", in arm_spe_find_snapshot()
460 __func__, idx, (size_t)*old, (size_t)*head, mm->len); in arm_spe_find_snapshot()
463 * No wrap has occurred, we can just use *head and *old. in arm_spe_find_snapshot()
469 * *head has wrapped around - adjust *head and *old to pickup the in arm_spe_find_snapshot()
472 if (*head >= mm->len) { in arm_spe_find_snapshot()
473 *old = *head - mm->len; in arm_spe_find_snapshot()
475 *head += mm->len; in arm_spe_find_snapshot()
476 *old = *head - mm->len; in arm_spe_find_snapshot()
496 zfree(&sper->wrapped); in arm_spe_recording_free()
506 *err = -ENODEV; in arm_spe_recording_init()
512 *err = -ENOMEM; in arm_spe_recording_init()
516 sper->arm_spe_pmu = arm_spe_pmu; in arm_spe_recording_init()
517 sper->itr.snapshot_start = arm_spe_snapshot_start; in arm_spe_recording_init()
518 sper->itr.snapshot_finish = arm_spe_snapshot_finish; in arm_spe_recording_init()
519 sper->itr.find_snapshot = arm_spe_find_snapshot; in arm_spe_recording_init()
520 sper->itr.parse_snapshot_options = arm_spe_parse_snapshot_options; in arm_spe_recording_init()
521 sper->itr.recording_options = arm_spe_recording_options; in arm_spe_recording_init()
522 sper->itr.info_priv_size = arm_spe_info_priv_size; in arm_spe_recording_init()
523 sper->itr.info_fill = arm_spe_info_fill; in arm_spe_recording_init()
524 sper->itr.free = arm_spe_recording_free; in arm_spe_recording_init()
525 sper->itr.reference = arm_spe_reference; in arm_spe_recording_init()
526 sper->itr.read_finish = auxtrace_record__read_finish; in arm_spe_recording_init()
527 sper->itr.alignment = 0; in arm_spe_recording_init()
530 return &sper->itr; in arm_spe_recording_init()
536 attr->sample_period = arm_spe_pmu__sample_period(arm_spe_pmu); in arm_spe_pmu_default_config()