summaryrefslogtreecommitdiffstats
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
parentd69067be2350d635683b524381c3d084498ec7aa (diff)
downloadlibsandglass-ab843ae81eb445d94ed6821e45df8a782d2886e6.tar.xz
Don't change the `ts' parameter in sandglass_spin.
-rw-r--r--src/sandglass_impl.h2
-rw-r--r--src/timespec.c6
-rw-r--r--src/tsc.c15
-rw-r--r--tests/introspective-cputime.c8
-rw-r--r--tests/introspective-system.c8
-rw-r--r--tests/monotonic-cputime.c8
-rw-r--r--tests/monotonic-realticks.c8
-rw-r--r--tests/monotonic-system.c8
8 files changed, 26 insertions, 37 deletions
diff --git a/src/sandglass_impl.h b/src/sandglass_impl.h
index 07a3616..689c6bf 100644
--- a/src/sandglass_impl.h
+++ b/src/sandglass_impl.h
@@ -41,6 +41,6 @@ void sandglass_get_currtime(struct timespec *ts);
void sandglass_timespec_add(struct timespec *ts, const struct timespec *d);
void sandglass_timespec_sub(struct timespec *ts, const struct timespec *d);
int sandglass_timespec_cmp(const struct timespec *a, const struct timespec *b);
-void sandglass_spin(struct timespec *ts);
+void sandglass_spin(const struct timespec *ts);
#endif /* SANDGLASS_IMPL_H_INCLUDED */ \ No newline at end of file
diff --git a/src/timespec.c b/src/timespec.c
index f8ab791..c077f8b 100644
--- a/src/timespec.c
+++ b/src/timespec.c
@@ -91,7 +91,7 @@ sandglass_timespec_cmp(const struct timespec *a, const struct timespec *b)
/* Spins for the time interval specified by ts */
void
-sandglass_spin(struct timespec *ts)
+sandglass_spin(const struct timespec *ts)
{
struct timespec curr, until;
sandglass_get_currtime(&curr);
@@ -102,8 +102,4 @@ sandglass_spin(struct timespec *ts)
do {
sandglass_get_currtime(&curr);
} while (sandglass_timespec_cmp(&curr, &until) < 0);
-
- /* Adjust ts to the time actually waited */
- sandglass_timespec_sub(&curr, &until);
- sandglass_timespec_add(ts, &curr);
}
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;
diff --git a/tests/introspective-cputime.c b/tests/introspective-cputime.c
index 026ae94..b35e2f4 100644
--- a/tests/introspective-cputime.c
+++ b/tests/introspective-cputime.c
@@ -30,18 +30,14 @@ main()
{
sandglass_t sandglass;
sandglass_attributes_t attr = { SANDGLASS_INTROSPECTIVE, SANDGLASS_CPUTIME };
- struct timespec tosleep;
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000L };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
return EXIT_FAILURE;
}
- sandglass_bench(&sandglass, {
- tosleep.tv_sec = 0;
- tosleep.tv_nsec = 100000000L;
- sandglass_spin(&tosleep);
- });
+ sandglass_bench(&sandglass, sandglass_spin(&tosleep));
printf("%g\n", sandglass.grains/sandglass.resolution);
diff --git a/tests/introspective-system.c b/tests/introspective-system.c
index 21ffa4c..beb799f 100644
--- a/tests/introspective-system.c
+++ b/tests/introspective-system.c
@@ -30,18 +30,14 @@ main()
{
sandglass_t sandglass;
sandglass_attributes_t attr = { SANDGLASS_INTROSPECTIVE, SANDGLASS_SYSTEM };
- struct timespec tosleep;
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000L };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
return EXIT_FAILURE;
}
- sandglass_bench(&sandglass, {
- tosleep.tv_sec = 0;
- tosleep.tv_nsec = 100000000L;
- sandglass_spin(&tosleep);
- });
+ sandglass_bench(&sandglass, sandglass_spin(&tosleep));
printf("%g\n", sandglass.grains/sandglass.resolution);
diff --git a/tests/monotonic-cputime.c b/tests/monotonic-cputime.c
index 7e0fdef..4d56793 100644
--- a/tests/monotonic-cputime.c
+++ b/tests/monotonic-cputime.c
@@ -30,18 +30,14 @@ main()
{
sandglass_t sandglass;
sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
- struct timespec tosleep;
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000L };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
return EXIT_FAILURE;
}
- sandglass_bench(&sandglass, {
- tosleep.tv_sec = 0;
- tosleep.tv_nsec = 100000000L;
- sandglass_spin(&tosleep);
- });
+ sandglass_bench(&sandglass, sandglass_spin(&tosleep));
printf("%g\n", sandglass.grains/sandglass.resolution);
diff --git a/tests/monotonic-realticks.c b/tests/monotonic-realticks.c
index 5cadd1d..c548f18 100644
--- a/tests/monotonic-realticks.c
+++ b/tests/monotonic-realticks.c
@@ -30,18 +30,14 @@ main()
{
sandglass_t sandglass;
sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_REALTICKS };
- struct timespec tosleep;
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000L };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
return EXIT_FAILURE;
}
- sandglass_bench(&sandglass, {
- tosleep.tv_sec = 0;
- tosleep.tv_nsec = 100000000L;
- sandglass_spin(&tosleep);
- });
+ sandglass_bench(&sandglass, sandglass_spin(&tosleep));
printf("%g\n", sandglass.grains/sandglass.resolution);
diff --git a/tests/monotonic-system.c b/tests/monotonic-system.c
index 49a1b8c..3c8e9be 100644
--- a/tests/monotonic-system.c
+++ b/tests/monotonic-system.c
@@ -30,18 +30,14 @@ main()
{
sandglass_t sandglass;
sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_SYSTEM };
- struct timespec tosleep;
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000L };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
return EXIT_FAILURE;
}
- sandglass_bench(&sandglass, {
- tosleep.tv_sec = 0;
- tosleep.tv_nsec = 100000000L;
- sandglass_spin(&tosleep);
- });
+ sandglass_bench(&sandglass, sandglass_spin(&tosleep));
printf("%g\n", sandglass.grains/sandglass.resolution);