evlist.c (3d3b5e95997208067c963923db90ed1517565d14) | evlist.c (a91e5431d54f5359fccb5ec2512f252eb217707e) |
---|---|
1/* 2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 * 4 * Parts came from builtin-{top,stat,record}.c, see those files for further 5 * copyright notes. 6 * 7 * Released under the GPL v2. (and only v2, not any later version) 8 */ --- 5 unchanged lines hidden (view full) --- 14#include "util.h" 15 16#include <sys/mman.h> 17 18#include <linux/bitops.h> 19#include <linux/hash.h> 20 21#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 1/* 2 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 * 4 * Parts came from builtin-{top,stat,record}.c, see those files for further 5 * copyright notes. 6 * 7 * Released under the GPL v2. (and only v2, not any later version) 8 */ --- 5 unchanged lines hidden (view full) --- 14#include "util.h" 15 16#include <sys/mman.h> 17 18#include <linux/bitops.h> 19#include <linux/hash.h> 20 21#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
22#define SID(e, x, y) xyarray__entry(e->id, x, y) | 22#define SID(e, x, y) xyarray__entry(e->sample_id, x, y) |
23 24void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, 25 struct thread_map *threads) 26{ 27 int i; 28 29 for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i) 30 INIT_HLIST_HEAD(&evlist->heads[i]); --- 70 unchanged lines hidden (view full) --- 101void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) 102{ 103 fcntl(fd, F_SETFL, O_NONBLOCK); 104 evlist->pollfd[evlist->nr_fds].fd = fd; 105 evlist->pollfd[evlist->nr_fds].events = POLLIN; 106 evlist->nr_fds++; 107} 108 | 23 24void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, 25 struct thread_map *threads) 26{ 27 int i; 28 29 for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i) 30 INIT_HLIST_HEAD(&evlist->heads[i]); --- 70 unchanged lines hidden (view full) --- 101void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd) 102{ 103 fcntl(fd, F_SETFL, O_NONBLOCK); 104 evlist->pollfd[evlist->nr_fds].fd = fd; 105 evlist->pollfd[evlist->nr_fds].events = POLLIN; 106 evlist->nr_fds++; 107} 108 |
109void perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel, 110 int cpu, int thread, u64 id) | 109static void perf_evlist__id_hash(struct perf_evlist *evlist, 110 struct perf_evsel *evsel, 111 int cpu, int thread, u64 id) |
111{ 112 int hash; 113 struct perf_sample_id *sid = SID(evsel, cpu, thread); 114 115 sid->id = id; 116 sid->evsel = evsel; 117 hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS); 118 hlist_add_head(&sid->node, &evlist->heads[hash]); 119} 120 | 112{ 113 int hash; 114 struct perf_sample_id *sid = SID(evsel, cpu, thread); 115 116 sid->id = id; 117 sid->evsel = evsel; 118 hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS); 119 hlist_add_head(&sid->node, &evlist->heads[hash]); 120} 121 |
121static int perf_evlist__id_hash_fd(struct perf_evlist *evlist, 122 struct perf_evsel *evsel, 123 int cpu, int thread, int fd) | 122void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, 123 int cpu, int thread, u64 id) |
124{ | 124{ |
125 perf_evlist__id_hash(evlist, evsel, cpu, thread, id); 126 evsel->id[evsel->ids++] = id; 127} 128 129static int perf_evlist__id_add_fd(struct perf_evlist *evlist, 130 struct perf_evsel *evsel, 131 int cpu, int thread, int fd) 132{ |
|
125 u64 read_data[4] = { 0, }; 126 int id_idx = 1; /* The first entry is the counter value */ 127 128 if (!(evsel->attr.read_format & PERF_FORMAT_ID) || 129 read(fd, &read_data, sizeof(read_data)) == -1) 130 return -1; 131 132 if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) 133 ++id_idx; 134 if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) 135 ++id_idx; 136 | 133 u64 read_data[4] = { 0, }; 134 int id_idx = 1; /* The first entry is the counter value */ 135 136 if (!(evsel->attr.read_format & PERF_FORMAT_ID) || 137 read(fd, &read_data, sizeof(read_data)) == -1) 138 return -1; 139 140 if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) 141 ++id_idx; 142 if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) 143 ++id_idx; 144 |
137 perf_evlist__id_hash(evlist, evsel, cpu, thread, read_data[id_idx]); | 145 perf_evlist__id_add(evlist, evsel, cpu, thread, read_data[id_idx]); |
138 return 0; 139} 140 141struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) 142{ 143 struct hlist_head *head; 144 struct hlist_node *pos; 145 struct perf_sample_id *sid; --- 141 unchanged lines hidden (view full) --- 287 return -ENOMEM; 288 289 evlist->overwrite = overwrite; 290 evlist->mmap_len = (pages + 1) * page_size; 291 first_evsel = list_entry(evlist->entries.next, struct perf_evsel, node); 292 293 list_for_each_entry(evsel, &evlist->entries, node) { 294 if ((evsel->attr.read_format & PERF_FORMAT_ID) && | 146 return 0; 147} 148 149struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) 150{ 151 struct hlist_head *head; 152 struct hlist_node *pos; 153 struct perf_sample_id *sid; --- 141 unchanged lines hidden (view full) --- 295 return -ENOMEM; 296 297 evlist->overwrite = overwrite; 298 evlist->mmap_len = (pages + 1) * page_size; 299 first_evsel = list_entry(evlist->entries.next, struct perf_evsel, node); 300 301 list_for_each_entry(evsel, &evlist->entries, node) { 302 if ((evsel->attr.read_format & PERF_FORMAT_ID) && |
295 evsel->id == NULL && | 303 evsel->sample_id == NULL && |
296 perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0) 297 return -ENOMEM; 298 299 for (cpu = 0; cpu < cpus->nr; cpu++) { 300 for (thread = 0; thread < threads->nr; thread++) { 301 int fd = FD(evsel, cpu, thread); 302 303 if (evsel->idx || thread) { 304 if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, 305 FD(first_evsel, cpu, 0)) != 0) 306 goto out_unmap; 307 } else if (__perf_evlist__mmap(evlist, cpu, prot, mask, fd) < 0) 308 goto out_unmap; 309 310 if ((evsel->attr.read_format & PERF_FORMAT_ID) && | 304 perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0) 305 return -ENOMEM; 306 307 for (cpu = 0; cpu < cpus->nr; cpu++) { 308 for (thread = 0; thread < threads->nr; thread++) { 309 int fd = FD(evsel, cpu, thread); 310 311 if (evsel->idx || thread) { 312 if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, 313 FD(first_evsel, cpu, 0)) != 0) 314 goto out_unmap; 315 } else if (__perf_evlist__mmap(evlist, cpu, prot, mask, fd) < 0) 316 goto out_unmap; 317 318 if ((evsel->attr.read_format & PERF_FORMAT_ID) && |
311 perf_evlist__id_hash_fd(evlist, evsel, cpu, thread, fd) < 0) | 319 perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0) |
312 goto out_unmap; 313 } 314 } 315 } 316 317 return 0; 318 319out_unmap: --- 67 unchanged lines hidden --- | 320 goto out_unmap; 321 } 322 } 323 } 324 325 return 0; 326 327out_unmap: --- 67 unchanged lines hidden --- |