diff --git a/main.c b/main.c index 6205555..3285e8e 100644 --- a/main.c +++ b/main.c @@ -40,7 +40,7 @@ #include "asm-opt.h" #include "version.h" -#define SIZE (32 * 1024 * 1024) +#define SIZE_DEFAULT (32 * 1024 * 1024) #define BLOCKSIZE 2048 #ifndef MAXREPEATS # define MAXREPEATS 10 @@ -480,12 +480,14 @@ int latency_bench(int size, int count, int use_hugepage) return 1; } -int main(void) +int main(int argc, char *argv[]) { - int latbench_size = SIZE * 2, latbench_count = LATBENCH_COUNT; + int latbench_size, latbench_count = LATBENCH_COUNT; + int custom_size = SIZE_DEFAULT; int64_t *srcbuf, *dstbuf, *tmpbuf; void *poolbuf; - size_t bufsize = SIZE; + size_t bufsize; + bench_info *bi; #ifdef __linux__ size_t fbsize = 0; int64_t *fbbuf = mmap_framebuffer(&fbsize); @@ -494,11 +496,32 @@ int main(void) printf("tinymembench v" VERSION " (simple benchmark for memory throughput and latency)\n"); + if (argc > 1) { + custom_size = atoi (argv[1]); + if ((custom_size < 4096) || (custom_size > 16*SIZE_DEFAULT)) { + printf("WARNING: unexpected size specified, using default instead.\n"); + custom_size = SIZE_DEFAULT; + } + } + if (argc > 2) { + latbench_count = atoi (argv[2]); + if ((latbench_count < 100) || (latbench_count > 100*LATBENCH_COUNT)) { + printf("WARNING: unexpected count specified, using default instead.\n"); + latbench_count = LATBENCH_COUNT; + } + } + latbench_size = custom_size * 2; + bufsize = custom_size; poolbuf = alloc_four_nonaliased_buffers((void **)&srcbuf, bufsize, (void **)&dstbuf, bufsize, (void **)&tmpbuf, BLOCKSIZE, NULL, 0); + if (!poolbuf) { + printf("FATAL: memory allocation failed. Please override SIZE_DEFAULT (%ld bytes) on command line.\n", (long)SIZE_DEFAULT); + return 1; + } + printf("\n"); printf("==========================================================================\n"); printf("== Memory bandwidth tests ==\n"); @@ -517,7 +540,7 @@ int main(void) bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", c_benchmarks); printf(" ---\n"); bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", libc_benchmarks); - bench_info *bi = get_asm_benchmarks(); + bi = get_asm_benchmarks(); if (bi->f) { printf(" ---\n"); bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", bi); diff --git a/util.c b/util.c index a0d562c..10d8c87 100644 --- a/util.c +++ b/util.c @@ -337,6 +337,7 @@ void *alloc_four_nonaliased_buffers(void **buf1_, int size1, ptr = buf = (char *)malloc(size1 + size2 + size3 + size4 + 9 * ALIGN_PADDING); + if (!ptr) return ptr; memset(buf, 0xCC, size1 + size2 + size3 + size4 + 9 * ALIGN_PADDING); ptr = align_up(ptr, ALIGN_PADDING);