diff options
author | Ciprian Barbu <ciprian.barbu@linaro.org> | 2013-12-12 16:47:19 +0200 |
---|---|---|
committer | Clark Williams <clark.williams@gmail.com> | 2013-12-12 09:13:12 -0600 |
commit | 3917fdbe56a8e8716f3d1ba93806083e598d3e49 (patch) | |
tree | 8908f839b8ece0ab115951c02d787a9d30a1d794 | |
parent | b0413ae5ed802004fb0c4af74a1757381fd2b91f (diff) | |
download | rt-tests-3917fdbe56a8e8716f3d1ba93806083e598d3e49.tar.gz |
rt-tests: hackbench: fix for uninitialized start time
Hello,
While playing around with hackbench I discovered that I would sometimes
get an enormous time reported, even if the run time would be less than a
second or so. The problem was that the struct timeval start was not
initialized until after all children have been created. But if the
program receives a signal before this is done, the start time is left
uninitialized.
I propose that in such situations an error message be displayed, like
the following patch does.
Please let me know if this is acceptable.
Regards,
/Ciprian
Signed-off-by: Clark Williams <williams@redhat.com>
-rw-r--r-- | src/hackbench/hackbench.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/hackbench/hackbench.c b/src/hackbench/hackbench.c index c21b4db..34a27ef 100644 --- a/src/hackbench/hackbench.c +++ b/src/hackbench/hackbench.c @@ -443,6 +443,7 @@ int main(int argc, char *argv[]) struct timeval start, stop, diff; int readyfds[2], wakefds[2]; char dummy; + int timer_started = 0; struct sched_param sp; process_options (argc, argv); @@ -489,9 +490,10 @@ int main(int argc, char *argv[]) reap_workers(child_tab, total_children, 1); barf("Reading for readyfds"); } - + gettimeofday(&start, NULL); - + timer_started = 1; + /* Kick them off */ if (write(wakefds[1], &dummy, 1) != 1) { reap_workers(child_tab, total_children, 1); @@ -510,8 +512,12 @@ int main(int argc, char *argv[]) gettimeofday(&stop, NULL); /* Print time... */ - timersub(&stop, &start, &diff); - printf("Time: %lu.%03lu\n", diff.tv_sec, diff.tv_usec/1000); + if (timer_started) { + timersub(&stop, &start, &diff); + printf("Time: %lu.%03lu\n", diff.tv_sec, diff.tv_usec/1000); + } + else + fprintf(stderr, "No measurements available\n"); free(child_tab); exit(0); } |