Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make some hard-coded values into arguments #23

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#include <math.h>
#include <sys/time.h>

#ifdef __linux__
#if !defined(_WIN64) && !defined(_WIN32)
#include <unistd.h>
#endif
#ifdef __linux__
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
Expand All @@ -49,6 +51,8 @@
# define LATBENCH_COUNT 10000000
#endif

char *progname;

#ifdef __linux__
static void *mmap_framebuffer(size_t *fbsize)
{
Expand Down Expand Up @@ -480,28 +484,65 @@ int latency_bench(int size, int count, int use_hugepage)
return 1;
}

int main(void)
static void
usage()
{
int latbench_size = SIZE * 2, latbench_count = LATBENCH_COUNT;
fprintf(stderr, "usage: %s [-s buffer size -b blocksize -l latency max size -c latency count]\n",
progname);
fprintf(stderr, "\t-b Memory blocksize in Bytes <%d>\n", BLOCKSIZE);
fprintf(stderr, "\t-s Memory buffer size in Bytes <%d>\n", SIZE);
fprintf(stderr, "\t-l Latency test maximum buffer size in Bytes <%d>\n", SIZE * 2);
fprintf(stderr, "\t-c Latency count <%d>\n", LATBENCH_COUNT);
exit(EXIT_FAILURE);
}

int main(int argc, char *argv[])
{
int ch;
int latbench_size = SIZE * 2, latbench_count = LATBENCH_COUNT;
size_t bufsize = SIZE;
int blocksize = BLOCKSIZE;

progname = argv[0];
while ((ch = getopt(argc, argv, "hb:c:l:s:")) != -1) {
switch (ch) {
case 'b':
blocksize = atoi(optarg);
break;
case 'c':
latbench_count = atoi(optarg);
break;
case 'l':
latbench_size = atoi(optarg);
break;
case 's':
bufsize = atoi(optarg);
break;
case 'h':
usage();
}
}

int64_t *srcbuf, *dstbuf, *tmpbuf;
void *poolbuf;
size_t bufsize = SIZE;
#ifdef __linux__
size_t fbsize = 0;
int64_t *fbbuf = mmap_framebuffer(&fbsize);
fbsize = (fbsize / BLOCKSIZE) * BLOCKSIZE;
fbsize = (fbsize / blocksize) * blocksize;
#endif

printf("tinymembench v" VERSION " (simple benchmark for memory throughput and latency)\n");


poolbuf = alloc_four_nonaliased_buffers((void **)&srcbuf, bufsize,
(void **)&dstbuf, bufsize,
(void **)&tmpbuf, BLOCKSIZE,
(void **)&tmpbuf, blocksize,
NULL, 0);
printf("\n");
printf("==========================================================================\n");
printf("== Memory bandwidth tests ==\n");
printf("== size Bytes: %zu ==\n", bufsize);
printf("== blocksize Bytes: %d ==\n", blocksize);
printf("== ==\n");
printf("== Note 1: 1MB = 1000000 bytes ==\n");
printf("== Note 2: Results for 'copy' tests show how many bytes can be ==\n");
Expand All @@ -514,13 +555,13 @@ int main(void)
printf("== brackets ==\n");
printf("==========================================================================\n\n");

bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", c_benchmarks);
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, blocksize, " ", c_benchmarks);
printf(" ---\n");
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", libc_benchmarks);
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, blocksize, " ", libc_benchmarks);
bench_info *bi = get_asm_benchmarks();
if (bi->f) {
printf(" ---\n");
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", bi);
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, blocksize, " ", bi);
}

#ifdef __linux__
Expand Down Expand Up @@ -551,7 +592,7 @@ int main(void)
srcbuf = fbbuf;
if (bufsize > fbsize)
bufsize = fbsize;
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, BLOCKSIZE, " ", bi);
bandwidth_bench(dstbuf, srcbuf, tmpbuf, bufsize, blocksize, " ", bi);
}
#endif

Expand All @@ -560,6 +601,8 @@ int main(void)
printf("\n");
printf("==========================================================================\n");
printf("== Memory latency test ==\n");
printf("== latbench_size Bytes: %d ==\n", latbench_size);
printf("== latbench_count: %d ==\n", latbench_count);
printf("== ==\n");
printf("== Average time is measured for random memory accesses in the buffers ==\n");
printf("== of different sizes. The larger is the buffer, the more significant ==\n");
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define VERSION "0.4.9"
#define VERSION "0.5.0"