From a6dce3abffdfc5ba96a877cfd61b023c9f633306 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Tue, 17 Apr 2012 13:14:30 -0400 Subject: [PATCH] regressions/ck_bag: Use epoch reclamation, allow for user-defined block size. --- regressions/ck_bag/validate/Makefile | 4 +-- regressions/ck_bag/validate/order.c | 54 ++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/regressions/ck_bag/validate/Makefile b/regressions/ck_bag/validate/Makefile index 563566f..1d1b1aa 100644 --- a/regressions/ck_bag/validate/Makefile +++ b/regressions/ck_bag/validate/Makefile @@ -4,8 +4,8 @@ OBJECTS=order all: $(OBJECTS) -order: order.c ../../../include/ck_bag.h ../../../src/ck_bag.c - $(CC) $(CFLAGS) -o order order.c ../../../src/ck_bag.c +order: order.c ../../../include/ck_bag.h ../../../src/ck_bag.c ../../../src/ck_epoch.c + $(CC) $(CFLAGS) -o order order.c ../../../src/ck_bag.c ../../../src/ck_epoch.c clean: rm -rf *.dSYM *~ *.o $(OBJECTS) diff --git a/regressions/ck_bag/validate/order.c b/regressions/ck_bag/validate/order.c index 9625cee..941e9be 100644 --- a/regressions/ck_bag/validate/order.c +++ b/regressions/ck_bag/validate/order.c @@ -39,24 +39,45 @@ #define READ_LATENCY 8 static ck_bag_t bag; +static ck_epoch_t epoch_bag; +static ck_epoch_record_t epoch_wr; static int leave; static unsigned int barrier; +struct bag_epoch { + ck_epoch_entry_t epoch_entry; +}; + +static void +bag_destroy(ck_epoch_entry_t *e) +{ + + free(e); + return; +} + static void * bag_malloc(size_t r) { + struct bag_epoch *b; - return malloc(r); + b = malloc(sizeof(*b) + r); + return b + 1; } static void bag_free(void *p, size_t b, bool r) { + struct bag_epoch *e = p; - (void)p; (void)b; - (void)r; -// free(p); + + if (r == true) { + ck_epoch_free(&epoch_wr, &(--e)->epoch_entry, bag_destroy); + } else { + free(--e); + } + return; } @@ -71,11 +92,13 @@ reader(void *arg) void *curr_ptr; intptr_t curr, prev, curr_max, prev_max; unsigned long long n_entries = 0, iterations = 0; + ck_epoch_record_t epoch_record; + ck_bag_iterator_t iterator; + struct ck_bag_block *block = NULL; (void)arg; - ck_bag_iterator_t iterator; - struct ck_bag_block *block = NULL; + ck_epoch_register(&epoch_bag, &epoch_record); /* * Check if entries within a block are sequential. Since ck_bag inserts @@ -175,14 +198,23 @@ main(int argc, char **argv) unsigned int i, curr; void *curr_ptr; ck_bag_iterator_t bag_it; + size_t b = CK_BAG_DEFAULT; - (void)argc; - (void)argv; + if (argc == 2) { + int r = atoi(argv[1]); + if (r <= 0) { + fprintf(stderr, "# entries in block must be > 0\n"); + exit(EXIT_FAILURE); + } - ck_bag_allocator_set(&allocator, 0); - ck_bag_init(&bag, CK_BAG_DEFAULT, CK_BAG_ALLOCATE_GEOMETRIC); + b = (size_t)r; + } - fprintf(stderr, "Block Size: %zuB\n", bag.info.bytes); + ck_epoch_init(&epoch_bag, 100); + ck_epoch_register(&epoch_bag, &epoch_wr); + ck_bag_allocator_set(&allocator, sizeof(struct bag_epoch)); + ck_bag_init(&bag, b, CK_BAG_ALLOCATE_GEOMETRIC); + fprintf(stderr, "Configuration: %zu bytes/block, %zu entries/block\n", bag.info.bytes, bag.info.max); /* Sequential test */ for (i = 0; i < 10; i++)