hi,
sending changes for exporting basic sampling interface
in libperf. It's now possible to use following code in
applications via libperf:
--- (example is without error checks for simplicity)
struct perf_event_attr attr = {
.type = PERF_TYPE_TRACEPOINT,
.sample_period = 1,
.wakeup_watermark = 1,
.disabled = 1,
};
/* ... setup attr */
cpus = perf_cpu_map__new(NULL);
evlist = perf_evlist__new();
evsel = perf_evsel__new(&attr);
perf_evlist__add(evlist, evsel);
perf_evlist__set_maps(evlist, cpus, NULL);
err = perf_evlist__open(evlist);
err = perf_evlist__mmap(evlist, 4);
err = perf_evlist__enable(evlist);
/* ... monitored area, plus all the other cpus */
err = perf_evlist__disable(evlist);
perf_evlist__for_each_mmap(evlist, map) {
if (perf_mmap__read_init(map) < 0)
continue;
while ((event = perf_mmap__read_event(map)) != NULL) {
perf_mmap__consume(map);
}
perf_mmap__read_done(map);
}
perf_evlist__delete(evlist);
perf_cpu_map__put(cpus);
--- (end)
Nothing is carved in stone so far, the interface is exported
as is available in perf now and we can change it as we want.
New tests are added in test-evlist.c to do thread and cpu based
sampling.
All the functionality should not change, however there's considerable
mmap code rewrite, so would be great if guys could run your usual
workloads to see if all is fine.. so far so good in my tests ;-)
It's also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/lib
thanks,
jirka
Cc: Kan Liang <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Alexey Budankov <[email protected]>
Cc: Andi Kleen <[email protected]>
---
Jiri Olsa (73):
tools: Add missing stdio.h include to asm/bug.h header
perf tests: Fix static build test
perf tools: Rename struct perf_mmap to struct mmap
perf tools: Rename perf_evlist__mmap() to evlist__mmap()
perf tools: Rename perf_evlist__munmap() to evlist__munmap()
perf tools: Rename perf_evlist__alloc_mmap() to evlist__alloc_mmap()
perf tools: Rename perf_evlist__exit() to evlist__exit()
perf tools: Rename perf_evlist__purge() to evlist__purge()
libperf: Link libapi.a in libperf.so
libperf: Add perf_mmap struct
libperf: Add mask to struct perf_mmap
libperf: Add fd to struct perf_mmap
libperf: Add cpu to struct perf_mmap
libperf: Add refcnt to struct perf_mmap
libperf: Add prev/start/end to struct perf_mmap
libperf: Add overwrite to struct perf_mmap
libperf: Add event_copy to struct perf_mmap
libperf: Add flush to struct perf_mmap
libperf: Move system_wide from struct evsel to struct perf_evsel
libperf: Move nr_mmaps from struct evlist to struct perf_evlist
libperf: Move mmap_len from struct evlist to struct perf_evlist
libperf: Move pollfd from struct evlist to struct perf_evlist
libperf: Move sample_id from struct evsel to struct perf_evsel
libperf: Move id from struct evsel to struct perf_evsel
libperf: Move ids from struct evsel to struct perf_evsel
libperf: Move heads from struct evlist to struct perf_evlist
libperf: Add perf_evsel__alloc_id/perf_evsel__free_id functions
libperf: Add perf_evlist__first/last functions
libperf: Add perf_evlist__read_format function
libperf: Add perf_evlist__id_add function
libperf: Add perf_evlist__id_add_fd function
libperf: Move page_size into libperf
libperf: Merge libperf_set_print in libperf_init
libperf: Add libperf_init call to tests
libperf: Add libperf dependency for tests targets
libperf: Add perf_evlist__alloc_pollfd function
libperf: Add perf_evlist__add_pollfd function
libperf: Add perf_evlist__poll function
libperf: Add perf_mmap__init function
libperf: Add struct perf_mmap_param
libperf: Add perf_mmap__mmap_len function
libperf: Add perf_mmap__mmap function
libperf: Add perf_mmap__get function
libperf: Add perf_mmap__unmap function
libperf: Add perf_mmap__put function
libperf: Add perf_mmap__new function
perf tools: Use perf_mmap way to detect aux mmap
libperf: Add perf_mmap__consume function
libperf: Add perf_mmap__read_init function
libperf: Add perf_mmap__read_done function
libperf: Add perf_mmap__read_event function
libperf: Add perf_evlist__mmap/munmap function
libperf: Add perf_evlist__mmap_ops function
libperf: Add perf_evlist_mmap_ops::idx callback
libperf: Add perf_evlist_mmap_ops::new callback
libperf: Add perf_evlist_mmap_ops::mmap callback
perf tools: Add perf_evlist__mmap_cb_idx function
perf tools: Add perf_evlist__mmap_cb_new function
perf tools: Add perf_evlist__mmap_cb_mmap function
perf tools: Switch to libperf mmap interface
libperf: Move pollfd allocation to libperf
libperf: Add perf_evlist__exit function
libperf: Add perf_evlist__purge function
libperf: Call perf_evlist__munmap/close on perf_evlist__delete
libperf: Add perf_evlist__filter_pollfd function
libperf: Add perf_evlist__for_each_mmap function
libperf: Link static tests with libapi.a
libperf: Add _GNU_SOURCE define to compilation
libperf: Add tests_mmap_thread test
libperf: Add tests_mmap_cpus test
libperf: Keep count of failed tests
libperf: Do not export perf_evsel__init/perf_evlist__init
libperf: Add pr_err macro
tools/include/asm/bug.h | 1 +
tools/perf/arch/arm/util/cs-etm.c | 4 +-
tools/perf/arch/arm64/util/arm-spe.c | 4 +-
tools/perf/arch/x86/tests/intel-cqm.c | 4 +-
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 19 +-
tools/perf/arch/x86/util/intel-bts.c | 6 +-
tools/perf/arch/x86/util/intel-pt.c | 14 +-
tools/perf/builtin-kvm.c | 23 +-
tools/perf/builtin-record.c | 90 ++---
tools/perf/builtin-script.c | 4 +-
tools/perf/builtin-stat.c | 6 +-
tools/perf/builtin-top.c | 29 +-
tools/perf/builtin-trace.c | 21 +-
tools/perf/lib/Build | 1 +
tools/perf/lib/Makefile | 42 ++-
tools/perf/lib/core.c | 13 +-
tools/perf/lib/evlist.c | 440 +++++++++++++++++++++++++
tools/perf/lib/evsel.c | 30 ++
tools/perf/lib/include/internal/evlist.h | 74 +++++
tools/perf/lib/include/internal/evsel.h | 32 ++
tools/perf/lib/include/internal/lib.h | 2 +
tools/perf/lib/include/internal/mmap.h | 59 ++++
tools/perf/lib/include/internal/tests.h | 20 +-
tools/perf/lib/include/perf/core.h | 5 +-
tools/perf/lib/include/perf/evlist.h | 14 +-
tools/perf/lib/include/perf/evsel.h | 2 -
tools/perf/lib/include/perf/mmap.h | 14 +
tools/perf/lib/internal.h | 5 +
tools/perf/lib/lib.c | 2 +
tools/perf/lib/libperf.map | 13 +-
tools/perf/lib/mmap.c | 289 +++++++++++++++++
tools/perf/lib/tests/Makefile | 8 +-
tools/perf/lib/tests/test-cpumap.c | 10 +-
tools/perf/lib/tests/test-evlist.c | 228 ++++++++++++-
tools/perf/lib/tests/test-evsel.c | 10 +-
tools/perf/lib/tests/test-threadmap.c | 10 +-
tools/perf/perf.c | 10 +-
tools/perf/tests/backward-ring-buffer.c | 17 +-
tools/perf/tests/bpf.c | 15 +-
tools/perf/tests/code-reading.c | 19 +-
tools/perf/tests/event-times.c | 14 +-
tools/perf/tests/event_update.c | 6 +-
tools/perf/tests/evsel-roundtrip-name.c | 2 +-
tools/perf/tests/hists_cumulate.c | 2 +-
tools/perf/tests/hists_link.c | 4 +-
tools/perf/tests/hists_output.c | 2 +-
tools/perf/tests/keep-tracking.c | 19 +-
tools/perf/tests/make | 2 +-
tools/perf/tests/mmap-basic.c | 13 +-
tools/perf/tests/openat-syscall-tp-fields.c | 19 +-
tools/perf/tests/parse-events.c | 116 +++----
tools/perf/tests/perf-record.c | 21 +-
tools/perf/tests/sw-clock.c | 13 +-
tools/perf/tests/switch-tracking.c | 37 ++-
tools/perf/tests/task-exit.c | 17 +-
tools/perf/ui/browsers/hists.c | 6 +-
tools/perf/util/auxtrace.c | 6 +-
tools/perf/util/auxtrace.h | 8 +-
tools/perf/util/bpf-loader.c | 2 +-
tools/perf/util/evlist.c | 469 +++++++--------------------
tools/perf/util/evlist.h | 50 ++-
tools/perf/util/evsel.c | 44 +--
tools/perf/util/evsel.h | 29 --
tools/perf/util/header.c | 38 +--
tools/perf/util/intel-bts.c | 4 +-
tools/perf/util/intel-pt.c | 10 +-
tools/perf/util/jitdump.c | 2 +-
tools/perf/util/mmap.c | 309 +++---------------
tools/perf/util/mmap.h | 51 +--
tools/perf/util/parse-events.c | 6 +-
tools/perf/util/python.c | 29 +-
tools/perf/util/record.c | 6 +-
tools/perf/util/session.c | 10 +-
tools/perf/util/sort.c | 2 +-
tools/perf/util/stat.c | 2 +-
tools/perf/util/top.c | 2 +-
tools/perf/util/util.h | 2 -
77 files changed, 1862 insertions(+), 1121 deletions(-)
create mode 100644 tools/perf/lib/include/internal/mmap.h
create mode 100644 tools/perf/lib/include/perf/mmap.h
create mode 100644 tools/perf/lib/mmap.c
Disable the potential shared library features/libraries,
which breaks static build if they are enabled and detected:
jvmti and vdso libraries.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/tests/make | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 6b3afed5d910..c850d1664c56 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -100,7 +100,7 @@ make_install_info := install-info
make_install_pdf := install-pdf
make_install_prefix := install prefix=/tmp/krava
make_install_prefix_slash := install prefix=/tmp/krava/
-make_static := LDFLAGS=-static
+make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1
# all the NO_* variable combined
make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
--
2.21.0
Rename perf_evlist__munmap() to evlist__munmap(), so we don't have a
name clash when we add perf_evlist__munmap() in libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/tests/backward-ring-buffer.c | 2 +-
tools/perf/util/evlist.c | 12 ++++++------
tools/perf/util/evlist.h | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index f1eb7e9c1d7d..3073a68d17b9 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -75,7 +75,7 @@ static int do_test(struct evlist *evlist, int mmap_pages,
evlist__disable(evlist);
err = count_samples(evlist, sample_count, comm_count);
- perf_evlist__munmap(evlist);
+ evlist__munmap(evlist);
return err;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 5ca726c15cce..cc11b1a22042 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -149,7 +149,7 @@ void evlist__delete(struct evlist *evlist)
if (evlist == NULL)
return;
- perf_evlist__munmap(evlist);
+ evlist__munmap(evlist);
evlist__close(evlist);
perf_cpu_map__put(evlist->core.cpus);
perf_thread_map__put(evlist->core.threads);
@@ -673,7 +673,7 @@ static int perf_evlist__resume(struct evlist *evlist)
return perf_evlist__set_paused(evlist, false);
}
-static void perf_evlist__munmap_nofree(struct evlist *evlist)
+static void evlist__munmap_nofree(struct evlist *evlist)
{
int i;
@@ -686,9 +686,9 @@ static void perf_evlist__munmap_nofree(struct evlist *evlist)
perf_mmap__munmap(&evlist->overwrite_mmap[i]);
}
-void perf_evlist__munmap(struct evlist *evlist)
+void evlist__munmap(struct evlist *evlist)
{
- perf_evlist__munmap_nofree(evlist);
+ evlist__munmap_nofree(evlist);
zfree(&evlist->mmap);
zfree(&evlist->overwrite_mmap);
}
@@ -835,7 +835,7 @@ static int evlist__mmap_per_cpu(struct evlist *evlist,
return 0;
out_unmap:
- perf_evlist__munmap_nofree(evlist);
+ evlist__munmap_nofree(evlist);
return -1;
}
@@ -861,7 +861,7 @@ static int evlist__mmap_per_thread(struct evlist *evlist,
return 0;
out_unmap:
- perf_evlist__munmap_nofree(evlist);
+ evlist__munmap_nofree(evlist);
return -1;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index aaf06182c1b8..f07501602353 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -175,7 +175,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
bool auxtrace_overwrite, int nr_cblocks,
int affinity, int flush, int comp_level);
int evlist__mmap(struct evlist *evlist, unsigned int pages);
-void perf_evlist__munmap(struct evlist *evlist);
+void evlist__munmap(struct evlist *evlist);
size_t evlist__mmap_size(unsigned long pages);
--
2.21.0
Rename perf_evlist__mmap() to evlist__mmap(), so we don't have a
name clash when we add perf_evlist__mmap() in libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-record.c | 6 ++--
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/tests/backward-ring-buffer.c | 4 +--
tools/perf/tests/bpf.c | 4 +--
tools/perf/tests/code-reading.c | 4 +--
tools/perf/tests/keep-tracking.c | 2 +-
tools/perf/tests/mmap-basic.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 4 +--
tools/perf/tests/perf-record.c | 4 +--
tools/perf/tests/sw-clock.c | 2 +-
tools/perf/tests/switch-tracking.c | 4 +--
tools/perf/tests/task-exit.c | 2 +-
tools/perf/util/evlist.c | 30 ++++++++++----------
tools/perf/util/evlist.h | 8 +++---
tools/perf/util/python.c | 2 +-
18 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 181e76dc597a..3644ebd45a46 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -91,7 +91,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
CHECK__(evlist__open(evlist));
- CHECK__(perf_evlist__mmap(evlist, UINT_MAX));
+ CHECK__(evlist__mmap(evlist, UINT_MAX));
pc = evlist->mmap[0].base;
ret = perf_read_tsc_conversion(pc, &tc);
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index cb40c5c38b44..da16349f2808 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1058,7 +1058,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
goto out;
}
- if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages) < 0) {
+ if (evlist__mmap(evlist, kvm->opts.mmap_pages) < 0) {
ui__error("Failed to mmap the events: %s\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
evlist__close(evlist);
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 949ea29fae66..df16e1ca1f36 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -437,7 +437,7 @@ static int record__mmap_flush_parse(const struct option *opt,
if (!opts->mmap_flush)
opts->mmap_flush = MMAP_FLUSH_DEFAULT;
- flush_max = perf_evlist__mmap_size(opts->mmap_pages);
+ flush_max = evlist__mmap_size(opts->mmap_pages);
flush_max /= 4;
if (opts->mmap_flush > flush_max)
opts->mmap_flush = flush_max;
@@ -705,7 +705,7 @@ static int record__mmap_evlist(struct record *rec,
if (opts->affinity != PERF_AFFINITY_SYS)
cpu__setup_cpunode_map();
- if (perf_evlist__mmap_ex(evlist, opts->mmap_pages,
+ if (evlist__mmap_ex(evlist, opts->mmap_pages,
opts->auxtrace_mmap_pages,
opts->auxtrace_snapshot_mode,
opts->nr_cblocks, opts->affinity,
@@ -1976,7 +1976,7 @@ static int record__parse_mmap_pages(const struct option *opt,
static void switch_output_size_warn(struct record *rec)
{
- u64 wakeup_size = perf_evlist__mmap_size(rec->opts.mmap_pages);
+ u64 wakeup_size = evlist__mmap_size(rec->opts.mmap_pages);
struct switch_output *s = &rec->switch_output;
wakeup_size /= 2;
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5802ca9ca849..9adc91d06e16 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1040,7 +1040,7 @@ static int perf_top__start_counters(struct perf_top *top)
}
}
- if (perf_evlist__mmap(evlist, opts->mmap_pages) < 0) {
+ if (evlist__mmap(evlist, opts->mmap_pages) < 0) {
ui__error("Failed to mmap with %d (%s)\n",
errno, str_error_r(errno, msg, sizeof(msg)));
goto out_err;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index fa813187fb0d..c2e842a6467b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3408,7 +3408,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (trace->dump.map)
bpf_map__fprintf(trace->dump.map, trace->output);
- err = perf_evlist__mmap(evlist, trace->opts.mmap_pages);
+ err = evlist__mmap(evlist, trace->opts.mmap_pages);
if (err < 0)
goto out_error_mmap;
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 0a046096e6f4..f1eb7e9c1d7d 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -63,9 +63,9 @@ static int do_test(struct evlist *evlist, int mmap_pages,
int err;
char sbuf[STRERR_BUFSIZE];
- err = perf_evlist__mmap(evlist, mmap_pages);
+ err = evlist__mmap(evlist, mmap_pages);
if (err < 0) {
- pr_debug("perf_evlist__mmap: %s\n",
+ pr_debug("evlist__mmap: %s\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
return TEST_FAIL;
}
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index cf9776aceb82..964731915498 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -167,9 +167,9 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
goto out_delete_evlist;
}
- err = perf_evlist__mmap(evlist, opts.mmap_pages);
+ err = evlist__mmap(evlist, opts.mmap_pages);
if (err < 0) {
- pr_debug("perf_evlist__mmap: %s\n",
+ pr_debug("evlist__mmap: %s\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 1e755c4f066d..2c2400d93813 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -685,9 +685,9 @@ static int do_test_code_reading(bool try_kcore)
break;
}
- ret = perf_evlist__mmap(evlist, UINT_MAX);
+ ret = evlist__mmap(evlist, UINT_MAX);
if (ret < 0) {
- pr_debug("perf_evlist__mmap failed\n");
+ pr_debug("evlist__mmap failed\n");
goto out_put;
}
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 0c10d992d815..ba77eaa215b3 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -105,7 +105,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un
goto out_err;
}
- CHECK__(perf_evlist__mmap(evlist, UINT_MAX));
+ CHECK__(evlist__mmap(evlist, UINT_MAX));
/*
* First, test that a 'comm' event can be found when the event is
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 1bca796ac2bd..9b3b11702850 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -100,7 +100,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
expected_nr_events[i] = 1 + rand() % 127;
}
- if (perf_evlist__mmap(evlist, 128) < 0) {
+ if (evlist__mmap(evlist, 128) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno,
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index e5ef74d4e925..5c2576174ae9 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -69,9 +69,9 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
goto out_delete_evlist;
}
- err = perf_evlist__mmap(evlist, UINT_MAX);
+ err = evlist__mmap(evlist, UINT_MAX);
if (err < 0) {
- pr_debug("perf_evlist__mmap: %s\n",
+ pr_debug("evlist__mmap: %s\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 49d2d4c5956d..669fd88e7f30 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -143,9 +143,9 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
* fds in the same CPU to be injected in the same mmap ring buffer
* (using ioctl(PERF_EVENT_IOC_SET_OUTPUT)).
*/
- err = perf_evlist__mmap(evlist, opts.mmap_pages);
+ err = evlist__mmap(evlist, opts.mmap_pages);
if (err < 0) {
- pr_debug("perf_evlist__mmap: %s\n",
+ pr_debug("evlist__mmap: %s\n",
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
}
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 7abe0b6aabb7..fbff60815be8 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -82,7 +82,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
goto out_delete_evlist;
}
- err = perf_evlist__mmap(evlist, 128);
+ err = evlist__mmap(evlist, 128);
if (err < 0) {
pr_debug("failed to mmap event: %d (%s)\n", errno,
str_error_r(errno, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 8374979ceb22..f6c2c026988a 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -461,9 +461,9 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out;
}
- err = perf_evlist__mmap(evlist, UINT_MAX);
+ err = evlist__mmap(evlist, UINT_MAX);
if (err) {
- pr_debug("perf_evlist__mmap failed!\n");
+ pr_debug("evlist__mmap failed!\n");
goto out_err;
}
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index c7e87c588c25..76c1a8417da9 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -106,7 +106,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
goto out_delete_evlist;
}
- if (perf_evlist__mmap(evlist, 128) < 0) {
+ if (evlist__mmap(evlist, 128) < 0) {
pr_debug("failed to mmap events: %d (%s)\n", errno,
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_delete_evlist;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 9a5c90392951..5ca726c15cce 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -732,7 +732,7 @@ perf_evlist__should_poll(struct evlist *evlist __maybe_unused,
return true;
}
-static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
+static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
struct mmap_params *mp, int cpu_idx,
int thread, int *_output, int *_output_overwrite)
{
@@ -810,7 +810,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
return 0;
}
-static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
+static int evlist__mmap_per_cpu(struct evlist *evlist,
struct mmap_params *mp)
{
int cpu, thread;
@@ -826,7 +826,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
true);
for (thread = 0; thread < nr_threads; thread++) {
- if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
+ if (evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
thread, &output, &output_overwrite))
goto out_unmap;
}
@@ -839,7 +839,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
return -1;
}
-static int perf_evlist__mmap_per_thread(struct evlist *evlist,
+static int evlist__mmap_per_thread(struct evlist *evlist,
struct mmap_params *mp)
{
int thread;
@@ -853,7 +853,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist,
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
false);
- if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
+ if (evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
&output, &output_overwrite))
goto out_unmap;
}
@@ -888,7 +888,7 @@ unsigned long perf_event_mlock_kb_in_pages(void)
return pages;
}
-size_t perf_evlist__mmap_size(unsigned long pages)
+size_t evlist__mmap_size(unsigned long pages)
{
if (pages == UINT_MAX)
pages = perf_event_mlock_kb_in_pages();
@@ -971,7 +971,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
}
/**
- * perf_evlist__mmap_ex - Create mmaps to receive events.
+ * evlist__mmap_ex - Create mmaps to receive events.
* @evlist: list of events
* @pages: map length in pages
* @overwrite: overwrite older events?
@@ -979,7 +979,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
* @auxtrace_overwrite - overwrite older auxtrace data?
*
* If @overwrite is %false the user needs to signal event consumption using
- * perf_mmap__write_tail(). Using perf_evlist__mmap_read() does this
+ * perf_mmap__write_tail(). Using evlist__mmap_read() does this
* automatically.
*
* Similarly, if @auxtrace_overwrite is %false the user needs to signal data
@@ -987,7 +987,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
*
* Return: %0 on success, negative error code otherwise.
*/
-int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
+int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
unsigned int auxtrace_pages,
bool auxtrace_overwrite, int nr_cblocks, int affinity, int flush,
int comp_level)
@@ -1011,7 +1011,7 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
return -ENOMEM;
- evlist->mmap_len = perf_evlist__mmap_size(pages);
+ evlist->mmap_len = evlist__mmap_size(pages);
pr_debug("mmap size %zuB\n", evlist->mmap_len);
mp.mask = evlist->mmap_len - page_size - 1;
@@ -1026,14 +1026,14 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
}
if (perf_cpu_map__empty(cpus))
- return perf_evlist__mmap_per_thread(evlist, &mp);
+ return evlist__mmap_per_thread(evlist, &mp);
- return perf_evlist__mmap_per_cpu(evlist, &mp);
+ return evlist__mmap_per_cpu(evlist, &mp);
}
-int perf_evlist__mmap(struct evlist *evlist, unsigned int pages)
+int evlist__mmap(struct evlist *evlist, unsigned int pages)
{
- return perf_evlist__mmap_ex(evlist, pages, 0, false, 0, PERF_AFFINITY_SYS, 1, 0);
+ return evlist__mmap_ex(evlist, pages, 0, false, 0, PERF_AFFINITY_SYS, 1, 0);
}
int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
@@ -1889,7 +1889,7 @@ int perf_evlist__start_sb_thread(struct evlist *evlist,
goto out_delete_evlist;
}
- if (perf_evlist__mmap(evlist, UINT_MAX))
+ if (evlist__mmap(evlist, UINT_MAX))
goto out_delete_evlist;
evlist__for_each_entry(evlist, counter) {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 129786361572..aaf06182c1b8 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -139,7 +139,7 @@ struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
-void perf_evlist__mmap_consume(struct evlist *evlist, int idx);
+void evlist__mmap_consume(struct evlist *evlist, int idx);
int evlist__open(struct evlist *evlist);
void evlist__close(struct evlist *evlist);
@@ -170,14 +170,14 @@ int perf_evlist__parse_mmap_pages(const struct option *opt,
unsigned long perf_event_mlock_kb_in_pages(void);
-int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
+int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
unsigned int auxtrace_pages,
bool auxtrace_overwrite, int nr_cblocks,
int affinity, int flush, int comp_level);
-int perf_evlist__mmap(struct evlist *evlist, unsigned int pages);
+int evlist__mmap(struct evlist *evlist, unsigned int pages);
void perf_evlist__munmap(struct evlist *evlist);
-size_t perf_evlist__mmap_size(unsigned long pages);
+size_t evlist__mmap_size(unsigned long pages);
void evlist__disable(struct evlist *evlist);
void evlist__enable(struct evlist *evlist);
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e22013b08337..9b0eaf83212f 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -899,7 +899,7 @@ static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist,
&pages, &overwrite))
return NULL;
- if (perf_evlist__mmap(evlist, pages) < 0) {
+ if (evlist__mmap(evlist, pages) < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
--
2.21.0
Rename (perf_evlist__purge) to evlist__purge(), so we don't have a
name clash when we add (perf_evlist__purge) in libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d71fafd472ea..ac738b90a71f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -124,7 +124,7 @@ static void perf_evlist__update_id_pos(struct evlist *evlist)
perf_evlist__set_id_pos(evlist);
}
-static void perf_evlist__purge(struct evlist *evlist)
+static void evlist__purge(struct evlist *evlist)
{
struct evsel *pos, *n;
@@ -155,7 +155,7 @@ void evlist__delete(struct evlist *evlist)
perf_thread_map__put(evlist->core.threads);
evlist->core.cpus = NULL;
evlist->core.threads = NULL;
- perf_evlist__purge(evlist);
+ evlist__purge(evlist);
evlist__exit(evlist);
free(evlist);
}
--
2.21.0
Move fd from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/util/evlist.c | 4 ++--
tools/perf/util/mmap.c | 4 ++--
tools/perf/util/mmap.h | 1 -
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index a6a464097f14..2cbe2c463c0a 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -15,6 +15,7 @@
struct perf_mmap {
void *base;
int mask;
+ int fd;
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ac738b90a71f..57b117532ade 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -651,7 +651,7 @@ static int perf_evlist__set_paused(struct evlist *evlist, bool value)
return 0;
for (i = 0; i < evlist->nr_mmaps; i++) {
- int fd = evlist->overwrite_mmap[i].fd;
+ int fd = evlist->overwrite_mmap[i].core.fd;
int err;
if (fd < 0)
@@ -707,7 +707,7 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
return NULL;
for (i = 0; i < evlist->nr_mmaps; i++) {
- map[i].fd = -1;
+ map[i].core.fd = -1;
map[i].overwrite = overwrite;
/*
* When the perf_mmap() call is made we grab one refcount, plus
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 702e8e0b90ea..40bf124cb658 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -320,7 +320,7 @@ void perf_mmap__munmap(struct mmap *map)
if (map->core.base != NULL) {
munmap(map->core.base, perf_mmap__mmap_len(map));
map->core.base = NULL;
- map->fd = -1;
+ map->core.fd = -1;
refcount_set(&map->refcnt, 0);
}
auxtrace_mmap__munmap(&map->auxtrace_mmap);
@@ -378,7 +378,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
map->core.base = NULL;
return -1;
}
- map->fd = fd;
+ map->core.fd = fd;
map->cpu = cpu;
perf_mmap__setup_affinity_mask(map, mp);
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index a6e60596f889..6eb7a4c6b14a 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -22,7 +22,6 @@ struct aiocb;
*/
struct mmap {
struct perf_mmap core;
- int fd;
int cpu;
refcount_t refcnt;
u64 prev;
--
2.21.0
Move sample_id array from struct evsel to libperf's struct perf_evsel.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-stat.c | 2 +-
tools/perf/lib/include/internal/evsel.h | 1 +
tools/perf/util/evlist.c | 4 ++--
tools/perf/util/evsel.c | 12 ++++++------
tools/perf/util/evsel.h | 1 -
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 35897048ba53..292fccf8f13c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -233,7 +233,7 @@ static int write_stat_round_event(u64 tm, u64 type)
#define WRITE_STAT_ROUND_EVENT(time, interval) \
write_stat_round_event(time, PERF_STAT_ROUND_TYPE__ ## interval)
-#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
+#define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y)
static int
perf_evsel__write_stat_event(struct evsel *counter, u32 cpu, u32 thread,
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index 220cb2e2b54e..d284825383af 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -15,6 +15,7 @@ struct perf_evsel {
struct perf_cpu_map *own_cpus;
struct perf_thread_map *threads;
struct xyarray *fd;
+ struct xyarray *sample_id;
/* parse modifier helper */
int nr_members;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 8f5b28eefde7..4018f0ff75c8 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -49,7 +49,7 @@ int sigqueue(pid_t pid, int sig, const union sigval value);
#endif
#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
-#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
+#define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y)
void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
struct perf_thread_map *threads)
@@ -1020,7 +1020,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
evlist__for_each_entry(evlist, evsel) {
if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
- evsel->sample_id == NULL &&
+ evsel->core.sample_id == NULL &&
perf_evsel__alloc_id(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
return -ENOMEM;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 9dcee5a8875e..db89f98bb357 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1234,14 +1234,14 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
if (evsel->core.system_wide)
nthreads = 1;
- evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
- if (evsel->sample_id == NULL)
+ evsel->core.sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
+ if (evsel->core.sample_id == NULL)
return -ENOMEM;
evsel->id = zalloc(ncpus * nthreads * sizeof(u64));
if (evsel->id == NULL) {
- xyarray__delete(evsel->sample_id);
- evsel->sample_id = NULL;
+ xyarray__delete(evsel->core.sample_id);
+ evsel->core.sample_id = NULL;
return -ENOMEM;
}
@@ -1250,8 +1250,8 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
static void perf_evsel__free_id(struct evsel *evsel)
{
- xyarray__delete(evsel->sample_id);
- evsel->sample_id = NULL;
+ xyarray__delete(evsel->core.sample_id);
+ evsel->core.sample_id = NULL;
zfree(&evsel->id);
evsel->ids = 0;
}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index eb4d03cd0b17..9934e99e0c64 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -117,7 +117,6 @@ struct evsel {
struct perf_evsel core;
struct evlist *evlist;
char *filter;
- struct xyarray *sample_id;
u64 *id;
struct perf_counts *counts;
struct perf_counts *prev_raw_counts;
--
2.21.0
We need page_size in libperf, so moving it in there.
Adding libperf_init as a global libperf init functon.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/core.c | 7 +++++++
tools/perf/lib/include/internal/lib.h | 2 ++
tools/perf/lib/include/perf/core.h | 1 +
tools/perf/lib/lib.c | 2 ++
tools/perf/lib/libperf.map | 1 +
tools/perf/perf.c | 4 ++--
tools/perf/util/util.h | 2 --
7 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
index 29d5e3348718..6689d593c2d1 100644
--- a/tools/perf/lib/core.c
+++ b/tools/perf/lib/core.c
@@ -4,7 +4,9 @@
#include <stdio.h>
#include <stdarg.h>
+#include <unistd.h>
#include <perf/core.h>
+#include <internal/lib.h>
#include "internal.h"
static int __base_pr(enum libperf_print_level level, const char *format,
@@ -32,3 +34,8 @@ void libperf_print(enum libperf_print_level level, const char *format, ...)
__libperf_pr(level, format, args);
va_end(args);
}
+
+void libperf_init(void)
+{
+ page_size = sysconf(_SC_PAGE_SIZE);
+}
diff --git a/tools/perf/lib/include/internal/lib.h b/tools/perf/lib/include/internal/lib.h
index 0b56f1201dc9..9168b7d2a7e1 100644
--- a/tools/perf/lib/include/internal/lib.h
+++ b/tools/perf/lib/include/internal/lib.h
@@ -4,6 +4,8 @@
#include <unistd.h>
+extern unsigned int page_size;
+
ssize_t readn(int fd, void *buf, size_t n);
ssize_t writen(int fd, const void *buf, size_t n);
diff --git a/tools/perf/lib/include/perf/core.h b/tools/perf/lib/include/perf/core.h
index c341a7b2c874..ba2f4e76a3e2 100644
--- a/tools/perf/lib/include/perf/core.h
+++ b/tools/perf/lib/include/perf/core.h
@@ -18,5 +18,6 @@ typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
const char *, va_list ap);
LIBPERF_API void libperf_set_print(libperf_print_fn_t fn);
+LIBPERF_API void libperf_init(void);
#endif /* __LIBPERF_CORE_H */
diff --git a/tools/perf/lib/lib.c b/tools/perf/lib/lib.c
index 2a81819c3b8c..18658931fc71 100644
--- a/tools/perf/lib/lib.c
+++ b/tools/perf/lib/lib.c
@@ -5,6 +5,8 @@
#include <linux/kernel.h>
#include <internal/lib.h>
+unsigned int page_size;
+
static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
{
void *buf_start = buf;
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index dc4d66363bc4..3fbf050b5add 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -1,5 +1,6 @@
LIBPERF_0.0.1 {
global:
+ libperf_init;
libperf_set_print;
perf_cpu_map__dummy_new;
perf_cpu_map__get;
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 1193b923e801..ead18b712d6c 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -25,6 +25,7 @@
#include "perf-sys.h"
#include <api/fs/fs.h>
#include <api/fs/tracing_path.h>
+#include <internal/lib.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
@@ -438,8 +439,7 @@ int main(int argc, const char **argv)
exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
pager_init(PERF_PAGER_ENVIRONMENT);
- /* The page_size is placed in util object. */
- page_size = sysconf(_SC_PAGE_SIZE);
+ libperf_init();
cmd = extract_argv0_path(argv[0]);
if (!cmd)
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 45a5c6f20197..d6ae394e67c4 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -33,8 +33,6 @@ int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
size_t hex_width(u64 v);
-extern unsigned int page_size;
-
int sysctl__max_stack(void);
int fetch_kernel_version(unsigned int *puint,
--
2.21.0
Adding libperf_init call to automated tests.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/tests/test-cpumap.c | 8 ++++++++
tools/perf/lib/tests/test-evlist.c | 10 ++++++++++
tools/perf/lib/tests/test-evsel.c | 8 ++++++++
tools/perf/lib/tests/test-threadmap.c | 8 ++++++++
4 files changed, 34 insertions(+)
diff --git a/tools/perf/lib/tests/test-cpumap.c b/tools/perf/lib/tests/test-cpumap.c
index 76a43cfb83a1..4224d6f213f8 100644
--- a/tools/perf/lib/tests/test-cpumap.c
+++ b/tools/perf/lib/tests/test-cpumap.c
@@ -2,12 +2,20 @@
#include <perf/cpumap.h>
#include <internal/tests.h>
+static int libperf_print(enum libperf_print_level level,
+ const char *fmt, va_list ap)
+{
+ return vfprintf(stderr, fmt, ap);
+}
+
int main(int argc, char **argv)
{
struct perf_cpu_map *cpus;
__T_START;
+ libperf_init(libperf_print);
+
cpus = perf_cpu_map__dummy_new();
if (!cpus)
return -1;
diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c
index 4e1407f20ffd..e6b2ab2e2bde 100644
--- a/tools/perf/lib/tests/test-evlist.c
+++ b/tools/perf/lib/tests/test-evlist.c
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <stdarg.h>
#include <linux/perf_event.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
@@ -6,6 +8,12 @@
#include <perf/evsel.h>
#include <internal/tests.h>
+static int libperf_print(enum libperf_print_level level,
+ const char *fmt, va_list ap)
+{
+ return vfprintf(stderr, fmt, ap);
+}
+
static int test_stat_cpu(void)
{
struct perf_cpu_map *cpus;
@@ -177,6 +185,8 @@ int main(int argc, char **argv)
{
__T_START;
+ libperf_init(libperf_print);
+
test_stat_cpu();
test_stat_thread();
test_stat_thread_enable();
diff --git a/tools/perf/lib/tests/test-evsel.c b/tools/perf/lib/tests/test-evsel.c
index 2c648fe5617e..64d2257a93cb 100644
--- a/tools/perf/lib/tests/test-evsel.c
+++ b/tools/perf/lib/tests/test-evsel.c
@@ -5,6 +5,12 @@
#include <perf/evsel.h>
#include <internal/tests.h>
+static int libperf_print(enum libperf_print_level level,
+ const char *fmt, va_list ap)
+{
+ return vfprintf(stderr, fmt, ap);
+}
+
static int test_stat_cpu(void)
{
struct perf_cpu_map *cpus;
@@ -116,6 +122,8 @@ int main(int argc, char **argv)
{
__T_START;
+ libperf_init(libperf_print);
+
test_stat_cpu();
test_stat_thread();
test_stat_thread_enable();
diff --git a/tools/perf/lib/tests/test-threadmap.c b/tools/perf/lib/tests/test-threadmap.c
index 10a4f4cbbdd5..9b72c43c8c59 100644
--- a/tools/perf/lib/tests/test-threadmap.c
+++ b/tools/perf/lib/tests/test-threadmap.c
@@ -2,12 +2,20 @@
#include <perf/threadmap.h>
#include <internal/tests.h>
+static int libperf_print(enum libperf_print_level level,
+ const char *fmt, va_list ap)
+{
+ return vfprintf(stderr, fmt, ap);
+}
+
int main(int argc, char **argv)
{
struct perf_thread_map *threads;
__T_START;
+ libperf_init(libperf_print);
+
threads = perf_thread_map__new_dummy();
if (!threads)
return -1;
--
2.21.0
The libperf_set_print needs to be called in any
case so let's merge it with libperf_init, so
we have just one init function.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/core.c | 8 ++------
tools/perf/lib/include/perf/core.h | 3 +--
tools/perf/lib/libperf.map | 1 -
tools/perf/perf.c | 8 +++++++-
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
index 6689d593c2d1..d0b9ae422b9f 100644
--- a/tools/perf/lib/core.c
+++ b/tools/perf/lib/core.c
@@ -17,11 +17,6 @@ static int __base_pr(enum libperf_print_level level, const char *format,
static libperf_print_fn_t __libperf_pr = __base_pr;
-void libperf_set_print(libperf_print_fn_t fn)
-{
- __libperf_pr = fn;
-}
-
__printf(2, 3)
void libperf_print(enum libperf_print_level level, const char *format, ...)
{
@@ -35,7 +30,8 @@ void libperf_print(enum libperf_print_level level, const char *format, ...)
va_end(args);
}
-void libperf_init(void)
+void libperf_init(libperf_print_fn_t fn)
{
page_size = sysconf(_SC_PAGE_SIZE);
+ __libperf_pr = fn;
}
diff --git a/tools/perf/lib/include/perf/core.h b/tools/perf/lib/include/perf/core.h
index ba2f4e76a3e2..cfd70e720c1c 100644
--- a/tools/perf/lib/include/perf/core.h
+++ b/tools/perf/lib/include/perf/core.h
@@ -17,7 +17,6 @@ enum libperf_print_level {
typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
const char *, va_list ap);
-LIBPERF_API void libperf_set_print(libperf_print_fn_t fn);
-LIBPERF_API void libperf_init(void);
+LIBPERF_API void libperf_init(libperf_print_fn_t fn);
#endif /* __LIBPERF_CORE_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 3fbf050b5add..507b4cc4784c 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -1,7 +1,6 @@
LIBPERF_0.0.1 {
global:
libperf_init;
- libperf_set_print;
perf_cpu_map__dummy_new;
perf_cpu_map__get;
perf_cpu_map__put;
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index ead18b712d6c..d13a9b1ce65d 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -429,6 +429,12 @@ void pthread__unblock_sigwinch(void)
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
}
+static int libperf_print(enum libperf_print_level level,
+ const char *fmt, va_list ap)
+{
+ return eprintf(level, verbose, fmt, ap);
+}
+
int main(int argc, const char **argv)
{
int err;
@@ -439,7 +445,7 @@ int main(int argc, const char **argv)
exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
pager_init(PERF_PAGER_ENVIRONMENT);
- libperf_init();
+ libperf_init(libperf_print);
cmd = extract_argv0_path(argv[0]);
if (!cmd)
--
2.21.0
Move perf_evlist__alloc_pollfd function under libperf,
it will be used in following patches.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 21 +++++++++++++++++++++
tools/perf/lib/include/internal/evlist.h | 2 ++
tools/perf/util/evlist.c | 23 +----------------------
tools/perf/util/evlist.h | 1 -
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 35467d99cea5..0f84f5dc519f 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -237,3 +237,24 @@ int perf_evlist__id_add_fd(struct perf_evlist *evlist,
perf_evlist__id_add(evlist, evsel, cpu, thread, id);
return 0;
}
+
+int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
+{
+ int nr_cpus = perf_cpu_map__nr(evlist->cpus);
+ int nr_threads = perf_thread_map__nr(evlist->threads);
+ int nfds = 0;
+ struct perf_evsel *evsel;
+
+ perf_evlist__for_each_entry(evlist, evsel) {
+ if (evsel->system_wide)
+ nfds += nr_cpus;
+ else
+ nfds += nr_cpus * nr_threads;
+ }
+
+ if (fdarray__available_entries(&evlist->pollfd) < nfds &&
+ fdarray__grow(&evlist->pollfd, nfds) < 0)
+ return -ENOMEM;
+
+ return 0;
+}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 7d64185cfabd..88c0dfaf0ddc 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -24,6 +24,8 @@ struct perf_evlist {
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
};
+int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
+
/**
* __perf_evlist__for_each_entry - iterate thru all the evsels
* @list: list_head instance to iterate
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 433e9af6e063..664c8e87ec96 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -397,27 +397,6 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
return perf_evlist__enable_event_thread(evlist, evsel, idx);
}
-int perf_evlist__alloc_pollfd(struct evlist *evlist)
-{
- int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
- int nr_threads = perf_thread_map__nr(evlist->core.threads);
- int nfds = 0;
- struct evsel *evsel;
-
- evlist__for_each_entry(evlist, evsel) {
- if (evsel->core.system_wide)
- nfds += nr_cpus;
- else
- nfds += nr_cpus * nr_threads;
- }
-
- if (fdarray__available_entries(&evlist->core.pollfd) < nfds &&
- fdarray__grow(&evlist->core.pollfd, nfds) < 0)
- return -ENOMEM;
-
- return 0;
-}
-
static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
struct mmap *map, short revent)
{
@@ -943,7 +922,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
if (!evlist->mmap)
return -ENOMEM;
- if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
+ if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(&evlist->core) < 0)
return -ENOMEM;
evlist->core.mmap_len = evlist__mmap_size(pages);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 204315516c32..9c90df51ce08 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -114,7 +114,6 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
const char *name);
int perf_evlist__add_pollfd(struct evlist *evlist, int fd);
-int perf_evlist__alloc_pollfd(struct evlist *evlist);
int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
int perf_evlist__poll(struct evlist *evlist, int timeout);
--
2.21.0
Adding libperf dependency for tests targets.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index 54466cc84544..85ccb8c439a4 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -138,7 +138,7 @@ clean: $(LIBAPI)-clean
*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
$(Q)$(MAKE) -C tests clean
-tests:
+tests: libs
$(Q)$(MAKE) -C tests
$(Q)$(MAKE) -C tests run
--
2.21.0
Move perf_mmap__unmap function under libperf,
to internal header internal/mmap.h. It will be
used in following patches. And rename the existing
perf's function to mmap__munmap.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/lib/mmap.c | 10 ++++++++++
tools/perf/util/evlist.c | 4 ++--
tools/perf/util/mmap.c | 11 +++--------
tools/perf/util/mmap.h | 2 +-
5 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 372521cae06d..5c9ba00e67e1 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -39,6 +39,7 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map);
void perf_mmap__init(struct perf_mmap *map, bool overwrite);
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu);
+void perf_mmap__munmap(struct perf_mmap *map);
void perf_mmap__get(struct perf_mmap *map);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index b765e0505bb6..6eb228d89206 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -32,6 +32,16 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
return 0;
}
+void perf_mmap__munmap(struct perf_mmap *map)
+{
+ if (map && map->base != NULL) {
+ munmap(map->base, perf_mmap__mmap_len(map));
+ map->base = NULL;
+ map->fd = -1;
+ refcount_set(&map->refcnt, 0);
+ }
+}
+
void perf_mmap__get(struct perf_mmap *map)
{
refcount_inc(&map->refcnt);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0191d3b2eb20..22165862f587 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -576,11 +576,11 @@ static void evlist__munmap_nofree(struct evlist *evlist)
if (evlist->mmap)
for (i = 0; i < evlist->core.nr_mmaps; i++)
- perf_mmap__munmap(&evlist->mmap[i]);
+ mmap__munmap(&evlist->mmap[i]);
if (evlist->overwrite_mmap)
for (i = 0; i < evlist->core.nr_mmaps; i++)
- perf_mmap__munmap(&evlist->overwrite_mmap[i]);
+ mmap__munmap(&evlist->overwrite_mmap[i]);
}
void evlist__munmap(struct evlist *evlist)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index a7e0b4afc176..eb77141dbfca 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -114,7 +114,7 @@ void perf_mmap__put(struct mmap *map)
BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0);
if (refcount_dec_and_test(&map->core.refcnt))
- perf_mmap__munmap(map);
+ mmap__munmap(map);
}
void perf_mmap__consume(struct mmap *map)
@@ -305,19 +305,14 @@ static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused)
}
#endif
-void perf_mmap__munmap(struct mmap *map)
+void mmap__munmap(struct mmap *map)
{
+ perf_mmap__munmap(&map->core);
perf_mmap__aio_munmap(map);
if (map->data != NULL) {
munmap(map->data, mmap__mmap_len(map));
map->data = NULL;
}
- if (map->core.base != NULL) {
- munmap(map->core.base, mmap__mmap_len(map));
- map->core.base = NULL;
- map->core.fd = -1;
- refcount_set(&map->core.refcnt, 0);
- }
auxtrace_mmap__munmap(&map->auxtrace_mmap);
}
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index f7ee0252db24..852f1ec20787 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -71,7 +71,7 @@ struct mmap_params {
};
int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
-void perf_mmap__munmap(struct mmap *map);
+void mmap__munmap(struct mmap *map);
void perf_mmap__put(struct mmap *map);
--
2.21.0
Move perf_mmap__read_init function under libperf
and export it in perf/mmap.h header.
And add pr_debug2/pr_debug3 macros support, because
the code is using them.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/include/perf/core.h | 2 +
tools/perf/lib/include/perf/mmap.h | 1 +
tools/perf/lib/internal.h | 2 +
tools/perf/lib/libperf.map | 1 +
tools/perf/lib/mmap.c | 84 ++++++++++++++++++++
tools/perf/tests/backward-ring-buffer.c | 2 +-
tools/perf/tests/bpf.c | 2 +-
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/keep-tracking.c | 2 +-
tools/perf/tests/mmap-basic.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/sw-clock.c | 2 +-
tools/perf/tests/switch-tracking.c | 2 +-
tools/perf/tests/task-exit.c | 2 +-
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 82 +------------------
tools/perf/util/mmap.h | 1 -
tools/perf/util/python.c | 2 +-
23 files changed, 107 insertions(+), 98 deletions(-)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index c9b359a16f75..ca5e483c3fda 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -118,7 +118,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index fea07ee4c68b..ca7e48379f57 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -756,7 +756,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
*mmap_time = ULLONG_MAX;
md = &evlist->mmap[idx];
- err = perf_mmap__read_init(md);
+ err = perf_mmap__read_init(&md->core);
if (err < 0)
return (err == -EAGAIN) ? 0 : -1;
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 19775c7a5563..86b7a71dc5ed 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -866,7 +866,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
union perf_event *event;
md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
return;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index fa8296e8be2a..fcdb30e93a81 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3447,7 +3447,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
struct mmap *md;
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/lib/include/perf/core.h b/tools/perf/lib/include/perf/core.h
index cfd70e720c1c..2a80e4b6f819 100644
--- a/tools/perf/lib/include/perf/core.h
+++ b/tools/perf/lib/include/perf/core.h
@@ -12,6 +12,8 @@ enum libperf_print_level {
LIBPERF_WARN,
LIBPERF_INFO,
LIBPERF_DEBUG,
+ LIBPERF_DEBUG2,
+ LIBPERF_DEBUG3,
};
typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
diff --git a/tools/perf/lib/include/perf/mmap.h b/tools/perf/lib/include/perf/mmap.h
index d3678d1834d9..646e9052b003 100644
--- a/tools/perf/lib/include/perf/mmap.h
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -7,5 +7,6 @@
struct perf_mmap;
LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
+LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
#endif /* __LIBPERF_MMAP_H */
diff --git a/tools/perf/lib/internal.h b/tools/perf/lib/internal.h
index dc92f241732e..37db745e1502 100644
--- a/tools/perf/lib/internal.h
+++ b/tools/perf/lib/internal.h
@@ -14,5 +14,7 @@ do { \
#define pr_warning(fmt, ...) __pr(LIBPERF_WARN, fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) __pr(LIBPERF_INFO, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) __pr(LIBPERF_DEBUG, fmt, ##__VA_ARGS__)
+#define pr_debug2(fmt, ...) __pr(LIBPERF_DEBUG2, fmt, ##__VA_ARGS__)
+#define pr_debug3(fmt, ...) __pr(LIBPERF_DEBUG3, fmt, ##__VA_ARGS__)
#endif /* __LIBPERF_INTERNAL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 8c876fbc1fa3..fba8cdfb3987 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -40,6 +40,7 @@ LIBPERF_0.0.1 {
perf_evlist__set_maps;
perf_evlist__poll;
perf_mmap__consume;
+ perf_mmap__read_init;
local:
*;
};
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 8545e7a03691..15f91b976ce7 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,11 +1,15 @@
// SPDX-License-Identifier: GPL-2.0
#include <sys/mman.h>
+#include <inttypes.h>
+#include <asm/bug.h>
+#include <errno.h>
#include <linux/zalloc.h>
#include <linux/ring_buffer.h>
#include <linux/perf_event.h>
#include <perf/mmap.h>
#include <internal/mmap.h>
#include <internal/lib.h>
+#include "internal.h"
void perf_mmap__init(struct perf_mmap *map, bool overwrite,
libperf_unmap_cb_t unmap_cb)
@@ -101,3 +105,83 @@ void perf_mmap__consume(struct perf_mmap *map)
if (refcount_read(&map->refcnt) == 1 && perf_mmap__empty(map))
perf_mmap__put(map);
}
+
+static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
+{
+ struct perf_event_header *pheader;
+ u64 evt_head = *start;
+ int size = mask + 1;
+
+ pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
+ pheader = (struct perf_event_header *)(buf + (*start & mask));
+ while (true) {
+ if (evt_head - *start >= (unsigned int)size) {
+ pr_debug("Finished reading overwrite ring buffer: rewind\n");
+ if (evt_head - *start > (unsigned int)size)
+ evt_head -= pheader->size;
+ *end = evt_head;
+ return 0;
+ }
+
+ pheader = (struct perf_event_header *)(buf + (evt_head & mask));
+
+ if (pheader->size == 0) {
+ pr_debug("Finished reading overwrite ring buffer: get start\n");
+ *end = evt_head;
+ return 0;
+ }
+
+ evt_head += pheader->size;
+ pr_debug3("move evt_head: %"PRIx64"\n", evt_head);
+ }
+ WARN_ONCE(1, "Shouldn't get here\n");
+ return -1;
+}
+
+/*
+ * Report the start and end of the available data in ringbuffer
+ */
+static int __perf_mmap__read_init(struct perf_mmap *md)
+{
+ u64 head = perf_mmap__read_head(md);
+ u64 old = md->prev;
+ unsigned char *data = md->base + page_size;
+ unsigned long size;
+
+ md->start = md->overwrite ? head : old;
+ md->end = md->overwrite ? old : head;
+
+ if ((md->end - md->start) < md->flush)
+ return -EAGAIN;
+
+ size = md->end - md->start;
+ if (size > (unsigned long)(md->mask) + 1) {
+ if (!md->overwrite) {
+ WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
+
+ md->prev = head;
+ perf_mmap__consume(md);
+ return -EAGAIN;
+ }
+
+ /*
+ * Backward ring buffer is full. We still have a chance to read
+ * most of data from it.
+ */
+ if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int perf_mmap__read_init(struct perf_mmap *map)
+{
+ /*
+ * Check if event was unmapped due to a POLLHUP/POLLERR.
+ */
+ if (!refcount_read(&map->refcnt))
+ return -ENOENT;
+
+ return __perf_mmap__read_init(map);
+}
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 6d8a49b0d4e0..085e4d632be4 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -37,7 +37,7 @@ static int count_samples(struct evlist *evlist, int *sample_count,
struct mmap *map = &evlist->overwrite_mmap[i];
union perf_event *event;
- perf_mmap__read_init(map);
+ perf_mmap__read_init(&map->core);
while ((event = perf_mmap__read_event(map)) != NULL) {
const u32 type = event->header.type;
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 79acb857841c..d7e328d2d1f2 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -184,7 +184,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
struct mmap *md;
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 8ce99aeadb34..3c5de881b43c 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -425,7 +425,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 2169d74d9872..3cdee969958d 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -39,7 +39,7 @@ static int find_comm(struct evlist *evlist, const char *comm)
found = 0;
for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
if (event->header.type == PERF_RECORD_COMM &&
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 18dd25ed8a2c..e9c1fbe5a9aa 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -114,7 +114,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
}
md = &evlist->mmap[0];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 878d32237fb3..6c04753fe5f0 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -92,7 +92,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
struct mmap *md;
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index b2552ee06329..086cabb56db2 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -170,7 +170,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
struct mmap *md;
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 67615d90cd73..4b13d746f264 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -99,7 +99,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
evlist__disable(evlist);
md = &evlist->mmap[0];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 529b39f39299..f774b50f926e 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -270,7 +270,7 @@ static int process_events(struct evlist *evlist,
for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 4fd52522357a..6a1ca5d6dfdf 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -117,7 +117,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
retry:
md = &evlist->mmap[0];
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index e9cc637881b8..38fd27f5bf0f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1752,7 +1752,7 @@ static void *perf_evlist__poll_thread(void *arg)
struct mmap *map = &evlist->mmap[i];
union perf_event *event;
- if (perf_mmap__read_init(map))
+ if (perf_mmap__read_init(&map->core))
continue;
while ((event = perf_mmap__read_event(map)) != NULL) {
struct evsel *evsel = perf_evlist__event2evsel(evlist, event);
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 5ec12483e79d..5913f7354232 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -364,86 +364,6 @@ int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
return perf_mmap__aio_mmap(map, mp);
}
-static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
-{
- struct perf_event_header *pheader;
- u64 evt_head = *start;
- int size = mask + 1;
-
- pr_debug2("%s: buf=%p, start=%"PRIx64"\n", __func__, buf, *start);
- pheader = (struct perf_event_header *)(buf + (*start & mask));
- while (true) {
- if (evt_head - *start >= (unsigned int)size) {
- pr_debug("Finished reading overwrite ring buffer: rewind\n");
- if (evt_head - *start > (unsigned int)size)
- evt_head -= pheader->size;
- *end = evt_head;
- return 0;
- }
-
- pheader = (struct perf_event_header *)(buf + (evt_head & mask));
-
- if (pheader->size == 0) {
- pr_debug("Finished reading overwrite ring buffer: get start\n");
- *end = evt_head;
- return 0;
- }
-
- evt_head += pheader->size;
- pr_debug3("move evt_head: %"PRIx64"\n", evt_head);
- }
- WARN_ONCE(1, "Shouldn't get here\n");
- return -1;
-}
-
-/*
- * Report the start and end of the available data in ringbuffer
- */
-static int __perf_mmap__read_init(struct mmap *md)
-{
- u64 head = perf_mmap__read_head(&md->core);
- u64 old = md->core.prev;
- unsigned char *data = md->core.base + page_size;
- unsigned long size;
-
- md->core.start = md->core.overwrite ? head : old;
- md->core.end = md->core.overwrite ? old : head;
-
- if ((md->core.end - md->core.start) < md->core.flush)
- return -EAGAIN;
-
- size = md->core.end - md->core.start;
- if (size > (unsigned long)(md->core.mask) + 1) {
- if (!md->core.overwrite) {
- WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
-
- md->core.prev = head;
- perf_mmap__consume(&md->core);
- return -EAGAIN;
- }
-
- /*
- * Backward ring buffer is full. We still have a chance to read
- * most of data from it.
- */
- if (overwrite_rb_find_range(data, md->core.mask, &md->core.start, &md->core.end))
- return -EINVAL;
- }
-
- return 0;
-}
-
-int perf_mmap__read_init(struct mmap *map)
-{
- /*
- * Check if event was unmapped due to a POLLHUP/POLLERR.
- */
- if (!refcount_read(&map->core.refcnt))
- return -ENOENT;
-
- return __perf_mmap__read_init(map);
-}
-
int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size))
{
@@ -453,7 +373,7 @@ int perf_mmap__push(struct mmap *md, void *to,
void *buf;
int rc = 0;
- rc = perf_mmap__read_init(md);
+ rc = perf_mmap__read_init(&md->core);
if (rc < 0)
return (rc == -EAGAIN) ? 1 : -1;
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index d90554168127..3849bcbbe9ce 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -82,6 +82,5 @@ int perf_mmap__push(struct mmap *md, void *to,
size_t mmap__mmap_len(struct mmap *map);
-int perf_mmap__read_init(struct mmap *md);
void perf_mmap__read_done(struct mmap *map);
#endif /*__PERF_MMAP_H */
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 04c1d350a9c5..ba7a7cace740 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1017,7 +1017,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
if (!md)
return NULL;
- if (perf_mmap__read_init(md) < 0)
+ if (perf_mmap__read_init(&md->core) < 0)
goto end;
event = perf_mmap__read_event(md);
--
2.21.0
Switching to libperf mmap interface by calling directly
perf_evlist__mmap_ops and removing perf's evlist__mmap_per_*
functions.
By switching libperf perf_evlist__mmap we need to operate
over 'struct perf_mmap' in evlist__add_pollfd, so making
related changes there.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 179 +--------------------------------------
1 file changed, 4 insertions(+), 175 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index a0f09e78e89d..94d8a1d96b81 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -406,10 +406,10 @@ int evlist__add_pollfd(struct evlist *evlist, int fd)
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
void *arg __maybe_unused)
{
- struct mmap *map = fda->priv[fd].ptr;
+ struct perf_mmap *map = fda->priv[fd].ptr;
if (map)
- perf_mmap__put(&map->core);
+ perf_mmap__put(map);
}
int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
@@ -423,22 +423,6 @@ int evlist__poll(struct evlist *evlist, int timeout)
return perf_evlist__poll(&evlist->core, timeout);
}
-static void perf_evlist__set_sid_idx(struct evlist *evlist,
- struct evsel *evsel, int idx, int cpu,
- int thread)
-{
- struct perf_sample_id *sid = SID(evsel, cpu, thread);
- sid->idx = idx;
- if (evlist->core.cpus && cpu >= 0)
- sid->cpu = evlist->core.cpus->map[cpu];
- else
- sid->cpu = -1;
- if (!evsel->core.system_wide && evlist->core.threads && thread >= 0)
- sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
- else
- sid->tid = -1;
-}
-
struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id)
{
struct hlist_head *head;
@@ -627,93 +611,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
return map;
}
-static bool
-perf_evlist__should_poll(struct evlist *evlist __maybe_unused,
- struct evsel *evsel)
-{
- if (evsel->core.attr.write_backward)
- return false;
- return true;
-}
-
-static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
- struct mmap_params *mp, int cpu_idx,
- int thread, int *_output, int *_output_overwrite)
-{
- struct evsel *evsel;
- int revent;
- int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
-
- evlist__for_each_entry(evlist, evsel) {
- struct mmap *maps = evlist->mmap;
- int *output = _output;
- int fd;
- int cpu;
-
- mp->core.prot = PROT_READ | PROT_WRITE;
- if (evsel->core.attr.write_backward) {
- output = _output_overwrite;
- maps = evlist->overwrite_mmap;
-
- if (!maps) {
- maps = evlist__alloc_mmap(evlist, true);
- if (!maps)
- return -1;
- evlist->overwrite_mmap = maps;
- if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
- perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
- }
- mp->core.prot &= ~PROT_WRITE;
- }
-
- if (evsel->core.system_wide && thread)
- continue;
-
- cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
- if (cpu == -1)
- continue;
-
- fd = FD(evsel, cpu, thread);
-
- if (*output == -1) {
- *output = fd;
-
- if (mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0)
- return -1;
- } else {
- if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
- return -1;
-
- perf_mmap__get(&maps[idx].core);
- }
-
- revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
-
- /*
- * The system_wide flag causes a selected event to be opened
- * always without a pid. Consequently it will never get a
- * POLLHUP, but it is used for tracking in combination with
- * other events, so it should not need to be polled anyway.
- * Therefore don't add it for polling.
- */
- if (!evsel->core.system_wide &&
- perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) {
- perf_mmap__put(&maps[idx].core);
- return -1;
- }
-
- if (evsel->core.attr.read_format & PERF_FORMAT_ID) {
- if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, cpu, thread,
- fd) < 0)
- return -1;
- perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
- thread);
- }
- }
-
- return 0;
-}
-
static void
perf_evlist__mmap_cb_idx(struct perf_evlist *_evlist,
struct perf_mmap_param *_mp,
@@ -758,61 +655,6 @@ perf_evlist__mmap_cb_mmap(struct perf_mmap *_map, struct perf_mmap_param *_mp,
return mmap__mmap(map, mp, output, cpu);
}
-static int evlist__mmap_per_cpu(struct evlist *evlist,
- struct mmap_params *mp)
-{
- int cpu, thread;
- int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
- int nr_threads = perf_thread_map__nr(evlist->core.threads);
-
- pr_debug2("perf event ring buffer mmapped per cpu\n");
- for (cpu = 0; cpu < nr_cpus; cpu++) {
- int output = -1;
- int output_overwrite = -1;
-
- auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, cpu,
- true);
-
- for (thread = 0; thread < nr_threads; thread++) {
- if (evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
- thread, &output, &output_overwrite))
- goto out_unmap;
- }
- }
-
- return 0;
-
-out_unmap:
- evlist__munmap_nofree(evlist);
- return -1;
-}
-
-static int evlist__mmap_per_thread(struct evlist *evlist,
- struct mmap_params *mp)
-{
- int thread;
- int nr_threads = perf_thread_map__nr(evlist->core.threads);
-
- pr_debug2("perf event ring buffer mmapped per thread\n");
- for (thread = 0; thread < nr_threads; thread++) {
- int output = -1;
- int output_overwrite = -1;
-
- auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
- false);
-
- if (evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
- &output, &output_overwrite))
- goto out_unmap;
- }
-
- return 0;
-
-out_unmap:
- evlist__munmap_nofree(evlist);
- return -1;
-}
-
unsigned long perf_event_mlock_kb_in_pages(void)
{
unsigned long pages;
@@ -940,9 +782,6 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
bool auxtrace_overwrite, int nr_cblocks, int affinity, int flush,
int comp_level)
{
- struct evsel *evsel;
- const struct perf_cpu_map *cpus = evlist->core.cpus;
- const struct perf_thread_map *threads = evlist->core.threads;
/*
* Delay setting mp.prot: set it before calling perf_mmap__mmap.
* Its value is decided by evsel's write_backward.
@@ -954,7 +793,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
.flush = flush,
.comp_level = comp_level
};
- struct perf_evlist_mmap_ops ops __maybe_unused = {
+ struct perf_evlist_mmap_ops ops = {
.idx = perf_evlist__mmap_cb_idx,
.new = perf_evlist__mmap_cb_new,
.mmap = perf_evlist__mmap_cb_mmap,
@@ -975,17 +814,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->core.mmap_len,
auxtrace_pages, auxtrace_overwrite);
- evlist__for_each_entry(evlist, evsel) {
- if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
- evsel->core.sample_id == NULL &&
- perf_evsel__alloc_id(&evsel->core, perf_cpu_map__nr(cpus), threads->nr) < 0)
- return -ENOMEM;
- }
-
- if (perf_cpu_map__empty(cpus))
- return evlist__mmap_per_thread(evlist, &mp);
-
- return evlist__mmap_per_cpu(evlist, &mp);
+ return perf_evlist__mmap_ops(&evlist->core, &ops, &mp.core);
}
int evlist__mmap(struct evlist *evlist, unsigned int pages)
--
2.21.0
Adding perf_evlist__exit function, so far it's not
exported and added only for internal use for perf
and libperf.
Using it to release cpus/threads and pollfd array.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 15 ++++++++++++---
tools/perf/lib/include/internal/evlist.h | 2 ++
tools/perf/util/evlist.c | 6 +-----
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index e27fe1fcef3d..b9dd040a6162 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -107,11 +107,20 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev)
return next;
}
-void perf_evlist__delete(struct perf_evlist *evlist)
+void perf_evlist__exit(struct perf_evlist *evlist)
{
- free(evlist->mmap);
- free(evlist->mmap_ovw);
+ perf_cpu_map__put(evlist->cpus);
+ perf_thread_map__put(evlist->threads);
+ evlist->cpus = NULL;
+ evlist->threads = NULL;
+ zfree(&evlist->mmap);
+ zfree(&evlist->mmap_ovw);
fdarray__exit(&evlist->pollfd);
+}
+
+void perf_evlist__delete(struct perf_evlist *evlist)
+{
+ perf_evlist__exit(evlist);
free(evlist);
}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 851837ce4ff8..1ca822eeab1d 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -48,6 +48,8 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
struct perf_evlist_mmap_ops *ops,
struct perf_mmap_param *mp);
+void perf_evlist__exit(struct perf_evlist *evlist);
+
/**
* __perf_evlist__for_each_entry - iterate thru all the evsels
* @list: list_head instance to iterate
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 728a15cddda7..0c69621e2b2e 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -137,7 +137,7 @@ void evlist__exit(struct evlist *evlist)
{
zfree(&evlist->mmap);
zfree(&evlist->overwrite_mmap);
- fdarray__exit(&evlist->core.pollfd);
+ perf_evlist__exit(&evlist->core);
}
void evlist__delete(struct evlist *evlist)
@@ -147,10 +147,6 @@ void evlist__delete(struct evlist *evlist)
evlist__munmap(evlist);
evlist__close(evlist);
- perf_cpu_map__put(evlist->core.cpus);
- perf_thread_map__put(evlist->core.threads);
- evlist->core.cpus = NULL;
- evlist->core.threads = NULL;
evlist__purge(evlist);
evlist__exit(evlist);
free(evlist);
--
2.21.0
Add the perf_mmap to libperf.
The definition is added into:
include/internal/mmap.h
which is not to be included by users, but shared
within perf and libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/arch/x86/util/intel-bts.c | 2 +-
tools/perf/arch/x86/util/intel-pt.c | 2 +-
tools/perf/builtin-record.c | 14 ++++++-------
tools/perf/lib/include/internal/mmap.h | 19 +++++++++++++++++
tools/perf/util/mmap.c | 22 ++++++++++----------
tools/perf/util/mmap.h | 7 ++++---
7 files changed, 44 insertions(+), 24 deletions(-)
create mode 100644 tools/perf/lib/include/internal/mmap.h
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 3644ebd45a46..42725e6882e9 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -93,7 +93,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
CHECK__(evlist__mmap(evlist, UINT_MAX));
- pc = evlist->mmap[0].base;
+ pc = evlist->mmap[0].core.base;
ret = perf_read_tsc_conversion(pc, &tc);
if (ret) {
if (ret == -EOPNOTSUPP) {
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index d263430c045f..aa13df948049 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -77,7 +77,7 @@ static int intel_bts_info_fill(struct auxtrace_record *itr,
if (!session->evlist->nr_mmaps)
return -EINVAL;
- pc = session->evlist->mmap[0].base;
+ pc = session->evlist->mmap[0].core.base;
if (pc) {
err = perf_read_tsc_conversion(pc, &tc);
if (err) {
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index cb7cf16af79c..c0a7535cfd0e 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -354,7 +354,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
if (!session->evlist->nr_mmaps)
return -EINVAL;
- pc = session->evlist->mmap[0].base;
+ pc = session->evlist->mmap[0].core.base;
if (pc) {
err = perf_read_tsc_conversion(pc, &tc);
if (err) {
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index df16e1ca1f36..6c0349dcb20c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -258,7 +258,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size
struct record_aio *aio = to;
/*
- * map->base data pointed by buf is copied into free map->aio.data[] buffer
+ * map->core.base data pointed by buf is copied into free map->aio.data[] buffer
* to release space in the kernel buffer as fast as possible, calling
* perf_mmap__consume() from perf_mmap__push() function.
*
@@ -357,7 +357,7 @@ static void record__aio_mmap_read_sync(struct record *rec)
for (i = 0; i < evlist->nr_mmaps; i++) {
struct mmap *map = &maps[i];
- if (map->base)
+ if (map->core.base)
record__aio_sync(map, true);
}
}
@@ -956,7 +956,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
u64 flush = 0;
struct mmap *map = &maps[i];
- if (map->base) {
+ if (map->core.base) {
record__adjust_affinity(rec, map);
if (synch) {
flush = map->flush;
@@ -1193,10 +1193,10 @@ static const struct perf_event_mmap_page *
perf_evlist__pick_pc(struct evlist *evlist)
{
if (evlist) {
- if (evlist->mmap && evlist->mmap[0].base)
- return evlist->mmap[0].base;
- if (evlist->overwrite_mmap && evlist->overwrite_mmap[0].base)
- return evlist->overwrite_mmap[0].base;
+ if (evlist->mmap && evlist->mmap[0].core.base)
+ return evlist->mmap[0].core.base;
+ if (evlist->overwrite_mmap && evlist->overwrite_mmap[0].core.base)
+ return evlist->overwrite_mmap[0].core.base;
}
return NULL;
}
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
new file mode 100644
index 000000000000..8d10559dee49
--- /dev/null
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_MMAP_H
+#define __LIBPERF_INTERNAL_MMAP_H
+
+#include <linux/refcount.h>
+#include <linux/compiler.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+/**
+ * struct perf_mmap - perf's ring buffer mmap details
+ *
+ * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
+ */
+struct perf_mmap {
+ void *base;
+};
+
+#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index f3b7c8b0fa90..76190b2edd78 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -31,7 +31,7 @@ size_t perf_mmap__mmap_len(struct mmap *map)
static union perf_event *perf_mmap__read(struct mmap *map,
u64 *startp, u64 end)
{
- unsigned char *data = map->base + page_size;
+ unsigned char *data = map->core.base + page_size;
union perf_event *event = NULL;
int diff = end - *startp;
@@ -116,7 +116,7 @@ void perf_mmap__get(struct mmap *map)
void perf_mmap__put(struct mmap *map)
{
- BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
+ BUG_ON(map->core.base && refcount_read(&map->refcnt) == 0);
if (refcount_dec_and_test(&map->refcnt))
perf_mmap__munmap(map);
@@ -317,9 +317,9 @@ void perf_mmap__munmap(struct mmap *map)
munmap(map->data, perf_mmap__mmap_len(map));
map->data = NULL;
}
- if (map->base != NULL) {
- munmap(map->base, perf_mmap__mmap_len(map));
- map->base = NULL;
+ if (map->core.base != NULL) {
+ munmap(map->core.base, perf_mmap__mmap_len(map));
+ map->core.base = NULL;
map->fd = -1;
refcount_set(&map->refcnt, 0);
}
@@ -370,12 +370,12 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
refcount_set(&map->refcnt, 2);
map->prev = 0;
map->mask = mp->mask;
- map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
+ map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
MAP_SHARED, fd, 0);
- if (map->base == MAP_FAILED) {
+ if (map->core.base == MAP_FAILED) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
errno);
- map->base = NULL;
+ map->core.base = NULL;
return -1;
}
map->fd = fd;
@@ -399,7 +399,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
}
if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
- &mp->auxtrace_mp, map->base, fd))
+ &mp->auxtrace_mp, map->core.base, fd))
return -1;
return perf_mmap__aio_mmap(map, mp);
@@ -444,7 +444,7 @@ static int __perf_mmap__read_init(struct mmap *md)
{
u64 head = perf_mmap__read_head(md);
u64 old = md->prev;
- unsigned char *data = md->base + page_size;
+ unsigned char *data = md->core.base + page_size;
unsigned long size;
md->start = md->overwrite ? head : old;
@@ -489,7 +489,7 @@ int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size))
{
u64 head = perf_mmap__read_head(md);
- unsigned char *data = md->base + page_size;
+ unsigned char *data = md->core.base + page_size;
unsigned long size;
void *buf;
int rc = 0;
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 01524608a984..9028b0e8a0ed 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -1,6 +1,7 @@
#ifndef __PERF_MMAP_H
#define __PERF_MMAP_H 1
+#include <internal/mmap.h>
#include <linux/compiler.h>
#include <linux/refcount.h>
#include <linux/types.h>
@@ -20,7 +21,7 @@ struct aiocb;
* @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
*/
struct mmap {
- void *base;
+ struct perf_mmap core;
int mask;
int fd;
int cpu;
@@ -88,12 +89,12 @@ void perf_mmap__consume(struct mmap *map);
static inline u64 perf_mmap__read_head(struct mmap *mm)
{
- return ring_buffer_read_head(mm->base);
+ return ring_buffer_read_head(mm->core.base);
}
static inline void perf_mmap__write_tail(struct mmap *md, u64 tail)
{
- ring_buffer_write_tail(md->base, tail);
+ ring_buffer_write_tail(md->core.base, tail);
}
union perf_event *perf_mmap__read_forward(struct mmap *map);
--
2.21.0
Adding mmaping tests that generates prctl call on
every cpu validates it gets all the related events
in ring buffer.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/tests/test-evlist.c | 97 ++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c
index aa90e8d40738..2b7271130223 100644
--- a/tools/perf/lib/tests/test-evlist.c
+++ b/tools/perf/lib/tests/test-evlist.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <stdio.h>
+#include <sched.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
@@ -299,6 +300,101 @@ static int test_mmap_thread(void)
return 0;
}
+static int test_mmap_cpus(void)
+{
+ struct perf_evlist *evlist;
+ struct perf_evsel *evsel;
+ struct perf_mmap *map;
+ struct perf_cpu_map *cpus;
+ struct perf_event_attr attr = {
+ .type = PERF_TYPE_TRACEPOINT,
+ .sample_period = 1,
+ .wakeup_watermark = 1,
+ .disabled = 1,
+ };
+ cpu_set_t saved_mask;
+ char path[PATH_MAX];
+ int id, err, cpu, tmp;
+ union perf_event *event;
+ int count = 0;
+
+ snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
+ sysfs__mountpoint());
+
+ if (filename__read_int(path, &id)) {
+ fprintf(stderr, "error: failed to get tracepoint id: %s\n", path);
+ return -1;
+ }
+
+ attr.config = id;
+
+ cpus = perf_cpu_map__new(NULL);
+ __T("failed to create cpus", cpus);
+
+ evlist = perf_evlist__new();
+ __T("failed to create evlist", evlist);
+
+ evsel = perf_evsel__new(&attr);
+ __T("failed to create evsel1", evsel);
+
+ perf_evlist__add(evlist, evsel);
+
+ perf_evlist__set_maps(evlist, cpus, NULL);
+
+ err = perf_evlist__open(evlist);
+ __T("failed to open evlist", err == 0);
+
+ err = perf_evlist__mmap(evlist, 4);
+ __T("failed to mmap evlist", err == 0);
+
+ perf_evlist__enable(evlist);
+
+ err = sched_getaffinity(0, sizeof(saved_mask), &saved_mask);
+ __T("sched_getaffinity failed", err == 0);
+
+ perf_cpu_map__for_each_cpu(cpu, tmp, cpus) {
+ cpu_set_t mask;
+
+ CPU_ZERO(&mask);
+ CPU_SET(cpu, &mask);
+
+ err = sched_setaffinity(0, sizeof(mask), &mask);
+ __T("sched_setaffinity failed", err == 0);
+
+ prctl(0, 0, 0, 0, 0);
+ }
+
+ err = sched_setaffinity(0, sizeof(saved_mask), &saved_mask);
+ __T("sched_setaffinity failed", err == 0);
+
+ perf_evlist__disable(evlist);
+
+ perf_evlist__for_each_mmap(evlist, map) {
+ if (perf_mmap__read_init(map) < 0)
+ continue;
+
+ while ((event = perf_mmap__read_event(map)) != NULL) {
+ count++;
+ perf_mmap__consume(map);
+ }
+
+ perf_mmap__read_done(map);
+ }
+
+ /* calls perf_evlist__munmap/perf_evlist__close */
+ perf_evlist__delete(evlist);
+
+ /*
+ * The generated prctl events should match the
+ * number of cpus or be bigger (we are system-wide).
+ */
+ __T("failed count", count >= perf_cpu_map__nr(cpus));
+
+ perf_cpu_map__put(cpus);
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
__T_START;
@@ -309,6 +405,7 @@ int main(int argc, char **argv)
test_stat_thread();
test_stat_thread_enable();
test_mmap_thread();
+ test_mmap_cpus();
__T_OK;
return 0;
--
2.21.0
Move mask from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/util/mmap.c | 24 ++++++++++++------------
tools/perf/util/mmap.h | 1 -
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 8d10559dee49..a6a464097f14 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -14,6 +14,7 @@
*/
struct perf_mmap {
void *base;
+ int mask;
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 76190b2edd78..702e8e0b90ea 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -24,7 +24,7 @@
size_t perf_mmap__mmap_len(struct mmap *map)
{
- return map->mask + 1 + page_size;
+ return map->core.mask + 1 + page_size;
}
/* When check_messup is true, 'end' must points to a good entry */
@@ -38,7 +38,7 @@ static union perf_event *perf_mmap__read(struct mmap *map,
if (diff >= (int)sizeof(event->header)) {
size_t size;
- event = (union perf_event *)&data[*startp & map->mask];
+ event = (union perf_event *)&data[*startp & map->core.mask];
size = event->header.size;
if (size < sizeof(event->header) || diff < (int)size)
@@ -48,14 +48,14 @@ static union perf_event *perf_mmap__read(struct mmap *map,
* Event straddles the mmap boundary -- header should always
* be inside due to u64 alignment of output.
*/
- if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) {
+ if ((*startp & map->core.mask) + size != ((*startp + size) & map->core.mask)) {
unsigned int offset = *startp;
unsigned int len = min(sizeof(*event), size), cpy;
void *dst = map->event_copy;
do {
- cpy = min(map->mask + 1 - (offset & map->mask), len);
- memcpy(dst, &data[offset & map->mask], cpy);
+ cpy = min(map->core.mask + 1 - (offset & map->core.mask), len);
+ memcpy(dst, &data[offset & map->core.mask], cpy);
offset += cpy;
dst += cpy;
len -= cpy;
@@ -369,7 +369,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
*/
refcount_set(&map->refcnt, 2);
map->prev = 0;
- map->mask = mp->mask;
+ map->core.mask = mp->mask;
map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
MAP_SHARED, fd, 0);
if (map->core.base == MAP_FAILED) {
@@ -454,7 +454,7 @@ static int __perf_mmap__read_init(struct mmap *md)
return -EAGAIN;
size = md->end - md->start;
- if (size > (unsigned long)(md->mask) + 1) {
+ if (size > (unsigned long)(md->core.mask) + 1) {
if (!md->overwrite) {
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
@@ -467,7 +467,7 @@ static int __perf_mmap__read_init(struct mmap *md)
* Backward ring buffer is full. We still have a chance to read
* most of data from it.
*/
- if (overwrite_rb_find_range(data, md->mask, &md->start, &md->end))
+ if (overwrite_rb_find_range(data, md->core.mask, &md->start, &md->end))
return -EINVAL;
}
@@ -500,9 +500,9 @@ int perf_mmap__push(struct mmap *md, void *to,
size = md->end - md->start;
- if ((md->start & md->mask) + size != (md->end & md->mask)) {
- buf = &data[md->start & md->mask];
- size = md->mask + 1 - (md->start & md->mask);
+ if ((md->start & md->core.mask) + size != (md->end & md->core.mask)) {
+ buf = &data[md->start & md->core.mask];
+ size = md->core.mask + 1 - (md->start & md->core.mask);
md->start += size;
if (push(md, to, buf, size) < 0) {
@@ -511,7 +511,7 @@ int perf_mmap__push(struct mmap *md, void *to,
}
}
- buf = &data[md->start & md->mask];
+ buf = &data[md->start & md->core.mask];
size = md->end - md->start;
md->start += size;
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 9028b0e8a0ed..a6e60596f889 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -22,7 +22,6 @@ struct aiocb;
*/
struct mmap {
struct perf_mmap core;
- int mask;
int fd;
int cpu;
refcount_t refcnt;
--
2.21.0
And missing include for "perf/core.h" header, which provides
LIBPERF_* debug levels and adding missing pr_err support.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/perf/core.h | 1 +
tools/perf/lib/internal.h | 3 +++
2 files changed, 4 insertions(+)
diff --git a/tools/perf/lib/include/perf/core.h b/tools/perf/lib/include/perf/core.h
index 2a80e4b6f819..a3f6d68edad7 100644
--- a/tools/perf/lib/include/perf/core.h
+++ b/tools/perf/lib/include/perf/core.h
@@ -9,6 +9,7 @@
#endif
enum libperf_print_level {
+ LIBPERF_ERR,
LIBPERF_WARN,
LIBPERF_INFO,
LIBPERF_DEBUG,
diff --git a/tools/perf/lib/internal.h b/tools/perf/lib/internal.h
index 37db745e1502..2c27e158de6b 100644
--- a/tools/perf/lib/internal.h
+++ b/tools/perf/lib/internal.h
@@ -2,6 +2,8 @@
#ifndef __LIBPERF_INTERNAL_H
#define __LIBPERF_INTERNAL_H
+#include <perf/core.h>
+
void libperf_print(enum libperf_print_level level,
const char *format, ...)
__attribute__((format(printf, 2, 3)));
@@ -11,6 +13,7 @@ do { \
libperf_print(level, "libperf: " fmt, ##__VA_ARGS__); \
} while (0)
+#define pr_err(fmt, ...) __pr(LIBPERF_ERR, fmt, ##__VA_ARGS__)
#define pr_warning(fmt, ...) __pr(LIBPERF_WARN, fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) __pr(LIBPERF_INFO, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) __pr(LIBPERF_DEBUG, fmt, ##__VA_ARGS__)
--
2.21.0
Adding perf_evlist_mmap_ops::new callback to be called
in mmap_per_evsel to get/allocate the new 'struct perf_mmap'
object.
Adding libperf's perf_evlist__mmap_cb_new function as
libperf's new callback.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 32 +++++++++++++++++-------
tools/perf/lib/include/internal/evlist.h | 3 +++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 67b5f14f738f..8caced7d489a 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -327,9 +327,23 @@ static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
#define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
+static struct perf_mmap*
+perf_evlist__mmap_cb_new(struct perf_evlist *evlist, bool overwrite, int idx)
+{
+ struct perf_mmap **maps, *map;
+
+ map = perf_mmap__new(overwrite, NULL);
+ if (map == NULL)
+ return NULL;
+
+ maps = overwrite ? evlist->mmap_ovw : evlist->mmap;
+ maps[idx] = map;
+ return map;
+}
+
static int
-mmap_per_evsel(struct perf_evlist *evlist, int idx,
- struct perf_mmap_param *mp, int cpu_idx,
+mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
+ int idx, struct perf_mmap_param *mp, int cpu_idx,
int thread, int *_output, int *_output_overwrite)
{
int evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx);
@@ -348,18 +362,16 @@ mmap_per_evsel(struct perf_evlist *evlist, int idx,
if (cpu == -1)
continue;
- map = perf_mmap__new(overwrite, NULL);
+ map = ops->new(evlist, overwrite, idx);
if (map == NULL)
return -ENOMEM;
if (overwrite) {
mp->prot = PROT_READ;
output = _output_overwrite;
- evlist->mmap_ovw[idx] = map;
} else {
mp->prot = PROT_READ | PROT_WRITE;
output = _output;
- evlist->mmap[idx] = map;
}
fd = FD(evsel, cpu, thread);
@@ -410,7 +422,7 @@ mmap_per_thread(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
if (ops->idx)
ops->idx(evlist, mp, thread, false);
- if (mmap_per_evsel(evlist, thread, mp, 0, thread,
+ if (mmap_per_evsel(evlist, ops, thread, mp, 0, thread,
&output, &output_overwrite))
goto out_unmap;
}
@@ -438,7 +450,7 @@ mmap_per_cpu(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
ops->idx(evlist, mp, cpu, true);
for (thread = 0; thread < nr_threads; thread++) {
- if (mmap_per_evsel(evlist, cpu, mp, cpu,
+ if (mmap_per_evsel(evlist, ops, cpu, mp, cpu,
thread, &output, &output_overwrite))
goto out_unmap;
}
@@ -459,7 +471,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;
- if (!ops)
+ if (!ops || !ops->new)
return -EINVAL;
perf_evlist__for_each_entry(evlist, evsel) {
@@ -478,7 +490,9 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
{
struct perf_mmap_param mp;
- struct perf_evlist_mmap_ops ops = { 0 };
+ struct perf_evlist_mmap_ops ops = {
+ .new = perf_evlist__mmap_cb_new,
+ };
if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
return -ENOMEM;
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 64522b8237be..3cb836912ee6 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -29,9 +29,12 @@ struct perf_evlist {
typedef void
(*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool);
+typedef struct perf_mmap*
+(*perf_evlist_mmap__cb_new_t)(struct perf_evlist*, bool, int);
struct perf_evlist_mmap_ops {
perf_evlist_mmap__cb_idx_t idx;
+ perf_evlist_mmap__cb_new_t new;
};
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
--
2.21.0
Adding perf_mmap__init function to initialize
'struct perf_mmap' object. Adding it to new
mmap.c object, that will carry all the mmap
related functions.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/Build | 1 +
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/mmap.c | 9 +++++++++
tools/perf/util/evlist.c | 5 ++---
4 files changed, 14 insertions(+), 3 deletions(-)
create mode 100644 tools/perf/lib/mmap.c
diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index c31f1c111f8f..2ef9a4ec6d99 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -3,6 +3,7 @@ libperf-y += cpumap.o
libperf-y += threadmap.o
libperf-y += evsel.o
libperf-y += evlist.o
+libperf-y += mmap.o
libperf-y += zalloc.o
libperf-y += xyarray.o
libperf-y += lib.o
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index a147b25c4b88..e95fc51e5bd0 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -29,4 +29,6 @@ struct perf_mmap {
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
};
+void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
new file mode 100644
index 000000000000..3da6177510e6
--- /dev/null
+++ b/tools/perf/lib/mmap.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <internal/mmap.h>
+
+void perf_mmap__init(struct perf_mmap *map, bool overwrite)
+{
+ map->fd = -1;
+ map->overwrite = overwrite;
+ refcount_set(&map->refcnt, 0);
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index dcc4accd3180..0d1ae00d22f3 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -604,8 +604,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
return NULL;
for (i = 0; i < evlist->core.nr_mmaps; i++) {
- map[i].core.fd = -1;
- map[i].core.overwrite = overwrite;
/*
* When the perf_mmap() call is made we grab one refcount, plus
* one extra to let perf_mmap__consume() get the last
@@ -615,8 +613,9 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
* Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
* thus does perf_mmap__get() on it.
*/
- refcount_set(&map[i].core.refcnt, 0);
+ perf_mmap__init(&map[i].core, overwrite);
}
+
return map;
}
--
2.21.0
Move perf_mmap__consume function under libperf
and export it in perf/mmap.h header.
Moving also needed helpers perf_mmap__write_tail,
perf_mmap__read_head and perf_mmap__empty.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 3 +-
tools/perf/builtin-kvm.c | 5 +--
tools/perf/builtin-top.c | 3 +-
tools/perf/builtin-trace.c | 3 +-
tools/perf/lib/Makefile | 5 +--
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/include/perf/mmap.h | 11 +++++++
tools/perf/lib/libperf.map | 1 +
tools/perf/lib/mmap.c | 32 ++++++++++++++++++++
tools/perf/tests/backward-ring-buffer.c | 1 +
tools/perf/tests/bpf.c | 1 +
tools/perf/tests/code-reading.c | 3 +-
tools/perf/tests/keep-tracking.c | 3 +-
tools/perf/tests/mmap-basic.c | 3 +-
tools/perf/tests/openat-syscall-tp-fields.c | 3 +-
tools/perf/tests/perf-record.c | 3 +-
tools/perf/tests/sw-clock.c | 3 +-
tools/perf/tests/switch-tracking.c | 3 +-
tools/perf/tests/task-exit.c | 3 +-
tools/perf/util/evlist.c | 3 +-
tools/perf/util/mmap.c | 32 +++++---------------
tools/perf/util/mmap.h | 12 --------
tools/perf/util/python.c | 3 +-
23 files changed, 87 insertions(+), 54 deletions(-)
create mode 100644 tools/perf/lib/include/perf/mmap.h
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 0aa96f531653..c9b359a16f75 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -9,6 +9,7 @@
#include <sys/prctl.h>
#include <perf/cpumap.h>
#include <perf/evlist.h>
+#include <perf/mmap.h>
#include "debug.h"
#include "parse-events.h"
@@ -139,7 +140,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
comm2_time = sample.time;
}
next_event:
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
}
perf_mmap__read_done(md);
}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index a90c7d4302b9..fea07ee4c68b 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -42,6 +42,7 @@
#include <semaphore.h>
#include <signal.h>
#include <math.h>
+#include <perf/mmap.h>
static const char *get_filename_for_perf_kvm(void)
{
@@ -762,7 +763,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
while ((event = perf_mmap__read_event(md)) != NULL) {
err = perf_evlist__parse_sample_timestamp(evlist, event, ×tamp);
if (err) {
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
pr_err("Failed to parse sample\n");
return -1;
}
@@ -772,7 +773,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
* FIXME: Here we can't consume the event, as perf_session__queue_event will
* point to it, and it'll get possibly overwritten by the kernel.
*/
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
if (err) {
pr_err("Failed to enqueue sample: %d\n", err);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index fb62e10f4d4f..19775c7a5563 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -78,6 +78,7 @@
#include <linux/types.h>
#include <linux/ctype.h>
+#include <perf/mmap.h>
static volatile int done;
static volatile int resize;
@@ -879,7 +880,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
if (ret)
break;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
if (top->qe.rotate) {
pthread_mutex_lock(&top->qe.mutex);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 55daadb001f6..fa8296e8be2a 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -73,6 +73,7 @@
#include <sys/sysmacros.h>
#include <linux/ctype.h>
+#include <perf/mmap.h>
#ifndef O_CLOEXEC
# define O_CLOEXEC 02000000
@@ -3456,7 +3457,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (err)
goto out_disable;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
if (interrupted)
goto out_disable;
diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index 85ccb8c439a4..0889c9c3ec19 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -172,8 +172,9 @@ install_headers:
$(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
$(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
$(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
- $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644);
- $(call do_install,include/perf/event.h,$(prefix)/include/perf,644);
+ $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \
+ $(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \
+ $(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644);
install_pkgconfig: $(LIBPERF_PC)
$(call QUIET_INSTALL, $(LIBPERF_PC)) \
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 31946e26368a..30e34ec622bf 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -51,4 +51,6 @@ void perf_mmap__munmap(struct perf_mmap *map);
void perf_mmap__get(struct perf_mmap *map);
void perf_mmap__put(struct perf_mmap *map);
+u64 perf_mmap__read_head(struct perf_mmap *map);
+
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/include/perf/mmap.h b/tools/perf/lib/include/perf/mmap.h
new file mode 100644
index 000000000000..d3678d1834d9
--- /dev/null
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_MMAP_H
+#define __LIBPERF_MMAP_H
+
+#include <perf/core.h>
+
+struct perf_mmap;
+
+LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
+
+#endif /* __LIBPERF_MMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 2672f21b4908..8c876fbc1fa3 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -39,6 +39,7 @@ LIBPERF_0.0.1 {
perf_evlist__next;
perf_evlist__set_maps;
perf_evlist__poll;
+ perf_mmap__consume;
local:
*;
};
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 720dda578ed9..8545e7a03691 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
#include <sys/mman.h>
#include <linux/zalloc.h>
+#include <linux/ring_buffer.h>
+#include <linux/perf_event.h>
+#include <perf/mmap.h>
#include <internal/mmap.h>
#include <internal/lib.h>
@@ -69,3 +72,32 @@ void perf_mmap__put(struct perf_mmap *map)
if (refcount_dec_and_test(&map->refcnt))
perf_mmap__munmap(map);
}
+
+static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
+{
+ ring_buffer_write_tail(md->base, tail);
+}
+
+u64 perf_mmap__read_head(struct perf_mmap *map)
+{
+ return ring_buffer_read_head(map->base);
+}
+
+static bool perf_mmap__empty(struct perf_mmap *map)
+{
+ struct perf_event_mmap_page *pc = map->base;
+
+ return perf_mmap__read_head(map) == map->prev && !pc->aux_size;
+}
+
+void perf_mmap__consume(struct perf_mmap *map)
+{
+ if (!map->overwrite) {
+ u64 old = map->prev;
+
+ perf_mmap__write_tail(map, old);
+ }
+
+ if (refcount_read(&map->refcnt) == 1 && perf_mmap__empty(map))
+ perf_mmap__put(map);
+}
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 3297d2eb67fc..6d8a49b0d4e0 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -12,6 +12,7 @@
#include "parse-events.h"
#include <errno.h>
#include <linux/string.h>
+#include <perf/mmap.h>
#define NR_ITERS 111
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 20cacf1e980b..79acb857841c 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -15,6 +15,7 @@
#include <linux/string.h>
#include <api/fs/fs.h>
#include <bpf/bpf.h>
+#include <perf/mmap.h>
#include "tests.h"
#include "llvm.h"
#include "debug.h"
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 77dc68a23b70..8ce99aeadb34 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -10,6 +10,7 @@
#include <sys/param.h>
#include <perf/cpumap.h>
#include <perf/evlist.h>
+#include <perf/mmap.h>
#include "debug.h"
#include "dso.h"
@@ -429,7 +430,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
while ((event = perf_mmap__read_event(md)) != NULL) {
ret = process_event(machine, evlist, event, state);
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
if (ret < 0)
return ret;
}
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 2623b925b87f..2169d74d9872 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -5,6 +5,7 @@
#include <sys/prctl.h>
#include <perf/cpumap.h>
#include <perf/evlist.h>
+#include <perf/mmap.h>
#include "debug.h"
#include "parse-events.h"
@@ -46,7 +47,7 @@ static int find_comm(struct evlist *evlist, const char *comm)
(pid_t)event->comm.tid == getpid() &&
strcmp(event->comm.comm, comm) == 0)
found += 1;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
}
perf_mmap__read_done(md);
}
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 9b3b11702850..18dd25ed8a2c 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -16,6 +16,7 @@
#include <linux/kernel.h>
#include <linux/string.h>
#include <perf/evlist.h>
+#include <perf/mmap.h>
/*
* This test will generate random numbers of calls to some getpid syscalls,
@@ -139,7 +140,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
goto out_delete_evlist;
}
nr_events[evsel->idx]++;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
}
perf_mmap__read_done(md);
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index a5daf4cf17ac..878d32237fb3 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -12,6 +12,7 @@
#include "tests.h"
#include "debug.h"
#include <errno.h>
+#include <perf/mmap.h>
#ifndef O_DIRECTORY
#define O_DIRECTORY 00200000
@@ -102,7 +103,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
++nr_events;
if (type != PERF_RECORD_SAMPLE) {
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
continue;
}
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 1b313da8bce9..b2552ee06329 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -6,6 +6,7 @@
#include <pthread.h>
#include <sched.h>
+#include <perf/mmap.h>
#include "evlist.h"
#include "evsel.h"
#include "debug.h"
@@ -275,7 +276,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
++errs;
}
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
}
perf_mmap__read_done(md);
}
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index fbff60815be8..67615d90cd73 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -14,6 +14,7 @@
#include "util/cpumap.h"
#include "util/thread_map.h"
#include <perf/evlist.h>
+#include <perf/mmap.h>
#define NR_LOOPS 10000000
@@ -116,7 +117,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
total_periods += sample.period;
nr_samples++;
next_event:
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
}
perf_mmap__read_done(md);
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 29f503820a1e..529b39f39299 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -8,6 +8,7 @@
#include <linux/zalloc.h>
#include <perf/cpumap.h>
#include <perf/evlist.h>
+#include <perf/mmap.h>
#include "debug.h"
#include "parse-events.h"
@@ -275,7 +276,7 @@ static int process_events(struct evlist *evlist,
while ((event = perf_mmap__read_event(md)) != NULL) {
cnt += 1;
ret = add_event(evlist, &events, event);
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
if (ret < 0)
goto out_free_nodes;
}
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index e6e8a7a970b6..4fd52522357a 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -11,6 +11,7 @@
#include <signal.h>
#include <linux/string.h>
#include <perf/evlist.h>
+#include <perf/mmap.h>
static int exited;
static int nr_exit;
@@ -123,7 +124,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
if (event->header.type == PERF_RECORD_EXIT)
nr_exit++;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
}
perf_mmap__read_done(md);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f1af59df1167..e9cc637881b8 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -41,6 +41,7 @@
#include <perf/evlist.h>
#include <perf/evsel.h>
#include <perf/cpumap.h>
+#include <perf/mmap.h>
#include <internal/xyarray.h>
@@ -1761,7 +1762,7 @@ static void *perf_evlist__poll_thread(void *arg)
else
pr_warning("cannot locate proper evsel for the side band event\n");
- perf_mmap__consume(map);
+ perf_mmap__consume(&map->core);
got_data = true;
}
perf_mmap__read_done(map);
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 4b1d1ae79042..5ec12483e79d 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -12,6 +12,7 @@
#include <linux/zalloc.h>
#include <stdlib.h>
#include <string.h>
+#include <perf/mmap.h>
#ifdef HAVE_LIBNUMA_SUPPORT
#include <numaif.h>
#endif
@@ -94,7 +95,7 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
/* non-overwirte doesn't pause the ringbuffer */
if (!map->core.overwrite)
- map->core.end = perf_mmap__read_head(map);
+ map->core.end = perf_mmap__read_head(&map->core);
event = perf_mmap__read(map, &map->core.start, map->core.end);
@@ -104,25 +105,6 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
return event;
}
-static bool perf_mmap__empty(struct mmap *map)
-{
- struct perf_event_mmap_page *pc = map->core.base;
-
- return perf_mmap__read_head(map) == map->core.prev && !pc->aux_size;
-}
-
-void perf_mmap__consume(struct mmap *map)
-{
- if (!map->core.overwrite) {
- u64 old = map->core.prev;
-
- perf_mmap__write_tail(map, old);
- }
-
- if (refcount_read(&map->core.refcnt) == 1 && perf_mmap__empty(map))
- perf_mmap__put(&map->core);
-}
-
int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
struct auxtrace_mmap_params *mp __maybe_unused,
void *userpg __maybe_unused,
@@ -419,7 +401,7 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
*/
static int __perf_mmap__read_init(struct mmap *md)
{
- u64 head = perf_mmap__read_head(md);
+ u64 head = perf_mmap__read_head(&md->core);
u64 old = md->core.prev;
unsigned char *data = md->core.base + page_size;
unsigned long size;
@@ -436,7 +418,7 @@ static int __perf_mmap__read_init(struct mmap *md)
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
md->core.prev = head;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
return -EAGAIN;
}
@@ -465,7 +447,7 @@ int perf_mmap__read_init(struct mmap *map)
int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size))
{
- u64 head = perf_mmap__read_head(md);
+ u64 head = perf_mmap__read_head(&md->core);
unsigned char *data = md->core.base + page_size;
unsigned long size;
void *buf;
@@ -498,7 +480,7 @@ int perf_mmap__push(struct mmap *md, void *to,
}
md->core.prev = head;
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
out:
return rc;
}
@@ -517,5 +499,5 @@ void perf_mmap__read_done(struct mmap *map)
if (!refcount_read(&map->core.refcnt))
return;
- map->core.prev = perf_mmap__read_head(map);
+ map->core.prev = perf_mmap__read_head(&map->core);
}
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 8a8f99cc7ecd..d90554168127 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -73,18 +73,6 @@ struct mmap_params {
int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
void mmap__munmap(struct mmap *map);
-void perf_mmap__consume(struct mmap *map);
-
-static inline u64 perf_mmap__read_head(struct mmap *mm)
-{
- return ring_buffer_read_head(mm->core.base);
-}
-
-static inline void perf_mmap__write_tail(struct mmap *md, u64 tail)
-{
- ring_buffer_write_tail(md->core.base, tail);
-}
-
union perf_event *perf_mmap__read_forward(struct mmap *map);
union perf_event *perf_mmap__read_event(struct mmap *map);
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 48fd93a6a247..04c1d350a9c5 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -7,6 +7,7 @@
#include <perf/cpumap.h>
#include <traceevent/event-parse.h>
#include "debug.h"
+#include <perf/mmap.h>
#include "evlist.h"
#include "callchain.h"
#include "evsel.h"
@@ -1039,7 +1040,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
err = perf_evsel__parse_sample(evsel, event, &pevent->sample);
/* Consume the even only after we parsed it out. */
- perf_mmap__consume(md);
+ perf_mmap__consume(&md->core);
if (err)
return PyErr_Format(PyExc_OSError,
--
2.21.0
Move perf_mmap__get function under libperf
to internal header internal/mmap.h.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 2 +-
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/lib/mmap.c | 5 +++++
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 5 -----
tools/perf/util/mmap.h | 1 -
6 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 40780434b23e..82f6bd6b1adc 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -290,7 +290,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size
* after started aio request completion or at record__aio_push()
* if the request failed to start.
*/
- perf_mmap__get(map);
+ perf_mmap__get(&map->core);
}
aio->size += size;
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 5452ed7dabfe..372521cae06d 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -39,5 +39,6 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map);
void perf_mmap__init(struct perf_mmap *map, bool overwrite);
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu);
+void perf_mmap__get(struct perf_mmap *map);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index b216a7db857f..b765e0505bb6 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -31,3 +31,8 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
map->cpu = cpu;
return 0;
}
+
+void perf_mmap__get(struct perf_mmap *map)
+{
+ refcount_inc(&map->refcnt);
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 8da573307734..0191d3b2eb20 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -676,7 +676,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
return -1;
- perf_mmap__get(&maps[idx]);
+ perf_mmap__get(&maps[idx].core);
}
revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 7096e9b130cd..a7e0b4afc176 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -109,11 +109,6 @@ static bool perf_mmap__empty(struct mmap *map)
return perf_mmap__read_head(map) == map->core.prev && !map->auxtrace_mmap.base;
}
-void perf_mmap__get(struct mmap *map)
-{
- refcount_inc(&map->core.refcnt);
-}
-
void perf_mmap__put(struct mmap *map)
{
BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0);
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index aeb94d128354..f7ee0252db24 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -73,7 +73,6 @@ struct mmap_params {
int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
void perf_mmap__munmap(struct mmap *map);
-void perf_mmap__get(struct mmap *map);
void perf_mmap__put(struct mmap *map);
void perf_mmap__consume(struct mmap *map);
--
2.21.0
Move perf_mmap__mmap function under libperf,
it will be used in following patches. And rename
the existing perf's function to mmap__mmap.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/mmap.c | 18 ++++++++++++++++++
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 12 +++---------
tools/perf/util/mmap.h | 2 +-
5 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 45ab791aa392..5452ed7dabfe 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -37,5 +37,7 @@ struct perf_mmap_param {
size_t perf_mmap__mmap_len(struct perf_mmap *map);
void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+ int fd, int cpu);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index cc4284da4d99..b216a7db857f 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include <sys/mman.h>
#include <internal/mmap.h>
#include <internal/lib.h>
@@ -13,3 +14,20 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map)
{
return map->mask + 1 + page_size;
}
+
+int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+ int fd, int cpu)
+{
+ map->prev = 0;
+ map->mask = mp->mask;
+ map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
+ MAP_SHARED, fd, 0);
+ if (map->base == MAP_FAILED) {
+ map->base = NULL;
+ return -1;
+ }
+
+ map->fd = fd;
+ map->cpu = cpu;
+ return 0;
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c0c0882dc343..8da573307734 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -670,7 +670,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
if (*output == -1) {
*output = fd;
- if (perf_mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0)
+ if (mmap__mmap(&maps[idx], mp, *output, evlist_cpu) < 0)
return -1;
} else {
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 4e2ef633d425..7096e9b130cd 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -352,7 +352,7 @@ static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params
CPU_SET(map->core.cpu, &map->affinity_mask);
}
-int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
+int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
{
/*
* The last one will be done at perf_mmap__consume(), so that we
@@ -368,18 +368,12 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
* perf_evlist__filter_pollfd().
*/
refcount_set(&map->core.refcnt, 2);
- map->core.prev = 0;
- map->core.mask = mp->core.mask;
- map->core.base = mmap(NULL, mmap__mmap_len(map), mp->core.prot,
- MAP_SHARED, fd, 0);
- if (map->core.base == MAP_FAILED) {
+
+ if (perf_mmap__mmap(&map->core, &mp->core, fd, cpu)) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
errno);
- map->core.base = NULL;
return -1;
}
- map->core.fd = fd;
- map->core.cpu = cpu;
perf_mmap__setup_affinity_mask(map, mp);
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 308492a59ea1..aeb94d128354 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -70,7 +70,7 @@ struct mmap_params {
struct auxtrace_mmap_params auxtrace_mp;
};
-int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
+int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
void perf_mmap__munmap(struct mmap *map);
void perf_mmap__get(struct mmap *map);
--
2.21.0
Adding perf_evlist_mmap_ops::mmap callback to be called
in mmap_per_evsel to actually mmap the map.
Adding libperf's perf_evlist__mmap_cb_mmap function as
libperf's mmap callback.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 15 ++++++++++++---
tools/perf/lib/include/internal/evlist.h | 3 +++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 8caced7d489a..ec83022cd62f 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -341,6 +341,14 @@ perf_evlist__mmap_cb_new(struct perf_evlist *evlist, bool overwrite, int idx)
return map;
}
+static int
+perf_evlist__mmap_cb_mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+ int output, int cpu)
+{
+ refcount_set(&map->refcnt, 2);
+ return perf_mmap__mmap(map, mp, output, cpu);
+}
+
static int
mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
int idx, struct perf_mmap_param *mp, int cpu_idx,
@@ -379,7 +387,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
if (*output == -1) {
*output = fd;
- if (perf_mmap__mmap(map, mp, *output, evlist_cpu) < 0)
+ if (ops->mmap(map, mp, *output, evlist_cpu) < 0)
return -1;
} else {
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
@@ -471,7 +479,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;
- if (!ops || !ops->new)
+ if (!ops || !ops->new || !ops->mmap)
return -EINVAL;
perf_evlist__for_each_entry(evlist, evsel) {
@@ -491,7 +499,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
{
struct perf_mmap_param mp;
struct perf_evlist_mmap_ops ops = {
- .new = perf_evlist__mmap_cb_new,
+ .new = perf_evlist__mmap_cb_new,
+ .mmap = perf_evlist__mmap_cb_mmap,
};
if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 3cb836912ee6..851837ce4ff8 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -31,10 +31,13 @@ typedef void
(*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool);
typedef struct perf_mmap*
(*perf_evlist_mmap__cb_new_t)(struct perf_evlist*, bool, int);
+typedef int
+(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, int);
struct perf_evlist_mmap_ops {
perf_evlist_mmap__cb_idx_t idx;
perf_evlist_mmap__cb_new_t new;
+ perf_evlist_mmap__cb_mmap_t mmap;
};
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
--
2.21.0
Moving mmap_len from struct evlist to struct perf_evlist
it will be used in following patches.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 2 +-
tools/perf/lib/include/internal/evlist.h | 1 +
tools/perf/util/evlist.c | 10 +++++-----
tools/perf/util/evlist.h | 1 -
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 6e9f5619f062..68091f3773a8 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1407,7 +1407,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
err = -1;
goto out_child;
}
- session->header.env.comp_mmap_len = session->evlist->mmap_len;
+ session->header.env.comp_mmap_len = session->evlist->core.mmap_len;
err = bpf__apply_obj_config();
if (err) {
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 035c1e1cc324..01b813616440 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -14,6 +14,7 @@ struct perf_evlist {
struct perf_cpu_map *cpus;
struct perf_thread_map *threads;
int nr_mmaps;
+ size_t mmap_len;
};
/**
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 891052570e73..07f02afa3407 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1011,11 +1011,11 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
return -ENOMEM;
- evlist->mmap_len = evlist__mmap_size(pages);
- pr_debug("mmap size %zuB\n", evlist->mmap_len);
- mp.mask = evlist->mmap_len - page_size - 1;
+ evlist->core.mmap_len = evlist__mmap_size(pages);
+ pr_debug("mmap size %zuB\n", evlist->core.mmap_len);
+ mp.mask = evlist->core.mmap_len - page_size - 1;
- auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->mmap_len,
+ auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->core.mmap_len,
auxtrace_pages, auxtrace_overwrite);
evlist__for_each_entry(evlist, evsel) {
@@ -1599,7 +1599,7 @@ int perf_evlist__strerror_open(struct evlist *evlist,
int perf_evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size)
{
char sbuf[STRERR_BUFSIZE], *emsg = str_error_r(err, sbuf, sizeof(sbuf));
- int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user, printed = 0;
+ int pages_attempted = evlist->core.mmap_len / 1024, pages_max_per_user, printed = 0;
switch (err) {
case EPERM:
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 4c465b4aced8..3767866e98c1 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -28,7 +28,6 @@ struct evlist {
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
int nr_groups;
bool enabled;
- size_t mmap_len;
int id_pos;
int is_pos;
u64 combined_sample_type;
--
2.21.0
Move ids from struct evsel to libperf's struct perf_evsel.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/evsel.h | 1 +
tools/perf/util/evlist.c | 2 +-
tools/perf/util/evsel.c | 2 +-
tools/perf/util/evsel.h | 1 -
tools/perf/util/header.c | 16 ++++++++--------
tools/perf/util/intel-bts.c | 2 +-
tools/perf/util/intel-pt.c | 2 +-
tools/perf/util/session.c | 4 ++--
8 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index bea14e6e28f5..0b04065cae8e 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -17,6 +17,7 @@ struct perf_evsel {
struct xyarray *fd;
struct xyarray *sample_id;
u64 *id;
+ u32 ids;
/* parse modifier helper */
int nr_members;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index ae7f62ae1d29..9dcecb5e05a0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -481,7 +481,7 @@ void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel,
int cpu, int thread, u64 id)
{
perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
- evsel->core.id[evsel->ids++] = id;
+ evsel->core.id[evsel->core.ids++] = id;
}
int perf_evlist__id_add_fd(struct evlist *evlist,
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 194bead17f64..7501b4403b7f 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1253,7 +1253,7 @@ static void perf_evsel__free_id(struct evsel *evsel)
xyarray__delete(evsel->core.sample_id);
evsel->core.sample_id = NULL;
zfree(&evsel->core.id);
- evsel->ids = 0;
+ evsel->core.ids = 0;
}
static void perf_evsel__free_config_terms(struct evsel *evsel)
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index f313e07925c4..765f722fc128 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -120,7 +120,6 @@ struct evsel {
struct perf_counts *counts;
struct perf_counts *prev_raw_counts;
int idx;
- u32 ids;
unsigned long max_events;
unsigned long nr_events_printed;
char *name;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index ebdabaa33d8b..360fc61c5754 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -524,7 +524,7 @@ static int write_event_desc(struct feat_fd *ff,
* copy into an nri to be independent of the
* type of ids,
*/
- nri = evsel->ids;
+ nri = evsel->core.ids;
ret = do_write(ff, &nri, sizeof(nri));
if (ret < 0)
return ret;
@@ -538,7 +538,7 @@ static int write_event_desc(struct feat_fd *ff,
/*
* write unique ids for this event
*/
- ret = do_write(ff, evsel->core.id, evsel->ids * sizeof(u64));
+ ret = do_write(ff, evsel->core.id, evsel->core.ids * sizeof(u64));
if (ret < 0)
return ret;
}
@@ -1664,7 +1664,7 @@ static struct evsel *read_event_desc(struct feat_fd *ff)
id = calloc(nr, sizeof(*id));
if (!id)
goto error;
- evsel->ids = nr;
+ evsel->core.ids = nr;
evsel->core.id = id;
for (j = 0 ; j < nr; j++) {
@@ -1707,9 +1707,9 @@ static void print_event_desc(struct feat_fd *ff, FILE *fp)
for (evsel = events; evsel->core.attr.size; evsel++) {
fprintf(fp, "# event : name = %s, ", evsel->name);
- if (evsel->ids) {
+ if (evsel->core.ids) {
fprintf(fp, ", id = {");
- for (j = 0, id = evsel->core.id; j < evsel->ids; j++, id++) {
+ for (j = 0, id = evsel->core.id; j < evsel->core.ids; j++, id++) {
if (j)
fputc(',', fp);
fprintf(fp, " %"PRIu64, *id);
@@ -3083,7 +3083,7 @@ int perf_session__write_header(struct perf_session *session,
evlist__for_each_entry(session->evlist, evsel) {
evsel->id_offset = lseek(fd, 0, SEEK_CUR);
- err = do_write(&ff, evsel->core.id, evsel->ids * sizeof(u64));
+ err = do_write(&ff, evsel->core.id, evsel->core.ids * sizeof(u64));
if (err < 0) {
pr_debug("failed to write perf header\n");
return err;
@@ -3097,7 +3097,7 @@ int perf_session__write_header(struct perf_session *session,
.attr = evsel->core.attr,
.ids = {
.offset = evsel->id_offset,
- .size = evsel->ids * sizeof(u64),
+ .size = evsel->core.ids * sizeof(u64),
}
};
err = do_write(&ff, &f_attr, sizeof(f_attr));
@@ -3951,7 +3951,7 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
int err = 0;
evlist__for_each_entry(evlist, evsel) {
- err = perf_event__synthesize_attr(tool, &evsel->core.attr, evsel->ids,
+ err = perf_event__synthesize_attr(tool, &evsel->core.attr, evsel->core.ids,
evsel->core.id, process);
if (err) {
pr_debug("failed to create perf header attribute\n");
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index daf42915b326..e49d38b21909 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -768,7 +768,7 @@ static int intel_bts_synth_events(struct intel_bts *bts,
int err;
evlist__for_each_entry(evlist, evsel) {
- if (evsel->core.attr.type == bts->pmu_type && evsel->ids) {
+ if (evsel->core.attr.type == bts->pmu_type && evsel->core.ids) {
found = true;
break;
}
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 4a1d46158401..b08d80adfa32 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -2734,7 +2734,7 @@ static struct evsel *intel_pt_evsel(struct intel_pt *pt,
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel) {
- if (evsel->core.attr.type == pt->pmu_type && evsel->ids)
+ if (evsel->core.attr.type == pt->pmu_type && evsel->core.ids)
return evsel;
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index f50cd54cf96b..32226e71949e 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2429,7 +2429,7 @@ int perf_event__synthesize_id_index(struct perf_tool *tool,
sizeof(struct id_index_entry);
evlist__for_each_entry(evlist, evsel)
- nr += evsel->ids;
+ nr += evsel->core.ids;
n = nr > max_nr ? max_nr : nr;
sz = sizeof(struct perf_record_id_index) + n * sizeof(struct id_index_entry);
@@ -2444,7 +2444,7 @@ int perf_event__synthesize_id_index(struct perf_tool *tool,
evlist__for_each_entry(evlist, evsel) {
u32 j;
- for (j = 0; j < evsel->ids; j++) {
+ for (j = 0; j < evsel->core.ids; j++) {
struct id_index_entry *e;
struct perf_sample_id *sid;
--
2.21.0
Moving nr_mmaps from struct evlist to struct perf_evlist,
it will be used in following patches.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/arm/util/cs-etm.c | 2 +-
tools/perf/arch/arm64/util/arm-spe.c | 2 +-
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/arch/x86/util/intel-bts.c | 2 +-
tools/perf/arch/x86/util/intel-pt.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-record.c | 6 +++---
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/include/internal/evlist.h | 1 +
tools/perf/tests/backward-ring-buffer.c | 2 +-
tools/perf/tests/bpf.c | 2 +-
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/keep-tracking.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/switch-tracking.c | 2 +-
tools/perf/util/evlist.c | 16 ++++++++--------
tools/perf/util/evlist.h | 1 -
tools/perf/util/python.c | 2 +-
20 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index c32db09baf0d..6407edf72edd 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -648,7 +648,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
if (priv_size != cs_etm_info_priv_size(itr, session->evlist))
return -EINVAL;
- if (!session->evlist->nr_mmaps)
+ if (!session->evlist->core.nr_mmaps)
return -EINVAL;
/* If the cpu_map is empty all online CPUs are involved */
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 4b364692da67..2fcabddd87b5 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -51,7 +51,7 @@ static int arm_spe_info_fill(struct auxtrace_record *itr,
if (priv_size != ARM_SPE_AUXTRACE_PRIV_SIZE)
return -EINVAL;
- if (!session->evlist->nr_mmaps)
+ if (!session->evlist->core.nr_mmaps)
return -EINVAL;
auxtrace_info->type = PERF_AUXTRACE_ARM_SPE;
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 42725e6882e9..185bdbf8cb9d 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -115,7 +115,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
evlist__disable(evlist);
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
continue;
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index aa13df948049..5dd42e6d22f9 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -74,7 +74,7 @@ static int intel_bts_info_fill(struct auxtrace_record *itr,
if (priv_size != INTEL_BTS_AUXTRACE_PRIV_SIZE)
return -EINVAL;
- if (!session->evlist->nr_mmaps)
+ if (!session->evlist->core.nr_mmaps)
return -EINVAL;
pc = session->evlist->mmap[0].core.base;
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 1ae050c4045b..42f111323c31 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -351,7 +351,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
filter = intel_pt_find_filter(session->evlist, ptr->intel_pt_pmu);
filter_str_len = filter ? strlen(filter) : 0;
- if (!session->evlist->nr_mmaps)
+ if (!session->evlist->core.nr_mmaps)
return -EINVAL;
pc = session->evlist->mmap[0].core.base;
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index da16349f2808..2b8e71d0a722 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -799,7 +799,7 @@ static int perf_kvm__mmap_read(struct perf_kvm_stat *kvm)
s64 n, ntotal = 0;
u64 flush_time = ULLONG_MAX, mmap_time;
- for (i = 0; i < kvm->evlist->nr_mmaps; i++) {
+ for (i = 0; i < kvm->evlist->core.nr_mmaps; i++) {
n = perf_kvm__mmap_read_idx(kvm, i, &mmap_time);
if (n < 0)
return -1;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 400ce2f3fa99..6e9f5619f062 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -354,7 +354,7 @@ static void record__aio_mmap_read_sync(struct record *rec)
if (!record__aio_enabled(rec))
return;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
struct mmap *map = &maps[i];
if (map->core.base)
@@ -600,7 +600,7 @@ static int record__auxtrace_read_snapshot_all(struct record *rec)
int i;
int rc = 0;
- for (i = 0; i < rec->evlist->nr_mmaps; i++) {
+ for (i = 0; i < rec->evlist->core.nr_mmaps; i++) {
struct mmap *map = &rec->evlist->mmap[i];
if (!map->auxtrace_mmap.base)
@@ -952,7 +952,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
if (record__aio_enabled(rec))
off = record__aio_get_pos(trace_fd);
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
u64 flush = 0;
struct mmap *map = &maps[i];
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 9adc91d06e16..5698234cef88 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -901,7 +901,7 @@ static void perf_top__mmap_read(struct perf_top *top)
if (overwrite)
perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_DATA_PENDING);
- for (i = 0; i < top->evlist->nr_mmaps; i++)
+ for (i = 0; i < top->evlist->core.nr_mmaps; i++)
perf_top__mmap_read_idx(top, i);
if (overwrite) {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c2e842a6467b..6e9797d85d54 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3441,7 +3441,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
again:
before = trace->nr_events;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
union perf_event *event;
struct mmap *md;
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 448891f06e3e..035c1e1cc324 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -13,6 +13,7 @@ struct perf_evlist {
bool has_user_cpus;
struct perf_cpu_map *cpus;
struct perf_thread_map *threads;
+ int nr_mmaps;
};
/**
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 3073a68d17b9..3297d2eb67fc 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -32,7 +32,7 @@ static int count_samples(struct evlist *evlist, int *sample_count,
{
int i;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
struct mmap *map = &evlist->overwrite_mmap[i];
union perf_event *event;
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 964731915498..20cacf1e980b 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -178,7 +178,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
(*func)();
evlist__disable(evlist);
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
union perf_event *event;
struct mmap *md;
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 2c2400d93813..72ae94be686e 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -422,7 +422,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
struct mmap *md;
int i, ret;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
continue;
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index ba77eaa215b3..ac44d72e39c3 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -36,7 +36,7 @@ static int find_comm(struct evlist *evlist, const char *comm)
int i, found;
found = 0;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
continue;
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 5c2576174ae9..abf4d4f5e429 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -86,7 +86,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
while (1) {
int before = nr_events;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
union perf_event *event;
struct mmap *md;
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 669fd88e7f30..dbecc66712af 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -164,7 +164,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
while (1) {
int before = total_events;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
union perf_event *event;
struct mmap *md;
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 01bfb087ce22..115eae0f45f1 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -267,7 +267,7 @@ static int process_events(struct evlist *evlist,
struct mmap *md;
int i, ret;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
continue;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0ffa1e9b6243..891052570e73 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -650,7 +650,7 @@ static int perf_evlist__set_paused(struct evlist *evlist, bool value)
if (!evlist->overwrite_mmap)
return 0;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
int fd = evlist->overwrite_mmap[i].core.fd;
int err;
@@ -678,11 +678,11 @@ static void evlist__munmap_nofree(struct evlist *evlist)
int i;
if (evlist->mmap)
- for (i = 0; i < evlist->nr_mmaps; i++)
+ for (i = 0; i < evlist->core.nr_mmaps; i++)
perf_mmap__munmap(&evlist->mmap[i]);
if (evlist->overwrite_mmap)
- for (i = 0; i < evlist->nr_mmaps; i++)
+ for (i = 0; i < evlist->core.nr_mmaps; i++)
perf_mmap__munmap(&evlist->overwrite_mmap[i]);
}
@@ -699,14 +699,14 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
int i;
struct mmap *map;
- evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
+ evlist->core.nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
if (perf_cpu_map__empty(evlist->core.cpus))
- evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
- map = zalloc(evlist->nr_mmaps * sizeof(struct mmap));
+ evlist->core.nr_mmaps = perf_thread_map__nr(evlist->core.threads);
+ map = zalloc(evlist->core.nr_mmaps * sizeof(struct mmap));
if (!map)
return NULL;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
map[i].core.fd = -1;
map[i].core.overwrite = overwrite;
/*
@@ -1846,7 +1846,7 @@ static void *perf_evlist__poll_thread(void *arg)
if (!draining)
perf_evlist__poll(evlist, 1000);
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
struct mmap *map = &evlist->mmap[i];
union perf_event *event;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index b33c5d67410a..4c465b4aced8 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -27,7 +27,6 @@ struct evlist {
struct perf_evlist core;
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
int nr_groups;
- int nr_mmaps;
bool enabled;
size_t mmap_len;
int id_pos;
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 96100ed73dbe..b71b899407df 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -988,7 +988,7 @@ static struct mmap *get_md(struct evlist *evlist, int cpu)
{
int i;
- for (i = 0; i < evlist->nr_mmaps; i++) {
+ for (i = 0; i < evlist->core.nr_mmaps; i++) {
struct mmap *md = &evlist->mmap[i];
if (md->core.cpu == cpu)
--
2.21.0
Move overwrite from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 12 ++++++------
tools/perf/util/mmap.h | 1 -
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 5af28668913c..631e58dbc9e6 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -21,6 +21,7 @@ struct perf_mmap {
u64 prev;
u64 start;
u64 end;
+ bool overwrite;
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f6e0bceec156..98827df5a40a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -708,7 +708,7 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
for (i = 0; i < evlist->nr_mmaps; i++) {
map[i].core.fd = -1;
- map[i].overwrite = overwrite;
+ map[i].core.overwrite = overwrite;
/*
* When the perf_mmap() call is made we grab one refcount, plus
* one extra to let perf_mmap__consume() get the last
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 6ce70ff005cb..a8850ce2c2ff 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -93,12 +93,12 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
return NULL;
/* non-overwirte doesn't pause the ringbuffer */
- if (!map->overwrite)
+ if (!map->core.overwrite)
map->core.end = perf_mmap__read_head(map);
event = perf_mmap__read(map, &map->core.start, map->core.end);
- if (!map->overwrite)
+ if (!map->core.overwrite)
map->core.prev = map->core.start;
return event;
@@ -124,7 +124,7 @@ void perf_mmap__put(struct mmap *map)
void perf_mmap__consume(struct mmap *map)
{
- if (!map->overwrite) {
+ if (!map->core.overwrite) {
u64 old = map->core.prev;
perf_mmap__write_tail(map, old);
@@ -447,15 +447,15 @@ static int __perf_mmap__read_init(struct mmap *md)
unsigned char *data = md->core.base + page_size;
unsigned long size;
- md->core.start = md->overwrite ? head : old;
- md->core.end = md->overwrite ? old : head;
+ md->core.start = md->core.overwrite ? head : old;
+ md->core.end = md->core.overwrite ? old : head;
if ((md->core.end - md->core.start) < md->flush)
return -EAGAIN;
size = md->core.end - md->core.start;
if (size > (unsigned long)(md->core.mask) + 1) {
- if (!md->overwrite) {
+ if (!md->core.overwrite) {
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
md->core.prev = head;
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 16e4a5ca773d..1dea2abe1de5 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -22,7 +22,6 @@ struct aiocb;
*/
struct mmap {
struct perf_mmap core;
- bool overwrite;
struct auxtrace_mmap auxtrace_mmap;
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
#ifdef HAVE_AIO_SUPPORT
--
2.21.0
Move cpu from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/util/mmap.c | 8 ++++----
tools/perf/util/mmap.h | 1 -
tools/perf/util/python.c | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 2cbe2c463c0a..153348724bf3 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -16,6 +16,7 @@ struct perf_mmap {
void *base;
int mask;
int fd;
+ int cpu;
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 40bf124cb658..dc8320891344 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -256,7 +256,7 @@ static int perf_mmap__aio_mmap(struct mmap *map, struct mmap_params *mp)
pr_debug2("failed to allocate data buffer area, error %m");
return -1;
}
- ret = perf_mmap__aio_bind(map, i, map->cpu, mp->affinity);
+ ret = perf_mmap__aio_bind(map, i, map->core.cpu, mp->affinity);
if (ret == -1)
return -1;
/*
@@ -347,9 +347,9 @@ static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params
{
CPU_ZERO(&map->affinity_mask);
if (mp->affinity == PERF_AFFINITY_NODE && cpu__max_node() > 1)
- build_node_mask(cpu__get_node(map->cpu), &map->affinity_mask);
+ build_node_mask(cpu__get_node(map->core.cpu), &map->affinity_mask);
else if (mp->affinity == PERF_AFFINITY_CPU)
- CPU_SET(map->cpu, &map->affinity_mask);
+ CPU_SET(map->core.cpu, &map->affinity_mask);
}
int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
@@ -379,7 +379,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
return -1;
}
map->core.fd = fd;
- map->cpu = cpu;
+ map->core.cpu = cpu;
perf_mmap__setup_affinity_mask(map, mp);
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 6eb7a4c6b14a..bab46642e639 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -22,7 +22,6 @@ struct aiocb;
*/
struct mmap {
struct perf_mmap core;
- int cpu;
refcount_t refcnt;
u64 prev;
u64 start;
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 7e28f7e18d41..96100ed73dbe 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -991,7 +991,7 @@ static struct mmap *get_md(struct evlist *evlist, int cpu)
for (i = 0; i < evlist->nr_mmaps; i++) {
struct mmap *md = &evlist->mmap[i];
- if (md->cpu == cpu)
+ if (md->core.cpu == cpu)
return md;
}
--
2.21.0
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/Makefile | 1 +
tools/perf/lib/tests/Makefile | 2 ++
2 files changed, 3 insertions(+)
diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index 0f233638ef1f..20396f68fcad 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -73,6 +73,7 @@ override CFLAGS += -Werror -Wall
override CFLAGS += -fPIC
override CFLAGS += $(INCLUDES)
override CFLAGS += -fvisibility=hidden
+override CFLAGS += -D_GNU_SOURCE
all:
diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
index a43cd08c5c03..78c3d8c83c53 100644
--- a/tools/perf/lib/tests/Makefile
+++ b/tools/perf/lib/tests/Makefile
@@ -12,6 +12,8 @@ else
CFLAGS := -g -Wall
endif
+CFLAGS += -D_GNU_SOURCE
+
all:
include $(srctree)/tools/scripts/Makefile.include
--
2.21.0
Move refcnt from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 18 +++++++++---------
tools/perf/util/mmap.h | 1 -
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 153348724bf3..96a8a278340c 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -17,6 +17,7 @@ struct perf_mmap {
int mask;
int fd;
int cpu;
+ refcount_t refcnt;
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 57b117532ade..f6e0bceec156 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -718,7 +718,7 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
* Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
* thus does perf_mmap__get() on it.
*/
- refcount_set(&map[i].refcnt, 0);
+ refcount_set(&map[i].core.refcnt, 0);
}
return map;
}
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index dc8320891344..d6406d216cfe 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -89,7 +89,7 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
/*
* Check if event was unmapped due to a POLLHUP/POLLERR.
*/
- if (!refcount_read(&map->refcnt))
+ if (!refcount_read(&map->core.refcnt))
return NULL;
/* non-overwirte doesn't pause the ringbuffer */
@@ -111,14 +111,14 @@ static bool perf_mmap__empty(struct mmap *map)
void perf_mmap__get(struct mmap *map)
{
- refcount_inc(&map->refcnt);
+ refcount_inc(&map->core.refcnt);
}
void perf_mmap__put(struct mmap *map)
{
- BUG_ON(map->core.base && refcount_read(&map->refcnt) == 0);
+ BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0);
- if (refcount_dec_and_test(&map->refcnt))
+ if (refcount_dec_and_test(&map->core.refcnt))
perf_mmap__munmap(map);
}
@@ -130,7 +130,7 @@ void perf_mmap__consume(struct mmap *map)
perf_mmap__write_tail(map, old);
}
- if (refcount_read(&map->refcnt) == 1 && perf_mmap__empty(map))
+ if (refcount_read(&map->core.refcnt) == 1 && perf_mmap__empty(map))
perf_mmap__put(map);
}
@@ -321,7 +321,7 @@ void perf_mmap__munmap(struct mmap *map)
munmap(map->core.base, perf_mmap__mmap_len(map));
map->core.base = NULL;
map->core.fd = -1;
- refcount_set(&map->refcnt, 0);
+ refcount_set(&map->core.refcnt, 0);
}
auxtrace_mmap__munmap(&map->auxtrace_mmap);
}
@@ -367,7 +367,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
* evlist layer can't just drop it when filtering events in
* perf_evlist__filter_pollfd().
*/
- refcount_set(&map->refcnt, 2);
+ refcount_set(&map->core.refcnt, 2);
map->prev = 0;
map->core.mask = mp->mask;
map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
@@ -479,7 +479,7 @@ int perf_mmap__read_init(struct mmap *map)
/*
* Check if event was unmapped due to a POLLHUP/POLLERR.
*/
- if (!refcount_read(&map->refcnt))
+ if (!refcount_read(&map->core.refcnt))
return -ENOENT;
return __perf_mmap__read_init(map);
@@ -537,7 +537,7 @@ void perf_mmap__read_done(struct mmap *map)
/*
* Check if event was unmapped due to a POLLHUP/POLLERR.
*/
- if (!refcount_read(&map->refcnt))
+ if (!refcount_read(&map->core.refcnt))
return;
map->prev = perf_mmap__read_head(map);
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index bab46642e639..117ba39f0f7a 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -22,7 +22,6 @@ struct aiocb;
*/
struct mmap {
struct perf_mmap core;
- refcount_t refcnt;
u64 prev;
u64 start;
u64 end;
--
2.21.0
We have direct fprintf call in the header, so we need
stdio.h include, otherwise it could fail compilation
if there's no prior stdio.h include.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/include/asm/bug.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/include/asm/bug.h b/tools/include/asm/bug.h
index bbd75ac8b202..550223f0a6e6 100644
--- a/tools/include/asm/bug.h
+++ b/tools/include/asm/bug.h
@@ -3,6 +3,7 @@
#define _TOOLS_ASM_BUG_H
#include <linux/compiler.h>
+#include <stdio.h>
#define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0)
--
2.21.0
Rename struct perf_evlist to struct evlist, so we don't have
a name clash when we add struct perf_mmap in libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-record.c | 34 ++++++------
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/tests/backward-ring-buffer.c | 2 +-
tools/perf/tests/bpf.c | 2 +-
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/keep-tracking.c | 2 +-
tools/perf/tests/mmap-basic.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/sw-clock.c | 2 +-
tools/perf/tests/switch-tracking.c | 2 +-
tools/perf/tests/task-exit.c | 2 +-
tools/perf/util/auxtrace.c | 6 +--
tools/perf/util/auxtrace.h | 8 +--
tools/perf/util/evlist.c | 14 ++---
tools/perf/util/evlist.h | 4 +-
tools/perf/util/mmap.c | 54 ++++++++++----------
tools/perf/util/mmap.h | 32 ++++++------
tools/perf/util/python.c | 6 +--
22 files changed, 93 insertions(+), 93 deletions(-)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index eb3635941c2b..181e76dc597a 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -66,7 +66,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
union perf_event *event;
u64 test_tsc, comm1_tsc, comm2_tsc;
u64 test_time, comm1_time = 0, comm2_time = 0;
- struct perf_mmap *md;
+ struct mmap *md;
threads = thread_map__new(-1, getpid(), UINT_MAX);
CHECK_NOT_NULL__(threads);
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 0a4fcbe32bf6..cb40c5c38b44 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -748,7 +748,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
{
struct evlist *evlist = kvm->evlist;
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
u64 timestamp;
s64 n = 0;
int err;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1447004eee8a..949ea29fae66 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -117,7 +117,7 @@ static bool switch_output_time(struct record *rec)
trigger_is_ready(&switch_output_trigger);
}
-static int record__write(struct record *rec, struct perf_mmap *map __maybe_unused,
+static int record__write(struct record *rec, struct mmap *map __maybe_unused,
void *bf, size_t size)
{
struct perf_data_file *file = &rec->session->data->file;
@@ -166,7 +166,7 @@ static int record__aio_write(struct aiocb *cblock, int trace_fd,
return rc;
}
-static int record__aio_complete(struct perf_mmap *md, struct aiocb *cblock)
+static int record__aio_complete(struct mmap *md, struct aiocb *cblock)
{
void *rem_buf;
off_t rem_off;
@@ -212,7 +212,7 @@ static int record__aio_complete(struct perf_mmap *md, struct aiocb *cblock)
return rc;
}
-static int record__aio_sync(struct perf_mmap *md, bool sync_all)
+static int record__aio_sync(struct mmap *md, bool sync_all)
{
struct aiocb **aiocb = md->aio.aiocb;
struct aiocb *cblocks = md->aio.cblocks;
@@ -253,7 +253,7 @@ struct record_aio {
size_t size;
};
-static int record__aio_pushfn(struct perf_mmap *map, void *to, void *buf, size_t size)
+static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size)
{
struct record_aio *aio = to;
@@ -298,7 +298,7 @@ static int record__aio_pushfn(struct perf_mmap *map, void *to, void *buf, size_t
return size;
}
-static int record__aio_push(struct record *rec, struct perf_mmap *map, off_t *off)
+static int record__aio_push(struct record *rec, struct mmap *map, off_t *off)
{
int ret, idx;
int trace_fd = rec->session->data->file.fd;
@@ -349,13 +349,13 @@ static void record__aio_mmap_read_sync(struct record *rec)
{
int i;
struct evlist *evlist = rec->evlist;
- struct perf_mmap *maps = evlist->mmap;
+ struct mmap *maps = evlist->mmap;
if (!record__aio_enabled(rec))
return;
for (i = 0; i < evlist->nr_mmaps; i++) {
- struct perf_mmap *map = &maps[i];
+ struct mmap *map = &maps[i];
if (map->base)
record__aio_sync(map, true);
@@ -385,7 +385,7 @@ static int record__aio_parse(const struct option *opt,
#else /* HAVE_AIO_SUPPORT */
static int nr_cblocks_max = 0;
-static int record__aio_push(struct record *rec __maybe_unused, struct perf_mmap *map __maybe_unused,
+static int record__aio_push(struct record *rec __maybe_unused, struct mmap *map __maybe_unused,
off_t *off __maybe_unused)
{
return -1;
@@ -480,7 +480,7 @@ static int process_synthesized_event(struct perf_tool *tool,
return record__write(rec, NULL, event, event->header.size);
}
-static int record__pushfn(struct perf_mmap *map, void *to, void *bf, size_t size)
+static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size)
{
struct record *rec = to;
@@ -525,7 +525,7 @@ static void record__sig_exit(void)
#ifdef HAVE_AUXTRACE_SUPPORT
static int record__process_auxtrace(struct perf_tool *tool,
- struct perf_mmap *map,
+ struct mmap *map,
union perf_event *event, void *data1,
size_t len1, void *data2, size_t len2)
{
@@ -563,7 +563,7 @@ static int record__process_auxtrace(struct perf_tool *tool,
}
static int record__auxtrace_mmap_read(struct record *rec,
- struct perf_mmap *map)
+ struct mmap *map)
{
int ret;
@@ -579,7 +579,7 @@ static int record__auxtrace_mmap_read(struct record *rec,
}
static int record__auxtrace_mmap_read_snapshot(struct record *rec,
- struct perf_mmap *map)
+ struct mmap *map)
{
int ret;
@@ -601,7 +601,7 @@ static int record__auxtrace_read_snapshot_all(struct record *rec)
int rc = 0;
for (i = 0; i < rec->evlist->nr_mmaps; i++) {
- struct perf_mmap *map = &rec->evlist->mmap[i];
+ struct mmap *map = &rec->evlist->mmap[i];
if (!map->auxtrace_mmap.base)
continue;
@@ -666,7 +666,7 @@ static int record__auxtrace_init(struct record *rec)
static inline
int record__auxtrace_mmap_read(struct record *rec __maybe_unused,
- struct perf_mmap *map __maybe_unused)
+ struct mmap *map __maybe_unused)
{
return 0;
}
@@ -888,7 +888,7 @@ static struct perf_event_header finished_round_event = {
.type = PERF_RECORD_FINISHED_ROUND,
};
-static void record__adjust_affinity(struct record *rec, struct perf_mmap *map)
+static void record__adjust_affinity(struct record *rec, struct mmap *map)
{
if (rec->opts.affinity != PERF_AFFINITY_SYS &&
!CPU_EQUAL(&rec->affinity_mask, &map->affinity_mask)) {
@@ -935,7 +935,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
u64 bytes_written = rec->bytes_written;
int i;
int rc = 0;
- struct perf_mmap *maps;
+ struct mmap *maps;
int trace_fd = rec->data.file.fd;
off_t off = 0;
@@ -954,7 +954,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
for (i = 0; i < evlist->nr_mmaps; i++) {
u64 flush = 0;
- struct perf_mmap *map = &maps[i];
+ struct mmap *map = &maps[i];
if (map->base) {
record__adjust_affinity(rec, map);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 726e3f2dd8c7..5802ca9ca849 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -861,7 +861,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
{
struct record_opts *opts = &top->record_opts;
struct evlist *evlist = top->evlist;
- struct perf_mmap *md;
+ struct mmap *md;
union perf_event *event;
md = opts->overwrite ? &evlist->overwrite_mmap[idx] : &evlist->mmap[idx];
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 0f633f0d6be8..fa813187fb0d 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3443,7 +3443,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index a637a4a90760..0a046096e6f4 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -33,7 +33,7 @@ static int count_samples(struct evlist *evlist, int *sample_count,
int i;
for (i = 0; i < evlist->nr_mmaps; i++) {
- struct perf_mmap *map = &evlist->overwrite_mmap[i];
+ struct mmap *map = &evlist->overwrite_mmap[i];
union perf_event *event;
perf_mmap__read_init(map);
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index fc102e4f403e..cf9776aceb82 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -180,7 +180,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index c1c29e08e7fb..1e755c4f066d 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -419,7 +419,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
struct state *state)
{
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
int i, ret;
for (i = 0; i < evlist->nr_mmaps; i++) {
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 9f0762d987fa..0c10d992d815 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -32,7 +32,7 @@
static int find_comm(struct evlist *evlist, const char *comm)
{
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
int i, found;
found = 0;
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 85e1d7337dc0..1bca796ac2bd 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -43,7 +43,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
expected_nr_events[nsyscalls], i, j;
struct evsel *evsels[nsyscalls], *evsel;
char sbuf[STRERR_BUFSIZE];
- struct perf_mmap *md;
+ struct mmap *md;
threads = thread_map__new(-1, getpid(), UINT_MAX);
if (threads == NULL) {
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index b71167b43dda..e5ef74d4e925 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -88,7 +88,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index e1b42292cf7f..49d2d4c5956d 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -166,7 +166,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
for (i = 0; i < evlist->nr_mmaps; i++) {
union perf_event *event;
- struct perf_mmap *md;
+ struct mmap *md;
md = &evlist->mmap[i];
if (perf_mmap__read_init(md) < 0)
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 97694a040986..7abe0b6aabb7 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -42,7 +42,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
};
struct perf_cpu_map *cpus;
struct perf_thread_map *threads;
- struct perf_mmap *md;
+ struct mmap *md;
attr.sample_freq = 500;
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 1a60fa1219f5..8374979ceb22 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -264,7 +264,7 @@ static int process_events(struct evlist *evlist,
unsigned pos, cnt = 0;
LIST_HEAD(events);
struct event_node *events_array, *node;
- struct perf_mmap *md;
+ struct mmap *md;
int i, ret;
for (i = 0; i < evlist->nr_mmaps; i++) {
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index f610e8c0a083..c7e87c588c25 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -51,7 +51,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
char sbuf[STRERR_BUFSIZE];
struct perf_cpu_map *cpus;
struct perf_thread_map *threads;
- struct perf_mmap *md;
+ struct mmap *md;
signal(SIGCHLD, sig_handler);
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 6f25224a3def..60e3a18577a6 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -1226,7 +1226,7 @@ int perf_event__process_auxtrace_error(struct perf_session *session,
return 0;
}
-static int __auxtrace_mmap__read(struct perf_mmap *map,
+static int __auxtrace_mmap__read(struct mmap *map,
struct auxtrace_record *itr,
struct perf_tool *tool, process_auxtrace_t fn,
bool snapshot, size_t snapshot_size)
@@ -1337,13 +1337,13 @@ static int __auxtrace_mmap__read(struct perf_mmap *map,
return 1;
}
-int auxtrace_mmap__read(struct perf_mmap *map, struct auxtrace_record *itr,
+int auxtrace_mmap__read(struct mmap *map, struct auxtrace_record *itr,
struct perf_tool *tool, process_auxtrace_t fn)
{
return __auxtrace_mmap__read(map, itr, tool, fn, false, 0);
}
-int auxtrace_mmap__read_snapshot(struct perf_mmap *map,
+int auxtrace_mmap__read_snapshot(struct mmap *map,
struct auxtrace_record *itr,
struct perf_tool *tool, process_auxtrace_t fn,
size_t snapshot_size)
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 37e70dc01436..8b5d2cc589b0 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -23,7 +23,7 @@ union perf_event;
struct perf_session;
struct evlist;
struct perf_tool;
-struct perf_mmap;
+struct mmap;
struct option;
struct record_opts;
struct perf_record_auxtrace_info;
@@ -444,14 +444,14 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
bool per_cpu);
typedef int (*process_auxtrace_t)(struct perf_tool *tool,
- struct perf_mmap *map,
+ struct mmap *map,
union perf_event *event, void *data1,
size_t len1, void *data2, size_t len2);
-int auxtrace_mmap__read(struct perf_mmap *map, struct auxtrace_record *itr,
+int auxtrace_mmap__read(struct mmap *map, struct auxtrace_record *itr,
struct perf_tool *tool, process_auxtrace_t fn);
-int auxtrace_mmap__read_snapshot(struct perf_mmap *map,
+int auxtrace_mmap__read_snapshot(struct mmap *map,
struct auxtrace_record *itr,
struct perf_tool *tool, process_auxtrace_t fn,
size_t snapshot_size);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 095924aa186b..9a5c90392951 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -423,7 +423,7 @@ int perf_evlist__alloc_pollfd(struct evlist *evlist)
}
static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
- struct perf_mmap *map, short revent)
+ struct mmap *map, short revent)
{
int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
/*
@@ -447,7 +447,7 @@ int perf_evlist__add_pollfd(struct evlist *evlist, int fd)
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
void *arg __maybe_unused)
{
- struct perf_mmap *map = fda->priv[fd].ptr;
+ struct mmap *map = fda->priv[fd].ptr;
if (map)
perf_mmap__put(map);
@@ -693,16 +693,16 @@ void perf_evlist__munmap(struct evlist *evlist)
zfree(&evlist->overwrite_mmap);
}
-static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
+static struct mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
bool overwrite)
{
int i;
- struct perf_mmap *map;
+ struct mmap *map;
evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
if (perf_cpu_map__empty(evlist->core.cpus))
evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
- map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
+ map = zalloc(evlist->nr_mmaps * sizeof(struct mmap));
if (!map)
return NULL;
@@ -741,7 +741,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
evlist__for_each_entry(evlist, evsel) {
- struct perf_mmap *maps = evlist->mmap;
+ struct mmap *maps = evlist->mmap;
int *output = _output;
int fd;
int cpu;
@@ -1847,7 +1847,7 @@ static void *perf_evlist__poll_thread(void *arg)
perf_evlist__poll(evlist, 1000);
for (i = 0; i < evlist->nr_mmaps; i++) {
- struct perf_mmap *map = &evlist->mmap[i];
+ struct mmap *map = &evlist->mmap[i];
union perf_event *event;
if (perf_mmap__read_init(map))
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index a55f0f2546e5..129786361572 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -39,8 +39,8 @@ struct evlist {
pid_t pid;
} workload;
struct fdarray pollfd;
- struct perf_mmap *mmap;
- struct perf_mmap *overwrite_mmap;
+ struct mmap *mmap;
+ struct mmap *overwrite_mmap;
struct evsel *selected;
struct events_stats stats;
struct perf_env *env;
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 33c5b5495482..f3b7c8b0fa90 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -22,13 +22,13 @@
#include "../perf.h"
#include "util.h" /* page_size */
-size_t perf_mmap__mmap_len(struct perf_mmap *map)
+size_t perf_mmap__mmap_len(struct mmap *map)
{
return map->mask + 1 + page_size;
}
/* When check_messup is true, 'end' must points to a good entry */
-static union perf_event *perf_mmap__read(struct perf_mmap *map,
+static union perf_event *perf_mmap__read(struct mmap *map,
u64 *startp, u64 end)
{
unsigned char *data = map->base + page_size;
@@ -82,7 +82,7 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map,
* }
* perf_mmap__read_done()
*/
-union perf_event *perf_mmap__read_event(struct perf_mmap *map)
+union perf_event *perf_mmap__read_event(struct mmap *map)
{
union perf_event *event;
@@ -104,17 +104,17 @@ union perf_event *perf_mmap__read_event(struct perf_mmap *map)
return event;
}
-static bool perf_mmap__empty(struct perf_mmap *map)
+static bool perf_mmap__empty(struct mmap *map)
{
return perf_mmap__read_head(map) == map->prev && !map->auxtrace_mmap.base;
}
-void perf_mmap__get(struct perf_mmap *map)
+void perf_mmap__get(struct mmap *map)
{
refcount_inc(&map->refcnt);
}
-void perf_mmap__put(struct perf_mmap *map)
+void perf_mmap__put(struct mmap *map)
{
BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
@@ -122,7 +122,7 @@ void perf_mmap__put(struct perf_mmap *map)
perf_mmap__munmap(map);
}
-void perf_mmap__consume(struct perf_mmap *map)
+void perf_mmap__consume(struct mmap *map)
{
if (!map->overwrite) {
u64 old = map->prev;
@@ -161,13 +161,13 @@ void __weak auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp __mayb
}
#ifdef HAVE_AIO_SUPPORT
-static int perf_mmap__aio_enabled(struct perf_mmap *map)
+static int perf_mmap__aio_enabled(struct mmap *map)
{
return map->aio.nr_cblocks > 0;
}
#ifdef HAVE_LIBNUMA_SUPPORT
-static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
+static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{
map->aio.data[idx] = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
@@ -179,7 +179,7 @@ static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
return 0;
}
-static void perf_mmap__aio_free(struct perf_mmap *map, int idx)
+static void perf_mmap__aio_free(struct mmap *map, int idx)
{
if (map->aio.data[idx]) {
munmap(map->aio.data[idx], perf_mmap__mmap_len(map));
@@ -187,7 +187,7 @@ static void perf_mmap__aio_free(struct perf_mmap *map, int idx)
}
}
-static int perf_mmap__aio_bind(struct perf_mmap *map, int idx, int cpu, int affinity)
+static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity)
{
void *data;
size_t mmap_len;
@@ -207,7 +207,7 @@ static int perf_mmap__aio_bind(struct perf_mmap *map, int idx, int cpu, int affi
return 0;
}
#else /* !HAVE_LIBNUMA_SUPPORT */
-static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
+static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{
map->aio.data[idx] = malloc(perf_mmap__mmap_len(map));
if (map->aio.data[idx] == NULL)
@@ -216,19 +216,19 @@ static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
return 0;
}
-static void perf_mmap__aio_free(struct perf_mmap *map, int idx)
+static void perf_mmap__aio_free(struct mmap *map, int idx)
{
zfree(&(map->aio.data[idx]));
}
-static int perf_mmap__aio_bind(struct perf_mmap *map __maybe_unused, int idx __maybe_unused,
+static int perf_mmap__aio_bind(struct mmap *map __maybe_unused, int idx __maybe_unused,
int cpu __maybe_unused, int affinity __maybe_unused)
{
return 0;
}
#endif
-static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
+static int perf_mmap__aio_mmap(struct mmap *map, struct mmap_params *mp)
{
int delta_max, i, prio, ret;
@@ -282,7 +282,7 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
return 0;
}
-static void perf_mmap__aio_munmap(struct perf_mmap *map)
+static void perf_mmap__aio_munmap(struct mmap *map)
{
int i;
@@ -294,23 +294,23 @@ static void perf_mmap__aio_munmap(struct perf_mmap *map)
zfree(&map->aio.aiocb);
}
#else /* !HAVE_AIO_SUPPORT */
-static int perf_mmap__aio_enabled(struct perf_mmap *map __maybe_unused)
+static int perf_mmap__aio_enabled(struct mmap *map __maybe_unused)
{
return 0;
}
-static int perf_mmap__aio_mmap(struct perf_mmap *map __maybe_unused,
+static int perf_mmap__aio_mmap(struct mmap *map __maybe_unused,
struct mmap_params *mp __maybe_unused)
{
return 0;
}
-static void perf_mmap__aio_munmap(struct perf_mmap *map __maybe_unused)
+static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused)
{
}
#endif
-void perf_mmap__munmap(struct perf_mmap *map)
+void perf_mmap__munmap(struct mmap *map)
{
perf_mmap__aio_munmap(map);
if (map->data != NULL) {
@@ -343,7 +343,7 @@ static void build_node_mask(int node, cpu_set_t *mask)
}
}
-static void perf_mmap__setup_affinity_mask(struct perf_mmap *map, struct mmap_params *mp)
+static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp)
{
CPU_ZERO(&map->affinity_mask);
if (mp->affinity == PERF_AFFINITY_NODE && cpu__max_node() > 1)
@@ -352,7 +352,7 @@ static void perf_mmap__setup_affinity_mask(struct perf_mmap *map, struct mmap_pa
CPU_SET(map->cpu, &map->affinity_mask);
}
-int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu)
+int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
{
/*
* The last one will be done at perf_mmap__consume(), so that we
@@ -440,7 +440,7 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
/*
* Report the start and end of the available data in ringbuffer
*/
-static int __perf_mmap__read_init(struct perf_mmap *md)
+static int __perf_mmap__read_init(struct mmap *md)
{
u64 head = perf_mmap__read_head(md);
u64 old = md->prev;
@@ -474,7 +474,7 @@ static int __perf_mmap__read_init(struct perf_mmap *md)
return 0;
}
-int perf_mmap__read_init(struct perf_mmap *map)
+int perf_mmap__read_init(struct mmap *map)
{
/*
* Check if event was unmapped due to a POLLHUP/POLLERR.
@@ -485,8 +485,8 @@ int perf_mmap__read_init(struct perf_mmap *map)
return __perf_mmap__read_init(map);
}
-int perf_mmap__push(struct perf_mmap *md, void *to,
- int push(struct perf_mmap *map, void *to, void *buf, size_t size))
+int perf_mmap__push(struct mmap *md, void *to,
+ int push(struct mmap *map, void *to, void *buf, size_t size))
{
u64 head = perf_mmap__read_head(md);
unsigned char *data = md->base + page_size;
@@ -532,7 +532,7 @@ int perf_mmap__push(struct perf_mmap *md, void *to,
* The last perf_mmap__read() will set tail to map->prev.
* Need to correct the map->prev to head which is the end of next read.
*/
-void perf_mmap__read_done(struct perf_mmap *map)
+void perf_mmap__read_done(struct mmap *map)
{
/*
* Check if event was unmapped due to a POLLHUP/POLLERR.
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 3857a49e8f96..01524608a984 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -15,11 +15,11 @@
struct aiocb;
/**
- * struct perf_mmap - perf's ring buffer mmap details
+ * struct mmap - perf's ring buffer mmap details
*
* @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
*/
-struct perf_mmap {
+struct mmap {
void *base;
int mask;
int fd;
@@ -78,33 +78,33 @@ struct mmap_params {
struct auxtrace_mmap_params auxtrace_mp;
};
-int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu);
-void perf_mmap__munmap(struct perf_mmap *map);
+int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
+void perf_mmap__munmap(struct mmap *map);
-void perf_mmap__get(struct perf_mmap *map);
-void perf_mmap__put(struct perf_mmap *map);
+void perf_mmap__get(struct mmap *map);
+void perf_mmap__put(struct mmap *map);
-void perf_mmap__consume(struct perf_mmap *map);
+void perf_mmap__consume(struct mmap *map);
-static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
+static inline u64 perf_mmap__read_head(struct mmap *mm)
{
return ring_buffer_read_head(mm->base);
}
-static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
+static inline void perf_mmap__write_tail(struct mmap *md, u64 tail)
{
ring_buffer_write_tail(md->base, tail);
}
-union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
+union perf_event *perf_mmap__read_forward(struct mmap *map);
-union perf_event *perf_mmap__read_event(struct perf_mmap *map);
+union perf_event *perf_mmap__read_event(struct mmap *map);
-int perf_mmap__push(struct perf_mmap *md, void *to,
- int push(struct perf_mmap *map, void *to, void *buf, size_t size));
+int perf_mmap__push(struct mmap *md, void *to,
+ int push(struct mmap *map, void *to, void *buf, size_t size));
-size_t perf_mmap__mmap_len(struct perf_mmap *map);
+size_t perf_mmap__mmap_len(struct mmap *map);
-int perf_mmap__read_init(struct perf_mmap *md);
-void perf_mmap__read_done(struct perf_mmap *map);
+int perf_mmap__read_init(struct mmap *md);
+void perf_mmap__read_done(struct mmap *map);
#endif /*__PERF_MMAP_H */
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 07ca4535e6f7..e22013b08337 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -984,12 +984,12 @@ static PyObject *pyrf_evlist__add(struct pyrf_evlist *pevlist,
return Py_BuildValue("i", evlist->core.nr_entries);
}
-static struct perf_mmap *get_md(struct evlist *evlist, int cpu)
+static struct mmap *get_md(struct evlist *evlist, int cpu)
{
int i;
for (i = 0; i < evlist->nr_mmaps; i++) {
- struct perf_mmap *md = &evlist->mmap[i];
+ struct mmap *md = &evlist->mmap[i];
if (md->cpu == cpu)
return md;
@@ -1005,7 +1005,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
union perf_event *event;
int sample_id_all = 1, cpu;
static char *kwlist[] = { "cpu", "sample_id_all", NULL };
- struct perf_mmap *md;
+ struct mmap *md;
int err;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist,
--
2.21.0
Adding perf_evlist__id_add_fd function to libperf
as internal function.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 44 ++++++++++++++++++++++++
tools/perf/lib/include/internal/evlist.h | 4 +++
tools/perf/util/evlist.c | 43 +----------------------
tools/perf/util/evlist.h | 4 ---
tools/perf/util/evsel.c | 2 +-
5 files changed, 50 insertions(+), 47 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index f4f8e37c6272..35467d99cea5 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -3,11 +3,14 @@
#include <perf/evsel.h>
#include <linux/list.h>
#include <linux/hash.h>
+#include <sys/ioctl.h>
#include <internal/evlist.h>
#include <internal/evsel.h>
#include <internal/xyarray.h>
#include <linux/zalloc.h>
#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
@@ -193,3 +196,44 @@ void perf_evlist__id_add(struct perf_evlist *evlist,
perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
evsel->id[evsel->ids++] = id;
}
+
+int perf_evlist__id_add_fd(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ int cpu, int thread, int fd)
+{
+ u64 read_data[4] = { 0, };
+ int id_idx = 1; /* The first entry is the counter value */
+ u64 id;
+ int ret;
+
+ ret = ioctl(fd, PERF_EVENT_IOC_ID, &id);
+ if (!ret)
+ goto add;
+
+ if (errno != ENOTTY)
+ return -1;
+
+ /* Legacy way to get event id.. All hail to old kernels! */
+
+ /*
+ * This way does not work with group format read, so bail
+ * out in that case.
+ */
+ if (perf_evlist__read_format(evlist) & PERF_FORMAT_GROUP)
+ return -1;
+
+ if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
+ read(fd, &read_data, sizeof(read_data)) == -1)
+ return -1;
+
+ if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
+ ++id_idx;
+ if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
+ ++id_idx;
+
+ id = read_data[id_idx];
+
+add:
+ perf_evlist__id_add(evlist, evsel, cpu, thread, id);
+ return 0;
+}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 649406f717bc..7d64185cfabd 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -72,4 +72,8 @@ void perf_evlist__id_add(struct perf_evlist *evlist,
struct perf_evsel *evsel,
int cpu, int thread, u64 id);
+int perf_evlist__id_add_fd(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ int cpu, int thread, int fd);
+
#endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index dde6c68b9a42..433e9af6e063 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -460,47 +460,6 @@ int perf_evlist__poll(struct evlist *evlist, int timeout)
return fdarray__poll(&evlist->core.pollfd, timeout);
}
-int perf_evlist__id_add_fd(struct evlist *evlist,
- struct evsel *evsel,
- int cpu, int thread, int fd)
-{
- u64 read_data[4] = { 0, };
- int id_idx = 1; /* The first entry is the counter value */
- u64 id;
- int ret;
-
- ret = ioctl(fd, PERF_EVENT_IOC_ID, &id);
- if (!ret)
- goto add;
-
- if (errno != ENOTTY)
- return -1;
-
- /* Legacy way to get event id.. All hail to old kernels! */
-
- /*
- * This way does not work with group format read, so bail
- * out in that case.
- */
- if (perf_evlist__read_format(&evlist->core) & PERF_FORMAT_GROUP)
- return -1;
-
- if (!(evsel->core.attr.read_format & PERF_FORMAT_ID) ||
- read(fd, &read_data, sizeof(read_data)) == -1)
- return -1;
-
- if (evsel->core.attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
- ++id_idx;
- if (evsel->core.attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
- ++id_idx;
-
- id = read_data[id_idx];
-
- add:
- perf_evlist__id_add(&evlist->core, &evsel->core, cpu, thread, id);
- return 0;
-}
-
static void perf_evlist__set_sid_idx(struct evlist *evlist,
struct evsel *evsel, int idx, int cpu,
int thread)
@@ -775,7 +734,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
}
if (evsel->core.attr.read_format & PERF_FORMAT_ID) {
- if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
+ if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, cpu, thread,
fd) < 0)
return -1;
perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 37f29b67dd61..204315516c32 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -113,10 +113,6 @@ struct evsel *
perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
const char *name);
-int perf_evlist__id_add_fd(struct evlist *evlist,
- struct evsel *evsel,
- int cpu, int thread, int fd);
-
int perf_evlist__add_pollfd(struct evlist *evlist, int fd);
int perf_evlist__alloc_pollfd(struct evlist *evlist);
int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 904b67d23bde..d69549c57fda 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2936,7 +2936,7 @@ static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
thread++) {
int fd = FD(evsel, cpu, thread);
- if (perf_evlist__id_add_fd(evlist, evsel,
+ if (perf_evlist__id_add_fd(&evlist->core, &evsel->core,
cpu, thread, fd) < 0)
return -1;
}
--
2.21.0
Adding perf_evlist__mmap_cb_mmap function to call perf
specific mmap__mmap function during perf_evlist__mmap_ops
call.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 52a6af91e877..a0f09e78e89d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -748,6 +748,16 @@ perf_evlist__mmap_cb_new(struct perf_evlist *_evlist, bool overwrite, int idx)
return &maps[idx].core;
}
+static int
+perf_evlist__mmap_cb_mmap(struct perf_mmap *_map, struct perf_mmap_param *_mp,
+ int output, int cpu)
+{
+ struct mmap *map = container_of(_map, struct mmap, core);
+ struct mmap_params *mp = container_of(_mp, struct mmap_params, core);
+
+ return mmap__mmap(map, mp, output, cpu);
+}
+
static int evlist__mmap_per_cpu(struct evlist *evlist,
struct mmap_params *mp)
{
@@ -945,8 +955,9 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
.comp_level = comp_level
};
struct perf_evlist_mmap_ops ops __maybe_unused = {
- .idx = perf_evlist__mmap_cb_idx,
- .new = perf_evlist__mmap_cb_new,
+ .idx = perf_evlist__mmap_cb_idx,
+ .new = perf_evlist__mmap_cb_new,
+ .mmap = perf_evlist__mmap_cb_mmap,
};
if (!evlist->mmap)
--
2.21.0
Moving perf_mmap__read_event function into libperf
and export it in perf/mmap.h header.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/lib/include/perf/mmap.h | 1 +
tools/perf/lib/libperf.map | 1 +
tools/perf/lib/mmap.c | 79 ++++++++++++++++++++
tools/perf/tests/backward-ring-buffer.c | 2 +-
tools/perf/tests/bpf.c | 2 +-
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/keep-tracking.c | 2 +-
tools/perf/tests/mmap-basic.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/sw-clock.c | 2 +-
tools/perf/tests/switch-tracking.c | 2 +-
tools/perf/tests/task-exit.c | 2 +-
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 77 -------------------
tools/perf/util/mmap.h | 2 -
tools/perf/util/python.c | 2 +-
22 files changed, 98 insertions(+), 95 deletions(-)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 04da28d15039..128c61c866d7 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -121,7 +121,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_COMM ||
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 4b281d77d22c..9bcf025343a6 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -760,7 +760,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
if (err < 0)
return (err == -EAGAIN) ? 0 : -1;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
err = perf_evlist__parse_sample_timestamp(evlist, event, ×tamp);
if (err) {
perf_mmap__consume(&md->core);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index c122aa1e9ca1..0141afd2f3ff 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -869,7 +869,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
if (perf_mmap__read_init(&md->core) < 0)
return;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
int ret;
ret = perf_evlist__parse_sample_timestamp(evlist, event, &last_timestamp);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 1ae249d9ecf0..a6f57d1c9a70 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3450,7 +3450,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
++trace->nr_events;
err = trace__deliver_event(trace, event);
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 30e34ec622bf..98e31f8ab461 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -11,6 +11,7 @@
#define PERF_SAMPLE_MAX_SIZE (1 << 16)
struct perf_mmap;
+union perf_event;
typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
diff --git a/tools/perf/lib/include/perf/mmap.h b/tools/perf/lib/include/perf/mmap.h
index 4f946e7f724b..396c6543d95d 100644
--- a/tools/perf/lib/include/perf/mmap.h
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -9,5 +9,6 @@ struct perf_mmap;
LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
LIBPERF_API void perf_mmap__read_done(struct perf_mmap *map);
+LIBPERF_API union perf_event *perf_mmap__read_event(struct perf_mmap *map);
#endif /* __LIBPERF_MMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index eca40c75b753..6e7d9be3c35f 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -42,6 +42,7 @@ LIBPERF_0.0.1 {
perf_mmap__consume;
perf_mmap__read_init;
perf_mmap__read_done;
+ perf_mmap__read_event;
local:
*;
};
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index f27cb743183c..f8816c7bee87 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -3,10 +3,12 @@
#include <inttypes.h>
#include <asm/bug.h>
#include <errno.h>
+#include <string.h>
#include <linux/zalloc.h>
#include <linux/ring_buffer.h>
#include <linux/perf_event.h>
#include <perf/mmap.h>
+#include <perf/event.h>
#include <internal/mmap.h>
#include <internal/lib.h>
#include "internal.h"
@@ -202,3 +204,80 @@ void perf_mmap__read_done(struct perf_mmap *map)
map->prev = perf_mmap__read_head(map);
}
+
+/* When check_messup is true, 'end' must points to a good entry */
+static union perf_event *perf_mmap__read(struct perf_mmap *map,
+ u64 *startp, u64 end)
+{
+ unsigned char *data = map->base + page_size;
+ union perf_event *event = NULL;
+ int diff = end - *startp;
+
+ if (diff >= (int)sizeof(event->header)) {
+ size_t size;
+
+ event = (union perf_event *)&data[*startp & map->mask];
+ size = event->header.size;
+
+ if (size < sizeof(event->header) || diff < (int)size)
+ return NULL;
+
+ /*
+ * Event straddles the mmap boundary -- header should always
+ * be inside due to u64 alignment of output.
+ */
+ if ((*startp & map->mask) + size != ((*startp + size) & map->mask)) {
+ unsigned int offset = *startp;
+ unsigned int len = min(sizeof(*event), size), cpy;
+ void *dst = map->event_copy;
+
+ do {
+ cpy = min(map->mask + 1 - (offset & map->mask), len);
+ memcpy(dst, &data[offset & map->mask], cpy);
+ offset += cpy;
+ dst += cpy;
+ len -= cpy;
+ } while (len);
+
+ event = (union perf_event *)map->event_copy;
+ }
+
+ *startp += size;
+ }
+
+ return event;
+}
+
+/*
+ * Read event from ring buffer one by one.
+ * Return one event for each call.
+ *
+ * Usage:
+ * perf_mmap__read_init()
+ * while(event = perf_mmap__read_event()) {
+ * //process the event
+ * perf_mmap__consume()
+ * }
+ * perf_mmap__read_done()
+ */
+union perf_event *perf_mmap__read_event(struct perf_mmap *map)
+{
+ union perf_event *event;
+
+ /*
+ * Check if event was unmapped due to a POLLHUP/POLLERR.
+ */
+ if (!refcount_read(&map->refcnt))
+ return NULL;
+
+ /* non-overwirte doesn't pause the ringbuffer */
+ if (!map->overwrite)
+ map->end = perf_mmap__read_head(map);
+
+ event = perf_mmap__read(map, &map->start, map->end);
+
+ if (!map->overwrite)
+ map->prev = map->start;
+
+ return event;
+}
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 4b5625ac257c..a63b95bd0c52 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -38,7 +38,7 @@ static int count_samples(struct evlist *evlist, int *sample_count,
union perf_event *event;
perf_mmap__read_init(&map->core);
- while ((event = perf_mmap__read_event(map)) != NULL) {
+ while ((event = perf_mmap__read_event(&map->core)) != NULL) {
const u32 type = event->header.type;
switch (type) {
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index a0b559c90f9b..ec7f236d6da9 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -187,7 +187,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
const u32 type = event->header.type;
if (type == PERF_RECORD_SAMPLE)
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 3306d75cb596..00f2109249f4 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -428,7 +428,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
ret = process_event(machine, evlist, event, state);
perf_mmap__consume(&md->core);
if (ret < 0)
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 10ea5112b996..8909ed382268 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -41,7 +41,7 @@ static int find_comm(struct evlist *evlist, const char *comm)
md = &evlist->mmap[i];
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
if (event->header.type == PERF_RECORD_COMM &&
(pid_t)event->comm.pid == getpid() &&
(pid_t)event->comm.tid == getpid() &&
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 65b84032ee13..b4919cb87796 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -117,7 +117,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_SAMPLE) {
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 771d1671f1fe..072a5e3bb441 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -95,7 +95,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
const u32 type = event->header.type;
int tp_flags;
struct perf_sample sample;
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index a0a2d9a49157..ee7ec9e21886 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -173,7 +173,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
const u32 type = event->header.type;
const char *name = perf_event__name(type);
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index d2612960669f..2ee9a5d4a221 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -102,7 +102,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
struct perf_sample sample;
if (event->header.type != PERF_RECORD_SAMPLE)
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index e2beb68281e2..05bc3b1c87ce 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -273,7 +273,7 @@ static int process_events(struct evlist *evlist,
if (perf_mmap__read_init(&md->core) < 0)
continue;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
cnt += 1;
ret = add_event(evlist, &events, event);
perf_mmap__consume(&md->core);
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 988739fcaf8d..e4bae44babc4 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -120,7 +120,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
if (perf_mmap__read_init(&md->core) < 0)
goto out_init;
- while ((event = perf_mmap__read_event(md)) != NULL) {
+ while ((event = perf_mmap__read_event(&md->core)) != NULL) {
if (event->header.type == PERF_RECORD_EXIT)
nr_exit++;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4f92b65e702c..a9fc35d25a59 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1754,7 +1754,7 @@ static void *perf_evlist__poll_thread(void *arg)
if (perf_mmap__read_init(&map->core))
continue;
- while ((event = perf_mmap__read_event(map)) != NULL) {
+ while ((event = perf_mmap__read_event(&map->core)) != NULL) {
struct evsel *evsel = perf_evlist__event2evsel(evlist, event);
if (evsel && evsel->side_band.cb)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 5ede1d2c84b1..bb81dd0c438f 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -28,83 +28,6 @@ size_t mmap__mmap_len(struct mmap *map)
return perf_mmap__mmap_len(&map->core);
}
-/* When check_messup is true, 'end' must points to a good entry */
-static union perf_event *perf_mmap__read(struct mmap *map,
- u64 *startp, u64 end)
-{
- unsigned char *data = map->core.base + page_size;
- union perf_event *event = NULL;
- int diff = end - *startp;
-
- if (diff >= (int)sizeof(event->header)) {
- size_t size;
-
- event = (union perf_event *)&data[*startp & map->core.mask];
- size = event->header.size;
-
- if (size < sizeof(event->header) || diff < (int)size)
- return NULL;
-
- /*
- * Event straddles the mmap boundary -- header should always
- * be inside due to u64 alignment of output.
- */
- if ((*startp & map->core.mask) + size != ((*startp + size) & map->core.mask)) {
- unsigned int offset = *startp;
- unsigned int len = min(sizeof(*event), size), cpy;
- void *dst = map->core.event_copy;
-
- do {
- cpy = min(map->core.mask + 1 - (offset & map->core.mask), len);
- memcpy(dst, &data[offset & map->core.mask], cpy);
- offset += cpy;
- dst += cpy;
- len -= cpy;
- } while (len);
-
- event = (union perf_event *)map->core.event_copy;
- }
-
- *startp += size;
- }
-
- return event;
-}
-
-/*
- * Read event from ring buffer one by one.
- * Return one event for each call.
- *
- * Usage:
- * perf_mmap__read_init()
- * while(event = perf_mmap__read_event()) {
- * //process the event
- * perf_mmap__consume()
- * }
- * perf_mmap__read_done()
- */
-union perf_event *perf_mmap__read_event(struct mmap *map)
-{
- union perf_event *event;
-
- /*
- * Check if event was unmapped due to a POLLHUP/POLLERR.
- */
- if (!refcount_read(&map->core.refcnt))
- return NULL;
-
- /* non-overwirte doesn't pause the ringbuffer */
- if (!map->core.overwrite)
- map->core.end = perf_mmap__read_head(&map->core);
-
- event = perf_mmap__read(map, &map->core.start, map->core.end);
-
- if (!map->core.overwrite)
- map->core.prev = map->core.start;
-
- return event;
-}
-
int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
struct auxtrace_mmap_params *mp __maybe_unused,
void *userpg __maybe_unused,
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index efc2392747ba..beb90531ea7f 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -75,8 +75,6 @@ void mmap__munmap(struct mmap *map);
union perf_event *perf_mmap__read_forward(struct mmap *map);
-union perf_event *perf_mmap__read_event(struct mmap *map);
-
int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size));
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index ba7a7cace740..7ea4086942aa 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1020,7 +1020,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
if (perf_mmap__read_init(&md->core) < 0)
goto end;
- event = perf_mmap__read_event(md);
+ event = perf_mmap__read_event(&md->core);
if (event != NULL) {
PyObject *pyevent = pyrf_event__new(event);
struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
--
2.21.0
Move perf_mmap__mmap_len function under libperf,
it will be used in following patches. And rename
the existing perf's function to mmap__mmap_len.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 4 ++--
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/mmap.c | 6 ++++++
tools/perf/util/mmap.c | 20 ++++++++++----------
tools/perf/util/mmap.h | 2 +-
5 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7b12877de27c..40780434b23e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -273,7 +273,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size
if (record__comp_enabled(aio->rec)) {
size = zstd_compress(aio->rec->session, aio->data + aio->size,
- perf_mmap__mmap_len(map) - aio->size,
+ mmap__mmap_len(map) - aio->size,
buf, size);
} else {
memcpy(aio->data + aio->size, buf, size);
@@ -485,7 +485,7 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size)
struct record *rec = to;
if (record__comp_enabled(rec)) {
- size = zstd_compress(rec->session, map->data, perf_mmap__mmap_len(map), bf, size);
+ size = zstd_compress(rec->session, map->data, mmap__mmap_len(map), bf, size);
bf = map->data;
}
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 8e06eb840c47..45ab791aa392 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -34,6 +34,8 @@ struct perf_mmap_param {
int mask;
};
+size_t perf_mmap__mmap_len(struct perf_mmap *map);
+
void perf_mmap__init(struct perf_mmap *map, bool overwrite);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 3da6177510e6..cc4284da4d99 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <internal/mmap.h>
+#include <internal/lib.h>
void perf_mmap__init(struct perf_mmap *map, bool overwrite)
{
@@ -7,3 +8,8 @@ void perf_mmap__init(struct perf_mmap *map, bool overwrite)
map->overwrite = overwrite;
refcount_set(&map->refcnt, 0);
}
+
+size_t perf_mmap__mmap_len(struct perf_mmap *map)
+{
+ return map->mask + 1 + page_size;
+}
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 2f34a93a72f4..4e2ef633d425 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -22,9 +22,9 @@
#include "../perf.h"
#include "util.h" /* page_size */
-size_t perf_mmap__mmap_len(struct mmap *map)
+size_t mmap__mmap_len(struct mmap *map)
{
- return map->core.mask + 1 + page_size;
+ return perf_mmap__mmap_len(&map->core);
}
/* When check_messup is true, 'end' must points to a good entry */
@@ -169,7 +169,7 @@ static int perf_mmap__aio_enabled(struct mmap *map)
#ifdef HAVE_LIBNUMA_SUPPORT
static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{
- map->aio.data[idx] = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE,
+ map->aio.data[idx] = mmap(NULL, mmap__mmap_len(map), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map->aio.data[idx] == MAP_FAILED) {
map->aio.data[idx] = NULL;
@@ -182,7 +182,7 @@ static int perf_mmap__aio_alloc(struct mmap *map, int idx)
static void perf_mmap__aio_free(struct mmap *map, int idx)
{
if (map->aio.data[idx]) {
- munmap(map->aio.data[idx], perf_mmap__mmap_len(map));
+ munmap(map->aio.data[idx], mmap__mmap_len(map));
map->aio.data[idx] = NULL;
}
}
@@ -195,7 +195,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity)
if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) {
data = map->aio.data[idx];
- mmap_len = perf_mmap__mmap_len(map);
+ mmap_len = mmap__mmap_len(map);
node_mask = 1UL << cpu__get_node(cpu);
if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) {
pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n",
@@ -209,7 +209,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity)
#else /* !HAVE_LIBNUMA_SUPPORT */
static int perf_mmap__aio_alloc(struct mmap *map, int idx)
{
- map->aio.data[idx] = malloc(perf_mmap__mmap_len(map));
+ map->aio.data[idx] = malloc(mmap__mmap_len(map));
if (map->aio.data[idx] == NULL)
return -1;
@@ -314,11 +314,11 @@ void perf_mmap__munmap(struct mmap *map)
{
perf_mmap__aio_munmap(map);
if (map->data != NULL) {
- munmap(map->data, perf_mmap__mmap_len(map));
+ munmap(map->data, mmap__mmap_len(map));
map->data = NULL;
}
if (map->core.base != NULL) {
- munmap(map->core.base, perf_mmap__mmap_len(map));
+ munmap(map->core.base, mmap__mmap_len(map));
map->core.base = NULL;
map->core.fd = -1;
refcount_set(&map->core.refcnt, 0);
@@ -370,7 +370,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
refcount_set(&map->core.refcnt, 2);
map->core.prev = 0;
map->core.mask = mp->core.mask;
- map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->core.prot,
+ map->core.base = mmap(NULL, mmap__mmap_len(map), mp->core.prot,
MAP_SHARED, fd, 0);
if (map->core.base == MAP_FAILED) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
@@ -388,7 +388,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
map->comp_level = mp->comp_level;
if (map->comp_level && !perf_mmap__aio_enabled(map)) {
- map->data = mmap(NULL, perf_mmap__mmap_len(map), PROT_READ|PROT_WRITE,
+ map->data = mmap(NULL, mmap__mmap_len(map), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map->data == MAP_FAILED) {
pr_debug2("failed to mmap data buffer, error %d\n",
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 965acb46df81..308492a59ea1 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -95,7 +95,7 @@ union perf_event *perf_mmap__read_event(struct mmap *map);
int perf_mmap__push(struct mmap *md, void *to,
int push(struct mmap *map, void *to, void *buf, size_t size));
-size_t perf_mmap__mmap_len(struct mmap *map);
+size_t mmap__mmap_len(struct mmap *map);
int perf_mmap__read_init(struct mmap *md);
void perf_mmap__read_done(struct mmap *map);
--
2.21.0
Move perf_evlist__add_pollfd function under libperf,
it will be used in following patches.
Also renaming perf's perf_evlist__add_pollfd/perf_evlist__filter_pollfd
to evlist__add_pollfd/evlist__filter_pollfd.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-kvm.c | 4 ++--
tools/perf/builtin-record.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/evlist.c | 16 +++++++++++++++
tools/perf/lib/include/internal/evlist.h | 2 ++
tools/perf/util/evlist.c | 25 ++++--------------------
tools/perf/util/evlist.h | 4 ++--
7 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 66acac16bcb2..a90c7d4302b9 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -964,10 +964,10 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
goto out;
}
- if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
+ if (evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
goto out;
- nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
+ nr_stdin = evlist__add_pollfd(kvm->evlist, fileno(stdin));
if (nr_stdin < 0)
goto out;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index efad7e6a2dca..cb5d750cbbdf 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1619,7 +1619,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
err = 0;
waking++;
- if (perf_evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0)
+ if (evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0)
draining = true;
}
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 0dc35aa624c5..685935b533f4 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3473,7 +3473,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
int timeout = done ? 100 : -1;
if (!draining && perf_evlist__poll(evlist, timeout) > 0) {
- if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0)
+ if (evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0)
draining = true;
goto again;
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 0f84f5dc519f..a2c01dcec5ae 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -11,6 +11,9 @@
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <poll.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
@@ -258,3 +261,16 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
return 0;
}
+
+int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
+ void *ptr, short revent)
+{
+ int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
+
+ if (pos >= 0) {
+ evlist->pollfd.priv[pos].ptr = ptr;
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ }
+
+ return pos;
+}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 88c0dfaf0ddc..9f440ab12b76 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -25,6 +25,8 @@ struct perf_evlist {
};
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
+int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
+ void *ptr, short revent);
/**
* __perf_evlist__for_each_entry - iterate thru all the evsels
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 664c8e87ec96..449425d9a033 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -397,26 +397,9 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
return perf_evlist__enable_event_thread(evlist, evsel, idx);
}
-static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
- struct mmap *map, short revent)
+int evlist__add_pollfd(struct evlist *evlist, int fd)
{
- int pos = fdarray__add(&evlist->core.pollfd, fd, revent | POLLERR | POLLHUP);
- /*
- * Save the idx so that when we filter out fds POLLHUP'ed we can
- * close the associated evlist->mmap[] entry.
- */
- if (pos >= 0) {
- evlist->core.pollfd.priv[pos].ptr = map;
-
- fcntl(fd, F_SETFL, O_NONBLOCK);
- }
-
- return pos;
-}
-
-int perf_evlist__add_pollfd(struct evlist *evlist, int fd)
-{
- return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN);
+ return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN);
}
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
@@ -428,7 +411,7 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
perf_mmap__put(map);
}
-int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
+int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
{
return fdarray__filter(&evlist->core.pollfd, revents_and_mask,
perf_evlist__munmap_filtered, NULL);
@@ -707,7 +690,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
* Therefore don't add it for polling.
*/
if (!evsel->core.system_wide &&
- __perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) {
+ perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) {
perf_mmap__put(&maps[idx]);
return -1;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 9c90df51ce08..6c5455cf5829 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -113,8 +113,8 @@ struct evsel *
perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
const char *name);
-int perf_evlist__add_pollfd(struct evlist *evlist, int fd);
-int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
+int evlist__add_pollfd(struct evlist *evlist, int fd);
+int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
int perf_evlist__poll(struct evlist *evlist, int timeout);
--
2.21.0
Linking libapi.a in libperf.so, because we are about
to use some of the api functions in it.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/Makefile | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index e325c0503dc6..54466cc84544 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -59,7 +59,13 @@ else
CFLAGS := -g -Wall
endif
-INCLUDES = -I$(srctree)/tools/perf/lib/include -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/ -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
+INCLUDES = \
+-I$(srctree)/tools/perf/lib/include \
+-I$(srctree)/tools/lib/ \
+-I$(srctree)/tools/include \
+-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
+-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
+-I$(srctree)/tools/include/uapi
# Append required CFLAGS
override CFLAGS += $(EXTRA_WARNINGS)
@@ -88,13 +94,34 @@ LIBPERF_PC := $(OUTPUT)libperf.pc
LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
+LIB_DIR := $(srctree)/tools/lib/api/
+
+ifneq ($(OUTPUT),)
+ifneq ($(subdir),)
+ API_PATH=$(OUTPUT)/../lib/api/
+else
+ API_PATH=$(OUTPUT)
+endif
+else
+ API_PATH=$(LIB_DIR)
+endif
+
+LIBAPI = $(API_PATH)libapi.a
+
+$(LIBAPI): FORCE
+ $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
+
+$(LIBAPI)-clean:
+ $(call QUIET_CLEAN, libapi)
+ $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
+
$(LIBPERF_IN): FORCE
$(Q)$(MAKE) $(build)=libperf
$(LIBPERF_A): $(LIBPERF_IN)
$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
-$(LIBPERF_SO): $(LIBPERF_IN)
+$(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
$(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
-Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
@ln -sf $(@F) $(OUTPUT)libperf.so
@@ -106,7 +133,7 @@ libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
all: fixdep
$(Q)$(MAKE) libs
-clean:
+clean: $(LIBAPI)-clean
$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
$(Q)$(MAKE) -C tests clean
--
2.21.0
Adding perf_evlist__id_add function to libperf
as internal function. We already have the heads
member in 'struct perf_evlist'.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 25 ++++++++++++++++++++++++
tools/perf/lib/include/internal/evlist.h | 4 ++++
tools/perf/tests/event_update.c | 2 +-
tools/perf/util/evlist.c | 22 +--------------------
tools/perf/util/evlist.h | 2 --
tools/perf/util/header.c | 4 ++--
6 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index ae861bf38976..f4f8e37c6272 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -2,8 +2,10 @@
#include <perf/evlist.h>
#include <perf/evsel.h>
#include <linux/list.h>
+#include <linux/hash.h>
#include <internal/evlist.h>
#include <internal/evsel.h>
+#include <internal/xyarray.h>
#include <linux/zalloc.h>
#include <stdlib.h>
#include <perf/cpumap.h>
@@ -168,3 +170,26 @@ u64 perf_evlist__read_format(struct perf_evlist *evlist)
return first->attr.read_format;
}
+
+#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
+
+static void perf_evlist__id_hash(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ int cpu, int thread, u64 id)
+{
+ int hash;
+ struct perf_sample_id *sid = SID(evsel, cpu, thread);
+
+ sid->id = id;
+ sid->evsel = evsel;
+ hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
+ hlist_add_head(&sid->node, &evlist->heads[hash]);
+}
+
+void perf_evlist__id_add(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ int cpu, int thread, u64 id)
+{
+ perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
+ evsel->id[evsel->ids++] = id;
+}
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)
u64 perf_evlist__read_format(struct perf_evlist *evlist);
+void perf_evlist__id_add(struct perf_evlist *evlist,
+ struct perf_evsel *evsel,
+ int cpu, int thread, u64 id);
+
#endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c
index 0c982550799c..89c8f047676a 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
TEST_ASSERT_VAL("failed to allos ids",
!perf_evsel__alloc_id(&evsel->core, 1, 1));
- perf_evlist__id_add(evlist, evsel, 0, 0, 123);
+ perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123);
evsel->unit = strdup("KRAVA");
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index de1dc73d1fe4..dde6c68b9a42 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -460,26 +460,6 @@ int perf_evlist__poll(struct evlist *evlist, int timeout)
return fdarray__poll(&evlist->core.pollfd, timeout);
}
-static void perf_evlist__id_hash(struct evlist *evlist,
- struct evsel *evsel,
- int cpu, int thread, u64 id)
-{
- int hash;
- struct perf_sample_id *sid = SID(evsel, cpu, thread);
-
- sid->id = id;
- sid->evsel = &evsel->core;
- hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
- hlist_add_head(&sid->node, &evlist->core.heads[hash]);
-}
-
-void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel,
- int cpu, int thread, u64 id)
-{
- perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
- evsel->core.id[evsel->core.ids++] = id;
-}
-
int perf_evlist__id_add_fd(struct evlist *evlist,
struct evsel *evsel,
int cpu, int thread, int fd)
@@ -517,7 +497,7 @@ int perf_evlist__id_add_fd(struct evlist *evlist,
id = read_data[id_idx];
add:
- perf_evlist__id_add(evlist, evsel, cpu, thread, id);
+ perf_evlist__id_add(&evlist->core, &evsel->core, cpu, thread, id);
return 0;
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index f0212738bed6..37f29b67dd61 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -113,8 +113,6 @@ struct evsel *
perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
const char *name);
-void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel,
- int cpu, int thread, u64 id);
int perf_evlist__id_add_fd(struct evlist *evlist,
struct evsel *evsel,
int cpu, int thread, int fd);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 65b6e387e3ae..20f6c8eda8ff 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3633,7 +3633,7 @@ int perf_session__read_header(struct perf_session *session)
if (perf_header__getbuffer64(header, fd, &f_id, sizeof(f_id)))
goto out_errno;
- perf_evlist__id_add(session->evlist, evsel, 0, j, f_id);
+ perf_evlist__id_add(&session->evlist->core, &evsel->core, 0, j, f_id);
}
lseek(fd, tmp, SEEK_SET);
@@ -4062,7 +4062,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused,
return -ENOMEM;
for (i = 0; i < n_ids; i++) {
- perf_evlist__id_add(evlist, evsel, 0, i, event->attr.id[i]);
+ perf_evlist__id_add(&evlist->core, &evsel->core, 0, i, event->attr.id[i]);
}
return 0;
--
2.21.0
Move prev/start/end from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 3 ++
tools/perf/util/mmap.c | 50 +++++++++++++-------------
tools/perf/util/mmap.h | 3 --
3 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 96a8a278340c..5af28668913c 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -18,6 +18,9 @@ struct perf_mmap {
int fd;
int cpu;
refcount_t refcnt;
+ u64 prev;
+ u64 start;
+ u64 end;
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index d6406d216cfe..6ce70ff005cb 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -94,19 +94,19 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
/* non-overwirte doesn't pause the ringbuffer */
if (!map->overwrite)
- map->end = perf_mmap__read_head(map);
+ map->core.end = perf_mmap__read_head(map);
- event = perf_mmap__read(map, &map->start, map->end);
+ event = perf_mmap__read(map, &map->core.start, map->core.end);
if (!map->overwrite)
- map->prev = map->start;
+ map->core.prev = map->core.start;
return event;
}
static bool perf_mmap__empty(struct mmap *map)
{
- return perf_mmap__read_head(map) == map->prev && !map->auxtrace_mmap.base;
+ return perf_mmap__read_head(map) == map->core.prev && !map->auxtrace_mmap.base;
}
void perf_mmap__get(struct mmap *map)
@@ -125,7 +125,7 @@ void perf_mmap__put(struct mmap *map)
void perf_mmap__consume(struct mmap *map)
{
if (!map->overwrite) {
- u64 old = map->prev;
+ u64 old = map->core.prev;
perf_mmap__write_tail(map, old);
}
@@ -368,7 +368,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
* perf_evlist__filter_pollfd().
*/
refcount_set(&map->core.refcnt, 2);
- map->prev = 0;
+ map->core.prev = 0;
map->core.mask = mp->mask;
map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
MAP_SHARED, fd, 0);
@@ -443,22 +443,22 @@ static int overwrite_rb_find_range(void *buf, int mask, u64 *start, u64 *end)
static int __perf_mmap__read_init(struct mmap *md)
{
u64 head = perf_mmap__read_head(md);
- u64 old = md->prev;
+ u64 old = md->core.prev;
unsigned char *data = md->core.base + page_size;
unsigned long size;
- md->start = md->overwrite ? head : old;
- md->end = md->overwrite ? old : head;
+ md->core.start = md->overwrite ? head : old;
+ md->core.end = md->overwrite ? old : head;
- if ((md->end - md->start) < md->flush)
+ if ((md->core.end - md->core.start) < md->flush)
return -EAGAIN;
- size = md->end - md->start;
+ size = md->core.end - md->core.start;
if (size > (unsigned long)(md->core.mask) + 1) {
if (!md->overwrite) {
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");
- md->prev = head;
+ md->core.prev = head;
perf_mmap__consume(md);
return -EAGAIN;
}
@@ -467,7 +467,7 @@ static int __perf_mmap__read_init(struct mmap *md)
* Backward ring buffer is full. We still have a chance to read
* most of data from it.
*/
- if (overwrite_rb_find_range(data, md->core.mask, &md->start, &md->end))
+ if (overwrite_rb_find_range(data, md->core.mask, &md->core.start, &md->core.end))
return -EINVAL;
}
@@ -498,12 +498,12 @@ int perf_mmap__push(struct mmap *md, void *to,
if (rc < 0)
return (rc == -EAGAIN) ? 1 : -1;
- size = md->end - md->start;
+ size = md->core.end - md->core.start;
- if ((md->start & md->core.mask) + size != (md->end & md->core.mask)) {
- buf = &data[md->start & md->core.mask];
- size = md->core.mask + 1 - (md->start & md->core.mask);
- md->start += size;
+ if ((md->core.start & md->core.mask) + size != (md->core.end & md->core.mask)) {
+ buf = &data[md->core.start & md->core.mask];
+ size = md->core.mask + 1 - (md->core.start & md->core.mask);
+ md->core.start += size;
if (push(md, to, buf, size) < 0) {
rc = -1;
@@ -511,16 +511,16 @@ int perf_mmap__push(struct mmap *md, void *to,
}
}
- buf = &data[md->start & md->core.mask];
- size = md->end - md->start;
- md->start += size;
+ buf = &data[md->core.start & md->core.mask];
+ size = md->core.end - md->core.start;
+ md->core.start += size;
if (push(md, to, buf, size) < 0) {
rc = -1;
goto out;
}
- md->prev = head;
+ md->core.prev = head;
perf_mmap__consume(md);
out:
return rc;
@@ -529,8 +529,8 @@ int perf_mmap__push(struct mmap *md, void *to,
/*
* Mandatory for overwrite mode
* The direction of overwrite mode is backward.
- * The last perf_mmap__read() will set tail to map->prev.
- * Need to correct the map->prev to head which is the end of next read.
+ * The last perf_mmap__read() will set tail to map->core.prev.
+ * Need to correct the map->core.prev to head which is the end of next read.
*/
void perf_mmap__read_done(struct mmap *map)
{
@@ -540,5 +540,5 @@ void perf_mmap__read_done(struct mmap *map)
if (!refcount_read(&map->core.refcnt))
return;
- map->prev = perf_mmap__read_head(map);
+ map->core.prev = perf_mmap__read_head(map);
}
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 117ba39f0f7a..16e4a5ca773d 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -22,9 +22,6 @@ struct aiocb;
*/
struct mmap {
struct perf_mmap core;
- u64 prev;
- u64 start;
- u64 end;
bool overwrite;
struct auxtrace_mmap auxtrace_mmap;
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
--
2.21.0
Adding perf_evlist__read_format function to libperf
as internal function.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 7 +++++++
tools/perf/lib/include/internal/evlist.h | 2 ++
tools/perf/util/evlist.c | 8 +-------
tools/perf/util/evlist.h | 1 -
4 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 2bdd9d2c79d9..ae861bf38976 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -161,3 +161,10 @@ void perf_evlist__disable(struct perf_evlist *evlist)
perf_evlist__for_each_entry(evlist, evsel)
perf_evsel__disable(evsel);
}
+
+u64 perf_evlist__read_format(struct perf_evlist *evlist)
+{
+ struct perf_evsel *first = perf_evlist__first(evlist);
+
+ return first->attr.read_format;
+}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 16ae6d6cfb39..63516fe14f4c 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -66,4 +66,6 @@ static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
return list_entry(evlist->entries.prev, struct perf_evsel, node);
}
+u64 perf_evlist__read_format(struct perf_evlist *evlist);
+
#endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index a57e2f9c6e6d..de1dc73d1fe4 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -502,7 +502,7 @@ int perf_evlist__id_add_fd(struct evlist *evlist,
* This way does not work with group format read, so bail
* out in that case.
*/
- if (perf_evlist__read_format(evlist) & PERF_FORMAT_GROUP)
+ if (perf_evlist__read_format(&evlist->core) & PERF_FORMAT_GROUP)
return -1;
if (!(evsel->core.attr.read_format & PERF_FORMAT_ID) ||
@@ -1239,12 +1239,6 @@ bool perf_evlist__valid_read_format(struct evlist *evlist)
return true;
}
-u64 perf_evlist__read_format(struct evlist *evlist)
-{
- struct evsel *first = evlist__first(evlist);
- return first->core.attr.read_format;
-}
-
u16 perf_evlist__id_hdr_size(struct evlist *evlist)
{
struct evsel *first = evlist__first(evlist);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 88890e6a3ac7..f0212738bed6 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -189,7 +189,6 @@ int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
void __perf_evlist__set_leader(struct list_head *list);
void perf_evlist__set_leader(struct evlist *evlist);
-u64 perf_evlist__read_format(struct evlist *evlist);
u64 __perf_evlist__combined_sample_type(struct evlist *evlist);
u64 perf_evlist__combined_sample_type(struct evlist *evlist);
u64 perf_evlist__combined_branch_type(struct evlist *evlist);
--
2.21.0
Move perf_mmap__read_init function under libperf
and export it in perf/mmap.h header.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/builtin-kvm.c | 2 +-
tools/perf/builtin-top.c | 2 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/include/perf/mmap.h | 1 +
tools/perf/lib/libperf.map | 1 +
tools/perf/lib/mmap.c | 17 +++++++++++++++++
tools/perf/tests/backward-ring-buffer.c | 2 +-
tools/perf/tests/bpf.c | 2 +-
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/keep-tracking.c | 2 +-
tools/perf/tests/mmap-basic.c | 2 +-
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/sw-clock.c | 2 +-
tools/perf/tests/switch-tracking.c | 2 +-
tools/perf/tests/task-exit.c | 2 +-
tools/perf/util/evlist.c | 2 +-
tools/perf/util/mmap.c | 17 -----------------
tools/perf/util/mmap.h | 1 -
20 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index ca5e483c3fda..04da28d15039 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -142,7 +142,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
next_event:
perf_mmap__consume(&md->core);
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
if (!comm1_time || !comm2_time)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index ca7e48379f57..4b281d77d22c 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -790,7 +790,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
break;
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
return n;
}
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 86b7a71dc5ed..c122aa1e9ca1 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -890,7 +890,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
}
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
static void perf_top__mmap_read(struct perf_top *top)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index fcdb30e93a81..1ae249d9ecf0 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3467,7 +3467,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
draining = true;
}
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
if (trace->nr_events == before) {
diff --git a/tools/perf/lib/include/perf/mmap.h b/tools/perf/lib/include/perf/mmap.h
index 646e9052b003..4f946e7f724b 100644
--- a/tools/perf/lib/include/perf/mmap.h
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -8,5 +8,6 @@ struct perf_mmap;
LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
+LIBPERF_API void perf_mmap__read_done(struct perf_mmap *map);
#endif /* __LIBPERF_MMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index fba8cdfb3987..eca40c75b753 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -41,6 +41,7 @@ LIBPERF_0.0.1 {
perf_evlist__poll;
perf_mmap__consume;
perf_mmap__read_init;
+ perf_mmap__read_done;
local:
*;
};
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 15f91b976ce7..f27cb743183c 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -185,3 +185,20 @@ int perf_mmap__read_init(struct perf_mmap *map)
return __perf_mmap__read_init(map);
}
+
+/*
+ * Mandatory for overwrite mode
+ * The direction of overwrite mode is backward.
+ * The last perf_mmap__read() will set tail to map->core.prev.
+ * Need to correct the map->core.prev to head which is the end of next read.
+ */
+void perf_mmap__read_done(struct perf_mmap *map)
+{
+ /*
+ * Check if event was unmapped due to a POLLHUP/POLLERR.
+ */
+ if (!refcount_read(&map->refcnt))
+ return;
+
+ map->prev = perf_mmap__read_head(map);
+}
diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
index 085e4d632be4..4b5625ac257c 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -53,7 +53,7 @@ static int count_samples(struct evlist *evlist, int *sample_count,
return TEST_FAIL;
}
}
- perf_mmap__read_done(map);
+ perf_mmap__read_done(&map->core);
}
return TEST_OK;
}
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index d7e328d2d1f2..a0b559c90f9b 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -193,7 +193,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
if (type == PERF_RECORD_SAMPLE)
count ++;
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
if (count != expect) {
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 3c5de881b43c..3306d75cb596 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -434,7 +434,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,
if (ret < 0)
return ret;
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
return 0;
}
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index 3cdee969958d..10ea5112b996 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -49,7 +49,7 @@ static int find_comm(struct evlist *evlist, const char *comm)
found += 1;
perf_mmap__consume(&md->core);
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
return found;
}
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index e9c1fbe5a9aa..65b84032ee13 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -142,7 +142,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse
nr_events[evsel->idx]++;
perf_mmap__consume(&md->core);
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
out_init:
err = 0;
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index 6c04753fe5f0..771d1671f1fe 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -123,7 +123,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
goto out_ok;
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
if (nr_events == before)
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 086cabb56db2..a0a2d9a49157 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -278,7 +278,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
perf_mmap__consume(&md->core);
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
/*
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 4b13d746f264..d2612960669f 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -119,7 +119,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
next_event:
perf_mmap__consume(&md->core);
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
out_init:
if ((u64) nr_samples == total_periods) {
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index f774b50f926e..e2beb68281e2 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -280,7 +280,7 @@ static int process_events(struct evlist *evlist,
if (ret < 0)
goto out_free_nodes;
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
}
events_array = calloc(cnt, sizeof(struct event_node));
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 6a1ca5d6dfdf..988739fcaf8d 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -126,7 +126,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
perf_mmap__consume(&md->core);
}
- perf_mmap__read_done(md);
+ perf_mmap__read_done(&md->core);
out_init:
if (!exited || !nr_exit) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 38fd27f5bf0f..4f92b65e702c 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1765,7 +1765,7 @@ static void *perf_evlist__poll_thread(void *arg)
perf_mmap__consume(&map->core);
got_data = true;
}
- perf_mmap__read_done(map);
+ perf_mmap__read_done(&map->core);
}
if (draining && !got_data)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 5913f7354232..5ede1d2c84b1 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -404,20 +404,3 @@ int perf_mmap__push(struct mmap *md, void *to,
out:
return rc;
}
-
-/*
- * Mandatory for overwrite mode
- * The direction of overwrite mode is backward.
- * The last perf_mmap__read() will set tail to map->core.prev.
- * Need to correct the map->core.prev to head which is the end of next read.
- */
-void perf_mmap__read_done(struct mmap *map)
-{
- /*
- * Check if event was unmapped due to a POLLHUP/POLLERR.
- */
- if (!refcount_read(&map->core.refcnt))
- return;
-
- map->core.prev = perf_mmap__read_head(&map->core);
-}
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 3849bcbbe9ce..efc2392747ba 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -82,5 +82,4 @@ int perf_mmap__push(struct mmap *md, void *to,
size_t mmap__mmap_len(struct mmap *map);
-void perf_mmap__read_done(struct mmap *map);
#endif /*__PERF_MMAP_H */
--
2.21.0
It's needed in libperf only, moving it to
perf_evlist__mmap_ops function.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 5 +++++
tools/perf/util/evlist.c | 4 ----
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index ec83022cd62f..e27fe1fcef3d 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -32,6 +32,7 @@ void perf_evlist__init(struct perf_evlist *evlist)
INIT_HLIST_HEAD(&evlist->heads[i]);
INIT_LIST_HEAD(&evlist->entries);
evlist->nr_entries = 0;
+ fdarray__init(&evlist->pollfd, 64);
}
static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
@@ -110,6 +111,7 @@ void perf_evlist__delete(struct perf_evlist *evlist)
{
free(evlist->mmap);
free(evlist->mmap_ovw);
+ fdarray__exit(&evlist->pollfd);
free(evlist);
}
@@ -489,6 +491,9 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
return -ENOMEM;
}
+ if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
+ return -ENOMEM;
+
if (perf_cpu_map__empty(cpus))
return mmap_per_thread(evlist, ops, mp);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 94d8a1d96b81..728a15cddda7 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -57,7 +57,6 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
{
perf_evlist__init(&evlist->core);
perf_evlist__set_maps(&evlist->core, cpus, threads);
- fdarray__init(&evlist->core.pollfd, 64);
evlist->workload.pid = -1;
evlist->bkw_mmap_state = BKW_MMAP_NOTREADY;
}
@@ -804,9 +803,6 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
if (!evlist->mmap)
return -ENOMEM;
- if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(&evlist->core) < 0)
- return -ENOMEM;
-
evlist->core.mmap_len = evlist__mmap_size(pages);
pr_debug("mmap size %zuB\n", evlist->core.mmap_len);
mp.core.mask = evlist->core.mmap_len - page_size - 1;
--
2.21.0
Adding perf_evlist_mmap_ops::idx callback to be called
in mmap_per_cpu and mmap_per_thread with current cpu and
thread indexes. It's used by current aux code, so perf
will used this callback to set aux index.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 18 +++++++++++++-----
tools/perf/lib/include/internal/evlist.h | 4 ++++
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 0f103c10d8ca..67b5f14f738f 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -397,7 +397,8 @@ mmap_per_evsel(struct perf_evlist *evlist, int idx,
}
static int
-mmap_per_thread(struct perf_evlist *evlist, struct perf_mmap_param *mp)
+mmap_per_thread(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
+ struct perf_mmap_param *mp)
{
int thread;
int nr_threads = perf_thread_map__nr(evlist->threads);
@@ -406,6 +407,9 @@ mmap_per_thread(struct perf_evlist *evlist, struct perf_mmap_param *mp)
int output = -1;
int output_overwrite = -1;
+ if (ops->idx)
+ ops->idx(evlist, mp, thread, false);
+
if (mmap_per_evsel(evlist, thread, mp, 0, thread,
&output, &output_overwrite))
goto out_unmap;
@@ -419,7 +423,8 @@ mmap_per_thread(struct perf_evlist *evlist, struct perf_mmap_param *mp)
}
static int
-mmap_per_cpu(struct perf_evlist *evlist, struct perf_mmap_param *mp)
+mmap_per_cpu(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
+ struct perf_mmap_param *mp)
{
int nr_threads = perf_thread_map__nr(evlist->threads);
int nr_cpus = perf_cpu_map__nr(evlist->cpus);
@@ -429,6 +434,9 @@ mmap_per_cpu(struct perf_evlist *evlist, struct perf_mmap_param *mp)
int output = -1;
int output_overwrite = -1;
+ if (ops->idx)
+ ops->idx(evlist, mp, cpu, true);
+
for (thread = 0; thread < nr_threads; thread++) {
if (mmap_per_evsel(evlist, cpu, mp, cpu,
thread, &output, &output_overwrite))
@@ -462,15 +470,15 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
}
if (perf_cpu_map__empty(cpus))
- return mmap_per_thread(evlist, mp);
+ return mmap_per_thread(evlist, ops, mp);
- return mmap_per_cpu(evlist, mp);
+ return mmap_per_cpu(evlist, ops, mp);
}
int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
{
struct perf_mmap_param mp;
- struct perf_evlist_mmap_ops ops;
+ struct perf_evlist_mmap_ops ops = { 0 };
if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
return -ENOMEM;
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 5a8706a81c0d..64522b8237be 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -27,7 +27,11 @@ struct perf_evlist {
struct perf_mmap **mmap_ovw;
};
+typedef void
+(*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool);
+
struct perf_evlist_mmap_ops {
+ perf_evlist_mmap__cb_idx_t idx;
};
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
--
2.21.0
Adding perf_evlist__for_each_mmap function and exporting
it in perf/evlist.h header, so user can iterate through
'struct perf_mmap' objects.
Adding internal perf_mmap__link function to do the actual
linking.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 13 +++++++++++++
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/include/perf/evlist.h | 7 +++++++
tools/perf/lib/libperf.map | 1 +
tools/perf/lib/mmap.c | 6 ++++++
tools/perf/util/evlist.c | 1 +
6 files changed, 30 insertions(+)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index ee1d364460e6..ca98aac80ce1 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -382,6 +382,7 @@ perf_evlist__mmap_cb_new(struct perf_evlist *evlist, bool overwrite, int idx)
maps = overwrite ? evlist->mmap_ovw : evlist->mmap;
maps[idx] = map;
+ perf_mmap__link(idx ? maps[idx - 1] : NULL, map);
return map;
}
@@ -584,3 +585,15 @@ void perf_evlist__munmap(struct perf_evlist *evlist)
zfree(&evlist->mmap);
zfree(&evlist->mmap_ovw);
}
+
+struct perf_mmap*
+perf_evlist__next_mmap(struct perf_evlist *evlist, struct perf_mmap *map)
+{
+ if (map)
+ return map->next;
+
+ if (!evlist->mmap)
+ return NULL;
+
+ return evlist->mmap[0];
+}
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 98e31f8ab461..f0fdf9b5a1d5 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -33,6 +33,7 @@ struct perf_mmap {
u64 flush;
libperf_unmap_cb_t unmap_cb;
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
+ struct perf_mmap *next;
};
struct perf_mmap_param {
@@ -54,4 +55,5 @@ void perf_mmap__put(struct perf_mmap *map);
u64 perf_mmap__read_head(struct perf_mmap *map);
+void perf_mmap__link(struct perf_mmap *prev, struct perf_mmap *map);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h
index 16f526e74d13..9c3f341dc261 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -38,4 +38,11 @@ LIBPERF_API int perf_evlist__filter_pollfd(struct perf_evlist *evlist,
LIBPERF_API int perf_evlist__mmap(struct perf_evlist *evlist, int pages);
LIBPERF_API void perf_evlist__munmap(struct perf_evlist *evlist);
+LIBPERF_API struct perf_mmap *perf_evlist__next_mmap(struct perf_evlist *evlist,
+ struct perf_mmap *map);
+#define perf_evlist__for_each_mmap(evlist, pos) \
+ for ((pos) = perf_evlist__next_mmap((evlist), NULL); \
+ (pos) != NULL; \
+ (pos) = perf_evlist__next_mmap((evlist), (pos)))
+
#endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 90aee2a635b2..265188126b08 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -42,6 +42,7 @@ LIBPERF_0.0.1 {
perf_evlist__mmap;
perf_evlist__munmap;
perf_evlist__filter_pollfd;
+ perf_evlist__next_mmap;
perf_mmap__consume;
perf_mmap__read_init;
perf_mmap__read_done;
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index f8816c7bee87..453c8a57a895 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -281,3 +281,9 @@ union perf_event *perf_mmap__read_event(struct perf_mmap *map)
return event;
}
+
+void perf_mmap__link(struct perf_mmap *prev, struct perf_mmap *map)
+{
+ if (prev)
+ prev->next = map;
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 9edb0855f711..1e703eb11500 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -591,6 +591,7 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
* thus does perf_mmap__get() on it.
*/
perf_mmap__init(&map[i].core, overwrite, perf_mmap__unmap_cb);
+ perf_mmap__link(i ? &map[i - 1].core : NULL, &map[i].core);
}
return map;
--
2.21.0
Let perf_evlist__delete do all the necessary cleanup.
All the cleanup functions check if the their data is
created before cleaning it up, so it's ok to call any
of them separately before perf_evlist__delete.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 1c8a9e283adc..8920833afa9e 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -132,6 +132,11 @@ void perf_evlist__exit(struct perf_evlist *evlist)
void perf_evlist__delete(struct perf_evlist *evlist)
{
+ if (evlist == NULL)
+ return;
+
+ perf_evlist__munmap(evlist);
+ perf_evlist__close(evlist);
perf_evlist__purge(evlist);
perf_evlist__exit(evlist);
free(evlist);
--
2.21.0
Keeping the count of failed tests, so we
get better output with failures, like:
# make tests
...
running static:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...FAILED test-evlist.c:53 failed to create evsel2
FAILED test-evlist.c:163 failed to create evsel2
FAILED test-evlist.c:287 failed count
FAILED (3)
- running test-evsel.c...OK
running dynamic:
- running test-cpumap.c...OK
- running test-threadmap.c...OK
- running test-evlist.c...FAILED test-evlist.c:53 failed to create evsel2
FAILED test-evlist.c:163 failed to create evsel2
FAILED test-evlist.c:287 failed count
FAILED (3)
- running test-evsel.c...OK
...
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/tests.h | 20 +++++++++++++++++---
tools/perf/lib/tests/test-cpumap.c | 2 +-
tools/perf/lib/tests/test-evlist.c | 2 +-
tools/perf/lib/tests/test-evsel.c | 2 +-
tools/perf/lib/tests/test-threadmap.c | 2 +-
5 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/tools/perf/lib/include/internal/tests.h b/tools/perf/lib/include/internal/tests.h
index b7a20cd24ee1..2093e8868a67 100644
--- a/tools/perf/lib/include/internal/tests.h
+++ b/tools/perf/lib/include/internal/tests.h
@@ -4,14 +4,28 @@
#include <stdio.h>
-#define __T_START fprintf(stdout, "- running %s...", __FILE__)
-#define __T_OK fprintf(stdout, "OK\n")
-#define __T_FAIL fprintf(stdout, "FAIL\n")
+int tests_failed;
+
+#define __T_START \
+do { \
+ fprintf(stdout, "- running %s...", __FILE__); \
+ fflush(NULL); \
+ tests_failed = 0; \
+} while (0)
+
+#define __T_END \
+do { \
+ if (tests_failed) \
+ fprintf(stdout, " FAILED (%d)\n", tests_failed); \
+ else \
+ fprintf(stdout, "OK\n"); \
+} while (0)
#define __T(text, cond) \
do { \
if (!(cond)) { \
fprintf(stderr, "FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
+ tests_failed++; \
return -1; \
} \
} while (0)
diff --git a/tools/perf/lib/tests/test-cpumap.c b/tools/perf/lib/tests/test-cpumap.c
index 4224d6f213f8..d28306710104 100644
--- a/tools/perf/lib/tests/test-cpumap.c
+++ b/tools/perf/lib/tests/test-cpumap.c
@@ -24,6 +24,6 @@ int main(int argc, char **argv)
perf_cpu_map__put(cpus);
perf_cpu_map__put(cpus);
- __T_OK;
+ __T_END;
return 0;
}
diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c
index 2b7271130223..80906e04ab0c 100644
--- a/tools/perf/lib/tests/test-evlist.c
+++ b/tools/perf/lib/tests/test-evlist.c
@@ -407,6 +407,6 @@ int main(int argc, char **argv)
test_mmap_thread();
test_mmap_cpus();
- __T_OK;
+ __T_END;
return 0;
}
diff --git a/tools/perf/lib/tests/test-evsel.c b/tools/perf/lib/tests/test-evsel.c
index 64d2257a93cb..1c9c4ec94e59 100644
--- a/tools/perf/lib/tests/test-evsel.c
+++ b/tools/perf/lib/tests/test-evsel.c
@@ -128,6 +128,6 @@ int main(int argc, char **argv)
test_stat_thread();
test_stat_thread_enable();
- __T_OK;
+ __T_END;
return 0;
}
diff --git a/tools/perf/lib/tests/test-threadmap.c b/tools/perf/lib/tests/test-threadmap.c
index 9b72c43c8c59..7366bdbf4adf 100644
--- a/tools/perf/lib/tests/test-threadmap.c
+++ b/tools/perf/lib/tests/test-threadmap.c
@@ -24,6 +24,6 @@ int main(int argc, char **argv)
perf_thread_map__put(threads);
perf_thread_map__put(threads);
- __T_OK;
+ __T_END;
return 0;
}
--
2.21.0
Move flush from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 10 +++++-----
tools/perf/lib/include/internal/mmap.h | 1 +
tools/perf/util/mmap.c | 4 ++--
tools/perf/util/mmap.h | 1 -
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 6c0349dcb20c..400ce2f3fa99 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -959,13 +959,13 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
if (map->core.base) {
record__adjust_affinity(rec, map);
if (synch) {
- flush = map->flush;
- map->flush = 1;
+ flush = map->core.flush;
+ map->core.flush = 1;
}
if (!record__aio_enabled(rec)) {
if (perf_mmap__push(map, rec, record__pushfn) < 0) {
if (synch)
- map->flush = flush;
+ map->core.flush = flush;
rc = -1;
goto out;
}
@@ -973,13 +973,13 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
if (record__aio_push(rec, map, &off) < 0) {
record__aio_set_pos(trace_fd, off);
if (synch)
- map->flush = flush;
+ map->core.flush = flush;
rc = -1;
goto out;
}
}
if (synch)
- map->flush = flush;
+ map->core.flush = flush;
}
if (map->auxtrace_mmap.base && !rec->opts.auxtrace_snapshot_mode &&
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 3a404ec06214..a147b25c4b88 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -25,6 +25,7 @@ struct perf_mmap {
u64 start;
u64 end;
bool overwrite;
+ u64 flush;
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
};
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 4b8ec8dd79c5..4cc3b54b2f73 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -383,7 +383,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
perf_mmap__setup_affinity_mask(map, mp);
- map->flush = mp->flush;
+ map->core.flush = mp->flush;
map->comp_level = mp->comp_level;
@@ -450,7 +450,7 @@ static int __perf_mmap__read_init(struct mmap *md)
md->core.start = md->core.overwrite ? head : old;
md->core.end = md->core.overwrite ? old : head;
- if ((md->core.end - md->core.start) < md->flush)
+ if ((md->core.end - md->core.start) < md->core.flush)
return -EAGAIN;
size = md->core.end - md->core.start;
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index bdbbf48ee906..e335c341d073 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -32,7 +32,6 @@ struct mmap {
} aio;
#endif
cpu_set_t affinity_mask;
- u64 flush;
void *data;
int comp_level;
};
--
2.21.0
Move heads hash from struct evlist to struct perf_evlist.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 4 ++++
tools/perf/lib/include/internal/evlist.h | 4 ++++
tools/perf/util/evlist.c | 10 +++-------
tools/perf/util/evlist.h | 4 ----
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index f4dc9a208332..2bdd9d2c79d9 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -11,6 +11,10 @@
void perf_evlist__init(struct perf_evlist *evlist)
{
+ int i;
+
+ for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i)
+ INIT_HLIST_HEAD(&evlist->heads[i]);
INIT_LIST_HEAD(&evlist->entries);
evlist->nr_entries = 0;
}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 8a4eb66fbf3a..c5a06890fd6a 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -5,6 +5,9 @@
#include <linux/list.h>
#include <api/fd/array.h>
+#define PERF_EVLIST__HLIST_BITS 8
+#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
+
struct perf_cpu_map;
struct perf_thread_map;
@@ -17,6 +20,7 @@ struct perf_evlist {
int nr_mmaps;
size_t mmap_len;
struct fdarray pollfd;
+ struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
};
/**
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 9dcecb5e05a0..2f883db7c8e7 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -54,10 +54,6 @@ int sigqueue(pid_t pid, int sig, const union sigval value);
void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
struct perf_thread_map *threads)
{
- int i;
-
- for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i)
- INIT_HLIST_HEAD(&evlist->heads[i]);
perf_evlist__init(&evlist->core);
perf_evlist__set_maps(&evlist->core, cpus, threads);
fdarray__init(&evlist->core.pollfd, 64);
@@ -474,7 +470,7 @@ static void perf_evlist__id_hash(struct evlist *evlist,
sid->id = id;
sid->evsel = evsel;
hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
- hlist_add_head(&sid->node, &evlist->heads[hash]);
+ hlist_add_head(&sid->node, &evlist->core.heads[hash]);
}
void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel,
@@ -548,7 +544,7 @@ struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id)
int hash;
hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
- head = &evlist->heads[hash];
+ head = &evlist->core.heads[hash];
hlist_for_each_entry(sid, head, node)
if (sid->id == id)
@@ -634,7 +630,7 @@ struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
return first;
hash = hash_64(id, PERF_EVLIST__HLIST_BITS);
- head = &evlist->heads[hash];
+ head = &evlist->core.heads[hash];
hlist_for_each_entry(sid, head, node) {
if (sid->id == id)
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index b8f03452196f..7306a0677171 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -20,12 +20,8 @@ struct thread_map;
struct perf_cpu_map;
struct record_opts;
-#define PERF_EVLIST__HLIST_BITS 8
-#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
-
struct evlist {
struct perf_evlist core;
- struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
int nr_groups;
bool enabled;
int id_pos;
--
2.21.0
Adding perf_evlist__first/last functions to libperf,
as internal functions and renaming perf's origins
to evlist__first/last.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/arm/util/cs-etm.c | 2 +-
tools/perf/arch/arm64/util/arm-spe.c | 2 +-
tools/perf/arch/x86/tests/intel-cqm.c | 4 +-
tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
tools/perf/arch/x86/util/intel-bts.c | 2 +-
tools/perf/arch/x86/util/intel-pt.c | 6 +-
tools/perf/builtin-record.c | 4 +-
tools/perf/builtin-script.c | 2 +-
tools/perf/builtin-top.c | 10 +-
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/include/internal/evlist.h | 11 ++
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/event-times.c | 14 +--
tools/perf/tests/event_update.c | 2 +-
tools/perf/tests/evsel-roundtrip-name.c | 2 +-
tools/perf/tests/hists_cumulate.c | 2 +-
tools/perf/tests/hists_link.c | 4 +-
tools/perf/tests/hists_output.c | 2 +-
tools/perf/tests/keep-tracking.c | 4 +-
tools/perf/tests/parse-events.c | 116 +++++++++----------
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/switch-tracking.c | 14 +--
tools/perf/tests/task-exit.c | 2 +-
tools/perf/ui/browsers/hists.c | 6 +-
tools/perf/util/bpf-loader.c | 2 +-
tools/perf/util/evlist.c | 24 ++--
tools/perf/util/evlist.h | 13 ++-
tools/perf/util/jitdump.c | 2 +-
tools/perf/util/parse-events.c | 4 +-
tools/perf/util/record.c | 6 +-
tools/perf/util/sort.c | 2 +-
tools/perf/util/top.c | 2 +-
32 files changed, 145 insertions(+), 129 deletions(-)
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 6407edf72edd..f95e52b84991 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -416,7 +416,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr,
if (err)
goto out;
- tracking_evsel = perf_evlist__last(evlist);
+ tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel);
tracking_evsel->core.attr.freq = 0;
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 2fcabddd87b5..685dcc43223a 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -129,7 +129,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
if (err)
return err;
- tracking_evsel = perf_evlist__last(evlist);
+ tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel);
tracking_evsel->core.attr.freq = 0;
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c b/tools/perf/arch/x86/tests/intel-cqm.c
index 3b5cc3373821..1eed126a1a7b 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -63,9 +63,9 @@ int test__intel_cqm_count_nmi_context(struct test *test __maybe_unused, int subt
goto out;
}
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
if (!evsel) {
- pr_debug("perf_evlist__first failed\n");
+ pr_debug("evlist__first failed\n");
goto out;
}
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 185bdbf8cb9d..0aa96f531653 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -83,7 +83,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
perf_evlist__config(evlist, &opts, NULL);
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1;
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 5dd42e6d22f9..c521fd8acddc 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -230,7 +230,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr,
if (err)
return err;
- tracking_evsel = perf_evlist__last(evlist);
+ tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel);
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 42f111323c31..a6e8db467c4c 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -416,7 +416,7 @@ static int intel_pt_track_switches(struct evlist *evlist)
return err;
}
- evsel = perf_evlist__last(evlist);
+ evsel = evlist__last(evlist);
perf_evsel__set_sample_bit(evsel, CPU);
perf_evsel__set_sample_bit(evsel, TIME);
@@ -716,7 +716,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
if (err)
return err;
- switch_evsel = perf_evlist__last(evlist);
+ switch_evsel = evlist__last(evlist);
switch_evsel->core.attr.freq = 0;
switch_evsel->core.attr.sample_period = 1;
@@ -774,7 +774,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
if (err)
return err;
- tracking_evsel = perf_evlist__last(evlist);
+ tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel);
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 68091f3773a8..efad7e6a2dca 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -753,9 +753,9 @@ static int record__open(struct record *rec)
if (perf_evlist__add_dummy(evlist))
return -ENOMEM;
- pos = perf_evlist__first(evlist);
+ pos = evlist__first(evlist);
pos->tracking = 0;
- pos = perf_evlist__last(evlist);
+ pos = evlist__last(evlist);
pos->tracking = 1;
pos->core.attr.enable_on_exec = 1;
}
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c602793d5483..e3c7013099c6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2042,7 +2042,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
return err;
evlist = *pevlist;
- evsel = perf_evlist__last(*pevlist);
+ evsel = evlist__last(*pevlist);
if (!evsel->priv) {
if (scr->per_event_dump) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5698234cef88..0942e8d4c93b 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -528,7 +528,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
prompt_integer(&counter, "Enter details event counter");
if (counter >= top->evlist->core.nr_entries) {
- top->sym_evsel = perf_evlist__first(top->evlist);
+ top->sym_evsel = evlist__first(top->evlist);
fprintf(stderr, "Sorry, no such event, using %s.\n", perf_evsel__name(top->sym_evsel));
sleep(1);
break;
@@ -537,7 +537,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
if (top->sym_evsel->idx == counter)
break;
} else
- top->sym_evsel = perf_evlist__first(top->evlist);
+ top->sym_evsel = evlist__first(top->evlist);
break;
case 'f':
prompt_integer(&top->count_filter, "Enter display event count filter");
@@ -959,7 +959,7 @@ static int perf_top__overwrite_check(struct perf_top *top)
/* has term for current event */
if ((overwrite < 0) && (set >= 0)) {
/* if it's first event, set overwrite */
- if (evsel == perf_evlist__first(evlist))
+ if (evsel == evlist__first(evlist))
overwrite = set;
else
return -1;
@@ -983,7 +983,7 @@ static int perf_top_overwrite_fallback(struct perf_top *top,
return 0;
/* only fall back when first event fails */
- if (evsel != perf_evlist__first(evlist))
+ if (evsel != evlist__first(evlist))
return 0;
evlist__for_each_entry(evlist, counter)
@@ -1641,7 +1641,7 @@ int cmd_top(int argc, const char **argv)
goto out_delete_evlist;
}
- top.sym_evsel = perf_evlist__first(top.evlist);
+ top.sym_evsel = evlist__first(top.evlist);
if (!callchain_param.enabled) {
symbol_conf.cumulate_callchain = false;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6e9797d85d54..0dc35aa624c5 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3425,7 +3425,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
evlist->core.threads->nr > 1 ||
- perf_evlist__first(evlist)->core.attr.inherit;
+ evlist__first(evlist)->core.attr.inherit;
/*
* Now that we already used evsel->core.attr to ask the kernel to setup the
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index c5a06890fd6a..16ae6d6cfb39 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -4,6 +4,7 @@
#include <linux/list.h>
#include <api/fd/array.h>
+#include <internal/evsel.h>
#define PERF_EVLIST__HLIST_BITS 8
#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
@@ -55,4 +56,14 @@ struct perf_evlist {
#define perf_evlist__for_each_entry_reverse(evlist, evsel) \
__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
+static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
+{
+ return list_entry(evlist->entries.next, struct perf_evsel, node);
+}
+
+static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
+{
+ return list_entry(evlist->entries.prev, struct perf_evsel, node);
+}
+
#endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 72ae94be686e..77dc68a23b70 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -651,7 +651,7 @@ static int do_test_code_reading(bool try_kcore)
perf_evlist__config(evlist, &opts, NULL);
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1;
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index d824a726906c..afba710b2591 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -17,7 +17,7 @@
static int attach__enable_on_exec(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__last(evlist);
+ struct evsel *evsel = evlist__last(evlist);
struct target target = {
.uid = UINT_MAX,
};
@@ -59,7 +59,7 @@ static int detach__enable_on_exec(struct evlist *evlist)
static int attach__current_disabled(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__last(evlist);
+ struct evsel *evsel = evlist__last(evlist);
struct perf_thread_map *threads;
int err;
@@ -85,7 +85,7 @@ static int attach__current_disabled(struct evlist *evlist)
static int attach__current_enabled(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__last(evlist);
+ struct evsel *evsel = evlist__last(evlist);
struct perf_thread_map *threads;
int err;
@@ -105,14 +105,14 @@ static int attach__current_enabled(struct evlist *evlist)
static int detach__disable(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__last(evlist);
+ struct evsel *evsel = evlist__last(evlist);
return evsel__enable(evsel);
}
static int attach__cpu_disabled(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__last(evlist);
+ struct evsel *evsel = evlist__last(evlist);
struct perf_cpu_map *cpus;
int err;
@@ -141,7 +141,7 @@ static int attach__cpu_disabled(struct evlist *evlist)
static int attach__cpu_enabled(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__last(evlist);
+ struct evsel *evsel = evlist__last(evlist);
struct perf_cpu_map *cpus;
int err;
@@ -181,7 +181,7 @@ static int test_times(int (attach)(struct evlist *),
goto out_err;
}
- evsel = perf_evlist__last(evlist);
+ evsel = evlist__last(evlist);
evsel->core.attr.read_format |=
PERF_FORMAT_TOTAL_TIME_ENABLED |
PERF_FORMAT_TOTAL_TIME_RUNNING;
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c
index dce929c83062..0c982550799c 100644
--- a/tools/perf/tests/event_update.c
+++ b/tools/perf/tests/event_update.c
@@ -90,7 +90,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
evlist = perf_evlist__new_default();
TEST_ASSERT_VAL("failed to get evlist", evlist);
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
TEST_ASSERT_VAL("failed to allos ids",
!perf_evsel__alloc_id(&evsel->core, 1, 1));
diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c
index 5330f106a6ee..956205bf9326 100644
--- a/tools/perf/tests/evsel-roundtrip-name.c
+++ b/tools/perf/tests/evsel-roundtrip-name.c
@@ -34,7 +34,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)
}
idx = 0;
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index fa55b7bad3af..6367c8f6ca22 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -721,7 +721,7 @@ int test__hists_cumulate(struct test *test __maybe_unused, int subtest __maybe_u
if (verbose > 1)
machine__fprintf(machine, stderr);
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
for (i = 0; i < ARRAY_SIZE(testcases); i++) {
err = testcases[i](evsel, machine);
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 8be4d0b61e3a..a6d9126cf9b6 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -310,8 +310,8 @@ int test__hists_link(struct test *test __maybe_unused, int subtest __maybe_unuse
print_hists_in(hists);
}
- first = perf_evlist__first(evlist);
- evsel = perf_evlist__last(evlist);
+ first = evlist__first(evlist);
+ evsel = evlist__last(evlist);
first_hists = evsel__hists(first);
hists = evsel__hists(evsel);
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index 3f6dfa212260..38f804ff6452 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -608,7 +608,7 @@ int test__hists_output(struct test *test __maybe_unused, int subtest __maybe_unu
if (verbose > 1)
machine__fprintf(machine, stderr);
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
for (i = 0; i < ARRAY_SIZE(testcases); i++) {
err = testcases[i](evsel, machine);
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index ac44d72e39c3..2623b925b87f 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -93,7 +93,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un
perf_evlist__config(evlist, &opts, NULL);
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1;
@@ -132,7 +132,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_un
evlist__enable(evlist);
- evsel = perf_evlist__last(evlist);
+ evsel = evlist__last(evlist);
CHECK__(evsel__disable(evsel));
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 02ba696fb87f..c95e2a46911a 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -47,7 +47,7 @@ static bool kvm_s390_create_vm_valid(void)
static int test__checkevent_tracepoint(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong number of groups", 0 == evlist->nr_groups);
@@ -78,7 +78,7 @@ static int test__checkevent_tracepoint_multi(struct evlist *evlist)
static int test__checkevent_raw(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
@@ -88,7 +88,7 @@ static int test__checkevent_raw(struct evlist *evlist)
static int test__checkevent_numeric(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", 1 == evsel->core.attr.type);
@@ -98,7 +98,7 @@ static int test__checkevent_numeric(struct evlist *evlist)
static int test__checkevent_symbolic_name(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
@@ -109,7 +109,7 @@ static int test__checkevent_symbolic_name(struct evlist *evlist)
static int test__checkevent_symbolic_name_config(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
@@ -130,7 +130,7 @@ static int test__checkevent_symbolic_name_config(struct evlist *evlist)
static int test__checkevent_symbolic_alias(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
@@ -141,7 +141,7 @@ static int test__checkevent_symbolic_alias(struct evlist *evlist)
static int test__checkevent_genhw(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->core.attr.type);
@@ -151,7 +151,7 @@ static int test__checkevent_genhw(struct evlist *evlist)
static int test__checkevent_breakpoint(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
@@ -165,7 +165,7 @@ static int test__checkevent_breakpoint(struct evlist *evlist)
static int test__checkevent_breakpoint_x(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
@@ -178,7 +178,7 @@ static int test__checkevent_breakpoint_x(struct evlist *evlist)
static int test__checkevent_breakpoint_r(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type",
@@ -193,7 +193,7 @@ static int test__checkevent_breakpoint_r(struct evlist *evlist)
static int test__checkevent_breakpoint_w(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type",
@@ -208,7 +208,7 @@ static int test__checkevent_breakpoint_w(struct evlist *evlist)
static int test__checkevent_breakpoint_rw(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type",
@@ -223,7 +223,7 @@ static int test__checkevent_breakpoint_rw(struct evlist *evlist)
static int test__checkevent_tracepoint_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
@@ -254,7 +254,7 @@ test__checkevent_tracepoint_multi_modifier(struct evlist *evlist)
static int test__checkevent_raw_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
@@ -266,7 +266,7 @@ static int test__checkevent_raw_modifier(struct evlist *evlist)
static int test__checkevent_numeric_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -278,7 +278,7 @@ static int test__checkevent_numeric_modifier(struct evlist *evlist)
static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -290,7 +290,7 @@ static int test__checkevent_symbolic_name_modifier(struct evlist *evlist)
static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host", evsel->core.attr.exclude_host);
@@ -300,7 +300,7 @@ static int test__checkevent_exclude_host_modifier(struct evlist *evlist)
static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
@@ -310,7 +310,7 @@ static int test__checkevent_exclude_guest_modifier(struct evlist *evlist)
static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -322,7 +322,7 @@ static int test__checkevent_symbolic_alias_modifier(struct evlist *evlist)
static int test__checkevent_genhw_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
@@ -334,7 +334,7 @@ static int test__checkevent_genhw_modifier(struct evlist *evlist)
static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
@@ -349,7 +349,7 @@ static int test__checkevent_exclude_idle_modifier(struct evlist *evlist)
static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude idle", evsel->core.attr.exclude_idle);
TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
@@ -364,7 +364,7 @@ static int test__checkevent_exclude_idle_modifier_1(struct evlist *evlist)
static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
@@ -379,7 +379,7 @@ static int test__checkevent_breakpoint_modifier(struct evlist *evlist)
static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
@@ -393,7 +393,7 @@ static int test__checkevent_breakpoint_x_modifier(struct evlist *evlist)
static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -407,7 +407,7 @@ static int test__checkevent_breakpoint_r_modifier(struct evlist *evlist)
static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -421,7 +421,7 @@ static int test__checkevent_breakpoint_w_modifier(struct evlist *evlist)
static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
@@ -436,7 +436,7 @@ static int test__checkevent_breakpoint_rw_modifier(struct evlist *evlist)
static int test__checkevent_pmu(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
@@ -454,7 +454,7 @@ static int test__checkevent_pmu(struct evlist *evlist)
static int test__checkevent_list(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
@@ -493,7 +493,7 @@ static int test__checkevent_list(struct evlist *evlist)
static int test__checkevent_pmu_name(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
/* cpu/config=1,name=krava/u */
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
@@ -514,7 +514,7 @@ static int test__checkevent_pmu_name(struct evlist *evlist)
static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
/* cpu/config=1,call-graph=fp,time,period=100000/ */
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
@@ -547,7 +547,7 @@ static int test__checkevent_pmu_partial_time_callgraph(struct evlist *evlist)
static int test__checkevent_pmu_events(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type);
@@ -565,7 +565,7 @@ static int test__checkevent_pmu_events(struct evlist *evlist)
static int test__checkevent_pmu_events_mix(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
/* pmu-event:u */
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
@@ -643,7 +643,7 @@ static int test__group1(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* instructions:k */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
@@ -685,7 +685,7 @@ static int test__group2(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* faults + :ku modifier */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_SW_PAGE_FAULTS == evsel->core.attr.config);
@@ -740,7 +740,7 @@ static int test__group3(struct evlist *evlist __maybe_unused)
TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
/* group1 syscalls:sys_enter_openat:H */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong sample_type",
PERF_TP_SAMPLE_TYPE == evsel->core.attr.sample_type);
@@ -832,7 +832,7 @@ static int test__group4(struct evlist *evlist __maybe_unused)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* cycles:u + p */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -876,7 +876,7 @@ static int test__group5(struct evlist *evlist __maybe_unused)
TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
/* cycles + G */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -962,7 +962,7 @@ static int test__group_gh1(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* cycles + :H group modifier */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -1002,7 +1002,7 @@ static int test__group_gh2(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* cycles + :G group modifier */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -1042,7 +1042,7 @@ static int test__group_gh3(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* cycles:G + :u group modifier */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -1082,7 +1082,7 @@ static int test__group_gh4(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of groups", 1 == evlist->nr_groups);
/* cycles:G + :uG group modifier */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -1121,7 +1121,7 @@ static int test__leader_sample1(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
/* cycles - sampling group leader */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -1174,7 +1174,7 @@ static int test__leader_sample2(struct evlist *evlist __maybe_unused)
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
/* instructions - sampling group leader */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_INSTRUCTIONS == evsel->core.attr.config);
@@ -1208,7 +1208,7 @@ static int test__leader_sample2(struct evlist *evlist __maybe_unused)
static int test__checkevent_pinned_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -1226,7 +1226,7 @@ static int test__pinned_group(struct evlist *evlist)
TEST_ASSERT_VAL("wrong number of entries", 3 == evlist->core.nr_entries);
/* cycles - group leader */
- evsel = leader = perf_evlist__first(evlist);
+ evsel = leader = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->core.attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->core.attr.config);
@@ -1252,7 +1252,7 @@ static int test__pinned_group(struct evlist *evlist)
static int test__checkevent_breakpoint_len(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
@@ -1267,7 +1267,7 @@ static int test__checkevent_breakpoint_len(struct evlist *evlist)
static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->core.attr.type);
@@ -1283,7 +1283,7 @@ static int test__checkevent_breakpoint_len_w(struct evlist *evlist)
static int
test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
@@ -1295,7 +1295,7 @@ test__checkevent_breakpoint_len_rw_modifier(struct evlist *evlist)
static int test__checkevent_precise_max_modifier(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->core.nr_entries);
TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->core.attr.type);
@@ -1306,7 +1306,7 @@ static int test__checkevent_precise_max_modifier(struct evlist *evlist)
static int test__checkevent_config_symbol(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
return 0;
@@ -1314,7 +1314,7 @@ static int test__checkevent_config_symbol(struct evlist *evlist)
static int test__checkevent_config_raw(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
return 0;
@@ -1322,7 +1322,7 @@ static int test__checkevent_config_raw(struct evlist *evlist)
static int test__checkevent_config_num(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
return 0;
@@ -1330,7 +1330,7 @@ static int test__checkevent_config_num(struct evlist *evlist)
static int test__checkevent_config_cache(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0);
return 0;
@@ -1343,7 +1343,7 @@ static bool test__intel_pt_valid(void)
static int test__intel_pt(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0);
return 0;
@@ -1351,7 +1351,7 @@ static int test__intel_pt(struct evlist *evlist)
static int test__checkevent_complex_name(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong complex name parsing", strcmp(evsel->name, "COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks") == 0);
return 0;
@@ -1359,7 +1359,7 @@ static int test__checkevent_complex_name(struct evlist *evlist)
static int test__sym_event_slash(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
@@ -1369,7 +1369,7 @@ static int test__sym_event_slash(struct evlist *evlist)
static int test__sym_event_dc(struct evlist *evlist)
{
- struct evsel *evsel = perf_evlist__first(evlist);
+ struct evsel *evsel = evlist__first(evlist);
TEST_ASSERT_VAL("wrong type", evsel->core.attr.type == PERF_TYPE_HARDWARE);
TEST_ASSERT_VAL("wrong config", evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES);
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index dbecc66712af..80da5b2c6bdc 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -103,7 +103,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
/*
* Config the evsels, setting attr->comm on the first one, etc.
*/
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
perf_evsel__set_sample_bit(evsel, CPU);
perf_evsel__set_sample_bit(evsel, TID);
perf_evsel__set_sample_bit(evsel, TIME);
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 115eae0f45f1..29f503820a1e 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -367,7 +367,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err;
}
- cpu_clocks_evsel = perf_evlist__last(evlist);
+ cpu_clocks_evsel = evlist__last(evlist);
/* Second event */
err = parse_events(evlist, "cycles:u", NULL);
@@ -376,7 +376,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err;
}
- cycles_evsel = perf_evlist__last(evlist);
+ cycles_evsel = evlist__last(evlist);
/* Third event */
if (!perf_evlist__can_select_event(evlist, sched_switch)) {
@@ -391,7 +391,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err;
}
- switch_evsel = perf_evlist__last(evlist);
+ switch_evsel = evlist__last(evlist);
perf_evsel__set_sample_bit(switch_evsel, CPU);
perf_evsel__set_sample_bit(switch_evsel, TIME);
@@ -401,12 +401,12 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
switch_evsel->immediate = true;
/* Test moving an event to the front */
- if (cycles_evsel == perf_evlist__first(evlist)) {
+ if (cycles_evsel == evlist__first(evlist)) {
pr_debug("cycles event already at front");
goto out_err;
}
perf_evlist__to_front(evlist, cycles_evsel);
- if (cycles_evsel != perf_evlist__first(evlist)) {
+ if (cycles_evsel != evlist__first(evlist)) {
pr_debug("Failed to move cycles event to front");
goto out_err;
}
@@ -421,7 +421,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
goto out_err;
}
- tracking_evsel = perf_evlist__last(evlist);
+ tracking_evsel = evlist__last(evlist);
perf_evlist__set_tracking_event(evlist, tracking_evsel);
@@ -434,7 +434,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
perf_evlist__config(evlist, &opts, NULL);
/* Check moved event is still at the front */
- if (cycles_evsel != perf_evlist__first(evlist)) {
+ if (cycles_evsel != evlist__first(evlist)) {
pr_debug("Front event no longer at front");
goto out_err;
}
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 76c1a8417da9..81c57a6b627f 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -87,7 +87,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
goto out_delete_evlist;
}
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
evsel->core.attr.task = 1;
#ifdef __s390x__
evsel->core.attr.sample_freq = 1000000;
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 589168ca9f62..7a7187e069b4 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -3319,13 +3319,13 @@ static int perf_evsel_menu__run(struct evsel_menu *menu,
switch (key) {
case K_TAB:
if (pos->core.node.next == &evlist->core.entries)
- pos = perf_evlist__first(evlist);
+ pos = evlist__first(evlist);
else
pos = perf_evsel__next(pos);
goto browse_hists;
case K_UNTAB:
if (pos->core.node.prev == &evlist->core.entries)
- pos = perf_evlist__last(evlist);
+ pos = evlist__last(evlist);
else
pos = perf_evsel__prev(pos);
goto browse_hists;
@@ -3417,7 +3417,7 @@ int perf_evlist__tui_browse_hists(struct evlist *evlist, const char *help,
single_entry:
if (nr_entries == 1) {
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
return perf_evsel__hists_browse(first, nr_entries, help,
false, hbt, min_pcnt,
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 37283e865352..10c187b8b8ea 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1568,7 +1568,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name)
return ERR_PTR(-err);
}
- evsel = perf_evlist__last(evlist);
+ evsel = evlist__last(evlist);
}
bpf__for_each_map_named(map, obj, tmp, name) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 472cbb47272a..a57e2f9c6e6d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -104,7 +104,7 @@ struct evlist *perf_evlist__new_dummy(void)
*/
void perf_evlist__set_id_pos(struct evlist *evlist)
{
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
evlist->id_pos = first->id_pos;
evlist->is_pos = first->is_pos;
@@ -558,14 +558,14 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
struct perf_sample_id *sid;
if (evlist->core.nr_entries == 1 || !id)
- return perf_evlist__first(evlist);
+ return evlist__first(evlist);
sid = perf_evlist__id2sid(evlist, id);
if (sid)
return container_of(sid->evsel, struct evsel, core);
if (!perf_evlist__sample_id_all(evlist))
- return perf_evlist__first(evlist);
+ return evlist__first(evlist);
return NULL;
}
@@ -609,7 +609,7 @@ static int perf_evlist__event2id(struct evlist *evlist,
struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
union perf_event *event)
{
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
struct hlist_head *head;
struct perf_sample_id *sid;
int hash;
@@ -1221,7 +1221,7 @@ u64 perf_evlist__combined_branch_type(struct evlist *evlist)
bool perf_evlist__valid_read_format(struct evlist *evlist)
{
- struct evsel *first = perf_evlist__first(evlist), *pos = first;
+ struct evsel *first = evlist__first(evlist), *pos = first;
u64 read_format = first->core.attr.read_format;
u64 sample_type = first->core.attr.sample_type;
@@ -1241,13 +1241,13 @@ bool perf_evlist__valid_read_format(struct evlist *evlist)
u64 perf_evlist__read_format(struct evlist *evlist)
{
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
return first->core.attr.read_format;
}
u16 perf_evlist__id_hdr_size(struct evlist *evlist)
{
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
struct perf_sample *data;
u64 sample_type;
u16 size = 0;
@@ -1280,7 +1280,7 @@ u16 perf_evlist__id_hdr_size(struct evlist *evlist)
bool perf_evlist__valid_sample_id_all(struct evlist *evlist)
{
- struct evsel *first = perf_evlist__first(evlist), *pos = first;
+ struct evsel *first = evlist__first(evlist), *pos = first;
evlist__for_each_entry_continue(evlist, pos) {
if (first->core.attr.sample_id_all != pos->core.attr.sample_id_all)
@@ -1292,7 +1292,7 @@ bool perf_evlist__valid_sample_id_all(struct evlist *evlist)
bool perf_evlist__sample_id_all(struct evlist *evlist)
{
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
return first->core.attr.sample_id_all;
}
@@ -1567,7 +1567,7 @@ int perf_evlist__strerror_open(struct evlist *evlist,
"Hint:\tThe current value is %d.", value);
break;
case EINVAL: {
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
int max_freq;
if (sysctl__read_int("kernel/perf_event_max_sample_rate", &max_freq) < 0)
@@ -1629,7 +1629,7 @@ void perf_evlist__to_front(struct evlist *evlist,
struct evsel *evsel, *n;
LIST_HEAD(move);
- if (move_evsel == perf_evlist__first(evlist))
+ if (move_evsel == evlist__first(evlist))
return;
evlist__for_each_entry_safe(evlist, n, evsel) {
@@ -1750,7 +1750,7 @@ bool perf_evlist__exclude_kernel(struct evlist *evlist)
void perf_evlist__force_leader(struct evlist *evlist)
{
if (!evlist->nr_groups) {
- struct evsel *leader = perf_evlist__first(evlist);
+ struct evsel *leader = evlist__first(evlist);
perf_evlist__set_leader(evlist);
leader->forced_leader = true;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 7306a0677171..88890e6a3ac7 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -9,6 +9,7 @@
#include <api/fd/array.h>
#include <stdio.h>
#include <internal/evlist.h>
+#include <internal/evsel.h>
#include "events_stats.h"
#include "evsel.h"
#include "mmap.h"
@@ -214,14 +215,18 @@ static inline bool perf_evlist__empty(struct evlist *evlist)
return list_empty(&evlist->core.entries);
}
-static inline struct evsel *perf_evlist__first(struct evlist *evlist)
+static inline struct evsel *evlist__first(struct evlist *evlist)
{
- return list_entry(evlist->core.entries.next, struct evsel, core.node);
+ struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
+
+ return container_of(evsel, struct evsel, core);
}
-static inline struct evsel *perf_evlist__last(struct evlist *evlist)
+static inline struct evsel *evlist__last(struct evlist *evlist)
{
- return list_entry(evlist->core.entries.prev, struct evsel, core.node);
+ struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
+
+ return container_of(evsel, struct evsel, core);
}
size_t perf_evlist__fprintf(struct evlist *evlist, FILE *fp);
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index b80f29bfc7bb..c5945068b9c6 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -779,7 +779,7 @@ jit_process(struct perf_session *session,
* track sample_type to compute id_all layout
* perf sets the same sample type to all events as of now
*/
- first = perf_evlist__first(session->evlist);
+ first = evlist__first(session->evlist);
jd.sample_type = first->core.attr.sample_type;
*nbytes = 0;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 403fb5e05108..e2db348639f6 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1936,7 +1936,7 @@ int parse_events(struct evlist *evlist, const char *str,
perf_evlist__splice_list_tail(evlist, &parse_state.list);
evlist->nr_groups += parse_state.nr_groups;
- last = perf_evlist__last(evlist);
+ last = evlist__last(evlist);
last->cmdline_group_boundary = true;
return 0;
@@ -2050,7 +2050,7 @@ foreach_evsel_in_last_glob(struct evlist *evlist,
* So no need to WARN here, let *func do this.
*/
if (evlist->core.nr_entries > 0)
- last = perf_evlist__last(evlist);
+ last = evlist__last(evlist);
do {
err = (*func)(last, arg);
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 286fe816c0f3..60b29e6e005b 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -32,7 +32,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str)
if (parse_events(evlist, str, NULL))
goto out_delete;
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
while (1) {
fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags);
@@ -173,7 +173,7 @@ void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
use_sample_identifier = perf_can_sample_identifier();
sample_id = true;
} else if (evlist->core.nr_entries > 1) {
- struct evsel *first = perf_evlist__first(evlist);
+ struct evsel *first = evlist__first(evlist);
evlist__for_each_entry(evlist, evsel) {
if (evsel->core.attr.sample_type == first->core.attr.sample_type)
@@ -278,7 +278,7 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str)
if (err)
goto out_delete;
- evsel = perf_evlist__last(temp_evlist);
+ evsel = evlist__last(temp_evlist);
if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) {
struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index a2308eb77681..43d1d410854a 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -2329,7 +2329,7 @@ static struct evsel *find_evsel(struct evlist *evlist, char *event_name)
if (nr > evlist->core.nr_entries)
return NULL;
- evsel = perf_evlist__first(evlist);
+ evsel = evlist__first(evlist);
while (--nr > 0)
evsel = perf_evsel__next(evsel);
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 51fb574998bb..e588194428e8 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -72,7 +72,7 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
}
if (top->evlist->core.nr_entries == 1) {
- struct evsel *first = perf_evlist__first(top->evlist);
+ struct evsel *first = evlist__first(top->evlist);
ret += SNPRINTF(bf + ret, size - ret, "%" PRIu64 "%s ",
(uint64_t)first->core.attr.sample_period,
opts->freq ? "Hz" : "");
--
2.21.0
Move perf_evlist__poll function under libperf,
it will be used in following patches. And rename
the existing perf's function to evlist__poll.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 2 +-
tools/perf/builtin-top.c | 4 ++--
tools/perf/builtin-trace.c | 2 +-
tools/perf/lib/evlist.c | 5 +++++
tools/perf/lib/include/perf/evlist.h | 1 +
tools/perf/lib/libperf.map | 1 +
tools/perf/tests/openat-syscall-tp-fields.c | 2 +-
tools/perf/tests/perf-record.c | 2 +-
tools/perf/tests/task-exit.c | 2 +-
tools/perf/util/evlist.c | 6 +++---
tools/perf/util/evlist.h | 2 +-
tools/perf/util/python.c | 2 +-
12 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index cb5d750cbbdf..7b12877de27c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1610,7 +1610,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (hits == rec->samples) {
if (done || draining)
break;
- err = perf_evlist__poll(rec->evlist, -1);
+ err = evlist__poll(rec->evlist, -1);
/*
* Propagate error, only if there's any. Ignore positive
* number of returned events and interrupt error.
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 0942e8d4c93b..fb62e10f4d4f 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1304,7 +1304,7 @@ static int __cmd_top(struct perf_top *top)
}
/* Wait for a minimal set of events before starting the snapshot */
- perf_evlist__poll(top->evlist, 100);
+ evlist__poll(top->evlist, 100);
perf_top__mmap_read(top);
@@ -1314,7 +1314,7 @@ static int __cmd_top(struct perf_top *top)
perf_top__mmap_read(top);
if (opts->overwrite || (hits == top->samples))
- ret = perf_evlist__poll(top->evlist, 100);
+ ret = evlist__poll(top->evlist, 100);
if (resize) {
perf_top__resize(top);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 685935b533f4..55daadb001f6 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3472,7 +3472,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (trace->nr_events == before) {
int timeout = done ? 100 : -1;
- if (!draining && perf_evlist__poll(evlist, timeout) > 0) {
+ if (!draining && evlist__poll(evlist, timeout) > 0) {
if (evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0)
draining = true;
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index a2c01dcec5ae..160393cb9bed 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -274,3 +274,8 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
return pos;
}
+
+int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
+{
+ return fdarray__poll(&evlist->pollfd, timeout);
+}
diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h
index 38365f8f3fba..8a2ce0757ab2 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -31,5 +31,6 @@ LIBPERF_API void perf_evlist__disable(struct perf_evlist *evlist);
LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist,
struct perf_cpu_map *cpus,
struct perf_thread_map *threads);
+LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
#endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 507b4cc4784c..2672f21b4908 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -38,6 +38,7 @@ LIBPERF_0.0.1 {
perf_evlist__remove;
perf_evlist__next;
perf_evlist__set_maps;
+ perf_evlist__poll;
local:
*;
};
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
index abf4d4f5e429..a5daf4cf17ac 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -126,7 +126,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
}
if (nr_events == before)
- perf_evlist__poll(evlist, 10);
+ evlist__poll(evlist, 10);
if (++nr_polls > 5) {
pr_debug("%s: no events!\n", __func__);
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 80da5b2c6bdc..1b313da8bce9 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -286,7 +286,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
* perf_event_attr.wakeup_events, just PERF_EVENT_SAMPLE does.
*/
if (total_events == before && false)
- perf_evlist__poll(evlist, -1);
+ evlist__poll(evlist, -1);
sleep(1);
if (++wakeups > 5) {
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 81c57a6b627f..e6e8a7a970b6 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -129,7 +129,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
out_init:
if (!exited || !nr_exit) {
- perf_evlist__poll(evlist, -1);
+ evlist__poll(evlist, -1);
goto retry;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 449425d9a033..dcc4accd3180 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -417,9 +417,9 @@ int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
perf_evlist__munmap_filtered, NULL);
}
-int perf_evlist__poll(struct evlist *evlist, int timeout)
+int evlist__poll(struct evlist *evlist, int timeout)
{
- return fdarray__poll(&evlist->core.pollfd, timeout);
+ return perf_evlist__poll(&evlist->core, timeout);
}
static void perf_evlist__set_sid_idx(struct evlist *evlist,
@@ -1735,7 +1735,7 @@ static void *perf_evlist__poll_thread(void *arg)
draining = true;
if (!draining)
- perf_evlist__poll(evlist, 1000);
+ evlist__poll(evlist, 1000);
for (i = 0; i < evlist->core.nr_mmaps; i++) {
struct mmap *map = &evlist->mmap[i];
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 6c5455cf5829..0042eac7e627 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -116,7 +116,7 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
int evlist__add_pollfd(struct evlist *evlist, int fd);
int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
-int perf_evlist__poll(struct evlist *evlist, int timeout);
+int evlist__poll(struct evlist *evlist, int timeout);
struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index fdc787cfa9f7..48fd93a6a247 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -918,7 +918,7 @@ static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &timeout))
return NULL;
- n = perf_evlist__poll(evlist, timeout);
+ n = evlist__poll(evlist, timeout);
if (n < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
--
2.21.0
Rename (perf_evlist__alloc_mmap) to evlist__alloc_mmap(), so we don't
have a name clash when we add (perf_evlist__alloc_mmap) in libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index cc11b1a22042..dc7117c33ab8 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -693,8 +693,8 @@ void evlist__munmap(struct evlist *evlist)
zfree(&evlist->overwrite_mmap);
}
-static struct mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
- bool overwrite)
+static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
+ bool overwrite)
{
int i;
struct mmap *map;
@@ -752,7 +752,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
maps = evlist->overwrite_mmap;
if (!maps) {
- maps = perf_evlist__alloc_mmap(evlist, true);
+ maps = evlist__alloc_mmap(evlist, true);
if (!maps)
return -1;
evlist->overwrite_mmap = maps;
@@ -1004,7 +1004,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
.comp_level = comp_level };
if (!evlist->mmap)
- evlist->mmap = perf_evlist__alloc_mmap(evlist, false);
+ evlist->mmap = evlist__alloc_mmap(evlist, false);
if (!evlist->mmap)
return -ENOMEM;
--
2.21.0
Move the system_wide member from perf's evsel to libperf's perf_evsel.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/arch/x86/util/intel-pt.c | 4 ++--
tools/perf/builtin-script.c | 2 +-
tools/perf/builtin-stat.c | 4 ++--
tools/perf/lib/include/internal/evsel.h | 1 +
tools/perf/tests/switch-tracking.c | 6 +++---
tools/perf/util/evlist.c | 10 +++++-----
tools/perf/util/evsel.c | 8 ++++----
tools/perf/util/evsel.h | 1 -
tools/perf/util/parse-events.c | 2 +-
tools/perf/util/stat.c | 2 +-
10 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index c0a7535cfd0e..1ae050c4045b 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -421,7 +421,7 @@ static int intel_pt_track_switches(struct evlist *evlist)
perf_evsel__set_sample_bit(evsel, CPU);
perf_evsel__set_sample_bit(evsel, TIME);
- evsel->system_wide = true;
+ evsel->core.system_wide = true;
evsel->no_aux_samples = true;
evsel->immediate = true;
@@ -722,7 +722,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
switch_evsel->core.attr.sample_period = 1;
switch_evsel->core.attr.context_switch = 1;
- switch_evsel->system_wide = true;
+ switch_evsel->core.system_wide = true;
switch_evsel->no_aux_samples = true;
switch_evsel->immediate = true;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index e079b34201f2..c602793d5483 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1915,7 +1915,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp)
int cpu, thread;
static int header_printed;
- if (counter->system_wide)
+ if (counter->core.system_wide)
nthreads = 1;
if (!header_printed) {
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7e17bf9f700a..35897048ba53 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -276,7 +276,7 @@ static int read_counter(struct evsel *counter, struct timespec *rs)
if (!counter->supported)
return -ENOENT;
- if (counter->system_wide)
+ if (counter->core.system_wide)
nthreads = 1;
for (thread = 0; thread < nthreads; thread++) {
@@ -1681,7 +1681,7 @@ static void setup_system_wide(int forks)
struct evsel *counter;
evlist__for_each_entry(evsel_list, counter) {
- if (!counter->system_wide)
+ if (!counter->core.system_wide)
return;
}
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index 8b854d1c9b45..220cb2e2b54e 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -18,6 +18,7 @@ struct perf_evsel {
/* parse modifier helper */
int nr_members;
+ bool system_wide;
};
int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index f6c2c026988a..01bfb087ce22 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -144,7 +144,7 @@ static int process_sample_event(struct evlist *evlist,
return err;
/*
* Check for no missing sched_switch events i.e. that the
- * evsel->system_wide flag has worked.
+ * evsel->core.system_wide flag has worked.
*/
if (switch_tracking->tids[cpu] != -1 &&
switch_tracking->tids[cpu] != prev_tid) {
@@ -316,7 +316,7 @@ static int process_events(struct evlist *evlist,
*
* This function implements a test that checks that sched_switch events and
* tracking events can be recorded for a workload (current process) using the
- * evsel->system_wide and evsel->tracking flags (respectively) with other events
+ * evsel->core.system_wide and evsel->tracking flags (respectively) with other events
* sometimes enabled or disabled.
*/
int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_unused)
@@ -396,7 +396,7 @@ int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_
perf_evsel__set_sample_bit(switch_evsel, CPU);
perf_evsel__set_sample_bit(switch_evsel, TIME);
- switch_evsel->system_wide = true;
+ switch_evsel->core.system_wide = true;
switch_evsel->no_aux_samples = true;
switch_evsel->immediate = true;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 98827df5a40a..0ffa1e9b6243 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -318,7 +318,7 @@ int perf_evlist__add_newtp(struct evlist *evlist,
static int perf_evlist__nr_threads(struct evlist *evlist,
struct evsel *evsel)
{
- if (evsel->system_wide)
+ if (evsel->core.system_wide)
return 1;
else
return perf_thread_map__nr(evlist->core.threads);
@@ -409,7 +409,7 @@ int perf_evlist__alloc_pollfd(struct evlist *evlist)
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel) {
- if (evsel->system_wide)
+ if (evsel->core.system_wide)
nfds += nr_cpus;
else
nfds += nr_cpus * nr_threads;
@@ -535,7 +535,7 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist,
sid->cpu = evlist->core.cpus->map[cpu];
else
sid->cpu = -1;
- if (!evsel->system_wide && evlist->core.threads && thread >= 0)
+ if (!evsel->core.system_wide && evlist->core.threads && thread >= 0)
sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
else
sid->tid = -1;
@@ -762,7 +762,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
mp->prot &= ~PROT_WRITE;
}
- if (evsel->system_wide && thread)
+ if (evsel->core.system_wide && thread)
continue;
cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
@@ -792,7 +792,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
* other events, so it should not need to be polled anyway.
* Therefore don't add it for polling.
*/
- if (!evsel->system_wide &&
+ if (!evsel->core.system_wide &&
__perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) {
perf_mmap__put(&maps[idx]);
return -1;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 85825384f9e8..9dcee5a8875e 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1231,7 +1231,7 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
if (ncpus == 0 || nthreads == 0)
return 0;
- if (evsel->system_wide)
+ if (evsel->core.system_wide)
nthreads = 1;
evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
@@ -1662,7 +1662,7 @@ static bool ignore_missing_thread(struct evsel *evsel,
return false;
/* The system wide setup does not work with threads. */
- if (evsel->system_wide)
+ if (evsel->core.system_wide)
return false;
/* The -ESRCH is perf event syscall errno for pid's not found. */
@@ -1771,7 +1771,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
threads = empty_thread_map;
}
- if (evsel->system_wide)
+ if (evsel->core.system_wide)
nthreads = 1;
else
nthreads = threads->nr;
@@ -1818,7 +1818,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
for (thread = 0; thread < nthreads; thread++) {
int fd, group_fd;
- if (!evsel->cgrp && !evsel->system_wide)
+ if (!evsel->cgrp && !evsel->core.system_wide)
pid = perf_thread_map__pid(threads, thread);
group_fd = get_group_fd(evsel, cpu, thread);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 68321d10eb2d..eb4d03cd0b17 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -146,7 +146,6 @@ struct evsel {
bool disabled;
bool no_aux_samples;
bool immediate;
- bool system_wide;
bool tracking;
bool per_pkg;
bool precise_max;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5ec21d21113c..403fb5e05108 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -335,7 +335,7 @@ __add_event(struct list_head *list, int *idx,
(*idx)++;
evsel->core.cpus = perf_cpu_map__get(cpus);
evsel->core.own_cpus = perf_cpu_map__get(cpus);
- evsel->system_wide = pmu ? pmu->is_uncore : false;
+ evsel->core.system_wide = pmu ? pmu->is_uncore : false;
evsel->auto_merge_stats = auto_merge_stats;
if (name)
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 8f1ea27f976f..ef02d8b709ff 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -318,7 +318,7 @@ static int process_counter_maps(struct perf_stat_config *config,
int ncpus = perf_evsel__nr_cpus(counter);
int cpu, thread;
- if (counter->system_wide)
+ if (counter->core.system_wide)
nthreads = 1;
for (thread = 0; thread < nthreads; thread++) {
--
2.21.0
Moving pollfd from struct evlist to struct perf_evlist
it will be used in following patches.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-kvm.c | 2 +-
tools/perf/lib/include/internal/evlist.h | 2 ++
tools/perf/util/evlist.c | 18 +++++++++---------
tools/perf/util/evlist.h | 1 -
tools/perf/util/python.c | 6 +++---
5 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 2b8e71d0a722..66acac16bcb2 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -978,7 +978,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
evlist__enable(kvm->evlist);
while (!done) {
- struct fdarray *fda = &kvm->evlist->pollfd;
+ struct fdarray *fda = &kvm->evlist->core.pollfd;
int rc;
rc = perf_kvm__mmap_read(kvm);
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 01b813616440..8a4eb66fbf3a 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -3,6 +3,7 @@
#define __LIBPERF_INTERNAL_EVLIST_H
#include <linux/list.h>
+#include <api/fd/array.h>
struct perf_cpu_map;
struct perf_thread_map;
@@ -15,6 +16,7 @@ struct perf_evlist {
struct perf_thread_map *threads;
int nr_mmaps;
size_t mmap_len;
+ struct fdarray pollfd;
};
/**
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 07f02afa3407..8f5b28eefde7 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -60,7 +60,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
INIT_HLIST_HEAD(&evlist->heads[i]);
perf_evlist__init(&evlist->core);
perf_evlist__set_maps(&evlist->core, cpus, threads);
- fdarray__init(&evlist->pollfd, 64);
+ fdarray__init(&evlist->core.pollfd, 64);
evlist->workload.pid = -1;
evlist->bkw_mmap_state = BKW_MMAP_NOTREADY;
}
@@ -141,7 +141,7 @@ void evlist__exit(struct evlist *evlist)
{
zfree(&evlist->mmap);
zfree(&evlist->overwrite_mmap);
- fdarray__exit(&evlist->pollfd);
+ fdarray__exit(&evlist->core.pollfd);
}
void evlist__delete(struct evlist *evlist)
@@ -415,8 +415,8 @@ int perf_evlist__alloc_pollfd(struct evlist *evlist)
nfds += nr_cpus * nr_threads;
}
- if (fdarray__available_entries(&evlist->pollfd) < nfds &&
- fdarray__grow(&evlist->pollfd, nfds) < 0)
+ if (fdarray__available_entries(&evlist->core.pollfd) < nfds &&
+ fdarray__grow(&evlist->core.pollfd, nfds) < 0)
return -ENOMEM;
return 0;
@@ -425,13 +425,13 @@ int perf_evlist__alloc_pollfd(struct evlist *evlist)
static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
struct mmap *map, short revent)
{
- int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
+ int pos = fdarray__add(&evlist->core.pollfd, fd, revent | POLLERR | POLLHUP);
/*
* Save the idx so that when we filter out fds POLLHUP'ed we can
* close the associated evlist->mmap[] entry.
*/
if (pos >= 0) {
- evlist->pollfd.priv[pos].ptr = map;
+ evlist->core.pollfd.priv[pos].ptr = map;
fcntl(fd, F_SETFL, O_NONBLOCK);
}
@@ -455,13 +455,13 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
{
- return fdarray__filter(&evlist->pollfd, revents_and_mask,
+ return fdarray__filter(&evlist->core.pollfd, revents_and_mask,
perf_evlist__munmap_filtered, NULL);
}
int perf_evlist__poll(struct evlist *evlist, int timeout)
{
- return fdarray__poll(&evlist->pollfd, timeout);
+ return fdarray__poll(&evlist->core.pollfd, timeout);
}
static void perf_evlist__id_hash(struct evlist *evlist,
@@ -1008,7 +1008,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
if (!evlist->mmap)
return -ENOMEM;
- if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
+ if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
return -ENOMEM;
evlist->core.mmap_len = evlist__mmap_size(pages);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 3767866e98c1..b8f03452196f 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -36,7 +36,6 @@ struct evlist {
int cork_fd;
pid_t pid;
} workload;
- struct fdarray pollfd;
struct mmap *mmap;
struct mmap *overwrite_mmap;
struct evsel *selected;
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index b71b899407df..fdc787cfa9f7 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -935,17 +935,17 @@ static PyObject *pyrf_evlist__get_pollfd(struct pyrf_evlist *pevlist,
PyObject *list = PyList_New(0);
int i;
- for (i = 0; i < evlist->pollfd.nr; ++i) {
+ for (i = 0; i < evlist->core.pollfd.nr; ++i) {
PyObject *file;
#if PY_MAJOR_VERSION < 3
- FILE *fp = fdopen(evlist->pollfd.entries[i].fd, "r");
+ FILE *fp = fdopen(evlist->core.pollfd.entries[i].fd, "r");
if (fp == NULL)
goto free_list;
file = PyFile_FromFile(fp, "perf", "r", NULL);
#else
- file = PyFile_FromFd(evlist->pollfd.entries[i].fd, "perf", "r", -1,
+ file = PyFile_FromFd(evlist->core.pollfd.entries[i].fd, "perf", "r", -1,
NULL, NULL, NULL, 0);
#endif
if (file == NULL)
--
2.21.0
Move perf_mmap__put function under libperf.
Once perf_mmap__put is moved, we need a way to call
application related unmap code (AIO and aux related
code for eprf), when the map goes away.
Adding perf_mmap::unmap callback to do that.
The unmap path from perf is:
perf_mmap__put (libperf)
perf_mmap__munmap (libperf)
map->unmap_cb -> perf_mmap__unmap_cb (perf)
mmap__munmap (perf)
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 4 ++--
tools/perf/lib/include/internal/mmap.h | 31 ++++++++++++++++----------
tools/perf/lib/mmap.c | 14 +++++++++++-
tools/perf/util/evlist.c | 17 +++++++++-----
tools/perf/util/mmap.c | 11 +--------
tools/perf/util/mmap.h | 2 --
6 files changed, 47 insertions(+), 32 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 82f6bd6b1adc..df0f2eceb359 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -194,7 +194,7 @@ static int record__aio_complete(struct mmap *md, struct aiocb *cblock)
* every aio write request started in record__aio_push() so
* decrement it because the request is now complete.
*/
- perf_mmap__put(md);
+ perf_mmap__put(&md->core);
rc = 1;
} else {
/*
@@ -329,7 +329,7 @@ static int record__aio_push(struct record *rec, struct mmap *map, off_t *off)
* map->refcount is decremented in record__aio_complete() after
* aio write operation finishes successfully.
*/
- perf_mmap__put(map);
+ perf_mmap__put(&map->core);
}
return ret;
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 5c9ba00e67e1..cc0a5995cd3c 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -10,23 +10,28 @@
/* perf sample has 16 bits size limit */
#define PERF_SAMPLE_MAX_SIZE (1 << 16)
+struct perf_mmap;
+
+typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
+
/**
* struct perf_mmap - perf's ring buffer mmap details
*
* @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
*/
struct perf_mmap {
- void *base;
- int mask;
- int fd;
- int cpu;
- refcount_t refcnt;
- u64 prev;
- u64 start;
- u64 end;
- bool overwrite;
- u64 flush;
- char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
+ void *base;
+ int mask;
+ int fd;
+ int cpu;
+ refcount_t refcnt;
+ u64 prev;
+ u64 start;
+ u64 end;
+ bool overwrite;
+ u64 flush;
+ libperf_unmap_cb_t unmap_cb;
+ char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
};
struct perf_mmap_param {
@@ -36,10 +41,12 @@ struct perf_mmap_param {
size_t perf_mmap__mmap_len(struct perf_mmap *map);
-void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+void perf_mmap__init(struct perf_mmap *map, bool overwrite,
+ libperf_unmap_cb_t unmap_cb);
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu);
void perf_mmap__munmap(struct perf_mmap *map);
void perf_mmap__get(struct perf_mmap *map);
+void perf_mmap__put(struct perf_mmap *map);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 6eb228d89206..ea46f325fa98 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -3,10 +3,12 @@
#include <internal/mmap.h>
#include <internal/lib.h>
-void perf_mmap__init(struct perf_mmap *map, bool overwrite)
+void perf_mmap__init(struct perf_mmap *map, bool overwrite,
+ libperf_unmap_cb_t unmap_cb)
{
map->fd = -1;
map->overwrite = overwrite;
+ map->unmap_cb = unmap_cb;
refcount_set(&map->refcnt, 0);
}
@@ -40,9 +42,19 @@ void perf_mmap__munmap(struct perf_mmap *map)
map->fd = -1;
refcount_set(&map->refcnt, 0);
}
+ if (map && map->unmap_cb)
+ map->unmap_cb(map);
}
void perf_mmap__get(struct perf_mmap *map)
{
refcount_inc(&map->refcnt);
}
+
+void perf_mmap__put(struct perf_mmap *map)
+{
+ BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
+
+ if (refcount_dec_and_test(&map->refcnt))
+ perf_mmap__munmap(map);
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 22165862f587..f1af59df1167 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -408,7 +408,7 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
struct mmap *map = fda->priv[fd].ptr;
if (map)
- perf_mmap__put(map);
+ perf_mmap__put(&map->core);
}
int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
@@ -576,11 +576,11 @@ static void evlist__munmap_nofree(struct evlist *evlist)
if (evlist->mmap)
for (i = 0; i < evlist->core.nr_mmaps; i++)
- mmap__munmap(&evlist->mmap[i]);
+ perf_mmap__munmap(&evlist->mmap[i].core);
if (evlist->overwrite_mmap)
for (i = 0; i < evlist->core.nr_mmaps; i++)
- mmap__munmap(&evlist->overwrite_mmap[i]);
+ perf_mmap__munmap(&evlist->overwrite_mmap[i].core);
}
void evlist__munmap(struct evlist *evlist)
@@ -590,6 +590,13 @@ void evlist__munmap(struct evlist *evlist)
zfree(&evlist->overwrite_mmap);
}
+static void perf_mmap__unmap_cb(struct perf_mmap *map)
+{
+ struct mmap *m = container_of(map, struct mmap, core);
+
+ mmap__munmap(m);
+}
+
static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
bool overwrite)
{
@@ -613,7 +620,7 @@ static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
* Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
* thus does perf_mmap__get() on it.
*/
- perf_mmap__init(&map[i].core, overwrite);
+ perf_mmap__init(&map[i].core, overwrite, perf_mmap__unmap_cb);
}
return map;
@@ -690,7 +697,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
*/
if (!evsel->core.system_wide &&
perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) {
- perf_mmap__put(&maps[idx]);
+ perf_mmap__put(&maps[idx].core);
return -1;
}
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index eb77141dbfca..b904a7a57fdf 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -109,14 +109,6 @@ static bool perf_mmap__empty(struct mmap *map)
return perf_mmap__read_head(map) == map->core.prev && !map->auxtrace_mmap.base;
}
-void perf_mmap__put(struct mmap *map)
-{
- BUG_ON(map->core.base && refcount_read(&map->core.refcnt) == 0);
-
- if (refcount_dec_and_test(&map->core.refcnt))
- mmap__munmap(map);
-}
-
void perf_mmap__consume(struct mmap *map)
{
if (!map->core.overwrite) {
@@ -126,7 +118,7 @@ void perf_mmap__consume(struct mmap *map)
}
if (refcount_read(&map->core.refcnt) == 1 && perf_mmap__empty(map))
- perf_mmap__put(map);
+ perf_mmap__put(&map->core);
}
int __weak auxtrace_mmap__mmap(struct auxtrace_mmap *mm __maybe_unused,
@@ -307,7 +299,6 @@ static void perf_mmap__aio_munmap(struct mmap *map __maybe_unused)
void mmap__munmap(struct mmap *map)
{
- perf_mmap__munmap(&map->core);
perf_mmap__aio_munmap(map);
if (map->data != NULL) {
munmap(map->data, mmap__mmap_len(map));
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 852f1ec20787..8a8f99cc7ecd 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -73,8 +73,6 @@ struct mmap_params {
int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
void mmap__munmap(struct mmap *map);
-void perf_mmap__put(struct mmap *map);
-
void perf_mmap__consume(struct mmap *map);
static inline u64 perf_mmap__read_head(struct mmap *mm)
--
2.21.0
We will move this code into libperf shortly, so we
need to free it of 'struct auxtrace_mmap' usage,
because it won't be available in libperf (for now).
The perf_event_mmap_page::aux_size is set when the
aux mmap is mapped, so the check is equivalent.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/mmap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index b904a7a57fdf..4b1d1ae79042 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -106,7 +106,9 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
static bool perf_mmap__empty(struct mmap *map)
{
- return perf_mmap__read_head(map) == map->core.prev && !map->auxtrace_mmap.base;
+ struct perf_event_mmap_page *pc = map->core.base;
+
+ return perf_mmap__read_head(map) == map->core.prev && !pc->aux_size;
}
void perf_mmap__consume(struct mmap *map)
--
2.21.0
Adding perf_evlist__filter_pollfd function and exporting
it in perf/evlist.h header, so libperf users can check if
descriptor is still alive.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 15 +++++++++++++++
tools/perf/lib/include/perf/evlist.h | 2 ++
tools/perf/lib/libperf.map | 1 +
tools/perf/util/evlist.c | 12 +-----------
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 8920833afa9e..ee1d364460e6 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -313,6 +313,21 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
return pos;
}
+static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
+ void *arg __maybe_unused)
+{
+ struct perf_mmap *map = fda->priv[fd].ptr;
+
+ if (map)
+ perf_mmap__put(map);
+}
+
+int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask)
+{
+ return fdarray__filter(&evlist->pollfd, revents_and_mask,
+ perf_evlist__munmap_filtered, NULL);
+}
+
int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
{
return fdarray__poll(&evlist->pollfd, timeout);
diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h
index 28b6a12a8a2b..16f526e74d13 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -32,6 +32,8 @@ LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist,
struct perf_cpu_map *cpus,
struct perf_thread_map *threads);
LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
+LIBPERF_API int perf_evlist__filter_pollfd(struct perf_evlist *evlist,
+ short revents_and_mask);
LIBPERF_API int perf_evlist__mmap(struct perf_evlist *evlist, int pages);
LIBPERF_API void perf_evlist__munmap(struct perf_evlist *evlist);
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 198dcf305356..90aee2a635b2 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -41,6 +41,7 @@ LIBPERF_0.0.1 {
perf_evlist__poll;
perf_evlist__mmap;
perf_evlist__munmap;
+ perf_evlist__filter_pollfd;
perf_mmap__consume;
perf_mmap__read_init;
perf_mmap__read_done;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0c69621e2b2e..9edb0855f711 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -398,19 +398,9 @@ int evlist__add_pollfd(struct evlist *evlist, int fd)
return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN);
}
-static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
- void *arg __maybe_unused)
-{
- struct perf_mmap *map = fda->priv[fd].ptr;
-
- if (map)
- perf_mmap__put(map);
-}
-
int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
{
- return fdarray__filter(&evlist->core.pollfd, revents_and_mask,
- perf_evlist__munmap_filtered, NULL);
+ return perf_evlist__filter_pollfd(&evlist->core, revents_and_mask);
}
int evlist__poll(struct evlist *evlist, int timeout)
--
2.21.0
Adding libperf's version of mmap params 'struct perf_mmap_param'
object with the basics: prot and mask. It's encapsulated in current
struct mmap_params object.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 5 +++++
tools/perf/util/evlist.c | 14 +++++++++-----
tools/perf/util/mmap.c | 4 ++--
tools/perf/util/mmap.h | 3 ++-
4 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index e95fc51e5bd0..8e06eb840c47 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -29,6 +29,11 @@ struct perf_mmap {
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
};
+struct perf_mmap_param {
+ int prot;
+ int mask;
+};
+
void perf_mmap__init(struct perf_mmap *map, bool overwrite);
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 0d1ae00d22f3..c0c0882dc343 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -642,7 +642,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
int fd;
int cpu;
- mp->prot = PROT_READ | PROT_WRITE;
+ mp->core.prot = PROT_READ | PROT_WRITE;
if (evsel->core.attr.write_backward) {
output = _output_overwrite;
maps = evlist->overwrite_mmap;
@@ -655,7 +655,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
}
- mp->prot &= ~PROT_WRITE;
+ mp->core.prot &= ~PROT_WRITE;
}
if (evsel->core.system_wide && thread)
@@ -896,8 +896,12 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
* Its value is decided by evsel's write_backward.
* So &mp should not be passed through const pointer.
*/
- struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = affinity, .flush = flush,
- .comp_level = comp_level };
+ struct mmap_params mp = {
+ .nr_cblocks = nr_cblocks,
+ .affinity = affinity,
+ .flush = flush,
+ .comp_level = comp_level
+ };
if (!evlist->mmap)
evlist->mmap = evlist__alloc_mmap(evlist, false);
@@ -909,7 +913,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
evlist->core.mmap_len = evlist__mmap_size(pages);
pr_debug("mmap size %zuB\n", evlist->core.mmap_len);
- mp.mask = evlist->core.mmap_len - page_size - 1;
+ mp.core.mask = evlist->core.mmap_len - page_size - 1;
auxtrace_mmap_params__init(&mp.auxtrace_mp, evlist->core.mmap_len,
auxtrace_pages, auxtrace_overwrite);
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 4cc3b54b2f73..2f34a93a72f4 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -369,8 +369,8 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
*/
refcount_set(&map->core.refcnt, 2);
map->core.prev = 0;
- map->core.mask = mp->mask;
- map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
+ map->core.mask = mp->core.mask;
+ map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->core.prot,
MAP_SHARED, fd, 0);
if (map->core.base == MAP_FAILED) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index e335c341d073..965acb46df81 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -65,7 +65,8 @@ enum bkw_mmap_state {
};
struct mmap_params {
- int prot, mask, nr_cblocks, affinity, flush, comp_level;
+ struct perf_mmap_param core;
+ int nr_cblocks, affinity, flush, comp_level;
struct auxtrace_mmap_params auxtrace_mp;
};
--
2.21.0
Adding perf_evlist__mmap_cb_new function to return 'struct perf_mmap'
object during perf_evlist__mmap_ops call.
The array of 'struct mmap' is allocated via evlist__alloc_mmap,
in this callback we simply returns pointer to the base object.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 850dacf7bf97..52a6af91e877 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -725,6 +725,29 @@ perf_evlist__mmap_cb_idx(struct perf_evlist *_evlist,
auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, idx, per_cpu);
}
+static struct perf_mmap*
+perf_evlist__mmap_cb_new(struct perf_evlist *_evlist, bool overwrite, int idx)
+{
+ struct evlist *evlist = container_of(_evlist, struct evlist, core);
+ struct mmap *maps = evlist->mmap;
+
+ if (overwrite) {
+ maps = evlist->overwrite_mmap;
+
+ if (!maps) {
+ maps = evlist__alloc_mmap(evlist, true);
+ if (!maps)
+ return NULL;
+
+ evlist->overwrite_mmap = maps;
+ if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
+ perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_RUNNING);
+ }
+ }
+
+ return &maps[idx].core;
+}
+
static int evlist__mmap_per_cpu(struct evlist *evlist,
struct mmap_params *mp)
{
@@ -923,6 +946,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
};
struct perf_evlist_mmap_ops ops __maybe_unused = {
.idx = perf_evlist__mmap_cb_idx,
+ .new = perf_evlist__mmap_cb_new,
};
if (!evlist->mmap)
--
2.21.0
Adding mmaping tests that generates 100 prctl calls
in monitored child process and validates it gets
100 events in ring buffer.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/tests/test-evlist.c | 119 +++++++++++++++++++++++++++++
1 file changed, 119 insertions(+)
diff --git a/tools/perf/lib/tests/test-evlist.c b/tools/perf/lib/tests/test-evlist.c
index e6b2ab2e2bde..aa90e8d40738 100644
--- a/tools/perf/lib/tests/test-evlist.c
+++ b/tools/perf/lib/tests/test-evlist.c
@@ -1,12 +1,21 @@
// SPDX-License-Identifier: GPL-2.0
#include <stdio.h>
#include <stdarg.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <linux/perf_event.h>
+#include <linux/limits.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/prctl.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
#include <perf/evlist.h>
#include <perf/evsel.h>
+#include <perf/mmap.h>
+#include <perf/event.h>
#include <internal/tests.h>
+#include <api/fs/fs.h>
static int libperf_print(enum libperf_print_level level,
const char *fmt, va_list ap)
@@ -181,6 +190,115 @@ static int test_stat_thread_enable(void)
return 0;
}
+static int test_mmap_thread(void)
+{
+ struct perf_evlist *evlist;
+ struct perf_evsel *evsel;
+ struct perf_mmap *map;
+ struct perf_cpu_map *cpus;
+ struct perf_thread_map *threads;
+ struct perf_event_attr attr = {
+ .type = PERF_TYPE_TRACEPOINT,
+ .sample_period = 1,
+ .wakeup_watermark = 1,
+ .disabled = 1,
+ };
+ char path[PATH_MAX];
+ int id, err, pid, go_pipe[2];
+ union perf_event *event;
+ char bf;
+ int count = 0;
+
+ snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
+ sysfs__mountpoint());
+
+ if (filename__read_int(path, &id)) {
+ fprintf(stderr, "error: failed to get tracepoint id: %s\n", path);
+ return -1;
+ }
+
+ attr.config = id;
+
+ err = pipe(go_pipe);
+ __T("failed to create pipe", err == 0);
+
+ fflush(NULL);
+
+ pid = fork();
+ if (!pid) {
+ int i;
+
+ read(go_pipe[0], &bf, 1);
+
+ /* Generate 100 prctl calls. */
+ for (i = 0; i < 100; i++)
+ prctl(0, 0, 0, 0, 0);
+
+ exit(0);
+ }
+
+ threads = perf_thread_map__new_dummy();
+ __T("failed to create threads", threads);
+
+ cpus = perf_cpu_map__dummy_new();
+ __T("failed to create cpus", cpus);
+
+ perf_thread_map__set_pid(threads, 0, pid);
+
+ evlist = perf_evlist__new();
+ __T("failed to create evlist", evlist);
+
+ evsel = perf_evsel__new(&attr);
+ __T("failed to create evsel1", evsel);
+
+ perf_evlist__add(evlist, evsel);
+
+ perf_evlist__set_maps(evlist, cpus, threads);
+
+ err = perf_evlist__open(evlist);
+ __T("failed to open evlist", err == 0);
+
+ err = perf_evlist__mmap(evlist, 4);
+ __T("failed to mmap evlist", err == 0);
+
+ perf_evlist__enable(evlist);
+
+ /* kick the child and wait for it to finish */
+ write(go_pipe[1], &bf, 1);
+ waitpid(pid, NULL, 0);
+
+ /*
+ * There's no need to call perf_evlist__disable,
+ * monitored process is dead now.
+ */
+
+ perf_evlist__for_each_mmap(evlist, map) {
+ if (perf_mmap__read_init(map) < 0)
+ continue;
+
+ while ((event = perf_mmap__read_event(map)) != NULL) {
+ count++;
+ perf_mmap__consume(map);
+ }
+
+ perf_mmap__read_done(map);
+ }
+
+ /* calls perf_evlist__munmap/perf_evlist__close */
+ perf_evlist__delete(evlist);
+
+ perf_thread_map__put(threads);
+ perf_cpu_map__put(cpus);
+
+ /*
+ * The generated prctl calls should match the
+ * number of events in the buffer.
+ */
+ __T("failed count", count == 100);
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
__T_START;
@@ -190,6 +308,7 @@ int main(int argc, char **argv)
test_stat_cpu();
test_stat_thread();
test_stat_thread_enable();
+ test_mmap_thread();
__T_OK;
return 0;
--
2.21.0
Adding perf_evsel__alloc_id/perf_evsel__free_id functions
to libperf as internal functions.
Moving 'struct perf_sample_id' to internal/evsel.h header
and changing struct perf_sample_id::evsel to 'struct perf_evsel'
and the related code that touches it.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evsel.c | 30 +++++++++++++++++++++
tools/perf/lib/include/internal/evsel.h | 27 +++++++++++++++++++
tools/perf/tests/event_update.c | 2 +-
tools/perf/util/evlist.c | 10 +++----
tools/perf/util/evsel.c | 36 +++----------------------
tools/perf/util/evsel.h | 25 -----------------
tools/perf/util/header.c | 4 +--
tools/perf/util/session.c | 4 ++-
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)
{
return &evsel->attr;
}
+
+int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
+{
+ if (ncpus == 0 || nthreads == 0)
+ return 0;
+
+ if (evsel->system_wide)
+ nthreads = 1;
+
+ evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
+ if (evsel->sample_id == NULL)
+ return -ENOMEM;
+
+ evsel->id = zalloc(ncpus * nthreads * sizeof(u64));
+ if (evsel->id == NULL) {
+ xyarray__delete(evsel->sample_id);
+ evsel->sample_id = NULL;
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+void perf_evsel__free_id(struct perf_evsel *evsel)
+{
+ xyarray__delete(evsel->sample_id);
+ evsel->sample_id = NULL;
+ zfree(&evsel->id);
+ evsel->ids = 0;
+}
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index 0b04065cae8e..0ff4811a7f32 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -4,10 +4,34 @@
#include <linux/types.h>
#include <linux/perf_event.h>
+#include <sys/types.h>
struct perf_cpu_map;
struct perf_thread_map;
+/*
+ * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
+ * more than one entry in the evlist.
+ */
+struct perf_sample_id {
+ struct hlist_node node;
+ u64 id;
+ struct perf_evsel *evsel;
+ /*
+ * 'idx' will be used for AUX area sampling. A sample will have AUX area
+ * data that will be queued for decoding, where there are separate
+ * queues for each CPU (per-cpu tracing) or task (per-thread tracing).
+ * The sample ID can be used to lookup 'idx' which is effectively the
+ * queue number.
+ */
+ int idx;
+ int cpu;
+ pid_t tid;
+
+ /* Holds total ID period value for PERF_SAMPLE_READ processing. */
+ u64 period;
+};
+
struct perf_evsel {
struct list_head node;
struct perf_event_attr attr;
@@ -30,4 +54,7 @@ void perf_evsel__free_fd(struct perf_evsel *evsel);
int perf_evsel__read_size(struct perf_evsel *evsel);
int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
+int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
+void perf_evsel__free_id(struct perf_evsel *evsel);
+
#endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c
index cac4290e233a..dce929c83062 100644
--- a/tools/perf/tests/event_update.c
+++ b/tools/perf/tests/event_update.c
@@ -93,7 +93,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unu
evsel = perf_evlist__first(evlist);
TEST_ASSERT_VAL("failed to allos ids",
- !perf_evsel__alloc_id(evsel, 1, 1));
+ !perf_evsel__alloc_id(&evsel->core, 1, 1));
perf_evlist__id_add(evlist, evsel, 0, 0, 123);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 2f883db7c8e7..472cbb47272a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -468,7 +468,7 @@ static void perf_evlist__id_hash(struct evlist *evlist,
struct perf_sample_id *sid = SID(evsel, cpu, thread);
sid->id = id;
- sid->evsel = evsel;
+ sid->evsel = &evsel->core;
hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
hlist_add_head(&sid->node, &evlist->core.heads[hash]);
}
@@ -562,7 +562,7 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
sid = perf_evlist__id2sid(evlist, id);
if (sid)
- return sid->evsel;
+ return container_of(sid->evsel, struct evsel, core);
if (!perf_evlist__sample_id_all(evlist))
return perf_evlist__first(evlist);
@@ -580,7 +580,7 @@ struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
sid = perf_evlist__id2sid(evlist, id);
if (sid)
- return sid->evsel;
+ return container_of(sid->evsel, struct evsel, core);
return NULL;
}
@@ -634,7 +634,7 @@ struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
hlist_for_each_entry(sid, head, node) {
if (sid->id == id)
- return sid->evsel;
+ return container_of(sid->evsel, struct evsel, core);
}
return NULL;
}
@@ -1017,7 +1017,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
evlist__for_each_entry(evlist, evsel) {
if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
evsel->core.sample_id == NULL &&
- perf_evsel__alloc_id(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
+ perf_evsel__alloc_id(&evsel->core, perf_cpu_map__nr(cpus), threads->nr) < 0)
return -ENOMEM;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 7501b4403b7f..904b67d23bde 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1226,36 +1226,6 @@ int evsel__disable(struct evsel *evsel)
return err;
}
-int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
-{
- if (ncpus == 0 || nthreads == 0)
- return 0;
-
- if (evsel->core.system_wide)
- nthreads = 1;
-
- evsel->core.sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
- if (evsel->core.sample_id == NULL)
- return -ENOMEM;
-
- evsel->core.id = zalloc(ncpus * nthreads * sizeof(u64));
- if (evsel->core.id == NULL) {
- xyarray__delete(evsel->core.sample_id);
- evsel->core.sample_id = NULL;
- return -ENOMEM;
- }
-
- return 0;
-}
-
-static void perf_evsel__free_id(struct evsel *evsel)
-{
- xyarray__delete(evsel->core.sample_id);
- evsel->core.sample_id = NULL;
- zfree(&evsel->core.id);
- evsel->core.ids = 0;
-}
-
static void perf_evsel__free_config_terms(struct evsel *evsel)
{
struct perf_evsel_config_term *term, *h;
@@ -1272,7 +1242,7 @@ void perf_evsel__exit(struct evsel *evsel)
assert(evsel->evlist == NULL);
perf_evsel__free_counts(evsel);
perf_evsel__free_fd(&evsel->core);
- perf_evsel__free_id(evsel);
+ perf_evsel__free_id(&evsel->core);
perf_evsel__free_config_terms(evsel);
cgroup__put(evsel->cgrp);
perf_cpu_map__put(evsel->core.cpus);
@@ -1991,7 +1961,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
void evsel__close(struct evsel *evsel)
{
perf_evsel__close(&evsel->core);
- perf_evsel__free_id(evsel);
+ perf_evsel__free_id(&evsel->core);
}
int perf_evsel__open_per_cpu(struct evsel *evsel,
@@ -2980,7 +2950,7 @@ int perf_evsel__store_ids(struct evsel *evsel, struct evlist *evlist)
struct perf_cpu_map *cpus = evsel->core.cpus;
struct perf_thread_map *threads = evsel->core.threads;
- if (perf_evsel__alloc_id(evsel, cpus->nr, threads->nr))
+ if (perf_evsel__alloc_id(&evsel->core, cpus->nr, threads->nr))
return -ENOMEM;
return store_evsel_ids(evsel, evlist);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 765f722fc128..57ba20f361cd 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -17,29 +17,6 @@ struct addr_location;
struct evsel;
union perf_event;
-/*
- * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
- * more than one entry in the evlist.
- */
-struct perf_sample_id {
- struct hlist_node node;
- u64 id;
- struct evsel *evsel;
- /*
- * 'idx' will be used for AUX area sampling. A sample will have AUX area
- * data that will be queued for decoding, where there are separate
- * queues for each CPU (per-cpu tracing) or task (per-thread tracing).
- * The sample ID can be used to lookup 'idx' which is effectively the
- * queue number.
- */
- int idx;
- int cpu;
- pid_t tid;
-
- /* Holds total ID period value for PERF_SAMPLE_READ processing. */
- u64 period;
-};
-
struct cgroup;
/*
@@ -278,8 +255,6 @@ const char *perf_evsel__name(struct evsel *evsel);
const char *perf_evsel__group_name(struct evsel *evsel);
int perf_evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
-int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads);
-
void __perf_evsel__set_sample_bit(struct evsel *evsel,
enum perf_event_sample_format bit);
void __perf_evsel__reset_sample_bit(struct evsel *evsel,
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 360fc61c5754..65b6e387e3ae 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3624,7 +3624,7 @@ int perf_session__read_header(struct perf_session *session)
* for allocating the perf_sample_id table we fake 1 cpu and
* hattr->ids threads.
*/
- if (perf_evsel__alloc_id(evsel, 1, nr_ids))
+ if (perf_evsel__alloc_id(&evsel->core, 1, nr_ids))
goto out_delete_evlist;
lseek(fd, f_attr.ids.offset, SEEK_SET);
@@ -4058,7 +4058,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused,
* for allocating the perf_sample_id table we fake 1 cpu and
* hattr->ids threads.
*/
- if (perf_evsel__alloc_id(evsel, 1, n_ids))
+ if (perf_evsel__alloc_id(&evsel->core, 1, n_ids))
return -ENOMEM;
for (i = 0; i < n_ids; i++) {
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 32226e71949e..88ed10e2be1c 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1317,6 +1317,7 @@ static int deliver_sample_value(struct evlist *evlist,
struct machine *machine)
{
struct perf_sample_id *sid = perf_evlist__id2sid(evlist, v->id);
+ struct evsel *evsel;
if (sid) {
sample->id = v->id;
@@ -1336,7 +1337,8 @@ static int deliver_sample_value(struct evlist *evlist,
if (!sample->period)
return 0;
- return tool->sample(tool, event, sample, sid->evsel, machine);
+ evsel = container_of(sid->evsel, struct evsel, core);
+ return tool->sample(tool, event, sample, evsel, machine);
}
static int deliver_sample_group(struct evlist *evlist,
--
2.21.0
Rename (perf_evlist__exit) to evlist__exit(), so we don't have a
name clash when we add (perf_evlist__exit) in libperf.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 4 ++--
tools/perf/util/evlist.h | 2 +-
tools/perf/util/python.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index dc7117c33ab8..d71fafd472ea 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -137,7 +137,7 @@ static void perf_evlist__purge(struct evlist *evlist)
evlist->core.nr_entries = 0;
}
-void perf_evlist__exit(struct evlist *evlist)
+void evlist__exit(struct evlist *evlist)
{
zfree(&evlist->mmap);
zfree(&evlist->overwrite_mmap);
@@ -156,7 +156,7 @@ void evlist__delete(struct evlist *evlist)
evlist->core.cpus = NULL;
evlist->core.threads = NULL;
perf_evlist__purge(evlist);
- perf_evlist__exit(evlist);
+ evlist__exit(evlist);
free(evlist);
}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index f07501602353..b33c5d67410a 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -65,7 +65,7 @@ struct evlist *perf_evlist__new_default(void);
struct evlist *perf_evlist__new_dummy(void);
void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
struct perf_thread_map *threads);
-void perf_evlist__exit(struct evlist *evlist);
+void evlist__exit(struct evlist *evlist);
void evlist__delete(struct evlist *evlist);
void evlist__add(struct evlist *evlist, struct evsel *entry);
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 9b0eaf83212f..7e28f7e18d41 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -884,7 +884,7 @@ static int pyrf_evlist__init(struct pyrf_evlist *pevlist,
static void pyrf_evlist__delete(struct pyrf_evlist *pevlist)
{
- perf_evlist__exit(&pevlist->evlist);
+ evlist__exit(&pevlist->evlist);
Py_TYPE(pevlist)->tp_free((PyObject*)pevlist);
}
--
2.21.0
Move id array from struct evsel to libperf's struct perf_evsel.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/evsel.h | 1 +
tools/perf/util/evlist.c | 2 +-
tools/perf/util/evsel.c | 6 +++---
tools/perf/util/evsel.h | 1 -
tools/perf/util/header.c | 20 ++++++++++----------
tools/perf/util/intel-bts.c | 2 +-
tools/perf/util/intel-pt.c | 8 ++++----
tools/perf/util/session.c | 2 +-
8 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index d284825383af..bea14e6e28f5 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -16,6 +16,7 @@ struct perf_evsel {
struct perf_thread_map *threads;
struct xyarray *fd;
struct xyarray *sample_id;
+ u64 *id;
/* parse modifier helper */
int nr_members;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4018f0ff75c8..ae7f62ae1d29 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -481,7 +481,7 @@ void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel,
int cpu, int thread, u64 id)
{
perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
- evsel->id[evsel->ids++] = id;
+ evsel->core.id[evsel->ids++] = id;
}
int perf_evlist__id_add_fd(struct evlist *evlist,
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index db89f98bb357..194bead17f64 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1238,8 +1238,8 @@ int perf_evsel__alloc_id(struct evsel *evsel, int ncpus, int nthreads)
if (evsel->core.sample_id == NULL)
return -ENOMEM;
- evsel->id = zalloc(ncpus * nthreads * sizeof(u64));
- if (evsel->id == NULL) {
+ evsel->core.id = zalloc(ncpus * nthreads * sizeof(u64));
+ if (evsel->core.id == NULL) {
xyarray__delete(evsel->core.sample_id);
evsel->core.sample_id = NULL;
return -ENOMEM;
@@ -1252,7 +1252,7 @@ static void perf_evsel__free_id(struct evsel *evsel)
{
xyarray__delete(evsel->core.sample_id);
evsel->core.sample_id = NULL;
- zfree(&evsel->id);
+ zfree(&evsel->core.id);
evsel->ids = 0;
}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 9934e99e0c64..f313e07925c4 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -117,7 +117,6 @@ struct evsel {
struct perf_evsel core;
struct evlist *evlist;
char *filter;
- u64 *id;
struct perf_counts *counts;
struct perf_counts *prev_raw_counts;
int idx;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b0c34dda30a0..ebdabaa33d8b 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -538,7 +538,7 @@ static int write_event_desc(struct feat_fd *ff,
/*
* write unique ids for this event
*/
- ret = do_write(ff, evsel->id, evsel->ids * sizeof(u64));
+ ret = do_write(ff, evsel->core.id, evsel->ids * sizeof(u64));
if (ret < 0)
return ret;
}
@@ -1598,7 +1598,7 @@ static void free_event_desc(struct evsel *events)
for (evsel = events; evsel->core.attr.size; evsel++) {
zfree(&evsel->name);
- zfree(&evsel->id);
+ zfree(&evsel->core.id);
}
free(events);
@@ -1665,7 +1665,7 @@ static struct evsel *read_event_desc(struct feat_fd *ff)
if (!id)
goto error;
evsel->ids = nr;
- evsel->id = id;
+ evsel->core.id = id;
for (j = 0 ; j < nr; j++) {
if (do_read_u64(ff, id))
@@ -1709,7 +1709,7 @@ static void print_event_desc(struct feat_fd *ff, FILE *fp)
if (evsel->ids) {
fprintf(fp, ", id = {");
- for (j = 0, id = evsel->id; j < evsel->ids; j++, id++) {
+ for (j = 0, id = evsel->core.id; j < evsel->ids; j++, id++) {
if (j)
fputc(',', fp);
fprintf(fp, " %"PRIu64, *id);
@@ -3083,7 +3083,7 @@ int perf_session__write_header(struct perf_session *session,
evlist__for_each_entry(session->evlist, evsel) {
evsel->id_offset = lseek(fd, 0, SEEK_CUR);
- err = do_write(&ff, evsel->id, evsel->ids * sizeof(u64));
+ err = do_write(&ff, evsel->core.id, evsel->ids * sizeof(u64));
if (err < 0) {
pr_debug("failed to write perf header\n");
return err;
@@ -3824,7 +3824,7 @@ perf_event__synthesize_event_update_unit(struct perf_tool *tool,
size_t size = strlen(evsel->unit);
int err;
- ev = event_update_event__new(size + 1, PERF_EVENT_UPDATE__UNIT, evsel->id[0]);
+ ev = event_update_event__new(size + 1, PERF_EVENT_UPDATE__UNIT, evsel->core.id[0]);
if (ev == NULL)
return -ENOMEM;
@@ -3843,7 +3843,7 @@ perf_event__synthesize_event_update_scale(struct perf_tool *tool,
struct perf_record_event_update_scale *ev_data;
int err;
- ev = event_update_event__new(sizeof(*ev_data), PERF_EVENT_UPDATE__SCALE, evsel->id[0]);
+ ev = event_update_event__new(sizeof(*ev_data), PERF_EVENT_UPDATE__SCALE, evsel->core.id[0]);
if (ev == NULL)
return -ENOMEM;
@@ -3863,7 +3863,7 @@ perf_event__synthesize_event_update_name(struct perf_tool *tool,
size_t len = strlen(evsel->name);
int err;
- ev = event_update_event__new(len + 1, PERF_EVENT_UPDATE__NAME, evsel->id[0]);
+ ev = event_update_event__new(len + 1, PERF_EVENT_UPDATE__NAME, evsel->core.id[0]);
if (ev == NULL)
return -ENOMEM;
@@ -3893,7 +3893,7 @@ perf_event__synthesize_event_update_cpus(struct perf_tool *tool,
ev->header.type = PERF_RECORD_EVENT_UPDATE;
ev->header.size = (u16)size;
ev->type = PERF_EVENT_UPDATE__CPUS;
- ev->id = evsel->id[0];
+ ev->id = evsel->core.id[0];
cpu_map_data__synthesize((struct perf_record_cpu_map_data *)ev->data,
evsel->core.own_cpus,
@@ -3952,7 +3952,7 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
evlist__for_each_entry(evlist, evsel) {
err = perf_event__synthesize_attr(tool, &evsel->core.attr, evsel->ids,
- evsel->id, process);
+ evsel->core.id, process);
if (err) {
pr_debug("failed to create perf header attribute\n");
return err;
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index aacffa2b0362..daf42915b326 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -795,7 +795,7 @@ static int intel_bts_synth_events(struct intel_bts *bts,
attr.sample_id_all = evsel->core.attr.sample_id_all;
attr.read_format = evsel->core.attr.read_format;
- id = evsel->id[0] + 1000000000;
+ id = evsel->core.id[0] + 1000000000;
if (!id)
id = 1;
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 9b56fb74bedf..4a1d46158401 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1704,7 +1704,7 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)
struct intel_pt *pt = ptq->pt;
struct evsel *evsel = pt->pebs_evsel;
u64 sample_type = evsel->core.attr.sample_type;
- u64 id = evsel->id[0];
+ u64 id = evsel->core.id[0];
u8 cpumode;
if (intel_pt_skip_event(pt))
@@ -2719,7 +2719,7 @@ static void intel_pt_set_event_name(struct evlist *evlist, u64 id,
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel) {
- if (evsel->id && evsel->id[0] == id) {
+ if (evsel->core.id && evsel->core.id[0] == id) {
if (evsel->name)
zfree(&evsel->name);
evsel->name = strdup(name);
@@ -2775,7 +2775,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
attr.sample_id_all = evsel->core.attr.sample_id_all;
attr.read_format = evsel->core.attr.read_format;
- id = evsel->id[0] + 1000000000;
+ id = evsel->core.id[0] + 1000000000;
if (!id)
id = 1;
@@ -2902,7 +2902,7 @@ static void intel_pt_setup_pebs_events(struct intel_pt *pt)
return;
evlist__for_each_entry(pt->session->evlist, evsel) {
- if (evsel->core.attr.aux_output && evsel->id) {
+ if (evsel->core.attr.aux_output && evsel->core.id) {
pt->sample_pebs = true;
pt->pebs_evsel = evsel;
return;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index e9e4a04f15db..f50cd54cf96b 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2458,7 +2458,7 @@ int perf_event__synthesize_id_index(struct perf_tool *tool,
e = &ev->id_index.entries[i++];
- e->id = evsel->id[j];
+ e->id = evsel->core.id[j];
sid = perf_evlist__id2sid(evlist, e->id);
if (!sid) {
--
2.21.0
Adding perf_mmap__new function to create and
initialize new 'struct perf_mmap' object to
internal header internal/mmap.h
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 2 ++
tools/perf/lib/mmap.c | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index cc0a5995cd3c..31946e26368a 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -41,6 +41,8 @@ struct perf_mmap_param {
size_t perf_mmap__mmap_len(struct perf_mmap *map);
+struct perf_mmap *perf_mmap__new(bool overwrite,
+ libperf_unmap_cb_t unmap_cb);
void perf_mmap__init(struct perf_mmap *map, bool overwrite,
libperf_unmap_cb_t unmap_cb);
int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index ea46f325fa98..720dda578ed9 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include <sys/mman.h>
+#include <linux/zalloc.h>
#include <internal/mmap.h>
#include <internal/lib.h>
@@ -12,6 +13,16 @@ void perf_mmap__init(struct perf_mmap *map, bool overwrite,
refcount_set(&map->refcnt, 0);
}
+struct perf_mmap *perf_mmap__new(bool overwrite, libperf_unmap_cb_t unmap_cb)
+{
+ struct perf_mmap *map = zalloc(sizeof(*map));
+
+ if (map)
+ perf_mmap__init(map, overwrite, unmap_cb);
+
+ return map;
+}
+
size_t perf_mmap__mmap_len(struct perf_mmap *map)
{
return map->mask + 1 + page_size;
--
2.21.0
Adding perf_evlist__mmap_cb_idx function to call
auxtrace_mmap_params__set_idx on each new index
during perf_evlist__mmap_ops call.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/util/evlist.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index a9fc35d25a59..850dacf7bf97 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -714,6 +714,17 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
return 0;
}
+static void
+perf_evlist__mmap_cb_idx(struct perf_evlist *_evlist,
+ struct perf_mmap_param *_mp,
+ int idx, bool per_cpu)
+{
+ struct evlist *evlist = container_of(_evlist, struct evlist, core);
+ struct mmap_params *mp = container_of(_mp, struct mmap_params, core);
+
+ auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, idx, per_cpu);
+}
+
static int evlist__mmap_per_cpu(struct evlist *evlist,
struct mmap_params *mp)
{
@@ -910,6 +921,9 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
.flush = flush,
.comp_level = comp_level
};
+ struct perf_evlist_mmap_ops ops __maybe_unused = {
+ .idx = perf_evlist__mmap_cb_idx,
+ };
if (!evlist->mmap)
evlist->mmap = evlist__alloc_mmap(evlist, false);
--
2.21.0
There's no point to export perf_evsel__init/perf_evlist__init,
it's called from perf_evsel__new/perf_evlist__new respectively.
It's used only from perf where perf_evsel/perf_evlist is embedded
perf's evsel/evlist.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/evlist.h | 1 +
tools/perf/lib/include/internal/evsel.h | 1 +
tools/perf/lib/include/perf/evlist.h | 1 -
tools/perf/lib/include/perf/evsel.h | 2 --
tools/perf/lib/libperf.map | 2 --
5 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index a5bf13df08dc..63b6bc838854 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -48,6 +48,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
struct perf_evlist_mmap_ops *ops,
struct perf_mmap_param *mp);
+void perf_evlist__init(struct perf_evlist *evlist);
void perf_evlist__exit(struct perf_evlist *evlist);
/**
diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
index 0ff4811a7f32..1da21325386b 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -48,6 +48,7 @@ struct perf_evsel {
bool system_wide;
};
+void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr);
int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
void perf_evsel__close_fd(struct perf_evsel *evsel);
void perf_evsel__free_fd(struct perf_evsel *evsel);
diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h
index 9c3f341dc261..bdd272a2fd47 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -9,7 +9,6 @@ struct perf_evsel;
struct perf_cpu_map;
struct perf_thread_map;
-LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist);
LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
struct perf_evsel *evsel);
LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,
diff --git a/tools/perf/lib/include/perf/evsel.h b/tools/perf/lib/include/perf/evsel.h
index 4388667f265c..557f5815a9c9 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -21,8 +21,6 @@ struct perf_counts_values {
};
};
-LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,
- struct perf_event_attr *attr);
LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 265188126b08..f4c09b0c5ca0 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -20,7 +20,6 @@ LIBPERF_0.0.1 {
perf_evsel__delete;
perf_evsel__enable;
perf_evsel__disable;
- perf_evsel__init;
perf_evsel__open;
perf_evsel__close;
perf_evsel__read;
@@ -33,7 +32,6 @@ LIBPERF_0.0.1 {
perf_evlist__close;
perf_evlist__enable;
perf_evlist__disable;
- perf_evlist__init;
perf_evlist__add;
perf_evlist__remove;
perf_evlist__next;
--
2.21.0
Adding libperf's version of perf_evlist__mmap/munmap
functions and exporting them in perf/evlist.h header.
It's the backbone of what we have in perf code. The
following changes will add needed callbacks and then
we finally switch perf code to use libperf's version.
Adding mmap/mmap_ovw 'struct perf_mmap' object arrays
to hold maps for libperf's evlist.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 215 +++++++++++++++++++++++
tools/perf/lib/include/internal/evlist.h | 2 +
tools/perf/lib/include/perf/evlist.h | 3 +
tools/perf/lib/libperf.map | 2 +
4 files changed, 222 insertions(+)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 160393cb9bed..168bc5d0a1c8 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -7,13 +7,20 @@
#include <internal/evlist.h>
#include <internal/evsel.h>
#include <internal/xyarray.h>
+#include <internal/mmap.h>
+#include <internal/cpumap.h>
+#include <internal/threadmap.h>
+#include <internal/xyarray.h>
+#include <internal/lib.h>
#include <linux/zalloc.h>
+#include <sys/ioctl.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <poll.h>
+#include <sys/mman.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
@@ -101,6 +108,8 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev)
void perf_evlist__delete(struct perf_evlist *evlist)
{
+ free(evlist->mmap);
+ free(evlist->mmap_ovw);
free(evlist);
}
@@ -279,3 +288,209 @@ int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
{
return fdarray__poll(&evlist->pollfd, timeout);
}
+
+static int perf_evlist__alloc_maps(struct perf_evlist *evlist)
+{
+ struct perf_mmap **map;
+
+ evlist->nr_mmaps = perf_cpu_map__nr(evlist->cpus);
+ if (perf_cpu_map__empty(evlist->cpus))
+ evlist->nr_mmaps = perf_thread_map__nr(evlist->threads);
+
+ map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap *));
+ if (map)
+ evlist->mmap = map;
+
+ map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap *));
+ if (map)
+ evlist->mmap_ovw = map;
+
+ return 0;
+}
+
+static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
+ struct perf_evsel *evsel, int idx, int cpu,
+ int thread)
+{
+ struct perf_sample_id *sid = SID(evsel, cpu, thread);
+
+ sid->idx = idx;
+ if (evlist->cpus && cpu >= 0)
+ sid->cpu = evlist->cpus->map[cpu];
+ else
+ sid->cpu = -1;
+ if (!evsel->system_wide && evlist->threads && thread >= 0)
+ sid->tid = perf_thread_map__pid(evlist->threads, thread);
+ else
+ sid->tid = -1;
+}
+
+#define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
+
+static int
+mmap_per_evsel(struct perf_evlist *evlist, int idx,
+ struct perf_mmap_param *mp, int cpu_idx,
+ int thread, int *_output, int *_output_overwrite)
+{
+ int evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx);
+ struct perf_evsel *evsel;
+ int revent;
+
+ perf_evlist__for_each_entry(evlist, evsel) {
+ bool overwrite = evsel->attr.write_backward;
+ struct perf_mmap *map;
+ int *output, fd, cpu;
+
+ if (evsel->system_wide && thread)
+ continue;
+
+ cpu = perf_cpu_map__idx(evsel->cpus, evlist_cpu);
+ if (cpu == -1)
+ continue;
+
+ map = perf_mmap__new(overwrite, NULL);
+ if (map == NULL)
+ return -ENOMEM;
+
+ if (overwrite) {
+ mp->prot = PROT_READ;
+ output = _output_overwrite;
+ evlist->mmap_ovw[idx] = map;
+ } else {
+ mp->prot = PROT_READ | PROT_WRITE;
+ output = _output;
+ evlist->mmap[idx] = map;
+ }
+
+ fd = FD(evsel, cpu, thread);
+
+ if (*output == -1) {
+ *output = fd;
+
+ if (perf_mmap__mmap(map, mp, *output, evlist_cpu) < 0)
+ return -1;
+ } else {
+ if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
+ return -1;
+
+ perf_mmap__get(map);
+ }
+
+ revent = !overwrite ? POLLIN : 0;
+
+ if (!evsel->system_wide &&
+ perf_evlist__add_pollfd(evlist, fd, map, revent) < 0) {
+ perf_mmap__put(map);
+ return -1;
+ }
+
+ if (evsel->attr.read_format & PERF_FORMAT_ID) {
+ if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
+ fd) < 0)
+ return -1;
+ perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
+ thread);
+ }
+ }
+
+ return 0;
+}
+
+static int
+mmap_per_thread(struct perf_evlist *evlist, struct perf_mmap_param *mp)
+{
+ int thread;
+ int nr_threads = perf_thread_map__nr(evlist->threads);
+
+ for (thread = 0; thread < nr_threads; thread++) {
+ int output = -1;
+ int output_overwrite = -1;
+
+ if (mmap_per_evsel(evlist, thread, mp, 0, thread,
+ &output, &output_overwrite))
+ goto out_unmap;
+ }
+
+ return 0;
+
+out_unmap:
+ perf_evlist__munmap(evlist);
+ return -1;
+}
+
+static int
+mmap_per_cpu(struct perf_evlist *evlist, struct perf_mmap_param *mp)
+{
+ int nr_threads = perf_thread_map__nr(evlist->threads);
+ int nr_cpus = perf_cpu_map__nr(evlist->cpus);
+ int cpu, thread;
+
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
+ int output = -1;
+ int output_overwrite = -1;
+
+ for (thread = 0; thread < nr_threads; thread++) {
+ if (mmap_per_evsel(evlist, cpu, mp, cpu,
+ thread, &output, &output_overwrite))
+ goto out_unmap;
+ }
+ }
+
+ return 0;
+
+out_unmap:
+ perf_evlist__munmap(evlist);
+ return -1;
+}
+
+int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
+{
+ struct perf_evsel *evsel;
+ const struct perf_cpu_map *cpus = evlist->cpus;
+ const struct perf_thread_map *threads = evlist->threads;
+ struct perf_mmap_param mp;
+
+ if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
+ return -ENOMEM;
+
+ perf_evlist__for_each_entry(evlist, evsel) {
+ if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
+ evsel->sample_id == NULL &&
+ perf_evsel__alloc_id(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
+ return -ENOMEM;
+ }
+
+ evlist->mmap_len = (pages + 1) * page_size;
+ mp.mask = evlist->mmap_len - page_size - 1;
+
+ if (perf_cpu_map__empty(cpus))
+ return mmap_per_thread(evlist, &mp);
+
+ return mmap_per_cpu(evlist, &mp);
+}
+
+void perf_evlist__munmap(struct perf_evlist *evlist)
+{
+ int i;
+
+ if (evlist->mmap) {
+ for (i = 0; i < evlist->nr_mmaps; i++) {
+ struct perf_mmap *map = evlist->mmap[i];
+
+ perf_mmap__munmap(map);
+ free(map);
+ }
+ }
+
+ if (evlist->mmap_ovw) {
+ for (i = 0; i < evlist->nr_mmaps; i++) {
+ struct perf_mmap *map = evlist->mmap_ovw[i];
+
+ perf_mmap__munmap(map);
+ free(map);
+ }
+ }
+
+ zfree(&evlist->mmap);
+ zfree(&evlist->mmap_ovw);
+}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 9f440ab12b76..b136d1b4ea72 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -22,6 +22,8 @@ struct perf_evlist {
size_t mmap_len;
struct fdarray pollfd;
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
+ struct perf_mmap **mmap;
+ struct perf_mmap **mmap_ovw;
};
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h
index 8a2ce0757ab2..28b6a12a8a2b 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -33,4 +33,7 @@ LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist,
struct perf_thread_map *threads);
LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
+LIBPERF_API int perf_evlist__mmap(struct perf_evlist *evlist, int pages);
+LIBPERF_API void perf_evlist__munmap(struct perf_evlist *evlist);
+
#endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 6e7d9be3c35f..198dcf305356 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -39,6 +39,8 @@ LIBPERF_0.0.1 {
perf_evlist__next;
perf_evlist__set_maps;
perf_evlist__poll;
+ perf_evlist__mmap;
+ perf_evlist__munmap;
perf_mmap__consume;
perf_mmap__read_init;
perf_mmap__read_done;
--
2.21.0
Both static and dynamic tests needs to link libapi.a,
because it's using its functions. Adding also include
path for libapi includes.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/Makefile | 1 +
tools/perf/lib/tests/Makefile | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index 0889c9c3ec19..0f233638ef1f 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -107,6 +107,7 @@ else
endif
LIBAPI = $(API_PATH)libapi.a
+export LIBAPI
$(LIBAPI): FORCE
$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
index 1ee4e9ba848b..a43cd08c5c03 100644
--- a/tools/perf/lib/tests/Makefile
+++ b/tools/perf/lib/tests/Makefile
@@ -16,13 +16,13 @@ all:
include $(srctree)/tools/scripts/Makefile.include
-INCLUDE = -I$(srctree)/tools/perf/lib/include -I$(srctree)/tools/include
+INCLUDE = -I$(srctree)/tools/perf/lib/include -I$(srctree)/tools/include -I$(srctree)/tools/lib
$(TESTS_A): FORCE
- $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -o $@ $(subst -a,.c,$@) ../libperf.a
+ $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -o $@ $(subst -a,.c,$@) ../libperf.a $(LIBAPI)
$(TESTS_SO): FORCE
- $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -L.. -o $@ $(subst -so,.c,$@) -lperf
+ $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -L.. -o $@ $(subst -so,.c,$@) $(LIBAPI) -lperf
all: $(TESTS_A) $(TESTS_SO)
--
2.21.0
To be able to pass specific callbacks to evlist's mmap.
There will be specific call to this function from perf's
evlist_mmap and libperf's perf_evlist__mmap functions in
following changes.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 28 +++++++++++++++++-------
tools/perf/lib/include/internal/evlist.h | 8 +++++++
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 168bc5d0a1c8..0f103c10d8ca 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -443,15 +443,16 @@ mmap_per_cpu(struct perf_evlist *evlist, struct perf_mmap_param *mp)
return -1;
}
-int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
+int perf_evlist__mmap_ops(struct perf_evlist *evlist,
+ struct perf_evlist_mmap_ops *ops,
+ struct perf_mmap_param *mp)
{
struct perf_evsel *evsel;
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;
- struct perf_mmap_param mp;
- if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
- return -ENOMEM;
+ if (!ops)
+ return -EINVAL;
perf_evlist__for_each_entry(evlist, evsel) {
if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
@@ -460,13 +461,24 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
return -ENOMEM;
}
+ if (perf_cpu_map__empty(cpus))
+ return mmap_per_thread(evlist, mp);
+
+ return mmap_per_cpu(evlist, mp);
+}
+
+int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
+{
+ struct perf_mmap_param mp;
+ struct perf_evlist_mmap_ops ops;
+
+ if (!evlist->mmap && perf_evlist__alloc_maps(evlist))
+ return -ENOMEM;
+
evlist->mmap_len = (pages + 1) * page_size;
mp.mask = evlist->mmap_len - page_size - 1;
- if (perf_cpu_map__empty(cpus))
- return mmap_per_thread(evlist, &mp);
-
- return mmap_per_cpu(evlist, &mp);
+ return perf_evlist__mmap_ops(evlist, &ops, &mp);
}
void perf_evlist__munmap(struct perf_evlist *evlist)
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index b136d1b4ea72..5a8706a81c0d 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -11,6 +11,7 @@
struct perf_cpu_map;
struct perf_thread_map;
+struct perf_mmap_param;
struct perf_evlist {
struct list_head entries;
@@ -26,10 +27,17 @@ struct perf_evlist {
struct perf_mmap **mmap_ovw;
};
+struct perf_evlist_mmap_ops {
+};
+
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
void *ptr, short revent);
+int perf_evlist__mmap_ops(struct perf_evlist *evlist,
+ struct perf_evlist_mmap_ops *ops,
+ struct perf_mmap_param *mp);
+
/**
* __perf_evlist__for_each_entry - iterate thru all the evsels
* @list: list_head instance to iterate
--
2.21.0
Adding static perf_evlist__purge function to purge
and delete evsels from evlist.
Adding also perf_evlist__for_each_entry_safe which
is used by perf_evlist__purge.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/evlist.c | 13 +++++++++++++
tools/perf/lib/include/internal/evlist.h | 18 ++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index b9dd040a6162..1c8a9e283adc 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -107,6 +107,18 @@ perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev)
return next;
}
+static void perf_evlist__purge(struct perf_evlist *evlist)
+{
+ struct perf_evsel *pos, *n;
+
+ perf_evlist__for_each_entry_safe(evlist, n, pos) {
+ list_del_init(&pos->node);
+ perf_evsel__delete(pos);
+ }
+
+ evlist->nr_entries = 0;
+}
+
void perf_evlist__exit(struct perf_evlist *evlist)
{
perf_cpu_map__put(evlist->cpus);
@@ -120,6 +132,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
void perf_evlist__delete(struct perf_evlist *evlist)
{
+ perf_evlist__purge(evlist);
perf_evlist__exit(evlist);
free(evlist);
}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 1ca822eeab1d..a5bf13df08dc 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -82,6 +82,24 @@ void perf_evlist__exit(struct perf_evlist *evlist);
#define perf_evlist__for_each_entry_reverse(evlist, evsel) \
__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
+/**
+ * __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
+ * @list: list_head instance to iterate
+ * @tmp: struct evsel temp iterator
+ * @evsel: struct evsel iterator
+ */
+#define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \
+ list_for_each_entry_safe(evsel, tmp, list, node)
+
+/**
+ * perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
+ * @evlist: evlist instance to iterate
+ * @evsel: struct evsel iterator
+ * @tmp: struct evsel temp iterator
+ */
+#define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \
+ __perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
+
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
{
return list_entry(evlist->entries.next, struct perf_evsel, node);
--
2.21.0
Move event_copy from tools/perf's mmap to libperf's perf_mmap struct.
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/lib/include/internal/mmap.h | 4 ++++
tools/perf/util/mmap.c | 4 ++--
tools/perf/util/mmap.h | 1 -
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
index 631e58dbc9e6..3a404ec06214 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -7,6 +7,9 @@
#include <stdlib.h>
#include <stdbool.h>
+/* perf sample has 16 bits size limit */
+#define PERF_SAMPLE_MAX_SIZE (1 << 16)
+
/**
* struct perf_mmap - perf's ring buffer mmap details
*
@@ -22,6 +25,7 @@ struct perf_mmap {
u64 start;
u64 end;
bool overwrite;
+ char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
};
#endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index a8850ce2c2ff..4b8ec8dd79c5 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -51,7 +51,7 @@ static union perf_event *perf_mmap__read(struct mmap *map,
if ((*startp & map->core.mask) + size != ((*startp + size) & map->core.mask)) {
unsigned int offset = *startp;
unsigned int len = min(sizeof(*event), size), cpy;
- void *dst = map->event_copy;
+ void *dst = map->core.event_copy;
do {
cpy = min(map->core.mask + 1 - (offset & map->core.mask), len);
@@ -61,7 +61,7 @@ static union perf_event *perf_mmap__read(struct mmap *map,
len -= cpy;
} while (len);
- event = (union perf_event *)map->event_copy;
+ event = (union perf_event *)map->core.event_copy;
}
*startp += size;
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 1dea2abe1de5..bdbbf48ee906 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -23,7 +23,6 @@ struct aiocb;
struct mmap {
struct perf_mmap core;
struct auxtrace_mmap auxtrace_mmap;
- char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
#ifdef HAVE_AIO_SUPPORT
struct {
void **data;
--
2.21.0
On Fri, Sep 13, 2019 at 03:22:42PM +0200, Jiri Olsa wrote:
> hi,
> sending changes for exporting basic sampling interface
> in libperf. It's now possible to use following code in
> applications via libperf:
>
> --- (example is without error checks for simplicity)
>
> struct perf_event_attr attr = {
> .type = PERF_TYPE_TRACEPOINT,
> .sample_period = 1,
> .wakeup_watermark = 1,
> .disabled = 1,
> };
> /* ... setup attr */
>
> cpus = perf_cpu_map__new(NULL);
>
> evlist = perf_evlist__new();
> evsel = perf_evsel__new(&attr);
> perf_evlist__add(evlist, evsel);
>
> perf_evlist__set_maps(evlist, cpus, NULL);
>
> err = perf_evlist__open(evlist);
> err = perf_evlist__mmap(evlist, 4);
>
> err = perf_evlist__enable(evlist);
>
> /* ... monitored area, plus all the other cpus */
>
> err = perf_evlist__disable(evlist);
>
> perf_evlist__for_each_mmap(evlist, map) {
> if (perf_mmap__read_init(map) < 0)
> continue;
>
> while ((event = perf_mmap__read_event(map)) != NULL) {
> perf_mmap__consume(map);
> }
>
> perf_mmap__read_done(map);
> }
>
> perf_evlist__delete(evlist);
> perf_cpu_map__put(cpus);
>
> --- (end)
>
> Nothing is carved in stone so far, the interface is exported
> as is available in perf now and we can change it as we want.
>
> New tests are added in test-evlist.c to do thread and cpu based
> sampling.
>
> All the functionality should not change, however there's considerable
> mmap code rewrite, so would be great if guys could run your usual
> workloads to see if all is fine.. so far so good in my tests ;-)
>
> It's also available in here:
> git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
> perf/lib
hi,
I rebased the branch to latest Arnaldo's perf/core branch
jirka
Em Fri, Sep 13, 2019 at 03:22:52PM +0200, Jiri Olsa escreveu:
> Add the perf_mmap to libperf.
>
> The definition is added into:
>
> include/internal/mmap.h
>
> which is not to be included by users, but shared
> within perf and libperf.
> diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
> new file mode 100644
> index 000000000000..8d10559dee49
> --- /dev/null
> +++ b/tools/perf/lib/include/internal/mmap.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __LIBPERF_INTERNAL_MMAP_H
> +#define __LIBPERF_INTERNAL_MMAP_H
> +
> +#include <linux/refcount.h>
> +#include <linux/compiler.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
So you're doing this with high granularity, cool! But then you should
take care not to add unnecessary stuff here, i.e. these four headers are
not necessary at this point in the series, I'm removing them and adding
as they become necessary.
- Arnaldo
> +/**
> + * struct perf_mmap - perf's ring buffer mmap details
> + *
> + * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
> + */
> +struct perf_mmap {
> + void *base;
> +};
> +
> +#endif /* __LIBPERF_INTERNAL_MMAP_H */
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index f3b7c8b0fa90..76190b2edd78 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -31,7 +31,7 @@ size_t perf_mmap__mmap_len(struct mmap *map)
> static union perf_event *perf_mmap__read(struct mmap *map,
> u64 *startp, u64 end)
> {
> - unsigned char *data = map->base + page_size;
> + unsigned char *data = map->core.base + page_size;
> union perf_event *event = NULL;
> int diff = end - *startp;
>
> @@ -116,7 +116,7 @@ void perf_mmap__get(struct mmap *map)
>
> void perf_mmap__put(struct mmap *map)
> {
> - BUG_ON(map->base && refcount_read(&map->refcnt) == 0);
> + BUG_ON(map->core.base && refcount_read(&map->refcnt) == 0);
>
> if (refcount_dec_and_test(&map->refcnt))
> perf_mmap__munmap(map);
> @@ -317,9 +317,9 @@ void perf_mmap__munmap(struct mmap *map)
> munmap(map->data, perf_mmap__mmap_len(map));
> map->data = NULL;
> }
> - if (map->base != NULL) {
> - munmap(map->base, perf_mmap__mmap_len(map));
> - map->base = NULL;
> + if (map->core.base != NULL) {
> + munmap(map->core.base, perf_mmap__mmap_len(map));
> + map->core.base = NULL;
> map->fd = -1;
> refcount_set(&map->refcnt, 0);
> }
> @@ -370,12 +370,12 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
> refcount_set(&map->refcnt, 2);
> map->prev = 0;
> map->mask = mp->mask;
> - map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
> + map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
> MAP_SHARED, fd, 0);
> - if (map->base == MAP_FAILED) {
> + if (map->core.base == MAP_FAILED) {
> pr_debug2("failed to mmap perf event ring buffer, error %d\n",
> errno);
> - map->base = NULL;
> + map->core.base = NULL;
> return -1;
> }
> map->fd = fd;
> @@ -399,7 +399,7 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
> }
>
> if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
> - &mp->auxtrace_mp, map->base, fd))
> + &mp->auxtrace_mp, map->core.base, fd))
> return -1;
>
> return perf_mmap__aio_mmap(map, mp);
> @@ -444,7 +444,7 @@ static int __perf_mmap__read_init(struct mmap *md)
> {
> u64 head = perf_mmap__read_head(md);
> u64 old = md->prev;
> - unsigned char *data = md->base + page_size;
> + unsigned char *data = md->core.base + page_size;
> unsigned long size;
>
> md->start = md->overwrite ? head : old;
> @@ -489,7 +489,7 @@ int perf_mmap__push(struct mmap *md, void *to,
> int push(struct mmap *map, void *to, void *buf, size_t size))
> {
> u64 head = perf_mmap__read_head(md);
> - unsigned char *data = md->base + page_size;
> + unsigned char *data = md->core.base + page_size;
> unsigned long size;
> void *buf;
> int rc = 0;
> diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
> index 01524608a984..9028b0e8a0ed 100644
> --- a/tools/perf/util/mmap.h
> +++ b/tools/perf/util/mmap.h
> @@ -1,6 +1,7 @@
> #ifndef __PERF_MMAP_H
> #define __PERF_MMAP_H 1
>
> +#include <internal/mmap.h>
> #include <linux/compiler.h>
> #include <linux/refcount.h>
> #include <linux/types.h>
> @@ -20,7 +21,7 @@ struct aiocb;
> * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
> */
> struct mmap {
> - void *base;
> + struct perf_mmap core;
> int mask;
> int fd;
> int cpu;
> @@ -88,12 +89,12 @@ void perf_mmap__consume(struct mmap *map);
>
> static inline u64 perf_mmap__read_head(struct mmap *mm)
> {
> - return ring_buffer_read_head(mm->base);
> + return ring_buffer_read_head(mm->core.base);
> }
>
> static inline void perf_mmap__write_tail(struct mmap *md, u64 tail)
> {
> - ring_buffer_write_tail(md->base, tail);
> + ring_buffer_write_tail(md->core.base, tail);
> }
>
> union perf_event *perf_mmap__read_forward(struct mmap *map);
> --
> 2.21.0
--
- Arnaldo
On Mon, Sep 23, 2019 at 12:05:33PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Sep 13, 2019 at 03:22:52PM +0200, Jiri Olsa escreveu:
> > Add the perf_mmap to libperf.
> >
> > The definition is added into:
> >
> > include/internal/mmap.h
> >
> > which is not to be included by users, but shared
> > within perf and libperf.
>
> > diff --git a/tools/perf/lib/include/internal/mmap.h b/tools/perf/lib/include/internal/mmap.h
> > new file mode 100644
> > index 000000000000..8d10559dee49
> > --- /dev/null
> > +++ b/tools/perf/lib/include/internal/mmap.h
> > @@ -0,0 +1,19 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef __LIBPERF_INTERNAL_MMAP_H
> > +#define __LIBPERF_INTERNAL_MMAP_H
> > +
> > +#include <linux/refcount.h>
> > +#include <linux/compiler.h>
> > +#include <stdlib.h>
> > +#include <stdbool.h>
>
> So you're doing this with high granularity, cool! But then you should
> take care not to add unnecessary stuff here, i.e. these four headers are
yea, they will be needed for added fields in following patches
> not necessary at this point in the series, I'm removing them and adding
> as they become necessary.
ok, thanks
jirka
Em Fri, Sep 13, 2019 at 03:23:01PM +0200, Jiri Olsa escreveu:
> diff --git a/tools/perf/lib/include/internal/evsel.h b/tools/perf/lib/include/internal/evsel.h
> index 8b854d1c9b45..220cb2e2b54e 100644
> --- a/tools/perf/lib/include/internal/evsel.h
> +++ b/tools/perf/lib/include/internal/evsel.h
> @@ -18,6 +18,7 @@ struct perf_evsel {
>
> /* parse modifier helper */
> int nr_members;
> + bool system_wide;
> };
Forgot to add:
#include <stdbool.h>
Added.
- Arnaldo
Em Fri, Sep 13, 2019 at 03:23:14PM +0200, Jiri Olsa escreveu:
> We need page_size in libperf, so moving it in there.
> Adding libperf_init as a global libperf init functon.
>
> Link: http://lkml.kernel.org/n/[email protected]
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/perf/lib/core.c | 7 +++++++
> tools/perf/lib/include/internal/lib.h | 2 ++
> tools/perf/lib/include/perf/core.h | 1 +
> tools/perf/lib/lib.c | 2 ++
> tools/perf/lib/libperf.map | 1 +
> tools/perf/perf.c | 4 ++--
> tools/perf/util/util.h | 2 --
you forgot to remove it from tools/perf/util/util.c, I did it, and also
added internal/lib.h to the places that use page_size, after this I'll
remove that include from util/util.h, that header has to die :-)
- Arnaldo
> 7 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
> index 29d5e3348718..6689d593c2d1 100644
> --- a/tools/perf/lib/core.c
> +++ b/tools/perf/lib/core.c
> @@ -4,7 +4,9 @@
>
> #include <stdio.h>
> #include <stdarg.h>
> +#include <unistd.h>
> #include <perf/core.h>
> +#include <internal/lib.h>
> #include "internal.h"
>
> static int __base_pr(enum libperf_print_level level, const char *format,
> @@ -32,3 +34,8 @@ void libperf_print(enum libperf_print_level level, const char *format, ...)
> __libperf_pr(level, format, args);
> va_end(args);
> }
> +
> +void libperf_init(void)
> +{
> + page_size = sysconf(_SC_PAGE_SIZE);
> +}
> diff --git a/tools/perf/lib/include/internal/lib.h b/tools/perf/lib/include/internal/lib.h
> index 0b56f1201dc9..9168b7d2a7e1 100644
> --- a/tools/perf/lib/include/internal/lib.h
> +++ b/tools/perf/lib/include/internal/lib.h
> @@ -4,6 +4,8 @@
>
> #include <unistd.h>
>
> +extern unsigned int page_size;
> +
> ssize_t readn(int fd, void *buf, size_t n);
> ssize_t writen(int fd, const void *buf, size_t n);
>
> diff --git a/tools/perf/lib/include/perf/core.h b/tools/perf/lib/include/perf/core.h
> index c341a7b2c874..ba2f4e76a3e2 100644
> --- a/tools/perf/lib/include/perf/core.h
> +++ b/tools/perf/lib/include/perf/core.h
> @@ -18,5 +18,6 @@ typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
> const char *, va_list ap);
>
> LIBPERF_API void libperf_set_print(libperf_print_fn_t fn);
> +LIBPERF_API void libperf_init(void);
>
> #endif /* __LIBPERF_CORE_H */
> diff --git a/tools/perf/lib/lib.c b/tools/perf/lib/lib.c
> index 2a81819c3b8c..18658931fc71 100644
> --- a/tools/perf/lib/lib.c
> +++ b/tools/perf/lib/lib.c
> @@ -5,6 +5,8 @@
> #include <linux/kernel.h>
> #include <internal/lib.h>
>
> +unsigned int page_size;
> +
> static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
> {
> void *buf_start = buf;
> diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
> index dc4d66363bc4..3fbf050b5add 100644
> --- a/tools/perf/lib/libperf.map
> +++ b/tools/perf/lib/libperf.map
> @@ -1,5 +1,6 @@
> LIBPERF_0.0.1 {
> global:
> + libperf_init;
> libperf_set_print;
> perf_cpu_map__dummy_new;
> perf_cpu_map__get;
> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
> index 1193b923e801..ead18b712d6c 100644
> --- a/tools/perf/perf.c
> +++ b/tools/perf/perf.c
> @@ -25,6 +25,7 @@
> #include "perf-sys.h"
> #include <api/fs/fs.h>
> #include <api/fs/tracing_path.h>
> +#include <internal/lib.h>
> #include <errno.h>
> #include <pthread.h>
> #include <signal.h>
> @@ -438,8 +439,7 @@ int main(int argc, const char **argv)
> exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT);
> pager_init(PERF_PAGER_ENVIRONMENT);
>
> - /* The page_size is placed in util object. */
> - page_size = sysconf(_SC_PAGE_SIZE);
> + libperf_init();
>
> cmd = extract_argv0_path(argv[0]);
> if (!cmd)
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 45a5c6f20197..d6ae394e67c4 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -33,8 +33,6 @@ int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
>
> size_t hex_width(u64 v);
>
> -extern unsigned int page_size;
> -
> int sysctl__max_stack(void);
>
> int fetch_kernel_version(unsigned int *puint,
> --
> 2.21.0
--
- Arnaldo
On Mon, Sep 23, 2019 at 04:10:36PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Sep 13, 2019 at 03:23:14PM +0200, Jiri Olsa escreveu:
> > We need page_size in libperf, so moving it in there.
> > Adding libperf_init as a global libperf init functon.
> >
> > Link: http://lkml.kernel.org/n/[email protected]
> > Signed-off-by: Jiri Olsa <[email protected]>
> > ---
> > tools/perf/lib/core.c | 7 +++++++
> > tools/perf/lib/include/internal/lib.h | 2 ++
> > tools/perf/lib/include/perf/core.h | 1 +
> > tools/perf/lib/lib.c | 2 ++
> > tools/perf/lib/libperf.map | 1 +
> > tools/perf/perf.c | 4 ++--
> > tools/perf/util/util.h | 2 --
>
> you forgot to remove it from tools/perf/util/util.c, I did it, and also
> added internal/lib.h to the places that use page_size, after this I'll
> remove that include from util/util.h, that header has to die :-)
ah right.. linker wouldn't fail because it's variable,
so there's no conflict..
thanks,
jirka