Skip to content
Snippets Groups Projects
Commit 3bb12208 authored by Florian Fischer's avatar Florian Fischer
Browse files

use uint64_t for cycles and average calculation

parent 6e546000
No related branches found
No related tags found
1 merge request!2work work work
Pipeline #66484 passed
...@@ -8,7 +8,7 @@ LDFLAGS := -luring -pthread -lrt ...@@ -8,7 +8,7 @@ LDFLAGS := -luring -pthread -lrt
CFLAGS := -Werror -Wall -g -O3 CFLAGS := -Werror -Wall -g -O3
# CFLAGS := -Werror -Wall -g -O0 # CFLAGS := -Werror -Wall -g -O0
.PHONY: all clean eval docker-eval .PHONY: all clean eval docker-eval check
eval: all eval: all
@for syscall in $(SYSCALLS); do echo -n "$$syscall " ; ./bench-$$syscall; done @for syscall in $(SYSCALLS); do echo -n "$$syscall " ; ./bench-$$syscall; done
...@@ -28,6 +28,8 @@ $(foreach syscall,$(SYSCALLS),$(eval $(call generateTargets,$(syscall)))) ...@@ -28,6 +28,8 @@ $(foreach syscall,$(SYSCALLS),$(eval $(call generateTargets,$(syscall))))
clean: clean:
rm -f $(OBJ) rm -f $(OBJ)
check: tidy check-format
tidy: tidy:
clang-tidy *.c clang-tidy *.c
......
...@@ -42,8 +42,12 @@ int main() { ...@@ -42,8 +42,12 @@ int main() {
errx(EXIT_FAILURE, "cycles overflowed at %ld", i); errx(EXIT_FAILURE, "cycles overflowed at %ld", i);
} }
double avg_nanos = nanos_sum / (double)iterations; // Since uint64_t <-> double conversion are not well defined
double avg_cycles = cycles_sum / (double)iterations; // and we use really small units (cycles and nanoseconds) I am willing
printf("%lf ns, %lf cycles\n", avg_nanos, avg_cycles); // 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; return 0;
} }
#include "stopwatch.h" #include "stopwatch.h"
int64_t cycles_start, cycles_stop; uint64_t cycles_start, cycles_stop;
struct timespec start, stop; struct timespec start, stop;
int64_t sec_to_nanos(int64_t sec) { return sec * 1000 * 1000 * 1000; } int64_t sec_to_nanos(int64_t sec) { return sec * 1000 * 1000 * 1000; }
...@@ -13,4 +13,4 @@ int64_t clock_diff_nanos() { ...@@ -13,4 +13,4 @@ int64_t clock_diff_nanos() {
return nanos; return nanos;
} }
int64_t clock_diff_cycles() { return cycles_stop - cycles_start; } uint64_t clock_diff_cycles() { return cycles_stop - cycles_start; }
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
extern int64_t cycles_start, cycles_stop; extern uint64_t cycles_start, cycles_stop;
extern struct timespec start, stop; extern struct timespec start, stop;
static __inline__ int64_t rdtsc_s(void) { static __inline__ uint64_t rdtsc_s(void) {
unsigned a, d; unsigned a, d;
asm volatile("cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx"); asm volatile("cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx");
asm volatile("rdtsc" : "=a"(a), "=d"(d)); asm volatile("rdtsc" : "=a"(a), "=d"(d));
return ((unsigned long)a) | (((unsigned long)d) << 32); 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; unsigned a, d;
asm volatile("rdtscp" : "=a"(a), "=d"(d)); asm volatile("rdtscp" : "=a"(a), "=d"(d));
asm volatile("cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx"); asm volatile("cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx");
...@@ -30,7 +30,7 @@ static inline void stop_watch() { ...@@ -30,7 +30,7 @@ static inline void stop_watch() {
clock_gettime(CLOCK_MONOTONIC, &stop); clock_gettime(CLOCK_MONOTONIC, &stop);
} }
int64_t clock_diff_cycles(); uint64_t clock_diff_cycles();
int64_t clock_diff_nanos(); int64_t clock_diff_nanos();
double nanos_to_millis(int64_t nanos); double nanos_to_millis(int64_t nanos);
int64_t sec_to_nanos(int64_t sec); int64_t sec_to_nanos(int64_t sec);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment