diff --git a/kernel/Makefile b/kernel/Makefile index 124b945c..489d4e67 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,4 +1,5 @@ -BUILD_TARGET = mee knf +#BUILD_TARGET = mee knf +BUILD_TARGET = knf SRC = $(CURDIR) AALBASE ?= $(SRC)/../../aal/manycore diff --git a/kernel/include/uio.h b/kernel/include/uio.h new file mode 100644 index 00000000..78f531d1 --- /dev/null +++ b/kernel/include/uio.h @@ -0,0 +1,27 @@ +#ifndef __UIO_H +#define __UIO_H + +struct iovec +{ + void *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */ + size_t iov_len; /* Must be size_t (1003.1g) */ +}; + +/* + * Total number of bytes covered by an iovec. + * + * NOTE that it is not safe to use this function until all the iovec's + * segment lengths have been validated. Because the individual lengths can + * overflow a size_t when added together. + */ +static inline size_t iov_length(const struct iovec *iov, unsigned long nr_segs) +{ + unsigned long seg; + size_t ret = 0; + + for (seg = 0; seg < nr_segs; seg++) + ret += iov[seg].iov_len; + return ret; +} + +#endif diff --git a/kernel/syscall.c b/kernel/syscall.c index 05feeb6f..554316d0 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -9,6 +9,17 @@ #include #include #include +#include + +#define SYSCALL_BY_IKC + +#define DEBUG_PRINT_SC + +#ifdef DEBUG_PRINT_SC +#define dkprintf kprintf +#else +#define dkprintf(...) +#endif int memcpy_async(unsigned long dest, unsigned long src, unsigned long len, int wait, unsigned long *notify); @@ -45,15 +56,23 @@ static void send_syscall(struct syscall_request *req) #endif } -static int do_syscall(struct syscall_request *req) +static int do_syscall(struct syscall_request *req, aal_mc_user_context_t *ctx) { struct syscall_response *res = cpu_local_var(scp).response_va; send_syscall(req); + dkprintf("SC(%d)[%3d] waiting for host.. \n", + aal_mc_get_processor_id(), + req->number); + while (!res->status) { cpu_pause(); } + + dkprintf("SC(%d)[%3d] got host reply: %d \n", + aal_mc_get_processor_id(), + req->number, res->ret); return res->ret; } @@ -105,7 +124,7 @@ long sys_brk(int n, aal_mc_user_context_t *ctx) SYSCALL_ARG_##a0(0); SYSCALL_ARG_##a1(1); \ SYSCALL_ARG_##a2(2); SYSCALL_ARG_##a3(3) -#define SYSCALL_FOOTER return do_syscall(&request) +#define SYSCALL_FOOTER return do_syscall(&request, ctx) SYSCALL_DECLARE(fstat) { @@ -187,7 +206,7 @@ SYSCALL_DECLARE(lseek) SYSCALL_DECLARE(exit_group) { SYSCALL_HEADER; - do_syscall(&request); + do_syscall(&request, ctx); free_process_memory(cpu_local_var(current)); cpu_local_var(next) = &cpu_local_var(idle); @@ -218,7 +237,7 @@ SYSCALL_DECLARE(mmap) return -EINVAL; } } - kprintf("Non-anonymous mmap: fd = %lx, %lx\n", + dkprintf("Non-anonymous mmap: fd = %lx, %lx\n", aal_mc_syscall_arg4(ctx), aal_mc_syscall_arg5(ctx)); while(1); } @@ -243,6 +262,7 @@ SYSCALL_DECLARE(uname) { SYSCALL_HEADER; unsigned long phys; + int ret; if (aal_mc_pt_virt_to_phys(cpu_local_var(current)->vm->page_table, (void *)aal_mc_syscall_arg0(ctx), &phys)) { @@ -252,7 +272,9 @@ SYSCALL_DECLARE(uname) request.number = n; request.args[0] = phys; - return do_syscall(&request); + ret = do_syscall(&request, ctx); + + return ret; } long sys_getxid(int n, aal_mc_user_context_t *ctx) @@ -261,7 +283,7 @@ long sys_getxid(int n, aal_mc_user_context_t *ctx) request.number = n; - return do_syscall(&request); + return do_syscall(&request, ctx); } long sys_arch_prctl(int n, aal_mc_user_context_t *ctx) @@ -293,7 +315,7 @@ SYSCALL_DECLARE(clone) aal_mc_syscall_arg1(ctx)); /* XXX Assign new pid! */ new->pid = cpu_local_var(current)->pid; - kprintf("Cloned: %p \n", new); + dkprintf("Cloned: %p \n", new); aal_mc_syscall_ret(new->uctx) = 0; @@ -301,11 +323,50 @@ SYSCALL_DECLARE(clone) request.number = n; request.args[0] = (unsigned long)new; /* Sync */ - do_syscall(&request); - kprintf("Clone ret.\n"); + do_syscall(&request, ctx); + dkprintf("Clone ret.\n"); return new->pid; } + +SYSCALL_DECLARE(writev) +{ + /* Adhoc implementation of writev calling write sequentially */ + struct syscall_request request AAL_DMA_ALIGN; + unsigned long seg; + size_t seg_ret, ret = 0; + + int fd = aal_mc_syscall_arg0(ctx); + struct iovec *iov = (struct iovec*)aal_mc_syscall_arg1(ctx); + unsigned long nr_segs = aal_mc_syscall_arg2(ctx); + + for (seg = 0; seg < nr_segs; ++seg) { + unsigned long __phys; + + if (aal_mc_pt_virt_to_phys(cpu_local_var(current)->vm->page_table, + (void *)iov[seg].iov_base, &__phys)) { + return -EFAULT; + } + + request.number = 1; /* write */ + request.args[0] = fd; + request.args[1] = __phys; + request.args[2] = iov[seg].iov_len; + + seg_ret = do_syscall(&request, ctx); + + if (seg_ret < 0) { + ret = -EFAULT; + break; + } + + ret += seg_ret; + } + + return ret; +} + + static long (*syscall_table[])(int, aal_mc_user_context_t *) = { [0] = sys_read, [1] = sys_write, @@ -319,6 +380,7 @@ static long (*syscall_table[])(int, aal_mc_user_context_t *) = { [16] = sys_ioctl, [17] = sys_pread, [18] = sys_pwrite, + [20] = sys_writev, [39] = sys_getpid, [56] = sys_clone, [63] = sys_uname, @@ -338,27 +400,23 @@ long syscall(int num, aal_mc_user_context_t *ctx) cpu_enable_interrupt(); -#ifdef DEBUG_PRINT_SC - kprintf("SC(%d)[%3d](%lx, %lx) @ %lx | %lx = ", + dkprintf("SC(%d)[%3d](%lx, %lx) @ %lx | %lx = ", aal_mc_get_processor_id(), num, aal_mc_syscall_arg0(ctx), aal_mc_syscall_arg1(ctx), aal_mc_syscall_pc(ctx), aal_mc_syscall_sp(ctx)); -#endif if (syscall_table[num]) { l = syscall_table[num](num, ctx); -#ifdef DEBUG_PRINT_SC - kprintf(" %lx\n", l); -#endif + dkprintf(" %lx\n", l); return l; } else { - kprintf("USC[%3d](%lx, %lx, %lx, %lx, %lx) @ %lx | %lx\n", num, + dkprintf("USC[%3d](%lx, %lx, %lx, %lx, %lx) @ %lx | %lx\n", num, aal_mc_syscall_arg0(ctx), aal_mc_syscall_arg1(ctx), aal_mc_syscall_arg2(ctx), aal_mc_syscall_arg3(ctx), aal_mc_syscall_arg4(ctx), aal_mc_syscall_pc(ctx), aal_mc_syscall_sp(ctx)); - while(1); + //while(1); return -ENOSYS; } } diff --git a/linux/executer/Makefile b/linux/executer/Makefile index ef502e60..c7de1161 100644 --- a/linux/executer/Makefile +++ b/linux/executer/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -O3 +CFLAGS = -O3 -Wall -g all: mcexec diff --git a/linux/executer/mcexec.c b/linux/executer/mcexec.c index cbf36cec..b4a74c3b 100644 --- a/linux/executer/mcexec.c +++ b/linux/executer/mcexec.c @@ -17,6 +17,8 @@ #include #include +#define DEBUG + #ifndef DEBUG #define __dprint(msg, ...) #define __dprintf(arg, ...) @@ -220,9 +222,9 @@ int main(int argc, char **argv) fprintf(stderr, "Error: Failed to open /dev/mcctrl.\n"); return 1; } - fdm = open("/dev/mem", O_RDWR); + fdm = open("/dev/fmem", O_RDWR); if (fdm < 0) { - fprintf(stderr, "Error: Failed to open /dev/mem.\n"); + fprintf(stderr, "Error: Failed to open /dev/fmem.\n"); return 1; } @@ -299,14 +301,20 @@ int main_loop(int fd, int cpu) w.cpu = cpu; while (ioctl(fd, MCEXEC_UP_WAIT_SYSCALL, (unsigned long)&w) == 0) { + + __dprintf("got syscall: %d\n", w.sr.number); + switch (w.sr.number) { case __NR_open: dma_buf[256] = 0; - do_syscall_load(fd, cpu, dma_buf_pa, w.sr.args[0], 256); - + + do_syscall_load(fd, cpu, dma_buf, w.sr.args[0], 256); + /* while (!dma_buf[256]) { asm volatile ("" : : : "memory"); } + */ + ret = open(dma_buf, w.sr.args[1], w.sr.args[2]); SET_ERR(ret); do_syscall_return(fd, cpu, ret, 0, 0, 0, 0); @@ -321,19 +329,21 @@ int main_loop(int fd, int cpu) case __NR_read: ret = read(w.sr.args[0], dma_buf, w.sr.args[2]); SET_ERR(ret); - do_syscall_return(fd, cpu, ret, 1, dma_buf_pa, + do_syscall_return(fd, cpu, ret, 1, dma_buf, w.sr.args[1], w.sr.args[2]); break; case __NR_write: dma_buf[w.sr.args[2]] = 0; SET_ERR(ret); - do_syscall_load(fd, cpu, dma_buf_pa, + do_syscall_load(fd, cpu, dma_buf, w.sr.args[1], w.sr.args[2]); + /* while (!dma_buf[w.sr.args[2]]) { asm volatile ("" : : : "memory"); } + */ ret = write(w.sr.args[0], dma_buf, w.sr.args[2]); do_syscall_return(fd, cpu, ret, 0, 0, 0, 0); @@ -347,18 +357,20 @@ int main_loop(int fd, int cpu) case __NR_pread64: ret = pread(w.sr.args[0], dma_buf, w.sr.args[2], w.sr.args[3]); - do_syscall_return(fd, cpu, ret, 1, dma_buf_pa, + do_syscall_return(fd, cpu, ret, 1, dma_buf, w.sr.args[1], w.sr.args[2]); break; case __NR_pwrite64: dma_buf[w.sr.args[2]] = 0; - do_syscall_load(fd, cpu, dma_buf_pa, + do_syscall_load(fd, cpu, dma_buf, w.sr.args[1], w.sr.args[2]); + /* while (!dma_buf[w.sr.args[2]]) { asm volatile ("" : : : "memory"); } + */ ret = pwrite(w.sr.args[0], dma_buf, w.sr.args[2], w.sr.args[3]); @@ -371,7 +383,7 @@ int main_loop(int fd, int cpu) if (ret == -1) { ret = -errno; } - do_syscall_return(fd, cpu, ret, 1, dma_buf_pa, + do_syscall_return(fd, cpu, ret, 1, dma_buf, w.sr.args[1], sizeof(struct stat)); break; @@ -382,7 +394,7 @@ int main_loop(int fd, int cpu) if (ret == -1) { ret = -errno; } - do_syscall_return(fd, cpu, ret, 1, dma_buf_pa, + do_syscall_return(fd, cpu, ret, 1, dma_buf, w.sr.args[2], sizeof(struct kernel_termios) ); @@ -413,7 +425,7 @@ int main_loop(int fd, int cpu) ret = -errno; } do_syscall_return(fd, - cpu, ret, 1, dma_buf_pa, w.sr.args[0], + cpu, ret, 1, dma_buf, w.sr.args[0], sizeof(struct utsname)); break; default: diff --git a/linux/mod_mcctrl/Makefile b/linux/mod_mcctrl/Makefile index 438567f4..a9f16588 100644 --- a/linux/mod_mcctrl/Makefile +++ b/linux/mod_mcctrl/Makefile @@ -1,8 +1,10 @@ -ifeq ($(K),"current") + +#ifeq ($(K),"current") KDIR=/lib/modules/`uname -r `/build -else -KDIR=../target -endif +#else +#KDIR=../target +#endif + obj-m += mcctrl.o diff --git a/linux/mod_mcctrl/control.c b/linux/mod_mcctrl/control.c index 58bc21a5..38995626 100644 --- a/linux/mod_mcctrl/control.c +++ b/linux/mod_mcctrl/control.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "mcctrl.h" #ifdef DEBUG @@ -145,9 +146,10 @@ int mcexec_syscall(struct mcctrl_channel *c, unsigned long arg) return 0; } - +#ifndef DO_USER_MODE int __do_in_kernel_syscall(aal_os_t os, struct mcctrl_channel *c, struct syscall_request *sc); +#endif static int remaining_job, base_cpu, job_pos; extern int num_channels; @@ -251,29 +253,52 @@ long mcexec_pin_region(aal_os_t os, unsigned long *__user uaddress) long mcexec_load_syscall(aal_os_t os, struct syscall_load_desc *__user arg) { struct syscall_load_desc desc; + unsigned long phys; + void *rpm; + + if (copy_from_user(&desc, arg, sizeof(struct syscall_load_desc))) { + return -EFAULT; + } + + phys = aal_device_map_memory(aal_os_to_dev(os), desc.src, desc.size); + rpm = ioremap_wc(phys, desc.size); + + printk("mcexec_load_syscall: %s (desc.size: %d)\n", rpm, desc.size); + + if (copy_to_user((void *__user)desc.dest, rpm, desc.size)) { + return -EFAULT; + } + + iounmap(rpm); + aal_device_unmap_memory(aal_os_to_dev(os), phys, desc.size); + +/* aal_dma_channel_t channel; struct aal_dma_request request; + unsigned long dma_status = 0; channel = aal_device_get_dma_channel(aal_os_to_dev(os), 0); if (!channel) { return -EINVAL; } - if (copy_from_user(&desc, arg, sizeof(struct syscall_load_desc))) { - return -EFAULT; - } - memset(&request, 0, sizeof(request)); request.src_os = os; request.src_phys = desc.src; request.dest_os = NULL; request.dest_phys = desc.dest; request.size = desc.size; - request.notify = (void *)(desc.dest + desc.size); + request.notify = (void *)virt_to_phys(&dma_status); request.priv = (void *)1; aal_dma_request(channel, &request); + while (!dma_status) { + mb(); + udelay(1); + } +*/ + return 0; } @@ -308,7 +333,10 @@ long mcexec_ret_syscall(aal_os_t os, struct syscall_ret_desc *__user arg) ret.size); rpm = ioremap_wc(phys, ret.size); - memcpy(rpm, phys_to_virt(ret.src), ret.size); + if (copy_from_user(rpm, (void *__user)ret.src, ret.size)) { + return -EFAULT; + } + mc->param.response_va->status = 1; iounmap(rpm); diff --git a/linux/mod_mcctrl/mcctrl.h b/linux/mod_mcctrl/mcctrl.h index b37e82df..8f9d604a 100644 --- a/linux/mod_mcctrl/mcctrl.h +++ b/linux/mod_mcctrl/mcctrl.h @@ -16,6 +16,8 @@ #define DMA_PIN_SHIFT 21 +#define DO_USER_MODE + struct ikc_scd_packet { int msg; int ref; diff --git a/linux/mod_mcctrl/syscall.c b/linux/mod_mcctrl/syscall.c index ef46deac..2e1d4a63 100644 --- a/linux/mod_mcctrl/syscall.c +++ b/linux/mod_mcctrl/syscall.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "mcctrl.h" #define ALIGN_WAIT_BUF(z) (((z + 63) >> 6) << 6) @@ -112,10 +113,14 @@ static unsigned long translate_remote_va(struct mcctrl_channel *c, return -EFAULT; } + unsigned long last_thread_exec = 0; extern struct mcctrl_channel *channels; +#ifndef DO_USER_MODE + + int __do_in_kernel_syscall(aal_os_t os, struct mcctrl_channel *c, struct syscall_request *sc) { @@ -230,3 +235,4 @@ int __do_in_kernel_syscall(aal_os_t os, struct mcctrl_channel *c, } } } +#endif /* DO_USER_MODE */