diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-06-27 01:08:35 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-06-27 01:08:35 +0200 |
| commit | 8676bdeadd162d8e3c1f27cc7ad9f7456496b0ce (patch) | |
| tree | 69ee5b183195e4fb72d60c6fd5e74a5b67d76859 | |
| parent | 23e77009bb8da35e2285c3a8f5913c192f9e009f (diff) | |
| download | allocbench-8676bdeadd162d8e3c1f27cc7ad9f7456496b0ce.tar.gz allocbench-8676bdeadd162d8e3c1f27cc7ad9f7456496b0ce.zip | |
add draft of loop benchmark with two flavorsloop_keep_allocs
plot_fixed is broken because of the three args
TODO: implement usfull plots for n arg commands.
| -rw-r--r-- | src/benchmarks/loop.py | 5 | ||||
| -rw-r--r-- | src/benchmarks/loop/Makefile | 6 | ||||
| -rw-r--r-- | src/benchmarks/loop/loop.c | 43 |
3 files changed, 36 insertions, 18 deletions
diff --git a/src/benchmarks/loop.py b/src/benchmarks/loop.py index be0def8..69621f1 100644 --- a/src/benchmarks/loop.py +++ b/src/benchmarks/loop.py @@ -8,10 +8,11 @@ class Benchmark_Loop(Benchmark): self.descrition = """This benchmark allocates and frees n blocks in t concurrent threads.""" - self.cmd = "loop{binary_suffix} {nthreads} 1000000 {maxsize}" + self.cmd = "loop{version}{binary_suffix} {nthreads} 1000000 {maxsize} 100" self.args = {"maxsize": [2 ** x for x in range(6, 16)], - "nthreads": Benchmark.scale_threads_for_cpus(2)} + "nthreads": Benchmark.scale_threads_for_cpus(2), + "version": ("", "KeepAllocs")} self.requirements = ["loop"] super().__init__() diff --git a/src/benchmarks/loop/Makefile b/src/benchmarks/loop/Makefile index b297933..9bcb247 100644 --- a/src/benchmarks/loop/Makefile +++ b/src/benchmarks/loop/Makefile @@ -12,12 +12,16 @@ LDFLAGS ?= -pthread -static-libgcc .PHONY = all clean -all: $(OBJDIR)/loop +all: $(OBJDIR)/loop $(OBJDIR)/loopKeepAllocs $(OBJDIR)/loop: loop.c | $(OBJDIR) @echo compiling $@... $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< +$(OBJDIR)/loopKeepAllocs: loop.c | $(OBJDIR) + @echo compiling $@... + $(CC) $(LDFLAGS) -DKEEP_ALLOCS $(CFLAGS) -o $@ $< + $(OBJDIR): mkdir -p $@ diff --git a/src/benchmarks/loop/loop.c b/src/benchmarks/loop/loop.c index 6297e49..9593cd5 100644 --- a/src/benchmarks/loop/loop.c +++ b/src/benchmarks/loop/loop.c @@ -19,26 +19,29 @@ typedef struct ThreadArgs { double benchmark; int allocations; int max_size; +#ifdef KEEP_ALLOCS + int num_to_keep; +#endif } ThreadArgs; -static void* malloc_then_write(size_t size) { - void* ptr = malloc(size); - // Write to ptr - /* *((char*)ptr) = '!'; */ - return ptr; -} - -static void read_then_free(void* ptr) { - // Read before free - /* char s __attribute__((unused)) = *((char*)ptr); */ - free(ptr); -} static void* test_thread_func(void* arg) { ThreadArgs* args = (ThreadArgs*)arg; +#ifdef KEEP_ALLOCS + void** ptrs = (void**)calloc(args->num_to_keep, sizeof(void*)); +#endif for(int i = 0; i < args->allocations; i++) { - void* ptr = malloc_then_write((_rand() % args->max_size) + 1); - read_then_free(ptr); +#ifdef KEEP_ALLOCS + int pos = i % args->num_to_keep; + if (0 == pos && i > 0) { + for (int j = 0; j < args->num_to_keep; j++) + free(ptrs[j]); + } + ptrs[pos] = malloc((_rand() % args->max_size) + 1); +#else + void* ptr = malloc((_rand() % args->max_size) + 1); + free(ptr); +#endif } return NULL; } @@ -48,14 +51,24 @@ int main(int argc, char* argv[]) { int num_threads; struct ThreadArgs thread_args; +#ifdef KEEP_ALLOCS + if (argc < 5) { + fprintf(stderr, "Usage: %s <num threads> <num allocations> <max size> <allocs to keep>\n", argv[0]); + return 1; + } +#else if (argc < 4) { fprintf(stderr, "Usage: %s <num threads> <num allocations> <max size>\n", argv[0]); return 1; } +#endif num_threads = atoi(argv[1]); thread_args.allocations = atoi(argv[2]); thread_args.max_size = atoi(argv[3]); +#ifdef KEEP_ALLOCS + thread_args.num_to_keep = atoi(argv[4]); +#endif threads = (pthread_t*)malloc(num_threads * sizeof(pthread_t)); @@ -73,7 +86,7 @@ int main(int argc, char* argv[]) { } } - if (argc == 5) + if (argc == 6) { FILE* f = stdout; if (strcmp(argv[4],"stdout") != 0) |
