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

More ns.c and proc.c stuff.

上级 dc16e760
...@@ -5,6 +5,7 @@ OBJS = \ ...@@ -5,6 +5,7 @@ OBJS = \
cga.o \ cga.o \
condvar.o \ condvar.o \
console.o \ console.o \
fs.o \
lapic.o \ lapic.o \
kalloc.o \ kalloc.o \
main.o \ main.o \
......
#include "types.h"
#include "kernel.h"
#include "fs.h"
int
namecmp(const char *s, const char *t)
{
return strncmp(s, t, DIRSIZ);
}
#if 0
// File system implementation. Four layers: // File system implementation. Four layers:
// + Blocks: allocator for raw disk blocks. // + Blocks: allocator for raw disk blocks.
// + Files: inode allocator, reading, writing, metadata. // + Files: inode allocator, reading, writing, metadata.
...@@ -764,3 +775,4 @@ nameiparent(char *path, char *name) ...@@ -764,3 +775,4 @@ nameiparent(char *path, char *name)
{ {
return namex(path, 1, name); return namex(path, 1, name);
} }
#endif
// Directory is a file containing a sequence of dirent structures.
#define DIRSIZ 14
#if 0
// On-disk file system format. // On-disk file system format.
// Both the kernel and user programs use this header file. // Both the kernel and user programs use this header file.
...@@ -51,3 +55,4 @@ struct dirent { ...@@ -51,3 +55,4 @@ struct dirent {
char name[DIRSIZ]; char name[DIRSIZ];
}; };
#endif
...@@ -25,6 +25,9 @@ void cv_wakeup(struct condvar *cv); ...@@ -25,6 +25,9 @@ void cv_wakeup(struct condvar *cv);
void cprintf(const char*, ...); void cprintf(const char*, ...);
void panic(const char*) __attribute__((noreturn)); void panic(const char*) __attribute__((noreturn));
// fs.c
int namecmp(const char*, const char*);
// kalloc.c // kalloc.c
char* kalloc(void); char* kalloc(void);
void kfree(void *); void kfree(void *);
...@@ -75,7 +78,7 @@ struct nskey { ...@@ -75,7 +78,7 @@ struct nskey {
void nsinit(void); void nsinit(void);
struct ns* nsalloc(int allowdup); struct ns* nsalloc(int allowdup);
void nsfree(struct ns*); void nsfree(struct ns*);
int ns_allockey(struct ns*); u64 ns_allockey(struct ns*);
int ns_insert(struct ns*, struct nskey key, void*); int ns_insert(struct ns*, struct nskey key, void*);
void* ns_lookup(struct ns*, struct nskey key); void* ns_lookup(struct ns*, struct nskey key);
void* ns_remove(struct ns *ns, struct nskey key, void *val); // removed val void* ns_remove(struct ns *ns, struct nskey key, void *val); // removed val
...@@ -98,6 +101,17 @@ int wait(void); ...@@ -98,6 +101,17 @@ int wait(void);
void yield(void); void yield(void);
void migrate(struct proc *); void migrate(struct proc *);
// rcu.c
void rcuinit(void);
void rcu_begin_write(struct spinlock *);
void rcu_end_write(struct spinlock *);
void rcu_begin_read(void);
void rcu_end_read(void);
void rcu_delayed(void*, void (*dofree)(void*));
void rcu_delayed2(int, u64, void (*dofree)(int, u64));
void rcu_gc(void);
void rcu_gc_worker(void);
// spinlock.c // spinlock.c
void acquire(struct spinlock*); void acquire(struct spinlock*);
void getcallerpcs(void*, uptr*); void getcallerpcs(void*, uptr*);
......
...@@ -12,6 +12,7 @@ extern void initseg(void); ...@@ -12,6 +12,7 @@ extern void initseg(void);
extern void inittrap(void); extern void inittrap(void);
extern void initkalloc(void); extern void initkalloc(void);
extern void initrcu(void); extern void initrcu(void);
extern void initproc(void);
void void
cmain(void) cmain(void)
...@@ -28,6 +29,7 @@ cmain(void) ...@@ -28,6 +29,7 @@ cmain(void)
initkalloc(); initkalloc();
initrcu(); // initialize rcu module initrcu(); // initialize rcu module
initproc();
cprintf("ncpu %d\n", ncpu); cprintf("ncpu %d\n", ncpu);
panic("end"); panic("end");
......
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
void *
ns_enumerate(struct ns *ns, void *(*f)(void *, void *, void *), void *arg)
{
panic("ns_enumerate");
}
#if 0
#include "types.h"
#include "defs.h"
#include "spinlock.h" #include "spinlock.h"
#include "param.h" #include "param.h"
#include "fs.h" #include "fs.h"
...@@ -29,16 +19,16 @@ struct elem { ...@@ -29,16 +19,16 @@ struct elem {
int next_lock; int next_lock;
struct elem * volatile next; struct elem * volatile next;
union { union {
uint ikey; u64 ikey;
struct { struct {
uint a; u64 a;
uint b; u64 b;
} iikey; } iikey;
char skey[0]; char skey[0];
char dnkey[DIRSIZ]; char dnkey[DIRSIZ];
struct { struct {
uint a; u64 a;
uint b; u64 b;
char s[0]; char s[0];
} iiskey; } iiskey;
}; };
...@@ -50,7 +40,7 @@ struct bucket { ...@@ -50,7 +40,7 @@ struct bucket {
struct ns { struct ns {
int allowdup; int allowdup;
uint nextkey; u64 nextkey;
struct bucket table[NHASH]; struct bucket table[NHASH];
}; };
...@@ -120,7 +110,7 @@ elemalloc(struct nskey *k) ...@@ -120,7 +110,7 @@ elemalloc(struct nskey *k)
return e; return e;
} }
static int static u64
h(struct nskey *k) h(struct nskey *k)
{ {
switch (k->type) { switch (k->type) {
...@@ -188,10 +178,10 @@ cmpkey(struct elem *e, struct nskey *k) ...@@ -188,10 +178,10 @@ cmpkey(struct elem *e, struct nskey *k)
} }
// XXX need something more scalable; partition the name space? // XXX need something more scalable; partition the name space?
int u64
ns_allockey(struct ns *ns) ns_allockey(struct ns *ns)
{ {
uint n = __sync_fetch_and_add(&ns->nextkey, 1); u64 n = __sync_fetch_and_add(&ns->nextkey, 1);
return n; return n;
} }
...@@ -202,7 +192,7 @@ ns_insert(struct ns *ns, struct nskey key, void *val) ...@@ -202,7 +192,7 @@ ns_insert(struct ns *ns, struct nskey key, void *val)
if (e) { if (e) {
setkey(e, &key); setkey(e, &key);
e->val = val; e->val = val;
uint i = h(&key); u64 i = h(&key);
rcu_begin_write(0); rcu_begin_write(0);
retry: retry:
...@@ -231,7 +221,7 @@ ns_insert(struct ns *ns, struct nskey key, void *val) ...@@ -231,7 +221,7 @@ ns_insert(struct ns *ns, struct nskey key, void *val)
void* void*
ns_lookup(struct ns *ns, struct nskey key) ns_lookup(struct ns *ns, struct nskey key)
{ {
uint i = h(&key); u64 i = h(&key);
rcu_begin_read(); rcu_begin_read();
struct elem *e = ns->table[i].chain; struct elem *e = ns->table[i].chain;
...@@ -251,7 +241,7 @@ ns_lookup(struct ns *ns, struct nskey key) ...@@ -251,7 +241,7 @@ ns_lookup(struct ns *ns, struct nskey key)
void* void*
ns_remove(struct ns *ns, struct nskey key, void *v) ns_remove(struct ns *ns, struct nskey key, void *v)
{ {
uint i = h(&key); u64 i = h(&key);
rcu_begin_write(0); rcu_begin_write(0);
retry: retry:
...@@ -315,7 +305,7 @@ ns_enumerate(struct ns *ns, void *(*f)(void *, void *, void *), void *arg) ...@@ -315,7 +305,7 @@ ns_enumerate(struct ns *ns, void *(*f)(void *, void *, void *), void *arg)
void * void *
ns_enumerate_key(struct ns *ns, struct nskey key, void *(*f)(void *, void *), void *arg) ns_enumerate_key(struct ns *ns, struct nskey key, void *(*f)(void *, void *), void *arg)
{ {
uint i = h(&key); u64 i = h(&key);
rcu_begin_read(); rcu_begin_read();
struct elem *e = ns->table[i].chain; struct elem *e = ns->table[i].chain;
while (e) { while (e) {
...@@ -331,4 +321,3 @@ ns_enumerate_key(struct ns *ns, struct nskey key, void *(*f)(void *, void *), vo ...@@ -331,4 +321,3 @@ ns_enumerate_key(struct ns *ns, struct nskey key, void *(*f)(void *, void *), vo
rcu_end_read(); rcu_end_read();
return 0; return 0;
} }
#endif
...@@ -25,6 +25,26 @@ addrun(struct proc *p) ...@@ -25,6 +25,26 @@ addrun(struct proc *p)
panic("addrun"); panic("addrun");
} }
void
initproc(void)
{
int c;
nspid = nsalloc(0);
if (nspid == 0)
panic("pinit");
nsrunq = nsalloc(1);
if (nsrunq == 0)
panic("pinit runq");
for (c = 0; c < NCPU; c++)
idle[c] = 1;
}
#if 0 #if 0
extern void forkret(void); extern void forkret(void);
extern void trapret(void); extern void trapret(void);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论