Skip to contentSkip to conversation

perf record: Fix poll return value propagation

PATCH In review Jiri Olsa 4 participants 4 messages Jun 2, 2014 – Jun 5, 2014 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 perf record: Fix poll return value propagation

If the perf record command is interrupted in record__mmap_read_all function, the 'done' is set and err has the latest poll return value, which is most likely positive number (= number of pollfds ready to read).

This 'positive err' is then propagated to the exit code, resulting in not finishing the perf.data header properly, causing following error in report:

  # perf record -F 50000 -a

---
make the system real busy, so there's more chance to interrupt perf in event writing code
---

^C[ perf record: Woken up 16 times to write data ]
[ perf record: Captured and wrote 30.292 MB perf.data (~1323468 samples) ]

  # perf report --stdio > /dev/null
  WARNING: The perf.data file's data size field is 0 which is unexpected.
  Was the 'perf record' command properly terminated?

Fixing this by checking for positive poll return value and setting err to 0.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-record.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +5 -1
index e4c85b8..ce2cfec 100644
@@ -454,7 +454,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 			if (done)
 				break;
 			err = poll(rec->evlist->pollfd, rec->evlist->nr_fds, -1);
-			if (err < 0 && errno == EINTR)
+			/*
+			 * Propagate error, only if there's any. Ignore positive
+			 * number of returned events and interrupt error.
+			 */
+			if (err > 0 || (err < 0 && errno == EINTR))
 				err = 0;
 			waking++;
 		}
Signature · 1 line
1.8.3.1
maintainer Acked-by on v1 1/1
#1 lore raw

Em Mon, Jun 02, 2014 at 08:02:06PM +0200, Jiri Olsa escreveu:

Quoted 10 lines

If the perf record command is interrupted in record__mmap_read_all function, the 'done' is set and err has the latest poll return value, which is most likely positive number (= number of pollfds ready to read).

This 'positive err' is then propagated to the exit code, resulting in not finishing the perf.data header properly, causing following error in report:

  # perf record -F 50000 -a
Acked-by on v1 1/1
#2 lore raw
In reply to Jiri Olsa
Quoted 19 lines · Jiri Olsa

If the perf record command is interrupted in record__mmap_read_all function, the 'done' is set and err has the latest poll return value, which is most likely positive number (= number of pollfds ready to read).

This 'positive err' is then propagated to the exit code, resulting in not finishing the perf.data header properly, causing following error in report:

  # perf record -F 50000 -a

---
make the system real busy, so there's more chance to interrupt perf in event writing code
---

^C[ perf record: Woken up 16 times to write data ]
[ perf record: Captured and wrote 30.292 MB perf.data (~1323468 samples) ]

Quoted 6 lines
  # perf report --stdio > /dev/null
  WARNING: The perf.data file's data size field is 0 which is unexpected.
  Was the 'perf record' command properly terminated?

Fixing this by checking for positive poll return value and setting err to 0.

Thanks,
Namhyung

#3 lore raw
In reply to Jiri Olsa
perf record: Fix poll return value propagation
Commit-ID:  a515114fa3cff8f1da10cd68914d55c10879c3e0
Gitweb:     http://git.kernel.org/tip/a515114fa3cff8f1da10cd68914d55c10879c3e0
Author:     Jiri Olsa <[email protected]>
AuthorDate: Mon, 2 Jun 2014 13:44:23 -0400
Committer:  Jiri Olsa <[email protected]>
CommitDate: Tue, 3 Jun 2014 21:35:05 +0200

perf record: Fix poll return value propagation

If the perf record command is interrupted in record__mmap_read_all function, the 'done' is set and err has the latest poll return value, which is most likely positive number (= number of pollfds ready to read).

This 'positive err' is then propagated to the exit code, resulting in not finishing the perf.data header properly, causing following error in report:

  # perf record -F 50000 -a

---
make the system real busy, so there's more chance to interrupt perf in event writing code
---

^C[ perf record: Woken up 16 times to write data ]
[ perf record: Captured and wrote 30.292 MB perf.data (~1323468 samples) ]

  # perf report --stdio > /dev/null
  WARNING: The perf.data file's data size field is 0 which is unexpected.
  Was the 'perf record' command properly terminated?

Fixing this by checking for positive poll return value and setting err to 0.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-record.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +5 -1
index e4c85b8..ce2cfec 100644
@@ -454,7 +454,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 			if (done)
 				break;
 			err = poll(rec->evlist->pollfd, rec->evlist->nr_fds, -1);
-			if (err < 0 && errno == EINTR)
+			/*
+			 * Propagate error, only if there's any. Ignore positive
+			 * number of returned events and interrupt error.
+			 */
+			if (err > 0 || (err < 0 && errno == EINTR))
 				err = 0;
 			waking++;
 		}