Mercurial > hg > Members > kono > Cerium
changeset 230:2b114977852d
fix Random
author | gongo@localhost.localdomain |
---|---|
date | Fri, 13 Feb 2009 10:53:58 +0900 |
parents | 401b55a4a4dd |
children | 4bfa24811786 |
files | TaskManager/Cell/spe/SchedTask.cc TaskManager/Cell/spe/SchedTaskList.cc TaskManager/ChangeLog TaskManager/kernel/ppe/Random.cc example/many_task/main.cc example/many_task/sort.cc example/many_task/spe/QuickSort.cc include/TaskManager/Random.h |
diffstat | 8 files changed, 46 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Cell/spe/SchedTask.cc Thu Feb 12 19:05:02 2009 +0900 +++ b/TaskManager/Cell/spe/SchedTask.cc Fri Feb 13 10:53:58 2009 +0900 @@ -110,6 +110,8 @@ sizeof(ListData), DMA_READ_IN_LIST); __scheduler->dma_load(__outListData, (uint32)__task->outData, sizeof(ListData), DMA_READ_OUT_LIST); + __scheduler->dma_wait(DMA_READ_IN_LIST); + __scheduler->dma_wait(DMA_READ_OUT_LIST); __taskGroup = new TaskGroup; __taskGroup->command = __task->self; @@ -151,6 +153,7 @@ // load Input Data __readbuf = __scheduler->allocate(__inListData->size); __scheduler->dma_loadList(__inListData, __readbuf, DMA_READ); + __scheduler->dma_wait(DMA_READ); (this->*ex_read)(); } @@ -188,6 +191,7 @@ // 書き込む領域がなければ無視 if (__outListData->size > 0 || __outListData->length > 0) { __scheduler->dma_storeList(__outListData, __writebuf, DMA_WRITE); + __scheduler->dma_wait(DMA_WRITE); } (this->*ex_exec)();
--- a/TaskManager/Cell/spe/SchedTaskList.cc Thu Feb 12 19:05:02 2009 +0900 +++ b/TaskManager/Cell/spe/SchedTaskList.cc Fri Feb 13 10:53:58 2009 +0900 @@ -57,6 +57,8 @@ delete p; + scheduler->dma_wait(DMA_READ_TASKLIST); + if (list->length < 1) { nextSched = new SchedNop2Ready(scheduler);
--- a/TaskManager/ChangeLog Thu Feb 12 19:05:02 2009 +0900 +++ b/TaskManager/ChangeLog Fri Feb 13 10:53:58 2009 +0900 @@ -1,3 +1,9 @@ +2009-02-13 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> + + * kernel/ppe/Random.cc (reset): fix + urandom -> random 茯c + gettimeofday() с seed 羆 + 2009-02-12 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> * add: kernel/ppe/Random.cc
--- a/TaskManager/kernel/ppe/Random.cc Thu Feb 12 19:05:02 2009 +0900 +++ b/TaskManager/kernel/ppe/Random.cc Fri Feb 13 10:53:58 2009 +0900 @@ -1,23 +1,14 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/time.h> #include "Random.h" /** - * /dev/random 緇ゃ seed 篏帥 + * /dev/urandom, random 緇ゃ seed 篏帥 */ Random::Random(void) { - FILE *fp; - unsigned int seed; - - if ((fp = fopen("/dev/random", "r")) == NULL) { - seed = 12345; - } else { - fread(&seed, sizeof(unsigned int), 1, fp); - fclose(fp); - } - - srandom(seed); + reset(); } /** @@ -28,6 +19,34 @@ srandom(seed); } +void +Random::reset(void) +{ + FILE *fp; + unsigned int seed; + struct timeval tv; + + fp = fopen("/dev/urandom", "r"); + if (!fp) fp = fopen("/dev/random", "r"); + + if (fp) { + int res = fread(&seed, sizeof(unsigned int), 1, fp); + if (res != sizeof(unsigned int)) { + fclose(fp); + fp = NULL; + } + } + + if (!fp) { + gettimeofday(&tv, NULL); + seed = (tv.tv_sec ^ tv.tv_usec); + } else { + fclose(fp); + } + + srandom(seed); +} + int Random::getData(void) {
--- a/example/many_task/main.cc Thu Feb 12 19:05:02 2009 +0900 +++ b/example/many_task/main.cc Fri Feb 13 10:53:58 2009 +0900 @@ -88,6 +88,6 @@ TMend(void) { ed_time = getTime(); - show_data(); + //show_data(); printf("Time: %0.6f\n",ed_time-st_time); }
--- a/example/many_task/sort.cc Thu Feb 12 19:05:02 2009 +0900 +++ b/example/many_task/sort.cc Fri Feb 13 10:53:58 2009 +0900 @@ -1,4 +1,3 @@ -#include <stdlib.h> #include "TaskManager.h" #include "sort.h" #include "Func.h" @@ -16,28 +15,6 @@ static void sort_restart(void *); static void sort_start(void); - -/** - * set random seed - */ -static void -set_seed(void) -{ - FILE *fp; - unsigned int seed; - - if ((fp = fopen("/dev/random", "r")) == NULL) { - seed = 12345; - goto FINISH; - } - - fread(&seed, sizeof(unsigned int), 1, fp); - fclose(fp); - -FINISH: - srandom(seed); -} - /** * 筝ゃ block data 違 MAX_BLOCK_SIZE 莇 * len 我違菴 @@ -91,7 +68,6 @@ fsort[i]->add_inData(&data[i*block_num], sizeof(Data)*block_num); fsort[i]->add_outData(&data[i*block_num], sizeof(Data)*block_num); fsort[i]->add_param(block_num); - fsort[i]->add_param(i*block_num); fsort[i]->set_cpu(SPE_ANY); } @@ -103,7 +79,6 @@ fsort[i]->add_inData(&data[i*block_num], sizeof(Data)*last_block_num); fsort[i]->add_outData(&data[i*block_num], sizeof(Data)*last_block_num); fsort[i]->add_param(last_block_num); - fsort[i]->add_param(i*block_num); fsort[i]->set_cpu(SPE_ANY); } @@ -117,7 +92,6 @@ bsort[i]->add_outData(&data[i*block_num+half_block_num], sizeof(Data)*block_num); bsort[i]->add_param(block_num); - bsort[i]->add_param(i*block_num + half_block_num); bsort[i]->set_cpu(SPE_ANY); } @@ -130,7 +104,6 @@ bsort[i]->add_outData(&data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num); bsort[i]->add_param(last_half_block_num); - bsort[i]->add_param(i*block_num + half_block_num); bsort[i]->set_cpu(SPE_ANY); } @@ -153,10 +126,8 @@ data = (DataPtr)manager->allocate(sizeof(Data)*length); data_length = length; - set_seed(); - for (int i = 0; i < length; i++) { - data[i].index = random()%10000; + data[i].index = manager->get_random()%10000; data[i].ptr = 0; }
--- a/example/many_task/spe/QuickSort.cc Thu Feb 12 19:05:02 2009 +0900 +++ b/example/many_task/spe/QuickSort.cc Fri Feb 13 10:53:58 2009 +0900 @@ -4,18 +4,6 @@ SchedDefineTask(QuickSort); -static void -check_data(DataPtr data, int length) -{ - for (int i = 0; i < length-1; i++) { - if (data[i].index > data[i+1].index) { - printf("error!!\n"); - } else { - printf("%d < %d\n", data[i].index, data[i+1].index); - } - } -} - int QuickSort::run(void* rbuff, void* wbuff) { int begin = 0; @@ -23,10 +11,7 @@ DataPtr r_data = (DataPtr)smanager->get_input(0); DataPtr w_data = (DataPtr)smanager->get_output(0); - int real_start = smanager->get_param(1); - quick_sort(r_data, begin, end-1); - //check_data(r_data, end); //bubble_sort(r_data, begin, end-1); memcpy(w_data, r_data, sizeof(Data)*end);