Skip to contentSkip to conversation

Fix perf-tool crashes when kvm guest is running

PATCH Superseded Joerg Roedel 2 participants 6 messages Feb 9, 2012 – Feb 10, 2012 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix perf-tool crashes when kvm guest is running

Hi,

here are the fixes I promised. These patches should fix the crashes David and Jason have seen by making sure no sample is processed when ther is no valid machine object for it. The second patch also changes the perf_guest default back to false.

Regards,

Joerg

#1 lore raw

PATCH 1/2 perf-tool: Don't process samples with no valid machine object

The perf sample processing code relies on a valid machine object. Make sure that this path is only entered when such a object exists.

---
 tools/perf/builtin-top.c  |    2 +-
 tools/perf/util/session.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +1 -1
index dd162aa..7c81d1d 100644
@@ -805,7 +805,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
 		}
 
 
-		if (event->header.type == PERF_RECORD_SAMPLE) {
+		if (event->header.type == PERF_RECORD_SAMPLE && machine != NULL) {
 			perf_event__process_sample(&top->tool, event, evsel,
 						   &sample, machine);
 		} else if (event->header.type < PERF_RECORD_MAX) {
tools/perf/util/session.c +1 -1
index b5ca2558..c9593c7 100644
@@ -792,7 +792,7 @@ static int perf_session_deliver_event(struct perf_session *session,
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
 		dump_sample(session, event, sample);
-		if (evsel == NULL) {
+		if (evsel == NULL || machine == NULL) {
 			++session->hists.stats.nr_unknown_id;
 			return -1;
 		}
Signature · 1 line
1.7.5.4
#2 lore raw

Re: [PATCH 1/2] perf-tool: Don't process samples with no valid machine object

Em Thu, Feb 09, 2012 at 05:07:38PM +0100, Joerg Roedel escreveu:

Quoted 15 lines

The perf sample processing code relies on a valid machine object. Make sure that this path is only entered when such a object exists.

---
 tools/perf/builtin-top.c  |    2 +-
 tools/perf/util/session.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +0 -0
index dd162aa..7c81d1d 100644

tools/perf/builtin-top.c static void perf_top__mmap_read_idx(struct perf_top *top, int idx) · line 808

Quoted 5 lines
tools/perf/builtin-top.c +1 -1
@@ -805,7 +805,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
 		}
 
 
-		if (event->header.type == PERF_RECORD_SAMPLE) {
+		if (event->header.type == PERF_RECORD_SAMPLE && machine != NULL) {

Shouldn't we warn the user, even if just once, on the status (last line on the screen) line?

Quoted 19 lines
tools/perf/builtin-top.c +0 -0
 			perf_event__process_sample(&top->tool, event, evsel,
 						   &sample, machine);
 		} else if (event->header.type < PERF_RECORD_MAX) {
tools/perf/util/session.c +1 -1
index b5ca2558..c9593c7 100644
@@ -792,7 +792,7 @@ static int perf_session_deliver_event(struct perf_session *session,
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
 		dump_sample(session, event, sample);
-		if (evsel == NULL) {
+		if (evsel == NULL || machine == NULL) {
 			++session->hists.stats.nr_unknown_id;
 			return -1;
 		}
Signature · 1 line
1.7.5.4
#3 lore raw

Re: [PATCH 1/2] perf-tool: Don't process samples with no valid machine object

Quoted 6 lines · Arnaldo Carvalho de Melo

Em Thu, Feb 09, 2012 at 05:07:38PM +0100, Joerg Roedel escreveu:

tools/perf/builtin-top.c static void perf_top__mmap_read_idx(struct perf_top *top, int idx) · line 808

Quoted 2 lines
tools/perf/builtin-top.c +1 -1
-		if (event->header.type == PERF_RECORD_SAMPLE) {
+		if (event->header.type == PERF_RECORD_SAMPLE && machine != NULL) {

Shouldn't we warn the user, even if just once, on the status (last line on the screen) line?

Probably yes, what would be a good message? I guess something like

"no machine object for sample"

is not helpful to the user. Maybe something like

"Unresolvable sample(s) recorded"?

Or something completly different?

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
#4 lore raw

Re: [PATCH 1/2] perf-tool: Don't process samples with no valid machine object

Em Thu, Feb 09, 2012 at 06:13:34PM +0100, Joerg Roedel escreveu:

Quoted 10 lines · Arnaldo Carvalho de Melo
Quoted 6 lines

Em Thu, Feb 09, 2012 at 05:07:38PM +0100, Joerg Roedel escreveu:

tools/perf/builtin-top.c static void perf_top__mmap_read_idx(struct perf_top *top, int idx) · line 808

Quoted 2 lines
tools/perf/builtin-top.c +1 -1
-		if (event->header.type == PERF_RECORD_SAMPLE) {
+		if (event->header.type == PERF_RECORD_SAMPLE && machine != NULL) {

Shouldn't we warn the user, even if just once, on the status (last line on the screen) line?

Probably yes, what would be a good message? I guess something like

Quoted 7 lines

"no machine object for sample"

is not helpful to the user. Maybe something like

"Unresolvable sample(s) recorded"?

Or something completly different?

This is not completely standardized or harminized across the sources, but we have things like:

	if (verbose)
		error("Failed to resolve callchain.  Skipping\n");

---

        if (perf_event__preprocess_sample(event, machine, &al, sample,
                                          NULL) < 0) {
                error("problem processing %d event, skipping it.\n",
                        event->header.type);
                return;
        }

---

       if (!ip_callchain__valid(sample->callchain, event)) {
                pr_debug("call-chain problem with event, skipping it.\n");
                ++session->hists.stats.nr_invalid_chains;

---

What has been done more recently is like the above, account the
number of different problems and then, at the end do like:

        if (session->hists.stats.nr_unknown_id != 0) {
                ui__warning("%u samples with id not present in the header\n",
                            session->hists.stats.nr_unknown_id);
        }


	But this is for perf report or other tools that process all

events and then provide some post processed results, just before presenting these results.

I guess we could do that too for 'perf top' like tools, that
continuously show results while collecting more. Perhaps call ui__warning() if some threshold happens, i.e. if way too many errors of some kind are happening and then at the end provide a summary of errors found.

- Arnaldo

#5 lore raw

PATCH 2/2 perf-tool: Change perf_guest default back to false

In reply to Joerg Roedel

Setting perf_guest to true by default makes no sense because the perf subcommands can not setup guest symbol information and thus not process and guest samples. The only exception is perf-kvm which changes the perf_guest value on its own. So change the default for perf_guest back to false.

---
 tools/perf/util/util.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/util.c +1 -1
index 8131410..fb25d13 100644
@@ -6,7 +6,7 @@
  * XXX We need to find a better place for these things...
  */
 bool perf_host  = true;
-bool perf_guest = true;
+bool perf_guest = false;
 
 void event_attr_init(struct perf_event_attr *attr)
 {
Signature · 1 line
1.7.5.4