diff options
-rw-r--r-- | bench/MHz.c | 10 | ||||
-rw-r--r-- | bench/benchmarks.c | 14 | ||||
-rw-r--r-- | x86info.h | 16 |
3 files changed, 18 insertions, 22 deletions
diff --git a/bench/MHz.c b/bench/MHz.c index 521ac76..2aa9ad3 100644 --- a/bench/MHz.c +++ b/bench/MHz.c @@ -9,9 +9,6 @@ #include <unistd.h> #include <stdlib.h> -#define _GNU_SOURCE -#define __USE_GNU -#include <sched.h> #include <string.h> #include <signal.h> @@ -27,7 +24,6 @@ static void sighandler(int sig __attribute__((unused))) void estimate_MHz(struct cpudata *cpu) { - cpu_set_t set; unsigned long long int cycles[2]; /* gotta be 64 bit */ unsigned int eax, ebx, ecx, edx; unsigned long r; @@ -40,11 +36,7 @@ void estimate_MHz(struct cpudata *cpu) return; } - if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) { - CPU_ZERO(&set); - CPU_SET(cpu->number, &set); - sched_setaffinity(getpid(), sizeof(set), &set); - } + bind_cpu(cpu); if (signal(SIGALRM, sighandler) == SIG_ERR) { printf("Some kind of signal failure.\n"); diff --git a/bench/benchmarks.c b/bench/benchmarks.c index b311000..7b61ec4 100644 --- a/bench/benchmarks.c +++ b/bench/benchmarks.c @@ -9,26 +9,14 @@ #include <asm/unistd.h> #endif -#define _GNU_SOURCE -#define __USE_GNU -#include <sched.h> - #include <sys/types.h> #include <unistd.h> void show_benchmarks(struct cpudata *cpu) { int tmp = 0; - cpu_set_t set; - - if (show_bench != 1) - return; - if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) { - CPU_ZERO(&set); - CPU_SET(cpu->number, &set); - sched_setaffinity(getpid(), sizeof(set), &set); - } + bind_cpu(cpu); #ifdef __linux__ TIME(asm volatile("int $0x80" :"=a" (tmp) :"0" (__NR_getppid)), "int 0x80"); @@ -173,4 +173,20 @@ extern int user_is_root; #define X86_FEATURE_MTRR 1<<12 +#define _GNU_SOURCE +#define __USE_GNU +#include <sched.h> +#include <sys/types.h> +#include <unistd.h> +static inline void bind_cpu(struct cpudata *cpu) +{ + cpu_set_t set; + + if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) { + CPU_ZERO(&set); + CPU_SET(cpu->number, &set); + sched_setaffinity(getpid(), sizeof(set), &set); + } +} + #endif /* _X86INFO_H */ |