summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sandglass.c17
-rw-r--r--src/sandglass.h26
2 files changed, 25 insertions, 18 deletions
diff --git a/src/sandglass.c b/src/sandglass.c
index b9316e5..6db28a3 100644
--- a/src/sandglass.c
+++ b/src/sandglass.c
@@ -189,16 +189,6 @@ sandglass_elapse(sandglass_t *sandglass)
/* Magical correction for timespec-based grains */
sandglass->grains += sandglass->adjustment;
- if (sandglass->attributes.resolution == SANDGLASS_REALTICKS) {
- baseline.attributes.incrementation = SANDGLASS_MONOTONIC;
- baseline.attributes.resolution = SANDGLASS_CPUTIME;
- baseline.loops = sandglass->loops;
-
- sandglass_bench(&baseline, { });
- sandglass->grains -= baseline.grains;
- sandglass->grains /= sandglass->loops;
- }
-
return 0;
}
@@ -213,13 +203,6 @@ sandglass_real_gettime(sandglass_t *sandglass)
case SANDGLASS_MONOTONIC:
switch (sandglass->attributes.resolution) {
case SANDGLASS_REALTICKS:
-#ifdef SANDGLASS_TSC
- sandglass->grains = sandglass_get_tsc();
- break;
-#else
- return -1;
-#endif
-
case SANDGLASS_CPUTIME:
#ifdef SANDGLASS_TSC
sandglass->grains = sandglass_get_tsc();
diff --git a/src/sandglass.h b/src/sandglass.h
index 7073fb9..0d5e5e5 100644
--- a/src/sandglass.h
+++ b/src/sandglass.h
@@ -102,8 +102,12 @@ struct sandglass_t
/* Adjustment to be added for negative (i.e. overflowed) grains counts */
long adjustment;
- /* For SANDGLASS_TICKS looping support */
+ /* For SANDGLASS_REALTICKS looping support */
unsigned int i, loops;
+
+ /* A field used by sandglass_bench() to store the overhead of
+ sandglass_begin()/_elapse(), and of looping */
+ long baseline;
};
typedef struct sandglass_t sandglass_t;
@@ -141,7 +145,23 @@ int sandglass_elapse(sandglass_t *sandglass);
*/
#define sandglass_bench(sandglass, routine) \
do { \
+ /* Warm up the cache for these functions */ \
+ sandglass_begin(sandglass); \
+ sandglass_elapse(sandglass); \
+ \
+ /* Time an empty loop for our baseline */ \
+ sandglass_begin(sandglass); \
+ for ((sandglass)->i = 0; \
+ (sandglass)->i < (sandglass)->loops; \
+ ++(sandglass)->i) { \
+ SANDGLASS_NO_UNROLL(); \
+ } \
+ sandglass_elapse(sandglass); \
+ (sandglass)->baseline = (sandglass)->grains; \
+ \
+ /* Warm up the cache for our routine */ \
routine; \
+ /* Time our routine in a loop */ \
sandglass_begin(sandglass); \
for ((sandglass)->i = 0; \
(sandglass)->i < (sandglass)->loops; \
@@ -150,6 +170,10 @@ int sandglass_elapse(sandglass_t *sandglass);
routine; \
} \
sandglass_elapse(sandglass); \
+ \
+ /* Subtract the baseline and divide by the loop count */ \
+ (sandglass)->grains -= (sandglass)->baseline; \
+ (sandglass)->grains /= (sandglass)->loops; \
} while (0)
#ifdef __cplusplus