summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authordavej <davej>2003-01-18 15:15:46 +0000
committerdavej <davej>2003-01-18 15:15:46 +0000
commit7df2a8a6f4a4e1636694ad3a5c9e9940c9cb219f (patch)
tree3bf9b8847f9a7501a7cff27d30dc877229e92585 /bench
parent10ab47e1ba43e0adc6423ed41dc87f691a7cc456 (diff)
Various cleanups and addition of locked add benchmark
Diffstat (limited to 'bench')
-rw-r--r--bench/bench.h14
-rw-r--r--bench/benchmarks.c20
-rw-r--r--bench/cpuid.c32
-rw-r--r--bench/int80h.c26
4 files changed, 31 insertions, 61 deletions
diff --git a/bench/bench.h b/bench/bench.h
index e17009d..1cdd461 100644
--- a/bench/bench.h
+++ b/bench/bench.h
@@ -2,3 +2,17 @@ void time_int80h(void);
void time_cpuid(void);
#define rdtsc() ({ unsigned long a,d; asm volatile("rdtsc":"=a" (a), "=d" (d)); a; })
+
+#define TIME(x,y) \
+ bmin = 100000; \
+ for (i = 0; i < 1000; i++) { \
+ unsigned long bstart,bend; \
+ bstart = rdtsc(); \
+ x; \
+ bend = rdtsc(); \
+ bend -= bstart; \
+ if (bend < bmin) \
+ bmin = bend; \
+ } \
+ printf(y ": %ld cycles\n", bmin);
+
diff --git a/bench/benchmarks.c b/bench/benchmarks.c
index 5860d41..caff045 100644
--- a/bench/benchmarks.c
+++ b/bench/benchmarks.c
@@ -1,7 +1,21 @@
+#include <time.h>
+#include <sys/time.h>
+#include <asm/unistd.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include "../x86info.h"
#include "bench.h"
-void show_benchmarks (void)
+void show_benchmarks()
{
- time_cpuid();
- time_int80h();
+ int i, ret;
+ unsigned long bmin;
+
+ if (show_bench != 1)
+ return;
+
+ TIME(asm volatile("int $0x80" :"=a" (ret) :"0" (__NR_getppid)), "int 0x80");
+ TIME(asm volatile("cpuid": : :"ax", "dx", "cx", "bx"), "cpuid");
+ TIME(asm volatile("lock ; addl $0,0(%esp)"), "locked add");
}
+
diff --git a/bench/cpuid.c b/bench/cpuid.c
deleted file mode 100644
index 389c69a..0000000
--- a/bench/cpuid.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <time.h>
-#include <sys/time.h>
-#include <asm/unistd.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include "../x86info.h"
-#include "bench.h"
-
-static inline void __cpuid(int op, int *eax, int *ebx, int *ecx, int *edx)
-{
- __asm__("cpuid"
- : "=a" (*eax),"=b" (*ebx),"=c" (*ecx),"=d" (*edx)
- : "0" (op));
-}
-
-void time_cpuid()
-{
- int i;
- unsigned long start, end;
- int eax, ebx, ecx, edx;
-
- if (show_bench != 1)
- return;
-
- start = rdtsc();
- for (i = 0; i < 1000000; i++) {
- __cpuid (0, &eax, &ebx, &ecx, &edx);
- }
- end = rdtsc();
- printf("cpuid took %d cycles\n", (end - start) / 1000000);
-}
-
diff --git a/bench/int80h.c b/bench/int80h.c
deleted file mode 100644
index 03227eb..0000000
--- a/bench/int80h.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <time.h>
-#include <sys/time.h>
-#include <asm/unistd.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include "../x86info.h"
-#include "bench.h"
-
-void time_int80h()
-{
- int i, ret;
- unsigned long start, end;
-
- if (show_bench != 1)
- return;
-
- start = rdtsc();
- for (i = 0; i < 1000000; i++) {
- asm volatile("int $0x80"
- :"=a" (ret)
- :"0" (__NR_getppid));
- }
- end = rdtsc();
- printf("int 0x80 took %d cycles\n", (end - start) / 1000000);
-}
-