From: Luke M. <lu...@us...> - 2005-08-19 06:11:09
|
Update of /cvsroot/ipbench/ipbench2/src/tests/nfs_latency In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2101 Modified Files: nfs_latency.c Log Message: Lots of features --- mostly working now Index: nfs_latency.c =================================================================== RCS file: /cvsroot/ipbench/ipbench2/src/tests/nfs_latency/nfs_latency.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** nfs_latency.c 18 Aug 2005 07:04:28 -0000 1.8 --- nfs_latency.c 19 Aug 2005 06:11:01 -0000 1.9 *************** *** 27,30 **** --- 27,81 ---- }; + struct nfs_options{ + char *path; + char *filename; + uint64_t rate; + } nfs_options; + + static int parse_arg(char *arg) + { + char *p, cmd[200], *val; + + /* set up default values */ + nfs_options.path = "/tmp"; + nfs_options.filename = "bench.file"; + nfs_options.rate = 10000; + + /* parse parameters */ + while (next_token(&arg, cmd, " \t,")){ + if ((p = strchr(cmd, '='))) { + *p = '\0'; + val = p+1; + }else{ + val = NULL; + } + + /* test arguments */ + dbprintf("Got cmd %s val %s\n", cmd, val); + + if (!strcmp(cmd, "path")){ + nfs_options.path = strdup(val); + continue; + } + if (!strcmp(cmd, "filename")){ + nfs_options.filename = strdup(val); + continue; + } + if (!strcmp(cmd, "rate")){ + nfs_options.rate = strtoll(val, NULL, 10); + continue; + } + + dbprintf("Invalid argument %s=%s.\n", cmd, val); + } + + dbprintf("parse_arg: using: path=%s,filename=%s,rate=%lld\n", + nfs_options.path, + nfs_options.filename, + nfs_options.rate); + + return 0; + } + /* * Setup your test. After this is complete you should be ready to *************** *** 36,40 **** { int x; - char *tmp, *path, *filename; dbprintf("nfs_latency_setup - %s - %d - %s\n", hostname, port, arg); --- 87,90 ---- *************** *** 43,74 **** * port you can ignore. * arg is just a string that you need to parse however you want ! */ ! ! tmp = strdup(arg); ! path = filename = tmp; ! while(*tmp!='\0'){ ! if(*tmp=='/') ! filename=tmp; ! tmp++; ! } ! ! if(filename==path){ ! /* no / found, just a filename */ ! path="/"; ! }else{ ! /* split the filename and path */ ! *filename='\0'; ! filename++; ! } ! ! assert(*path!='\0' && *filename!='\0'); ! dbprintf("nfs_latency_setup - path=%s filename=%s\n", path, filename); ! x = init_and_open(hostname, path, filename); assert(x==0); - free(tmp); - return 0; } --- 93,106 ---- * port you can ignore. * arg is just a string that you need to parse however you want ! */ ! /* configure nfs options */ ! if (strlen(arg) != 0) ! if (parse_arg(arg)) ! return -1; ! x = init_and_open(hostname, nfs_options.path, nfs_options.filename); assert(x==0); return 0; } *************** *** 96,102 **** int target=200000; int r; ! uint64_t now, then; uint64_t start_time, end_time; uint64_t requests, replies; dbprintf("NFS_LATENCY START\n"); --- 128,135 ---- int target=200000; int r; ! uint64_t now, then, delta; uint64_t start_time, end_time; uint64_t requests, replies; + uint64_t predicted_requests; dbprintf("NFS_LATENCY START\n"); *************** *** 118,123 **** while(i<target){ now = time_stamp(); ! r = generate_request(now); ! requests++; if(process_reply(&then)==0){ replies++; --- 151,167 ---- while(i<target){ now = time_stamp(); ! ! delta = tick_to_usec(now - start_time); ! predicted_requests = (delta * nfs_options.rate) / US_PER_S; ! ! if(predicted_requests > requests){ ! r = generate_request(now); ! if(r>0){ ! requests++; ! }else{ ! printf("generate request failed\n"); ! } ! } ! if(process_reply(&then)==0){ replies++; *************** *** 130,134 **** end_time = time_stamp(); ! result.microseconds = tick_to_usec(start_time - end_time); result.sends = requests; result.recvs = replies; --- 174,178 ---- end_time = time_stamp(); ! result.microseconds = tick_to_usec(end_time - start_time); result.sends = requests; result.recvs = replies; *************** *** 269,272 **** --- 313,350 ---- } + /* needed for qsort */ + static int + compare_uint64(const void *a, const void *b){ + uint64_t *x, *y; + + x = (uint64_t*)a; + y = (uint64_t*)b; + + if(*x < *y) + return -1; + + if(*x > *y) + return 1; + + return 0; + } + + static uint64_t + average_uint64(uint64_t *x, uint64_t n){ + uint64_t i, total, new_total; + + assert(n>0); + + total = 0; + + for(i=0; i<n; i++){ + new_total = total + x[i]; + assert(new_total >= total); + total = new_total; + } + + return (total / n); + } + /* * data[] is an array that has whatever was passed back from each *************** *** 282,288 **** { int i; ! uint64_t c=0, *s=NULL, *tmp; dbprintf("NFS_LATENCY OUTPUT (nelem %d)\n", nelem); for (i = 0; i < nelem; i++) { int j; --- 360,373 ---- { int i; ! uint64_t aggregate_count=0, *aggregate=NULL, *tmp; ! uint64_t *runtime=NULL; ! uint64_t avg_latency, avg_runtime; ! uint64_t tot_requests=0, tot_replies=0; dbprintf("NFS_LATENCY OUTPUT (nelem %d)\n", nelem); + + runtime = malloc(nelem*sizeof(uint64_t)); + assert(runtime!=NULL); + for (i = 0; i < nelem; i++) { int j; *************** *** 299,320 **** printf("samples=%lld\n", theresult->samples); ! if(theresult->samples<=0){ ! dbprintf("No samples from client %d\n", i); ! continue; ! } ! tmp = realloc(s, (c + theresult->samples) * sizeof(uint64_t)); if(tmp==NULL){ dbprintf("Out of memory!\n"); return -1; } ! s = tmp; for(j=0; j<theresult->samples; j++){ ! s[c++] = theresult->data[j]; } } ! printf("c==%lld\n", c); dbprintf ("NFS_LATENCY DONE\n"); --- 384,430 ---- printf("samples=%lld\n", theresult->samples); ! tot_requests += theresult->sends; ! tot_replies += theresult->recvs; ! /* aggregate runtime */ ! runtime[i] = theresult->time; ! ! /* aggreagate samples */ ! assert(theresult->samples>0); ! tmp = realloc(aggregate, ! (aggregate_count + theresult->samples) ! * sizeof(uint64_t)); if(tmp==NULL){ dbprintf("Out of memory!\n"); return -1; } ! aggregate = tmp; for(j=0; j<theresult->samples; j++){ ! aggregate[aggregate_count++] = theresult->data[j]; } } ! /* sort the runtimes */ ! qsort(runtime, nelem, sizeof(uint64_t), compare_uint64); ! avg_runtime = average_uint64(runtime, nelem); ! ! /* sort the samples */ ! qsort(aggregate, aggregate_count, sizeof(uint64_t), compare_uint64); ! avg_latency = average_uint64(aggregate, aggregate_count); ! ! printf("Min runtime: %lld\n", runtime[0]); ! printf("Average runtime: %lld\n", avg_runtime); ! printf("Median runtime: %lld\n", runtime[nelem/2]); ! printf("Max runtime: %lld\n", runtime[nelem-1]); ! printf("Min latency: %lld\n", aggregate[0]); ! printf("Average latency: %lld\n", avg_latency); ! printf("Median latency: %lld\n", aggregate[aggregate_count/2]); ! printf("Max latency: %lld\n", aggregate[aggregate_count-1]); ! printf("Samples: %lld\n", aggregate_count); ! printf("Achieved request rate (avg): %lld\n", ! (tot_requests*1000000) / avg_runtime); ! printf("Achieved reply rate (avg): %lld\n", ! (tot_replies*1000000) / avg_runtime); dbprintf ("NFS_LATENCY DONE\n"); |