Benchmarking stuff

上级 c63a4bc8
#include "types.h" #include "types.h"
#include "user.h" #include "user.h"
#include "amd64.h" #include "amd64.h"
#include "lib.h"
static u64 static u64
time_this(const char *av[]) time_this(const char *av[])
...@@ -64,17 +65,24 @@ struct TimedExec : public Bench ...@@ -64,17 +65,24 @@ struct TimedExec : public Bench
struct LoopsBench : public Bench struct LoopsBench : public Bench
{ {
static const int runs = 1;
LoopsBench(const char *cmd, int nloops, int cpuinc) : LoopsBench(const char *cmd, int nloops, int cpuinc) :
Bench(), cmd_(cmd), nloops_(nloops), cpuinc_(cpuinc) {} Bench(), cmd_(cmd), nloops_(nloops), cpuinc_(cpuinc) {}
char* runone(int ncore, const char** argv, char *res, int n) { char* runone(int ncore, const char** argv, char *res, int n) {
char cores[16]; u64 min = ~0ull;
char cores[16];
snprintf(cores, sizeof(cores), "%u", ncore); snprintf(cores, sizeof(cores), "%u", ncore);
argv[1] = cores; argv[1] = cores;
u64 r = time_this(argv); for (int i = 0; i < runs; i++) {
// r in usecs u64 r = time_this(argv);
r = (r*(1000*1000)) / cpuhz(); // r in usecs
snprintf(res, n, "%u %lu %lu\n", ncore, r, nloops_); r = (r*(1000*1000)) / cpuhz();
min = MIN(r, min);
}
snprintf(res, n, "%u %lu %lu\n", ncore, min, nloops_);
return res + strlen(res); return res + strlen(res);
} }
......
#if defined(LINUX)
#include <pthread.h>
#include "user/util.h"
#include "types.h"
#include <assert.h>
#include <sys/wait.h>
#include <unistd.h>
#else
#include "types.h" #include "types.h"
#include "stat.h" #include "stat.h"
#include "user.h" #include "user.h"
...@@ -5,7 +13,8 @@ ...@@ -5,7 +13,8 @@
#include "uspinlock.h" #include "uspinlock.h"
#include "mtrace.h" #include "mtrace.h"
#include "pthread.h" #include "pthread.h"
#endif
#include "xsys.h"
#include <sys/mman.h> #include <sys/mman.h>
enum { readaccess = 1 }; enum { readaccess = 1 };
...@@ -20,8 +29,9 @@ void* ...@@ -20,8 +29,9 @@ void*
thr(void *arg) thr(void *arg)
{ {
u64 tid = (u64)arg; u64 tid = (u64)arg;
if (setaffinity(tid) < 0) if (setaffinity(tid) < 0)
fprintf(1, "setaffinity err\n"); die("setaffinity err");
pthread_barrier_wait(&bar); pthread_barrier_wait(&bar);
...@@ -32,13 +42,12 @@ thr(void *arg) ...@@ -32,13 +42,12 @@ thr(void *arg)
for (int i = 0; i < niter; i++) { for (int i = 0; i < niter; i++) {
if (verbose && ((i % 100) == 0)) if (verbose && ((i % 100) == 0))
fprintf(1, "%d: %d ops\n", tid, i); printf("%d: %d ops\n", tid, i);
volatile char *p = (char*) (0x100000000UL + tid * npg * 0x100000); volatile char *p = (char*) (0x100000000UL + tid * npg * 0x100000);
if (mmap((void *) p, npg * 4096, PROT_READ|PROT_WRITE, if (mmap((void *) p, npg * 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) { MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) {
fprintf(1, "%d: map failed\n", tid); die("%d: map failed", tid);
exit();
} }
if (readaccess) { if (readaccess) {
...@@ -47,8 +56,7 @@ thr(void *arg) ...@@ -47,8 +56,7 @@ thr(void *arg)
} }
if (munmap((void *) p, npg * 4096) < 0) { if (munmap((void *) p, npg * 4096) < 0) {
fprintf(1, "%d: unmap failed\n", tid); die("%d: unmap failed\n", tid);
exit();
} }
} }
return 0; return 0;
...@@ -71,15 +79,15 @@ main(int ac, char **av) ...@@ -71,15 +79,15 @@ main(int ac, char **av)
for(u64 i = 0; i < nthread; i++) { for(u64 i = 0; i < nthread; i++) {
pthread_t tid; pthread_t tid;
pthread_create(&tid, 0, thr, (void*) i); pthread_create(&tid, 0, thr, (void*) i);
if (0) fprintf(1, "mapbench[%d]: child %d\n", getpid(), tid); if (0) printf("mapbench[%d]: child %d\n", getpid(), tid);
} }
for(int i = 0; i < nthread; i++) for(int i = 0; i < nthread; i++)
wait(); xwait();
mtdisable("xv6-asharing"); mtdisable("xv6-asharing");
// fprintf(1, "mapbench[%d]: done\n", getpid()); // fprintf(1, "mapbench[%d]: done\n", getpid());
// halt(); // halt();
exit(); xexit();
} }
...@@ -14,6 +14,7 @@ static inline void xwait() ...@@ -14,6 +14,7 @@ static inline void xwait()
#define xmkdir(pathname) mkdir((pathname), S_IWUSR|S_IRUSR); #define xmkdir(pathname) mkdir((pathname), S_IWUSR|S_IRUSR);
#define xcreat(name) open((name), O_CREATE|O_RDWR, S_IRUSR|S_IWUSR) #define xcreat(name) open((name), O_CREATE|O_RDWR, S_IRUSR|S_IWUSR)
#define mtenable(x) do { } while(0) #define mtenable(x) do { } while(0)
#define mtenable_type(x, y) do { } while (0)
#define mtdisable(x) do { } while(0) #define mtdisable(x) do { } while(0)
#else // Must be xv6 #else // Must be xv6
......
...@@ -23,4 +23,4 @@ $(O)/%: $(O)/user/%.o ...@@ -23,4 +23,4 @@ $(O)/%: $(O)/user/%.o
.PRECIOUS: $(O)/user/%.o .PRECIOUS: $(O)/user/%.o
-include $(O)/user/*.d -include $(O)/user/*.d
ALL := $(O)/filebench $(O)/dirbench ALL := $(O)/filebench $(O)/dirbench $(O)/mapbench
...@@ -32,7 +32,7 @@ edie(const char* errstr, ...) ...@@ -32,7 +32,7 @@ edie(const char* errstr, ...)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static inline void static inline int
setaffinity(int c) setaffinity(int c)
{ {
cpu_set_t cpuset; cpu_set_t cpuset;
...@@ -40,6 +40,7 @@ setaffinity(int c) ...@@ -40,6 +40,7 @@ setaffinity(int c)
CPU_SET(c, &cpuset); CPU_SET(c, &cpuset);
if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0) if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0)
edie("setaffinity, sched_setaffinity failed"); edie("setaffinity, sched_setaffinity failed");
return 0;
} }
static inline uint64_t static inline uint64_t
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论