TEST(STORE_STAT_TEST, HandleNoneZeroInput) { MEM_POOL* mem_pool = mem_pool_init(M_1M); store_stats_init(1000*10,mem_pool); uint64 i; for(i=0;i<10000;i++) record_time("index_equal",1000*100); ASSERT_EQ(100.000000,get_avg_time_inms("index_equal")); ASSERT_EQ(10000,get_count("index_equal")); ASSERT_EQ(10000,get_total_count("index_equal")); sleep(2); ASSERT_EQ(5000,get_throughput("index_equal")); }
static void migration_rate_tick(void *opaque) { FdMigrationState *s = opaque; int interval=30000; int64_t total_transfer = my_blk_mig_bytes_transferred(); int64_t current_transfer = total_transfer - s->last_transferred; int64_t real_speed = current_transfer*1000/s->last_interval; //Bytes per second int64_t pasttime=(qemu_get_clock(rt_clock)-s->starttime)/1000L; printf("time %"PRId64" real_speed %"PRId64" ",pasttime,real_speed); int64_t memsize=ram_bytes_remaining(); int64_t remaindisksize=get_remaining_dirty(); int64_t speed = 0L; int64_t maxspeed=80L*1024L*1024L; int64_t restdisk=(bdrv_get_totallength()-total_transfer); //old version for dirtyrate which is the average rate comparing to time zero /*int64_t dirtyamount=(disksize-restdisk); int64_t dirtyrate=dirtyamount/pasttime; int64_t newdirtyrate=dirtyrate; */ //old drity - transferred + generated = new dirty int64_t newgenerate = remaindisksize + current_transfer - s->last_dirty; int64_t dirtyrate=newgenerate*1000/s->last_interval; int64_t newdirtyrate=dirtyrate; int64_t resttime=(uint64_t)(s->mig_state.mig_time)-pasttime; int64_t real_speed_MB = real_speed >> 20L; int64_t last_speed_MB = s->last_speed >> 20L; int64_t speed_MB = 0L; if(s->mig_state.mig_time <= pasttime) { //already over the time speed=maxspeed; }else { /*pess*/ // speed=(disksize+memsize+dirtyrate*resttime)/(resttime); /*opt*/ // speed=(disksize+memsize)/resttime; /*pess-80*/ if((bdrv_get_totallength()<=total_transfer)||(s->precopy==0)) { s->precopy=0; // speed=maxspeed; interval=5000; /* if(dirtyrate>s->last_dirtyrate) newdirtyrate=dirtyrate+(dirtyrate-s->last_dirtyrate)*disksize/(real_speed*s->last_interval/1000L); else{ int64_t temprate=(s->last_dirtyrate-dirtyrate)*disksize/(real_speed*s->last_interval/1000L); if(temprate>dirtyrate) newdirtyrate=0; else newdirtyrate=dirtyrate-temprate; } */ speed=(remaindisksize+memsize+newdirtyrate*resttime)/resttime; } else { // newdirtyrate=dirtyrate; /* if(dirtyrate>s->last_dirtyrate) newdirtyrate=dirtyrate+(dirtyrate-s->last_dirtyrate)*restdisk/(real_speed*s->last_interval/1000L); else{ int64_t temprate=(s->last_dirtyrate-dirtyrate)*restdisk/(real_speed*s->last_interval/1000L); if(temprate>dirtyrate) newdirtyrate=0; else newdirtyrate=dirtyrate-temprate; } */ speed=(remaindisksize+memsize+newdirtyrate*resttime)/resttime; if(restdisk<speed*30L) { uint64_t interval_64=restdisk*1000/speed; interval=interval_64; printf("approaching pre-copy ending: interval %"PRId64"\n",interval_64); } } speed_MB = speed >> 20L; if((real_speed_MB<last_speed_MB)&&(speed_MB>=real_speed_MB)){ printf("extend speed from %"PRId64" ",speed); speed=speed*s->last_speed/real_speed; printf(" to %"PRId64" ",speed); } if(speed>maxspeed) speed =maxspeed; } speed_MB = speed >> 20L; printf("new generate %"PRId64" dirtyrate %"PRId64" new dirty rate %"PRId64" remaining disk %"PRId64" ram %"PRId64" \n",newgenerate,dirtyrate,newdirtyrate,remaindisksize,memsize); printf("real_speed_%"PRId64" last_speed_%"PRId64" speed_%"PRId64"\n",real_speed,s->last_speed,speed); printf("real_speed_MB %"PRId64" last_speed_MB %"PRId64" speed_MB %"PRId64"\n",real_speed_MB,last_speed_MB,speed_MB); if((s->mig_state.metricopt==1)||(s->mig_state.metricopt==2)){ int64_t total_throughput = get_throughput(); int64_t current_throughput=(total_throughput-s->last_throughput)*1000/s->last_interval; //Bytes per second s->last_throughput = total_throughput; int64_t current_throughput_MB = current_throughput >> 20L; printf("current_throughput_MB %"PRId64"\n",current_throughput_MB); if(s->mig_state.metricopt==1){ if(current_throughput_MB>=s->mig_state.metricvalue) { printf("case 1 "); printf("max speed %"PRId64" s->last_speed+step %"PRId64"\n",speed,s->last_speed+speed_step); speed=maxvalue(speed,s->last_speed+speed_step); } else { printf("case 2 "); printf("max speed %"PRId64" s->last_speed-step %"PRId64"\n",speed,s->last_speed-speed_step); speed=maxvalue(speed,s->last_speed-speed_step); } } }
inline void stm_tune_scheduler(){ TX_GET; int m=max_allowed_running_transactions; endEnergy(); stm_time_t now=STM_TIMER_READ(); stm_time_t total_tx_wasted_time=0; stm_time_t total_tx_time=0; stm_time_t total_no_tx_time=0; stm_time_t total_tx_spin_time=0; stm_time_t *wasted_time_k=(stm_time_t *)malloc((max_concurrent_threads+1)*sizeof(stm_time_t)); stm_time_t *useful_time_k=(stm_time_t *)malloc((max_concurrent_threads+1)*sizeof(stm_time_t)); long * conflict_active_threads=(long *)malloc((max_concurrent_threads + 1) * sizeof(long)); long * commit_active_threads=(long *)malloc((max_concurrent_threads + 1) * sizeof(long)); memset(conflict_active_threads, 0, (max_concurrent_threads+1) * sizeof(long)); memset(commit_active_threads, 0, (max_concurrent_threads+1) * sizeof(long)); memset(wasted_time_k, 0, (max_concurrent_threads+1) * sizeof(stm_time_t)); memset(useful_time_k, 0, (max_concurrent_threads+1) * sizeof(stm_time_t)); long total_committed_transactions_by_collector_threads=0; long total_committed_transactions=0; long tx_conflict_table_times=0; float avg_running_tx=0; tx->total_no_tx_time+=now - tx->start_no_tx_time ; stm_tx_t *thread=_tinystm.threads; int i=0; while(thread!=NULL){ total_tx_time+=thread->total_useful_time; total_no_tx_time+=thread->total_no_tx_time; total_tx_wasted_time+=thread->total_wasted_time; total_tx_spin_time+=thread->total_spin_time; total_committed_transactions_by_collector_threads+=thread->committed_transactions_as_a_collector_thread; total_committed_transactions+=thread->committed_transactions; tx_conflict_table_times+=thread->aborted_transactions; for(i=0;i<max_concurrent_threads+1;i++){ wasted_time_k[i]+=thread->total_tx_wasted_per_active_transactions[i]; //printf("\nwasted_time_k[%i] %llu", i, thread->total_tx_wasted_per_active_transactions[i]); useful_time_k[i]+=thread->total_tx_useful_per_active_transactions[i]; commit_active_threads[i]+=thread->total_tx_committed_per_active_transactions[i]; avg_running_tx+=(float)i * (float) thread->total_tx_committed_per_active_transactions[i]; conflict_active_threads[i]+=thread->total_conflict_per_active_transactions[i]; } reset_local_stats(thread); thread=thread->next; } for(i=0;i<max_concurrent_threads+1;i++) printf("\nwasted_time_k[%i] %llu", i, wasted_time_k[i]); printf("\ntotal_tx_time %llu, total_tx_wasted_time %llu, total_no_tx_time %llu, total_committed_transactions_by_collector_threads %i", total_tx_time, total_tx_wasted_time, total_no_tx_time, total_committed_transactions_by_collector_threads); avg_running_tx=avg_running_tx/(float)total_committed_transactions_by_collector_threads; float *mu_k=(float*)malloc((max_concurrent_threads+1) * sizeof(float)); float lambda = 1.0 / (((float) total_no_tx_time/(float)1000000000)/(float) total_committed_transactions_by_collector_threads); for (i=0;i<max_concurrent_threads+1;i++){ if((wasted_time_k[i]>0 || useful_time_k[i]>0) && commit_active_threads[i] > 0){ mu_k[i]= 1.0 / ((((float) wasted_time_k[i] / (float)1000000000) / (float)commit_active_threads[i]) + (((float) useful_time_k[i]/(float)1000000000) / (float) commit_active_threads[i])); printf("\nk:%i\tmu_k: %f, %llu, %llu, %llu", i, mu_k[i], wasted_time_k[i], useful_time_k[i], commit_active_threads[i]); }else{ mu_k[i]= 1.0 / ((((float)total_tx_wasted_time/(float)1000000000)/(float)total_committed_transactions_by_collector_threads)+(((float)total_tx_time/(float)1000000000) / (float) total_committed_transactions_by_collector_threads)); printf("\nk:%i\tmu_k: %f - average", i, mu_k[i]); } }//[email protected] float th = get_throughput(lambda,mu_k,m); float th_minus_1=0.0,th_plus_1=0.0,th_minus_2=0.0; if(m>3){ th_minus_1=get_throughput(lambda,mu_k,m-1); th_minus_2=get_throughput(lambda,mu_k,m-2); }else if(m>2)th_minus_1=get_throughput(lambda,mu_k,m-1); if(th_minus_2 >= th && th_minus_2 >= th_minus_1 && m>3) { max_allowed_running_transactions-=2; //printf("\nSelected th_minus_2"); }else if(th_minus_1>=th){ max_allowed_running_transactions--; //printf("\nSelected th_minus_1"); }else if(m<max_concurrent_threads){ float avg_restart_k= (float)conflict_active_threads[m]/(float)commit_active_threads[m]; float p_a_k = avg_restart_k /(1.0 + avg_restart_k); float p_a_1 = 1- pow(1-p_a_k,1.0/(double)(m-1)); float avg_restart_k_plus_1 = ((1.0 - pow((1.0 - p_a_1),m))/ pow((1-p_a_1),m)); float w_m=0.0,u_m=0.0; if(conflict_active_threads[m]>0) w_m=((float)wasted_time_k[m]/(float)1000000000)/(float)conflict_active_threads[m]; else if(tx_conflict_table_times>0)w_m=((float)total_tx_wasted_time/(float)1000000000)/(float)tx_conflict_table_times; if(commit_active_threads[m]>0) u_m = ((float)useful_time_k[m]/(float)1000000000)/(float)commit_active_threads[m]; else u_m = ((float)total_tx_time/(float)1000000000)/(float)total_committed_transactions_by_collector_threads; mu_k[m + 1]= 1.0/((w_m * avg_restart_k_plus_1) + u_m ); th_plus_1 = get_throughput(lambda,mu_k,m + 1); if(th_plus_1 > th) { max_allowed_running_transactions++; //printf("\nSelected th_plus_1"); } else { //printf("\nSelected th"); } }// tx->start_no_tx_time=STM_TIMER_READ(); printf("\nPredicted: %f|%f|%f|%f, measured: %f, max txs: %i", th_minus_2, th_minus_1, th, th_plus_1, (float)total_committed_transactions/((float)(now-last_tuning_time)/(float)1000000000), max_allowed_running_transactions); printf("\tTotal commits: %i (as a collector: %i)",total_committed_transactions, total_committed_transactions_by_collector_threads); printf("\nlambda: %f mu: %f", lambda, 1.0 / ((((float)total_tx_wasted_time/(float)1000000000)/(float)total_committed_transactions_by_collector_threads)+(((float)total_tx_time/(float)1000000000) / (float) total_committed_transactions_by_collector_threads))); printf("\nAvg_running_tx: %f", avg_running_tx, 1.0); fflush(stdout); startEnergy(); last_tuning_time=STM_TIMER_READ(); }