[pypy-commit] stmgc c8-overheads-instrumentation: Fix calculation of duration when a second jump lies between start and stop but the duration is less than a second, i.e., add carry over from the nanoseconds to the seconds component
tobweber
pypy.commits at gmail.com
Wed Mar 22 14:04:11 EDT 2017
Author: Tobias Weber <tobias_weber89 at gmx.de>
Branch: c8-overheads-instrumentation
Changeset: r2034:0e47a33eecfb
Date: 2017-03-22 18:22 +0100
http://bitbucket.org/pypy/stmgc/changeset/0e47a33eecfb/
Log: Fix calculation of duration when a second jump lies between start
and stop but the duration is less than a second, i.e., add carry
over from the nanoseconds to the seconds component
diff --git a/c8/stm/timing.h b/c8/stm/timing.h
--- a/c8/stm/timing.h
+++ b/c8/stm/timing.h
@@ -7,11 +7,18 @@
runtime. */
#define start_timer() struct timespec start, stop; \
struct timespec duration = { .tv_sec = 0, .tv_nsec = 0 };\
+ uint32_t nanosec_diff, sec_diff; \
continue_timer()
/* Must use start_timer before using this macro. */
-#define get_duration() duration.tv_sec += stop.tv_sec - start.tv_sec; \
- duration.tv_nsec += stop.tv_nsec - start.tv_nsec;
+#define get_duration() nanosec_diff = stop.tv_nsec - start.tv_nsec; \
+ sec_diff = stop.tv_sec - start.tv_sec; \
+ if (stop.tv_nsec < start.tv_nsec) { \
+ nanosec_diff += 1000000000; \
+ sec_diff -= 1; \
+ } \
+ duration.tv_sec += sec_diff; \
+ duration.tv_nsec += nanosec_diff;
#define pause_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &stop); \
get_duration()
More information about the pypy-commit
mailing list