From 096177a8b51937ba3004164f0366ef20656bb17a Mon Sep 17 00:00:00 2001 From: "Tzvetomir Stoyanov (VMware)" Date: Wed, 8 Aug 2018 14:02:46 -0400 Subject: tools lib traceevent, perf tools: Rename struct pevent to struct tep_handle In order to make libtraceevent into a proper library, variables, data structures and functions require a unique prefix to prevent name space conflicts. That prefix will be "tep_" and not "pevent_". This changes the struct pevent to struct tep_handle. Signed-off-by: Tzvetomir Stoyanov (VMware) Cc: Andrew Morton Cc: Peter Zijlstra Cc: Yordan Karadzhov (VMware) Cc: linux-trace-devel@vger.kernel.org Link: http://lkml.kernel.org/r/20180808180659.706175783@goodmis.org Signed-off-by: Steven Rostedt Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/util/python.c') diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 863b61478edd..fd72cce6599c 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -341,7 +341,7 @@ static bool is_tracepoint(struct pyrf_event *pevent) static PyObject* tracepoint_field(struct pyrf_event *pe, struct format_field *field) { - struct pevent *pevent = field->event->pevent; + struct tep_handle *pevent = field->event->pevent; void *data = pe->sample.raw_data; PyObject *ret = NULL; unsigned long long val; -- cgit From af85cd19521fe956eeb2cc8b9e41b9b5bbb8e3ae Mon Sep 17 00:00:00 2001 From: "Tzvetomir Stoyanov (VMware)" Date: Wed, 8 Aug 2018 14:02:50 -0400 Subject: tools lib traceevent, perf tools: Rename pevent find APIs In order to make libtraceevent into a proper library, variables, data structures and functions require a unique prefix to prevent name space conflicts. That prefix will be "tep_" and not "pevent_". This changes APIs: pevent_find_any_field, pevent_find_common_field, pevent_find_event, pevent_find_field Signed-off-by: Tzvetomir Stoyanov (VMware) Cc: Andrew Morton Cc: Peter Zijlstra Cc: Yordan Karadzhov (VMware) Cc: linux-trace-devel@vger.kernel.org Link: http://lkml.kernel.org/r/20180808180700.316995920@goodmis.org Signed-off-by: Steven Rostedt Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/util/python.c') diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index fd72cce6599c..ff01cd53eddd 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -394,7 +394,7 @@ get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name) evsel->tp_format = tp_format; } - field = pevent_find_any_field(evsel->tp_format, str); + field = tep_find_any_field(evsel->tp_format, str); if (!field) return NULL; -- cgit From 59c1baee25e2b34f8e26a923ea229b3e00cab55a Mon Sep 17 00:00:00 2001 From: "Tzvetomir Stoyanov (VMware)" Date: Wed, 8 Aug 2018 14:02:53 -0400 Subject: tools lib traceevent, perf tools: Rename pevent_read_number_* APIs In order to make libtraceevent into a proper library, variables, data structures and functions require a unique prefix to prevent name space conflicts. That prefix will be "tep_" and not "pevent_". This changes APIs: pevent_read_number, pevent_read_number_field Signed-off-by: Tzvetomir Stoyanov (VMware) Cc: Andrew Morton Cc: Peter Zijlstra Cc: Yordan Karadzhov (VMware) Cc: linux-trace-devel@vger.kernel.org Link: http://lkml.kernel.org/r/20180808180700.804271434@goodmis.org Signed-off-by: Steven Rostedt Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/perf/util/python.c') diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index ff01cd53eddd..f74fbb652a4f 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -351,7 +351,7 @@ tracepoint_field(struct pyrf_event *pe, struct format_field *field) offset = field->offset; len = field->size; if (field->flags & FIELD_IS_DYNAMIC) { - val = pevent_read_number(pevent, data + offset, len); + val = tep_read_number(pevent, data + offset, len); offset = val; len = offset >> 16; offset &= 0xffff; @@ -364,8 +364,8 @@ tracepoint_field(struct pyrf_event *pe, struct format_field *field) field->flags &= ~FIELD_IS_STRING; } } else { - val = pevent_read_number(pevent, data + field->offset, - field->size); + val = tep_read_number(pevent, data + field->offset, + field->size); if (field->flags & FIELD_IS_POINTER) ret = PyLong_FromUnsignedLong((unsigned long) val); else if (field->flags & FIELD_IS_SIGNED) -- cgit From 721f0dfc3ce821c6a32820ab63edfb48ed4af075 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Fri, 17 Aug 2018 13:45:56 +0200 Subject: perf python: Fix pyrf_evlist__read_on_cpu() interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jaroslav reported errors from valgrind over perf python script: # echo 0 > /sys/devices/system/cpu/cpu4/online # valgrind ./test.py ==7524== Memcheck, a memory error detector ... ==7524== Command: ./test.py ==7524== pid 7526 exited ==7524== Invalid read of size 8 ==7524== at 0xCC2C2B3: perf_mmap__read_forward (evlist.c:780) ==7524== by 0xCC2A681: pyrf_evlist__read_on_cpu (python.c:959) ... ==7524== Address 0x65c4868 is 16 bytes after a block of size 459,36.. ==7524== at 0x4C2B955: calloc (vg_replace_malloc.c:711) ==7524== by 0xCC2F484: zalloc (util.h:35) ==7524== by 0xCC2F484: perf_evlist__alloc_mmap (evlist.c:978) ... The reason for this is in the python interface, that allows a script to pass arbitrary cpu number, which is then used to access struct perf_evlist::mmap array. That's obviously wrong and works only when if all cpus are available and fails if some cpu is missing, like in the example above. This patch makes pyrf_evlist__read_on_cpu() search the evlist's maps array for the proper map to access. It's linear search at the moment. Based on the way how is the read_on_cpu used, I don't think we need to be fast in here. But we could add some hash in the middle to make it fast/er. We don't allow python interface to set write_backward event attribute, so it's safe to check only evlist's mmaps. Reported-by: Jaroslav Škarvada Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: David Ahern Cc: Joe Mario Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20180817114556.28000-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/python.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tools/perf/util/python.c') diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f74fbb652a4f..ce501ba14b08 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -11,6 +11,7 @@ #include "cpumap.h" #include "print_binary.h" #include "thread_map.h" +#include "mmap.h" #if PY_MAJOR_VERSION < 3 #define _PyUnicode_FromString(arg) \ @@ -976,6 +977,20 @@ static PyObject *pyrf_evlist__add(struct pyrf_evlist *pevlist, return Py_BuildValue("i", evlist->nr_entries); } +static struct perf_mmap *get_md(struct perf_evlist *evlist, int cpu) +{ + int i; + + for (i = 0; i < evlist->nr_mmaps; i++) { + struct perf_mmap *md = &evlist->mmap[i]; + + if (md->cpu == cpu) + return md; + } + + return NULL; +} + static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { @@ -990,7 +1005,10 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, &cpu, &sample_id_all)) return NULL; - md = &evlist->mmap[cpu]; + md = get_md(evlist, cpu); + if (!md) + return NULL; + if (perf_mmap__read_init(md) < 0) goto end; -- cgit