From e36b37583bebd229102f46c4ed7d2f6fad8697d4 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 23 Jul 2021 13:24:09 +0200 Subject: Adding upstream version 0.6.0. Signed-off-by: Daniel Baumann --- regressions/ck_bytelock/benchmark/Makefile | 14 +++ regressions/ck_bytelock/benchmark/latency.c | 99 +++++++++++++++++ regressions/ck_bytelock/validate/Makefile | 17 +++ regressions/ck_bytelock/validate/validate.c | 166 ++++++++++++++++++++++++++++ 4 files changed, 296 insertions(+) create mode 100644 regressions/ck_bytelock/benchmark/Makefile create mode 100644 regressions/ck_bytelock/benchmark/latency.c create mode 100644 regressions/ck_bytelock/validate/Makefile create mode 100644 regressions/ck_bytelock/validate/validate.c (limited to 'regressions/ck_bytelock') diff --git a/regressions/ck_bytelock/benchmark/Makefile b/regressions/ck_bytelock/benchmark/Makefile new file mode 100644 index 0000000..c819099 --- /dev/null +++ b/regressions/ck_bytelock/benchmark/Makefile @@ -0,0 +1,14 @@ +.PHONY: clean distribution + +OBJECTS=latency + +all: $(OBJECTS) + +latency: latency.c + $(CC) $(CFLAGS) -o latency latency.c + +clean: + rm -rf *.dSYM *.exe *~ *.o $(OBJECTS) + +include ../../../build/regressions.build +CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE diff --git a/regressions/ck_bytelock/benchmark/latency.c b/regressions/ck_bytelock/benchmark/latency.c new file mode 100644 index 0000000..be30165 --- /dev/null +++ b/regressions/ck_bytelock/benchmark/latency.c @@ -0,0 +1,99 @@ +/* + * Copyright 2011-2015 Samy Al Bahra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include "../../common.h" + +#ifndef STEPS +#define STEPS 1000000 +#endif + +int +main(void) +{ + uint64_t s_b, e_b, i; + ck_bytelock_t bytelock = CK_BYTELOCK_INITIALIZER; + ck_rwlock_t naive; + + for (i = 0; i < STEPS; i++) { + ck_bytelock_write_lock(&bytelock, 1); + ck_bytelock_write_unlock(&bytelock); + } + + s_b = rdtsc(); + for (i = 0; i < STEPS; i++) { + ck_bytelock_write_lock(&bytelock, 1); + ck_bytelock_write_unlock(&bytelock); + } + e_b = rdtsc(); + printf("WRITE: bytelock %15" PRIu64 "\n", (e_b - s_b) / STEPS); + + ck_rwlock_init(&naive); + for (i = 0; i < STEPS; i++) { + ck_rwlock_write_lock(&naive); + ck_rwlock_write_unlock(&naive); + } + + s_b = rdtsc(); + for (i = 0; i < STEPS; i++) { + ck_rwlock_write_lock(&naive); + ck_rwlock_write_unlock(&naive); + } + e_b = rdtsc(); + printf("WRITE: naive %15" PRIu64 "\n", (e_b - s_b) / STEPS); + + for (i = 0; i < STEPS; i++) { + ck_bytelock_read_lock(&bytelock, 1); + ck_bytelock_read_unlock(&bytelock, 1); + } + s_b = rdtsc(); + for (i = 0; i < STEPS; i++) { + ck_bytelock_read_lock(&bytelock, 1); + ck_bytelock_read_unlock(&bytelock, 1); + } + e_b = rdtsc(); + printf("READ: bytelock %15" PRIu64 "\n", (e_b - s_b) / STEPS); + + for (i = 0; i < STEPS; i++) { + ck_rwlock_read_lock(&naive); + ck_rwlock_read_unlock(&naive); + } + + s_b = rdtsc(); + for (i = 0; i < STEPS; i++) { + ck_rwlock_read_lock(&naive); + ck_rwlock_read_unlock(&naive); + } + e_b = rdtsc(); + printf("READ: naive %15" PRIu64 "\n", (e_b - s_b) / STEPS); + + return (0); +} + diff --git a/regressions/ck_bytelock/validate/Makefile b/regressions/ck_bytelock/validate/Makefile new file mode 100644 index 0000000..2a890e0 --- /dev/null +++ b/regressions/ck_bytelock/validate/Makefile @@ -0,0 +1,17 @@ +.PHONY: check clean distribution + +OBJECTS=validate + +all: $(OBJECTS) + +validate: validate.c ../../../include/ck_bytelock.h + $(CC) $(CFLAGS) -o validate validate.c + +check: all + ./validate $(CORES) 1 + +clean: + rm -rf *.dSYM *.exe *~ *.o $(OBJECTS) + +include ../../../build/regressions.build +CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE diff --git a/regressions/ck_bytelock/validate/validate.c b/regressions/ck_bytelock/validate/validate.c new file mode 100644 index 0000000..c164ce4 --- /dev/null +++ b/regressions/ck_bytelock/validate/validate.c @@ -0,0 +1,166 @@ +/* + * Copyright 2011-2015 Samy Al Bahra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "../../common.h" + +#ifndef ITERATE +#define ITERATE 5000000 +#endif + +struct block { + unsigned int tid; +}; + +static struct affinity a; +static unsigned int locked = 0; +static int nthr; +static ck_bytelock_t lock CK_CC_CACHELINE = CK_BYTELOCK_INITIALIZER; + +static void * +thread(void *null) +{ + struct block *context = null; + int i = ITERATE; + unsigned int l; + + if (aff_iterate(&a)) { + perror("ERROR: Could not affine thread"); + exit(EXIT_FAILURE); + } + + if (context->tid == (unsigned int)nthr - 1) + context->tid = sizeof(lock.readers) + 1; + + while (i--) { + ck_bytelock_write_lock(&lock, context->tid); + { + l = ck_pr_load_uint(&locked); + if (l != 0) { + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); + } + + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + ck_pr_inc_uint(&locked); + + l = ck_pr_load_uint(&locked); + if (l != 8) { + ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l); + } + + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + ck_pr_dec_uint(&locked); + + l = ck_pr_load_uint(&locked); + if (l != 0) { + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); + } + } + ck_bytelock_write_unlock(&lock); + + ck_bytelock_read_lock(&lock, context->tid); + { + l = ck_pr_load_uint(&locked); + if (l != 0) { + ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l); + } + } + ck_bytelock_read_unlock(&lock, context->tid); + } + + return (NULL); +} + +int +main(int argc, char *argv[]) +{ + pthread_t *threads; + struct block *context; + int i; + + if (argc != 3) { + ck_error("Usage: correct \n"); + } + + nthr = atoi(argv[1]); + if (nthr <= 0) { + ck_error("ERROR: Number of threads must be greater than 0\n"); + } + + threads = malloc(sizeof(pthread_t) * nthr); + if (threads == NULL) { + ck_error("ERROR: Could not allocate thread structures\n"); + } + + context = malloc(sizeof(struct block) * nthr); + if (context == NULL) { + ck_error("ERROR: Could not allocate thread contexts\n"); + } + + a.delta = atoi(argv[2]); + + fprintf(stderr, "Creating threads (mutual exclusion)..."); + for (i = 0; i < nthr; i++) { + context[i].tid = i + 1; + if (pthread_create(&threads[i], NULL, thread, context + i)) { + ck_error("ERROR: Could not create thread %d\n", i); + } + } + fprintf(stderr, "done\n"); + + fprintf(stderr, "Waiting for threads to finish correctness regression..."); + for (i = 0; i < nthr; i++) + pthread_join(threads[i], NULL); + fprintf(stderr, "done (passed)\n"); + + return (0); +} + -- cgit v1.2.3