diff --git a/bench/likwid-bench.c b/bench/likwid-bench.c index e27fb04b3..0abb7ba26 100644 --- a/bench/likwid-bench.c +++ b/bench/likwid-bench.c @@ -78,7 +78,7 @@ extern void* getIterSingle(void* arg); printf("-t/--test <TEST>\t type of test \n"); \ printf("-w/--workgroup\t\t <thread_domain>:<size>[:<num_threads>[:<chunk size>:<stride>]-<streamId>:<domain_id>[:<offset>]\n"); \ printf("-W/--Workgroup\t\t <thread_domain>:<size>[:<num_threads>[:<chunk size>:<stride>]]\n"); \ - printf("\t\t\t\t <size> in kB, MB or GB (mandatory)\n"); \ + printf("\t\t\t\t <size> in B, kB, MB, GB, kiB, MiB or GiB (mandatory)\n"); \ printf("For dynamically loaded benchmarks\n"); \ printf("-f/--tempdir <PATH>\t Specify a folder for the temporary files. default: /tmp\n"); \ printf("-o/--asmout <FILE>\t Save generated assembly to file\n"); \ @@ -355,6 +355,7 @@ int main(int argc, char** argv) } } bdestroy(testcase); + testcase = bfromcstr("none"); if (!builtin) { dynbench_close(test, NULL); @@ -410,6 +411,7 @@ int main(int argc, char** argv) return EXIT_FAILURE; } bdestroy(testcase); + testcase = bfromcstr("none"); break; case 'o': case 'f': diff --git a/bench/src/strUtil.c b/bench/src/strUtil.c index 2b1fd7d5b..a85e49d68 100644 --- a/bench/src/strUtil.c +++ b/bench/src/strUtil.c @@ -61,6 +61,38 @@ str2int(const char* str) return (int) val; } +static int +str2uint64_t(const char* str, uint64_t* result) +{ + char* endptr; + errno = 0; + unsigned long long val; + val = strtoull(str, &endptr, 10); + + if ((errno == ERANGE && val == ULLONG_MAX) + || (errno != 0 && val == 0)) + { + fprintf(stderr, "Value in string %s out of range\n", str); + return -EINVAL; + } + + if (endptr == str) + { + fprintf(stderr, "No digits were found in %s\n", str); + return -EINVAL; + } + + // long long could be larger than 64 bits + if (val > 0xFFFFFFFFFFFFFFFF) + { + fprintf(stderr, "Value in string %s out of range for uint64_t\n", str); + return -EINVAL; + } + + *result = val; + return 1; +} + /* ##### FUNCTION DEFINITIONS - EXPORTED FUNCTIONS ################## */ uint64_t @@ -69,31 +101,31 @@ bstr_to_doubleSize(const_bstring str, DataType type) int ret; bstring unit = bmidstr(str, blength(str)-2, 2); bstring single_unit = bmidstr(str, blength(str)-1, 1); + bstring triple_unit = bmidstr(str, blength(str)-3, 3); bstring sizeStr = bmidstr(str, 0, blength(str)-2); bstring single_sizeStr = bmidstr(str, 0, blength(str)-1); + bstring triple_sizeStr = bmidstr(str, 0, blength(str)-3); uint64_t sizeU = 0; uint64_t single_sizeU = 0; + uint64_t triple_sizeU = 0; uint64_t junk = 0; uint64_t bytesize = 0; if (blength(sizeStr) == 0) { return 0; } - ret = str2int(bdata(sizeStr)); - if (ret >= 0) - { - sizeU = str2int(bdata(sizeStr)); - } - else + ret = str2uint64_t(bdata(sizeStr), &sizeU); + if (ret < 0) { return 0; } - ret = str2int(bdata(single_sizeStr)); - if (ret >= 0) + ret = str2uint64_t(bdata(single_sizeStr), &single_sizeU); + if (ret < 0) { - single_sizeU = str2int(bdata(single_sizeStr)); + return 0; } - else + ret = str2uint64_t(bdata(triple_sizeStr), &triple_sizeU); + if (ret < 0) { return 0; } @@ -112,14 +144,28 @@ bstr_to_doubleSize(const_bstring str, DataType type) { junk = (sizeU *1000000000)/bytesize; } + else if ((biseqcstr(triple_unit, "kiB"))||(biseqcstr(triple_unit, "KiB"))) + { + junk = (triple_sizeU *1024)/bytesize; + } + else if (biseqcstr(triple_unit, "MiB")) + { + junk = (triple_sizeU *1024*1024)/bytesize; + } + else if (biseqcstr(triple_unit, "GiB")) + { + junk = (triple_sizeU *1024*1024*1024)/bytesize; + } else if (biseqcstr(single_unit, "B")) { junk = (single_sizeU)/bytesize; } bdestroy(unit); bdestroy(single_unit); + bdestroy(triple_unit); bdestroy(sizeStr); bdestroy(single_sizeStr); + bdestroy(triple_sizeStr); return junk; } diff --git a/doc/likwid-bench.1 b/doc/likwid-bench.1 index a6b78b68b..df7347170 100644 --- a/doc/likwid-bench.1 +++ b/doc/likwid-bench.1 @@ -71,7 +71,7 @@ Filepath for the dynamic generation of benchmarks. Default /tmp/. <PID> is alway .SH WORKGROUP SYNTAX .B <thread_domain>:<size> [:<num_threads>[:<chunk_size>:<stride>]] [-<streamId>:<domain_id>] -with size in kB, MB or GB. The +with size in B, kB, MB, GB, kiB, MiB or GiB. The .B <thread_domain> defines where the threads are placed. .B <size>