perf scripts: Fix rwtop script
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
---
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(-)
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
--- tools/perf/scripts/perl/rwtop.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/scripts/perl/rwtop.pl +5 -1
@@ -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
[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
--- tools/perf/scripts/perl/rwtop.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/scripts/perl/rwtop.pl +5 -1
@@ -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; }
PATCH 2/2 perf scripts: Fix rwtop record script
In reply to Jiri OlsaAdding -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.
--- tools/perf/scripts/perl/bin/rwtop-record | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/perl/bin/rwtop-record +1 -1
@@ -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
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
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