提交 20caefe7 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

mapbench

上级 ec4b9a8b
......@@ -182,6 +182,7 @@ UPROGS=\
_sleep\
_maptest\
_forktree\
_mapbench\
fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
......
......@@ -15,22 +15,6 @@ printf(int fd, char *s, ...)
write(fd, s, strlen(s));
}
char*
strncpy(char *s, const char *t, int n)
{
int tlen = strlen((char *)t);
memmove(s, (char *)t, n > tlen ? tlen : n);
if (n > tlen)
s[tlen] = 0;
return s;
}
void*
memcpy(void *dst, const void *src, uint n)
{
return memmove(dst, (void *)src, n);
}
void
forktest(void)
{
......
......@@ -6,22 +6,6 @@
#define NCHILD 2
#define NDEPTH 5
char*
strncpy(char *s, const char *t, int n)
{
int tlen = strlen((char *)t);
memmove(s, (char *)t, n > tlen ? tlen : n);
if (n > tlen)
s[tlen] = 0;
return s;
}
void*
memcpy(void *dst, const void *src, uint n)
{
return memmove(dst, (void *)src, n);
}
void
forktree(void)
{
......
#include "types.h"
#include "stat.h"
#include "user.h"
#include "xv6-mtrace.h"
#include "x86.h"
#include "uspinlock.h"
static struct uspinlock l;
static volatile uint tcount;
enum { nthread = 4 };
void
thr(uint tid)
{
for (uint i = 0; i < 100; i++) {
volatile char *p = (char*) (0x40000 + tid * 8 * 4096);
if (map((void *) p, 8 * 4096) < 0) {
printf(1, "%d: map failed\n", tid);
exit();
}
for (uint j = 0; j < 8 * 4096; j++)
p[j] = '\0';
if (unmap((void *) p, 8 * 4096) < 0) {
printf(1, "%d: unmap failed\n", tid);
exit();
}
}
acquire(&l);
// printf(1, "mapbench[%d]: done\n", getpid());
tcount++;
release(&l);
exit();
}
int
main(void)
{
mtrace_enable_set(1, "xv6-mapbench");
acquire(&l);
printf(1, "mapbench[%d]: start esp %x\n", getpid(), resp());
for(uint i = 0; i < nthread; i++) {
sbrk(4096);
uint *tstack = (uint*) sbrk(0);
tstack[-1] = i;
int tid = forkt(&tstack[-2], thr);
if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid);
}
for(;;){
uint lastc = tcount;
// printf(1, "mapbench[%d]: tcount=%d\n", getpid(), lastc);
release(&l);
if(lastc==nthread)
break;
while(tcount==lastc)
__asm __volatile("");
acquire(&l);
}
release(&l);
printf(1, "mapbench[%d]: done\n", getpid());
for(uint i = 0; i < nthread; i++)
wait();
mtrace_enable_set(0, "xv6-mapbench");
halt();
exit();
}
......@@ -56,7 +56,7 @@ allocproc(void)
p->epoch = INF;
p->cpuid = cpu->id;
snprintf(p->lockname, sizeof(p->lockname), "proc%d", p->pid);
snprintf(p->lockname, sizeof(p->lockname), "proc:%d", p->pid);
initlock(&p->lock, p->lockname);
initcondvar(&p->cv, p->lockname);
......@@ -502,8 +502,10 @@ scheduler(void)
panic("non-runnable process on runq\n");
STAILQ_REMOVE(&runq->runq, p, proc, run_next);
if (idle[cpu->id])
if (idle[cpu->id]) {
// cprintf("%d: no longer idle, running %d\n", cpu->id, p->pid);
idle[cpu->id] = 0;
}
release(&runq->lock);
// Switch to chosen process. It is the process's job
......@@ -531,8 +533,10 @@ scheduler(void)
if(p==0) {
release(&runq->lock);
if (!steal())
if (!steal() && !idle[cpu->id]) {
// cprintf("%d: idle\n", cpu->id);
idle[cpu->id] = 1;
}
}
}
}
......
......@@ -52,6 +52,7 @@ struct vma {
enum vmatype va_type;
struct vmnode *n;
struct spinlock lock; // serialize fault/unmap
char lockname[16];
};
// An address space: a set of vmas plus h/w page table.
......@@ -62,6 +63,7 @@ struct vmap {
uint ref;
uint alloc;
pde_t *pgdir; // Page table
char lockname[16];
};
// Per-process state
......
......@@ -5,6 +5,16 @@
#include "x86.h"
char*
strncpy(char *s, const char *t, int n)
{
int tlen = strlen((char *)t);
memmove(s, (char *)t, n > tlen ? tlen : n);
if (n > tlen)
s[tlen] = 0;
return s;
}
char*
strcpy(char *s, char *t)
{
char *os;
......@@ -93,6 +103,12 @@ atoi(const char *s)
}
void*
memcpy(void *dst, const void *src, uint n)
{
return memmove(dst, (void *)src, n);
}
void*
memmove(void *vdst, void *vsrc, int n)
{
char *dst, *src;
......
......@@ -1543,17 +1543,6 @@ unopentest(void)
printf(stdout, "concurrent unlink/open ok\n");
}
// for mtrace-magic.h
char*
strncpy(char *s, const char *t, int n)
{
int tlen = strlen((char *)t);
memmove(s, (char *)t, n > tlen ? tlen : n);
if (n > tlen)
s[tlen] = 0;
return s;
}
int
main(int argc, char *argv[])
{
......
......@@ -341,13 +341,17 @@ struct vmap *
vmap_alloc(void)
{
struct vmap *m = kmalloc(sizeof(struct vmap));
if (m == 0) return 0;
if (m == 0)
return 0;
memset(m, 0, sizeof(struct vmap));
for(uint j = 0; j < NELEM(m->e); j++){
m->e[j].va_type = PRIVATE;
m->e[j].lock.name = "vma";
snprintf(m->e[j].lockname, sizeof(m->e[j].lockname), "vma:%p", &m->e[j]);
initlock(&m->e[j].lock, m->e[j].lockname);
}
m->lock.name = "vmap";
snprintf(m->lockname, sizeof(m->lockname), "vmap:%p", m);
initlock(&m->lock, m->lockname);
m->ref = 1;
m->pgdir = setupkvm();
if (m->pgdir == 0) {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论