Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libperf: Add perf_evlist__id_add_fd() function

Add the perf_evlist__id_add_fd() function to libperf as an internal
function.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lore.kernel.org/lkml/20190913132355.21634-32-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
d5a99483 b0031c22

+50 -47
+44
tools/perf/lib/evlist.c
··· 4 4 #include <linux/bitops.h> 5 5 #include <linux/list.h> 6 6 #include <linux/hash.h> 7 + #include <sys/ioctl.h> 7 8 #include <internal/evlist.h> 8 9 #include <internal/evsel.h> 9 10 #include <internal/xyarray.h> 10 11 #include <linux/zalloc.h> 11 12 #include <stdlib.h> 13 + #include <errno.h> 14 + #include <unistd.h> 12 15 #include <perf/cpumap.h> 13 16 #include <perf/threadmap.h> 14 17 ··· 196 193 { 197 194 perf_evlist__id_hash(evlist, evsel, cpu, thread, id); 198 195 evsel->id[evsel->ids++] = id; 196 + } 197 + 198 + int perf_evlist__id_add_fd(struct perf_evlist *evlist, 199 + struct perf_evsel *evsel, 200 + int cpu, int thread, int fd) 201 + { 202 + u64 read_data[4] = { 0, }; 203 + int id_idx = 1; /* The first entry is the counter value */ 204 + u64 id; 205 + int ret; 206 + 207 + ret = ioctl(fd, PERF_EVENT_IOC_ID, &id); 208 + if (!ret) 209 + goto add; 210 + 211 + if (errno != ENOTTY) 212 + return -1; 213 + 214 + /* Legacy way to get event id.. All hail to old kernels! */ 215 + 216 + /* 217 + * This way does not work with group format read, so bail 218 + * out in that case. 219 + */ 220 + if (perf_evlist__read_format(evlist) & PERF_FORMAT_GROUP) 221 + return -1; 222 + 223 + if (!(evsel->attr.read_format & PERF_FORMAT_ID) || 224 + read(fd, &read_data, sizeof(read_data)) == -1) 225 + return -1; 226 + 227 + if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) 228 + ++id_idx; 229 + if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) 230 + ++id_idx; 231 + 232 + id = read_data[id_idx]; 233 + 234 + add: 235 + perf_evlist__id_add(evlist, evsel, cpu, thread, id); 236 + return 0; 199 237 }
+4
tools/perf/lib/include/internal/evlist.h
··· 72 72 struct perf_evsel *evsel, 73 73 int cpu, int thread, u64 id); 74 74 75 + int perf_evlist__id_add_fd(struct perf_evlist *evlist, 76 + struct perf_evsel *evsel, 77 + int cpu, int thread, int fd); 78 + 75 79 #endif /* __LIBPERF_INTERNAL_EVLIST_H */
+1 -42
tools/perf/util/evlist.c
··· 461 461 return fdarray__poll(&evlist->core.pollfd, timeout); 462 462 } 463 463 464 - int perf_evlist__id_add_fd(struct evlist *evlist, 465 - struct evsel *evsel, 466 - int cpu, int thread, int fd) 467 - { 468 - u64 read_data[4] = { 0, }; 469 - int id_idx = 1; /* The first entry is the counter value */ 470 - u64 id; 471 - int ret; 472 - 473 - ret = ioctl(fd, PERF_EVENT_IOC_ID, &id); 474 - if (!ret) 475 - goto add; 476 - 477 - if (errno != ENOTTY) 478 - return -1; 479 - 480 - /* Legacy way to get event id.. All hail to old kernels! */ 481 - 482 - /* 483 - * This way does not work with group format read, so bail 484 - * out in that case. 485 - */ 486 - if (perf_evlist__read_format(&evlist->core) & PERF_FORMAT_GROUP) 487 - return -1; 488 - 489 - if (!(evsel->core.attr.read_format & PERF_FORMAT_ID) || 490 - read(fd, &read_data, sizeof(read_data)) == -1) 491 - return -1; 492 - 493 - if (evsel->core.attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) 494 - ++id_idx; 495 - if (evsel->core.attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) 496 - ++id_idx; 497 - 498 - id = read_data[id_idx]; 499 - 500 - add: 501 - perf_evlist__id_add(&evlist->core, &evsel->core, cpu, thread, id); 502 - return 0; 503 - } 504 - 505 464 static void perf_evlist__set_sid_idx(struct evlist *evlist, 506 465 struct evsel *evsel, int idx, int cpu, 507 466 int thread) ··· 735 776 } 736 777 737 778 if (evsel->core.attr.read_format & PERF_FORMAT_ID) { 738 - if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread, 779 + if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, cpu, thread, 739 780 fd) < 0) 740 781 return -1; 741 782 perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
-4
tools/perf/util/evlist.h
··· 141 141 perf_evlist__find_tracepoint_by_name(struct evlist *evlist, 142 142 const char *name); 143 143 144 - int perf_evlist__id_add_fd(struct evlist *evlist, 145 - struct evsel *evsel, 146 - int cpu, int thread, int fd); 147 - 148 144 int perf_evlist__add_pollfd(struct evlist *evlist, int fd); 149 145 int perf_evlist__alloc_pollfd(struct evlist *evlist); 150 146 int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
+1 -1
tools/perf/util/evsel.c
··· 2662 2662 thread++) { 2663 2663 int fd = FD(evsel, cpu, thread); 2664 2664 2665 - if (perf_evlist__id_add_fd(evlist, evsel, 2665 + if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, 2666 2666 cpu, thread, fd) < 0) 2667 2667 return -1; 2668 2668 }