Skip to content

Handle memory allocation failure properly, allow to override SIZE, fix declaration compatability. #27

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

Open
wants to merge 2 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
33 changes: 28 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down