From: Martin R. <mr...@us...> - 2005-12-07 19:14:27
|
Update of /cvsroot/ltp/ltp/testcases/kernel/io/ltp-aiodio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14836 Modified Files: aio-stress.c Log Message: Update aio-stress.c tests from Chris Mason Index: aio-stress.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/io/ltp-aiodio/aio-stress.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** aio-stress.c 7 Feb 2005 19:40:18 -0000 1.5 --- aio-stress.c 7 Dec 2005 19:14:16 -0000 1.6 *************** *** 43,47 **** */ #define _FILE_OFFSET_BITS 64 ! #define PROG_VERSION "0.18" #define NEW_GETEVENTS --- 43,47 ---- */ #define _FILE_OFFSET_BITS 64 ! #define PROG_VERSION "0.21" #define NEW_GETEVENTS *************** *** 92,95 **** --- 92,96 ---- int o_sync = 0; int latency_stats = 0; + int completion_latency_stats = 0; int io_iter = 8; int iterations = RUN_FOREVER; *************** *** 109,112 **** --- 110,114 ---- int verify = 0; char *verify_buf = NULL; + int unlink_files = 0; struct io_unit; *************** *** 206,209 **** --- 208,213 ---- struct io_unit *next; + + struct timeval io_start_time; /* time of io_submit */ }; *************** *** 245,257 **** /* how much io this thread did in the last stage */ double stage_mb_trans; }; ! static double time_since(struct timeval *tv) { double sec, usec; double ret; ! struct timeval stop; ! gettimeofday(&stop, NULL); ! sec = stop.tv_sec - tv->tv_sec; ! usec = stop.tv_usec - tv->tv_usec; if (sec > 0 && usec < 0) { sec--; --- 249,266 ---- /* how much io this thread did in the last stage */ double stage_mb_trans; + + /* latency completion stats i/o time from io_submit until io_getevents */ + struct io_latency io_completion_latency; }; ! /* ! * return seconds between start_tv and stop_tv in double precision ! */ ! static double time_since(struct timeval *start_tv, struct timeval *stop_tv) ! { double sec, usec; double ret; ! sec = stop_tv->tv_sec - start_tv->tv_sec; ! usec = stop_tv->tv_usec - start_tv->tv_usec; if (sec > 0 && usec < 0) { sec--; *************** *** 264,272 **** } ! static void calc_latency(struct timeval *tv, struct io_latency *lat) { double delta; int i; ! delta = time_since(tv); delta = delta * 1000; --- 273,295 ---- } ! /* ! * return seconds between start_tv and now in double precision ! */ ! static double time_since_now(struct timeval *start_tv) ! { ! struct timeval stop_time; ! gettimeofday(&stop_time, NULL); ! return time_since(start_tv, &stop_time); ! } ! ! /* ! * Add latency info to latency struct ! */ ! static void calc_latency(struct timeval *start_tv, struct timeval *stop_tv, ! struct io_latency *lat) { double delta; int i; ! delta = time_since(start_tv, stop_tv); delta = delta * 1000; *************** *** 386,390 **** double mb; ! runtime = time_since(&oper->start_time); mb = oper_mb_trans(oper); tput = mb / runtime; --- 409,413 ---- double mb; ! runtime = time_since_now(&oper->start_time); mb = oper_mb_trans(oper); tput = mb / runtime; *************** *** 393,403 **** } ! static void print_latency(struct thread_info *t) { ! struct io_latency *lat = &t->io_submit_latency; double avg = lat->total_lat / lat->total_io; int i; double total_counted = 0; ! fprintf(stderr, "latency min %.2f avg %.2f max %.2f\n\t", ! lat->min, avg, lat->max); for (i = 0 ; i < DEVIATIONS ; i++) { --- 416,425 ---- } ! static void print_lat(char *str, struct io_latency *lat) { double avg = lat->total_lat / lat->total_io; int i; double total_counted = 0; ! fprintf(stderr, "%s min %.2f avg %.2f max %.2f\n\t", ! str, lat->min, avg, lat->max); for (i = 0 ; i < DEVIATIONS ; i++) { *************** *** 408,412 **** fprintf(stderr, " < %.0f", lat->total_io - total_counted); fprintf(stderr, "\n"); ! memset(&t->io_submit_latency, 0, sizeof(t->io_submit_latency)); } --- 430,446 ---- fprintf(stderr, " < %.0f", lat->total_io - total_counted); fprintf(stderr, "\n"); ! memset(lat, 0, sizeof(*lat)); ! } ! ! static void print_latency(struct thread_info *t) ! { ! struct io_latency *lat = &t->io_submit_latency; ! print_lat("latency", lat); ! } ! ! static void print_completion_latency(struct thread_info *t) ! { ! struct io_latency *lat = &t->io_completion_latency; ! print_lat("completion latency", lat); } *************** *** 415,421 **** * io unit, and make the io unit reusable again */ ! void finish_io(struct thread_info *t, struct io_unit *io, long result) { struct io_oper *oper = io->io_oper; io->res = result; io->busy = IO_FREE; --- 449,457 ---- * io unit, and make the io unit reusable again */ ! void finish_io(struct thread_info *t, struct io_unit *io, long result, ! struct timeval *tv_now) { struct io_oper *oper = io->io_oper; + calc_latency(&io->io_start_time, tv_now, &t->io_completion_latency); io->res = result; io->busy = IO_FREE; *************** *** 438,441 **** --- 474,478 ---- int i; int min_nr = io_iter; + struct timeval stop_time; if (t->num_global_pending < io_iter) *************** *** 450,457 **** return nr; for (i = 0 ; i < nr ; i++) { event = t->events + i; event_io = (struct io_unit *)((unsigned long)event->obj); ! finish_io(t, event_io, event->res); } return nr; --- 487,495 ---- return nr; + gettimeofday(&stop_time, NULL); for (i = 0 ; i < nr ; i++) { event = t->events + i; event_io = (struct io_unit *)((unsigned long)event->obj); ! finish_io(t, event_io, event->res, &stop_time); } return nr; *************** *** 507,513 **** while(io_getevents(t->io_ctx, 1, &event, NULL) > 0) { #endif event_io = (struct io_unit *)((unsigned long)event.obj); ! finish_io(t, event_io, event.res); if (oper->num_pending == 0) --- 545,553 ---- while(io_getevents(t->io_ctx, 1, &event, NULL) > 0) { #endif + struct timeval tv_now; event_io = (struct io_unit *)((unsigned long)event.obj); ! gettimeofday(&tv_now, NULL); ! finish_io(t, event_io, event.res, &tv_now); if (oper->num_pending == 0) *************** *** 683,687 **** * counters in the associated oper struct */ ! static void update_iou_counters(struct iocb **my_iocbs, int nr) { struct io_unit *io; --- 723,728 ---- * counters in the associated oper struct */ ! static void update_iou_counters(struct iocb **my_iocbs, int nr, ! struct timeval *tv_now) { struct io_unit *io; *************** *** 691,694 **** --- 732,736 ---- io->io_oper->num_pending++; io->io_oper->started_ios++; + io->io_start_time = *tv_now; /* set time of io_submit */ } } *************** *** 699,711 **** int ret; struct timeval start_time; resubmit: gettimeofday(&start_time, NULL); ret = io_submit(t->io_ctx, num_ios, my_iocbs); ! calc_latency(&start_time, &t->io_submit_latency); if (ret != num_ios) { /* some ios got through */ if (ret > 0) { ! update_iou_counters(my_iocbs, ret); my_iocbs += ret; t->num_global_pending += ret; --- 741,756 ---- int ret; struct timeval start_time; + struct timeval stop_time; resubmit: gettimeofday(&start_time, NULL); ret = io_submit(t->io_ctx, num_ios, my_iocbs); ! gettimeofday(&stop_time, NULL); ! calc_latency(&start_time, &stop_time, &t->io_submit_latency); ! if (ret != num_ios) { /* some ios got through */ if (ret > 0) { ! update_iou_counters(my_iocbs, ret, &stop_time); my_iocbs += ret; t->num_global_pending += ret; *************** *** 717,722 **** --- 762,771 ---- */ if (ret > 0 || ret == -EAGAIN) { + int old_ret = ret; if ((ret = read_some_events(t) > 0)) { goto resubmit; + } else { + fprintf(stderr, "ret was %d and now is %d\n", ret, old_ret); + abort(); } } *************** *** 725,729 **** return -1; } ! update_iou_counters(my_iocbs, ret); t->num_global_pending += ret; return 0; --- 774,778 ---- return -1; } ! update_iou_counters(my_iocbs, ret, &stop_time); t->num_global_pending += ret; return 0; *************** *** 1014,1018 **** void global_thread_throughput(struct thread_info *t, char *this_stage) { int i; ! double runtime = time_since(&global_stage_start_time); double total_mb = 0; double min_trans = 0; --- 1063,1067 ---- void global_thread_throughput(struct thread_info *t, char *this_stage) { int i; ! double runtime = time_since_now(&global_stage_start_time); double total_mb = 0; double min_trans = 0; *************** *** 1055,1110 **** restart: - printf("Starting %s iter:%d \n", __FUNCTION__,iteration); if (num_threads > 1) { - printf("num_threads %d \n", num_threads); pthread_mutex_lock(&stage_mutex); ! threads_starting++; ! if (threads_starting == num_threads) { ! threads_ending = 0; ! gettimeofday(&global_stage_start_time, NULL); ! pthread_cond_broadcast(&stage_cond); ! } ! while (threads_starting != num_threads) ! pthread_cond_wait(&stage_cond, &stage_mutex); pthread_mutex_unlock(&stage_mutex); } if (t->active_opers) { - // printf("active_opers %p line:%d\n", t->active_opers, __LINE__); this_stage = stage_name(t->active_opers->rw); ! gettimeofday(&stage_time, NULL); ! t->stage_mb_trans = 0; } cnt = 0; /* first we send everything through aio */ ! // printf("cnt:%d max_iterations:%d oper:%p\n",cnt, iterations,oper); ! ! while (t->active_opers && (cnt < iterations || iterations == RUN_FOREVER)) { ! // printf("active_opers %p line:%d cnt:%d ", t->active_opers,__LINE__,cnt); ! if (stonewall && threads_ending) { ! oper = t->active_opers; ! oper->stonewalled = 1; ! oper_list_del(oper, &t->active_opers); ! oper_list_add(oper, &t->finished_opers); ! // printf(" if branch\n"); ! } else { ! run_active_list(t, io_iter, max_io_submit); ! // printf(" else branch\n"); } ! cnt++; } - if (latency_stats) print_latency(t); /* then we wait for all the operations to finish */ oper = t->finished_opers; - // printf("line:%d oper:%p\n", __LINE__, oper); do { ! io_oper_wait(t, oper); ! if (oper != NULL) { ! oper = oper->next; ! } ! } while (oper != t->finished_opers); ! // printf("finished_opers %p line:%d\n", t->finished_opers,__LINE__); /* then we do an fsync to get the timing for any future operations --- 1104,1152 ---- restart: if (num_threads > 1) { pthread_mutex_lock(&stage_mutex); ! threads_starting++; ! if (threads_starting == num_threads) { ! threads_ending = 0; ! gettimeofday(&global_stage_start_time, NULL); ! pthread_cond_broadcast(&stage_cond); ! } ! while (threads_starting != num_threads) ! pthread_cond_wait(&stage_cond, &stage_mutex); pthread_mutex_unlock(&stage_mutex); } if (t->active_opers) { this_stage = stage_name(t->active_opers->rw); ! gettimeofday(&stage_time, NULL); ! t->stage_mb_trans = 0; } + cnt = 0; /* first we send everything through aio */ ! while(t->active_opers && (cnt < iterations || iterations == RUN_FOREVER)) { ! if (stonewall && threads_ending) { ! oper = t->active_opers; ! oper->stonewalled = 1; ! oper_list_del(oper, &t->active_opers); ! oper_list_add(oper, &t->finished_opers); ! } else { ! run_active_list(t, io_iter, max_io_submit); } ! cnt++; } if (latency_stats) print_latency(t); + if (completion_latency_stats) + print_completion_latency(t); + /* then we wait for all the operations to finish */ oper = t->finished_opers; do { ! if (!oper) ! break; ! io_oper_wait(t, oper); ! oper = oper->next; ! } while(oper != t->finished_opers); /* then we do an fsync to get the timing for any future operations *************** *** 1112,1166 **** */ oper = t->finished_opers; ! // printf("oper %p line:%d\n", oper,__LINE__); ! while (oper) { ! if (fsync_stages) fsync(oper->fd); ! t->stage_mb_trans += oper_mb_trans(oper); ! if (restart_oper(oper)) { ! oper_list_del(oper, &t->finished_opers); ! oper_list_add(oper, &t->active_opers); ! oper = t->finished_opers; ! continue; ! } ! oper = oper->next; ! if (oper == t->finished_opers) ! break; } if (t->stage_mb_trans && t->num_files > 0) { ! // printf("num_files %d line:%d\n", t->num_files,__LINE__); ! double seconds = time_since(&stage_time); ! fprintf(stderr, "thread %d %s totals (%.2f MB/s) %.2f MB in %.2fs\n", ! t - global_thread_info, this_stage, t->stage_mb_trans/seconds, ! t->stage_mb_trans, seconds); } if (num_threads > 1) { ! // printf("num_threads %d line:%d\n", num_threads,__LINE__); ! pthread_mutex_lock(&stage_mutex); ! threads_ending++; ! if (threads_ending == num_threads) { ! threads_starting = 0; ! pthread_cond_broadcast(&stage_cond); ! global_thread_throughput(t, this_stage); ! } ! // printf("threads_ending %d line:%d\n", threads_ending,__LINE__); ! while (threads_ending != num_threads) ! pthread_cond_wait(&stage_cond, &stage_mutex); ! pthread_mutex_unlock(&stage_mutex); } ! /* someone got restarted, go back to the beginning */ if (t->active_opers && (cnt < iterations || iterations == RUN_FOREVER)) { ! iteration++; goto restart; } /* finally, free all the ram */ ! // printf("finished_opers %p line:%d\n", t->finished_opers,__LINE__); ! while (t->finished_opers) { ! oper = t->finished_opers; ! oper_list_del(oper, &t->finished_opers); ! status = finish_oper(t, oper); } --- 1154,1203 ---- */ oper = t->finished_opers; ! while(oper) { ! if (fsync_stages) fsync(oper->fd); ! t->stage_mb_trans += oper_mb_trans(oper); ! if (restart_oper(oper)) { ! oper_list_del(oper, &t->finished_opers); ! oper_list_add(oper, &t->active_opers); ! oper = t->finished_opers; ! continue; ! } ! oper = oper->next; ! if (oper == t->finished_opers) ! break; } if (t->stage_mb_trans && t->num_files > 0) { ! double seconds = time_since_now(&stage_time); ! fprintf(stderr, "thread %d %s totals (%.2f MB/s) %.2f MB in %.2fs\n", ! t - global_thread_info, this_stage, t->stage_mb_trans/seconds, ! t->stage_mb_trans, seconds); } if (num_threads > 1) { ! pthread_mutex_lock(&stage_mutex); ! threads_ending++; ! if (threads_ending == num_threads) { ! threads_starting = 0; ! pthread_cond_broadcast(&stage_cond); ! global_thread_throughput(t, this_stage); ! } ! while(threads_ending != num_threads) ! pthread_cond_wait(&stage_cond, &stage_mutex); ! pthread_mutex_unlock(&stage_mutex); } ! /* someone got restarted, go back to the beginning */ if (t->active_opers && (cnt < iterations || iterations == RUN_FOREVER)) { ! iteration++; goto restart; } /* finally, free all the ram */ ! while(t->finished_opers) { ! oper = t->finished_opers; ! oper_list_del(oper, &t->finished_opers); ! status = finish_oper(t, oper); } *************** *** 1169,1173 **** } io_queue_release(t->io_ctx); ! return status; } --- 1206,1210 ---- } io_queue_release(t->io_ctx); ! return status; } *************** *** 1180,1184 **** int i; - // printf("%s num_threads %d line:%d\n", __FUNCTION__,num_threads,__LINE__); for(i = 0 ; i < num_threads ; i++) { ret = pthread_create(&t[i].tid, NULL, (start_routine)worker, t + i); --- 1217,1220 ---- *************** *** 1220,1223 **** --- 1256,1263 ---- mult = 1024; break; + case 'b': + case 'B': + mult = 1; + break; } ret = mult * num; *************** *** 1247,1251 **** --- 1287,1293 ---- printf("\t-n no fsyncs between write stage and read stage\n"); printf("\t-l print io_submit latencies after each stage\n"); + printf("\t-L print io completion latencies after each stage\n"); printf("\t-t number of threads to run\n"); + printf("\t-u unlink files after completion\n"); printf("\t-v verification of bytes written\n"); printf("\t-x turn off thread stonewalling\n"); *************** *** 1274,1278 **** while(1) { ! c = getopt(ac, av, "a:b:c:C:m:s:r:d:i:I:o:t:lnhOSxv"); if (c < 0) break; --- 1316,1320 ---- while(1) { ! c = getopt(ac, av, "a:b:c:C:m:s:r:d:i:I:o:t:lLnhOSxvu"); if (c < 0) break; *************** *** 1312,1315 **** --- 1354,1360 ---- latency_stats = 1; break; + case 'L': + completion_latency_stats = 1; + break; case 'm': if (!strcmp(optarg, "shm")) { *************** *** 1338,1341 **** --- 1383,1389 ---- stonewall = 0; break; + case 'u': + unlink_files = 1; + break; case 'v': verify = 1; *************** *** 1421,1425 **** thread_index = open_fds % num_threads; open_fds++; - // fprintf(stderr, "adding file %s thread %d\n", av[i], thread_index); rwfd = open(av[i], O_CREAT | O_RDWR | o_direct | o_sync, 0600); --- 1469,1472 ---- *************** *** 1449,1472 **** printf("Running multi thread version num_threads:%d\n", num_threads); run_workers(t, num_threads); ! } ! else { printf("Running single thread version \n"); ! status = worker(t); } ! ! ! for (i = optind ; i < ac ; i++) { ! printf("Cleaning up file %s \n", av[i]); ! unlink(av[i]); } if (status) { ! printf("non zero return %d \n", status); ! } ! else{ ! printf("aio-stress Completed successfully %d \n", status); } ! ! exit(0); } - --- 1496,1513 ---- printf("Running multi thread version num_threads:%d\n", num_threads); run_workers(t, num_threads); ! } else { printf("Running single thread version \n"); ! status = worker(t); } ! if (unlink_files) { ! for (i = optind ; i < ac ; i++) { ! printf("Cleaning up file %s \n", av[i]); ! unlink(av[i]); ! } } if (status) { ! exit(1); } ! return status; } |