Lines Matching +full:in +full:- +full:and +full:- +full:around

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2017-2018, Arm Ltd.
25 #include "../../../util/arm-spe.h"
53 struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu; in arm_spe_info_fill()
56 return -EINVAL; in arm_spe_info_fill()
58 if (!session->evlist->core.nr_mmaps) in arm_spe_info_fill()
59 return -EINVAL; in arm_spe_info_fill()
61 auxtrace_info->type = PERF_AUXTRACE_ARM_SPE; in arm_spe_info_fill()
62 auxtrace_info->priv[ARM_SPE_PMU_TYPE] = arm_spe_pmu->type; in arm_spe_info_fill()
83 * No size were given to '-S' or '-m,', so go with the default in arm_spe_snapshot_resolve_auxtrace_defaults()
85 if (!opts->auxtrace_snapshot_size && !opts->auxtrace_mmap_pages) { in arm_spe_snapshot_resolve_auxtrace_defaults()
87 opts->auxtrace_mmap_pages = MiB(4) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
89 opts->auxtrace_mmap_pages = KiB(128) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
90 if (opts->mmap_pages == UINT_MAX) in arm_spe_snapshot_resolve_auxtrace_defaults()
91 opts->mmap_pages = KiB(256) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
93 } else if (!opts->auxtrace_mmap_pages && !privileged && opts->mmap_pages == UINT_MAX) { in arm_spe_snapshot_resolve_auxtrace_defaults()
94 opts->mmap_pages = KiB(256) / page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
98 * '-m,xyz' was specified but no snapshot size, so make the snapshot size as big as the in arm_spe_snapshot_resolve_auxtrace_defaults()
101 if (!opts->auxtrace_snapshot_size) in arm_spe_snapshot_resolve_auxtrace_defaults()
102 opts->auxtrace_snapshot_size = opts->auxtrace_mmap_pages * (size_t)page_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
105 * '-Sxyz' was specified but no auxtrace mmap area, so make the auxtrace mmap area big in arm_spe_snapshot_resolve_auxtrace_defaults()
108 if (!opts->auxtrace_mmap_pages) { in arm_spe_snapshot_resolve_auxtrace_defaults()
109 size_t sz = opts->auxtrace_snapshot_size; in arm_spe_snapshot_resolve_auxtrace_defaults()
112 opts->auxtrace_mmap_pages = roundup_pow_of_two(sz); in arm_spe_snapshot_resolve_auxtrace_defaults()
122 struct perf_pmu *arm_spe_pmu = sper->arm_spe_pmu; in arm_spe_recording_options()
124 struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; in arm_spe_recording_options()
125 bool privileged = perf_event_paranoid_check(-1); in arm_spe_recording_options()
130 sper->evlist = evlist; in arm_spe_recording_options()
133 if (evsel->core.attr.type == arm_spe_pmu->type) { in arm_spe_recording_options()
136 return -EINVAL; in arm_spe_recording_options()
138 evsel->core.attr.freq = 0; in arm_spe_recording_options()
139 evsel->core.attr.sample_period = arm_spe_pmu->default_config->sample_period; in arm_spe_recording_options()
140 evsel->needs_auxtrace_mmap = true; in arm_spe_recording_options()
142 opts->full_auxtrace = true; in arm_spe_recording_options()
146 if (!opts->full_auxtrace) in arm_spe_recording_options()
150 * we are in snapshot mode. in arm_spe_recording_options()
152 if (opts->auxtrace_snapshot_mode) { in arm_spe_recording_options()
154 * Command arguments '-Sxyz' and/or '-m,xyz' are missing, so fill those in with in arm_spe_recording_options()
157 if (!opts->auxtrace_snapshot_size || !opts->auxtrace_mmap_pages) in arm_spe_recording_options()
163 if (opts->auxtrace_snapshot_size > opts->auxtrace_mmap_pages * (size_t)page_size) { in arm_spe_recording_options()
165 opts->auxtrace_snapshot_size, in arm_spe_recording_options()
166 opts->auxtrace_mmap_pages * (size_t)page_size); in arm_spe_recording_options()
167 return -EINVAL; in arm_spe_recording_options()
171 * Something went wrong somewhere - this shouldn't happen. in arm_spe_recording_options()
173 if (!opts->auxtrace_snapshot_size || !opts->auxtrace_mmap_pages) { in arm_spe_recording_options()
174 pr_err("Failed to calculate default snapshot size and/or AUX area tracing mmap pages\n"); in arm_spe_recording_options()
175 return -EINVAL; in arm_spe_recording_options()
179 /* We are in full trace mode but '-m,xyz' wasn't specified */ in arm_spe_recording_options()
180 if (!opts->auxtrace_mmap_pages) { in arm_spe_recording_options()
182 opts->auxtrace_mmap_pages = MiB(4) / page_size; in arm_spe_recording_options()
184 opts->auxtrace_mmap_pages = KiB(128) / page_size; in arm_spe_recording_options()
185 if (opts->mmap_pages == UINT_MAX) in arm_spe_recording_options()
186 opts->mmap_pages = KiB(256) / page_size; in arm_spe_recording_options()
191 if (opts->auxtrace_mmap_pages) { in arm_spe_recording_options()
192 size_t sz = opts->auxtrace_mmap_pages * (size_t)page_size; in arm_spe_recording_options()
196 pr_err("Invalid mmap size for ARM SPE: must be at least %zuKiB and a power of 2\n", in arm_spe_recording_options()
198 return -EINVAL; in arm_spe_recording_options()
202 if (opts->auxtrace_snapshot_mode) in arm_spe_recording_options()
204 opts->auxtrace_snapshot_size); in arm_spe_recording_options()
213 * In the case of per-cpu mmaps, sample CPU for AUX event; in arm_spe_recording_options()
234 if (arm_spe_evsel->core.attr.config & bit) in arm_spe_recording_options()
245 tracking_evsel->core.attr.freq = 0; in arm_spe_recording_options()
246 tracking_evsel->core.attr.sample_period = 1; in arm_spe_recording_options()
248 /* In per-cpu case, always need the time of mmap events etc */ in arm_spe_recording_options()
255 tracking_evsel->core.attr.context_switch = 1; in arm_spe_recording_options()
271 return -1; in arm_spe_parse_snapshot_options()
274 opts->auxtrace_snapshot_mode = true; in arm_spe_parse_snapshot_options()
275 opts->auxtrace_snapshot_size = snapshot_size; in arm_spe_parse_snapshot_options()
286 evlist__for_each_entry(ptr->evlist, evsel) { in arm_spe_snapshot_start()
287 if (evsel->core.attr.type == ptr->arm_spe_pmu->type) in arm_spe_snapshot_start()
290 return -EINVAL; in arm_spe_snapshot_start()
299 evlist__for_each_entry(ptr->evlist, evsel) { in arm_spe_snapshot_finish()
300 if (evsel->core.attr.type == ptr->arm_spe_pmu->type) in arm_spe_snapshot_finish()
303 return -EINVAL; in arm_spe_snapshot_finish()
309 int cnt = ptr->wrapped_cnt, new_cnt, i; in arm_spe_alloc_wrapped_array()
318 * Make ptr->wrapped as big as idx. in arm_spe_alloc_wrapped_array()
323 * Free'ed in arm_spe_recording_free(). in arm_spe_alloc_wrapped_array()
325 wrapped = reallocarray(ptr->wrapped, new_cnt, sizeof(bool)); in arm_spe_alloc_wrapped_array()
327 return -ENOMEM; in arm_spe_alloc_wrapped_array()
335 ptr->wrapped_cnt = new_cnt; in arm_spe_alloc_wrapped_array()
336 ptr->wrapped = wrapped; in arm_spe_alloc_wrapped_array()
349 * Defensively handle the case where head might be continually increasing - if its value is in arm_spe_buffer_has_wrapped()
351 * wrapped around. Otherwise, continue to detect if head might have wrapped. in arm_spe_buffer_has_wrapped()
357 * We want to look the very last 512 byte (chosen arbitrarily) in the ring buffer. in arm_spe_buffer_has_wrapped()
359 watermark = buf_size - 512; in arm_spe_buffer_has_wrapped()
364 * head has numerically wrapped around. To find we need to check if we have data at the in arm_spe_buffer_has_wrapped()
366 * out and there is a fresh mapping with every new session. in arm_spe_buffer_has_wrapped()
382 * If we find trace data at the end of the ring buffer, head has been there and has in arm_spe_buffer_has_wrapped()
383 * numerically wrapped around at least once. in arm_spe_buffer_has_wrapped()
405 if (idx >= ptr->wrapped_cnt) { in arm_spe_find_snapshot()
412 * Check to see if *head has wrapped around. If it hasn't only the in arm_spe_find_snapshot()
413 * amount of data between *head and *old is snapshot'ed to avoid in arm_spe_find_snapshot()
415 * wrapped around the entire size of the AUX ring buffer it taken. in arm_spe_find_snapshot()
417 wrapped = ptr->wrapped[idx]; in arm_spe_find_snapshot()
418 if (!wrapped && arm_spe_buffer_has_wrapped(data, mm->len, *head)) { in arm_spe_find_snapshot()
420 ptr->wrapped[idx] = true; in arm_spe_find_snapshot()
424 __func__, idx, (size_t)*old, (size_t)*head, mm->len); in arm_spe_find_snapshot()
427 * No wrap has occurred, we can just use *head and *old. in arm_spe_find_snapshot()
433 * *head has wrapped around - adjust *head and *old to pickup the in arm_spe_find_snapshot()
436 if (*head >= mm->len) { in arm_spe_find_snapshot()
437 *old = *head - mm->len; in arm_spe_find_snapshot()
439 *head += mm->len; in arm_spe_find_snapshot()
440 *old = *head - mm->len; in arm_spe_find_snapshot()
460 zfree(&sper->wrapped); in arm_spe_recording_free()
470 *err = -ENODEV; in arm_spe_recording_init()
476 *err = -ENOMEM; in arm_spe_recording_init()
480 sper->arm_spe_pmu = arm_spe_pmu; in arm_spe_recording_init()
481 sper->itr.pmu = arm_spe_pmu; in arm_spe_recording_init()
482 sper->itr.snapshot_start = arm_spe_snapshot_start; in arm_spe_recording_init()
483 sper->itr.snapshot_finish = arm_spe_snapshot_finish; in arm_spe_recording_init()
484 sper->itr.find_snapshot = arm_spe_find_snapshot; in arm_spe_recording_init()
485 sper->itr.parse_snapshot_options = arm_spe_parse_snapshot_options; in arm_spe_recording_init()
486 sper->itr.recording_options = arm_spe_recording_options; in arm_spe_recording_init()
487 sper->itr.info_priv_size = arm_spe_info_priv_size; in arm_spe_recording_init()
488 sper->itr.info_fill = arm_spe_info_fill; in arm_spe_recording_init()
489 sper->itr.free = arm_spe_recording_free; in arm_spe_recording_init()
490 sper->itr.reference = arm_spe_reference; in arm_spe_recording_init()
491 sper->itr.read_finish = auxtrace_record__read_finish; in arm_spe_recording_init()
492 sper->itr.alignment = 0; in arm_spe_recording_init()
495 return &sper->itr; in arm_spe_recording_init()
514 &attr->sample_period) != 1) { in arm_spe_pmu_default_config()
516 attr->sample_period = 4096; in arm_spe_pmu_default_config()
519 arm_spe_pmu->selectable = true; in arm_spe_pmu_default_config()
520 arm_spe_pmu->is_uncore = false; in arm_spe_pmu_default_config()