Mercurial > hg > Game > Cerium
changeset 1955:2573919e0d72 draft
MMAP change Task to Function
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 07 Feb 2014 15:08:03 +0900 |
parents | 30b95f372a0d |
children | b52fe4cceff3 5891ed42d21e |
files | example/regex_mas/Func.h example/regex_mas/main.cc example/regex_mas/ppe/Read.cc example/regex_mas/task_init.cc |
diffstat | 4 files changed, 20 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/example/regex_mas/Func.h Thu Feb 06 20:08:08 2014 +0900 +++ b/example/regex_mas/Func.h Fri Feb 07 15:08:03 2014 +0900 @@ -1,7 +1,6 @@ enum { #include "SysTasks.h" READ_TASK, - MMAP, TASK_EXEC, RUN_TASK_BLOCKS, PRINT_TASK,
--- a/example/regex_mas/main.cc Thu Feb 06 20:08:08 2014 +0900 +++ b/example/regex_mas/main.cc Fri Feb 07 15:08:03 2014 +0900 @@ -54,40 +54,37 @@ off_t size; } st_mmap_t; -/*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/ -static unsigned long long -fix_byte(unsigned long long size,int fix_byte_size) +static void +my_mmap(char *filename, WordCount *w) { - size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; - - return size; -} - -SchedDefineTask1(MMAP,my_mmap); - -static int -my_mmap(SchedTask *s, void *in, void *out) -{ - WordCountPtr w = (WordCountPtr)in; /*マッピングだよ!*/ - int map = MAP_PRIVATE; st_mmap_t st_mmap; + struct stat sb; + long fd = w->fd; - int fd = w->fd; - st_mmap.size = fix_byte(w->read_filesize,4096); - w->file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); + if ((fd=open(filename,O_RDONLY,0666))==0) { + fprintf(stderr,"can't open %s\n",filename); + } + + if (fstat(fd,&sb)) { + fprintf(stderr,"can't fstat %s\n",filename); + } + + printf("file size %d\n",(int)sb.st_size); + + w->file_mmap = (char*)mmap(NULL,w->read_filesize,PROT_READ,map,fd,(off_t)0); if (st_mmap.file_mmap == (caddr_t)-1) { fprintf(stderr,"Can't mmap file\n"); - perror(NULL); exit(0); } - return 0; + return ; } + static void run_tasks(SchedTask *manager, WordCount *w, int task_count,HTaskPtr t_read, HTaskPtr t_next, int size) { @@ -249,15 +246,13 @@ w->fd = fd; w->read_filesize = sb->st_size; - HTaskPtr r_read = NULL; if (divide_read_flag != 0) { printf("[divide read mode]\n"); w->file_mmap = (char*)manager->allocate(w->read_filesize); }else { printf("[mmap mode]\n"); - r_read = manager->create_task(MMAP , (memaddr)&w->self, sizeof(memaddr),0,0); - r_read->spawn(); + my_mmap(filename, w); }
--- a/example/regex_mas/ppe/Read.cc Thu Feb 06 20:08:08 2014 +0900 +++ b/example/regex_mas/ppe/Read.cc Fri Feb 07 15:08:03 2014 +0900 @@ -19,10 +19,10 @@ { long fd = (long)s->get_param(0); long start_read_position = (long)s->get_param(1); - long end_read_position = (long)s->get_param(2) - 1; + long end_read_position = (long)s->get_param(2); char *read_text = (char*)s->get_output(wbuf,0); - long read_size = end_read_position - start_read_position + 1; + long read_size = end_read_position - start_read_position; //char *read_text = (char*)s->get_output(wbuf,0); //s->printf("[read No %d : wbuf addr 0x%llx]\n",task_number,read_text);
--- a/example/regex_mas/task_init.cc Thu Feb 06 20:08:08 2014 +0900 +++ b/example/regex_mas/task_init.cc Fri Feb 07 15:08:03 2014 +0900 @@ -7,7 +7,6 @@ /* 必ずこの位置に書いて */ SchedExternTask(TASK_EXEC); SchedExternTask(READ_TASK); -SchedExternTask(MMAP); SchedExternTask(RUN_TASK_BLOCKS); SchedExternTask(PRINT_TASK); @@ -26,7 +25,6 @@ SchedRegister(TASK_EXEC); SchedRegister(READ_TASK); - SchedRegister(MMAP); SchedRegister(RUN_TASK_BLOCKS); SchedRegister(PRINT_TASK); }