Lines Matching refs:evlist
12 #include "evlist.h"
31 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
37 INIT_HLIST_HEAD(&evlist->heads[i]);
38 INIT_LIST_HEAD(&evlist->entries);
39 perf_evlist__set_maps(evlist, cpus, threads);
45 struct perf_evlist *evlist = zalloc(sizeof(*evlist));
47 if (evlist != NULL)
48 perf_evlist__init(evlist, cpus, threads);
50 return evlist;
53 static void perf_evlist__purge(struct perf_evlist *evlist)
57 list_for_each_entry_safe(pos, n, &evlist->entries, node) {
62 evlist->nr_entries = 0;
65 void perf_evlist__exit(struct perf_evlist *evlist)
67 free(evlist->mmap);
68 free(evlist->pollfd);
69 evlist->mmap = NULL;
70 evlist->pollfd = NULL;
73 void perf_evlist__delete(struct perf_evlist *evlist)
75 perf_evlist__purge(evlist);
76 perf_evlist__exit(evlist);
77 free(evlist);
80 void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
82 list_add_tail(&entry->node, &evlist->entries);
83 ++evlist->nr_entries;
86 int perf_evlist__add_default(struct perf_evlist *evlist)
97 perf_evlist__add(evlist, evsel);
101 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
103 int nfds = evlist->cpus->nr * evlist->threads->nr * evlist->nr_entries;
104 evlist->pollfd = malloc(sizeof(struct pollfd) * nfds);
105 return evlist->pollfd != NULL ? 0 : -ENOMEM;
108 void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
111 evlist->pollfd[evlist->nr_fds].fd = fd;
112 evlist->pollfd[evlist->nr_fds].events = POLLIN;
113 evlist->nr_fds++;
116 static void perf_evlist__id_hash(struct perf_evlist *evlist,
126 hlist_add_head(&sid->node, &evlist->heads[hash]);
129 void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
132 perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
136 static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
152 perf_evlist__id_add(evlist, evsel, cpu, thread, read_data[id_idx]);
156 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
163 if (evlist->nr_entries == 1)
164 return list_entry(evlist->entries.next, struct perf_evsel, node);
167 head = &evlist->heads[hash];
175 union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
179 struct perf_mmap *md = &evlist->mmap[idx];
185 if (evlist->overwrite) {
218 void *dst = &evlist->event_copy;
228 event = &evlist->event_copy;
236 if (!evlist->overwrite)
242 void perf_evlist__munmap(struct perf_evlist *evlist)
246 for (i = 0; i < evlist->nr_mmaps; i++) {
247 if (evlist->mmap[i].base != NULL) {
248 munmap(evlist->mmap[i].base, evlist->mmap_len);
249 evlist->mmap[i].base = NULL;
253 free(evlist->mmap);
254 evlist->mmap = NULL;
257 int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
259 evlist->nr_mmaps = evlist->cpus->nr;
260 if (evlist->cpus->map[0] == -1)
261 evlist->nr_mmaps = evlist->threads->nr;
262 evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
263 return evlist->mmap != NULL ? 0 : -ENOMEM;
266 static int __perf_evlist__mmap(struct perf_evlist *evlist,
269 evlist->mmap[idx].prev = 0;
270 evlist->mmap[idx].mask = mask;
271 evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, prot,
273 if (evlist->mmap[idx].base == MAP_FAILED)
276 perf_evlist__add_pollfd(evlist, fd);
280 static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mask)
285 for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
288 for (thread = 0; thread < evlist->threads->nr; thread++) {
289 list_for_each_entry(evsel, &evlist->entries, node) {
294 if (__perf_evlist__mmap(evlist, cpu,
303 perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
312 for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
313 if (evlist->mmap[cpu].base != NULL) {
314 munmap(evlist->mmap[cpu].base, evlist->mmap_len);
315 evlist->mmap[cpu].base = NULL;
321 static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, int mask)
326 for (thread = 0; thread < evlist->threads->nr; thread++) {
329 list_for_each_entry(evsel, &evlist->entries, node) {
334 if (__perf_evlist__mmap(evlist, thread,
343 perf_evlist__id_add_fd(evlist, evsel, 0, thread, fd) < 0)
351 for (thread = 0; thread < evlist->threads->nr; thread++) {
352 if (evlist->mmap[thread].base != NULL) {
353 munmap(evlist->mmap[thread].base, evlist->mmap_len);
354 evlist->mmap[thread].base = NULL;
362 * @evlist - list of events
368 * struct perf_mmap *m = &evlist->mmap[cpu];
375 int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
380 const struct cpu_map *cpus = evlist->cpus;
381 const struct thread_map *threads = evlist->threads;
384 if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
387 if (evlist->pollfd == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
390 evlist->overwrite = overwrite;
391 evlist->mmap_len = (pages + 1) * page_size;
393 list_for_each_entry(evsel, &evlist->entries, node) {
400 if (evlist->cpus->map[0] == -1)
401 return perf_evlist__mmap_per_thread(evlist, prot, mask);
403 return perf_evlist__mmap_per_cpu(evlist, prot, mask);
406 int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid,
409 evlist->threads = thread_map__new(target_pid, target_tid);
411 if (evlist->threads == NULL)
415 evlist->cpus = cpu_map__dummy_new();
417 evlist->cpus = cpu_map__new(cpu_list);
419 if (evlist->cpus == NULL)
425 thread_map__delete(evlist->threads);
429 void perf_evlist__delete_maps(struct perf_evlist *evlist)
431 cpu_map__delete(evlist->cpus);
432 thread_map__delete(evlist->threads);
433 evlist->cpus = NULL;
434 evlist->threads = NULL;
437 int perf_evlist__set_filters(struct perf_evlist *evlist)
439 const struct thread_map *threads = evlist->threads;
440 const struct cpu_map *cpus = evlist->cpus;
448 list_for_each_entry(evsel, &evlist->entries, node) {
465 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
469 pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
471 list_for_each_entry_continue(pos, &evlist->entries, node) {
479 u64 perf_evlist__sample_type(const struct perf_evlist *evlist)
483 first = list_entry(evlist->entries.next, struct perf_evsel, node);
487 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist)
491 pos = first = list_entry(evlist->entries.next, struct perf_evsel, node);
493 list_for_each_entry_continue(pos, &evlist->entries, node) {
501 bool perf_evlist__sample_id_all(const struct perf_evlist *evlist)
505 first = list_entry(evlist->entries.next, struct perf_evsel, node);