From 8f89f1da7b451b49fc579bdbd7fae5e2c51ff14d Mon Sep 17 00:00:00 2001 From: Andras HORVATH Date: Sun, 11 Mar 2012 10:26:29 +0100 Subject: Re-indenting, cosmetic changes --- mbw.c | 429 ++++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 221 insertions(+), 208 deletions(-) diff --git a/mbw.c b/mbw.c index 4fe77e4..3a02826 100644 --- a/mbw.c +++ b/mbw.c @@ -1,3 +1,6 @@ +/* + * vim: ai ts=4 sts=4 sw=4 cinoptions=>4 expandtab + */ #define _GNU_SOURCE #include @@ -21,57 +24,62 @@ #define DEFAULT_BLOCK_SIZE 262144 /* - * Bare-bones memory bandwidth tester + * MBW memory bandwidth benchmark + * + * 2006, 2012 Andras.Horvath@gmail.com + * + * http://github.com/raas/mbw * - * Andras.Horvath@cern.ch * compile with: * gcc -O -o mbw mbw.c * * run with eg.: * * ./mbw 300 - * + * * or './mbw -h' for help * * watch out for swap usage (or turn off swap) */ -void usage() { - printf("Usage: mbw [options] array_size_in_MiB\n"); - printf("Options:\n"); - printf(" -n: number of runs per test\n"); - printf(" -a: Don't display average\n"); - printf(" -t0: memcpy test\n"); - printf(" -t1: dumb (b[i]=a[i] style) test\n"); - printf(" -t2 : memcpy test with fixed block size\n"); - printf(" -b : block size in bytes for -t2 (default: %d)\n",DEFAULT_BLOCK_SIZE); - printf(" -q: quiet (print statistics only)\n"); - printf("(will then use two arrays, watch out for swapping)\n"); - printf("'Bandwidth' is amount of data copied over the time this operation took.\n"); - printf("\nThe default is to run all tests available.\n"); +void usage() +{ + printf("Usage: mbw [options] array_size_in_MiB\n"); + printf("Options:\n"); + printf(" -n: number of runs per test\n"); + printf(" -a: Don't display average\n"); + printf(" -t0: memcpy test\n"); + printf(" -t1: dumb (b[i]=a[i] style) test\n"); + printf(" -t2 : memcpy test with fixed block size\n"); + printf(" -b : block size in bytes for -t2 (default: %d)\n", DEFAULT_BLOCK_SIZE); + printf(" -q: quiet (print statistics only)\n"); + printf("(will then use two arrays, watch out for swapping)\n"); + printf("'Bandwidth' is amount of data copied over the time this operation took.\n"); + printf("\nThe default is to run all tests available.\n"); } /* ------------------------------------------------------ */ /* allocate a test array and fill it with data * so as to force Linux to _really_ allocate it */ -long *make_array(unsigned long long asize) { - unsigned long long t; - unsigned int long_size=sizeof(long); - long *a; - - a=calloc(asize, long_size); - - if(NULL==a) { - perror("Error allocating memory"); - exit(1); - } - - /* make sure both arrays are allocated, fill with pattern */ - for(t=0; tarray_bytes){ - b=mempcpy(b,a,t-array_bytes); - } - gettimeofday(&endtime, NULL); - } else { /* dumb test */ - gettimeofday(&starttime, NULL); - for(t=0; tarray_bytes) { + b=mempcpy(b, a, t-array_bytes); + } + gettimeofday(&endtime, NULL); + } else { /* dumb test */ + gettimeofday(&starttime, NULL); + for(t=0; ttestno) { - printf("Error: test number must be between 0 and %d\n",MAX_TESTS); - usage(); - exit(1); - } - tests[testno]=1; - break; - case 'b': /* block size in bytes*/ - block_size=strtoull(optarg, (char **)NULL, 10); - if(0>=block_size) { - printf("Error: what block size do you mean?\n"); - usage(); - exit(1); - } - break; - case 'q': /* quiet */ - quiet=1; - break; - default: - break; - } - } - - /* default is to run all tests if no specific tests were requested */ - if( (tests[0]+tests[1]+tests[2]) == 0) { - tests[0]=1; - tests[1]=1; - tests[2]=1; - } - - if(optind=mt) { - printf("Error: array size wrong!\n"); - usage(); - exit(1); - } - - /* ------------------------------------------------------ */ - - long_size=sizeof(long); /* the size of long on this platform */ - asize=1024*1024/long_size*mt; /* how many longs then in one array? */ - - if(asize*long_size < block_size) { - printf("Error: array size larger than block size!\n"); - usage(); - exit(1); - } - - if(!quiet) { - printf("Long uses %d bytes. ",long_size); - printf("Allocating 2*%lld elements = %lld bytes of memory.\n",asize,2*asize*long_size); - if(tests[2]) { - printf("Using %lld bytes as blocks for memcpy block copy test.\n",block_size); - } - } - - a=make_array(asize); - b=make_array(asize); - - /* ------------------------------------------------------ */ - if(!quiet) { - printf("Getting down to business... Doing %d runs per test.\n",nr_loops); - } - - /* run all tests requested, the proper number of times */ - for(testno=0; testnotestno) { + printf("Error: test number must be between 0 and %d\n", MAX_TESTS); + exit(1); + } + tests[testno]=1; + break; + case 'b': /* block size in bytes*/ + block_size=strtoull(optarg, (char **)NULL, 10); + if(0>=block_size) { + printf("Error: what block size do you mean?\n"); + exit(1); + } + break; + case 'q': /* quiet */ + quiet=1; + break; + default: + break; + } + } + + /* default is to run all tests if no specific tests were requested */ + if( (tests[0]+tests[1]+tests[2]) == 0) { + tests[0]=1; + tests[1]=1; + tests[2]=1; + } + + if(optind=mt) { + printf("Error: array size wrong!\n"); + exit(1); + } + + /* ------------------------------------------------------ */ + + long_size=sizeof(long); /* the size of long on this platform */ + asize=1024*1024/long_size*mt; /* how many longs then in one array? */ + + if(asize*long_size < block_size) { + printf("Error: array size larger than block size (%llu bytes)!\n", block_size); + exit(1); + } + + if(!quiet) { + printf("Long uses %d bytes. ", long_size); + printf("Allocating 2*%lld elements = %lld bytes of memory.\n", asize, 2*asize*long_size); + if(tests[2]) { + printf("Using %lld bytes as blocks for memcpy block copy test.\n", block_size); + } + } + + a=make_array(asize); + b=make_array(asize); + + /* ------------------------------------------------------ */ + if(!quiet) { + printf("Getting down to business... Doing %d runs per test.\n", nr_loops); + } + + /* run all tests requested, the proper number of times */ + for(testno=0; testno