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

More ns.c and proc.c stuff.

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