aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2019-09-03 04:34:29 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-09-25 08:51:48 -0400
commit70c20369ee95ef8b6887944194cfb74a5a8d1fe3 (patch)
treee25bde2c86f36e6375d234e97e62050daca95b0a /tools
parent1d5af02d7a92acaa877ab0fbec0756114852720a (diff)
libperf: Add perf_evsel__alloc_id/perf_evsel__free_id functions
Add perf_evsel__alloc_id()/perf_evsel__free_id() functions to libperf as internal functions. Move 'struct perf_sample_id' to internal/evsel.h header and change 'struct perf_sample_id::evsel' to 'struct perf_evsel' and the related code that touches it. 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-28-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/lib/evsel.c30
-rw-r--r--tools/perf/lib/include/internal/evsel.h27
-rw-r--r--tools/perf/tests/event_update.c2
-rw-r--r--tools/perf/util/evlist.c10
-rw-r--r--tools/perf/util/evsel.c36
-rw-r--r--tools/perf/util/evsel.h25
-rw-r--r--tools/perf/util/header.c4
-rw-r--r--tools/perf/util/session.c4
8 files changed, 71 insertions, 67 deletions
diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 24abc80dd767..a8cb582e2721 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -230,3 +230,33 @@ struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel)
230{ 230{
231 return &evsel->attr; 231 return &evsel->attr;
232} 232}
233
234int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
235{
236 if (ncpus == 0 || nthreads == 0)
237 return 0;
238
239 if (evsel->system_wide)
240 nthreads = 1;
241
242 evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
243 if (evsel->sample_id == NULL)
244 return -ENOMEM;
245
246 evsel->id = zalloc(ncpus * nthreads * sizeof(u64));
247 if (evsel->id == NULL) {
248 xyarray__delete(evsel->sample_id);
249 evsel->sample_id = NULL;
250 return -ENOMEM;
251 }
252
253 return 0;
254}
255
256void perf_evsel__free_id(struct perf_evsel *evsel)
257{
258 xyarray__delete(evsel->sample_id);
259 evsel->sample_id = NULL;
260 zfree(&evsel->id);
261 evsel->ids = 0;
262}
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index 385766f06591..a69b8299c36f 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -5,11 +5,35 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/perf_event.h> 6#include <linux/perf_event.h>
7#include <stdbool.h> 7#include <stdbool.h>
8#include <sys/types.h>
8 9
9struct perf_cpu_map; 10struct perf_cpu_map;
10struct perf_thread_map; 11struct perf_thread_map;
11struct xyarray; 12struct xyarray;
12 13
14/*
15 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
16 * more than one entry in the evlist.
17 */
18struct perf_sample_id {
19 struct hlist_node node;
20 u64 id;
21 struct perf_evsel *evsel;
22 /*
23 * 'idx' will be used for AUX area sampling. A sample will have AUX area
24 * data that will be queued for decoding, where there are separate
25 * queues for each CPU (per-cpu tracing) or task (per-thread tracing).
26 * The sample ID can be used to lookup 'idx' which is effectively the
27 * queue number.
28 */
29 int idx;
30 int cpu;
31 pid_t tid;
32
33 /* Holds total ID period value for PERF_SAMPLE_READ processing. */
34 u64 period;
35};
36
13struct perf_evsel { 37struct perf_evsel {
14 struct list_head node; 38 struct list_head node;
15 struct perf_event_attr attr; 39 struct perf_event_attr attr;
@@ -32,4 +56,7 @@ void perf_evsel__free_fd(struct perf_evsel *evsel);
32int perf_evsel__read_size(struct perf_evsel *evsel); 56int perf_evsel__read_size(struct perf_evsel *evsel);
33int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter); 57int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
34 58
59int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
60void perf_evsel__free_id(struct perf_evsel *evsel);
61
35#endif /* __LIBPERF_INTERNAL_EVSEL_H */ 62#endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c
index 0497d900ced2..cf4f90170f90 100644
--- a/tools/perf/tests/event_update.c
+++ b/tools/perf/tests/event_update.c
@@ -95,7 +95,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
95 evsel = perf_evlist__first(evlist); 95 evsel = perf_evlist__first(evlist);
96 96
97 TEST_ASSERT_VAL("failed to allocate ids", 97 TEST_ASSERT_VAL("failed to allocate ids",
98 !perf_evsel__alloc_id(evsel, 1, 1)); 98 !perf_evsel__alloc_id(&evsel->core, 1, 1));
99 99
100 perf_evlist__id_add(evlist, evsel, 0, 0, 123); 100 perf_evlist__id_add(evlist, evsel, 0, 0, 123);
101 101
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c6af7c622612..559db38594a8 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -469,7 +469,7 @@ static void perf_evlist__id_hash(struct evlist *evlist,
469 struct perf_sample_id *sid = SID(evsel, cpu, thread); 469 struct perf_sample_id *sid = SID(evsel, cpu, thread);
470 470
471 sid->id = id; 471 sid->id = id;
472 sid->evsel = evsel; 472 sid->evsel = &evsel->core;
473 hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS); 473 hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
474 hlist_add_head(&sid->node, &evlist->core.heads[hash]); 474 hlist_add_head(&sid->node, &evlist->core.heads[hash]);
475} 475}
@@ -563,7 +563,7 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
563 563
564 sid = perf_evlist__id2sid(evlist, id); 564 sid = perf_evlist__id2sid(evlist, id);
565 if (sid) 565 if (sid)
566 return sid->evsel; 566 return container_of(sid->evsel, struct evsel, core);
567 567
568 if (!perf_evlist__sample_id_all(evlist)) 568 if (!perf_evlist__sample_id_all(evlist))
569 return perf_evlist__first(evlist); 569 return perf_evlist__first(evlist);
@@ -581,7 +581,7 @@ struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
581 581
582 sid = perf_evlist__id2sid(evlist, id); 582 sid = perf_evlist__id2sid(evlist, id);
583 if (sid) 583 if (sid)
584 return sid->evsel; 584 return container_of(sid->evsel, struct evsel, core);
585 585
586 return NULL; 586 return NULL;
587} 587}
@@ -635,7 +635,7 @@ struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
635 635
636 hlist_for_each_entry(sid, head, node) { 636 hlist_for_each_entry(sid, head, node) {
637 if (sid->id == id) 637 if (sid->id == id)
638 return sid->evsel; 638 return container_of(sid->evsel, struct evsel, core);
639 } 639 }
640 return NULL; 640 return NULL;
641} 641}
@@ -1018,7 +1018,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
1018 evlist__for_each_entry(evlist, evsel) { 1018 evlist__for_each_entry(evlist, evsel) {
1019 if ((evsel->core.attr.read_format & PERF_FORMAT_ID) && 1019 if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
1020 evsel->core.sample_id == NULL && 1020 evsel->core.sample_id == NULL &&
1021 perf_evsel__alloc_id(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0) 1021 perf_evsel__alloc_id(&evsel->core, perf_cpu_map__nr(cpus), threads->nr) < 0)
1022 return -ENOMEM; 1022 return -ENOMEM;
1023 } 1023 }
1024 1024
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 55638eb9299c..a4a492f11849 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1227,36 +1227,6 @@ int evsel__disable(struct evsel *evsel)
1227 return err; 1227 return err;
1228} 1228}
1229 1229
1230int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
1231{
1232 if (ncpus == 0 || nthreads == 0)
1233 return 0;
1234
1235 if (evsel->core.system_wide)
1236 nthreads = 1;
1237
1238 evsel->core.sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
1239 if (evsel->core.sample_id == NULL)
1240 return -ENOMEM;
1241
1242 evsel->core.id = zalloc(ncpus * nthreads * sizeof(u64));
1243 if (evsel->core.id == NULL) {
1244 xyarray__delete(evsel->core.sample_id);
1245 evsel->core.sample_id = NULL;
1246 return -ENOMEM;
1247 }
1248
1249 return 0;
1250}
1251
1252static void perf_evsel__free_id(struct evsel *evsel)
1253{
1254 xyarray__delete(evsel->core.sample_id);
1255 evsel->core.sample_id = NULL;
1256 zfree(&evsel->core.id);
1257 evsel->core.ids = 0;
1258}
1259
1260static void perf_evsel__free_config_terms(struct evsel *evsel) 1230static void perf_evsel__free_config_terms(struct evsel *evsel)
1261{ 1231{
1262 struct perf_evsel_config_term *term, *h; 1232 struct perf_evsel_config_term *term, *h;
@@ -1273,7 +1243,7 @@ void perf_evsel__exit(struct evsel *evsel)
1273 assert(evsel->evlist == NULL); 1243 assert(evsel->evlist == NULL);
1274 perf_evsel__free_counts(evsel); 1244 perf_evsel__free_counts(evsel);
1275 perf_evsel__free_fd(&evsel->core); 1245 perf_evsel__free_fd(&evsel->core);
1276 perf_evsel__free_id(evsel); 1246 perf_evsel__free_id(&evsel->core);
1277 perf_evsel__free_config_terms(evsel); 1247 perf_evsel__free_config_terms(evsel);
1278 cgroup__put(evsel->cgrp); 1248 cgroup__put(evsel->cgrp);
1279 perf_cpu_map__put(evsel->core.cpus); 1249 perf_cpu_map__put(evsel->core.cpus);
@@ -1992,7 +1962,7 @@ out_close:
1992void evsel__close(struct evsel *evsel) 1962void evsel__close(struct evsel *evsel)
1993{ 1963{
1994 perf_evsel__close(&evsel->core); 1964 perf_evsel__close(&evsel->core);
1995 perf_evsel__free_id(evsel); 1965 perf_evsel__free_id(&evsel->core);
1996} 1966}
1997 1967
1998int perf_evsel__open_per_cpu(struct evsel *evsel, 1968int perf_evsel__open_per_cpu(struct evsel *evsel,
@@ -2706,7 +2676,7 @@ int perf_evsel__store_ids(struct evsel *evsel, struct evlist *evlist)
2706 struct perf_cpu_map *cpus = evsel->core.cpus; 2676 struct perf_cpu_map *cpus = evsel->core.cpus;
2707 struct perf_thread_map *threads = evsel->core.threads; 2677 struct perf_thread_map *threads = evsel->core.threads;
2708 2678
2709 if (perf_evsel__alloc_id(evsel, cpus->nr, threads->nr)) 2679 if (perf_evsel__alloc_id(&evsel->core, cpus->nr, threads->nr))
2710 return -ENOMEM; 2680 return -ENOMEM;
2711 2681
2712 return store_evsel_ids(evsel, evlist); 2682 return store_evsel_ids(evsel, evlist);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index ed64395ec340..a5b29ac10da0 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -17,29 +17,6 @@ struct addr_location;
17struct evsel; 17struct evsel;
18union perf_event; 18union perf_event;
19 19
20/*
21 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
22 * more than one entry in the evlist.
23 */
24struct perf_sample_id {
25 struct hlist_node node;
26 u64 id;
27 struct evsel *evsel;
28 /*
29 * 'idx' will be used for AUX area sampling. A sample will have AUX area
30 * data that will be queued for decoding, where there are separate
31 * queues for each CPU (per-cpu tracing) or task (per-thread tracing).
32 * The sample ID can be used to lookup 'idx' which is effectively the
33 * queue number.
34 */
35 int idx;
36 int cpu;
37 pid_t tid;
38
39 /* Holds total ID period value for PERF_SAMPLE_READ processing. */
40 u64 period;
41};
42
43struct cgroup; 20struct cgroup;
44 21
45/* 22/*
@@ -272,8 +249,6 @@ const char *perf_evsel__name(struct evsel *evsel);
272const char *perf_evsel__group_name(struct evsel *evsel); 249const char *perf_evsel__group_name(struct evsel *evsel);
273int perf_evsel__group_desc(struct evsel *evsel, char *buf, size_t size); 250int perf_evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
274 251
275int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads);
276
277void __perf_evsel__set_sample_bit(struct evsel *evsel, 252void __perf_evsel__set_sample_bit(struct evsel *evsel,
278 enum perf_event_sample_format bit); 253 enum perf_event_sample_format bit);
279void __perf_evsel__reset_sample_bit(struct evsel *evsel, 254void __perf_evsel__reset_sample_bit(struct evsel *evsel,
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 498f6a825656..fc5eac41e102 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3609,7 +3609,7 @@ int perf_session__read_header(struct perf_session *session)
3609 * for allocating the perf_sample_id table we fake 1 cpu and 3609 * for allocating the perf_sample_id table we fake 1 cpu and
3610 * hattr->ids threads. 3610 * hattr->ids threads.
3611 */ 3611 */
3612 if (perf_evsel__alloc_id(evsel, 1, nr_ids)) 3612 if (perf_evsel__alloc_id(&evsel->core, 1, nr_ids))
3613 goto out_delete_evlist; 3613 goto out_delete_evlist;
3614 3614
3615 lseek(fd, f_attr.ids.offset, SEEK_SET); 3615 lseek(fd, f_attr.ids.offset, SEEK_SET);
@@ -3750,7 +3750,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused,
3750 * for allocating the perf_sample_id table we fake 1 cpu and 3750 * for allocating the perf_sample_id table we fake 1 cpu and
3751 * hattr->ids threads. 3751 * hattr->ids threads.
3752 */ 3752 */
3753 if (perf_evsel__alloc_id(evsel, 1, n_ids)) 3753 if (perf_evsel__alloc_id(&evsel->core, 1, n_ids))
3754 return -ENOMEM; 3754 return -ENOMEM;
3755 3755
3756 for (i = 0; i < n_ids; i++) { 3756 for (i = 0; i < n_ids; i++) {
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a621c73bad42..84a30ff3968a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1324,6 +1324,7 @@ static int deliver_sample_value(struct evlist *evlist,
1324 struct machine *machine) 1324 struct machine *machine)
1325{ 1325{
1326 struct perf_sample_id *sid = perf_evlist__id2sid(evlist, v->id); 1326 struct perf_sample_id *sid = perf_evlist__id2sid(evlist, v->id);
1327 struct evsel *evsel;
1327 1328
1328 if (sid) { 1329 if (sid) {
1329 sample->id = v->id; 1330 sample->id = v->id;
@@ -1343,7 +1344,8 @@ static int deliver_sample_value(struct evlist *evlist,
1343 if (!sample->period) 1344 if (!sample->period)
1344 return 0; 1345 return 0;
1345 1346
1346 return tool->sample(tool, event, sample, sid->evsel, machine); 1347 evsel = container_of(sid->evsel, struct evsel, core);
1348 return tool->sample(tool, event, sample, evsel, machine);
1347} 1349}
1348 1350
1349static int deliver_sample_group(struct evlist *evlist, 1351static int deliver_sample_group(struct evlist *evlist,