Skip to content

Commit

Permalink
perf bench: Fix bench/sched-pipe.c to wait for child process
Browse files Browse the repository at this point in the history
Ingo reported this small 'perf bench sched pipe' output problem:

 | $ ./perf bench sched pipe
 | (executing 1000000 pipe operations between two tasks)
 |
 |	Total time:4.898 sec
 | $		4.898586 usecs/op
 |		204140 ops/sec
 |
 | the shell prompt came back before the usecs/op and ops/sec line
 | was printed. Process teardown race, lack of wait() or so?

This caused by lack of calling waitpid() by parent process,
so I added it.

Signed-off-by: Hitoshi Mitake <[email protected]>
Cc: Rusty Russell <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Kosina <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Hitoshi Mitake authored and Ingo Molnar committed Nov 9, 2009
1 parent bfde82e commit 5ff0cfc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/perf/bench/sched-pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <errno.h>
#include <assert.h>
#include <sys/time.h>
#include <sys/types.h>

#define LOOPS_DEFAULT 1000000
static int loops = LOOPS_DEFAULT;
Expand Down Expand Up @@ -58,8 +59,8 @@ int bench_sched_pipe(int argc, const char **argv,
* discarding returned value of read(), write()
* causes error in building environment for perf
*/
int ret;
pid_t pid;
int ret, wait_stat;
pid_t pid, retpid;

argc = parse_options(argc, argv, options,
bench_sched_pipe_usage, 0);
Expand Down Expand Up @@ -87,8 +88,11 @@ int bench_sched_pipe(int argc, const char **argv,
gettimeofday(&stop, NULL);
timersub(&stop, &start, &diff);

if (pid)
if (pid) {
retpid = waitpid(pid, &wait_stat, 0);
assert((retpid == pid) && WIFEXITED(wait_stat));
return 0;
}

if (simple)
printf("%lu.%03lu\n",
Expand Down

0 comments on commit 5ff0cfc

Please sign in to comment.