int main(int argc, char *argv[]) { FILE **fps; struct timespec start, end; double cpu_time1, cpu_time2; int threadnum = 10; /* printf("Specify number of worker threads: "); scanf("%d", &threadnum); */ /* check file opening */ int k; fps = (FILE **)malloc(threadnum * sizeof(FILE *)); for(k = 0; k < threadnum; k++) { fps[k] = fopen(DICT_FILE, "r"); if (fps[k] == NULL) { printf("cannot open the file\n"); return -1; } } /* build the entry */ entry *pHead, *e; pHead = (entry *) malloc(sizeof(entry)); printf("size of entry : %lu bytes\n", sizeof(entry)); e = pHead; e->pNext = NULL; #if defined(__GNUC__) __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry)); #endif pthread_t *threads = (pthread_t *)malloc(threadnum * sizeof(pthread_t)); thread_data **param = (thread_data **)malloc(threadnum * sizeof(thread_data *)); for(int k=0; k < TABLE_SIZE; k++) { if (pthread_mutex_init(&locks[k], NULL) != 0) { printf("\n mutex init failed\n"); return 1; } } clock_gettime(CLOCK_REALTIME, &start); int err; for(k = 0; k < threadnum; k++) { param[k] = pack_param(fps[k], k, threadnum); err = pthread_create(&threads[k], NULL, (void *) &thread_work, (void *) param[k]); if (err != 0) printf("\ncan't create thread :[%s]", strerror(err)); } for(k = 0; k < threadnum; k++) { pthread_join(threads[k], NULL); } clock_gettime(CLOCK_REALTIME, &end); cpu_time1 = diff_in_second(start, end); /* close file as soon as possible */ for(k = 0; k < threadnum; k++) { fclose(fps[k]); } for(int k=0; k < TABLE_SIZE; k++) { // printf("%d\n", hash_stats[k]); pthread_mutex_destroy(&locks[k]); } e = pHead; /* the givn last name to find */ char input[MAX_LAST_NAME_SIZE] = "zyxel"; e = pHead; assert(findName(input, e) && "Did you implement findName() in " IMPL "?"); assert(0 == strcmp(findName(input, e)->lastName, "zyxel")); #if defined(__GNUC__) __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry)); #endif /* compute the execution time */ clock_gettime(CLOCK_REALTIME, &start); findName(input, e); clock_gettime(CLOCK_REALTIME, &end); cpu_time2 = diff_in_second(start, end); FILE *output; #if defined(OPT) output = fopen("opt.txt", "a"); #else output = fopen("orig.txt", "a"); #endif fprintf(output, "append() findName() %lf %lf\n", cpu_time1, cpu_time2); fclose(output); printf("execution time of append() : %lf sec\n", cpu_time1); printf("execution time of findName() : %lf sec\n", cpu_time2); if (pHead->pNext) free(pHead->pNext); free(pHead); return 0; }
int do_host_autok(int id) { int i, j; int param_count; int vol_count; //std::list<unsigned int> undo_vol_list; struct autok_predata predata; unsigned int *param_list; unsigned int *vol_list; struct autok_predata full_data; std::list<struct res_data*> res_list; std::list<struct res_data*>::iterator it_res; struct res_data *p_res; char devnode[BUF_LEN]=""; char resnode[BUF_LEN]=""; char data_node[BUF_LEN]=""; int need_to_recover = 0; param_count = get_param_count(); printf("Param_count:%d\n", param_count); if(get_nvram_param_count(id)!=param_count){ system("rm -rf /data/autok_*"); system("rm -rf /data/nvram/APCFG/APRDCL/SDIO"); close_nvram(); init_autok_nvram(); need_to_recover = 1; } //duplicate nvram data partition //if(!is_nvram_mode()){ for(i=0; i<VCORE_NO; i++){ //char nvram_node[BUF_LEN]=""; //snprintf(nvram_node, BUF_LEN, "%s/%s_%d_%d", AUTOK_NVRAM_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]); snprintf(data_node, BUF_LEN, "%s/%s_%d_%d", AUTOK_RES_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]); // Check environment // 1. nvram data partition should exist // 2. autok parameter in data partion should not exist // 3. param_count should be the same if(is_nvram_data_exist(id, g_autok_vcore[i])>0 && is_file_valid(data_node)<=0){ //data_copy(nvram_node, data_node); int data_length; char *data_buf; read_from_nvram(id, g_autok_vcore[i], (unsigned char**)&data_buf, &data_length); if(write_to_file(data_node, data_buf, data_length)<0){ free(data_buf); return -1; } free(data_buf); printf("duplicata from [%s] to [%s]\n", AUTOK_NVRAM_PATH, data_node); } } //} //check autok folder for(i=0; i<VCORE_NO; i++){ // [FIXME] Normal mode & factory mode should store to different path snprintf(resnode, BUF_LEN, "%s/%s_%d_%d", AUTOK_RES_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]); printf("1-0 done\n"); //if(!is_nvram_mode()){ //std::string res_str(resnode); p_res = (struct res_data*)malloc(sizeof(struct res_data)); p_res->id = id; p_res->voltage = g_autok_vcore[i]; strcpy(p_res->filepath, resnode); res_list.push_back(p_res); //} /*else { snprintf(resnode, BUF_LEN, "%s/%s_%d_%d", AUTOK_RES_PATH, RESULT_FILE_PREFIX, id, g_autok_vcore[i]); write_file_to_nvram(resnode, id); }*/ struct timespec tstart={0,0}, tend={0,0}; printf("1-1 done\n"); if(is_file_valid(resnode)<=0){ //undo_vol_list.push_back(g_autok_vcore[i]); set_stage1_voltage(id, g_autok_vcore[i]); set_stage1_done(id, 0); printf("[%s] set done to 0\n", resnode); // prepare zero data to drive autok algorithm param_list = (unsigned int*)malloc(sizeof(unsigned int)*param_count); for(j=0; j<param_count; j++){ param_list[j] = 0; } vol_count = 1; vol_list = (unsigned int*)malloc(sizeof(unsigned int)*vol_count); vol_list[0] = g_autok_vcore[i]; pack_param(&predata, vol_list, vol_count, param_list, param_count); clock_gettime(CLOCK_MONOTONIC, &tstart); set_stage1_params(id, &predata); printf("operation col_count[%d] vcore[%d] param_count[%d]\n", vol_count, vol_list[0], param_count); release_predata(&predata); printf("release col_count[%d] param_count[%d]\n", vol_count, param_count); // Wait for autok stage1 for a specific voltage done // [FIXME] can switch to uevent? while(1){ if(get_stage1_done(id)) break; usleep(10*1000); } clock_gettime(CLOCK_MONOTONIC, &tend); printf("autok once %.5f seconds\n",((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec)); set_debug(0); snprintf(devnode, BUF_LEN, "%s/%d/%s", STAGE1_DEVNODE, id, "PARAMS"); if(!is_nvram_mode()){ printf("[NON_NV]From dev[%s] to res[%s]\n", devnode, resnode); from_dev_to_data(devnode, resnode); // For recover different version param_count if(need_to_recover){ write_dev_to_nvram(devnode, id); } } else { printf("[NV]From dev[%s] to nvram\n", devnode); from_dev_to_data(devnode, resnode); write_dev_to_nvram(devnode, id); } } printf("1-2 done\n"); } // Set stage2 data to apply autok parameter //if(!is_nvram_mode()){ // Merge Phase full_data.vol_count = VCORE_NO; full_data.param_count = param_count; full_data.vol_list = (unsigned int*)malloc(sizeof(unsigned int)*VCORE_NO); full_data.ai_data = (U_AUTOK_INTERFACE_DATA**)malloc(sizeof(U_AUTOK_INTERFACE_DATA*)*VCORE_NO); i = 0; for(it_res=res_list.begin(); it_res!=res_list.end(); ++it_res){ full_data.ai_data[i] = (U_AUTOK_INTERFACE_DATA*)malloc(sizeof(U_AUTOK_INTERFACE_DATA)*param_count); struct res_data *p_temp_res = *it_res; predata = get_param((char*)p_temp_res->filepath); full_data.vol_list[i] = p_temp_res->voltage; memcpy(full_data.ai_data[i], predata.ai_data[0], sizeof(U_AUTOK_INTERFACE_DATA)*param_count); release_predata(&predata); free(p_temp_res); i++; } printf("1-3 done\n"); set_stage2(id, &full_data); release_predata(&full_data); printf("1-4 done\n"); /*}else{ set_ready(id); }*/ return 0; }