summaryrefslogtreecommitdiffstats
path: root/src/tsc.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-09-20 01:09:24 +0000
committerTavian Barnes <tavianator@gmail.com>2009-09-20 01:09:24 +0000
commitab843ae81eb445d94ed6821e45df8a782d2886e6 (patch)
tree6004225779a1c9ce9d7915ccbde167a4c25f26d0 /src/tsc.c
parentd69067be2350d635683b524381c3d084498ec7aa (diff)
downloadlibsandglass-ab843ae81eb445d94ed6821e45df8a782d2886e6.tar.xz
Don't change the `ts' parameter in sandglass_spin.
Diffstat (limited to 'src/tsc.c')
-rw-r--r--src/tsc.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/tsc.c b/src/tsc.c
index 554a6d8..135cd2a 100644
--- a/src/tsc.c
+++ b/src/tsc.c
@@ -29,11 +29,24 @@ sandglass_tsc_resolution()
{
static long tsc = 0;
static struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000L };
+ struct timespec curr, until;
if (tsc == 0) {
+ sandglass_get_currtime(&curr);
+ until = curr;
+ sandglass_timespec_add(&until, &ts);
tsc = sandglass_get_tsc();
- sandglass_spin(&ts);
+
+ /* Spin */
+ do {
+ sandglass_get_currtime(&curr);
+ } while (sandglass_timespec_cmp(&curr, &until) < 0);
+
tsc = sandglass_get_tsc() - tsc;
+
+ /* Adjust ts to the time actually waited */
+ sandglass_timespec_sub(&curr, &until);
+ sandglass_timespec_add(&ts, &curr);
}
return tsc*1.0e9/ts.tv_nsec;