diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-07-24 16:42:17 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-07-24 16:42:17 +0200 |
| commit | 58cbdbd892c9a83369e3e46aa9700cc7df98a17b (patch) | |
| tree | 1ada4624144d5537c2584dad0a44e5291dce6a8c /bench/util.c | |
| parent | Rename bench/{benchmark.h => util.h} (diff) | |
| download | libzahl-58cbdbd892c9a83369e3e46aa9700cc7df98a17b.tar.gz libzahl-58cbdbd892c9a83369e3e46aa9700cc7df98a17b.tar.bz2 libzahl-58cbdbd892c9a83369e3e46aa9700cc7df98a17b.tar.xz | |
Clean up bench/util.h
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'bench/util.c')
| -rw-r--r-- | bench/util.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bench/util.c b/bench/util.c new file mode 100644 index 0000000..d11239d --- /dev/null +++ b/bench/util.c @@ -0,0 +1,39 @@ +#define COMPILING_UTIL_C +#include "util.h" + + +char timebuf[512]; +unsigned long long int freq; + + +void +benchmark_init(void) +{ +#if defined(__linux__) && defined(USE_RDTSC) + cpu_set_t cpuset; + FILE *f; + char *line = 0; + size_t size = 0; + char path[PATH_MAX]; + CPU_ZERO(&cpuset); + CPU_SET(USE_CPU, &cpuset); + sched_setaffinity(getpid(), sizeof(cpuset), &cpuset); + sprintf(path, "/sys/devices/system/cpu/cpu%i/cpufreq/cpuinfo_max_freq", USE_CPU); + f = fopen(path, "r"); + if (getline(&line, &size, f) < 0) + abort(); + fclose(f); + freq = strtoull(line, 0, 10); + free(line); + +#elif defined(__linux__) + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(USE_CPU, &cpuset); + sched_setaffinity(getpid(), sizeof(cpuset), &cpuset); + +#else + fprintf(stderr, "WARNING: Don't know how to set CPU affinity.\n"); + +#endif +} |
