Commit c06dcf95 authored by william's avatar william

remove main() testing code from timeout.c and tweak Makefile so we can compare...

remove main() testing code from timeout.c and tweak Makefile so we can compare different wheel sizes with the benchmark framework
parent cb3e2c7d
all: timeout timeout8 timeout16 timeout32 timeout64 bench bench-wheel.so bench-heap.so
all: bench bench-wheel.so bench-heap.so
WHEEL_BIT = 6
WHEEL_NUM = 4
CPPFLAGS = -DTIMEOUT_DEBUG -DTIMEOUT_MAIN
CPPFLAGS = -DTIMEOUT_DEBUG
CFLAGS = -O2 -g -Wall -Wextra
timeout: CPPFLAGS+=-DWHEEL_BIT=$(WHEEL_BIT) -DWHEEL_NUM=$(WHEEL_NUM)
......@@ -34,6 +34,26 @@ else
SOFLAGS = -shared
endif
bench-wheel8.so: CPPFLAGS+=-DWHEEL_BIT=3 -DWHEEL_NUM=$(WHEEL_NUM)
bench-wheel8.so: timeout.c
bench-wheel16.so: CPPFLAGS+=-DWHEEL_BIT=4 -DWHEEL_NUM=$(WHEEL_NUM)
bench-wheel16.so: timeout.c
bench-wheel32.so: CPPFLAGS+=-DWHEEL_BIT=5 -DWHEEL_NUM=$(WHEEL_NUM)
bench-wheel32.so: timeout.c
bench-wheel64.so: CPPFLAGS+=-DWHEEL_BIT=6 -DWHEEL_NUM=$(WHEEL_NUM)
bench-wheel64.so: timeout.c
bench-wheel%.so: bench-wheel.c timeout.h
$(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) -Wno-unused-function $(SOFLAGS)
bench-wheel.so: CPPFLAGS+=-DWHEEL_BIT=$(WHEEL_BIT) -DWHEEL_NUM=$(WHEEL_NUM)
bench-wheel.so: timeout.c
......
......@@ -24,6 +24,8 @@ struct {
void *solib;
size_t count;
timeout_t maximum;
int verbose;
struct timeout *timeout;
struct vops vops;
timeout_t curtime;
......@@ -130,12 +132,13 @@ badargc:
} /* parseop() */
#define SHORT_OPTS "n:t:h"
#define SHORT_OPTS "n:t:vh"
static void usage(FILE *fp) {
fprintf(fp,
"bench [-%s] LIBRARY\n" \
" -n MAX maximum number of timeouts\n" \
" -t MAX maximum timeout\n" \
" -v increase log level\n" \
" -h print usage message\n" \
"\n" \
"[commands]\n" \
......@@ -165,6 +168,12 @@ int main(int argc, char **argv) {
break;
case 't':
MAIN.maximum = (strtod(optarg, NULL) * TIMEOUT_mHZ);
break;
case 'v':
MAIN.verbose++;
break;
case 'h':
usage(stdout);
......
......@@ -3,7 +3,7 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#if TIMEOUT_DEBUG - 0 || TIMEOUT_MAIN - 0
#if TIMEOUT_DEBUG - 0
#include <stdlib.h>
#include <stdio.h>
......
......@@ -39,7 +39,7 @@
#include "timeout.h"
#if TIMEOUT_DEBUG - 0 || TIMEOUT_MAIN - 0
#if TIMEOUT_DEBUG - 0
#include "debug.h"
#endif
......@@ -69,7 +69,7 @@
#endif
#if !defined TAILQ_CONCAT
#define TAILQ_CONCAT(head1, head2, field) do { \
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
......@@ -661,89 +661,3 @@ TIMEOUT_PUBLIC int timeout_v_api(void) {
return TIMEOUT_V_API;
} /* timeout_version() */
#if TIMEOUT_MAIN - 0
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static timeout_t slow_timeout(struct timeouts *T) {
struct timeout *to = timeouts_min(T);
return (to)? to->expires - T->curtime : 0;
} /* slow_timeout() */
int main(int argc, char **argv) {
extern int optind;
extern char *optarg;
struct timeouts T;
struct timeout to[16];
struct timeout *expired;
uint64_t time = 0, step = 1, stop = 0;
unsigned count = 0;
int opt;
while (-1 != (opt = getopt(argc, argv, "s:t:v"))) {
switch (opt) {
case 's': {
char *end;
time = strtoul(optarg, &end, 10);
if (*end == ':')
stop = strtoul(end + 1, 0, 10);
break;
}
case 't':
if (!(step = strtoul(optarg, 0, 10)))
PANIC("%llu: invalid tick count", step);
break;
case 'v':
timeout_debug++;
break;
}
} /* while() */
argc -= optind;
argv += optind;
timeouts_init(&T, TIMEOUT_mHZ);
timeouts_update(&T, time);
timeouts_add(&T, timeout_init(&to[0], 0), 62); count++;
timeouts_add(&T, timeout_init(&to[1], 0), 63); count++;
timeouts_add(&T, timeout_init(&to[2], 0), 64); count++;
timeouts_add(&T, timeout_init(&to[3], 0), 65); count++;
timeouts_add(&T, timeout_init(&to[5], 0), 192); count++;
timeouts_add(&T, timeout_init(&to[6], 0), 6); count++;
timeouts_add(&T, timeout_init(&to[7], 0), 7); count++;
timeouts_add(&T, timeout_init(&to[8], 0), 8); count++;
while (count > 0 && time <= stop - 1) {
time += step;
SAY("timeout -> %" TIMEOUT_PRIu " (actual:%" TIMEOUT_PRIu " curtime:%" TIMEOUT_PRIu ")", timeouts_timeout(&T), slow_timeout(&T), T.curtime);
timeouts_check(&T, stderr);
timeouts_update(&T, time);
timeouts_check(&T, stderr);
while ((expired = timeouts_get(&T))) {
timeouts_del(&T, expired);
SAY("step %llu expired %llu @@@@@@@@@@@@@@@@@@@@", time, expired->expires);
count--;
}
}
SAY("%s curtime: %llu", (count == 0)? "OK" : "FAIL", T.curtime);
return 0;
} /* main() */
#endif /* TIMEOUT_MAIN */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment