提交 d3c7235d 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

maptest and thrtest.c

上级 0c7ee376
...@@ -67,6 +67,7 @@ UPROGS= \ ...@@ -67,6 +67,7 @@ UPROGS= \
_mapbench \ _mapbench \
_maptest \ _maptest \
_sh \ _sh \
_thrtest \
%.o: %.c %.o: %.c
@echo " CC $@" @echo " CC $@"
......
...@@ -11,8 +11,10 @@ enum { nthread = 4 }; ...@@ -11,8 +11,10 @@ enum { nthread = 4 };
enum { readaccess = 0 }; enum { readaccess = 0 };
void void
thr(int tid) thr(void *arg)
{ {
u64 tid = (u64)arg;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
volatile char *p = (char*) (0x40000UL + tid * 8 * 4096); volatile char *p = (char*) (0x40000UL + tid * 8 * 4096);
if (map((void *) p, 8 * 4096) < 0) { if (map((void *) p, 8 * 4096) < 0) {
...@@ -35,7 +37,6 @@ thr(int tid) ...@@ -35,7 +37,6 @@ thr(int tid)
// printf(1, "mapbench[%d]: done\n", getpid()); // printf(1, "mapbench[%d]: done\n", getpid());
tcount++; tcount++;
release(&l); release(&l);
exit();
} }
int int
...@@ -47,9 +48,10 @@ main(void) ...@@ -47,9 +48,10 @@ main(void)
printf(1, "mapbench[%d]: start esp %x\n", getpid(), rrsp()); printf(1, "mapbench[%d]: start esp %x\n", getpid(), rrsp());
for(int i = 0; i < nthread; i++) { for(int i = 0; i < nthread; i++) {
sbrk(4096); sbrk(8192);
void *tstack = sbrk(0); void *tstack = sbrk(0);
int tid = forkt(tstack, thr); printf(1, "tstack %lx\n", tstack);
int tid = forkt(tstack, thr, (void *)(u64)i);
if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid); if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid);
} }
......
...@@ -55,7 +55,7 @@ main(void) ...@@ -55,7 +55,7 @@ main(void)
} }
sbrk(4096); sbrk(4096);
forkt(sbrk(0), thr); forkt(sbrk(0), thr, 0);
acquire(&l); acquire(&l);
state = 1; state = 1;
......
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
#include "uspinlock.h" #include "uspinlock.h"
static struct uspinlock l; static struct uspinlock l;
static volatile uint tcount; static volatile int tcount;
enum { nthread = 4 }; enum { nthread = 4 };
void void
thr(uint arg) thr(void *arg)
{ {
acquire(&l); acquire(&l);
printf(1, "thrtest[%d]: arg 0x%x esp %x\n", getpid(), arg, resp()); printf(1, "thrtest[%d]: arg 0x%lx rsp %lx\n", getpid(), arg, rrsp());
tcount++; tcount++;
release(&l); release(&l);
exit(); exit();
...@@ -23,19 +23,17 @@ int ...@@ -23,19 +23,17 @@ int
main(void) main(void)
{ {
acquire(&l); acquire(&l);
printf(1, "thrtest[%d]: start esp %x\n", getpid(), resp()); printf(1, "thrtest[%d]: start esp %x\n", getpid(), rrsp());
for(uint i = 0; i < nthread; i++) { for(int i = 0; i < nthread; i++) {
sbrk(4096); sbrk(4096);
uint *tstack = (uint*) sbrk(0); void *tstack = sbrk(0);
tstack[-1] = 0xc0ffee00 | i; int tid = forkt(tstack, thr, (void*)(u64)(0xc0ffee00|i));
int tid = forkt(&tstack[-2], thr);
printf(1, "thrtest[%d]: child %d\n", getpid(), tid); printf(1, "thrtest[%d]: child %d\n", getpid(), tid);
} }
for(;;){ for(;;){
uint lastc = tcount; int lastc = tcount;
printf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc); printf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc);
release(&l); release(&l);
if(lastc==nthread) if(lastc==nthread)
...@@ -47,7 +45,7 @@ main(void) ...@@ -47,7 +45,7 @@ main(void)
release(&l); release(&l);
printf(1, "thrtest[%d]: done\n", getpid()); printf(1, "thrtest[%d]: done\n", getpid());
for(uint i = 0; i < nthread; i++) for(int i = 0; i < nthread; i++)
wait(); wait();
exit(); exit();
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论