diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-04-28 21:52:47 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-04-28 21:52:47 +0200 |
| commit | 73b0d33bafadb839962d5d6fbd5c1a8a18a8c56c (patch) | |
| tree | a263e3e79ae58b13925fa57845b7d7b991b25dbd /bench/benchmark.h | |
| parent | Fix warnings (diff) | |
| download | libzahl-73b0d33bafadb839962d5d6fbd5c1a8a18a8c56c.tar.gz libzahl-73b0d33bafadb839962d5d6fbd5c1a8a18a8c56c.tar.bz2 libzahl-73b0d33bafadb839962d5d6fbd5c1a8a18a8c56c.tar.xz | |
Some documentation and cleanup for benchmark stuff
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'bench/benchmark.h')
| -rw-r--r-- | bench/benchmark.h | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/bench/benchmark.h b/bench/benchmark.h index cb42777..f69da20 100644 --- a/bench/benchmark.h +++ b/bench/benchmark.h @@ -39,60 +39,16 @@ #endif + static struct timespec dur; static char timebuf[512]; -#if defined(USE_RDTSC) -typedef unsigned long long int rdtsc_t; -static unsigned int start_high, start_low, end_high, end_low; -static unsigned long long int freq; -#elif defined(USE_CLOCK) -static clock_t start, end; -#else -static struct timespec start; -#endif - - -static void -benchmark_init(void) -{ -#if defined(__linux__) - cpu_set_t cpuset; -# if defined(USE_RDTSC) - FILE *f; - char *line = 0; - size_t size = 0; -# endif - CPU_ZERO(&cpuset); - CPU_SET(0, &cpuset); - sched_setaffinity(getpid(), sizeof(cpuset), &cpuset); -# if defined(USE_RDTSC) - f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r"); - if (getline(&line, &size, f) < 0) - abort(); - fclose(f); - freq = strtoull(line, 0, 10); - free(line); -# endif -#endif - (void) timebuf; -} #if defined(USE_RDTSC) && defined(__x86_64__) -static inline void -rdtsc(unsigned int *low, unsigned int *high) -{ - __asm__ __volatile__ ("rdtsc" : "=a"(*low), "=d"(*high)); -} -static inline rdtsc_t -rdtsc_join(unsigned int low, unsigned int high) -{ - return (rdtsc_t)low | (((rdtsc_t)high) << 32); -} -#endif - +typedef unsigned long long int rdtsc_t; +static unsigned int start_high, start_low, end_high, end_low; +static unsigned long long int freq; -#if defined(USE_RDTSC) # define TIC (rdtsc(&start_low, &start_high)) # define TOC\ do {\ @@ -106,7 +62,23 @@ rdtsc_join(unsigned int low, unsigned int high) dur_seconds -= (double)(dur.tv_sec = (int)dur_seconds);\ dur.tv_nsec = (long int)(dur_seconds * 1000000000L);\ } while (0) + +static inline void +rdtsc(unsigned int *low, unsigned int *high) +{ + __asm__ __volatile__ ("rdtsc" : "=a"(*low), "=d"(*high)); +} + +static inline rdtsc_t +rdtsc_join(unsigned int low, unsigned int high) +{ + return (rdtsc_t)low | (((rdtsc_t)high) << 32); +} + + #elif defined(USE_CLOCK) +static clock_t start, end; + # define TIC (start = clock()) # define TOC\ do {\ @@ -114,7 +86,11 @@ rdtsc_join(unsigned int low, unsigned int high) dur.tv_sec = (end - start) / 1000000ULL;\ dur.tv_nsec = ((end - start) % 1000000ULL) * 1000;\ } while (0) + + #elif defined(USE_GETTIME) +static struct timespec start; + # define TIC clock_gettime(CLOCK_MONOTONIC_RAW, &start) # define TOC\ do {\ @@ -131,3 +107,29 @@ rdtsc_join(unsigned int low, unsigned int high) #define TICKS ((unsigned long long int)(dur.tv_sec) * 1000000000ULL + (unsigned long long int)(dur.tv_nsec)) #define STIME (sprintf(timebuf, "%lli.%09li", (long long)(dur.tv_sec), dur.tv_nsec), timebuf) + + +static void +benchmark_init(void) +{ +#if defined(__linux__) + cpu_set_t cpuset; +# if defined(USE_RDTSC) + FILE *f; + char *line = 0; + size_t size = 0; +# endif + CPU_ZERO(&cpuset); + CPU_SET(0, &cpuset); + sched_setaffinity(getpid(), sizeof(cpuset), &cpuset); +# if defined(USE_RDTSC) + f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r"); + if (getline(&line, &size, f) < 0) + abort(); + fclose(f); + freq = strtoull(line, 0, 10); + free(line); +# endif +#endif + (void) timebuf; +} |
