Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8968e65 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

perf python: Fix pyrf_evlist__read_on_cpu event consuming



We can't consume the event before parsing it. Under heavy load we could
get caught by kernel writer overwriting the event we're trying to parse.

Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1468148882-10362-5-git-send-email-jolsa@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ad4e3c04
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -865,12 +865,14 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
		PyObject *pyevent = pyrf_event__new(event);
		PyObject *pyevent = pyrf_event__new(event);
		struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
		struct pyrf_event *pevent = (struct pyrf_event *)pyevent;


		perf_evlist__mmap_consume(evlist, cpu);

		if (pyevent == NULL)
		if (pyevent == NULL)
			return PyErr_NoMemory();
			return PyErr_NoMemory();


		err = perf_evlist__parse_sample(evlist, event, &pevent->sample);
		err = perf_evlist__parse_sample(evlist, event, &pevent->sample);

		/* Consume the even only after we parsed it out. */
		perf_evlist__mmap_consume(evlist, cpu);

		if (err)
		if (err)
			return PyErr_Format(PyExc_OSError,
			return PyErr_Format(PyExc_OSError,
					    "perf: can't parse sample, err=%d", err);
					    "perf: can't parse sample, err=%d", err);