Skip to contentSkip to conversation

perf scripts: Fix rwtop script

PATCH In review Jiri Olsa 2 participants 6 messages Feb 5, 2013 – Feb 6, 2013 perf events

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover perf scripts: Fix rwtop script

hi,
sending patches for rwtop race issue caused by rwtop script triggering SIGALRM and underneath pipe reading layer reporting error when interrupted.

It's discussed in here:
https://lkml.org/lkml/2012/9/14/381

thanks,
jirka

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Andrew Jones <[email protected]>
Cc David Ahern <[email protected]>

---
Jiri Olsa (2):
perf scripts: Fix SIGALRM and pipe read race for rwtop perf scripts: Fix rwtop record script

 tools/perf/scripts/perl/bin/rwtop-record | 2 +-
 tools/perf/scripts/perl/rwtop.pl         | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
author
#1 lore raw

PATCH 1/2 perf scripts: Fix SIGALRM and pipe read race for rwtop

Fixing rwtop script race. The issue is caused by rwtop script triggering SIGALRM and underneath pipe reading layer reporting error when interrupted.

Fixing this by setting SA_RESTART for rwtop SIGALRM handler, which avoids interruption of the pipe reading layer.

The discussion for this issue & fix is here:
https://lkml.org/lkml/2012/9/18/123

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Andrew Jones <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/perf/scripts/perl/rwtop.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/scripts/perl/rwtop.pl +5 -1
index 4bb3ecd..8b20787 100644
@@ -17,6 +17,7 @@ use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
 use lib "./Perf-Trace-Util/lib";
 use Perf::Trace::Core;
 use Perf::Trace::Util;
+use POSIX qw/SIGALRM SA_RESTART/;
 
 my $default_interval = 3;
 my $nlines = 20;
@@ -90,7 +91,10 @@ sub syscalls::sys_enter_write
 
 sub trace_begin
 {
-    $SIG{ALRM} = \&set_print_pending;
+    my $sa = POSIX::SigAction->new(\&set_print_pending);
+    $sa->flags(SA_RESTART);
+    $sa->safe(1);
+    POSIX::sigaction(SIGALRM, $sa) or die "Can't set SIGALRM handler: $!\n";
     alarm 1;
 }
 
Signature · 1 line
1.7.11.7
#2 lore raw

[tip:perf/core] perf perl scripts: Fix SIGALRM and pipe read race for rwtop

Commit-ID:  b22e79395c0fe4c86dd35745a929366034386ccc
Gitweb:     http://git.kernel.org/tip/b22e79395c0fe4c86dd35745a929366034386ccc
Author:     Jiri Olsa <[email protected]>
AuthorDate: Tue, 5 Feb 2013 17:05:50 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Feb 2013 18:09:27 -0300

perf perl scripts: Fix SIGALRM and pipe read race for rwtop

Fixing rwtop script race. The issue is caused by rwtop script triggering SIGALRM and underneath pipe reading layer reporting error when interrupted.

Fixing this by setting SA_RESTART for rwtop SIGALRM handler, which avoids interruption of the pipe reading layer.

The discussion for this issue & fix is here:
https://lkml.org/lkml/2012/9/18/123

Cc Andrew Jones <[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/scripts/perl/rwtop.pl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/scripts/perl/rwtop.pl +5 -1
index 4bb3ecd..8b20787 100644
@@ -17,6 +17,7 @@ use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
 use lib "./Perf-Trace-Util/lib";
 use Perf::Trace::Core;
 use Perf::Trace::Util;
+use POSIX qw/SIGALRM SA_RESTART/;
 
 my $default_interval = 3;
 my $nlines = 20;
@@ -90,7 +91,10 @@ sub syscalls::sys_enter_write
 
 sub trace_begin
 {
-    $SIG{ALRM} = \&set_print_pending;
+    my $sa = POSIX::SigAction->new(\&set_print_pending);
+    $sa->flags(SA_RESTART);
+    $sa->safe(1);
+    POSIX::sigaction(SIGALRM, $sa) or die "Can't set SIGALRM handler: $!\n";
     alarm 1;
 }
 
author
#3 lore raw

PATCH 2/2 perf scripts: Fix rwtop record script

In reply to Jiri Olsa

Adding -D option into the rwtop record command line, to get immediate response when there's event in the buffer.

Otherwise we need to wait till half of the buffer is filled, which is the default wattermark if it's not set.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Andrew Jones <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/perf/scripts/perl/bin/rwtop-record | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/perl/bin/rwtop-record +1 -1
index 7cb9db2..e4ec090 100644
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
+perf record -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write -D $@
Signature · 1 line
1.7.11.7
#4 lore raw

Re: [PATCH 2/2] perf scripts: Fix rwtop record script

Quoted 2 lines · Jiri Olsa

Adding -D option into the rwtop record command line, to get immediate response when there's event in the buffer.

Seems like this will dramatically increase CPU usage of perf-record as well as increase the overhead of each event with a process wakeup. How about a poll option on perf-record to have it wake up at a given rate instead?

David

author
#5 lore raw

Re: [PATCH 2/2] perf scripts: Fix rwtop record script

Quoted 8 lines · David Ahern
Quoted 2 lines · Jiri Olsa

Adding -D option into the rwtop record command line, to get immediate response when there's event in the buffer.

Seems like this will dramatically increase CPU usage of perf-record as well as increase the overhead of each event with a process wakeup. How about a poll option on perf-record to have it wake up at a given rate instead?

right, I'll check

thanks,
jirka