libperf: Add sampling interface
Jiri Olsa
reviewercover libperf: Add sampling interface
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
---
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
Jiri Olsa
reviewerPATCH 1/73 tools: Add missing stdio.h include to asm/bug.h header
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.
--- tools/include/asm/bug.h | 1 + 1 file changed, 1 insertion(+)
tools/include/asm/bug.h +1 -0
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 2/73 perf tests: Fix static build test
In reply to Jiri OlsaDisable the potential shared library features/libraries, which breaks static build if they are enabled and detected:
jvmti and vdso libraries.
--- tools/perf/tests/make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/make +1 -1
@@ -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
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 3/73 perf tools: Rename struct perf_mmap to struct mmap
In reply to Jiri OlsaRename struct perf_evlist to struct evlist, so we don't have a name clash when we add struct perf_mmap in libperf.
--- 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(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -66,7 +66,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeunion 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);
tools/perf/builtin-kvm.c +1 -1
@@ -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;
tools/perf/builtin-record.c +17 -17
@@ -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_treturn 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);
tools/perf/builtin-top.c +1 -1
@@ -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];
tools/perf/builtin-trace.c +1 -1
@@ -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 )
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -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);
tools/perf/tests/bpf.c +1 -1
@@ -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 )
tools/perf/tests/code-reading.c +1 -1
@@ -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++) {
tools/perf/tests/keep-tracking.c +1 -1
@@ -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 ;
tools/perf/tests/mmap-basic.c +1 -1
@@ -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 ) {
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -88,7 +88,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestfor (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 )
tools/perf/tests/perf-record.c +1 -1
@@ -166,7 +166,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unusfor (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 )
tools/perf/tests/sw-clock.c +1 -1
@@ -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 ;
tools/perf/tests/switch-tracking.c +1 -1
@@ -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++) {
tools/perf/tests/task-exit.c +1 -1
@@ -51,7 +51,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedchar sbuf[STRERR_BUFSIZE ];struct perf_cpu_map *cpus;struct perf_thread_map *threads; -struct perf_mmap *md; +struct mmap *md;signal (SIGCHLD , sig_handler);
tools/perf/util/auxtrace.c +3 -3
@@ -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)
tools/perf/util/auxtrace.h +4 -4
@@ -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);
tools/perf/util/evlist.c +7 -7
@@ -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))
tools/perf/util/evlist.h +2 -2
@@ -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;
tools/perf/util/mmap.c +27 -27
197 lines not on this page · raw message
tools/perf/util/mmap.h +16 -16
@@ -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 */
tools/perf/util/python.c +3 -3
@@ -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,
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 4/73 perf tools: Rename perf_evlist__mmap() to evlist__mmap()
In reply to Jiri OlsaRename perf_evlist__mmap() to evlist__mmap(), so we don't have a name clash when we add perf_evlist__mmap() in libperf.
--- 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(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -91,7 +91,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeCHECK__ (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);
tools/perf/builtin-kvm.c +1 -1
@@ -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);
tools/perf/builtin-record.c +3 -3
@@ -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 ;
tools/perf/builtin-top.c +1 -1
@@ -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;
tools/perf/builtin-trace.c +1 -1
@@ -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;
tools/perf/tests/backward-ring-buffer.c +2 -2
@@ -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 ; }
tools/perf/tests/bpf.c +2 -2
@@ -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; }
tools/perf/tests/code-reading.c +2 -2
@@ -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; }
tools/perf/tests/keep-tracking.c +1 -1
@@ -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
tools/perf/tests/mmap-basic.c +1 -1
@@ -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;
tools/perf/tests/openat-syscall-tp-fields.c +2 -2
@@ -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; }
tools/perf/tests/perf-record.c +2 -2
@@ -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; }
tools/perf/tests/sw-clock.c +1 -1
@@ -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)));
tools/perf/tests/switch-tracking.c +2 -2
@@ -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; }
tools/perf/tests/task-exit.c +1 -1
@@ -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;
tools/perf/util/evlist.c +15 -15
@@ -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) {
tools/perf/util/evlist.h +4 -4
@@ -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);
tools/perf/util/python.c +1 -1
@@ -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 ; }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 5/73 perf tools: Rename perf_evlist__munmap() to evlist__munmap()
In reply to Jiri OlsaRename perf_evlist__munmap() to evlist__munmap(), so we don't have a name clash when we add perf_evlist__munmap() in libperf.
--- 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(-)
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -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; }
tools/perf/util/evlist.c +6 -6
@@ -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 ; }
tools/perf/util/evlist.h +1 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 6/73 perf tools: Rename perf_evlist__alloc_mmap() to evlist__alloc_mmap()
In reply to Jiri OlsaRename (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.
--- tools/perf/util/evlist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/evlist.c +4 -4
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 7/73 perf tools: Rename perf_evlist__exit() to evlist__exit()
In reply to Jiri OlsaRename (perf_evlist__exit) to evlist__exit(), so we don't have a name clash when we add (perf_evlist__exit) in libperf.
--- 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(-)
tools/perf/util/evlist.c +2 -2
@@ -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); }
tools/perf/util/evlist.h +1 -1
@@ -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);
tools/perf/util/python.c +1 -1
@@ -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); }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 8/73 perf tools: Rename perf_evlist__purge() to evlist__purge()
In reply to Jiri OlsaRename (perf_evlist__purge) to evlist__purge(), so we don't have a name clash when we add (perf_evlist__purge) in libperf.
--- tools/perf/util/evlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +2 -2
@@ -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); }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 9/73 libperf: Link libapi.a in libperf.so
In reply to Jiri OlsaLinking libapi.a in libperf.so, because we are about to use some of the api functions in it.
--- tools/perf/lib/Makefile | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
tools/perf/lib/Makefile +30 -3
@@ -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
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 10/73 libperf: Add perf_mmap struct
In reply to Jiri OlsaAdd 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.
--- 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
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -93,7 +93,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeCHECK__ (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 ) {
tools/perf/arch/x86/util/intel-bts.c +1 -1
@@ -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) {
tools/perf/arch/x86/util/intel-pt.c +1 -1
@@ -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) {
tools/perf/builtin-record.c +7 -7
@@ -258,7 +258,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t sizestruct 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 ; }
tools/perf/lib/include/internal/mmap.h new file +19 -0
@@ -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 */
tools/perf/util/mmap.c +11 -11
@@ -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 ;
tools/perf/util/mmap.h +4 -3
@@ -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);
Signature · 1 line
2.21.0
Re: [PATCH 10/73] libperf: Add perf_mmap struct
Em Fri, Sep 13, 2019 at 03:22:52PM +0200, Jiri Olsa escreveu:
Quoted 15 lines
Add the
perf_mmapto libperf.The definition is added into:
include/internal/mmap.hwhich is not to be included by users, but shared
within perf and libperf.tools/perf/lib/include/internal/mmap.h new file +0
-0
tools/perf/lib/include/internal/mmap.h line 8
Quoted 8 lines
tools/perf/lib/include/internal/mmap.h new file +8
-0@@ -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
Quoted 126 lines
tools/perf/lib/include/internal/mmap.h new file +10
-0+/** +* 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 */ tools/perf/util/mmap.c +11
-11@@ -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 ;tools/perf/util/mmap.h +4
-3@@ -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);Signature · 1 line
2.21.0
Signature · 1 line
- Arnaldo
Re: [PATCH 10/73] libperf: Add perf_mmap struct
Quoted 19 lines · Arnaldo Carvalho de Melo
Em Fri, Sep 13, 2019 at 03:22:52PM +0200, Jiri Olsa escreveu:
Quoted 18 lines
Add the
perf_mmapto libperf.The definition is added into:
include/internal/mmap.hwhich is not to be included by users, but shared
within perf and libperf.tools/perf/lib/include/internal/mmap.h new file +3
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_MMAP_H +#define __LIBPERF_INTERNAL_MMAP_H
Quoted 8 lines
tools/perf/lib/include/internal/mmap.h line 8
Quoted 5 lines
tools/perf/lib/include/internal/mmap.h new file +5
-0+ +#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
Quoted 2 lines
not necessary at this point in the series, I'm removing them and adding as they become necessary.
ok, thanks
jirka
Jiri Olsa
reviewerPATCH 11/73 libperf: Add mask to struct perf_mmap
In reply to Jiri OlsaMove mask from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -14,6 +14,7 @@*/ struct perf_mmap {void *base; +int mask; };#endif /* __LIBPERF_INTERNAL_MMAP_H */
tools/perf/util/mmap.c +12 -12
@@ -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;
tools/perf/util/mmap.h +0 -1
@@ -22,7 +22,6 @@ struct aiocb;*/ struct mmap {struct perf_mmap core; -int mask;int fd;int cpu;refcount_t refcnt;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 12/73 libperf: Add fd to struct perf_mmap
In reply to Jiri OlsaMove fd from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -15,6 +15,7 @@struct perf_mmap {void *base;int mask; +int fd; };#endif /* __LIBPERF_INTERNAL_MMAP_H */
tools/perf/util/evlist.c +2 -2
@@ -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
tools/perf/util/mmap.c +2 -2
@@ -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);
tools/perf/util/mmap.h +0 -1
@@ -22,7 +22,6 @@ struct aiocb;*/ struct mmap {struct perf_mmap core; -int fd;int cpu;refcount_t refcnt;u64 prev;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 13/73 libperf: Add cpu to struct perf_mmap
In reply to Jiri OlsaMove cpu from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -16,6 +16,7 @@ struct perf_mmap {void *base;int mask;int fd; + int cpu; };#endif /* __LIBPERF_INTERNAL_MMAP_H */
tools/perf/util/mmap.c +4 -4
@@ -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);
tools/perf/util/mmap.h +0 -1
@@ -22,7 +22,6 @@ struct aiocb;*/ struct mmap {struct perf_mmap core; -int cpu;refcount_t refcnt;u64 prev;u64 start;
tools/perf/util/python.c +1 -1
@@ -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; }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 14/73 libperf: Add refcnt to struct perf_mmap
In reply to Jiri OlsaMove refcnt from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -17,6 +17,7 @@ struct perf_mmap {int mask;int fd;int cpu; + refcount_t refcnt; };#endif /* __LIBPERF_INTERNAL_MMAP_H */
tools/perf/util/evlist.c +1 -1
@@ -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; }
tools/perf/util/mmap.c +9 -9
@@ -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);
tools/perf/util/mmap.h +0 -1
@@ -22,7 +22,6 @@ struct aiocb;*/ struct mmap {struct perf_mmap core; -refcount_t refcnt;u64 prev;u64 start;u64 end;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 15/73 libperf: Add prev/start/end to struct perf_mmap
In reply to Jiri OlsaMove prev/start/end from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +3 -0
@@ -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 */
tools/perf/util/mmap.c +25 -25
128 lines not on this page · raw message
tools/perf/util/mmap.h +0 -3
@@ -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) ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 16/73 libperf: Add overwrite to struct perf_mmap
In reply to Jiri OlsaMove overwrite from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -21,6 +21,7 @@ struct perf_mmap {u64 prev;u64 start;u64 end; + bool overwrite; };#endif /* __LIBPERF_INTERNAL_MMAP_H */
tools/perf/util/evlist.c +1 -1
@@ -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
tools/perf/util/mmap.c +6 -6
@@ -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;
tools/perf/util/mmap.h +0 -1
@@ -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
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 17/73 libperf: Add event_copy to struct perf_mmap
In reply to Jiri OlsaMove event_copy from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +4 -0
@@ -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 */
tools/perf/util/mmap.c +2 -2
@@ -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;
tools/perf/util/mmap.h +0 -1
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 18/73 libperf: Add flush to struct perf_mmap
In reply to Jiri OlsaMove flush from tools/perf's mmap to libperf's perf_mmap struct.
--- 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(-)
tools/perf/builtin-record.c +5 -5
@@ -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 &&
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -25,6 +25,7 @@ struct perf_mmap {u64 start;u64 end;bool overwrite; +u64 flush;char event_copy[PERF_SAMPLE_MAX_SIZE ]__aligned(8) ; };
tools/perf/util/mmap.c +2 -2
@@ -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;
tools/perf/util/mmap.h +0 -1
@@ -32,7 +32,6 @@ struct mmap { } aio;#endif cpu_set_t affinity_mask; -u64 flush;void *data;int comp_level; };
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 19/73 libperf: Move system_wide from struct evsel to struct perf_evsel
In reply to Jiri OlsaMove the system_wide member from perf's evsel to libperf's perf_evsel.
--- 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(-)
tools/perf/arch/x86/util/intel-pt.c +2 -2
@@ -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;
tools/perf/builtin-script.c +1 -1
@@ -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) {
tools/perf/builtin-stat.c +2 -2
@@ -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 ; }
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -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);
tools/perf/tests/switch-tracking.c +3 -3
@@ -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;
tools/perf/util/evlist.c +5 -5
@@ -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 ;
tools/perf/util/evsel.c +4 -4
@@ -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);
tools/perf/util/evsel.h +0 -1
@@ -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;
tools/perf/util/parse-events.c +1 -1
@@ -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)
tools/perf/util/stat.c +1 -1
@@ -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++) {
Signature · 1 line
2.21.0
Re: [PATCH 19/73] libperf: Move system_wide from struct evsel to struct perf_evsel
Em Fri, Sep 13, 2019 at 03:23:01PM +0200, Jiri Olsa escreveu:
tools/perf/lib/include/internal/evsel.h struct perf_evsel { · line 22
Quoted 10 lines
tools/perf/lib/include/internal/evsel.h +1
-0@@ -18,6 +18,7 @@ struct perf_evsel {/* parse modifier helper */ int nr_members; +bool system_wide; };
Forgot to add:
#include <stdbool.h>
Added.
- Arnaldo
Jiri Olsa
reviewerPATCH 20/73 libperf: Move nr_mmaps from struct evlist to struct perf_evlist
In reply to Jiri OlsaMoving nr_mmaps from struct evlist to struct perf_evlist, it will be used in following patches.
--- 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(-)
tools/perf/arch/arm/util/cs-etm.c +1 -1
@@ -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 */
tools/perf/arch/arm64/util/arm-spe.c +1 -1
@@ -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 ;
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -115,7 +115,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeevlist__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 ;
tools/perf/arch/x86/util/intel-bts.c +1 -1
@@ -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;
tools/perf/arch/x86/util/intel-pt.c +1 -1
@@ -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;
tools/perf/builtin-kvm.c +1 -1
@@ -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 ;
tools/perf/builtin-record.c +3 -3
@@ -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];
tools/perf/builtin-top.c +1 -1
@@ -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) {
tools/perf/builtin-trace.c +1 -1
@@ -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;
tools/perf/lib/include/internal/evlist.h +1 -0
@@ -13,6 +13,7 @@ struct perf_evlist {bool has_user_cpus;struct perf_cpu_map *cpus;struct perf_thread_map *threads; +int nr_mmaps; };/**
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -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;
tools/perf/tests/bpf.c +1 -1
@@ -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;
tools/perf/tests/code-reading.c +1 -1
@@ -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 ;
tools/perf/tests/keep-tracking.c +1 -1
@@ -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 ;
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -86,7 +86,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestwhile (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;
tools/perf/tests/perf-record.c +1 -1
@@ -164,7 +164,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unuswhile (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;
tools/perf/tests/switch-tracking.c +1 -1
@@ -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 ;
tools/perf/util/evlist.c +8 -8
@@ -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;
tools/perf/util/evlist.h +0 -1
@@ -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;
tools/perf/util/python.c +1 -1
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 21/73 libperf: Move mmap_len from struct evlist to struct perf_evlist
In reply to Jiri OlsaMoving mmap_len from struct evlist to struct perf_evlist it will be used in following patches.
--- 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(-)
tools/perf/builtin-record.c +1 -1
@@ -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) {
tools/perf/lib/include/internal/evlist.h +1 -0
@@ -14,6 +14,7 @@ struct perf_evlist {struct perf_cpu_map *cpus;struct perf_thread_map *threads;int nr_mmaps; +size_t mmap_len; };/**
tools/perf/util/evlist.c +5 -5
@@ -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 :
tools/perf/util/evlist.h +0 -1
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 22/73 libperf: Move pollfd from struct evlist to struct perf_evlist
In reply to Jiri OlsaMoving pollfd from struct evlist to struct perf_evlist it will be used in following patches.
--- 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(-)
tools/perf/builtin-kvm.c +1 -1
@@ -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);
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -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; };/**
tools/perf/util/evlist.c +9 -9
@@ -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);
tools/perf/util/evlist.h +0 -1
@@ -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;
tools/perf/util/python.c +3 -3
@@ -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 )
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 23/73 libperf: Move sample_id from struct evsel to struct perf_evsel
In reply to Jiri OlsaMove sample_id array from struct evsel to libperf's struct perf_evsel.
--- 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(-)
tools/perf/builtin-stat.c +1 -1
@@ -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,
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -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;
tools/perf/util/evlist.c +2 -2
@@ -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 ; }
tools/perf/util/evsel.c +6 -6
@@ -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 ; }
tools/perf/util/evsel.h +0 -1
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 24/73 libperf: Move id from struct evsel to struct perf_evsel
In reply to Jiri OlsaMove id array from struct evsel to libperf's struct perf_evsel.
--- 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(-)
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -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;
tools/perf/util/evlist.c +1 -1
@@ -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,
tools/perf/util/evsel.c +3 -3
@@ -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 ; }
tools/perf/util/evsel.h +0 -1
@@ -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;
tools/perf/util/header.c +10 -10
@@ -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;
tools/perf/util/intel-bts.c +1 -1
@@ -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 ;
tools/perf/util/intel-pt.c +4 -4
@@ -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 ;
tools/perf/util/session.c +1 -1
@@ -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) {
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 25/73 libperf: Move ids from struct evsel to struct perf_evsel
In reply to Jiri OlsaMove ids from struct evsel to libperf's struct perf_evsel.
--- 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(-)
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -17,6 +17,7 @@ struct perf_evsel {struct xyarray *fd;struct xyarray *sample_id;u64 *id; +u32 ids;/* parse modifier helper */ int nr_members;
tools/perf/util/evlist.c +1 -1
@@ -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,
tools/perf/util/evsel.c +1 -1
@@ -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)
tools/perf/util/evsel.h +0 -1
@@ -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;
tools/perf/util/header.c +8 -8
@@ -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" );
tools/perf/util/intel-bts.c +1 -1
@@ -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 ; }
tools/perf/util/intel-pt.c +1 -1
@@ -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; }
tools/perf/util/session.c +2 -2
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 26/73 libperf: Move heads from struct evlist to struct perf_evlist
In reply to Jiri OlsaMove heads hash from struct evlist to struct perf_evlist.
--- 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(-)
tools/perf/lib/evlist.c +4 -0
@@ -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 ; }
tools/perf/lib/include/internal/evlist.h +4 -0
@@ -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 ]; };/**
tools/perf/util/evlist.c +3 -7
@@ -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)
tools/perf/util/evlist.h +0 -4
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 27/73 libperf: Add perf_evsel__alloc_id/perf_evsel__free_id functions
In reply to Jiri OlsaAdding 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.
--- 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(-)
tools/perf/lib/evsel.c +30 -0
@@ -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 ; +}
tools/perf/lib/include/internal/evsel.h +27 -0
@@ -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 */
tools/perf/tests/event_update.c +1 -1
@@ -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 );
tools/perf/util/evlist.c +5 -5
@@ -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 ; }
tools/perf/util/evsel.c +3 -33
@@ -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);
tools/perf/util/evsel.h +0 -25
@@ -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,
tools/perf/util/header.c +2 -2
@@ -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++) {
tools/perf/util/session.c +3 -1
@@ -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,
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 28/73 libperf: Add perf_evlist__first/last functions
In reply to Jiri OlsaAdding perf_evlist__first/last functions to libperf, as internal functions and renaming perf's origins to evlist__first/last.
--- 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(-)
tools/perf/arch/arm/util/cs-etm.c +1 -1
@@ -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 ;
tools/perf/arch/arm64/util/arm-spe.c +1 -1
@@ -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 ;
tools/perf/arch/x86/tests/intel-cqm.c +2 -2
@@ -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; }
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -83,7 +83,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeperf_evlist__config (evlist, &opts,NULL ); - evsel =perf_evlist__first (evlist); + evsel =evlist__first (evlist); evsel->core.attr.comm =1 ; evsel->core.attr.disabled =1 ;
tools/perf/arch/x86/util/intel-bts.c +1 -1
@@ -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);
tools/perf/arch/x86/util/intel-pt.c +3 -3
@@ -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);
tools/perf/builtin-record.c +2 -2
@@ -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 ; }
tools/perf/builtin-script.c +1 -1
@@ -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) {
tools/perf/builtin-top.c +5 -5
@@ -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;
tools/perf/builtin-trace.c +1 -1
@@ -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
tools/perf/lib/include/internal/evlist.h +11 -0
@@ -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 */
tools/perf/tests/code-reading.c +1 -1
@@ -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 ;
tools/perf/tests/event-times.c +7 -7
@@ -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 ;
tools/perf/tests/event_update.c +1 -1
@@ -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 ));
tools/perf/tests/evsel-roundtrip-name.c +1 -1
@@ -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++) {
tools/perf/tests/hists_cumulate.c +1 -1
@@ -721,7 +721,7 @@ int test__hists_cumulate(struct test *test __maybe_unused, int subtest __maybe_uif (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);
tools/perf/tests/hists_link.c +2 -2
@@ -310,8 +310,8 @@ int test__hists_link(struct test *test __maybe_unused, int subtest __maybe_unuseprint_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);
tools/perf/tests/hists_output.c +1 -1
@@ -608,7 +608,7 @@ int test__hists_output(struct test *test __maybe_unused, int subtest __maybe_unuif (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);
tools/perf/tests/keep-tracking.c +2 -2
@@ -93,7 +93,7 @@ int test__keep_tracking(struct test *test __maybe_unused, int subtest __maybe_unperf_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_unevlist__enable (evlist); - evsel =perf_evlist__last (evlist); + evsel =evlist__last (evlist);CHECK__ (evsel__disable (evsel));
tools/perf/tests/parse-events.c +58 -58
464 lines not on this page · raw message
tools/perf/tests/perf-record.c +1 -1
@@ -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 );
tools/perf/tests/switch-tracking.c +7 -7
@@ -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; }
tools/perf/tests/task-exit.c +1 -1
@@ -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 ;
tools/perf/ui/browsers/hists.c +3 -3
@@ -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,
tools/perf/util/bpf-loader.c +1 -1
@@ -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) {
tools/perf/util/evlist.c +12 -12
@@ -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;
tools/perf/util/evlist.h +9 -4
@@ -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);
tools/perf/util/jitdump.c +1 -1
@@ -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 ;
tools/perf/util/parse-events.c +2 -2
@@ -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);
tools/perf/util/record.c +3 -3
@@ -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 );
tools/perf/util/sort.c +1 -1
@@ -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);
tools/perf/util/top.c +1 -1
@@ -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" :"" );
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 29/73 libperf: Add perf_evlist__read_format function
In reply to Jiri OlsaAdding perf_evlist__read_format function to libperf as internal function.
--- 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(-)
tools/perf/lib/evlist.c +7 -0
@@ -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; +}
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -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 */
tools/perf/util/evlist.c +1 -7
@@ -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);
tools/perf/util/evlist.h +0 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 30/73 libperf: Add perf_evlist__id_add function
In reply to Jiri OlsaAdding perf_evlist__id_add function to libperf
as internal function. We already have the heads
member in 'struct perf_evlist'.
--- 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(-)
tools/perf/lib/evlist.c +25 -0
@@ -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; +}
tools/perf/lib/include/internal/evlist.h +4 -0
@@ -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 */
tools/perf/tests/event_update.c +1 -1
@@ -95,7 +95,7 @@ int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unuTEST_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" );
tools/perf/util/evlist.c +1 -21
@@ -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 ; }
tools/perf/util/evlist.h +0 -2
@@ -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);
tools/perf/util/header.c +2 -2
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 31/73 libperf: Add perf_evlist__id_add_fd function
In reply to Jiri OlsaAdding perf_evlist__id_add_fd function to libperf
as internal function.
--- 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(-)
tools/perf/lib/evlist.c +44 -0
@@ -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 ; +}
tools/perf/lib/include/internal/evlist.h +4 -0
@@ -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 */
tools/perf/util/evlist.c +1 -42
55 lines not on this page · raw message
tools/perf/util/evlist.h +0 -4
@@ -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);
tools/perf/util/evsel.c +1 -1
@@ -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 ; }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 32/73 libperf: Move page_size into libperf
In reply to Jiri OlsaWe need page_size in libperf, so moving it in there. Adding libperf_init as a global libperf init functon.
--- 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(-)
tools/perf/lib/core.c +7 -0
@@ -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); +}
tools/perf/lib/include/internal/lib.h +2 -0
@@ -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);
tools/perf/lib/include/perf/core.h +1 -0
@@ -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 */
tools/perf/lib/lib.c +2 -0
@@ -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;
tools/perf/lib/libperf.map +1 -0
@@ -1,5 +1,6 @@ LIBPERF_0.0.1 { global: + libperf_init; libperf_set_print; perf_cpu_map__dummy_new; perf_cpu_map__get;
tools/perf/perf.c +2 -2
@@ -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)
tools/perf/util/util.h +0 -2
@@ -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,
Signature · 1 line
2.21.0
Re: [PATCH 32/73] libperf: Move page_size into libperf
Em Fri, Sep 13, 2019 at 03:23:14PM +0200, Jiri Olsa escreveu:
Quoted 5 lines
We need
page_sizein libperf, so moving it in there. Addinglibperf_initas a global libperf init functon.Signed-off-by Jiri Olsa <[email protected]>
Quoted 8 lines
--- 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
Quoted 110 lines
7 files changed, 15 insertions(+), 4 deletions(-)tools/perf/lib/core.c +7
-0@@ -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); +}tools/perf/lib/include/internal/lib.h +2
-0@@ -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);tools/perf/lib/include/perf/core.h +1
-0@@ -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 */ tools/perf/lib/lib.c +2
-0@@ -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;tools/perf/lib/libperf.map +1
-0@@ -1,5 +1,6 @@ LIBPERF_0.0.1 { global: + libperf_init; libperf_set_print; perf_cpu_map__dummy_new; perf_cpu_map__get;tools/perf/perf.c +2
-2@@ -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)tools/perf/util/util.h +0
-2@@ -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,Signature · 1 line
2.21.0
Signature · 1 line
- Arnaldo
Re: [PATCH 32/73] libperf: Move page_size into libperf
Quoted 15 lines · Arnaldo Carvalho de Melo
Em Fri, Sep 13, 2019 at 03:23:14PM +0200, Jiri Olsa escreveu:
Quoted 5 lines
We need
page_sizein libperf, so moving it in there. Addinglibperf_initas a global libperf init functon.Signed-off-by Jiri Olsa <[email protected]>Quoted 8 lines
--- 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 --
Quoted 3 lines
you forgot to remove it from
tools/perf/util/util.c, I did it, and also addedinternal/lib.hto the places that usepage_size, after this I'll remove that include fromutil/util.h, that header has to die :-)
ah right.. linker wouldn't fail because it's variable, so there's no conflict..
thanks,
jirka
Jiri Olsa
reviewerPATCH 33/73 libperf: Merge libperf_set_print in libperf_init
In reply to Jiri OlsaThe 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.
--- 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(-)
tools/perf/lib/core.c +2 -6
@@ -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; }
tools/perf/lib/include/perf/core.h +1 -2
@@ -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 */
tools/perf/lib/libperf.map +0 -1
@@ -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;
tools/perf/perf.c +7 -1
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 34/73 libperf: Add libperf_init call to tests
In reply to Jiri OlsaAdding libperf_init call to automated tests.
--- 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(+)
tools/perf/lib/tests/test-cpumap.c +8 -0
@@ -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 ;
tools/perf/lib/tests/test-evlist.c +10 -0
@@ -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 ();
tools/perf/lib/tests/test-evsel.c +8 -0
@@ -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 ();
tools/perf/lib/tests/test-threadmap.c +8 -0
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 35/73 libperf: Add libperf dependency for tests targets
In reply to Jiri OlsaAdding libperf dependency for tests targets.
--- tools/perf/lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/lib/Makefile +1 -1
@@ -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
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 36/73 libperf: Add perf_evlist__alloc_pollfd function
In reply to Jiri OlsaMove perf_evlist__alloc_pollfd function under libperf, it will be used in following patches.
--- 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(-)
tools/perf/lib/evlist.c +21 -0
@@ -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 ; +}
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -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
tools/perf/util/evlist.c +1 -22
@@ -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);
tools/perf/util/evlist.h +0 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 37/73 libperf: Add perf_evlist__add_pollfd function
In reply to Jiri OlsaMove 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.
--- 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(-)
tools/perf/builtin-kvm.c +2 -2
@@ -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;
tools/perf/builtin-record.c +1 -1
@@ -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; }
tools/perf/builtin-trace.c +1 -1
@@ -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;
tools/perf/lib/evlist.c +16 -0
@@ -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; +}
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -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
tools/perf/util/evlist.c +4 -21
@@ -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 ; }
tools/perf/util/evlist.h +2 -2
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 38/73 libperf: Add perf_evlist__poll function
In reply to Jiri OlsaMove perf_evlist__poll function under libperf,
it will be used in following patches. And rename
the existing perf's function to evlist__poll.
--- 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(-)
tools/perf/builtin-record.c +1 -1
@@ -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.
tools/perf/builtin-top.c +2 -2
@@ -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);
tools/perf/builtin-trace.c +1 -1
@@ -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;
tools/perf/lib/evlist.c +5 -0
@@ -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); +}
tools/perf/lib/include/perf/evlist.h +1 -0
@@ -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 */
tools/perf/lib/libperf.map +1 -0
@@ -38,6 +38,7 @@ LIBPERF_0.0.1 { perf_evlist__remove; perf_evlist__next; perf_evlist__set_maps; + perf_evlist__poll; local: *; };
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -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__);
tools/perf/tests/perf-record.c +1 -1
@@ -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 ) {
tools/perf/tests/task-exit.c +1 -1
@@ -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; }
tools/perf/util/evlist.c +3 -3
@@ -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];
tools/perf/util/evlist.h +1 -1
@@ -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,
tools/perf/util/python.c +1 -1
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 39/73 libperf: Add perf_mmap__init function
In reply to Jiri OlsaAdding perf_mmap__init function to initialize
'struct perf_mmap' object. Adding it to newmmap.c object, that will carry all the mmap
related functions.
--- 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
tools/perf/lib/Build +1 -0
@@ -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
tools/perf/lib/include/internal/mmap.h +2 -0
@@ -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 */
tools/perf/lib/mmap.c new file +9 -0
@@ -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 ); +}
tools/perf/util/evlist.c +2 -3
@@ -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; }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 40/73 libperf: Add struct perf_mmap_param
In reply to Jiri OlsaAdding 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.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +5 -0
@@ -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 */
tools/perf/util/evlist.c +9 -5
@@ -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);
tools/perf/util/mmap.c +2 -2
@@ -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",
tools/perf/util/mmap.h +2 -1
@@ -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; };
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 41/73 libperf: Add perf_mmap__mmap_len function
In reply to Jiri OlsaMove 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.
--- 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(-)
tools/perf/builtin-record.c +2 -2
@@ -273,7 +273,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t sizeif (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; }
tools/perf/lib/include/internal/mmap.h +2 -0
@@ -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 */
tools/perf/lib/mmap.c +6 -0
@@ -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; +}
tools/perf/util/mmap.c +10 -10
@@ -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",
tools/perf/util/mmap.h +1 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 42/73 libperf: Add perf_mmap__mmap function
In reply to Jiri OlsaMove perf_mmap__mmap function under libperf,
it will be used in following patches. And rename
the existing perf's function to mmap__mmap.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +2 -0
@@ -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 */
tools/perf/lib/mmap.c +18 -0
@@ -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 ; +}
tools/perf/util/evlist.c +1 -1
@@ -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 )
tools/perf/util/mmap.c +3 -9
@@ -352,7 +352,7 @@ static void perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_paramsCPU_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);
tools/perf/util/mmap.h +1 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 43/73 libperf: Add perf_mmap__get function
In reply to Jiri OlsaMove perf_mmap__get function under libperf
to internal header internal/mmap.h.
--- 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(-)
tools/perf/builtin-record.c +1 -1
@@ -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;
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -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 */
tools/perf/lib/mmap.c +5 -0
@@ -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); +}
tools/perf/util/evlist.c +1 -1
@@ -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 ;
tools/perf/util/mmap.c +0 -5
@@ -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 );
tools/perf/util/mmap.h +0 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 44/73 libperf: Add perf_mmap__unmap function
In reply to Jiri OlsaMove 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.
--- 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(-)
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -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 */
tools/perf/lib/mmap.c +10 -0
@@ -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);
tools/perf/util/evlist.c +2 -2
@@ -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)
tools/perf/util/mmap.c +3 -8
@@ -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); }
tools/perf/util/mmap.h +1 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 45/73 libperf: Add perf_mmap__put function
In reply to Jiri OlsaMove 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)--- 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(-)
tools/perf/builtin-record.c +2 -2
@@ -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;
tools/perf/lib/include/internal/mmap.h +19 -12
@@ -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 */
tools/perf/lib/mmap.c +13 -1
@@ -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); +}
tools/perf/util/evlist.c +12 -5
@@ -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 ; }
tools/perf/util/mmap.c +1 -10
@@ -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));
tools/perf/util/mmap.h +0 -2
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 46/73 libperf: Add perf_mmap__new function
In reply to Jiri OlsaAdding perf_mmap__new function to create and
initialize new 'struct perf_mmap' object to
internal header internal/mmap.h
--- tools/perf/lib/include/internal/mmap.h | 2 ++ tools/perf/lib/mmap.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
tools/perf/lib/include/internal/mmap.h +2 -0
@@ -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,
tools/perf/lib/mmap.c +11 -0
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 47/73 perf tools: Use perf_mmap way to detect aux mmap
In reply to Jiri OlsaWe 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.
--- tools/perf/util/mmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/mmap.c +3 -1
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 48/73 libperf: Add perf_mmap__consume function
In reply to Jiri OlsaMove 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.
--- 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
tools/perf/arch/x86/tests/perf-time-to-tsc.c +2 -1
@@ -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); }
tools/perf/builtin-kvm.c +3 -2
@@ -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);
tools/perf/builtin-top.c +2 -1
@@ -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);
tools/perf/builtin-trace.c +2 -1
@@ -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;
tools/perf/lib/Makefile +3 -2
@@ -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)) \
tools/perf/lib/include/internal/mmap.h +2 -0
@@ -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 */
tools/perf/lib/include/perf/mmap.h new file +11 -0
@@ -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 */
tools/perf/lib/libperf.map +1 -0
@@ -39,6 +39,7 @@ LIBPERF_0.0.1 { perf_evlist__next; perf_evlist__set_maps; perf_evlist__poll; + perf_mmap__consume; local: *; };
tools/perf/lib/mmap.c +32 -0
@@ -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); +}
tools/perf/tests/backward-ring-buffer.c +1 -0
@@ -12,6 +12,7 @@#include "parse-events.h" #include <errno.h> #include <linux/string.h> +#include <perf/mmap.h> #define NR_ITERS 111
tools/perf/tests/bpf.c +1 -0
@@ -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"
tools/perf/tests/code-reading.c +2 -1
@@ -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; }
tools/perf/tests/keep-tracking.c +2 -1
@@ -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); }
tools/perf/tests/mmap-basic.c +2 -1
@@ -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);
tools/perf/tests/openat-syscall-tp-fields.c +2 -1
@@ -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 ; }
tools/perf/tests/perf-record.c +2 -1
@@ -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); }
tools/perf/tests/sw-clock.c +2 -1
@@ -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);
tools/perf/tests/switch-tracking.c +2 -1
@@ -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; }
tools/perf/tests/task-exit.c +2 -1
@@ -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_unusedif (event->header.type ==PERF_RECORD_EXIT ) nr_exit++; -perf_mmap__consume (md); +perf_mmap__consume (&md->core); }perf_mmap__read_done (md);
tools/perf/util/evlist.c +2 -1
@@ -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);
tools/perf/util/mmap.c +7 -25
@@ -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); }
tools/perf/util/mmap.h +0 -12
@@ -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);
tools/perf/util/python.c +2 -1
@@ -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,
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 49/73 libperf: Add perf_mmap__read_init function
In reply to Jiri OlsaMove 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.
--- 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(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -118,7 +118,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybefor (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 ) {
tools/perf/builtin-kvm.c +1 -1
@@ -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 ;
tools/perf/builtin-top.c +1 -1
@@ -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 ) {
tools/perf/builtin-trace.c +1 -1
@@ -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 ) {
tools/perf/lib/include/perf/core.h +2 -0
@@ -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,
tools/perf/lib/include/perf/mmap.h +1 -0
@@ -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 */
tools/perf/lib/internal.h +2 -0
@@ -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 */
tools/perf/lib/libperf.map +1 -0
@@ -40,6 +40,7 @@ LIBPERF_0.0.1 { perf_evlist__set_maps; perf_evlist__poll; perf_mmap__consume; + perf_mmap__read_init; local: *; };
tools/perf/lib/mmap.c +84 -0
98 lines not on this page · raw message
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -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;
tools/perf/tests/bpf.c +1 -1
@@ -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 ) {
tools/perf/tests/code-reading.c +1 -1
@@ -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 ) {
tools/perf/tests/keep-tracking.c +1 -1
@@ -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 &&
tools/perf/tests/mmap-basic.c +1 -1
@@ -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 ) {
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -92,7 +92,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subteststruct 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 ) {
tools/perf/tests/perf-record.c +1 -1
@@ -170,7 +170,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unusstruct 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 ) {
tools/perf/tests/sw-clock.c +1 -1
@@ -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 ) {
tools/perf/tests/switch-tracking.c +1 -1
@@ -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 ) {
tools/perf/tests/task-exit.c +1 -1
@@ -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 ) {
tools/perf/util/evlist.c +1 -1
@@ -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);
tools/perf/util/mmap.c +1 -81
94 lines not on this page · raw message
tools/perf/util/mmap.h +0 -1
@@ -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 */
tools/perf/util/python.c +1 -1
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 50/73 libperf: Add perf_mmap__read_done function
In reply to Jiri OlsaMove perf_mmap__read_init function under libperf
and export it in perf/mmap.h header.
--- 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(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -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)
tools/perf/builtin-kvm.c +1 -1
@@ -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; }
tools/perf/builtin-top.c +1 -1
@@ -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)
tools/perf/builtin-trace.c +1 -1
@@ -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) {
tools/perf/lib/include/perf/mmap.h +1 -0
@@ -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 */
tools/perf/lib/libperf.map +1 -0
@@ -41,6 +41,7 @@ LIBPERF_0.0.1 { perf_evlist__poll; perf_mmap__consume; perf_mmap__read_init; + perf_mmap__read_done; local: *; };
tools/perf/lib/mmap.c +17 -0
@@ -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); +}
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -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 ; }
tools/perf/tests/bpf.c +1 -1
@@ -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) {
tools/perf/tests/code-reading.c +1 -1
@@ -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 ; }
tools/perf/tests/keep-tracking.c +1 -1
@@ -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; }
tools/perf/tests/mmap-basic.c +1 -1
@@ -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 ;
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -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)
tools/perf/tests/perf-record.c +1 -1
@@ -278,7 +278,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unusperf_mmap__consume (&md->core); } -perf_mmap__read_done (md); +perf_mmap__read_done (&md->core); }/*
tools/perf/tests/sw-clock.c +1 -1
@@ -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) {
tools/perf/tests/switch-tracking.c +1 -1
@@ -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 ));
tools/perf/tests/task-exit.c +1 -1
@@ -126,7 +126,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedperf_mmap__consume (&md->core); } -perf_mmap__read_done (md); +perf_mmap__read_done (&md->core); out_init:if (!exited || !nr_exit) {
tools/perf/util/evlist.c +1 -1
@@ -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)
tools/perf/util/mmap.c +0 -17
@@ -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); -}
tools/perf/util/mmap.h +0 -1
@@ -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 */
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 51/73 libperf: Add perf_mmap__read_event function
In reply to Jiri OlsaMoving perf_mmap__read_event function into libperf and export it in perf/mmap.h header.
--- 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(-)
tools/perf/arch/x86/tests/perf-time-to-tsc.c +1 -1
@@ -121,7 +121,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybeif (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 ||
tools/perf/builtin-kvm.c +1 -1
@@ -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);
tools/perf/builtin-top.c +1 -1
@@ -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);
tools/perf/builtin-trace.c +1 -1
@@ -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);
tools/perf/lib/include/internal/mmap.h +1 -0
@@ -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);
tools/perf/lib/include/perf/mmap.h +1 -0
@@ -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 */
tools/perf/lib/libperf.map +1 -0
@@ -42,6 +42,7 @@ LIBPERF_0.0.1 { perf_mmap__consume; perf_mmap__read_init; perf_mmap__read_done; + perf_mmap__read_event; local: *; };
tools/perf/lib/mmap.c +79 -0
92 lines not on this page · raw message
tools/perf/tests/backward-ring-buffer.c +1 -1
@@ -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) {
tools/perf/tests/bpf.c +1 -1
@@ -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 )
tools/perf/tests/code-reading.c +1 -1
@@ -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 )
tools/perf/tests/keep-tracking.c +1 -1
@@ -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() &&
tools/perf/tests/mmap-basic.c +1 -1
@@ -117,7 +117,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuseif (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 ) {
tools/perf/tests/openat-syscall-tp-fields.c +1 -1
@@ -95,7 +95,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtestif (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;
tools/perf/tests/perf-record.c +1 -1
@@ -173,7 +173,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unusif (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);
tools/perf/tests/sw-clock.c +1 -1
@@ -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 )
tools/perf/tests/switch-tracking.c +1 -1
@@ -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);
tools/perf/tests/task-exit.c +1 -1
@@ -120,7 +120,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unusedif (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++;
tools/perf/util/evlist.c +1 -1
@@ -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)
tools/perf/util/mmap.c +0 -77
83 lines not on this page · raw message
tools/perf/util/mmap.h +0 -2
@@ -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));
tools/perf/util/python.c +1 -1
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 52/73 libperf: Add perf_evlist__mmap/munmap function
In reply to Jiri OlsaAdding 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.
--- 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(+)
tools/perf/lib/evlist.c +215 -0
@@ -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); +}
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -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);
tools/perf/lib/include/perf/evlist.h +3 -0
@@ -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 */
tools/perf/lib/libperf.map +2 -0
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 53/73 libperf: Add perf_evlist__mmap_ops function
In reply to Jiri OlsaTo 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.
--- tools/perf/lib/evlist.c | 28 +++++++++++++++++------- tools/perf/lib/include/internal/evlist.h | 8 +++++++ 2 files changed, 28 insertions(+), 8 deletions(-)
tools/perf/lib/evlist.c +20 -8
@@ -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)
tools/perf/lib/include/internal/evlist.h +8 -0
@@ -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
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 54/73 libperf: Add perf_evlist_mmap_ops::idx callback
In reply to Jiri OlsaAdding 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.
--- tools/perf/lib/evlist.c | 18 +++++++++++++----- tools/perf/lib/include/internal/evlist.h | 4 ++++ 2 files changed, 17 insertions(+), 5 deletions(-)
tools/perf/lib/evlist.c +13 -5
@@ -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 ;
tools/perf/lib/include/internal/evlist.h +4 -0
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 55/73 libperf: Add perf_evlist_mmap_ops::new callback
In reply to Jiri OlsaAdding 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.
--- tools/perf/lib/evlist.c | 32 +++++++++++++++++------- tools/perf/lib/include/internal/evlist.h | 3 +++ 2 files changed, 26 insertions(+), 9 deletions(-)
tools/perf/lib/evlist.c +23 -9
@@ -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 ;
tools/perf/lib/include/internal/evlist.h +3 -0
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 56/73 libperf: Add perf_evlist_mmap_ops::mmap callback
In reply to Jiri OlsaAdding 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.
--- tools/perf/lib/evlist.c | 15 ++++++++++++--- tools/perf/lib/include/internal/evlist.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-)
tools/perf/lib/evlist.c +12 -3
@@ -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))
tools/perf/lib/include/internal/evlist.h +3 -0
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 57/73 perf tools: Add perf_evlist__mmap_cb_idx function
In reply to Jiri OlsaAdding perf_evlist__mmap_cb_idx function to callauxtrace_mmap_params__set_idx on each new index
during perf_evlist__mmap_ops call.
--- tools/perf/util/evlist.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/perf/util/evlist.c +14 -0
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 58/73 perf tools: Add perf_evlist__mmap_cb_new function
In reply to Jiri OlsaAdding 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.
--- tools/perf/util/evlist.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
tools/perf/util/evlist.c +24 -0
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 59/73 perf tools: Add perf_evlist__mmap_cb_mmap function
In reply to Jiri OlsaAdding perf_evlist__mmap_cb_mmap function to call perf specific mmap__mmap function during perf_evlist__mmap_ops call.
--- tools/perf/util/evlist.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +13 -2
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 60/73 perf tools: Switch to libperf mmap interface
In reply to Jiri OlsaSwitching 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.
--- tools/perf/util/evlist.c | 179 +-------------------------------------- 1 file changed, 4 insertions(+), 175 deletions(-)
tools/perf/util/evlist.c +4 -175
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 61/73 libperf: Move pollfd allocation to libperf
In reply to Jiri OlsaIt's needed in libperf only, moving it toperf_evlist__mmap_ops function.
--- tools/perf/lib/evlist.c | 5 +++++ tools/perf/util/evlist.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-)
tools/perf/lib/evlist.c +5 -0
@@ -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);
tools/perf/util/evlist.c +0 -4
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 62/73 libperf: Add perf_evlist__exit function
In reply to Jiri OlsaAdding 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.
--- 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(-)
tools/perf/lib/evlist.c +12 -3
@@ -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); }
tools/perf/lib/include/internal/evlist.h +2 -0
@@ -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
tools/perf/util/evlist.c +1 -5
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 63/73 libperf: Add perf_evlist__purge function
In reply to Jiri OlsaAdding 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.
--- tools/perf/lib/evlist.c | 13 +++++++++++++ tools/perf/lib/include/internal/evlist.h | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+)
tools/perf/lib/evlist.c +13 -0
@@ -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); }
tools/perf/lib/include/internal/evlist.h +18 -0
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 64/73 libperf: Call perf_evlist__munmap/close on perf_evlist__delete
In reply to Jiri OlsaLet 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.
--- tools/perf/lib/evlist.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/lib/evlist.c +5 -0
@@ -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);
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 65/73 libperf: Add perf_evlist__filter_pollfd function
In reply to Jiri OlsaAdding perf_evlist__filter_pollfd function and exporting it in perf/evlist.h header, so libperf users can check if descriptor is still alive.
--- 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(-)
tools/perf/lib/evlist.c +15 -0
@@ -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);
tools/perf/lib/include/perf/evlist.h +2 -0
@@ -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);
tools/perf/lib/libperf.map +1 -0
@@ -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;
tools/perf/util/evlist.c +1 -11
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 66/73 libperf: Add perf_evlist__for_each_mmap function
In reply to Jiri OlsaAdding 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.
--- 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(+)
tools/perf/lib/evlist.c +13 -0
@@ -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 ]; +}
tools/perf/lib/include/internal/mmap.h +2 -0
@@ -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 */
tools/perf/lib/include/perf/evlist.h +7 -0
@@ -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 */
tools/perf/lib/libperf.map +1 -0
@@ -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;
tools/perf/lib/mmap.c +6 -0
@@ -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; +}
tools/perf/util/evlist.c +1 -0
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 67/73 libperf: Link static tests with libapi.a
In reply to Jiri OlsaBoth static and dynamic tests needs to link libapi.a, because it's using its functions. Adding also include path for libapi includes.
--- tools/perf/lib/Makefile | 1 + tools/perf/lib/tests/Makefile | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/perf/lib/Makefile +1 -0
@@ -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
tools/perf/lib/tests/Makefile +3 -3
@@ -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)
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 68/73 libperf: Add _GNU_SOURCE define to compilation
In reply to Jiri Olsa--- tools/perf/lib/Makefile | 1 + tools/perf/lib/tests/Makefile | 2 ++ 2 files changed, 3 insertions(+)
tools/perf/lib/Makefile +1 -0
@@ -73,6 +73,7 @@ override CFLAGS += -Werror -Wall override CFLAGS += -fPIC override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden +override CFLAGS += -D_GNU_SOURCE all:
tools/perf/lib/tests/Makefile +2 -0
@@ -12,6 +12,8 @@ else CFLAGS := -g -Wall endif +CFLAGS += -D_GNU_SOURCE + all: include $(srctree)/tools/scripts/Makefile.include
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 69/73 libperf: Add tests_mmap_thread test
In reply to Jiri OlsaAdding mmaping tests that generates 100 prctl calls in monitored child process and validates it gets 100 events in ring buffer.
--- tools/perf/lib/tests/test-evlist.c | 119 +++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+)
tools/perf/lib/tests/test-evlist.c +119 -0
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 70/73 libperf: Add tests_mmap_cpus test
In reply to Jiri OlsaAdding mmaping tests that generates prctl call on every cpu validates it gets all the related events in ring buffer.
--- tools/perf/lib/tests/test-evlist.c | 97 ++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
tools/perf/lib/tests/test-evlist.c +97 -0
@@ -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 ;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 71/73 libperf: Keep count of failed tests
In reply to Jiri OlsaKeeping 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
...--- 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(-)
tools/perf/lib/include/internal/tests.h +17 -3
@@ -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)
tools/perf/lib/tests/test-cpumap.c +1 -1
@@ -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 ; }
tools/perf/lib/tests/test-evlist.c +1 -1
@@ -407,6 +407,6 @@ int main(int argc, char **argv)test_mmap_thread ();test_mmap_cpus (); - __T_OK; + __T_END;return 0 ; }
tools/perf/lib/tests/test-evsel.c +1 -1
@@ -128,6 +128,6 @@ int main(int argc, char **argv)test_stat_thread ();test_stat_thread_enable (); - __T_OK; + __T_END;return 0 ; }
tools/perf/lib/tests/test-threadmap.c +1 -1
@@ -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 ; }
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 72/73 libperf: Do not export perf_evsel__init/perf_evlist__init
In reply to Jiri OlsaThere'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.
--- 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(-)
tools/perf/lib/include/internal/evlist.h +1 -0
@@ -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);/**
tools/perf/lib/include/internal/evsel.h +1 -0
@@ -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);
tools/perf/lib/include/perf/evlist.h +0 -1
@@ -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,
tools/perf/lib/include/perf/evsel.h +0 -2
@@ -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,
tools/perf/lib/libperf.map +0 -2
@@ -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;
Signature · 1 line
2.21.0
Jiri Olsa
reviewerPATCH 73/73 libperf: Add pr_err macro
In reply to Jiri OlsaAnd missing include for "perf/core.h" header, which provides LIBPERF_* debug levels and adding missing pr_err support.
--- tools/perf/lib/include/perf/core.h | 1 + tools/perf/lib/internal.h | 3 +++ 2 files changed, 4 insertions(+)
tools/perf/lib/include/perf/core.h +1 -0
@@ -9,6 +9,7 @@#endif enum libperf_print_level { +LIBPERF_ERR ,LIBPERF_WARN ,LIBPERF_INFO ,LIBPERF_DEBUG ,
tools/perf/lib/internal.h +3 -0
@@ -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__)
Signature · 1 line
2.21.0
Quoted 54 lines · Jiri Olsa
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.cto do thread and cpu based sampling.
Quoted 7 lines
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