summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1999-02-04 06:28:14 +0000
committerDavid Leonard <d@cvs.openbsd.org>1999-02-04 06:28:14 +0000
commitba0a2a7598cec80429adbc8dd4d6598555d74c73 (patch)
tree6731ddf393df731f1e38e1647792158a9c57bf1f
parentbe5e2374b04e8a93601fe65bd740fe1226a61bcd (diff)
tidy
-rw-r--r--lib/libc_r/BENCH/Makefile2
-rw-r--r--lib/libc_r/BENCH/bench.h52
-rw-r--r--lib/libc_r/BENCH/cond_timed.c8
-rw-r--r--lib/libc_r/BENCH/cond_wake.c7
-rw-r--r--lib/libc_r/BENCH/mutex_cont.c5
-rw-r--r--lib/libc_r/BENCH/null.c3
-rw-r--r--lib/libc_r/BENCH/self_overhead.c6
7 files changed, 49 insertions, 34 deletions
diff --git a/lib/libc_r/BENCH/Makefile b/lib/libc_r/BENCH/Makefile
index 22a9618d291..180c86012a4 100644
--- a/lib/libc_r/BENCH/Makefile
+++ b/lib/libc_r/BENCH/Makefile
@@ -3,7 +3,7 @@ CPPFLAGS += -pthread
LDFLAGS += -pthread
CFLAGS += -O -ggdb
METRICS = null once_overhead self_overhead mutex_nocont mutex_cont\
- cond_nowait cond_wake cond_timed
+ cond_nowait cond_timed
MKDEP = -p
SRCS = ${METRICS:=.c}
CLEANFILES += ${METRICS}
diff --git a/lib/libc_r/BENCH/bench.h b/lib/libc_r/BENCH/bench.h
index 1d68915a75e..6e8eb581cb8 100644
--- a/lib/libc_r/BENCH/bench.h
+++ b/lib/libc_r/BENCH/bench.h
@@ -1,22 +1,22 @@
-#define BENCH_LOOPS (16384)
+/* The default number of cycles per test */
+#define BENCH_LOOPS (100000)
+
#include <sys/time.h>
typedef struct {
- int i;
- int n;
- int divisor;
- struct timespec start;
- struct timespec end;
- struct timespec elapsed;
- double average;
- char *name;
- char *doc;
- char *units;
+ int i; /* loop counter */
+ int n; /* loop maximum */
+ int divisor; /* operations per cycle */
+ struct timeval start; /* start time */
+ struct timeval end; /* end time */
+ char *name; /* benchmark title */
+ char *doc; /* benchmark description */
+ char *units; /* measurement units information */
} bench_t;
-#define bench_now(tsp) \
- clock_gettime(CLOCK_REALTIME, (tsp))
+#define bench_now(tvp) \
+ gettimeofday((tvp),0)
/*
* Repeat the body of the loop 'max' times, with a few extra 'warm up'
@@ -36,9 +36,8 @@ typedef struct {
(b)->name = (nm); \
(b)->doc = (dc); \
(b)->units = (un); \
- timespecclear(&(b)->start); \
- timespecclear(&(b)->end); \
- timespecclear(&(b)->elapsed); \
+ timerclear(&(b)->start); \
+ timerclear(&(b)->end); \
(b)->n = (b)->i = 0; \
(b)->divisor = 1; \
} while (0)
@@ -48,18 +47,23 @@ typedef struct {
"Name:\t%s\nDesc:%s\n", (b)->name, (b)->doc)
#define bench_report(b) do { \
- struct timespec elapsed; \
bench_t overhead; \
+ struct timeval oh_elapsed; \
+ struct timeval elapsed; \
+ struct timeval normal; \
+ double average; \
\
/* compute the loop overhead */ \
- bench_amortize(&overhead, BENCH_LOOPS) { /* nothing */ } \
+ bench_amortize(&overhead, (b)->n) { /* nothing */ } \
+ \
+ /* compute the test time */ \
+ timersub(&(b)->end, &(b)->start, &elapsed); \
+ timersub(&overhead.end, &overhead.start, &oh_elapsed); \
+ timersub(&elapsed, &oh_elapsed, &normal); \
\
- timespecsub(&(b)->end, &(b)->start, &(b)->elapsed); \
- (b)->average = ((double)(b)->elapsed.tv_sec * 1000000000.0 + \
- (b)->elapsed.tv_nsec) / (double)((b)->divisor) / \
+ average = ((double)normal.tv_sec * 1000000.0 + \
+ normal.tv_usec) / (double)((b)->divisor) / \
(double)((b)->n); \
\
- printf("Time: %f usec %s\n", (b)->average, (b)->units); \
- if ((b)->divisor != 1) \
- printf("\t(%d operations per cycle)\n", (b)->divisor); \
+ printf("Time: %f usec %s\n", average, (b)->units); \
} while (0)
diff --git a/lib/libc_r/BENCH/cond_timed.c b/lib/libc_r/BENCH/cond_timed.c
index dc48cd7e340..9eb30098ef1 100644
--- a/lib/libc_r/BENCH/cond_timed.c
+++ b/lib/libc_r/BENCH/cond_timed.c
@@ -1,11 +1,13 @@
+#include <stdio.h>
#include <pthread.h>
+#include <sched.h>
#include <string.h>
#include <err.h>
#include "bench.h"
static char name[] = "Time of Wakeup After Timed Wait";
static char doc[] =
-"\tThe tiem required for the highest-priority thread to rresume\n"
+"\tThe time required for the highest-priority thread to resume\n"
"\texecution after a call to pthread_cond_timedwait(). Metrics\n"
"\tare provided for both the cases when the pthread_cond_timedwait()\n"
"\tcall is awakened by a call to pthread_cond_signal() and when\n"
@@ -50,7 +52,7 @@ main() {
pthread_mutex_lock(&m1);
pthread_create(&other, NULL, other_thread, NULL);
- pthread_yield();
+ sched_yield();
while (b.i < b.n) {
pthread_cond_signal(&c);
pthread_cond_timedwait(&c, &m1, &waketime);
@@ -65,7 +67,7 @@ main() {
bench_init(&b, NULL, NULL, "per call when already expired");
pthread_mutex_init(&m, NULL);
pthread_mutex_lock(&m);
- timespecclear(&ts);
+ timespecclear(&ts); /* 1 Jan, 1970 */
bench_amortize(&b, BENCH_LOOPS) {
pthread_cond_timedwait(&c, &m, &ts);
}
diff --git a/lib/libc_r/BENCH/cond_wake.c b/lib/libc_r/BENCH/cond_wake.c
index 11055baaeed..c654a674bd2 100644
--- a/lib/libc_r/BENCH/cond_wake.c
+++ b/lib/libc_r/BENCH/cond_wake.c
@@ -1,4 +1,6 @@
+#include <stdio.h>
#include <pthread.h>
+#include <sched.h>
#include <string.h>
#include <err.h>
#include "bench.h"
@@ -13,6 +15,8 @@ static char doc[] =
"\tpthread_cond_signal() call is executed under the associated mutex,\n"
"\tas well as not under the mutex.";
+/* BROKEN */
+
pthread_mutex_t m1, m2;
pthread_cond_t c;
bench_t b;
@@ -44,7 +48,7 @@ main() {
pthread_mutex_lock(&m1);
pthread_create(&other, NULL, other_thread, NULL);
- pthread_yield();
+ sched_yield();
while (b.i < b.n) {
pthread_cond_signal(&c);
pthread_cond_wait(&c, &m1);
@@ -52,6 +56,7 @@ main() {
b.divisor = 2;
bench_report(&b);
+ pthread_join(other, NULL);
exit(0);
}
diff --git a/lib/libc_r/BENCH/mutex_cont.c b/lib/libc_r/BENCH/mutex_cont.c
index de9eecb0bce..3bb32b68469 100644
--- a/lib/libc_r/BENCH/mutex_cont.c
+++ b/lib/libc_r/BENCH/mutex_cont.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <pthread.h>
+#include <sched.h>
#include <string.h>
#include <err.h>
#include "bench.h"
@@ -63,7 +64,7 @@ thread_a(arg)
{
pthread_set_name_np(pthread_self(), "ta");
pthread_mutex_lock(&m2);
- pthread_yield();
+ sched_yield();
pthread_mutex_lock(&m1);
bench_amortize(&ba, BENCH_LOOPS) {
@@ -85,7 +86,7 @@ thread_b(arg)
pthread_set_name_np(pthread_self(), "tb");
pthread_mutex_lock(&m1);
pthread_mutex_lock(&m3);
- pthread_yield();
+ sched_yield();
bench_amortize(&bb, BENCH_LOOPS) {
pthread_mutex_unlock(&m1);
diff --git a/lib/libc_r/BENCH/null.c b/lib/libc_r/BENCH/null.c
index cbd7ad3a4f6..15436e18a66 100644
--- a/lib/libc_r/BENCH/null.c
+++ b/lib/libc_r/BENCH/null.c
@@ -6,7 +6,8 @@
static char name[] = "Null test";
static char doc[] =
"\tThe time needed for performing a tight empty loop. This indicates\n"
-"\tthe overhead incurred by the measurement harness.";
+"\tthe overhead incurred by the measurement harness. It should be zero,\n"
+"\tand may even be negative.";
diff --git a/lib/libc_r/BENCH/self_overhead.c b/lib/libc_r/BENCH/self_overhead.c
index eea74cfc75e..f48bd166a5d 100644
--- a/lib/libc_r/BENCH/self_overhead.c
+++ b/lib/libc_r/BENCH/self_overhead.c
@@ -1,4 +1,6 @@
+#include <stdio.h>
#include <pthread.h>
+#include <sched.h>
#include <string.h>
#include <err.h>
#include "bench.h"
@@ -34,7 +36,7 @@ numthreads(n)
if (error != 0)
errx(1, "pthread_create #%d: %s", nthreads,
strerror(error));
- pthread_yield();
+ sched_yield();
nthreads++;
}
@@ -42,7 +44,7 @@ numthreads(n)
error = pthread_cancel(children[nthreads - 1]);
if (error != 0)
errx(1, "pthread_cancel: %s", strerror(error));
- pthread_yield();
+ sched_yield();
nthreads --;
}