More pread/syscall stuff

上级 0f906e2c
struct ipcctl {
volatile char done;
volatile long result;
};
#include "types.h"
#include "kernel.h"
#include "spinlock.h"
#include "condvar.h"
#include "cpu.h"
#include "proc.h"
#include "vm.h"
#include "fs.h"
#include "file.h"
#include "wq.h"
#include "ipc.h"
static void
pread_work(struct work *w, void *a0, void *a1, void *a2, void *a3)
{
struct inode *ip = a0;
void *kshared = a1;
struct ipcctl *ipc = kshared;
size_t count = (uptr)a2;
off_t off = (uptr)a3;
int r;
if (count > KSHAREDSIZE-PGSIZE)
panic("pread_work");
//cprintf("1: %p %p %lu %lu\n", ip, buf, count, off);
ilock(ip, 0);
r = readi(ip, kshared+PGSIZE, off, count);
iunlock(ip);
ipc->result = r;
barrier();
ipc->done = 1;
}
static struct work *
pread_allocwork(struct inode *ip, void *buf, size_t count, off_t off)
{
struct work *w = allocwork();
if (w == NULL)
return NULL;
//cprintf("0: %p %p %lu %lu\n", ip, buf, count, off);
w->rip = pread_work;
w->arg0 = ip;
w->arg1 = buf;
w->arg2 = (void*)count;
w->arg3 = (void*)off;
return w;
}
long
sys_kernlet(int fd, size_t count, off_t off)
{
return -1;
struct file *f;
struct work *w;
if(fd < 0 || fd >= NOFILE || (f=myproc()->ofile[fd]) == 0)
return -1;
if(f->type != FD_INODE)
return -1;
w = pread_allocwork(f->ip, myproc()->vmap->kshared, count, off);
if (w == NULL)
return -1;
if (wq_push(w) < 0) {
freework(w);
return -1;
}
return 0;
}
......@@ -3,6 +3,7 @@
#include "fcntl.h"
#include "user.h"
#include "amd64.h"
#include "ipc.h"
// XXX(sbw) add a memlayout.h?
#define KSHARED 0xFFFFF00000000000ull
......@@ -13,11 +14,6 @@
static char buf[BSIZE];
struct ipcctl {
volatile char done;
volatile long result;
};
struct ipcctl *ipcctl = (struct ipcctl*)KSHARED;
static void
......@@ -46,6 +42,12 @@ main(int ac, char **av)
t0 = rdtsc();
for (k = 0; k < FSIZE; k+=PSIZE) {
kernlet_pread(fd, PSIZE, k);
while (ipcctl->done == 0)
nop_pause();
die("preadtest: %d\n", (int)ipcctl->result);
for (i = k; i < k+PSIZE; i+=BSIZE)
if (pread(fd, buf, BSIZE, i) != BSIZE)
die("pread failed");
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论