Lines Matching +full:close +full:- +full:range

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Parts came from builtin-{top,stat,record}.c, see those files for further
26 #include "bpf-event.h"
33 #include "util/bpf-filter.h"
37 #include "util/intel-tpebs.h"
43 #include "parse-events.h"
44 #include <subcmd/parse-options.h>
70 #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
71 #define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y)
76 perf_evlist__init(&evlist->core); in evlist__init()
77 perf_evlist__set_maps(&evlist->core, cpus, threads); in evlist__init()
78 evlist->workload.pid = -1; in evlist__init()
79 evlist->bkw_mmap_state = BKW_MMAP_NOTREADY; in evlist__init()
80 evlist->ctl_fd.fd = -1; in evlist__init()
81 evlist->ctl_fd.ack = -1; in evlist__init()
82 evlist->ctl_fd.pos = -1; in evlist__init()
83 evlist->nr_br_cntr = -1; in evlist__init()
112 if (evlist->core.nr_entries > 1) { in evlist__new_default()
135 * evlist__set_id_pos - set the positions of event ids.
145 evlist->id_pos = first->id_pos; in evlist__set_id_pos()
146 evlist->is_pos = first->is_pos; in evlist__set_id_pos()
164 list_del_init(&pos->core.node); in evlist__purge()
165 pos->evlist = NULL; in evlist__purge()
169 evlist->core.nr_entries = 0; in evlist__purge()
174 event_enable_timer__exit(&evlist->eet); in evlist__exit()
175 zfree(&evlist->mmap); in evlist__exit()
176 zfree(&evlist->overwrite_mmap); in evlist__exit()
177 perf_evlist__exit(&evlist->core); in evlist__exit()
196 perf_evlist__add(&evlist->core, &entry->core); in evlist__add()
197 entry->evlist = evlist; in evlist__add()
198 entry->tracking = !entry->core.idx; in evlist__add()
200 if (evlist->core.nr_entries == 1) in evlist__add()
206 evsel->evlist = NULL; in evlist__remove()
207 perf_evlist__remove(&evlist->core, &evsel->core); in evlist__remove()
216 list_del_init(&evsel->core.node); in evlist__splice_list_tail()
224 list_del_init(&evsel->core.node); in evlist__splice_list_tail()
243 err = -EEXIST; in __evlist__set_tracepoints_handlers()
244 if (evsel->handler != NULL) in __evlist__set_tracepoints_handlers()
246 evsel->handler = assocs[i].handler; in __evlist__set_tracepoints_handlers()
256 perf_evlist__set_leader(&evlist->core); in evlist__set_leader()
270 return evsel__new_idx(&attr, evlist->core.nr_entries); in evlist__dummy_event()
278 return -ENOMEM; in evlist__add_dummy()
291 evsel->core.attr.exclude_kernel = 1; in evlist__add_aux_dummy()
292 evsel->core.attr.exclude_guest = 1; in evlist__add_aux_dummy()
293 evsel->core.attr.exclude_hv = 1; in evlist__add_aux_dummy()
294 evsel->core.system_wide = system_wide; in evlist__add_aux_dummy()
295 evsel->no_aux_samples = true; in evlist__add_aux_dummy()
296 evsel->name = strdup("dummy:u"); in evlist__add_aux_dummy()
314 evsel->core.system_wide = system_wide; in evlist__add_sched_switch()
315 evsel->no_aux_samples = true; in evlist__add_sched_switch()
329 evsel = evsel__new_idx(attrs + i, evlist->core.nr_entries + i); in evlist__add_attrs()
332 list_add_tail(&evsel->core.node, &head); in evlist__add_attrs()
342 return -1; in evlist__add_attrs()
370 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && in evlist__find_tracepoint_by_id()
371 (int)evsel->core.attr.config == id) in evlist__find_tracepoint_by_id()
383 if ((evsel->core.attr.type == PERF_TYPE_TRACEPOINT) && in evlist__find_tracepoint_by_name()
384 (strcmp(evsel->name, name) == 0)) in evlist__find_tracepoint_by_name()
397 return -1; in evlist__add_newtp()
399 evsel->handler = handler; in evlist__add_newtp()
412 .evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus), in evlist__cpu_begin()
413 .cpu = (struct perf_cpu){ .cpu = -1}, in evlist__cpu_begin()
423 itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0); in evlist__cpu_begin()
425 itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu); in evlist__cpu_begin()
430 if (itr.cpu_map_idx == -1) in evlist__cpu_begin()
439 while (evlist_cpu_itr->evsel != evlist__last(evlist_cpu_itr->container)) { in evlist_cpu_iterator__next()
440 evlist_cpu_itr->evsel = evsel__next(evlist_cpu_itr->evsel); in evlist_cpu_iterator__next()
441 evlist_cpu_itr->cpu_map_idx = in evlist_cpu_iterator__next()
442 perf_cpu_map__idx(evlist_cpu_itr->evsel->core.cpus, in evlist_cpu_iterator__next()
443 evlist_cpu_itr->cpu); in evlist_cpu_iterator__next()
444 if (evlist_cpu_itr->cpu_map_idx != -1) in evlist_cpu_iterator__next()
447 evlist_cpu_itr->evlist_cpu_map_idx++; in evlist_cpu_iterator__next()
448 if (evlist_cpu_itr->evlist_cpu_map_idx < evlist_cpu_itr->evlist_cpu_map_nr) { in evlist_cpu_iterator__next()
449 evlist_cpu_itr->evsel = evlist__first(evlist_cpu_itr->container); in evlist_cpu_iterator__next()
450 evlist_cpu_itr->cpu = in evlist_cpu_iterator__next()
451 perf_cpu_map__cpu(evlist_cpu_itr->container->core.all_cpus, in evlist_cpu_iterator__next()
452 evlist_cpu_itr->evlist_cpu_map_idx); in evlist_cpu_iterator__next()
453 if (evlist_cpu_itr->affinity) in evlist_cpu_iterator__next()
454 affinity__set(evlist_cpu_itr->affinity, evlist_cpu_itr->cpu.cpu); in evlist_cpu_iterator__next()
455 evlist_cpu_itr->cpu_map_idx = in evlist_cpu_iterator__next()
456 perf_cpu_map__idx(evlist_cpu_itr->evsel->core.cpus, in evlist_cpu_iterator__next()
457 evlist_cpu_itr->cpu); in evlist_cpu_iterator__next()
462 if (evlist_cpu_itr->cpu_map_idx == -1) in evlist_cpu_iterator__next()
469 return evlist_cpu_itr->evlist_cpu_map_idx >= evlist_cpu_itr->evlist_cpu_map_nr; in evlist_cpu_iterator__end()
486 if (!evsel__is_group_leader(pos) || !pos->core.fd) in evlist__is_enabled()
489 if (!pos->disabled) in evlist__is_enabled()
503 if (!cpu_map__is_dummy(evlist->core.user_requested_cpus)) { in __evlist__disable()
515 if (pos->disabled || !evsel__is_group_leader(pos) || !pos->core.fd) in __evlist__disable()
519 if (pos->immediate) in __evlist__disable()
521 if (pos->immediate != imm) in __evlist__disable()
533 if (!evsel__is_group_leader(pos) || !pos->core.fd) in __evlist__disable()
537 pos->disabled = true; in __evlist__disable()
545 evlist->enabled = evlist__is_enabled(evlist); in __evlist__disable()
547 evlist->enabled = false; in __evlist__disable()
572 if (!cpu_map__is_dummy(evlist->core.user_requested_cpus)) { in __evlist__enable()
582 if (!evsel__is_group_leader(pos) || !pos->core.fd) in __evlist__enable()
592 if (!evsel__is_group_leader(pos) || !pos->core.fd) in __evlist__enable()
596 pos->disabled = false; in __evlist__enable()
604 evlist->enabled = true; in __evlist__enable()
624 (evlist->enabled ? evlist__disable : evlist__enable)(evlist); in evlist__toggle_enable()
629 return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN, fdarray_flag__default); in evlist__add_pollfd()
634 return perf_evlist__filter_pollfd(&evlist->core, revents_and_mask); in evlist__filter_pollfd()
640 return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN, in evlist__add_wakeup_eventfd()
648 return perf_evlist__poll(&evlist->core, timeout); in evlist__poll()
658 head = &evlist->core.heads[hash]; in evlist__id2sid()
661 if (sid->id == id) in evlist__id2sid()
671 if (evlist->core.nr_entries == 1 || !id) in evlist__id2evsel()
676 return container_of(sid->evsel, struct evsel, core); in evlist__id2evsel()
693 return container_of(sid->evsel, struct evsel, core); in evlist__id2evsel_strict()
700 const __u64 *array = event->sample.array; in evlist__event2id()
703 n = (event->header.size - sizeof(event->header)) >> 3; in evlist__event2id()
705 if (event->header.type == PERF_RECORD_SAMPLE) { in evlist__event2id()
706 if (evlist->id_pos >= n) in evlist__event2id()
707 return -1; in evlist__event2id()
708 *id = array[evlist->id_pos]; in evlist__event2id()
710 if (evlist->is_pos > n) in evlist__event2id()
711 return -1; in evlist__event2id()
712 n -= evlist->is_pos; in evlist__event2id()
726 if (evlist->core.nr_entries == 1) in evlist__event2evsel()
729 if (!first->core.attr.sample_id_all && in evlist__event2evsel()
730 event->header.type != PERF_RECORD_SAMPLE) in evlist__event2evsel()
741 head = &evlist->core.heads[hash]; in evlist__event2evsel()
744 if (sid->id == id) in evlist__event2evsel()
745 return container_of(sid->evsel, struct evsel, core); in evlist__event2evsel()
754 if (!evlist->overwrite_mmap) in evlist__set_paused()
757 for (i = 0; i < evlist->core.nr_mmaps; i++) { in evlist__set_paused()
758 int fd = evlist->overwrite_mmap[i].core.fd; in evlist__set_paused()
784 if (evlist->mmap) in evlist__munmap_nofree()
785 for (i = 0; i < evlist->core.nr_mmaps; i++) in evlist__munmap_nofree()
786 perf_mmap__munmap(&evlist->mmap[i].core); in evlist__munmap_nofree()
788 if (evlist->overwrite_mmap) in evlist__munmap_nofree()
789 for (i = 0; i < evlist->core.nr_mmaps; i++) in evlist__munmap_nofree()
790 perf_mmap__munmap(&evlist->overwrite_mmap[i].core); in evlist__munmap_nofree()
796 zfree(&evlist->mmap); in evlist__munmap()
797 zfree(&evlist->overwrite_mmap); in evlist__munmap()
813 map = zalloc(evlist->core.nr_mmaps * sizeof(struct mmap)); in evlist__alloc_mmap()
817 for (i = 0; i < evlist->core.nr_mmaps; i++) { in evlist__alloc_mmap()
818 struct perf_mmap *prev = i ? &map[i - 1].core : NULL; in evlist__alloc_mmap()
845 auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, evsel, idx); in perf_evlist__mmap_cb_idx()
854 maps = overwrite ? evlist->overwrite_mmap : evlist->mmap; in perf_evlist__mmap_cb_get()
862 evlist->overwrite_mmap = maps; in perf_evlist__mmap_cb_get()
863 if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY) in perf_evlist__mmap_cb_get()
866 evlist->mmap = maps; in perf_evlist__mmap_cb_get()
896 max -= (page_size / 1024); in perf_event_mlock_kb_in_pages()
929 return -EINVAL; in parse_pages_arg()
932 if (val != (unsigned long) -1) { in parse_pages_arg()
940 return -EINVAL; in parse_pages_arg()
951 return -EINVAL; in parse_pages_arg()
959 return -EINVAL; in parse_pages_arg()
974 pr_err("Invalid argument for --mmap_pages/-m\n"); in __evlist__parse_mmap_pages()
975 return -1; in __evlist__parse_mmap_pages()
984 return __evlist__parse_mmap_pages(opt->value, str); in evlist__parse_mmap_pages()
988 * evlist__mmap_ex - Create mmaps to receive events.
992 * @auxtrace_pages - auxtrace map length in pages
993 * @auxtrace_overwrite - overwrite older auxtrace data?
1026 evlist->core.mmap_len = evlist__mmap_size(pages); in evlist__mmap_ex()
1027 pr_debug("mmap size %zuB\n", evlist->core.mmap_len); in evlist__mmap_ex()
1029 auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->core.mmap_len, in evlist__mmap_ex()
1032 return perf_evlist__mmap_ops(&evlist->core, &ops, &mp.core); in evlist__mmap_ex()
1042 bool all_threads = (target->per_thread && target->system_wide); in evlist__create_maps()
1047 * If specify '-a' and '--per-thread' to perf record, perf record in evlist__create_maps()
1048 * will override '--per-thread'. target->per_thread = false and in evlist__create_maps()
1049 * target->system_wide = true. in evlist__create_maps()
1051 * If specify '--per-thread' only to perf record, in evlist__create_maps()
1052 * target->per_thread = true and target->system_wide = false. in evlist__create_maps()
1054 * So target->per_thread && target->system_wide is false. in evlist__create_maps()
1059 * For perf stat, it allows the case that target->per_thread and in evlist__create_maps()
1060 * target->system_wide are all true. It means to collect system-wide in evlist__create_maps()
1061 * per-thread data. thread_map__new_str will call in evlist__create_maps()
1064 threads = thread_map__new_str(target->pid, target->tid, target->uid, in evlist__create_maps()
1068 return -1; in evlist__create_maps()
1073 cpus = perf_cpu_map__new(target->cpu_list); in evlist__create_maps()
1078 evlist->core.has_user_cpus = !!target->cpu_list; in evlist__create_maps()
1080 perf_evlist__set_maps(&evlist->core, cpus, threads); in evlist__create_maps()
1090 return -1; in evlist__create_maps()
1104 if (evsel->filter) { in evlist__apply_filters()
1105 err = perf_evsel__apply_filter(&evsel->core, evsel->filter); in evlist__apply_filters()
1113 * non-tracepoint events can have BPF filters. in evlist__apply_filters()
1115 if (!list_empty(&evsel->bpf_filters)) { in evlist__apply_filters()
1133 return -1; in evlist__set_tp_filter()
1136 if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) in evlist__set_tp_filter()
1153 return -1; in evlist__append_tp_filter()
1156 if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) in evlist__append_tp_filter()
1225 if (evlist->core.nr_entries == 1) in evlist__valid_sample_type()
1228 if (evlist->id_pos < 0 || evlist->is_pos < 0) in evlist__valid_sample_type()
1232 if (pos->id_pos != evlist->id_pos || in evlist__valid_sample_type()
1233 pos->is_pos != evlist->is_pos) in evlist__valid_sample_type()
1244 if (evlist->combined_sample_type) in __evlist__combined_sample_type()
1245 return evlist->combined_sample_type; in __evlist__combined_sample_type()
1248 evlist->combined_sample_type |= evsel->core.attr.sample_type; in __evlist__combined_sample_type()
1250 return evlist->combined_sample_type; in __evlist__combined_sample_type()
1255 evlist->combined_sample_type = 0; in evlist__combined_sample_type()
1265 branch_type |= evsel->core.attr.branch_sample_type; in evlist__combined_branch_type()
1277 if ((pos->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) && in evlist__find_dup_event_from_prev()
1278 !strcmp(pos->name, event->name)) in evlist__find_dup_event_from_prev()
1308 name[1] = '0' + i - 1; in evlist__new_abbr_name()
1321 if (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) { in evlist__update_br_cntr()
1322 evsel->br_cntr_idx = i++; in evlist__update_br_cntr()
1323 evsel__leader(evsel)->br_cntr_nr++; in evlist__update_br_cntr()
1327 memcpy(evsel->abbr_name, dup->abbr_name, 3 * sizeof(char)); in evlist__update_br_cntr()
1329 evlist__new_abbr_name(evsel->abbr_name); in evlist__update_br_cntr()
1332 evlist->nr_br_cntr = i; in evlist__update_br_cntr()
1338 u64 read_format = first->core.attr.read_format; in evlist__valid_read_format()
1339 u64 sample_type = first->core.attr.sample_type; in evlist__valid_read_format()
1342 if (read_format != pos->core.attr.read_format) { in evlist__valid_read_format()
1344 read_format, (u64)pos->core.attr.read_format); in evlist__valid_read_format()
1361 return first->core.attr.sample_id_all ? evsel__id_hdr_size(first) : 0; in evlist__id_hdr_size()
1369 if (first->core.attr.sample_id_all != pos->core.attr.sample_id_all) in evlist__valid_sample_id_all()
1379 return first->core.attr.sample_id_all; in evlist__sample_id_all()
1384 evlist->selected = evsel; in evlist__set_selected()
1397 if (!evlist->core.user_requested_cpus || in evlist__close()
1398 cpu_map__is_dummy(evlist->core.user_requested_cpus)) { in evlist__close()
1408 perf_evsel__close_cpu(&evlist_cpu_itr.evsel->core, in evlist__close()
1414 perf_evsel__free_fd(&evsel->core); in evlist__close()
1415 perf_evsel__free_id(&evsel->core); in evlist__close()
1417 perf_evlist__reset_id_hash(&evlist->core); in evlist__close()
1429 * FIXME: -ENOMEM is the best we can do here, the cpu_map in evlist__create_syswide_maps()
1432 * default cpu identity map :-\ in evlist__create_syswide_maps()
1442 perf_evlist__set_maps(&evlist->core, cpus, threads); in evlist__create_syswide_maps()
1448 return -ENOMEM; in evlist__create_syswide_maps()
1458 * as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL in evlist__open()
1460 if (evlist->core.threads == NULL && evlist->core.user_requested_cpus == NULL) { in evlist__open()
1469 err = evsel__open(evsel, evsel->core.cpus, evsel->core.threads); in evlist__open()
1477 errno = -err; in evlist__open()
1489 return -1; in evlist__prepare_workload()
1497 evlist->workload.pid = fork(); in evlist__prepare_workload()
1498 if (evlist->workload.pid < 0) { in evlist__prepare_workload()
1503 if (!evlist->workload.pid) { in evlist__prepare_workload()
1511 close(child_ready_pipe[0]); in evlist__prepare_workload()
1512 close(go_pipe[1]); in evlist__prepare_workload()
1516 * Change the name of this process not to confuse --exclude-perf users in evlist__prepare_workload()
1520 prctl(PR_SET_NAME, "perf-exec"); in evlist__prepare_workload()
1525 close(child_ready_pipe[1]); in evlist__prepare_workload()
1537 * the parent will just close workload.cork_fd, without writing in evlist__prepare_workload()
1542 if (ret == -1) in evlist__prepare_workload()
1557 exit(-1); in evlist__prepare_workload()
1569 if (evlist->core.threads == NULL) { in evlist__prepare_workload()
1570 fprintf(stderr, "FATAL: evlist->threads need to be set at this point (%s:%d).\n", in evlist__prepare_workload()
1574 perf_thread_map__set_pid(evlist->core.threads, 0, evlist->workload.pid); in evlist__prepare_workload()
1577 close(child_ready_pipe[1]); in evlist__prepare_workload()
1578 close(go_pipe[0]); in evlist__prepare_workload()
1582 if (read(child_ready_pipe[0], &bf, 1) == -1) { in evlist__prepare_workload()
1588 evlist->workload.cork_fd = go_pipe[1]; in evlist__prepare_workload()
1589 close(child_ready_pipe[0]); in evlist__prepare_workload()
1593 close(go_pipe[0]); in evlist__prepare_workload()
1594 close(go_pipe[1]); in evlist__prepare_workload()
1596 close(child_ready_pipe[0]); in evlist__prepare_workload()
1597 close(child_ready_pipe[1]); in evlist__prepare_workload()
1598 return -1; in evlist__prepare_workload()
1603 if (evlist->workload.cork_fd > 0) { in evlist__start_workload()
1609 ret = write(evlist->workload.cork_fd, &bf, 1); in evlist__start_workload()
1613 close(evlist->workload.cork_fd); in evlist__start_workload()
1626 return -EFAULT; in evlist__parse_sample()
1630 if (perf_guest && sample->id) { in evlist__parse_sample()
1631 struct perf_sample_id *sid = evlist__id2sid(evlist, sample->id); in evlist__parse_sample()
1634 sample->machine_pid = sid->machine_pid; in evlist__parse_sample()
1635 sample->vcpu = sid->vcpu.cpu; in evlist__parse_sample()
1646 return -EFAULT; in evlist__parse_sample_timestamp()
1664 printed += scnprintf(buf + printed, size - printed, "\nHint:\t"); in evlist__strerror_open()
1667 printed += scnprintf(buf + printed, size - printed, in evlist__strerror_open()
1670 printed += scnprintf(buf + printed, size - printed, in evlist__strerror_open()
1671 "For system wide tracing it needs to be set to -1.\n"); in evlist__strerror_open()
1673 printed += scnprintf(buf + printed, size - printed, in evlist__strerror_open()
1674 "Hint:\tTry: 'sudo sh -c \"echo -1 > /proc/sys/kernel/perf_event_paranoid\"'\n" in evlist__strerror_open()
1684 if (first->core.attr.sample_freq < (u64)max_freq) in evlist__strerror_open()
1691 emsg, max_freq, first->core.attr.sample_freq); in evlist__strerror_open()
1706 int pages_attempted = evlist->core.mmap_len / 1024, pages_max_per_user, printed = 0; in evlist__strerror_mmap()
1711 printed += scnprintf(buf + printed, size - printed, in evlist__strerror_mmap()
1718 printed += scnprintf(buf + printed, size - printed, in evlist__strerror_mmap()
1719 "Hint:\tTry 'sudo sh -c \"echo %d > /proc/sys/kernel/perf_event_mlock_kb\"', or\n", in evlist__strerror_mmap()
1723 printed += scnprintf(buf + printed, size - printed, in evlist__strerror_mmap()
1724 "Hint:\tTry using a smaller -m/--mmap-pages value."); in evlist__strerror_mmap()
1744 list_move_tail(&evsel->core.node, &move); in evlist__to_front()
1747 list_splice(&move, &evlist->core.entries); in evlist__to_front()
1755 if (evsel->tracking) in evlist__get_tracking_event()
1766 if (tracking_evsel->tracking) in evlist__set_tracking_event()
1771 evsel->tracking = false; in evlist__set_tracking_event()
1774 tracking_evsel->tracking = true; in evlist__set_tracking_event()
1789 perf_evlist__go_system_wide(&evlist->core, &evsel->core); in evlist__findnew_tracking_event()
1800 if (!evsel->name) in evlist__find_evsel_by_str()
1811 enum bkw_mmap_state old_state = evlist->bkw_mmap_state; in evlist__toggle_bkw_mmap()
1818 if (!evlist->overwrite_mmap) in evlist__toggle_bkw_mmap()
1848 evlist->bkw_mmap_state = state; in evlist__toggle_bkw_mmap()
1871 if (!evsel->core.attr.exclude_kernel) in evlist__exclude_kernel()
1889 leader->forced_leader = true; in evlist__force_leader()
1893 struct evsel *evlist__reset_weak_group(struct evlist *evsel_list, struct evsel *evsel, bool close) in evlist__reset_weak_group() argument
1901 leader->name, leader->core.nr_members); in evlist__reset_weak_group()
1911 if (is_open && close) in evlist__reset_weak_group()
1912 perf_evsel__close(&c2->core); in evlist__reset_weak_group()
1914 * We want to close all members of the group and reopen in evlist__reset_weak_group()
1924 c2->reset_group = true; in evlist__reset_weak_group()
1928 if (leader->core.nr_members == 1) in evlist__reset_weak_group()
1929 leader->core.nr_members = 0; in evlist__reset_weak_group()
1939 return -EINVAL; in evlist__parse_control_fifo()
1943 return -EINVAL; in evlist__parse_control_fifo()
1947 return -ENOMEM; in evlist__parse_control_fifo()
1960 ret = -errno; in evlist__parse_control_fifo()
1971 ret = -errno; in evlist__parse_control_fifo()
1993 return -EINVAL; in evlist__parse_control()
1998 return -EINVAL; in evlist__parse_control()
2002 return -EINVAL; in evlist__parse_control()
2012 close(ctl_fd); in evlist__close_control()
2014 close(ctl_fd_ack); in evlist__close_control()
2020 if (fd == -1) { in evlist__initialize_ctlfd()
2025 evlist->ctl_fd.pos = perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN, in evlist__initialize_ctlfd()
2028 if (evlist->ctl_fd.pos < 0) { in evlist__initialize_ctlfd()
2029 evlist->ctl_fd.pos = -1; in evlist__initialize_ctlfd()
2031 return -1; in evlist__initialize_ctlfd()
2034 evlist->ctl_fd.fd = fd; in evlist__initialize_ctlfd()
2035 evlist->ctl_fd.ack = ack; in evlist__initialize_ctlfd()
2042 return evlist->ctl_fd.pos >= 0; in evlist__ctlfd_initialized()
2047 struct pollfd *entries = evlist->core.pollfd.entries; in evlist__finalize_ctlfd()
2052 entries[evlist->ctl_fd.pos].fd = -1; in evlist__finalize_ctlfd()
2053 entries[evlist->ctl_fd.pos].events = 0; in evlist__finalize_ctlfd()
2054 entries[evlist->ctl_fd.pos].revents = 0; in evlist__finalize_ctlfd()
2056 evlist->ctl_fd.pos = -1; in evlist__finalize_ctlfd()
2057 evlist->ctl_fd.ack = -1; in evlist__finalize_ctlfd()
2058 evlist->ctl_fd.fd = -1; in evlist__finalize_ctlfd()
2072 data_size--; in evlist__ctlfd_recv()
2075 err = read(evlist->ctl_fd.fd, &c, 1); in evlist__ctlfd_recv()
2083 } else if (err == -1) { in evlist__ctlfd_recv()
2089 pr_err("Failed to read from ctlfd %d: %m\n", evlist->ctl_fd.fd); in evlist__ctlfd_recv()
2099 (sizeof(EVLIST_CTL_CMD_ENABLE_TAG)-1))) { in evlist__ctlfd_recv()
2102 (sizeof(EVLIST_CTL_CMD_DISABLE_TAG)-1))) { in evlist__ctlfd_recv()
2105 (sizeof(EVLIST_CTL_CMD_SNAPSHOT_TAG)-1))) { in evlist__ctlfd_recv()
2109 (sizeof(EVLIST_CTL_CMD_EVLIST_TAG)-1))) { in evlist__ctlfd_recv()
2112 (sizeof(EVLIST_CTL_CMD_STOP_TAG)-1))) { in evlist__ctlfd_recv()
2115 (sizeof(EVLIST_CTL_CMD_PING_TAG)-1))) { in evlist__ctlfd_recv()
2127 if (evlist->ctl_fd.ack == -1) in evlist__ctlfd_ack()
2130 err = write(evlist->ctl_fd.ack, EVLIST_CTL_CMD_ACK_TAG, in evlist__ctlfd_ack()
2132 if (err == -1) in evlist__ctlfd_ack()
2133 pr_err("failed to write to ctl_ack_fd %d: %m\n", evlist->ctl_fd.ack); in evlist__ctlfd_ack()
2153 return -1; in get_cmd_arg()
2163 enable ? sizeof(EVLIST_CTL_CMD_ENABLE_TAG) - 1 : in evlist__ctlfd_enable()
2164 sizeof(EVLIST_CTL_CMD_DISABLE_TAG) - 1, in evlist__ctlfd_enable()
2168 return -1; in evlist__ctlfd_enable()
2178 pr_info("Event %s %s\n", evsel->name, in evlist__ctlfd_enable()
2204 sizeof(EVLIST_CTL_CMD_EVLIST_TAG) - 1, in evlist__ctlfd_list()
2208 return -1; in evlist__ctlfd_list()
2212 if (!strcmp(arg, "-v")) { in evlist__ctlfd_list()
2214 } else if (!strcmp(arg, "-g")) { in evlist__ctlfd_list()
2216 } else if (!strcmp(arg, "-F")) { in evlist__ctlfd_list()
2220 return -1; in evlist__ctlfd_list()
2234 int ctlfd_pos = evlist->ctl_fd.pos; in evlist__ctlfd_process()
2235 struct pollfd *entries = evlist->core.pollfd.entries; in evlist__ctlfd_process()
2278 * struct event_enable_time - perf record -D/--delay single time range.
2279 * @start: start of time range to enable events in milliseconds
2280 * @end: end of time range to enable events in milliseconds
2289 static int parse_event_enable_time(const char *str, struct event_enable_time *range, bool first) in parse_event_enable_time() argument
2291 const char *fmt = first ? "%u - %u %n" : " , %u - %u %n"; in parse_event_enable_time()
2296 return -EINVAL; in parse_event_enable_time()
2297 if (range) { in parse_event_enable_time()
2298 range->start = start; in parse_event_enable_time()
2299 range->end = end; in parse_event_enable_time()
2304 static ssize_t parse_event_enable_times(const char *str, struct event_enable_time *range) in parse_event_enable_times() argument
2306 int incr = !!range; in parse_event_enable_times()
2311 ret = parse_event_enable_time(str, range, first); in parse_event_enable_times()
2315 if (!first && range && range->start <= range[-1].end) in parse_event_enable_times()
2316 return -EINVAL; in parse_event_enable_times()
2318 range += incr; in parse_event_enable_times()
2325 * struct event_enable_timer - control structure for perf record -D/--delay.
2353 if (*endptr || d > INT_MAX || d < -1) in str_to_delay()
2370 opts->target.initial_delay = str_to_delay(str); in evlist__parse_event_enable_time()
2371 if (opts->target.initial_delay) in evlist__parse_event_enable_time()
2380 return -EINVAL; in evlist__parse_event_enable_time()
2384 return -ENOMEM; in evlist__parse_event_enable_time()
2386 eet->times = calloc(times_cnt, sizeof(*eet->times)); in evlist__parse_event_enable_time()
2387 if (!eet->times) { in evlist__parse_event_enable_time()
2388 err = -ENOMEM; in evlist__parse_event_enable_time()
2392 if (parse_event_enable_times(str, eet->times) != times_cnt) { in evlist__parse_event_enable_time()
2393 err = -EINVAL; in evlist__parse_event_enable_time()
2397 eet->times_cnt = times_cnt; in evlist__parse_event_enable_time()
2399 eet->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); in evlist__parse_event_enable_time()
2400 if (eet->timerfd == -1) { in evlist__parse_event_enable_time()
2401 err = -errno; in evlist__parse_event_enable_time()
2406 eet->pollfd_pos = perf_evlist__add_pollfd(&evlist->core, eet->timerfd, NULL, POLLIN, flags); in evlist__parse_event_enable_time()
2407 if (eet->pollfd_pos < 0) { in evlist__parse_event_enable_time()
2408 err = eet->pollfd_pos; in evlist__parse_event_enable_time()
2412 eet->evlist = evlist; in evlist__parse_event_enable_time()
2413 evlist->eet = eet; in evlist__parse_event_enable_time()
2414 opts->target.initial_delay = eet->times[0].start; in evlist__parse_event_enable_time()
2419 close(eet->timerfd); in evlist__parse_event_enable_time()
2421 zfree(&eet->times); in evlist__parse_event_enable_time()
2435 if (timerfd_settime(eet->timerfd, 0, &its, NULL) < 0) { in event_enable_timer__set_timer()
2436 err = -errno; in event_enable_timer__set_timer()
2449 ms = eet->times[0].end - eet->times[0].start; in event_enable_timer__start()
2450 eet->times_step = 1; in event_enable_timer__start()
2463 entries = eet->evlist->core.pollfd.entries; in event_enable_timer__process()
2464 revents = entries[eet->pollfd_pos].revents; in event_enable_timer__process()
2465 entries[eet->pollfd_pos].revents = 0; in event_enable_timer__process()
2468 size_t step = eet->times_step; in event_enable_timer__process()
2472 evlist__disable_non_dummy(eet->evlist); in event_enable_timer__process()
2474 if (pos >= eet->times_cnt - 1) { in event_enable_timer__process()
2480 evlist__enable_non_dummy(eet->evlist); in event_enable_timer__process()
2487 if (pos < eet->times_cnt) { in event_enable_timer__process()
2488 int *times = (int *)eet->times; /* Accessing 'times' as array of int */ in event_enable_timer__process()
2489 int ms = times[step] - times[step - 1]; in event_enable_timer__process()
2491 eet->times_step = step; in event_enable_timer__process()
2503 zfree(&(*ep)->times); in event_enable_timer__exit()
2512 if (evsel->core.idx == idx) in evlist__find_evsel()
2527 …printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "," : "", evsel__name(evsel)); in evlist__scnprintf_evsels()
2529 printed += scnprintf(bf + printed, size - printed, "%s...", printed ? "," : ""); in evlist__scnprintf_evsels()
2542 * For some platforms, the 'mem-loads' event is required to use in evlist__check_mem_load_aux()
2543 * together with 'mem-loads-aux' within a group and 'mem-loads-aux' in evlist__check_mem_load_aux()
2545 * because 'mem-loads-aux' is just an auxiliary event. It doesn't carry in evlist__check_mem_load_aux()
2553 if (leader->name && strstr(leader->name, "mem-loads-aux")) { in evlist__check_mem_load_aux()
2556 pos->core.nr_members = 0; in evlist__check_mem_load_aux()
2563 * evlist__warn_user_requested_cpus() - Check each evsel against requested CPUs
2587 to_test = pmu && pmu->is_core ? pmu->cpus : cpu_map__online(); in evlist__warn_user_requested_cpus()
2594 cpu_list, pmu ? pmu->name : "cpu", buf, evsel__name(pos)); in evlist__warn_user_requested_cpus()
2613 if (strchr(pos->name, '/')) in evlist__uniquify_name()
2616 attributes = strchr(pos->name, ':'); in evlist__uniquify_name()
2622 if (asprintf(&new_name, "%s/%s/%s", pos->pmu_name, pos->name, attributes + 1)) { in evlist__uniquify_name()
2623 free(pos->name); in evlist__uniquify_name()
2624 pos->name = new_name; in evlist__uniquify_name()