提交 010080dd 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

Merge commit '03f6bac6' into scale-amd64

......@@ -12,7 +12,7 @@ cat(int fd)
while((n = read(fd, buf, sizeof(buf))) > 0)
write(1, buf, n);
if(n < 0){
printf(1, "cat: read error\n");
fprintf(1, "cat: read error\n");
exit();
}
}
......@@ -29,7 +29,7 @@ main(int argc, char *argv[])
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %s\n", argv[i]);
fprintf(1, "cat: cannot open %s\n", argv[i]);
exit();
}
cat(fd);
......
......@@ -22,7 +22,7 @@ bench(u32 tid)
int fd = open(pn, O_CREATE | O_RDWR);
if (fd < 0)
printf(1, "create failed\n");
fprintf(1, "create failed\n");
close(fd);
}
......@@ -31,7 +31,7 @@ bench(u32 tid)
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, (i % nfile));
int fd = open(pn, O_RDWR);
if (fd < 0)
printf(1, "open failed\n");
fprintf(1, "open failed\n");
close(fd);
}
......@@ -39,7 +39,7 @@ bench(u32 tid)
for (u32 i = 0; i < nfile; i++) {
snprintf(pn, sizeof(pn), "%s/f:%d:%d", dirs[tid], tid, i);
if (unlink(pn) < 0)
printf(1, "unlink failed\n");
fprintf(1, "unlink failed\n");
}
}
......@@ -53,12 +53,12 @@ main(void)
//snprintf(dirs[i], sizeof(dirs[i]), "/db%d", i);
snprintf(dirs[i], sizeof(dirs[i]), "/dbx");
if (mkdir(dirs[i]) < 0)
printf(1, "mkdir failed\n");
fprintf(1, "mkdir failed\n");
}
// mtrace_enable_set(1, "xv6-dirbench");
printf(1, "dirbench[%d]: start\n", getpid());
fprintf(1, "dirbench[%d]: start\n", getpid());
for(u32 i = 0; i < nthread; i++) {
int pid = fork(0);
if (pid == 0)
......@@ -69,7 +69,7 @@ main(void)
wait();
// mtrace_enable_set(0, "xv6-dirbench");
printf(1, "dirbench[%d]: done\n", getpid());
fprintf(1, "dirbench[%d]: done\n", getpid());
// halt();
exit();
}
......@@ -8,6 +8,6 @@ main(int argc, char *argv[])
int i;
for(i = 1; i < argc; i++)
printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
fprintf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
exit();
}
......@@ -14,13 +14,13 @@ execbench(void)
for (int i = 0; i < NITERS; i++) {
int pid = fork(0);
if (pid < 0) {
printf(1, "fork error\n");
fprintf(1, "fork error\n");
exit();
}
if (pid == 0) {
const char *av[] = { "forkexecbench", "x", 0 };
exec("forkexecbench", av);
printf(1, "exec failed\n");
fprintf(1, "exec failed\n");
exit();
} else {
wait();
......@@ -30,7 +30,7 @@ execbench(void)
mtdisable("xv6-forkexecbench");
u64 e = rdtsc();
printf(1, "%lu\n", (e-s) / NITERS);
fprintf(1, "%lu\n", (e-s) / NITERS);
}
int
......
......@@ -10,7 +10,7 @@ void
forktree(int depth)
{
if (depth == 0) {
printf(1, "%d: forkexectree\n", getpid());
fprintf(1, "%d: forkexectree\n", getpid());
mtenable("xv6-forkexectree");
}
......@@ -20,7 +20,7 @@ forktree(int depth)
for (int i = 0; i < NCHILD; i++) {
int pid = fork(0);
if (pid < 0) {
printf(1, "fork error\n");
fprintf(1, "fork error\n");
exit();
}
......@@ -35,13 +35,13 @@ forktree(int depth)
for (int i = 0; i < NCHILD; i++) {
if (wait() < 0) {
printf(1, "wait stopped early\n");
fprintf(1, "wait stopped early\n");
exit();
}
}
if (wait() != -1) {
printf(1, "wait got too many\n");
fprintf(1, "wait got too many\n");
exit();
}
......@@ -51,7 +51,7 @@ forktree(int depth)
mtops(0);
mtdisable("xv6-forkexectree");
printf(1, "%d: forkexectree OK\n", getpid());
fprintf(1, "%d: forkexectree OK\n", getpid());
// halt();
}
......
......@@ -11,7 +11,7 @@ forktree(void)
{
int depth = 0;
printf(1, "%d: fork tree\n", getpid());
fprintf(1, "%d: fork tree\n", getpid());
mtenable("xv6-forktree");
next_level:
......@@ -22,7 +22,7 @@ forktree(void)
for (int i = 0; i < NCHILD; i++) {
int pid = fork(0);
if (pid < 0) {
printf(1, "fork error\n");
fprintf(1, "fork error\n");
exit();
}
......@@ -34,13 +34,13 @@ forktree(void)
for (int i = 0; i < NCHILD; i++) {
if (wait() < 0) {
printf(1, "wait stopped early\n");
fprintf(1, "wait stopped early\n");
exit();
}
}
if (wait() != -1) {
printf(1, "wait got too many\n");
fprintf(1, "wait got too many\n");
exit();
}
......@@ -50,7 +50,7 @@ forktree(void)
mtops(0);
mtdisable("xv6-forktree");
printf(1, "%d: fork tree OK\n", getpid());
fprintf(1, "%d: fork tree OK\n", getpid());
// halt();
}
......
......@@ -16,7 +16,7 @@ static int xwrite(int fd, const void *buf, u64 n)
while (n) {
r = write(fd, buf, n);
if (r < 0 || r == 0) {
printf(1, "xwrite: failed %d\n", r);
fprintf(1, "xwrite: failed %d\n", r);
return -1;
}
buf = (char *) buf + r;
......@@ -59,7 +59,7 @@ error(int s, int code)
r = strlen(buf);
if (xwrite(s, buf, r))
printf(2, "httpd error: incomplete write\n");
fprintf(2, "httpd error: incomplete write\n");
}
static int
......@@ -128,7 +128,7 @@ content(int s, int fd)
for (;;) {
n = read(fd, buf, sizeof(buf));
if (n < 0) {
printf(2, "send_data: read failed %d\n", n);
fprintf(2, "send_data: read failed %d\n", n);
return n;
} else if (n == 0) {
return 0;
......@@ -154,7 +154,7 @@ resp(int s, const char *url)
r = fstat(fd, &stat);
if (r < 0) {
printf(2, "httpd resp: fstat %d\n", r);
fprintf(2, "httpd resp: fstat %d\n", r);
close(fd);
return error(s, 404);
}
......@@ -227,7 +227,7 @@ client(int s)
r = read(s, b, NELEM(b)-1);
if (r < 0)
printf(1, "httpd client: read %d\n", r);
fprintf(1, "httpd client: read %d\n", r);
b[r] = 0;
r = parse(b, &url);
......@@ -236,7 +236,7 @@ client(int s)
return;
}
printf(1, "httpd client: url %s\n", url);
fprintf(1, "httpd client: url %s\n", url);
resp(s, url);
free(url);
}
......@@ -263,7 +263,7 @@ main(void)
if (r < 0)
die("httpd listen: %d\n", r);
printf(1, "httpd: port 80\n");
fprintf(1, "httpd: port 80\n");
for (;;) {
socklen_t socklen;
......@@ -272,10 +272,10 @@ main(void)
socklen = sizeof(sin);
ss = accept(s, (struct sockaddr *)&sin, &socklen);
if (ss < 0) {
printf(2, "telnetd accept: %d\n", ss);
fprintf(2, "telnetd accept: %d\n", ss);
continue;
}
printf(1, "httpd: connection %s\n", ipaddr(&sin));
fprintf(1, "httpd: connection %s\n", ipaddr(&sin));
client(ss);
close(ss);
......
......@@ -21,12 +21,12 @@ startone(const char **argv)
pid = fork(0);
if(pid < 0){
printf(1, "init: fork failed\n");
fprintf(1, "init: fork failed\n");
exit();
}
if(pid == 0){
exec(argv[0], argv);
printf(1, "init: exec %s failed\n", argv[0]);
fprintf(1, "init: exec %s failed\n", argv[0]);
exit();
}
return pid;
......@@ -46,11 +46,11 @@ main(void)
mkdir("dev");
if (mknod("/dev/netif", 2, 1) < 0)
printf(2, "init: mknod netif failed\n");
fprintf(2, "init: mknod netif failed\n");
if (mknod("/dev/sampler", 3, 1) < 0)
printf(2, "init: mknod sampler failed\n");
fprintf(2, "init: mknod sampler failed\n");
if (mknod("/dev/lockstat", 4, 1) < 0)
printf(2, "init: mknod lockstat failed\n");
fprintf(2, "init: mknod lockstat failed\n");
for (u32 i = 0; i < NELEM(app_argv); i++)
startone(app_argv[i]);
......@@ -58,6 +58,6 @@ main(void)
for(;;){
pid = startone(sh_argv);
while((wpid=wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n");
fprintf(1, "zombie!\n");
}
}
......@@ -29,8 +29,8 @@ stats(void)
if (sfd < 0)
die("lockstat: open failed");
printf(1, "## name acquires contends locking locked\n");
printf(sfd, "## name acquires contends locking locked\n");
fprintf(1, "## name acquires contends locking locked\n");
fprintf(sfd, "## name acquires contends locking locked\n");
while (1) {
r = read(fd, &ls, sz);
......@@ -51,9 +51,9 @@ stats(void)
locked += ls.cpu[i].locked;
}
if (contends > 0) {
printf(1, "%s %lu %lu %lu %lu\n",
fprintf(1, "%s %lu %lu %lu %lu\n",
ls.name, acquires, contends, locking, locked);
printf(sfd, "%s %lu %lu %lu %lu\n",
fprintf(sfd, "%s %lu %lu %lu %lu\n",
ls.name, acquires, contends, locking, locked);
}
}
......
......@@ -24,7 +24,7 @@ main(void)
{
const char *pw;
printf(1, "password: ");
fprintf(1, "password: ");
pw = readpw();
if (pw && !strcmp(pw, "xv6")) {
......
......@@ -31,24 +31,24 @@ ls(const char *path)
struct stat st;
if((fd = open(path, 0)) < 0){
printf(2, "ls: cannot open %s\n", path);
fprintf(2, "ls: cannot open %s\n", path);
return;
}
if(fstat(fd, &st) < 0){
printf(2, "ls: cannot stat %s\n", path);
fprintf(2, "ls: cannot stat %s\n", path);
close(fd);
return;
}
switch(st.type){
case T_FILE:
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
fprintf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
break;
case T_DIR:
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
printf(1, "ls: path too long\n");
fprintf(1, "ls: path too long\n");
break;
}
strcpy(buf, path);
......@@ -60,10 +60,10 @@ ls(const char *path)
memmove(p, de.name, DIRSIZ);
p[DIRSIZ] = 0;
if(stat(buf, &st) < 0){
printf(1, "ls: cannot stat %s\n", buf);
fprintf(1, "ls: cannot stat %s\n", buf);
continue;
}
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
fprintf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
}
break;
}
......
......@@ -21,7 +21,7 @@ thr(void *arg)
volatile char *p = (char*) (0x40000UL + tid * 8 * 4096);
if (map((void *) p, 8 * 4096) < 0) {
printf(1, "%d: map failed\n", tid);
fprintf(1, "%d: map failed\n", tid);
exit();
}
......@@ -31,13 +31,13 @@ thr(void *arg)
}
if (unmap((void *) p, 8 * 4096) < 0) {
printf(1, "%d: unmap failed\n", tid);
fprintf(1, "%d: unmap failed\n", tid);
exit();
}
}
acquire(&l);
// printf(1, "mapbench[%d]: done\n", getpid());
// fprintf(1, "mapbench[%d]: done\n", getpid());
tcount++;
release(&l);
}
......@@ -48,26 +48,26 @@ main(int ac, char **av)
mtenable("xv6-mapbench");
if (ac != 2) {
printf(1, "usage: %s nthreads\n", av[0]);
fprintf(1, "usage: %s nthreads\n", av[0]);
exit();
}
int nthread = atoi(av[1]);
acquire(&l);
// printf(1, "mapbench[%d]: start esp %x, nthread=%d\n", getpid(), rrsp(), nthread);
// fprintf(1, "mapbench[%d]: start esp %x, nthread=%d\n", getpid(), rrsp(), nthread);
for(int i = 0; i < nthread; i++) {
sbrk(8192);
void *tstack = sbrk(0);
// printf(1, "tstack %lx\n", tstack);
// fprintf(1, "tstack %lx\n", tstack);
int tid = forkt(tstack, (void*) thr, (void *)(u64)i);
if (0) printf(1, "mapbench[%d]: child %d\n", getpid(), tid);
if (0) fprintf(1, "mapbench[%d]: child %d\n", getpid(), tid);
}
for(;;){
int lastc = tcount;
// printf(1, "mapbench[%d]: tcount=%d\n", getpid(), lastc);
// fprintf(1, "mapbench[%d]: tcount=%d\n", getpid(), lastc);
release(&l);
if(lastc==nthread)
break;
......@@ -76,7 +76,7 @@ main(int ac, char **av)
acquire(&l);
}
release(&l);
// printf(1, "mapbench[%d]: done\n", getpid());
// fprintf(1, "mapbench[%d]: done\n", getpid());
for(int i = 0; i < nthread; i++)
wait();
......
......@@ -30,14 +30,14 @@ thr(void)
if (state == 3) {
state = 4;
printf(1, "about to access after unmap\n");
fprintf(1, "about to access after unmap\n");
release(&l);
p[0] = 'X';
p[4096] = 'Y';
acquire(&l);
printf(1, "still alive after unmap write\n");
fprintf(1, "still alive after unmap write\n");
exit();
}
release(&l);
......@@ -50,7 +50,7 @@ main(void)
{
p = (char *) 0x80000;
if (map((void *) p, 8192) < 0) {
printf(1, "map failed\n");
fprintf(1, "map failed\n");
exit();
}
......@@ -66,25 +66,25 @@ main(void)
}
if (p[0] != 'x' || p[4096] != 'y') {
printf(1, "mismatch\n");
fprintf(1, "mismatch\n");
exit();
}
printf(1, "shm ok\n");
fprintf(1, "shm ok\n");
if (unmap((void *) p, 8192) < 0) {
printf(1, "unmap failed\n");
fprintf(1, "unmap failed\n");
exit();
}
state = 3;
printf(1, "waiting for unmap access\n");
fprintf(1, "waiting for unmap access\n");
while (state != 4) {
release(&l);
spin();
acquire(&l);
}
printf(1, "maptest done\n");
fprintf(1, "maptest done\n");
exit();
}
......@@ -73,7 +73,7 @@ kernlet_pread(int fd, size_t count, off_t off)
msgid = ipc_msg_alloc();
if (msgid == NULL_MSGID) {
printf(2, "kernlet_pread: ipc_alloc_msg failed");
fprintf(2, "kernlet_pread: ipc_alloc_msg failed");
return;
}
......@@ -81,7 +81,7 @@ kernlet_pread(int fd, size_t count, off_t off)
die("kernlet_pread: count oops");
pageid = ipc_page_alloc();
if (pageid == NULL_PAGEID) {
printf(2, "kernlet_pread: ipc_alloc_page failed");
fprintf(2, "kernlet_pread: ipc_alloc_page failed");
return;
}
......@@ -152,8 +152,8 @@ main(int ac, char **av)
}
t1 = rdtsc();
printf(1, "usekernlet %u\n", usekernlet);
printf(1, "cycles %lu\n", t1 - t0);
fprintf(1, "usekernlet %u\n", usekernlet);
fprintf(1, "cycles %lu\n", t1 - t0);
exit();
}
......@@ -13,7 +13,7 @@ writec(int c, void *arg)
}
void
printf(int fd, const char *fmt, ...)
fprintf(int fd, const char *fmt, ...)
{
va_list ap;
......@@ -64,6 +64,6 @@ die(const char* errstr, ...)
va_start(ap, errstr);
vprintfmt(writec, (void*) (u64)1, errstr, ap);
va_end(ap);
printf(1, "\n");
fprintf(2, "\n");
exit();
}
......@@ -76,14 +76,14 @@ runcmd(struct cmd *cmd)
if(ecmd->argv[0] == 0)
exit();
exec(ecmd->argv[0], ecmd->argv);
printf(2, "exec %s failed\n", ecmd->argv[0]);
fprintf(2, "exec %s failed\n", ecmd->argv[0]);
break;
case REDIR:
rcmd = (struct redircmd*)cmd;
close(rcmd->fd);
if(open(rcmd->file, rcmd->mode) < 0){
printf(2, "open %s failed\n", rcmd->file);
fprintf(2, "open %s failed\n", rcmd->file);
exit();
}
runcmd(rcmd->cmd);
......@@ -133,7 +133,7 @@ runcmd(struct cmd *cmd)
int
getcmd(char *buf, int nbuf)
{
printf(2, "$ ");
fprintf(2, "$ ");
memset(buf, 0, nbuf);
gets(buf, nbuf);
if(buf[0] == 0) // EOF
......@@ -162,7 +162,7 @@ main(void)
// Chdir has no effect on the parent if run in the child.
buf[strlen(buf)-1] = 0; // chop \n
if(chdir(buf+3) < 0)
printf(2, "cannot cd %s\n", buf+3);
fprintf(2, "cannot cd %s\n", buf+3);
continue;
}
if(fork1() == 0)
......@@ -175,7 +175,7 @@ main(void)
void
panic(const char *s)
{
printf(2, "%s\n", s);
fprintf(2, "%s\n", s);
exit();
}
......@@ -335,7 +335,7 @@ parsecmd(char *s)
cmd = parseline(&s, es);
peek(&s, es, "");
if(s != es){
printf(2, "leftovers: %s\n", s);
fprintf(2, "leftovers: %s\n", s);
panic("syntax");
}
nulterminate(cmd);
......
......@@ -8,7 +8,7 @@ int
main(int ac, char *av[])
{
if (ac != 2) {
printf(1, "Usage: %s ticks\n", av[0]);
fprintf(1, "Usage: %s ticks\n", av[0]);
exit();
}
......
......@@ -24,7 +24,7 @@ main(void)
if (r < 0)
die("telnetd listen: %d\n", r);
printf(1, "telnetd: port 23\n");
fprintf(1, "telnetd: port 23\n");
for (;;) {
socklen_t socklen;
......@@ -34,14 +34,14 @@ main(void)
socklen = sizeof(sin);
ss = accept(s, (struct sockaddr *)&sin, &socklen);
if (ss < 0) {
printf(2, "telnetd accept: %d\n", ss);
fprintf(2, "telnetd accept: %d\n", ss);
continue;
}
printf(1, "telnetd: connection %s\n", ipaddr(&sin));
fprintf(1, "telnetd: connection %s\n", ipaddr(&sin));
pid = fork(0);
if (pid < 0) {
printf(2, "telnetd fork: %d\n", pid);
fprintf(2, "telnetd fork: %d\n", pid);
close(ss);
continue;
}
......@@ -58,6 +58,6 @@ main(void)
}
close(ss);
wait();
printf(1, "telnetd: connection closed\n");
fprintf(1, "telnetd: connection closed\n");
}
}
......@@ -13,7 +13,7 @@ void
thr(void *arg)
{
acquire(&l);
printf(1, "thrtest[%d]: arg 0x%lx rsp %lx\n", getpid(), arg, rrsp());
fprintf(1, "thrtest[%d]: arg 0x%lx rsp %lx\n", getpid(), arg, rrsp());
tcount++;
release(&l);
exit();
......@@ -23,18 +23,18 @@ int
main(void)
{
acquire(&l);
printf(1, "thrtest[%d]: start esp %x\n", getpid(), rrsp());
fprintf(1, "thrtest[%d]: start esp %x\n", getpid(), rrsp());
for(int i = 0; i < nthread; i++) {
sbrk(8192);
void *tstack = sbrk(0);
int tid = forkt(tstack, (void*) thr, (void*)(u64)(0xc0ffee00|i));
printf(1, "thrtest[%d]: child %d\n", getpid(), tid);
fprintf(1, "thrtest[%d]: child %d\n", getpid(), tid);
}
for(;;){
int lastc = tcount;
printf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc);
fprintf(1, "thrtest[%d]: tcount=%d\n", getpid(), lastc);
release(&l);
if(lastc==nthread)
break;
......@@ -43,7 +43,7 @@ main(void)
acquire(&l);
}
release(&l);
printf(1, "thrtest[%d]: done\n", getpid());
fprintf(1, "thrtest[%d]: done\n", getpid());
for(int i = 0; i < nthread; i++)
wait();
......
......@@ -11,18 +11,18 @@ main(int ac, const char *av[])
int pid = fork(0);
if (pid < 0) {
printf(1, "time: fork failed\n");
fprintf(1, "time: fork failed\n");
exit();
}
if (pid == 0) {
exec(av[1], av+1);
printf(1, "time: exec failed\n");
fprintf(1, "time: exec failed\n");
exit();
}
wait();
u64 t1 = rdtsc();
printf(1, "%lu cycles\n", t1-t0);
fprintf(1, "%lu cycles\n", t1-t0);
exit();
}
......@@ -49,7 +49,7 @@ int atoi(const char*);
int forkt(void *sp, void *pc, void *arg);
// printf.c
void printf(int, const char*, ...);
void fprintf(int, const char*, ...);
void snprintf(char *buf, unsigned int n, const char *fmt, ...);
void die(const char* errstr, ...) __attribute__((noreturn));
END_DECLS
差异被折叠。
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论