提交 2391829d 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

Merge branch 'scale-amd64' of ssh://amsterdam.csail.mit.edu/home/am0/6.828/xv6 into scale-amd64

......@@ -12,7 +12,7 @@ dolevel(int fd, int depth)
{
if (depth > 0) {
int it = 0;
wq_for_serial<int>(it,
wq_for<int>(it,
[](int &it)->bool { return it < branch; },
[&fd, &depth](int i)->void
{
......
......@@ -54,6 +54,7 @@ public:
}
}
release(&lock_);
cprintf("filetable::allocfd: failed\n");
return -1;
}
......
......@@ -173,7 +173,6 @@ void finishproc(struct proc*);
void exit(void);
int fork(int);
int growproc(int);
int kill(int);
void pinit(void);
void procdumpall(void);
void scheduler(void) __noret__;
......
......@@ -41,7 +41,13 @@ struct mtrace_stacks {
};
#endif
enum procstate { EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
typedef enum procstate {
EMBRYO,
SLEEPING,
RUNNABLE,
RUNNING,
ZOMBIE
} procstate_t;;
// Per-process state
struct proc : public rcu_freed {
......@@ -80,12 +86,14 @@ struct proc : public rcu_freed {
LIST_ENTRY(proc) cv_sleep; // Linked list of processes sleeping on a cv
u64 user_fs_;
virtual void do_gc(void) { delete this; }
void set_state(enum procstate s);
enum procstate get_state(void) const { return state_; }
int set_cpu_pin(int cpu);
static proc* alloc();
void set_state(procstate_t s);
procstate_t get_state(void) const { return state_; }
int set_cpu_pin(int cpu);
static int kill(int pid);
int kill();
virtual void do_gc(void) { delete this; }
private:
proc(int npid);
......@@ -94,5 +102,5 @@ private:
proc(const proc& x);
NEW_DELETE_OPS(proc);
enum procstate state_; // Process state
procstate_t state_; // Process state
};
......@@ -15,7 +15,6 @@
#include "wq.hh"
#include "cilk.hh"
#define USTACKPAGES 2
#define BRK (USERTOP >> 1)
struct eargs {
......
......@@ -264,18 +264,11 @@ initproc(void)
// Process won't exit until it returns
// to user space (see trap in trap.c).
int
kill(int pid)
proc::kill(void)
{
struct proc *p;
p = xnspid->lookup(pid);
if (p == 0) {
panic("kill");
return -1;
}
acquire(&p->lock);
p->killed = 1;
if(p->get_state() == SLEEPING){
acquire(&lock);
killed = 1;
if(get_state() == SLEEPING) {
// XXX
// we need to wake p up if it is cv_sleep()ing.
// can't change p from SLEEPING to RUNNABLE since that
......@@ -287,10 +280,23 @@ kill(int pid)
// cv might be deallocated while we're using it
// (pipes dynamically allocate condvars).
}
release(&p->lock);
release(&lock);
return 0;
}
int
proc::kill(int pid)
{
struct proc *p;
p = xnspid->lookup(pid);
if (p == 0) {
panic("kill");
return -1;
}
return p->kill();
}
// Print a process listing to console. For debugging.
// Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
......
......@@ -275,9 +275,8 @@ sys_openat(int dirfd, const char *path, int omode)
if (dirfd == AT_FDCWD) {
cwd = myproc()->cwd;
} else if (dirfd < 0 || dirfd >= NOFILE) {
return -1;
} else {
// XXX(sbw) do we need the sref while we touch fdir->ip?
sref<file> fdir;
if (!getfile(dirfd, &fdir) || fdir->type != file::FD_INODE)
return -1;
......
......@@ -33,7 +33,7 @@ sys_wait(void)
long
sys_kill(int pid)
{
return kill(pid);
return proc::kill(pid);
}
long
......
......@@ -277,18 +277,19 @@ uwq::allocworker(void)
p->ftable = ftable_;
struct vmnode *vmn;
if ((vmn = new vmnode(UWQSTACKPAGES)) == nullptr) {
if ((vmn = new vmnode(USTACKPAGES)) == nullptr) {
finishproc(p);
return nullptr;
}
uptr stacktop = ustack_ + (UWQSTACKPAGES*PGSIZE);
uptr stacktop = ustack_ + (USTACKPAGES*PGSIZE);
if (vmap_->insert(vmn, ustack_, 1) < 0) {
delete vmn;
finishproc(p);
return nullptr;
}
ustack_ += (UWQSTACKPAGES*PGSIZE);
// Include a bumper page
ustack_ += (USTACKPAGES*PGSIZE)+PGSIZE;
p->tf->rsp = stacktop - 8;
p->tf->rip = uentry;
......
......@@ -3,33 +3,67 @@
#include "user.h"
#include <stdarg.h>
#include "fmt.hh"
#include "lib.h"
struct outbuf {
char b[128];
int n;
int fd;
};
static void
flushoutbuf(struct outbuf* b)
{
int i = 0;
int r;
while (b->n != 0) {
r = write(b->fd, &b->b[i], b->n);
if (r == 0 || r < 0) {
b->n = 0;
} else {
b->n -= r;
i += r;
}
}
}
// Print to the given fd.
static void
writec(int c, void *arg)
writeoutbuf(int c, void *arg)
{
int fd = (int) (u64) arg;
write(fd, &c, 1);
struct outbuf* b = (struct outbuf*)arg;
if (b->n == NELEM(b->b))
flushoutbuf(b);
b->b[b->n] = c;
b->n++;
}
void
fprintf(int fd, const char *fmt, ...)
{
struct outbuf b;
va_list ap;
b.n = 0;
b.fd = fd;
va_start(ap, fmt);
vprintfmt(writec, (void*) (u64)fd, fmt, ap);
vprintfmt(writeoutbuf, (void*) &b, fmt, ap);
va_end(ap);
flushoutbuf(&b);
}
void
printf(const char *fmt, ...)
{
struct outbuf b;
va_list ap;
b.n = 0;
b.fd = 1;
va_start(ap, fmt);
vprintfmt(writec, (void*) 1, fmt, ap);
vprintfmt(writeoutbuf, (void*) &b, fmt, ap);
va_end(ap);
flushoutbuf(&b);
}
// Print to a buffer.
......@@ -69,11 +103,15 @@ snprintf(char *buf, u32 n, const char *fmt, ...)
void __attribute__((noreturn))
die(const char* errstr, ...)
{
struct outbuf b;
va_list ap;
b.n = 0;
b.fd = 2;
va_start(ap, errstr);
vprintfmt(writec, (void*) (u64)1, errstr, ap);
vprintfmt(writeoutbuf, (void*)&b, errstr, ap);
va_end(ap);
flushoutbuf(&b);
fprintf(2, "\n");
exit();
}
......@@ -2,7 +2,7 @@
#define DEBUG 0
#define NPROC 64 // maximum number of processes
#define KSTACKSIZE 8192 // size of per-process kernel stack
#define NOFILE 16 // open files per process
#define NOFILE 64 // open files per process
#define NFILE 100 // open files per system
#define NBUF 10000 // size of disk block cache
#define NINODE 5000 // maximum number of active i-nodes
......@@ -24,7 +24,7 @@
#define ALLOC_MEMSET DEBUG
#define KSHAREDSIZE (32 << 10)
#define USERWQSIZE (1 << 14)
#define UWQSTACKPAGES 2
#define USTACKPAGES 4
#define WQSHIFT 7
#define CILKENABLE 0
#if defined(HW_josmp)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论