char disk_io_read(test_results_t* result, int iters, cmd_line_args * cmd_args, benchmark_test* bmtest, result_table_t* res_table) { FILE *read_fp = NULL; long long time_diff; int block_size = 0; int done, loop, j; double clock_accuracy; char retry_status = UNACCEPTABLE_DEVIATIONS; int sub_iters = DEFAULT_SUBITERS; int count = 0; char *_read_buf = NULL; char print_flag = FALSE; struct timespec start_time, end_time; block_size = get_block_size(); assert(block_size> 0); clock_accuracy = get_min_exec_time(res_table); RTMB_verbose_printf(stdout, cmd_args, 1, "\nTest Report for disk I/O read configuration:\n"); RTMB_verbose_printf(stdout, cmd_args, 1, "=================================================\n"); RTMB_verbose_printf(stdout, cmd_args, 1, "\ndisk_io_config: Total number of iterations = %d\n\n", iters); done = 0; while (!done) { int n; _read_buf = calloc(1, block_size); if (_read_buf == NULL) { RTMB_printf(stderr, "calloc() failed in disk_io_read_config()\n"); abort(); } /*Make sure there is data in the file before attempting a read*/ setup_file_for_read(block_size * sub_iters, 1); for (loop = 0; loop < iters; loop++) { open_file_for_read(&read_fp); if (get_cur_time(&start_time) == ERROR) { abort(); } for (j = 0; j < sub_iters; j++) { if ((n = fread(_read_buf, sizeof(char), block_size, read_fp)) != block_size) { perror("fwrite:"); abort(); } } if (get_cur_time(&end_time) == ERROR) { abort(); } /* Get the time difference of start and end times */ time_diff = get_time_diff(start_time, end_time); RTMB_verbose_printf(stdout, cmd_args, 2, "disk_io_read_config: Difference between end" " and start times = %.3f us\n", MICROSEC(time_diff)); add_entry(result, time_diff, 0); fclose(read_fp); } if (IS_EXEC_TIME_GRT_THAN_CLK(result, clock_accuracy)) { print_flag = TRUE; if (check_pass_criteria(result, cmd_args, bmtest, 0) == SUCCESS) { /* * test passed, * disk IO rate is determined */ retry_status = ACCEPTABLE_DEVIATIONS; done = 1; break; } else { /*If we have completed, return error*/ if (++count == bmtest->_threshold) { RTMB_printf(stderr, "disk_io_read_config: exceeded" " maximum attempts \n"); break; } } } if (print_flag == TRUE) { RTMB_verbose_printf(stdout, cmd_args, 1, "\ndisk_io_read_config: Retrying test"); RTMB_verbose_printf(stdout, cmd_args, 1, " with bigger work quantum to get" " lesser variance...\n"); } /* * measured times are not accurate enough, * hence retry. */ free_chain(result, 0); sub_iters *= MULTIPLIER_FOR_SUB_ITER; free(_read_buf); } result->opern_amount = block_size * sub_iters; return retry_status; }
void* producer(void* arg){ arg_t* args = (arg_t *) arg; packet_t *packet = malloc(sizeof(packet_t)+MSS); int i; int len = 0; int numbytes = 0; long bytestoread = args->numBytes; setup_file_for_read(args->filename); if (bytestoread < file_size) { // Clip the file size to what ever need to be rad file_size = bytestoread; } sentbytes = 0; assert(packet != NULL); while(1) { while(1) { int rv = get_totalBytes(); if (rv >= cWnd) { pthread_yield(); } else { break; } } pthread_mutex_lock(&m); offset = file_off_to_read; pthread_mutex_unlock(&m); if ((offset+MSS) < file_size) { len = MSS; } else { if (offset < file_size) { len = (file_size - offset); } else { len = 0; } } if (len > 0) { memset(packet->data, 0, MSS); packet->packet_type = htonl(NORMAL_PKT); readbytes += len; packet->buf_bytes = htonl(len); packet->sequencenumber = htonl(getAndIncrseqNumber()); packet->f_offset = htonl(offset); memcpy(packet->data, file_base_addr+offset, len); // printf("recv sockfd: %d, sizeof(packet)+mss %lu, dest addr %s\n", // recv_sockfd, // sizeof(packet_t)+MSS, // inet_ntoa(si_other.sin_addr)); if ((numbytes = sendto(recv_sockfd, packet, sizeof(packet_t)+MSS, MSG_WAITALL, (struct sockaddr *)&si_other, si_other_addrlen)) == -1) { perror("producer 1: sendto"); exit(1); } incrTotalBytes(numbytes); sentbytes += ntohl(packet->buf_bytes); pthread_mutex_lock(&m); file_off_to_read += len; pthread_mutex_unlock(&m); } if (len == 0) { eof_packet_t *p1; free(packet); p1 = malloc(sizeof(eof_packet_t)); p1->packet_type = htonl(EOF_PKT); p1->eof = htonl(1); p1->file_sz = htonl(file_size); if ((numbytes = sendto(recv_sockfd, p1, sizeof(packet_t), MSG_WAITALL, (struct sockaddr *)&si_other, si_other_addrlen)) == -1) { perror("producer 2: sendto"); exit(1); } free(p1); int bytes_diff = (file_size - bytesReceivedByClient); printf("Totalsize %ld bytes Read %ld Total xfered %ld Tot Received %ld Bytes Re-transmitted %ld, Diff=%d\n", file_size, readbytes, sentbytes, bytesReceivedByClient, lostBytes, bytes_diff); break; } } producer_exiting = 1; pthread_kill(recvAckid, SIGUSR1); //pthread_kill(doTimerid, SIGUSR1); printf("Producer done and hence exiting \n"); printf("Congestion window Max %d Min: %d Last Value: %d\n", maxcWnd, mincWnd, cWnd); munmap(file_base_addr, file_size); return NULL; }