diff options
| author | Martin Fink <martin@finkmartin.com> | 2025-05-12 08:14:08 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-12 08:14:08 +0200 |
| commit | 0866a557ac461a1b345dd9ff1e13b01105458ef8 (patch) | |
| tree | 483f44335b623c1f2a8ba911d1feb776eb3df642 /archive/2024/winter/bsc_dichler/experiments/malloc/main.c | |
| parent | e546f71869e32e88716c4ad05e0254ea3352a668 (diff) | |
| parent | f60cf8c4ba75eee2b25ffbeea2330206b257aae9 (diff) | |
| download | research-work-archive-artifacts-0866a557ac461a1b345dd9ff1e13b01105458ef8.tar.gz research-work-archive-artifacts-0866a557ac461a1b345dd9ff1e13b01105458ef8.zip | |
Merge pull request #2 from raphaeldichler/main
Add source code of 'Evaluation of the Performance of the Memory Tagging Extensions'
Diffstat (limited to 'archive/2024/winter/bsc_dichler/experiments/malloc/main.c')
| -rw-r--r-- | archive/2024/winter/bsc_dichler/experiments/malloc/main.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/archive/2024/winter/bsc_dichler/experiments/malloc/main.c b/archive/2024/winter/bsc_dichler/experiments/malloc/main.c new file mode 100644 index 000000000..58932af78 --- /dev/null +++ b/archive/2024/winter/bsc_dichler/experiments/malloc/main.c @@ -0,0 +1,83 @@ +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <stdlib.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/auxv.h> +#include <sys/mman.h> +#include <sys/prctl.h> +#include <time.h> +#include "../allocator/allocator.h" + +#define _GNU_SOURCE + +#include <stdio.h> +#include <stdlib.h> +#include <sys/prctl.h> + +#define PR_TAGGED_ADDR_ENABLE (1UL << 0) + +#define WARUM_UP 1 + +struct bench { + size_t allocation; + size_t bytes_to_alloc; + void *ptrs[ALLOCATIONS]; +}; + +void benchmark(struct bench *bench) { + for (size_t i = 0; i < bench->allocation; ++i) { + bench->ptrs[i] = malloc(bench->bytes_to_alloc); + } +} + +int main(int argc, char *args[]) { + if (argc != 3) { + printf("Usage: %s <iterations> <size>\n", args[0]); + exit(EXIT_FAILURE); + } + + size_t iterations = atoll(args[1]); + size_t size = atoll(args[2]); + + size_t allocations = (1 << 28) / size; + // ensure we size is a multiple of 16, to match granularity + assert(size % 16 == 0); + assert(allocations * size < (1 << 29)); + + void *ptr = malloc(1024); + + struct bench *bench= alloc(sizeof(struct bench)); + bench->allocation = allocations; + bench->bytes_to_alloc = size; + for (size_t i = 0; i < iterations + WARUM_UP; ++i) { + + struct timespec s, e1, e2; + clock_gettime(CLOCK_MONOTONIC_RAW, &s); + benchmark(bench); + clock_gettime(CLOCK_MONOTONIC_RAW, &e1); + + for (size_t j = 0; j < bench->allocation; ++j) { + free(bench->ptrs[j]); + } + + clock_gettime(CLOCK_MONOTONIC_RAW, &e2); + + if (i > WARUM_UP) { + uint64_t duration_allocation = 1e9 * (e1.tv_sec - s.tv_sec) + (e1.tv_nsec - s.tv_nsec); + uint64_t duration_deallocation = 1e9 * (e2.tv_sec - e1.tv_sec) + (e2.tv_nsec - e1.tv_nsec); + + printf("%ld;%ld;%ld;%ld\n", size, allocations, duration_allocation, duration_deallocation); + } + + } + + alloc_free(bench, sizeof(struct bench)); + free(ptr); +} |