Mercurial > hg > Game > Cerium
changeset 1864:7211816380bd draft
implement my_mmap in fileread
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 24 Dec 2013 19:16:49 +0900 |
parents | 3f058fee44d2 |
children | a009522ed6c6 |
files | example/fileread/Func.h example/fileread/main.cc example/fileread/ppe/Read.cc example/fileread/task_init.cc |
diffstat | 4 files changed, 54 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/example/fileread/Func.h Tue Dec 24 17:56:24 2013 +0900 +++ b/example/fileread/Func.h Tue Dec 24 19:16:49 2013 +0900 @@ -3,5 +3,6 @@ Read_task, Print_task, RUN_BLOCKS, + MMAP, };
--- a/example/fileread/main.cc Tue Dec 24 17:56:24 2013 +0900 +++ b/example/fileread/main.cc Tue Dec 24 19:16:49 2013 +0900 @@ -3,6 +3,8 @@ #include <string.h> #include <sys/stat.h> #include <sys/time.h> +#include <sys/types.h> +#include <sys/mman.h> #include "TaskManager.h" #include "SchedTask.h" #include "Func.h" @@ -12,6 +14,7 @@ static double st_time; static double ed_time; static int spe_num = 1; +int divide_read_flag = 0; static CPU_TYPE spe_cpu = SPE_ANY; static int DIVISION_SIZE = 4096 * 4; @@ -31,6 +34,11 @@ CPU_TYPE cpu; } Fileread, *FilereadPtr; +typedef struct { + caddr_t file_mmap; + off_t size; +} st_mmap_t; + SchedDefineTask1(RUN_BLOCKS,run16); static int @@ -94,6 +102,8 @@ spe_num = atoi(argv[i+1]); } else if (strcmp(argv[i], "-file") == 0) { filename = argv[i+1]; + } else if (strcmp(argv[i], "-dr") == 0) { + divide_read_flag = 1; } } @@ -105,6 +115,36 @@ return filename; } + +SchedDefineTask1(MMAP,my_mmap); + +static int +my_mmap(SchedTask *s, void *in, void *out) +{ + + FilereadPtr fr = (FilereadPtr)in; + /*マッピングだよ!*/ + + int map = MAP_PRIVATE; + st_mmap_t st_mmap; + + int fd = fr->fd; + st_mmap.size = fr->filesize; + st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,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); + } + + //printf("%s\n",st_mmap.file_mmap); + printf("in mmap\n"); + + return 0; +} + + static void run_start(TaskManager *manager,char *filename) { @@ -135,8 +175,14 @@ printf("one_task_size: %ld\n",fr->division_size); printf("task_num : %ld\n",fr->task_num); - HTaskPtr run = manager->create_task(RUN_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0); - run->spawn(); + if (divide_read_flag != 0) { + HTaskPtr run = manager->create_task(RUN_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0); + run->spawn(); + }else { + //my_mmap(filename, fd, fr); + HTaskPtr run = manager->create_task(MMAP , (memaddr)&fr->self, sizeof(memaddr),0,0); + run->spawn(); + } }
--- a/example/fileread/ppe/Read.cc Tue Dec 24 17:56:24 2013 +0900 +++ b/example/fileread/ppe/Read.cc Tue Dec 24 19:16:49 2013 +0900 @@ -26,8 +26,8 @@ pread(fd, text, (long)read_size , division_size*task_number); - s->printf("[start task No. %d]\n",task_number); - s->printf("%s\n",text); - + //s->printf("[start task No. %d]\n",task_number); + //s->printf("%s\n",text); + s->printf("in divide_read\n"); return 0; }
--- a/example/fileread/task_init.cc Tue Dec 24 17:56:24 2013 +0900 +++ b/example/fileread/task_init.cc Tue Dec 24 19:16:49 2013 +0900 @@ -5,6 +5,7 @@ SchedExternTask(Read_task); SchedExternTask(Print_task); SchedExternTask(RUN_BLOCKS); +SchedExternTask(MMAP); /** * この関数は ../spe/spe-main と違って @@ -18,4 +19,5 @@ SchedRegister(Read_task); SchedRegister(Print_task); SchedRegister(RUN_BLOCKS); + SchedRegister(MMAP); }