diff options
author | Dave Jones <davej@redhat.com> | 2008-07-02 18:07:05 -0400 |
---|---|---|
committer | Dave Jones <davej@redhat.com> | 2008-07-02 18:07:05 -0400 |
commit | f3a8e170cb0ce8198afff6249ff0694cbeffdb90 (patch) | |
tree | 44ed86b98ccbb0f4207ce1b950b7190f2a5c3b88 /bench | |
parent | a2f50d9087f18494df86fde9376bd62cf9dea982 (diff) |
Make the benchmarks code work again
Diffstat (limited to 'bench')
-rw-r--r-- | bench/MHz.c | 11 | ||||
-rw-r--r-- | bench/bench.h | 31 | ||||
-rw-r--r-- | bench/benchmarks.c | 20 |
3 files changed, 34 insertions, 28 deletions
diff --git a/bench/MHz.c b/bench/MHz.c index 187aa28..521ac76 100644 --- a/bench/MHz.c +++ b/bench/MHz.c @@ -16,16 +16,7 @@ #include <signal.h> #include "../x86info.h" - -static inline unsigned long long int rdtsc(void) -{ - unsigned int low, high; - unsigned long tsc; - - __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)); - tsc = ((unsigned long long) high << 32) | low; - return tsc; -} +#include "bench.h" static volatile int nosignal = 0; diff --git a/bench/bench.h b/bench/bench.h index 0eb578f..b463dfa 100644 --- a/bench/bench.h +++ b/bench/bench.h @@ -1,21 +1,22 @@ -#define rdtsc() ({ unsigned long a,d; asm volatile("rdtsc":"=a" (a), "=d" (d)); a; }) +static inline unsigned long long int rdtsc(void) +{ + unsigned int low, high; + unsigned long tsc; + + __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)); + tsc = ((unsigned long long) high << 32) | low; + return tsc; +} #define NREPS 1000 #define TIME(x,y) \ { \ - int i,j; \ - unsigned long bmin,bstart,bend; \ - for (j=0; j<100; j++) { \ - bmin = 100000; \ - bstart = rdtsc(); \ - for (i=0; i<NREPS; i++) \ - x; \ - bend = rdtsc(); \ - bend -= bstart; \ - if (bend < bmin) \ - bmin = bend; \ - } \ - printf(y ": %ld cycles\n", bmin/NREPS); \ + int i; \ + unsigned long bstart, bend; \ + bstart = rdtsc(); \ + for (i=0; i<NREPS; i++) \ + x; \ + bend = rdtsc(); \ + printf(y ": %ld cycles\n", ((bend-bstart)/NREPS)); \ } - diff --git a/bench/benchmarks.c b/bench/benchmarks.c index 49ff008..b311000 100644 --- a/bench/benchmarks.c +++ b/bench/benchmarks.c @@ -9,20 +9,34 @@ #include <asm/unistd.h> #endif -void show_benchmarks(void) +#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); + } + #ifdef __linux__ TIME(asm volatile("int $0x80" :"=a" (tmp) :"0" (__NR_getppid)), "int 0x80"); #endif TIME(asm volatile("cpuid": : :"ax", "dx", "cx", "bx"), "cpuid"); - TIME(asm volatile("addl $1,0(%esp)"), "addl"); - TIME(asm volatile("lock ; addl $1,0(%esp)"), "locked add"); + //TIME(asm volatile("addl $1,0(%esp)"), "addl"); + //TIME(asm volatile("lock ; addl $1,0(%esp)"), "locked add"); TIME(asm volatile("bswap %0" : "=r" (tmp) : "0" (tmp)), "bswap"); } |