diff options
author | Jiri Olsa <jolsa@kernel.org> | 2019-09-03 05:01:04 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-09-25 08:51:48 -0400 |
commit | b0031c22819ab606a0cb648c0f0a7d80db3c3a89 (patch) | |
tree | 0ca1492189ab6d76d6ddb62a0f02b5c37329cec4 | |
parent | ff47d86a0d9bf618b185b49cb4bb9c6f957bb445 (diff) |
libperf: Add perf_evlist__id_add() function
Add the perf_evlist__id_add() function to libperf as an internal
function. We already have the 'heads' member in 'struct perf_evlist'.
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-31-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/lib/evlist.c | 26 | ||||
-rw-r--r-- | tools/perf/lib/include/internal/evlist.h | 4 | ||||
-rw-r--r-- | tools/perf/tests/event_update.c | 2 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 22 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 2 | ||||
-rw-r--r-- | tools/perf/util/header.c | 4 |
6 files changed, 34 insertions, 26 deletions
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index ae861bf38976..a29ee8a746d9 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c | |||
@@ -1,9 +1,12 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | #include <perf/evlist.h> | 2 | #include <perf/evlist.h> |
3 | #include <perf/evsel.h> | 3 | #include <perf/evsel.h> |
4 | #include <linux/bitops.h> | ||
4 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/hash.h> | ||
5 | #include <internal/evlist.h> | 7 | #include <internal/evlist.h> |
6 | #include <internal/evsel.h> | 8 | #include <internal/evsel.h> |
9 | #include <internal/xyarray.h> | ||
7 | #include <linux/zalloc.h> | 10 | #include <linux/zalloc.h> |
8 | #include <stdlib.h> | 11 | #include <stdlib.h> |
9 | #include <perf/cpumap.h> | 12 | #include <perf/cpumap.h> |
@@ -168,3 +171,26 @@ u64 perf_evlist__read_format(struct perf_evlist *evlist) | |||
168 | 171 | ||
169 | return first->attr.read_format; | 172 | return first->attr.read_format; |
170 | } | 173 | } |
174 | |||
175 | #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) | ||
176 | |||
177 | static void perf_evlist__id_hash(struct perf_evlist *evlist, | ||
178 | struct perf_evsel *evsel, | ||
179 | int cpu, int thread, u64 id) | ||
180 | { | ||
181 | int hash; | ||
182 | struct perf_sample_id *sid = SID(evsel, cpu, thread); | ||
183 | |||
184 | sid->id = id; | ||
185 | sid->evsel = evsel; | ||
186 | hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS); | ||
187 | hlist_add_head(&sid->node, &evlist->heads[hash]); | ||
188 | } | ||
189 | |||
190 | void perf_evlist__id_add(struct perf_evlist *evlist, | ||
191 | struct perf_evsel *evsel, | ||
192 | int cpu, int thread, u64 id) | ||
193 | { | ||
194 | perf_evlist__id_hash(evlist, evsel, cpu, thread, id); | ||
195 | evsel->id[evsel->ids++] = id; | ||
196 | } | ||
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h index 63516fe14f4c..649406f717bc 100644 --- a/tools/perf/lib/include/internal/evlist.h +++ b/tools/perf/lib/include/internal/evlist.h | |||
@@ -68,4 +68,8 @@ static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist) | |||
68 | 68 | ||
69 | u64 perf_evlist__read_format(struct perf_evlist *evlist); | 69 | u64 perf_evlist__read_format(struct perf_evlist *evlist); |
70 | 70 | ||
71 | void perf_evlist__id_add(struct perf_evlist *evlist, | ||
72 | struct perf_evsel *evsel, | ||
73 | int cpu, int thread, u64 id); | ||
74 | |||
71 | #endif /* __LIBPERF_INTERNAL_EVLIST_H */ | 75 | #endif /* __LIBPERF_INTERNAL_EVLIST_H */ |
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c index cd6cae8e5137..c727379cf20e 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c | |||
@@ -97,7 +97,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu | |||
97 | TEST_ASSERT_VAL("failed to allocate ids", | 97 | TEST_ASSERT_VAL("failed to allocate ids", |
98 | !perf_evsel__alloc_id(&evsel->core, 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->core, &evsel->core, 0, 0, 123); |
101 | 101 | ||
102 | evsel->unit = strdup("KRAVA"); | 102 | evsel->unit = strdup("KRAVA"); |
103 | 103 | ||
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index bc788192493f..f2863b4c61d7 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -461,26 +461,6 @@ int perf_evlist__poll(struct evlist *evlist, int timeout) | |||
461 | return fdarray__poll(&evlist->core.pollfd, timeout); | 461 | return fdarray__poll(&evlist->core.pollfd, timeout); |
462 | } | 462 | } |
463 | 463 | ||
464 | static void perf_evlist__id_hash(struct evlist *evlist, | ||
465 | struct evsel *evsel, | ||
466 | int cpu, int thread, u64 id) | ||
467 | { | ||
468 | int hash; | ||
469 | struct perf_sample_id *sid = SID(evsel, cpu, thread); | ||
470 | |||
471 | sid->id = id; | ||
472 | sid->evsel = &evsel->core; | ||
473 | hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS); | ||
474 | hlist_add_head(&sid->node, &evlist->core.heads[hash]); | ||
475 | } | ||
476 | |||
477 | void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel, | ||
478 | int cpu, int thread, u64 id) | ||
479 | { | ||
480 | perf_evlist__id_hash(evlist, evsel, cpu, thread, id); | ||
481 | evsel->core.id[evsel->core.ids++] = id; | ||
482 | } | ||
483 | |||
484 | int perf_evlist__id_add_fd(struct evlist *evlist, | 464 | int perf_evlist__id_add_fd(struct evlist *evlist, |
485 | struct evsel *evsel, | 465 | struct evsel *evsel, |
486 | int cpu, int thread, int fd) | 466 | int cpu, int thread, int fd) |
@@ -518,7 +498,7 @@ int perf_evlist__id_add_fd(struct evlist *evlist, | |||
518 | id = read_data[id_idx]; | 498 | id = read_data[id_idx]; |
519 | 499 | ||
520 | add: | 500 | add: |
521 | perf_evlist__id_add(evlist, evsel, cpu, thread, id); | 501 | perf_evlist__id_add(&evlist->core, &evsel->core, cpu, thread, id); |
522 | return 0; | 502 | return 0; |
523 | } | 503 | } |
524 | 504 | ||
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 3f89d9913a30..eb35b4b1d86f 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -141,8 +141,6 @@ struct evsel * | |||
141 | perf_evlist__find_tracepoint_by_name(struct evlist *evlist, | 141 | perf_evlist__find_tracepoint_by_name(struct evlist *evlist, |
142 | const char *name); | 142 | const char *name); |
143 | 143 | ||
144 | void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel, | ||
145 | int cpu, int thread, u64 id); | ||
146 | int perf_evlist__id_add_fd(struct evlist *evlist, | 144 | int perf_evlist__id_add_fd(struct evlist *evlist, |
147 | struct evsel *evsel, | 145 | struct evsel *evsel, |
148 | int cpu, int thread, int fd); | 146 | int cpu, int thread, int fd); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index fc5eac41e102..02602bc8cabf 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -3618,7 +3618,7 @@ int perf_session__read_header(struct perf_session *session) | |||
3618 | if (perf_header__getbuffer64(header, fd, &f_id, sizeof(f_id))) | 3618 | if (perf_header__getbuffer64(header, fd, &f_id, sizeof(f_id))) |
3619 | goto out_errno; | 3619 | goto out_errno; |
3620 | 3620 | ||
3621 | perf_evlist__id_add(session->evlist, evsel, 0, j, f_id); | 3621 | perf_evlist__id_add(&session->evlist->core, &evsel->core, 0, j, f_id); |
3622 | } | 3622 | } |
3623 | 3623 | ||
3624 | lseek(fd, tmp, SEEK_SET); | 3624 | lseek(fd, tmp, SEEK_SET); |
@@ -3754,7 +3754,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused, | |||
3754 | return -ENOMEM; | 3754 | return -ENOMEM; |
3755 | 3755 | ||
3756 | for (i = 0; i < n_ids; i++) { | 3756 | for (i = 0; i < n_ids; i++) { |
3757 | perf_evlist__id_add(evlist, evsel, 0, i, event->attr.id[i]); | 3757 | perf_evlist__id_add(&evlist->core, &evsel->core, 0, i, event->attr.id[i]); |
3758 | } | 3758 | } |
3759 | 3759 | ||
3760 | return 0; | 3760 | return 0; |