diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-23 11:24:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-23 11:24:09 +0000 |
commit | e36b37583bebd229102f46c4ed7d2f6fad8697d4 (patch) | |
tree | 73937b6f051fcaaa1ccbdfbaa9f3a1f36bbedb9e /regressions/ck_spinlock/validate | |
parent | Initial commit. (diff) | |
download | ck-e36b37583bebd229102f46c4ed7d2f6fad8697d4.tar.xz ck-e36b37583bebd229102f46c4ed7d2f6fad8697d4.zip |
Adding upstream version 0.6.0.upstream/0.6.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'regressions/ck_spinlock/validate')
-rw-r--r-- | regressions/ck_spinlock/validate/Makefile | 57 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_anderson.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_cas.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_clh.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_dec.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_fas.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_hclh.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_mcs.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_spinlock.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_ticket.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/ck_ticket_pb.c | 2 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/linux_spinlock.c | 14 | ||||
-rw-r--r-- | regressions/ck_spinlock/validate/validate.h | 180 |
13 files changed, 271 insertions, 0 deletions
diff --git a/regressions/ck_spinlock/validate/Makefile b/regressions/ck_spinlock/validate/Makefile new file mode 100644 index 0000000..b1d7cba --- /dev/null +++ b/regressions/ck_spinlock/validate/Makefile @@ -0,0 +1,57 @@ +.PHONY: check clean + +all: ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock \ + ck_ticket_pb ck_anderson ck_spinlock ck_hclh + +check: all + ./ck_ticket $(CORES) 1 + ./ck_mcs $(CORES) 1 + ./ck_dec $(CORES) 1 + ./ck_cas $(CORES) 1 + ./ck_fas $(CORES) 1 + ./ck_clh $(CORES) 1 + ./ck_hclh $(CORES) 1 + ./linux_spinlock $(CORES) 1 + ./ck_ticket_pb $(CORES) 1 + ./ck_anderson $(CORES) 1 + ./ck_spinlock $(CORES) 1 + +linux_spinlock: linux_spinlock.c + $(CC) $(CFLAGS) -o linux_spinlock linux_spinlock.c + +ck_spinlock: ck_spinlock.c + $(CC) $(CFLAGS) -o ck_spinlock ck_spinlock.c + +ck_ticket_pb: ck_ticket_pb.c + $(CC) $(CFLAGS) -o ck_ticket_pb ck_ticket_pb.c + +ck_clh: ck_clh.c + $(CC) $(CFLAGS) -o ck_clh ck_clh.c + +ck_hclh: ck_hclh.c + $(CC) $(CFLAGS) -o ck_hclh ck_hclh.c + +ck_anderson: ck_anderson.c + $(CC) $(CFLAGS) -o ck_anderson ck_anderson.c + +ck_fas: ck_fas.c + $(CC) $(CFLAGS) -o ck_fas ck_fas.c + +ck_ticket: ck_ticket.c + $(CC) $(CFLAGS) -o ck_ticket ck_ticket.c + +ck_cas: ck_cas.c + $(CC) $(CFLAGS) -o ck_cas ck_cas.c + +ck_mcs: ck_mcs.c + $(CC) $(CFLAGS) -o ck_mcs ck_mcs.c + +ck_dec: ck_dec.c + $(CC) $(CFLAGS) -o ck_dec ck_dec.c + +clean: + rm -rf ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock ck_ticket_pb \ + ck_anderson ck_spinlock ck_hclh *.dSYM *.exe + +include ../../../build/regressions.build +CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE -lm diff --git a/regressions/ck_spinlock/validate/ck_anderson.c b/regressions/ck_spinlock/validate/ck_anderson.c new file mode 100644 index 0000000..b10900c --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_anderson.c @@ -0,0 +1,2 @@ +#include "../ck_anderson.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_cas.c b/regressions/ck_spinlock/validate/ck_cas.c new file mode 100644 index 0000000..162490a --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_cas.c @@ -0,0 +1,2 @@ +#include "../ck_cas.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_clh.c b/regressions/ck_spinlock/validate/ck_clh.c new file mode 100644 index 0000000..19cb512 --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_clh.c @@ -0,0 +1,2 @@ +#include "../ck_clh.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_dec.c b/regressions/ck_spinlock/validate/ck_dec.c new file mode 100644 index 0000000..fd351de --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_dec.c @@ -0,0 +1,2 @@ +#include "../ck_dec.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_fas.c b/regressions/ck_spinlock/validate/ck_fas.c new file mode 100644 index 0000000..5cf4071 --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_fas.c @@ -0,0 +1,2 @@ +#include "../ck_fas.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_hclh.c b/regressions/ck_spinlock/validate/ck_hclh.c new file mode 100644 index 0000000..001f57b --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_hclh.c @@ -0,0 +1,2 @@ +#include "../ck_hclh.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_mcs.c b/regressions/ck_spinlock/validate/ck_mcs.c new file mode 100644 index 0000000..7adad43 --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_mcs.c @@ -0,0 +1,2 @@ +#include "../ck_mcs.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_spinlock.c b/regressions/ck_spinlock/validate/ck_spinlock.c new file mode 100644 index 0000000..e682905 --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_spinlock.c @@ -0,0 +1,2 @@ +#include "../ck_spinlock.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_ticket.c b/regressions/ck_spinlock/validate/ck_ticket.c new file mode 100644 index 0000000..be67254 --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_ticket.c @@ -0,0 +1,2 @@ +#include "../ck_ticket.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/ck_ticket_pb.c b/regressions/ck_spinlock/validate/ck_ticket_pb.c new file mode 100644 index 0000000..e62ee0e --- /dev/null +++ b/regressions/ck_spinlock/validate/ck_ticket_pb.c @@ -0,0 +1,2 @@ +#include "../ck_ticket_pb.h" +#include "validate.h" diff --git a/regressions/ck_spinlock/validate/linux_spinlock.c b/regressions/ck_spinlock/validate/linux_spinlock.c new file mode 100644 index 0000000..781e419 --- /dev/null +++ b/regressions/ck_spinlock/validate/linux_spinlock.c @@ -0,0 +1,14 @@ +#ifdef __x86_64__ +#include "../linux_spinlock.h" +#include "validate.h" +#else +#include <stdio.h> + +int +main(void) +{ + + fprintf(stderr, "Unsupported.\n"); + return 0; +} +#endif diff --git a/regressions/ck_spinlock/validate/validate.h b/regressions/ck_spinlock/validate/validate.h new file mode 100644 index 0000000..df40584 --- /dev/null +++ b/regressions/ck_spinlock/validate/validate.h @@ -0,0 +1,180 @@ +/* + * 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 <errno.h> +#include <inttypes.h> +#include <pthread.h> +#include <math.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> +#include <unistd.h> +#include <sys/time.h> + +#include <ck_cc.h> +#include <ck_pr.h> +#include <ck_spinlock.h> + +#include "../../common.h" + +#ifndef ITERATE +#define ITERATE 1000000 +#endif + +struct block { + unsigned int tid; +}; + +static struct affinity a; +static unsigned int locked = 0; +static uint64_t nthr; + +LOCK_DEFINE; + +static void * +thread(void *null CK_CC_UNUSED) +{ +#ifdef LOCK_STATE + LOCK_STATE; +#endif + unsigned int i = ITERATE; + unsigned int j; + unsigned int core; + + if (aff_iterate_core(&a, &core)) { + perror("ERROR: Could not affine thread"); + exit(EXIT_FAILURE); + } + + while (i--) { +#ifdef TRYLOCK + if (i & 1) { + LOCK; + } else { + while (TRYLOCK == false) + ck_pr_stall(); + } +#else + LOCK; +#endif + +#ifdef LOCKED + if (LOCKED == false) + ck_error("is_locked operation failed."); +#endif + + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + ck_pr_store_uint(&locked, locked + 1); + + j = ck_pr_load_uint(&locked); + + if (j != 10) { + ck_error("ERROR (WR): Race condition (%u)\n", j); + exit(EXIT_FAILURE); + } + + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + ck_pr_store_uint(&locked, locked - 1); + + UNLOCK; + LOCK; + + j = ck_pr_load_uint(&locked); + if (j != 0) { + ck_error("ERROR (RD): Race condition (%u)\n", j); + exit(EXIT_FAILURE); + } + + UNLOCK; + } + + return (NULL); +} + +int +main(int argc, char *argv[]) +{ + uint64_t i; + pthread_t *threads; + + if (argc != 3) { + ck_error("Usage: " LOCK_NAME " <number of threads> <affinity delta>\n"); + exit(EXIT_FAILURE); + } + + nthr = atoi(argv[1]); + if (nthr <= 0) { + ck_error("ERROR: Number of threads must be greater than 0\n"); + exit(EXIT_FAILURE); + } + +#ifdef LOCK_INIT + LOCK_INIT; +#endif + + threads = malloc(sizeof(pthread_t) * nthr); + if (threads == NULL) { + ck_error("ERROR: Could not allocate thread structures\n"); + exit(EXIT_FAILURE); + } + + a.delta = atoi(argv[2]); + a.request = 0; + + fprintf(stderr, "Creating threads (mutual exclusion)..."); + for (i = 0; i < nthr; i++) { + if (pthread_create(&threads[i], NULL, thread, NULL)) { + ck_error("ERROR: Could not create thread %" PRIu64 "\n", i); + exit(EXIT_FAILURE); + } + } + 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); +} + |