static int test_random_walking(char* pages, int64_t total_size, int nstride, int iter, uint64_t* timep) { int sum = 6, i, j; int64_t begin_u = get_usec(); for (i = 0; i < iter; i++) { for (j = 0; j <= nstride - 4; j += 4) { int r1 = rand() % (total_size - sizeof(int)); int r2 = rand() % (total_size - sizeof(int)); int r3 = rand() % (total_size - sizeof(int)); int r4 = rand() % (total_size - sizeof(int)); sum += *(int*) (&pages[r1]); sum += *(int*) (&pages[r2]); sum += *(int*) (&pages[r3]); sum += *(int*) (&pages[r4]); } int r; switch(nstride - j) { case 3: r = rand() % (total_size - sizeof(int)); sum += *(int*)(&pages[r]); case 2: r = rand() % (total_size - sizeof(int)); sum += *(int*)(&pages[r]); case 1: r = rand() % (total_size - sizeof(int)); sum += *(int*)(&pages[r]); } } *timep = get_usec() - begin_u; return sum; }
void udelay(unsigned long usec) { unsigned long end = get_usec() + usec; while (get_usec() < end) continue; }
int SSD_BLOCK_ERASE_DELAY(int reg) { int ret = 0; int64_t start = 0; int64_t end = 0; int64_t diff; int64_t time_stamp = cell_io_time[reg]; if( time_stamp == -1) return 0; /* Block Erase Delay */ start = get_usec(); diff = get_usec() - cell_io_time[reg]; if( diff < BLOCK_ERASE_DELAY){ while(diff < BLOCK_ERASE_DELAY){ diff = get_usec() - time_stamp; } ret = 1; } end = get_usec(); /* Send Delay Info to Perf Checker */ SEND_TO_PERF_CHECKER(reg_io_type[reg], end-start, REG_OP); /* Update IO Overhead */ cell_io_time[reg] = -1; reg_io_cmd[reg] = NOOP; reg_io_type[reg] = NOOP; return ret; }
int rtt(int *seqp, int recvport, float *ms_delay) { long sec_delay = 0, usec_delay = 0; int i, tablepos = -1, status; if (*seqp != 0) { for (i = 0; i < TABLESIZE; i++) if (delaytable[i].seq == *seqp) { tablepos = i; break; } } else { for (i=0; i<TABLESIZE; i++) if (delaytable[i].src == recvport) { tablepos = i; break; } if (i != TABLESIZE) *seqp = delaytable[i].seq; } if (tablepos != -1) { status = delaytable[tablepos].status; delaytable[tablepos].status = S_RECV; sec_delay = time(NULL) - delaytable[tablepos].sec; usec_delay = get_usec() - delaytable[tablepos].usec; if (sec_delay == 0 && usec_delay < 0) usec_delay += 1000000; *ms_delay = (sec_delay * 1000) + ((float)usec_delay / 1000); minavgmax(*ms_delay); } else { *ms_delay = 0; /* not in table.. */ status = 0; /* we don't know if it's DUP */ } /* SANITY CHECK */ if (*ms_delay < 0) { printf("\n\nSANITY CHECK in rtt.c FAILED!\n"); printf("- seqnum = %d\n", *seqp); printf("- status = %d\n", status); printf("- get_usec() = %ld\n", (long int) get_usec()); printf("- delaytable.usec = %ld\n", (long int) delaytable[tablepos].usec); printf("- usec_delay = %ld\n", usec_delay); printf("- time(NULL) = %ld\n", (long int) time(NULL)); printf("- delaytable.sec = %ld\n", (long int) delaytable[tablepos].sec); printf("- sec_delay = %ld\n", sec_delay); printf("- ms_delay = %f\n", *ms_delay); printf("END SANITY CHECK REPORT\n\n"); } return status; }
static int test_sequential_walking(char* pages, int nstride, int iter, int stride, uint64_t* timep) { int sum = 5; uint64_t begin_u = get_usec(); sum += walk(pages, stride, iter, nstride / 2); *timep = get_usec() - begin_u; return sum; }
static int small_alloc(int npage, int page_size) { int sum = 0, i; uint64_t begin = get_usec(); for (i = 0; i < CHECK_ALLOC_ITER; i++) { char* ptr = alloc_pages(i, npage); sum += (int64_t)ptr; free(ptr); } fprintf(stderr, "small %.3lf\n", 1000.0 * (get_usec() - begin) / CHECK_ALLOC_ITER); return sum; }
int main(int argc, char** argv) { int64_t page_size = HUGE_PAGE_SIZE; if (argc < 2 || strcmp(argv[1], "small") == 0) page_size = PAGE_SIZE; /* * It is not quite reasonable to allocate even larger chunk of data */ int64_t mem_size; int sum = 0; for (mem_size = 2048 * 1024; mem_size <= 64 * 1024 * 2048LL; mem_size *= 8) { int npage = mem_size / page_size; int iter, stride, i; for (iter = 1; iter <= 16; iter *= 2) { const int strides[] = {4, 4096, 32768, 2048 * 1024}; const int nstride = sizeof(strides) / sizeof(strides[0]); int inner_loop[] = {4, 16, 32, 512}; for (i = 0; i < nstride; i++) { int stride = strides[i], k; uint64_t time_inner = 0, time_out, begin_u; begin_u = get_usec(); for (k = 0; k < inner_loop[i]; k++) { uint64_t tmp; char* pages = alloc_raw_pages(npage, page_size); sum += test_random_walking(pages, mem_size, iter, mem_size / stride, &tmp); free_raw_pages(pages, npage, page_size); time_inner += tmp; } time_out = get_usec() - begin_u; fprintf(stderr, "rand %"PRId64" %d %d %"PRId64 " %"PRId64"\n", mem_size, iter, stride, time_inner / inner_loop[i], time_out/inner_loop[i]); time_inner = 0; begin_u = get_usec(); for (k = 0; k < inner_loop[i]; k++) { uint64_t tmp; char* pages = alloc_raw_pages(npage, page_size); sum += test_sequential_walking(pages, mem_size / stride, iter, stride, &tmp); free_raw_pages(pages, npage, page_size); time_inner += tmp; } time_out = get_usec() - begin_u; fprintf(stderr, "seq %"PRId64" %d %d %"PRId64 " %"PRId64"\n", mem_size, iter, stride, time_inner / inner_loop[i], time_out/inner_loop[i]); } printf("%d %d %d\n", mem_size, iter, nstride); } } printf("#%x\n", sum); return 0; }
int SSD_CELL_WRITE_DELAY(int reg) { int ret = 0; int64_t start = 0; int64_t end = 0; int64_t diff = 0; int64_t time_stamp = cell_io_time[reg]; if( time_stamp == -1 ) return 0; /* Cell Write Delay */ start = get_usec(); diff = start - time_stamp + io_overhead[reg]; #ifndef VSSIM_BENCH #ifdef DEL_QEMU_OVERHEAD if(diff < CELL_PROGRAM_DELAY){ SSD_UPDATE_QEMU_OVERHEAD(CELL_PROGRAM_DELAY-diff); } diff = start - cell_io_time[reg] + io_overhead[reg]; #endif #endif if( diff < CELL_PROGRAM_DELAY){ init_diff_reg = diff; while(diff < CELL_PROGRAM_DELAY){ diff = get_usec() - time_stamp + io_overhead[reg]; } ret = 1; } end = get_usec(); /* Send Delay Info To Perf Checker */ SEND_TO_PERF_CHECKER(reg_io_type[reg], end-start, REG_OP); SSD_UPDATE_IO_REQUEST(reg); /* Update Time Stamp Struct */ cell_io_time[reg] = -1; reg_io_cmd[reg] = NOOP; reg_io_type[reg] = NOOP; /* Update IO Overhead */ io_overhead[reg] = 0; return ret; }
int SSD_CH_ACCESS(int channel) { int i, j; int ret = SUCCESS; int r_num; for(i=0;i<WAY_NB;i++){ r_num = channel*PLANES_PER_FLASH + i*CHANNEL_NB*PLANES_PER_FLASH; for(j=0;j<PLANES_PER_FLASH;j++){ if(reg_io_time[r_num] <= get_usec() && reg_io_time[r_num] != -1){ if(reg_io_cmd[r_num] == READ){ SSD_CELL_READ_DELAY(r_num); SSD_REG_READ_DELAY(r_num); ret = FAIL; } else if(reg_io_cmd[r_num] == WRITE){ SSD_REG_WRITE_DELAY(r_num); ret = FAIL; } } r_num++; } } return ret; }
int SSD_REG_WRITE_DELAY(int reg) { int ret = 0; int64_t start = 0; int64_t end = 0; int64_t diff = 0; int64_t time_stamp = reg_io_time[reg]; if (time_stamp == -1) return 0; /* Reg Write Delay */ start = get_usec(); diff = start - time_stamp; #ifndef VSSIM_BENCH #ifdef DEL_QEMU_OVERHEAD if(diff < REG_WRITE_DELAY){ SSD_UPDATE_QEMU_OVERHEAD(REG_WRITE_DELAY-diff); } diff = start - reg_io_time[reg]; #endif #endif if (diff < REG_WRITE_DELAY){ while( diff < REG_WRITE_DELAY ){ diff = get_usec() - time_stamp; } ret = 1; } end = get_usec(); /* Send Delay Info To Perf Checker */ SEND_TO_PERF_CHECKER(reg_io_type[reg], end-start, CH_OP); /* Update Time Stamp Struct */ reg_io_time[reg] = -1; //TEMPs // FILE* fp_temp = fopen("./data/write.txt","a"); // fprintf(fp_temp,"%ld\n",end-start); // fclose(fp_temp); //TEMPe return ret; }
int SSD_REG_READ_DELAY(int reg) { int ret = 0; int64_t start = 0; int64_t end = 0; int64_t diff = 0; int64_t time_stamp = reg_io_time[reg]; if (time_stamp == -1) return 0; /* Reg Read Delay */ start = get_usec(); diff = start - time_stamp; #ifndef VSSIM_BENCH #ifdef DEL_QEMU_OVERHEAD if(diff < REG_READ_DELAY){ SSD_UPDATE_QEMU_OVERHEAD(REG_READ_DELAY-diff); } diff = start - reg_io_time[reg]; #endif #endif if(diff < REG_READ_DELAY){ while(diff < REG_READ_DELAY){ diff = get_usec() - time_stamp; } ret = 1; } end = get_usec(); /* Send Delay Info To Perf Checker */ SEND_TO_PERF_CHECKER(reg_io_type[reg], end-start, CH_OP); SSD_UPDATE_IO_REQUEST(reg); /* Update Time Stamp Struct */ reg_io_time[reg] = -1; reg_io_cmd[reg] = NOOP; reg_io_type[reg] = NOOP; return ret; }
/* return msec */ ulong get_timer(ulong base) { const ulong timecnt = OST_TIMER_RESET / (33 * 1000); /*130150*/ ulong now = (get_usec() / 1000); if (now >= base) return now - base; else return ((timecnt + 1) - base) + now; }
int64_t UPDATE_IO_REQUEST(int request_nb, int offset, int64_t time, int type) { int64_t start = get_usec(); int io_type; int64_t latency=0; int flag = 0; if(request_nb == -1) return 0; io_request* curr_request = LOOKUP_IO_REQUEST(request_nb, type); if(curr_request == NULL){ printf("ERROR[%s] No such io request, nb %d\n",__FUNCTION__, request_nb); return 0; } if(type == UPDATE_START_TIME){ curr_request->start_time[offset] = time; curr_request->start_count++; } else if(type == UPDATE_END_TIME){ curr_request->end_time[offset] = time; curr_request->end_count++; } if(curr_request->start_count == curr_request->request_size && curr_request->end_count == curr_request->request_size){ latency = CALC_IO_LATENCY(curr_request); io_type = curr_request->request_type; SEND_TO_PERF_CHECKER(io_type, latency, LATENCY_OP); FREE_IO_REQUEST(curr_request); flag = 1; } int64_t end = get_usec(); return (end - start); }
int64_t SSD_CH_SWITCH_DELAY(int channel) { int64_t start = 0; int64_t end = 0; int64_t diff = 0; int64_t switch_delay = 0; if(old_channel_cmd == READ){ switch_delay = CHANNEL_SWITCH_DELAY_R; } else if(old_channel_cmd == WRITE){ switch_delay = CHANNEL_SWITCH_DELAY_W; } else{ return 0; } start = get_usec(); diff = start - old_channel_time; #ifndef VSSIM_BENCH #ifdef DEL_QEMU_OVERHEAD if(diff < switch_delay){ SSD_UPDATE_QEMU_OVERHEAD(switch_delay-diff); } diff = start - old_channel_time; #endif #endif if (diff < switch_delay){ while( diff < switch_delay ){ diff = get_usec() - old_channel_time; } } end = get_usec(); return end-start; }
void SSD_UPDATE_IO_REQUEST(int reg) { int64_t curr_time = get_usec(); if(init_diff_reg != 0){ io_update_overhead = UPDATE_IO_REQUEST(access_nb[reg][0], access_nb[reg][1], curr_time, UPDATE_END_TIME); SSD_UPDATE_IO_OVERHEAD(reg, io_update_overhead); access_nb[reg][0] = -1; } else{ io_update_overhead = UPDATE_IO_REQUEST(access_nb[reg][0], access_nb[reg][1], 0, UPDATE_END_TIME); SSD_UPDATE_IO_OVERHEAD(reg, io_update_overhead); access_nb[reg][0] = -1; } }
// Get the current system time Fl_Date_Time Fl_Date_Time::System() { time_t tt; time(&tt); double datetime = convert(tt); #ifndef _WIN32 timeval tp; gettimeofday(&tp,0L); double mcsec = tp.tv_usec / 1000000.0 / (3600 * 24); #else // This works now! double mcsec = get_usec() / 1000000.0 / (3600 * 24); #endif return datetime + mcsec; }
void CTimeHistogram::Dump(FILE *fd){ fprintf (fd," min_delta : %lu usec \n",get_usec(m_min_delta)); fprintf (fd," cnt : %lu \n",m_cnt); fprintf (fd," high_cnt : %lu \n",m_high_cnt); fprintf (fd," max_d_time : %lu usec\n",get_usec(m_max_dt)); //fprintf (fd," average : %.0f usec\n", get_total_average()); fprintf (fd," sliding_average : %.0f usec\n", get_average_latency()); fprintf (fd," precent : %.1f %%\n",(100.0*(double)m_high_cnt/(double)m_cnt)); fprintf (fd," histogram \n"); fprintf (fd," -----------\n"); int i; int j; int base=10; for (j=0; j<HISTOGRAM_SIZE_LOG; j++) { for (i=0; i<HISTOGRAM_SIZE; i++) { if (m_hcnt[j][i] >0 ) { fprintf (fd," h[%lu] : %lu \n",(base*(i+1)),m_hcnt[j][i]); } } base=base*10; } }
int SSD_CELL_RECORD(int reg, int cmd) { if(cmd == WRITE){ cell_io_time[reg] = reg_io_time[reg] + REG_WRITE_DELAY; } else if(cmd == READ){ cell_io_time[reg] = old_channel_time + CHANNEL_SWITCH_DELAY_R; } else if(cmd == ERASE){ cell_io_time[reg] = get_usec(); } return SUCCESS; }
void CTimeHistogram::DumpWinMax(FILE *fd){ int i; uint32_t ci=m_win_cnt; for (i=0; i<HISTOGRAM_QUEUE_SIZE-1; i++) { dsec_t d=get_usec(m_max_ar[ci]); ci++; if (ci>HISTOGRAM_QUEUE_SIZE-1) { ci=0; } fprintf(fd," %.0f ",d); } }
int get_actual_shutdown(struct timeval tv, struct timeval ts, TWAMPTimestamp t) { /* If ts is 0 then no StopSessions message was received */ if ((ts.tv_sec * 1000000 + ts.tv_usec) == 0) return 1; /* Else compute time difference */ uint64_t current = tv.tv_sec * 1000000 + tv.tv_usec; uint64_t shutdown = ts.tv_sec * 1000000 + ts.tv_usec; uint64_t timeout = get_usec(t); /* This should be ok, as no difference is computed */ if (current > shutdown + timeout) return 1; return 0; }
void CTimeHistogram::dump_json(std::string name,std::string & json ){ char buff[200]; sprintf(buff,"\"%s\":{",name.c_str()); json+=std::string(buff); json+=add_json("min_usec",get_usec(m_min_delta)); json+=add_json("max_usec",get_usec(m_max_dt)); json+=add_json("high_cnt",m_high_cnt); json+=add_json("cnt",m_cnt); //json+=add_json("t_avg",get_total_average()); json+=add_json("s_avg",get_average_latency()); int i; int j; uint32_t base=10; json+=" \"histogram\": ["; bool first=true; for (j=0; j<HISTOGRAM_SIZE_LOG; j++) { for (i=0; i<HISTOGRAM_SIZE; i++) { if (m_hcnt[j][i] >0 ) { if ( first ){ first=false; }else{ json+=","; } json+="{"; json+=add_json("key",(base*(i+1))); json+=add_json("val",m_hcnt[j][i],true); json+="}"; } } base=base*10; } json+=" ] } ,"; }
int SSD_CH_RECORD(int channel, int cmd, int offset, int ret) { old_channel_nb = channel; old_channel_cmd = cmd; if(cmd == READ && offset != 0 && ret == 0){ old_channel_time += CHANNEL_SWITCH_DELAY_R; } else if(cmd == WRITE && offset != 0 && ret == 0){ old_channel_time += CHANNEL_SWITCH_DELAY_W; } else{ old_channel_time = get_usec(); } return SUCCESS; }
void send_icmp_timestamp(void) { char *packet; struct myicmphdr *icmp; struct icmp_tstamp_data *tstamp_data; packet = malloc(ICMPHDR_SIZE + sizeof(struct icmp_tstamp_data)); if (packet == NULL) { perror("[send_icmp] malloc"); return; } memset(packet, 0, ICMPHDR_SIZE + sizeof(struct icmp_tstamp_data)); icmp = (struct myicmphdr*) packet; tstamp_data = (struct icmp_tstamp_data*) (packet + ICMPHDR_SIZE); /* fill icmp hdr */ icmp->type = opt_icmptype; /* echo replay or echo request */ icmp->code = 0; icmp->checksum = 0; icmp->un.echo.id = getpid() & 0xffff; icmp->un.echo.sequence = _icmp_seq; tstamp_data->orig = htonl(get_midnight_ut_ms()); tstamp_data->recv = tstamp_data->tran = 0; /* icmp checksum */ if (icmp_cksum == -1) icmp->checksum = cksum((u_short*)packet, ICMPHDR_SIZE + sizeof(struct icmp_tstamp_data)); else icmp->checksum = icmp_cksum; /* adds this pkt in delaytable */ if (opt_icmptype == ICMP_TIMESTAMP) delaytable_add(_icmp_seq, 0, time(NULL), get_usec(), S_SENT); /* send packet */ send_ip_handler(packet, ICMPHDR_SIZE + sizeof(struct icmp_tstamp_data)); free (packet); _icmp_seq++; }
void send_icmp_echo(void) { char *packet, *data; struct myicmphdr *icmp; packet = malloc(ICMPHDR_SIZE + data_size); if (packet == NULL) { perror("[send_icmp] malloc"); return; } memset(packet, 0, ICMPHDR_SIZE + data_size); icmp = (struct myicmphdr*) packet; data = packet + ICMPHDR_SIZE; /* fill icmp hdr */ icmp->type = opt_icmptype; /* echo replay or echo request */ icmp->code = opt_icmpcode; /* should be indifferent */ icmp->checksum = 0; icmp->un.echo.id = getpid() & 0xffff; icmp->un.echo.sequence = _icmp_seq; /* data */ data_handler(data, data_size); /* icmp checksum */ if (icmp_cksum == -1) icmp->checksum = cksum((u_short*)packet, ICMPHDR_SIZE + data_size); else icmp->checksum = icmp_cksum; /* adds this pkt in delaytable */ if (opt_icmptype == ICMP_ECHO) delaytable_add(_icmp_seq, 0, time(NULL), get_usec(), S_SENT); /* send packet */ send_ip_handler(packet, ICMPHDR_SIZE + data_size); free (packet); _icmp_seq++; }
int main(int argc, char *argv[]) { unsigned int width, height; unsigned char *yuvdata, *vpxdata; int i = 0; vpxif_init(25, SCREEN_WIDTH, SCREEN_HEIGHT); FILE *yuv = fopen("/tmp/a.yuv", "wb"); fp = fopen("/tmp/a.webm", "wb"); while (i < 50) { printf("[Time] %u\n", get_usec()); capture_desktop(&width, &height, &yuvdata); vpx_img_update(yuvdata, &vpxdata, callback); fwrite(yuvdata, width * height * 3 / 2, 1, yuv); free(yuvdata); usleep(10000); i++; } vpxif_finish_up(&vpxdata, callback); fclose(fp); fclose(yuv); return 0; }
void send_icmp_address(void) { char *packet; struct myicmphdr *icmp; packet = malloc(ICMPHDR_SIZE + 4); if (packet == NULL) { perror("[send_icmp] malloc"); return; } memset(packet, 0, ICMPHDR_SIZE + 4); icmp = (struct myicmphdr*) packet; /* fill icmp hdr */ icmp->type = opt_icmptype; /* echo replay or echo request */ icmp->code = 0; icmp->checksum = 0; icmp->un.echo.id = getpid() & 0xffff; icmp->un.echo.sequence = _icmp_seq; memset(packet+ICMPHDR_SIZE, 0, 4); /* icmp checksum */ if (icmp_cksum == -1) icmp->checksum = cksum((u_short*)packet, ICMPHDR_SIZE + 4); else icmp->checksum = icmp_cksum; /* adds this pkt in delaytable */ if (opt_icmptype == ICMP_TIMESTAMP) delaytable_add(_icmp_seq, 0, time(NULL), get_usec(), S_SENT); /* send packet */ send_ip_handler(packet, ICMPHDR_SIZE + 4); free (packet); _icmp_seq++; }
static void test_latency_stream(rsa_context_mp *rsa, device_context *dev_ctx, int concurrency) { int max_len = rsa->max_ptext_bytes(); printf("# msg throughput(RSA msgs/s)\n"); for (int k = 1; k <= rsa_context::max_batch; k *= 2) { //if (k == 32) // k = 30; // GTX285 has 30 SMs :) uint64_t begin; uint64_t end; for (int s = 1; s <= concurrency; s++) { for (int i = 0; i < k; i++) { ptext_len_str[s][i] = (rand() % max_len + 1); ctext_len_str[s][i] = sizeof(ctext_str[s][i]); dtext_len_str[s][i] = sizeof(dtext_str[s][i]); set_random(ptext_str[s][i], ptext_len_str[s][i]); rsa->pub_encrypt(ctext_str[s][i], &ctext_len_str[s][i], ptext_str[s][i], ptext_len_str[s][i]); dtext_arr_str[s][i] = dtext_str[s][i]; ctext_arr_str[s][i] = ctext_str[s][i]; } } //warmup for (int i = 1; i < concurrency; i++) { rsa->priv_decrypt_stream((unsigned char **)dtext_arr_str[i], dtext_len_str[i], (const unsigned char **)ctext_arr_str[i], ctext_len_str[i], k, i); rsa->sync(i, true); } begin = get_usec(); int rounds = 200; int count = 0; do { int stream = 0; for (int i = 1; i <= concurrency; i++) { if (dev_ctx->get_state(i) == READY) { stream = i; break; } else { if (rsa->sync(i, false)) { count++; if (count == concurrency) begin = get_usec(); } } } if (stream != 0) { rsa->priv_decrypt_stream((unsigned char **)dtext_arr_str[stream], dtext_len_str[stream], (const unsigned char **)ctext_arr_str[stream], ctext_len_str[stream], k, stream); } else { usleep(0); } } while (count < rounds + concurrency); end = get_usec(); for (int s = 1; s <= concurrency; s++) rsa->sync(s, true); double throughput = (k * 1000000.0) * (count - concurrency) / (end - begin); printf("%4d *%2d\t%.2f\n", k, concurrency, throughput); } }
void retro_run(void) { poll_cb(); static unsigned frame_cnt = 0; #if 0 if (log_cb) log_cb(RETRO_LOG_INFO, "[NX]: Start frame.\n"); int64_t start_time = get_usec(); platform_sync_to_vblank(); #endif screen->Flip(); if (retro_60hz) { //int64_t start_time_frame = get_usec(); while (!run_main()); #if 0 int64_t total_time_frame = get_usec() - start_time_frame; if (log_cb) log_cb(RETRO_LOG_INFO, "[NX]: total_time_frame took %lld usec.\n", (long long)total_time_frame); #endif //int64_t start_time_frame_cb = get_usec(); video_cb(retro_frame_buffer, retro_frame_buffer_width, retro_frame_buffer_height, retro_frame_buffer_pitch); #if 0 int64_t total_time_frame_cb = get_usec() - start_time_frame_cb; if (log_cb) log_cb(RETRO_LOG_INFO, "[NX]: total_time_frame_cb took %lld usec.\n", (long long)total_time_frame_cb); #endif frame_cnt++; } else { if (frame_cnt % 6) { while (!run_main()); video_cb(retro_frame_buffer, retro_frame_buffer_width, retro_frame_buffer_height, retro_frame_buffer_pitch); } else video_cb(NULL, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH * sizeof(uint16_t)); // Dupe every 6th frame. frame_cnt++; } int16_t samples[(2 * 22050) / 60 + 1] = {0}; // Average audio frames / video frame: 367.5. unsigned frames = (22050 + (frame_cnt & 1 ? 30 : -30)) / 60; mixaudio(samples, frames * 2); audio_batch_cb(samples, frames); g_frame_cnt++; #if 0 int64_t total_time = get_usec() - start_time; if (log_cb) log_cb(RETRO_LOG_INFO, "[NX]: Frame took %lld usec.\n", (long long)total_time); #endif }
static void test_latency(rsa_context *rsa) { bool warmed_up = false; int max_len = rsa->max_ptext_bytes(); printf("# msg latency CPU kernel throughput(RSA msgs/s)\n"); for (int k = 1; k <= rsa_context::max_batch; k *= 2) { //if (k == 32) // k = 30; // GTX285 has 30 SMs :) unsigned char *ctext_arr[rsa_context::max_batch]; unsigned char *dtext_arr[rsa_context::max_batch]; uint64_t begin; uint64_t end; for (int i = 0; i < k; i++) { ptext_len[i] = (rand() % max_len) + 1; ctext_len[i] = sizeof(ctext[i]); dtext_len[i] = sizeof(dtext[i]); set_random(ptext[i], ptext_len[i]); rsa->pub_encrypt(ctext[i], &ctext_len[i], ptext[i], ptext_len[i]); dtext_arr[i] = dtext[i]; ctext_arr[i] = ctext[i]; } again: int iteration = 1; begin = get_usec(); try_more: rsa->priv_decrypt_batch((unsigned char **)dtext_arr, dtext_len, (const unsigned char **)ctext_arr, ctext_len, k); end = get_usec(); if (end - begin < 300000) { for (int i = 0; i < k; i++) dtext_len[i] = sizeof(dtext[i]); iteration++; if (!warmed_up) { warmed_up = true; goto again; } else goto try_more; } double total_time = (end - begin) / (iteration * 1000.0); double kernel_time = rsa->get_elapsed_ms_kernel(); double throughput = (k * 1000000.0) * iteration / (end - begin); printf("%4d\t%.2f\t%.2f\t%.2f\t%.2f\n", k, total_time, total_time - kernel_time, kernel_time, throughput); } }
int64_t ALLOC_IO_REQUEST(int32_t sector_nb, unsigned int length, int io_type, int* page_nb) { int64_t start = get_usec(); int io_page_nb = 0; unsigned int remain = length; unsigned int left_skip = sector_nb % SECTORS_PER_PAGE; unsigned int right_skip; unsigned int sects; io_request* curr_io_request = (io_request*)calloc(1, sizeof(io_request)); if(curr_io_request == NULL){ printf("ERROR[%s] Calloc io_request fail\n", __FUNCTION__); return 0; } while(remain > 0){ if(remain > SECTORS_PER_PAGE - left_skip){ right_skip = 0; } else{ right_skip = SECTORS_PER_PAGE - left_skip - remain; } sects = SECTORS_PER_PAGE - left_skip - right_skip; remain -= sects; left_skip = 0; io_page_nb++; } *page_nb = io_page_nb; int64_t* start_time_arr = (int64_t*)calloc(io_page_nb, sizeof(int64_t)); int64_t* end_time_arr = (int64_t*)calloc(io_page_nb, sizeof(int64_t)); if(start_time_arr == NULL || end_time_arr == NULL){ printf("ERROR[%s] Calloc time array fail\n", __FUNCTION__); return 0; } else{ memset(start_time_arr, 0, io_page_nb); memset(end_time_arr, 0, io_page_nb); } curr_io_request->request_nb = io_request_seq_nb; curr_io_request->request_type = io_type; curr_io_request->request_size = io_page_nb; curr_io_request->start_count = 0; curr_io_request->end_count = 0; curr_io_request->start_time = start_time_arr; curr_io_request->end_time = end_time_arr; curr_io_request->next = NULL; if(io_request_start == NULL && io_request_nb == 0){ io_request_start = curr_io_request; io_request_end = curr_io_request; } else{ io_request_end->next = curr_io_request; io_request_end = curr_io_request; } io_request_nb++; int64_t end = get_usec(); return (end - start); }