diff --git a/Makefile b/Makefile index bbc1e08ae00bcc800515b61c43072ac5677fd420..a9ced29e266a8d583c161a584437764298764a16 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ LDFLAGS := -luring -pthread -lrt CFLAGS := -Werror -Wall -g -O3 # CFLAGS := -Werror -Wall -g -O0 -.PHONY: all clean eval docker-eval +.PHONY: all clean eval docker-eval check eval: all @for syscall in $(SYSCALLS); do echo -n "$$syscall " ; ./bench-$$syscall; done @@ -28,6 +28,8 @@ $(foreach syscall,$(SYSCALLS),$(eval $(call generateTargets,$(syscall)))) clean: rm -f $(OBJ) +check: tidy check-format + tidy: clang-tidy *.c diff --git a/bench.c b/bench.c index 7a3c94118b43b07149aca1d3e52e5aaebf966399..b7439a6778522fdcc0a15b1f6cb0c9ea8176fa76 100644 --- a/bench.c +++ b/bench.c @@ -42,8 +42,12 @@ int main() { errx(EXIT_FAILURE, "cycles overflowed at %ld", i); } - double avg_nanos = nanos_sum / (double)iterations; - double avg_cycles = cycles_sum / (double)iterations; - printf("%lf ns, %lf cycles\n", avg_nanos, avg_cycles); + // Since uint64_t <-> double conversion are not well defined + // and we use really small units (cycles and nanoseconds) I am willing + // to accept that we throw away anything after the decimal point. + uint64_t avg_nanos = nanos_sum / iterations; + uint64_t avg_cycles = cycles_sum / iterations; + + printf("%lu ns, %lu cycles\n", avg_nanos, avg_cycles); return 0; } diff --git a/stopwatch.c b/stopwatch.c index aaf5028fd03cf8ab553d751c795e778191d4fdda..472baf59370274ea7880e627ed6fe96d9f74c5b7 100644 --- a/stopwatch.c +++ b/stopwatch.c @@ -1,6 +1,6 @@ #include "stopwatch.h" -int64_t cycles_start, cycles_stop; +uint64_t cycles_start, cycles_stop; struct timespec start, stop; int64_t sec_to_nanos(int64_t sec) { return sec * 1000 * 1000 * 1000; } @@ -13,4 +13,4 @@ int64_t clock_diff_nanos() { return nanos; } -int64_t clock_diff_cycles() { return cycles_stop - cycles_start; } +uint64_t clock_diff_cycles() { return cycles_stop - cycles_start; } diff --git a/stopwatch.h b/stopwatch.h index 6830f971f8bdc9d887e42fb6112d5c50d96d5186..7b670d132102574a27c90b9753a20ca6a486c653 100644 --- a/stopwatch.h +++ b/stopwatch.h @@ -3,17 +3,17 @@ #include <stdint.h> #include <time.h> -extern int64_t cycles_start, cycles_stop; +extern uint64_t cycles_start, cycles_stop; extern struct timespec start, stop; -static __inline__ int64_t rdtsc_s(void) { +static __inline__ uint64_t rdtsc_s(void) { unsigned a, d; asm volatile("cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx"); asm volatile("rdtsc" : "=a"(a), "=d"(d)); return ((unsigned long)a) | (((unsigned long)d) << 32); } -static __inline__ int64_t rdtsc_e(void) { +static __inline__ uint64_t rdtsc_e(void) { unsigned a, d; asm volatile("rdtscp" : "=a"(a), "=d"(d)); asm volatile("cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx"); @@ -30,7 +30,7 @@ static inline void stop_watch() { clock_gettime(CLOCK_MONOTONIC, &stop); } -int64_t clock_diff_cycles(); +uint64_t clock_diff_cycles(); int64_t clock_diff_nanos(); double nanos_to_millis(int64_t nanos); int64_t sec_to_nanos(int64_t sec);