You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2014/08/01 22:44:20 UTC

[07/20] TS-2950: Initial commit of libck.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_hs/benchmark/parallel_bytestring.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_hs/benchmark/parallel_bytestring.c b/lib/ck/regressions/ck_hs/benchmark/parallel_bytestring.c
new file mode 100644
index 0000000..ea2eaec
--- /dev/null
+++ b/lib/ck/regressions/ck_hs/benchmark/parallel_bytestring.c
@@ -0,0 +1,602 @@
+/*
+ * Copyright 2012 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 copyrighs
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyrighs
+ *    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 "../../common.h"
+#include <ck_hs.h>
+#include "../../../src/ck_ht_hash.h"
+#include <assert.h>
+#include <ck_epoch.h>
+#include <ck_malloc.h>
+#include <ck_pr.h>
+#include <ck_spinlock.h>
+
+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+static ck_hs_t hs CK_CC_CACHELINE;
+static char **keys;
+static size_t keys_length = 0;
+static size_t keys_capacity = 128;
+static ck_epoch_t epoch_hs;
+static ck_epoch_record_t epoch_wr;
+static int n_threads;
+static bool next_stage;
+
+enum state {
+	HS_STATE_STOP = 0,
+	HS_STATE_GET,
+	HS_STATE_STRICT_REPLACEMENT,
+	HS_STATE_DELETION,
+	HS_STATE_REPLACEMENT,
+	HS_STATE_COUNT
+};
+
+static ck_spinlock_t mtx = CK_SPINLOCK_INITIALIZER;
+static struct affinity affinerator = AFFINITY_INITIALIZER;
+static uint64_t accumulator[HS_STATE_COUNT];
+static int barrier[HS_STATE_COUNT];
+static int state;
+
+struct hs_epoch {
+	ck_epoch_entry_t epoch_entry;
+};
+
+COMMON_ALARM_DECLARE_GLOBAL(hs_alarm, alarm_event, next_stage)
+
+static void
+alarm_handler(int s)
+{
+
+	(void)s;
+	next_stage = true;
+	return;
+}
+
+static unsigned long
+hs_hash(const void *object, unsigned long seed)
+{
+	const char *c = object;
+	unsigned long h;
+
+	h = (unsigned long)MurmurHash64A(c, strlen(c), seed);
+	return h;
+}
+
+static bool
+hs_compare(const void *previous, const void *compare)
+{
+
+	return strcmp(previous, compare) == 0;
+}
+
+static void
+hs_destroy(ck_epoch_entry_t *e)
+{
+
+	free(e);
+	return;
+}
+
+static void *
+hs_malloc(size_t r)
+{
+	ck_epoch_entry_t *b;
+
+	b = malloc(sizeof(*b) + r);
+	return b + 1;
+}
+
+static void
+hs_free(void *p, size_t b, bool r)
+{
+	struct hs_epoch *e = p;
+
+	(void)b;
+
+	if (r == true) {
+		/* Destruction requires safe memory reclamation. */
+		ck_epoch_call(&epoch_hs, &epoch_wr, &(--e)->epoch_entry, hs_destroy);
+	} else {
+		free(--e);
+	}
+
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = hs_malloc,
+	.free = hs_free
+};
+
+static void
+set_init(void)
+{
+	unsigned int mode = CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC;
+
+#ifdef HS_DELETE
+	mode |= CK_HS_MODE_DELETE;
+#endif 
+
+	ck_epoch_init(&epoch_hs);
+	ck_epoch_register(&epoch_hs, &epoch_wr);
+	common_srand48((long int)time(NULL));
+	if (ck_hs_init(&hs, mode, hs_hash, hs_compare, &my_allocator, 65536, common_lrand48()) == false) {
+		perror("ck_hs_init");
+		exit(EXIT_FAILURE);
+	}
+
+	return;
+}
+
+static bool
+set_remove(const char *value)
+{
+	unsigned long h;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return (bool)ck_hs_remove(&hs, h, value);
+}
+
+static bool
+set_replace(const char *value)
+{
+	unsigned long h;
+	void *previous;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_set(&hs, h, value, &previous);
+}
+
+static bool
+set_swap(const char *value)
+{
+	unsigned long h;
+	void *previous;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_fas(&hs, h, value, &previous);
+}
+
+static void *
+set_get(const char *value)
+{
+	unsigned long h;
+	void *v;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	v = ck_hs_get(&hs, h, value);
+	return v;
+}
+
+static bool
+set_insert(const char *value)
+{
+	unsigned long h;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_put(&hs, h, value);
+}
+
+static size_t
+set_count(void)
+{
+
+	return ck_hs_count(&hs);
+}
+
+static bool
+set_reset(void)
+{
+
+	return ck_hs_reset(&hs);
+}
+
+static void *
+reader(void *unused)
+{
+	size_t i;
+	ck_epoch_record_t epoch_record;
+	int state_previous = HS_STATE_STOP;
+	int n_state = 0;
+	uint64_t s, j, a;
+
+	(void)unused;
+	if (aff_iterate(&affinerator) != 0)
+		perror("WARNING: Failed to affine thread");
+
+	s = j = a = 0;
+	ck_epoch_register(&epoch_hs, &epoch_record);
+	for (;;) {
+		j++;
+		ck_epoch_begin(&epoch_hs, &epoch_record);
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			char *r;
+
+			r = set_get(keys[i]);
+			if (r == NULL) {
+				if (n_state == HS_STATE_STRICT_REPLACEMENT) {
+					ck_error("ERROR: Did not find during replacement: %s\n", keys[i]);
+				}
+
+				continue;
+			}
+
+			if (strcmp(r, keys[i]) == 0)
+				continue;
+
+			ck_error("ERROR: Found invalid value: [%s] but expected [%s]\n", (char *)r, keys[i]);
+		}
+		a += rdtsc() - s;
+		ck_epoch_end(&epoch_hs, &epoch_record);
+
+		n_state = ck_pr_load_int(&state);
+		if (n_state != state_previous) {
+			ck_spinlock_lock(&mtx);
+			accumulator[state_previous] += a / (j * keys_length);
+			ck_spinlock_unlock(&mtx);
+
+			ck_pr_inc_int(&barrier[state_previous]);
+			while (ck_pr_load_int(&barrier[state_previous]) != n_threads + 1)
+				ck_pr_stall();
+
+			state_previous = n_state;
+			s = j = a = 0;
+		}
+	}
+
+	return NULL;
+}
+
+static uint64_t
+acc(size_t i)
+{
+	uint64_t r;
+
+	ck_spinlock_lock(&mtx);
+	r = accumulator[i];
+	ck_spinlock_unlock(&mtx);
+
+	return r;
+}
+
+int
+main(int argc, char *argv[])
+{
+	FILE *fp;
+	char buffer[512];
+	size_t i, j, r;
+	unsigned int d = 0;
+	uint64_t s, e, a, repeated;
+	char **t;
+	pthread_t *readers;
+	double p_r, p_d;
+
+	COMMON_ALARM_DECLARE_LOCAL(hs_alarm, alarm_event)
+
+	r = 20;
+	s = 8;
+	p_d = 0.5;
+	p_r = 0.5;
+	n_threads = CORES - 1;
+
+	if (argc < 2) {
+		ck_error("Usage: parallel <dictionary> [<interval length> <initial size> <readers>\n"
+		    " <probability of replacement> <probability of deletion> <epoch threshold>]\n");
+	}
+
+	if (argc >= 3)
+		r = atoi(argv[2]);
+
+	if (argc >= 4)
+		s = (uint64_t)atoi(argv[3]);
+
+	if (argc >= 5) {
+		n_threads = atoi(argv[4]);
+		if (n_threads < 1) {
+			ck_error("ERROR: Number of readers must be >= 1.\n");
+		}
+	}
+
+	if (argc >= 6) {
+		p_r = atof(argv[5]) / 100.00;
+		if (p_r < 0) {
+			ck_error("ERROR: Probability of replacement must be >= 0 and <= 100.\n");
+		}
+	}
+
+	if (argc >= 7) {
+		p_d = atof(argv[6]) / 100.00;
+		if (p_d < 0) {
+			ck_error("ERROR: Probability of deletion must be >= 0 and <= 100.\n");
+		}
+	}
+
+	COMMON_ALARM_INIT(hs_alarm, alarm_event, r)
+
+	affinerator.delta = 1;
+	readers = malloc(sizeof(pthread_t) * n_threads);
+	assert(readers != NULL);
+
+	keys = malloc(sizeof(char *) * keys_capacity);
+	assert(keys != NULL);
+
+	fp = fopen(argv[1], "r");
+	assert(fp != NULL);
+
+	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+		buffer[strlen(buffer) - 1] = '\0';
+		keys[keys_length++] = strdup(buffer);
+		assert(keys[keys_length - 1] != NULL);
+
+		if (keys_length == keys_capacity) {
+			t = realloc(keys, sizeof(char *) * (keys_capacity *= 2));
+			assert(t != NULL);
+			keys = t;
+		}
+	}
+
+	t = realloc(keys, sizeof(char *) * keys_length);
+	assert(t != NULL);
+	keys = t;
+
+	set_init();
+
+	for (i = 0; i < (size_t)n_threads; i++) {
+		if (pthread_create(&readers[i], NULL, reader, NULL) != 0) {
+			ck_error("ERROR: Failed to create thread %zu.\n", i);
+		}
+	}
+
+	for (i = 0; i < keys_length; i++)
+		d += set_insert(keys[i]) == false;
+
+	fprintf(stderr, " [S] %d readers, 1 writer.\n", n_threads);
+	fprintf(stderr, " [S] %zu entries stored and %u duplicates.\n\n",
+	    set_count(), d);
+
+	fprintf(stderr, " ,- BASIC TEST\n");
+	fprintf(stderr, " | Executing SMR test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (set_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += set_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing replacement test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing get test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (set_get(keys[i]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	a = 0;
+	fprintf(stderr, " | Executing removal test...");
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_remove(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			set_insert(keys[i]);
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing negative look-up test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			set_get("\x50\x03\x04\x05\x06\x10");
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	ck_epoch_record_t epoch_temporary = epoch_wr;
+	ck_epoch_synchronize(&epoch_hs, &epoch_wr);
+
+	fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> "
+	    "%u pending, %u peak, %lu reclamations\n\n",
+	    epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch,
+	    epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch);
+
+	fprintf(stderr, " ,- READER CONCURRENCY\n");
+	fprintf(stderr, " | Executing reader test...");
+
+	ck_pr_store_int(&state, HS_STATE_GET);
+	while (ck_pr_load_int(&barrier[HS_STATE_STOP]) != n_threads)
+		ck_pr_stall();
+	ck_pr_inc_int(&barrier[HS_STATE_STOP]);
+	common_sleep(r);
+	ck_pr_store_int(&state, HS_STATE_STRICT_REPLACEMENT);
+	while (ck_pr_load_int(&barrier[HS_STATE_GET]) != n_threads)
+		ck_pr_stall();
+
+	fprintf(stderr, "done (reader = %" PRIu64 " ticks)\n",
+	    acc(HS_STATE_GET) / n_threads);
+
+	fprintf(stderr, " | Executing strict replacement test...");
+
+	a = repeated = 0;
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	ck_pr_inc_int(&barrier[HS_STATE_GET]);
+	for (;;) {
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (i & 1) {
+				set_replace(keys[i]);
+			} else {
+				set_swap(keys[i]);
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+
+	ck_pr_store_int(&state, HS_STATE_DELETION);
+	while (ck_pr_load_int(&barrier[HS_STATE_STRICT_REPLACEMENT]) != n_threads)
+		ck_pr_stall();
+	set_reset();
+	ck_epoch_synchronize(&epoch_hs, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), acc(HS_STATE_STRICT_REPLACEMENT) / n_threads);
+
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100);
+	a = repeated = 0;
+	ck_pr_inc_int(&barrier[HS_STATE_STRICT_REPLACEMENT]);
+	for (;;) {
+		double delete;
+
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			set_insert(keys[i]);
+			if (p_d != 0.0) {
+				delete = common_drand48();
+				if (delete <= p_d)
+					set_remove(keys[i]);
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+	ck_pr_store_int(&state, HS_STATE_REPLACEMENT);
+	while (ck_pr_load_int(&barrier[HS_STATE_DELETION]) != n_threads)
+		ck_pr_stall();
+
+	set_reset();
+	ck_epoch_synchronize(&epoch_hs, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), acc(HS_STATE_DELETION) / n_threads);
+
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100);
+	a = repeated = 0;
+	ck_pr_inc_int(&barrier[HS_STATE_DELETION]);
+	for (;;) {
+		double delete, replace;
+
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			set_insert(keys[i]);
+			if (p_d != 0.0) {
+				delete = common_drand48();
+				if (delete <= p_d)
+					set_remove(keys[i]);
+			} else {
+				delete = 0.0;
+			}
+
+			if (p_r != 0.0) {
+				replace = common_drand48();
+				if (replace <= p_r) {
+					if ((i & 1) || (delete <= p_d)) {
+						set_replace(keys[i]);
+					} else {
+						set_swap(keys[i]);
+					}
+				}
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+	ck_pr_store_int(&state, HS_STATE_STOP);
+	while (ck_pr_load_int(&barrier[HS_STATE_REPLACEMENT]) != n_threads)
+		ck_pr_stall();
+	set_reset();
+	ck_epoch_synchronize(&epoch_hs, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), acc(HS_STATE_REPLACEMENT) / n_threads);
+
+	ck_pr_inc_int(&barrier[HS_STATE_REPLACEMENT]);
+	epoch_temporary = epoch_wr;
+	ck_epoch_synchronize(&epoch_hs, &epoch_wr);
+
+	fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> "
+	    "%u pending, %u peak, %lu reclamations\n\n",
+	    epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch,
+	    epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch);
+	return 0;
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_hs/benchmark/serial.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_hs/benchmark/serial.c b/lib/ck/regressions/ck_hs/benchmark/serial.c
new file mode 100644
index 0000000..995ef1c
--- /dev/null
+++ b/lib/ck/regressions/ck_hs/benchmark/serial.c
@@ -0,0 +1,517 @@
+/*
+ * Copyright 2012 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 copyrighs
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyrighs
+ *    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 <ck_hs.h>
+
+#include <assert.h>
+#include <ck_malloc.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "../../common.h"
+#include "../../../src/ck_ht_hash.h"
+
+static ck_hs_t hs;
+static char **keys;
+static size_t keys_length = 0;
+static size_t keys_capacity = 128;
+static unsigned long global_seed;
+
+static void *
+hs_malloc(size_t r)
+{
+
+	return malloc(r);
+}
+
+static void
+hs_free(void *p, size_t b, bool r)
+{
+
+	(void)b;
+	(void)r;
+
+	free(p);
+
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = hs_malloc,
+	.free = hs_free
+};
+
+static unsigned long
+hs_hash(const void *object, unsigned long seed)
+{
+	const char *c = object;
+	unsigned long h;
+
+	h = (unsigned long)MurmurHash64A(c, strlen(c), seed);
+	return h;
+}
+
+static bool
+hs_compare(const void *previous, const void *compare)
+{
+
+	return strcmp(previous, compare) == 0;
+}
+
+static void
+set_destroy(void)
+{
+
+	ck_hs_destroy(&hs);
+	return;
+}
+
+static void
+set_init(unsigned int size, unsigned int mode)
+{
+
+	if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC | mode, hs_hash, hs_compare,
+	    &my_allocator, size, global_seed) == false) {
+		perror("ck_hs_init");
+		exit(EXIT_FAILURE);
+	}
+
+	return;
+}
+
+static bool
+set_remove(const char *value)
+{
+	unsigned long h;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_remove(&hs, h, value) != NULL;
+}
+
+static bool
+set_swap(const char *value)
+{
+	unsigned long h;
+	void *previous;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_fas(&hs, h, value, &previous);
+}
+
+static bool
+set_replace(const char *value)
+{
+	unsigned long h;
+	void *previous;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	ck_hs_set(&hs, h, value, &previous);
+	return previous != NULL;
+}
+
+static void *
+set_get(const char *value)
+{
+	unsigned long h;
+	void *v;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	v = ck_hs_get(&hs, h, value);
+	return v;
+}
+
+static bool
+set_insert(const char *value)
+{
+	unsigned long h;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_put(&hs, h, value);
+}
+
+static bool
+set_insert_unique(const char *value)
+{
+	unsigned long h;
+
+	h = CK_HS_HASH(&hs, hs_hash, value);
+	return ck_hs_put_unique(&hs, h, value);
+}
+
+static size_t
+set_count(void)
+{
+
+	return ck_hs_count(&hs);
+}
+
+static bool
+set_reset(void)
+{
+
+	return ck_hs_reset(&hs);
+}
+
+static void
+set_gc(void)
+{
+
+	ck_hs_gc(&hs, 0, 0);
+	return;
+}
+
+static void
+set_rebuild(void)
+{
+
+	ck_hs_rebuild(&hs);
+	return;
+}
+
+static void
+keys_shuffle(char **k)
+{
+	size_t i, j;
+	char *t;
+
+	for (i = keys_length; i > 1; i--) {
+		j = rand() % (i - 1);
+
+		if (j != i - 1) {
+			t = k[i - 1];
+			k[i - 1] = k[j];
+			k[j] = t;
+		}
+	}
+
+	return;
+}
+
+static void
+run_test(const char *file, size_t r, unsigned int size, unsigned int mode)
+{
+	FILE *fp;
+	char buffer[512];
+	size_t i, j;
+	unsigned int d = 0;
+	uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng, ss, sts, su, sgc, sb;
+	struct ck_hs_stat st;
+	char **t;
+
+	keys = malloc(sizeof(char *) * keys_capacity);
+	assert(keys != NULL);
+
+	fp = fopen(file, "r");
+	assert(fp != NULL);
+
+	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+		buffer[strlen(buffer) - 1] = '\0';
+		keys[keys_length++] = strdup(buffer);
+		assert(keys[keys_length - 1] != NULL);
+
+		if (keys_length == keys_capacity) {
+			t = realloc(keys, sizeof(char *) * (keys_capacity *= 2));
+			assert(t != NULL);
+			keys = t;
+		}
+	}
+
+	t = realloc(keys, sizeof(char *) * keys_length);
+	assert(t != NULL);
+	keys = t;
+
+	set_init(size, mode);
+	for (i = 0; i < keys_length; i++)
+		d += set_insert(keys[i]) == false;
+	ck_hs_stat(&hs, &st);
+
+	fprintf(stderr, "# %zu entries stored, %u duplicates, %u probe.\n",
+	    set_count(), d, st.probe_maximum);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (set_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = keys_length; i > 0; i--)
+			d += set_insert(keys[i - 1]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	ri = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (set_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += set_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	si = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		keys_shuffle(keys);
+
+		if (set_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += set_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	ai = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_swap(keys[i]);
+		e = rdtsc();
+		a += e - s;
+	}
+	ss = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+	}
+	sr = a / (r * keys_length);
+
+	set_reset();
+	for (i = 0; i < keys_length; i++)
+		set_insert(keys[i]);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = keys_length; i > 0; i--) {
+			if (set_get(keys[i - 1]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	rg = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (set_get(keys[i]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	sg = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		keys_shuffle(keys);
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (set_get(keys[i]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	ag = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_remove(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			set_insert(keys[i]);
+	}
+	sd = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			set_get("\x50\x03\x04\x05\x06\x10");
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	ng = a / (r * keys_length);
+
+	set_reset();
+	for (i = 0; i < keys_length; i++)
+		set_insert(keys[i]);
+	for (i = 0; i < keys_length; i++)
+		set_remove(keys[i]);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_insert(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			set_remove(keys[i]);
+	}
+	sts = a / (r * keys_length);
+
+	set_reset();
+
+	/* Prune duplicates. */
+	for (i = 0; i < keys_length; i++) {
+		if (set_insert(keys[i]) == true)
+			continue;
+
+		free(keys[i]);
+		keys[i] = keys[--keys_length];
+	}
+
+	for (i = 0; i < keys_length; i++)
+		set_remove(keys[i]);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			set_insert_unique(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			set_remove(keys[i]);
+	}
+	su = a / (r * keys_length);
+
+	for (i = 0; i < keys_length; i++)
+		set_insert_unique(keys[i]);
+
+	for (i = 0; i < keys_length / 2; i++)
+		set_remove(keys[i]);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		set_gc();
+		e = rdtsc();
+		a += e - s;
+	}
+	sgc = a / r;
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		set_rebuild();
+		e = rdtsc();
+		a += e - s;
+	}
+	sb = a / r;
+
+	printf("%zu "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 "\n",
+	    keys_length, ri, si, ai, ss, sr, rg, sg, ag, sd, ng, sts, su, sgc, sb);
+
+	fclose(fp);
+
+	for (i = 0; i < keys_length; i++) {
+		free(keys[i]);
+	}
+
+	free(keys);
+	keys_length = 0;
+	set_destroy();
+	return;
+}
+
+int
+main(int argc, char *argv[])
+{
+	unsigned int r, size;
+
+	common_srand48((long int)time(NULL));
+	if (argc < 2) {
+		ck_error("Usage: ck_hs <dictionary> [<repetitions> <initial size>]\n");
+	}
+
+	r = 16;
+	if (argc >= 3)
+		r = atoi(argv[2]);
+
+	size = 8;
+	if (argc >= 4)
+		size = atoi(argv[3]);
+
+	global_seed = common_lrand48();
+	run_test(argv[1], r, size, 0);
+	run_test(argv[1], r, size, CK_HS_MODE_DELETE);
+	fprintf(stderr, "#    reverse_insertion serial_insertion random_insertion serial_swap "
+	    "serial_replace reverse_get serial_get random_get serial_remove negative_get tombstone "
+	    "set_unique gc rebuild\n\n");
+
+	return 0;
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_hs/validate/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_hs/validate/Makefile b/lib/ck/regressions/ck_hs/validate/Makefile
new file mode 100644
index 0000000..a96e652
--- /dev/null
+++ b/lib/ck/regressions/ck_hs/validate/Makefile
@@ -0,0 +1,17 @@
+.PHONY: check clean distribution
+
+OBJECTS=serial
+
+all: $(OBJECTS)
+
+serial: serial.c ../../../include/ck_hs.h ../../../src/ck_hs.c
+	$(CC) $(CFLAGS) -o serial serial.c ../../../src/ck_hs.c
+
+check: all
+	./serial
+
+clean:
+	rm -rf *~ *.o $(OBJECTS) *.dSYM *.exe
+
+include ../../../build/regressions.build
+CFLAGS+=-D_GNU_SOURCE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_hs/validate/serial.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_hs/validate/serial.c b/lib/ck/regressions/ck_hs/validate/serial.c
new file mode 100644
index 0000000..93a375b
--- /dev/null
+++ b/lib/ck/regressions/ck_hs/validate/serial.c
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2012 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 copyrighs
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyrighs
+ *    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 <ck_hs.h>
+
+#include <assert.h>
+#include <ck_malloc.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../common.h"
+
+static void *
+hs_malloc(size_t r)
+{
+
+	return malloc(r);
+}
+
+static void
+hs_free(void *p, size_t b, bool r)
+{
+
+	(void)b;
+	(void)r;
+	free(p);
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = hs_malloc,
+	.free = hs_free
+};
+
+const char *test[] = { "Samy", "Al", "Bahra", "dances", "in", "the", "wind.", "Once",
+			"upon", "a", "time", "his", "gypsy", "ate", "one", "itsy",
+			    "bitsy", "spider.", "What", "goes", "up", "must",
+				"come", "down.", "What", "is", "down", "stays",
+				    "down.", "A", "B", "C", "D", "E", "F", "G", "H",
+					"I", "J", "K", "L", "M", "N", "O", "P", "Q" };
+
+const char *negative = "negative";
+
+/* Purposefully crappy hash function. */
+static unsigned long
+hs_hash(const void *object, unsigned long seed)
+{
+	const char *c = object;
+	unsigned long h;
+
+	(void)seed;
+	h = c[0];
+	return h;
+}
+
+static bool
+hs_compare(const void *previous, const void *compare)
+{
+
+	return strcmp(previous, compare) == 0;
+}
+
+static void
+run_test(unsigned int is, unsigned int ad)
+{
+	ck_hs_t hs[16];
+	const size_t size = sizeof(hs) / sizeof(*hs);
+	size_t i, j;
+	const char *blob = "#blobs";
+	unsigned long h;
+
+	if (ck_hs_init(&hs[0], CK_HS_MODE_SPMC | CK_HS_MODE_OBJECT | ad, hs_hash, hs_compare, &my_allocator, is, 6602834) == false)
+		ck_error("ck_hs_init\n");
+
+	for (j = 0; j < size; j++) {
+		for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+			h = test[i][0];
+			if (ck_hs_get(&hs[j], h, test[i]) != NULL) {
+				continue;
+			}
+
+			if (ck_hs_put_unique(&hs[j], h, test[i]) == false)
+				ck_error("ERROR [%zu]: Failed to insert unique (%s)\n", j, test[i]);
+
+			if (ck_hs_remove(&hs[j], h, test[i]) == false)
+				ck_error("ERROR [%zu]: Failed to remove unique (%s)\n", j, test[i]);
+
+			break;
+		}
+
+		if (ck_hs_gc(&hs[j], 0, 0) == false)
+			ck_error("ERROR: Failed to GC empty set.\n");
+
+		for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+			h = test[i][0];
+			ck_hs_put(&hs[j], h, test[i]);
+			if (ck_hs_put(&hs[j], h, test[i]) == true) {
+				ck_error("ERROR [%u] [1]: put must fail on collision (%s).\n", is, test[i]);
+			}
+			if (ck_hs_get(&hs[j], h, test[i]) == NULL) {
+				ck_error("ERROR [%u]: get must not fail after put\n", is);
+			}
+		}
+
+		/* Test grow semantics. */
+		ck_hs_grow(&hs[j], 128);
+		for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+			h = test[i][0];
+			if (ck_hs_put(&hs[j], h, test[i]) == true) {
+				ck_error("ERROR [%u] [2]: put must fail on collision.\n", is);
+			}
+
+			if (ck_hs_get(&hs[j], h, test[i]) == NULL) {
+				ck_error("ERROR [%u]: get must not fail\n", is);
+			}
+		}
+
+		h = blob[0];
+		if (ck_hs_get(&hs[j], h, blob) == NULL) {
+			if (j > 0)
+				ck_error("ERROR [%u]: Blob must always exist after first.\n", is);
+
+			if (ck_hs_put(&hs[j], h, blob) == false) {
+				ck_error("ERROR [%u]: A unique blob put failed.\n", is);
+			}
+		} else {
+			if (ck_hs_put(&hs[j], h, blob) == true) {
+				ck_error("ERROR [%u]: Duplicate blob put succeeded.\n", is);
+			}
+		}
+
+		/* Grow set and check get semantics. */
+		ck_hs_grow(&hs[j], 512);
+		for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+			h = test[i][0];
+			if (ck_hs_get(&hs[j], h, test[i]) == NULL) {
+				ck_error("ERROR [%u]: get must not fail\n", is);
+			}
+		}
+
+		/* Delete and check negative membership. */
+		for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+			void *r;
+
+			h = test[i][0];
+			if (ck_hs_get(&hs[j], h, test[i]) == NULL)
+				continue;
+
+			if (r = ck_hs_remove(&hs[j], h, test[i]), r == NULL) {
+				ck_error("ERROR [%u]: remove must not fail\n", is);
+			}
+
+			if (strcmp(r, test[i]) != 0) {
+				ck_error("ERROR [%u]: Removed incorrect node (%s != %s)\n", (char *)r, test[i], is);
+			}
+		}
+
+		/* Test replacement semantics. */
+		for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+			void *r;
+			bool d;
+
+			h = test[i][0];
+			d = ck_hs_get(&hs[j], h, test[i]) != NULL;
+			if (ck_hs_set(&hs[j], h, test[i], &r) == false) {
+				ck_error("ERROR [%u]: Failed to set\n", is);
+			}
+
+			/* Expected replacement. */
+			if (d == true && (r == NULL || strcmp(r, test[i]) != 0)) {
+				ck_error("ERROR [%u]: Incorrect previous value: %s != %s\n",
+				    is, test[i], (char *)r);
+			}
+
+			/* Replacement should succeed. */
+			if (ck_hs_fas(&hs[j], h, test[i], &r) == false)
+				ck_error("ERROR [%u]: ck_hs_fas must succeed.\n", is);
+
+			if (strcmp(r, test[i]) != 0) {
+				ck_error("ERROR [%u]: Incorrect replaced value: %s != %s\n",
+				    is, test[i], (char *)r);
+			}
+
+			if (ck_hs_fas(&hs[j], h, negative, &r) == true)
+				ck_error("ERROR [%u]: Replacement of negative should fail.\n", is);
+
+			if (ck_hs_set(&hs[j], h, test[i], &r) == false) {
+				ck_error("ERROR [%u]: Failed to set [1]\n", is);
+			}
+
+			if (strcmp(r, test[i]) != 0) {
+				ck_error("ERROR [%u]: Invalid &hs[j]: %s != %s\n", (char *)r, test[i], is);
+			}
+		}
+
+		if (j == size - 1)
+			break;
+
+		if (ck_hs_move(&hs[j + 1], &hs[j], hs_hash, hs_compare, &my_allocator) == false)
+			ck_error("Failed to move hash table");
+
+		if (j & 1) {
+			ck_hs_gc(&hs[j + 1], 0, 0);
+		} else {
+			ck_hs_gc(&hs[j + 1], 26, 26);
+		}
+
+		if (ck_hs_rebuild(&hs[j + 1]) == false)
+			ck_error("Failed to rebuild");
+	}
+
+	return;
+}
+
+int
+main(void)
+{
+	unsigned int k;
+
+	for (k = 16; k <= 64; k <<= 1) {
+		run_test(k, 0);
+		run_test(k, CK_HS_MODE_DELETE);
+		break;
+	}
+
+	return 0;
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_ht/benchmark/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_ht/benchmark/Makefile b/lib/ck/regressions/ck_ht/benchmark/Makefile
new file mode 100644
index 0000000..fa31274
--- /dev/null
+++ b/lib/ck/regressions/ck_ht/benchmark/Makefile
@@ -0,0 +1,27 @@
+.PHONY: clean distribution
+
+OBJECTS=serial serial.delete parallel_bytestring parallel_bytestring.delete parallel_direct
+
+all: $(OBJECTS)
+
+serial: serial.c ../../../include/ck_ht.h ../../../src/ck_ht.c
+	$(CC) $(CFLAGS) -o serial serial.c ../../../src/ck_ht.c
+
+serial.delete: serial.c ../../../include/ck_ht.h ../../../src/ck_ht.c
+	$(CC) $(CFLAGS) -DHT_DELETE -o serial.delete serial.c ../../../src/ck_ht.c
+
+parallel_bytestring.delete: parallel_bytestring.c ../../../include/ck_ht.h ../../../src/ck_ht.c ../../../src/ck_epoch.c
+	$(CC) $(PTHREAD_CFLAGS) $(CFLAGS) -DHT_DELETE -o parallel_bytestring.delete parallel_bytestring.c ../../../src/ck_ht.c ../../../src/ck_epoch.c
+
+parallel_bytestring: parallel_bytestring.c ../../../include/ck_ht.h ../../../src/ck_ht.c ../../../src/ck_epoch.c
+	$(CC) $(PTHREAD_CFLAGS) $(CFLAGS) -o parallel_bytestring parallel_bytestring.c ../../../src/ck_ht.c ../../../src/ck_epoch.c
+
+parallel_direct: parallel_direct.c ../../../include/ck_ht.h ../../../src/ck_ht.c ../../../src/ck_epoch.c
+	$(CC) $(PTHREAD_CFLAGS) $(CFLAGS) -o parallel_direct parallel_direct.c ../../../src/ck_ht.c ../../../src/ck_epoch.c
+
+clean:
+	rm -rf *~ *.o $(OBJECTS) *.dSYM *.exe
+
+include ../../../build/regressions.build
+CFLAGS+=-D_GNU_SOURCE
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_ht/benchmark/parallel_bytestring.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_ht/benchmark/parallel_bytestring.c b/lib/ck/regressions/ck_ht/benchmark/parallel_bytestring.c
new file mode 100644
index 0000000..6458481
--- /dev/null
+++ b/lib/ck/regressions/ck_ht/benchmark/parallel_bytestring.c
@@ -0,0 +1,565 @@
+/*
+ * Copyright 2012-2014 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 <ck_ht.h>
+
+#ifdef CK_F_HT
+
+#include <assert.h>
+#include <ck_epoch.h>
+#include <ck_malloc.h>
+#include <ck_pr.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "../../common.h"
+
+static ck_ht_t ht CK_CC_CACHELINE;
+static char **keys;
+static size_t keys_length = 0;
+static size_t keys_capacity = 128;
+static ck_epoch_t epoch_ht;
+static ck_epoch_record_t epoch_wr;
+static int n_threads;
+static bool next_stage;
+
+enum state {
+	HT_STATE_STOP = 0,
+	HT_STATE_GET,
+	HT_STATE_STRICT_REPLACEMENT,
+	HT_STATE_DELETION,
+	HT_STATE_REPLACEMENT,
+	HT_STATE_COUNT
+};
+
+static struct affinity affinerator = AFFINITY_INITIALIZER;
+static uint64_t accumulator[HT_STATE_COUNT];
+static int barrier[HT_STATE_COUNT];
+static int state;
+
+struct ht_epoch {
+	ck_epoch_entry_t epoch_entry;
+};
+
+COMMON_ALARM_DECLARE_GLOBAL(ht_alarm, alarm_event, next_stage)
+
+static void
+alarm_handler(int s)
+{
+
+	(void)s;
+	next_stage = true;
+	return;
+}
+
+static void
+ht_destroy(ck_epoch_entry_t *e)
+{
+
+	free(e);
+	return;
+}
+
+static void *
+ht_malloc(size_t r)
+{
+	ck_epoch_entry_t *b;
+
+	b = malloc(sizeof(*b) + r);
+	return b + 1;
+}
+
+static void
+ht_free(void *p, size_t b, bool r)
+{
+	struct ht_epoch *e = p;
+
+	(void)b;
+
+	if (r == true) {
+		/* Destruction requires safe memory reclamation. */
+		ck_epoch_call(&epoch_ht, &epoch_wr, &(--e)->epoch_entry, ht_destroy);
+	} else {
+		free(--e);
+	}
+
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = ht_malloc,
+	.free = ht_free
+};
+
+static void
+table_init(void)
+{
+	unsigned int mode = CK_HT_MODE_BYTESTRING;
+
+#ifdef HT_DELETE
+	mode |= CK_HT_WORKLOAD_DELETE;
+#endif
+
+	ck_epoch_init(&epoch_ht);
+	ck_epoch_register(&epoch_ht, &epoch_wr);
+	common_srand48((long int)time(NULL));
+	if (ck_ht_init(&ht, mode, NULL, &my_allocator, 8, common_lrand48()) == false) {
+		perror("ck_ht_init");
+		exit(EXIT_FAILURE);
+	}
+
+	return;
+}
+
+static bool
+table_remove(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_key_set(&entry, value, l);
+	return ck_ht_remove_spmc(&ht, h, &entry);
+}
+
+static bool
+table_replace(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_set(&entry, h, value, l, "REPLACED");
+	return ck_ht_set_spmc(&ht, h, &entry);
+}
+
+static void *
+table_get(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_key_set(&entry, value, l);
+	if (ck_ht_get_spmc(&ht, h, &entry) == true)
+		return ck_ht_entry_value(&entry);
+
+	return NULL;
+}
+
+static bool
+table_insert(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_set(&entry, h, value, l, value);
+	return ck_ht_put_spmc(&ht, h, &entry);
+}
+
+static size_t
+table_count(void)
+{
+
+	return ck_ht_count(&ht);
+}
+
+static bool
+table_reset(void)
+{
+
+	return ck_ht_reset_spmc(&ht);
+}
+
+static void *
+reader(void *unused)
+{
+	size_t i;
+	ck_epoch_record_t epoch_record;
+	int state_previous = HT_STATE_STOP;
+	int n_state;
+	uint64_t s, j, a;
+
+	(void)unused;
+	if (aff_iterate(&affinerator) != 0)
+		perror("WARNING: Failed to affine thread");
+
+	s = j = a = 0;
+	ck_epoch_register(&epoch_ht, &epoch_record);
+	for (;;) {
+		j++;
+		ck_epoch_begin(&epoch_ht, &epoch_record);
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			char *r;
+
+			r = table_get(keys[i]);
+			if (r == NULL)
+				continue;
+
+			if (strcmp(r, "REPLACED") == 0)
+				continue;
+
+			if (strcmp(r, keys[i]) == 0)
+				continue;
+
+			ck_error("ERROR: Found invalid value: [%s] but expected [%s]\n", r, keys[i]);
+		}
+		a += rdtsc() - s;
+		ck_epoch_end(&epoch_ht, &epoch_record);
+
+		n_state = ck_pr_load_int(&state);
+		if (n_state != state_previous) {
+			ck_pr_add_64(&accumulator[state_previous], a / (j * keys_length));
+			ck_pr_inc_int(&barrier[state_previous]);
+			while (ck_pr_load_int(&barrier[state_previous]) != n_threads + 1)
+				ck_pr_stall();
+
+			state_previous = n_state;
+			s = j = a = 0;
+		}
+	}
+
+	return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+	FILE *fp;
+	char buffer[512];
+	size_t i, j, r;
+	unsigned int d = 0;
+	uint64_t s, e, a, repeated;
+	char **t;
+	pthread_t *readers;
+	double p_r, p_d;
+
+	COMMON_ALARM_DECLARE_LOCAL(ht_alarm, alarm_event)
+
+	r = 20;
+	s = 8;
+	p_d = 0.5;
+	p_r = 0.5;
+	n_threads = CORES - 1;
+
+	if (argc < 2) {
+		ck_error("Usage: parallel <dictionary> [<interval length> <initial size> <readers>\n"
+		    " <probability of replacement> <probability of deletion> <epoch threshold>]\n");
+	}
+
+	if (argc >= 3)
+		r = atoi(argv[2]);
+
+	if (argc >= 4)
+		s = (uint64_t)atoi(argv[3]);
+
+	if (argc >= 5) {
+		n_threads = atoi(argv[4]);
+		if (n_threads < 1) {
+			ck_error("ERROR: Number of readers must be >= 1.\n");
+		}
+	}
+
+	if (argc >= 6) {
+		p_r = atof(argv[5]) / 100.00;
+		if (p_r < 0) {
+			ck_error("ERROR: Probability of replacement must be >= 0 and <= 100.\n");
+		}
+	}
+
+	if (argc >= 7) {
+		p_d = atof(argv[6]) / 100.00;
+		if (p_d < 0) {
+			ck_error("ERROR: Probability of deletion must be >= 0 and <= 100.\n");
+		}
+	}
+
+	COMMON_ALARM_INIT(ht_alarm, alarm_event, r)
+
+	affinerator.delta = 1;
+	readers = malloc(sizeof(pthread_t) * n_threads);
+	assert(readers != NULL);
+
+	keys = malloc(sizeof(char *) * keys_capacity);
+	assert(keys != NULL);
+
+	fp = fopen(argv[1], "r");
+	assert(fp != NULL);
+
+	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+		buffer[strlen(buffer) - 1] = '\0';
+		keys[keys_length++] = strdup(buffer);
+		assert(keys[keys_length - 1] != NULL);
+
+		if (keys_length == keys_capacity) {
+			t = realloc(keys, sizeof(char *) * (keys_capacity *= 2));
+			assert(t != NULL);
+			keys = t;
+		}
+	}
+
+	t = realloc(keys, sizeof(char *) * keys_length);
+	assert(t != NULL);
+	keys = t;
+
+	table_init();
+
+	for (i = 0; i < (size_t)n_threads; i++) {
+		if (pthread_create(&readers[i], NULL, reader, NULL) != 0) {
+			ck_error("ERROR: Failed to create thread %zu.\n", i);
+		}
+	}
+
+	for (i = 0; i < keys_length; i++)
+		d += table_insert(keys[i]) == false;
+
+	fprintf(stderr, " [S] %d readers, 1 writer.\n", n_threads);
+	fprintf(stderr, " [S] %zu entries stored and %u duplicates.\n\n",
+	    table_count(), d);
+
+	fprintf(stderr, " ,- BASIC TEST\n");
+	fprintf(stderr, " | Executing SMR test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (table_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += table_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing replacement test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing get test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (table_get(keys[i]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	a = 0;
+	fprintf(stderr, " | Executing removal test...");
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_remove(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			table_insert(keys[i]);
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing negative look-up test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_get("\x50\x03\x04\x05\x06\x10");
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	ck_epoch_record_t epoch_temporary = epoch_wr;
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+
+	fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> "
+	    "%u pending, %u peak, %lu reclamations\n\n",
+	    epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch,
+	    epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch);
+
+	fprintf(stderr, " ,- READER CONCURRENCY\n");
+	fprintf(stderr, " | Executing reader test...");
+
+	ck_pr_store_int(&state, HT_STATE_GET);
+	while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads)
+		ck_pr_stall();
+	ck_pr_inc_int(&barrier[HT_STATE_STOP]);
+	common_sleep(r);
+	ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT);
+	while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads)
+		ck_pr_stall();
+	fprintf(stderr, "done (reader = %" PRIu64 " ticks)\n",
+	    accumulator[HT_STATE_GET] / n_threads);
+
+	fprintf(stderr, " | Executing strict replacement test...");
+
+	a = repeated = 0;
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	ck_pr_inc_int(&barrier[HT_STATE_GET]);
+	for (;;) {
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+
+	ck_pr_store_int(&state, HT_STATE_DELETION);
+	while (ck_pr_load_int(&barrier[HT_STATE_STRICT_REPLACEMENT]) != n_threads)
+		ck_pr_stall();
+	table_reset();
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads);
+
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100);
+	a = repeated = 0;
+	ck_pr_inc_int(&barrier[HT_STATE_STRICT_REPLACEMENT]);
+	for (;;) {
+		double delete;
+
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_insert(keys[i]);
+			if (p_d != 0.0) {
+				delete = common_drand48();
+				if (delete <= p_d)
+					table_remove(keys[i]);
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+	ck_pr_store_int(&state, HT_STATE_REPLACEMENT);
+	while (ck_pr_load_int(&barrier[HT_STATE_DELETION]) != n_threads)
+		ck_pr_stall();
+
+	table_reset();
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads);
+
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100);
+	a = repeated = 0;
+	ck_pr_inc_int(&barrier[HT_STATE_DELETION]);
+	for (;;) {
+		double replace, delete;
+
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_insert(keys[i]);
+			if (p_d != 0.0) {
+				delete = common_drand48();
+				if (delete <= p_d)
+					table_remove(keys[i]);
+			}
+			if (p_r != 0.0) {
+				replace = common_drand48();
+				if (replace <= p_r)
+					table_replace(keys[i]);
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+	ck_pr_store_int(&state, HT_STATE_STOP);
+	while (ck_pr_load_int(&barrier[HT_STATE_REPLACEMENT]) != n_threads)
+		ck_pr_stall();
+	table_reset();
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), accumulator[HT_STATE_REPLACEMENT] / n_threads);
+
+	ck_pr_inc_int(&barrier[HT_STATE_REPLACEMENT]);
+	epoch_temporary = epoch_wr;
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+
+	fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> "
+	    "%u pending, %u peak, %lu reclamations\n\n",
+	    epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch,
+	    epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch);
+	return 0;
+}
+#else
+int
+main(void)
+{
+
+	return 0;
+}
+#endif /* CK_F_HT */
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_ht/benchmark/parallel_direct.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_ht/benchmark/parallel_direct.c b/lib/ck/regressions/ck_ht/benchmark/parallel_direct.c
new file mode 100644
index 0000000..f9d7b47
--- /dev/null
+++ b/lib/ck/regressions/ck_ht/benchmark/parallel_direct.c
@@ -0,0 +1,552 @@
+/*
+ * Copyright 2012-2014 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 <ck_ht.h>
+
+#ifdef CK_F_HT
+
+#include <assert.h>
+#include <ck_epoch.h>
+#include <ck_malloc.h>
+#include <ck_pr.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "../../common.h"
+
+static ck_ht_t ht CK_CC_CACHELINE;
+static uintptr_t *keys;
+static size_t keys_length = 0;
+static ck_epoch_t epoch_ht;
+static ck_epoch_record_t epoch_wr;
+static int n_threads;
+static bool next_stage;
+
+enum state {
+	HT_STATE_STOP = 0,
+	HT_STATE_GET,
+	HT_STATE_STRICT_REPLACEMENT,
+	HT_STATE_DELETION,
+	HT_STATE_REPLACEMENT,
+	HT_STATE_COUNT
+};
+
+static struct affinity affinerator = AFFINITY_INITIALIZER;
+static uint64_t accumulator[HT_STATE_COUNT];
+static int barrier[HT_STATE_COUNT];
+static int state;
+
+struct ht_epoch {
+	ck_epoch_entry_t epoch_entry;
+};
+
+COMMON_ALARM_DECLARE_GLOBAL(ht_alarm, alarm_event, next_stage)
+
+static void
+alarm_handler(int s)
+{
+
+	(void)s;
+	next_stage = true;
+	return;
+}
+
+static void
+ht_destroy(ck_epoch_entry_t *e)
+{
+
+	free(e);
+	return;
+}
+
+static void *
+ht_malloc(size_t r)
+{
+	ck_epoch_entry_t *b;
+
+	b = malloc(sizeof(*b) + r);
+	return b + 1;
+}
+
+static void
+ht_free(void *p, size_t b, bool r)
+{
+	struct ht_epoch *e = p;
+
+	(void)b;
+
+	if (r == true) {
+		/* Destruction requires safe memory reclamation. */
+		ck_epoch_call(&epoch_ht, &epoch_wr, &(--e)->epoch_entry, ht_destroy);
+	} else {
+		free(--e);
+	}
+
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = ht_malloc,
+	.free = ht_free
+};
+
+static void
+hash_function(ck_ht_hash_t *h, const void *key, size_t key_length, uint64_t seed)
+{
+	const uintptr_t *value = key;
+
+	(void)key_length;
+	(void)seed;
+	h->value = *value;
+	return;
+}
+
+static void
+table_init(void)
+{
+
+	ck_epoch_init(&epoch_ht);
+	ck_epoch_register(&epoch_ht, &epoch_wr);
+	common_srand48((long int)time(NULL));
+	if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, hash_function, &my_allocator, 8, common_lrand48()) == false) {
+		perror("ck_ht_init");
+		exit(EXIT_FAILURE);
+	}
+
+	return;
+}
+
+static bool
+table_remove(uintptr_t value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+
+	ck_ht_hash_direct(&h, &ht, value);
+	ck_ht_entry_key_set_direct(&entry, value);
+	return ck_ht_remove_spmc(&ht, h, &entry);
+}
+
+static bool
+table_replace(uintptr_t value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+
+	ck_ht_hash_direct(&h, &ht, value);
+	ck_ht_entry_set_direct(&entry, h, value, 6605241);
+	return ck_ht_set_spmc(&ht, h, &entry);
+}
+
+static uintptr_t
+table_get(uintptr_t value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+
+	ck_ht_hash_direct(&h, &ht, value);
+	ck_ht_entry_key_set_direct(&entry, value);
+	if (ck_ht_get_spmc(&ht, h, &entry) == true)
+		return ck_ht_entry_value_direct(&entry);
+
+	return 0;
+}
+
+static bool
+table_insert(uintptr_t value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+
+	ck_ht_hash_direct(&h, &ht, value);
+	ck_ht_entry_set_direct(&entry, h, value, value);
+	return ck_ht_put_spmc(&ht, h, &entry);
+}
+
+static size_t
+table_count(void)
+{
+
+	return ck_ht_count(&ht);
+}
+
+static bool
+table_reset(void)
+{
+
+	return ck_ht_reset_spmc(&ht);
+}
+
+static void *
+ht_reader(void *unused)
+{
+	size_t i;
+	ck_epoch_record_t epoch_record;
+	int state_previous = HT_STATE_STOP;
+	int n_state;
+	uint64_t s, j, a;
+
+	(void)unused;
+	if (aff_iterate(&affinerator) != 0)
+		perror("WARNING: Failed to affine thread");
+
+	s = j = a = 0;
+	ck_epoch_register(&epoch_ht, &epoch_record);
+	for (;;) {
+		j++;
+		ck_epoch_begin(&epoch_ht, &epoch_record);
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			uintptr_t r;
+
+			r = table_get(keys[i]);
+			if (r == 0)
+				continue;
+
+			if (r == 6605241)
+				continue;
+
+			if (r == keys[i])
+				continue;
+
+			ck_error("ERROR: Found invalid value: [%ju]\n",
+			    (uintmax_t)r);
+		}
+		a += rdtsc() - s;
+		ck_epoch_end(&epoch_ht, &epoch_record);
+
+		n_state = ck_pr_load_int(&state);
+		if (n_state != state_previous) {
+			ck_pr_add_64(&accumulator[state_previous], a / (j * keys_length));
+			ck_pr_inc_int(&barrier[state_previous]);
+			while (ck_pr_load_int(&barrier[state_previous]) != n_threads + 1)
+				ck_pr_stall();
+
+			state_previous = n_state;
+			s = j = a = 0;
+		}
+	}
+
+	return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+	size_t i, j, r;
+	unsigned int d = 0;
+	uint64_t s, e, a, repeated;
+	pthread_t *readers;
+	double p_r, p_d;
+
+	COMMON_ALARM_DECLARE_LOCAL(ht_alarm, alarm_event)
+
+	r = 20;
+	s = 8;
+	p_d = 0.5;
+	p_r = 0.5;
+	n_threads = CORES - 1;
+
+	if (argc < 2) {
+		fprintf(stderr, "Usage: parallel <#entries> [<interval length> <initial size> <readers>\n"
+		    " <probability of replacement> <probability of deletion> <epoch threshold>]\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (argc >= 3)
+		r = atoi(argv[2]);
+
+	if (argc >= 4)
+		s = (uint64_t)atoi(argv[3]);
+
+	if (argc >= 5) {
+		n_threads = atoi(argv[4]);
+		if (n_threads < 1) {
+			ck_error("ERROR: Number of readers must be >= 1.\n");
+		}
+	}
+
+	if (argc >= 6) {
+		p_r = atof(argv[5]) / 100.00;
+		if (p_r < 0) {
+			ck_error("ERROR: Probability of replacement must be >= 0 and <= 100.\n");
+		}
+	}
+
+	if (argc >= 7) {
+		p_d = atof(argv[6]) / 100.00;
+		if (p_d < 0) {
+			ck_error("ERROR: Probability of deletion must be >= 0 and <= 100.\n");
+		}
+	}
+
+	COMMON_ALARM_INIT(ht_alarm, alarm_event, r)
+
+	affinerator.delta = 1;
+	readers = malloc(sizeof(pthread_t) * n_threads);
+	assert(readers != NULL);
+
+	keys_length = (size_t)atoi(argv[1]);
+	keys = malloc(sizeof(uintptr_t) * keys_length);
+	assert(keys != NULL);
+
+	table_init();
+
+	for (i = 0; i < keys_length; i++) {
+		keys[i] = (uintptr_t)common_lrand48();
+		while (keys[i] == 2)
+			keys[i] = (uintptr_t)common_lrand48();
+	}
+
+	for (i = 0; i < (size_t)n_threads; i++) {
+		if (pthread_create(&readers[i], NULL, ht_reader, NULL) != 0) {
+			ck_error("ERROR: Failed to create thread %zu.\n", i);
+		}
+	}
+
+	for (i = 0; i < keys_length; i++)
+		d += table_insert(keys[i]) == false;
+
+	fprintf(stderr, " [S] %zu entries stored and %u duplicates.\n\n",
+	    table_count(), d);
+
+	fprintf(stderr, " ,- BASIC TEST\n");
+	fprintf(stderr, " | Executing SMR test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (table_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += table_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing replacement test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing get test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (table_get(keys[i]) == 0) {
+				ck_error("ERROR: Unexpected 0 value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	a = 0;
+	fprintf(stderr, " | Executing removal test...");
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_remove(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			table_insert(keys[i]);
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	fprintf(stderr, " | Executing negative look-up test...");
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_get(2);
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length));
+
+	ck_epoch_record_t epoch_temporary = epoch_wr;
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+
+	fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> "
+	    "%u pending, %u peak, %lu reclamations\n\n",
+	    epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch,
+	    epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch);
+
+	fprintf(stderr, " ,- READER CONCURRENCY\n");
+	fprintf(stderr, " | Executing reader test...");
+
+	ck_pr_store_int(&state, HT_STATE_GET);
+	while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads)
+		ck_pr_stall();
+	ck_pr_inc_int(&barrier[HT_STATE_STOP]);
+	common_sleep(r);
+	ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT);
+	while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads)
+		ck_pr_stall();
+	fprintf(stderr, "done (reader = %" PRIu64 " ticks)\n",
+	    accumulator[HT_STATE_GET] / n_threads);
+
+	fprintf(stderr, " | Executing strict replacement test...");
+
+	a = repeated = 0;
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	ck_pr_inc_int(&barrier[HT_STATE_GET]);
+	for (;;) {
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+
+	ck_pr_store_int(&state, HT_STATE_DELETION);
+	while (ck_pr_load_int(&barrier[HT_STATE_STRICT_REPLACEMENT]) != n_threads)
+		ck_pr_stall();
+	table_reset();
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads);
+
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100);
+	a = repeated = 0;
+	ck_pr_inc_int(&barrier[HT_STATE_STRICT_REPLACEMENT]);
+	for (;;) {
+		double delete;
+
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_insert(keys[i]);
+			if (p_d != 0.0) {
+				delete = common_drand48();
+				if (delete <= p_d)
+					table_remove(keys[i]);
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+	ck_pr_store_int(&state, HT_STATE_REPLACEMENT);
+	while (ck_pr_load_int(&barrier[HT_STATE_DELETION]) != n_threads)
+		ck_pr_stall();
+
+	table_reset();
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads);
+
+	common_alarm(alarm_handler, &alarm_event, r);
+
+	fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100);
+	a = repeated = 0;
+	ck_pr_inc_int(&barrier[HT_STATE_DELETION]);
+	for (;;) {
+		double replace, delete;
+
+		repeated++;
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_insert(keys[i]);
+			if (p_d != 0.0) {
+				delete = common_drand48();
+				if (delete <= p_d)
+					table_remove(keys[i]);
+			}
+			if (p_r != 0.0) {
+				replace = common_drand48();
+				if (replace <= p_r)
+					table_replace(keys[i]);
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+
+		if (next_stage == true) {
+			next_stage = false;
+			break;
+		}
+	}
+	ck_pr_store_int(&state, HT_STATE_STOP);
+	while (ck_pr_load_int(&barrier[HT_STATE_REPLACEMENT]) != n_threads)
+		ck_pr_stall();
+	table_reset();
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+	fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
+	    a / (repeated * keys_length), accumulator[HT_STATE_REPLACEMENT] / n_threads);
+
+	ck_pr_inc_int(&barrier[HT_STATE_REPLACEMENT]);
+	epoch_temporary = epoch_wr;
+	ck_epoch_synchronize(&epoch_ht, &epoch_wr);
+
+	fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> "
+	    "%u pending, %u peak, %lu reclamations\n\n",
+	    epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch,
+	    epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch);
+	return 0;
+}
+#else
+int
+main(void)
+{
+
+	return 0;
+}
+#endif /* CK_F_HT */
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_ht/benchmark/serial.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_ht/benchmark/serial.c b/lib/ck/regressions/ck_ht/benchmark/serial.c
new file mode 100644
index 0000000..757e128
--- /dev/null
+++ b/lib/ck/regressions/ck_ht/benchmark/serial.c
@@ -0,0 +1,398 @@
+/*
+ * Copyright 2012-2014 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 <ck_ht.h>
+
+#ifdef CK_F_HT
+
+#include <assert.h>
+#include <ck_malloc.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "../../common.h"
+
+static ck_ht_t ht;
+static char **keys;
+static size_t keys_length = 0;
+static size_t keys_capacity = 128;
+
+static void *
+ht_malloc(size_t r)
+{
+
+	return malloc(r);
+}
+
+static void
+ht_free(void *p, size_t b, bool r)
+{
+
+	(void)b;
+	(void)r;
+
+	free(p);
+
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = ht_malloc,
+	.free = ht_free
+};
+
+static void
+table_init(void)
+{
+	unsigned int mode = CK_HT_MODE_BYTESTRING;
+
+#ifdef HT_DELETE
+	mode |= CK_HT_WORKLOAD_DELETE;
+#endif
+
+	common_srand48((long int)time(NULL));
+	if (ck_ht_init(&ht, mode, NULL, &my_allocator, 8, common_lrand48()) == false) {
+		perror("ck_ht_init");
+		exit(EXIT_FAILURE);
+	}
+
+	return;
+}
+
+static bool
+table_remove(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_key_set(&entry, value, l);
+	return ck_ht_remove_spmc(&ht, h, &entry);
+}
+
+static bool
+table_replace(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_set(&entry, h, value, l, "REPLACED");
+	return ck_ht_set_spmc(&ht, h, &entry);
+}
+
+static void *
+table_get(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+	void *v = NULL;
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_key_set(&entry, value, l);
+
+	if (ck_ht_get_spmc(&ht, h, &entry) == true) {
+		v = ck_ht_entry_value(&entry);
+	}
+	return v;
+}
+
+static bool
+table_insert(const char *value)
+{
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	size_t l = strlen(value);
+
+	ck_ht_hash(&h, &ht, value, l);
+	ck_ht_entry_set(&entry, h, value, l, "VALUE");
+	return ck_ht_put_spmc(&ht, h, &entry);
+}
+
+static size_t
+table_count(void)
+{
+
+	return ck_ht_count(&ht);
+}
+
+static bool
+table_gc(void)
+{
+
+	return ck_ht_gc(&ht, 0, common_lrand48());
+}
+
+static bool
+table_reset(void)
+{
+
+	return ck_ht_reset_spmc(&ht);
+}
+
+static void
+keys_shuffle(char **k)
+{
+	size_t i, j;
+	char *t;
+
+	for (i = keys_length; i > 1; i--) {
+		j = rand() % (i - 1);
+
+		if (j != i - 1) {
+			t = k[i - 1];
+			k[i - 1] = k[j];
+			k[j] = t;
+		}
+	}
+
+	return;
+}
+
+int
+main(int argc, char *argv[])
+{
+	FILE *fp;
+	char buffer[512];
+	size_t i, j, r;
+	unsigned int d = 0;
+	uint64_t s, e, a, ri, si, ai, sr, rg, sg, ag, sd, ng, gg;
+	char **t;
+	struct ck_ht_stat st;
+
+	r = 20;
+	s = 8;
+	srand(time(NULL));
+
+	if (argc < 2) {
+		ck_error("Usage: ck_ht <dictionary> [<repetitions> <initial size>]\n");
+	}
+
+	if (argc >= 3)
+		r = atoi(argv[2]);
+
+	if (argc >= 4)
+		s = (uint64_t)atoi(argv[3]);
+
+	keys = malloc(sizeof(char *) * keys_capacity);
+	assert(keys != NULL);
+
+	fp = fopen(argv[1], "r");
+	assert(fp != NULL);
+
+	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+		buffer[strlen(buffer) - 1] = '\0';
+		keys[keys_length++] = strdup(buffer);
+		assert(keys[keys_length - 1] != NULL);
+
+		if (keys_length == keys_capacity) {
+			t = realloc(keys, sizeof(char *) * (keys_capacity *= 2));
+			assert(t != NULL);
+			keys = t;
+		}
+	}
+
+	t = realloc(keys, sizeof(char *) * keys_length);
+	assert(t != NULL);
+	keys = t;
+
+	table_init();
+
+	for (i = 0; i < keys_length; i++)
+		d += table_insert(keys[i]) == false;
+	ck_ht_stat(&ht, &st);
+
+	fprintf(stderr, "# %zu entries stored, %u duplicates, %" PRIu64 " probe.\n",
+	    table_count(), d, st.probe_maximum);
+
+	fprintf(stderr, "#    reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get garbage_collect\n\n");
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (table_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = keys_length; i > 0; i--)
+			d += table_insert(keys[i - 1]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	ri = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		if (table_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += table_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	si = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		keys_shuffle(keys);
+
+		if (table_reset() == false) {
+			ck_error("ERROR: Failed to reset hash table.\n");
+		}
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			d += table_insert(keys[i]) == false;
+		e = rdtsc();
+		a += e - s;
+	}
+	ai = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_replace(keys[i]);
+		e = rdtsc();
+		a += e - s;
+	}
+	sr = a / (r * keys_length);
+
+	table_reset();
+	for (i = 0; i < keys_length; i++)
+		table_insert(keys[i]);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = keys_length; i > 0; i--) {
+			if (table_get(keys[i - 1]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	rg = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (table_get(keys[i]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	sg = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		keys_shuffle(keys);
+
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			if (table_get(keys[i]) == NULL) {
+				ck_error("ERROR: Unexpected NULL value.\n");
+			}
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	ag = a / (r * keys_length);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++)
+			table_remove(keys[i]);
+		e = rdtsc();
+		a += e - s;
+
+		for (i = 0; i < keys_length; i++)
+			table_insert(keys[i]);
+	}
+	sd = a / (r * keys_length);
+
+	for (i = 0; i < keys_length / 2; i++)
+		table_remove(keys[i]);
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		table_gc();
+		e = rdtsc();
+		a += e - s;
+	}
+	gg = a / r;
+
+	a = 0;
+	for (j = 0; j < r; j++) {
+		s = rdtsc();
+		for (i = 0; i < keys_length; i++) {
+			table_get("\x50\x03\x04\x05\x06\x10");
+		}
+		e = rdtsc();
+		a += e - s;
+	}
+	ng = a / (r * keys_length);
+
+	printf("%zu "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 " "
+	    "%" PRIu64 "\n",
+	    keys_length, ri, si, ai, sr, rg, sg, ag, sd, ng, gg);
+
+	return 0;
+}
+#else
+int
+main(void)
+{
+
+	return 0;
+}
+#endif /* CK_F_HT */
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_ht/validate/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_ht/validate/Makefile b/lib/ck/regressions/ck_ht/validate/Makefile
new file mode 100644
index 0000000..cb5682c
--- /dev/null
+++ b/lib/ck/regressions/ck_ht/validate/Makefile
@@ -0,0 +1,21 @@
+.PHONY: check clean distribution
+
+OBJECTS=serial serial.delete
+
+all: $(OBJECTS)
+
+serial: serial.c ../../../include/ck_ht.h ../../../src/ck_ht.c
+	$(CC) $(CFLAGS) -o serial serial.c ../../../src/ck_ht.c
+
+serial.delete: serial.c ../../../include/ck_ht.h ../../../src/ck_ht.c
+	$(CC) $(CFLAGS) -DHT_DELETE -o serial.delete serial.c ../../../src/ck_ht.c
+
+check: all
+	./serial
+	./serial.delete
+
+clean:
+	rm -rf *~ *.o $(OBJECTS) *.dSYM *.exe
+
+include ../../../build/regressions.build
+CFLAGS+=-D_GNU_SOURCE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_ht/validate/serial.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_ht/validate/serial.c b/lib/ck/regressions/ck_ht/validate/serial.c
new file mode 100644
index 0000000..e8a6f6c
--- /dev/null
+++ b/lib/ck/regressions/ck_ht/validate/serial.c
@@ -0,0 +1,292 @@
+/*
+ * Copyright 2012-2014 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 <ck_ht.h>
+
+#ifdef CK_F_HT
+#include <assert.h>
+#include <ck_malloc.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../../common.h"
+
+static void *
+ht_malloc(size_t r)
+{
+
+	return malloc(r);
+}
+
+static void
+ht_free(void *p, size_t b, bool r)
+{
+
+	(void)b;
+	(void)r;
+	free(p);
+	return;
+}
+
+static struct ck_malloc my_allocator = {
+	.malloc = ht_malloc,
+	.free = ht_free
+};
+
+const char *test[] = {"Samy", "Al", "Bahra", "dances", "in", "the", "wind.", "Once",
+			"upon", "a", "time", "his", "gypsy", "ate", "one", "itsy",
+			    "bitsy", "spider.", "What", "goes", "up", "must",
+				"come", "down.", "What", "is", "down", "stays",
+				    "down.", "A", "B", "C", "D", "E", "F", "G", "H",
+					"I", "J", "K", "L", "M", "N", "O"};
+
+static uintptr_t direct[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2, 3, 4, 5, 9 };
+
+const char *negative = "negative";
+
+int
+main(void)
+{
+	size_t i, l;
+	ck_ht_t ht;
+	ck_ht_entry_t entry;
+	ck_ht_hash_t h;
+	ck_ht_iterator_t iterator = CK_HT_ITERATOR_INITIALIZER;
+	ck_ht_entry_t *cursor;
+	unsigned int mode = CK_HT_MODE_BYTESTRING;
+
+#ifdef HT_DELETE
+	mode |= CK_HT_WORKLOAD_DELETE;
+#endif
+
+	if (ck_ht_init(&ht, mode, NULL, &my_allocator, 16, 6602834) == false) {
+		perror("ck_ht_init");
+		exit(EXIT_FAILURE);
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_set(&entry, h, test[i], l, test[i]);
+		ck_ht_put_spmc(&ht, h, &entry);
+	}
+
+	l = strlen(test[0]);
+	ck_ht_hash(&h, &ht, test[0], l);
+	ck_ht_entry_set(&entry, h, test[0], l, test[0]);
+	ck_ht_put_spmc(&ht, h, &entry);
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_key_set(&entry, test[i], l);
+		if (ck_ht_get_spmc(&ht, h, &entry) == false) {
+			ck_error("ERROR (put): Failed to find [%s]\n", test[i]);
+		} else {
+			void *k, *v;
+
+			k = ck_ht_entry_key(&entry);
+			v = ck_ht_entry_value(&entry);
+
+			if (strcmp(k, test[i]) || strcmp(v, test[i])) {
+				ck_error("ERROR: Mismatch: (%s, %s) != (%s, %s)\n",
+				    (char *)k, (char *)v, test[i], test[i]);
+			}
+		}
+	}
+
+	ck_ht_hash(&h, &ht, negative, strlen(negative));
+	ck_ht_entry_key_set(&entry, negative, strlen(negative));
+	if (ck_ht_get_spmc(&ht, h, &entry) == true) {
+		ck_error("ERROR: Found non-existing entry.\n");
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_key_set(&entry, test[i], l);
+
+		if (ck_ht_get_spmc(&ht, h, &entry) == false)
+			continue;
+
+		if (ck_ht_remove_spmc(&ht, h, &entry) == false) {
+			ck_error("ERROR: Failed to delete existing entry\n");
+		}
+
+		if (ck_ht_get_spmc(&ht, h, &entry) == true)
+			ck_error("ERROR: Able to find [%s] after delete\n", test[i]);
+
+		ck_ht_entry_set(&entry, h, test[i], l, test[i]);
+		if (ck_ht_put_spmc(&ht, h, &entry) == false)
+			ck_error("ERROR: Failed to insert [%s]\n", test[i]);
+
+		if (ck_ht_remove_spmc(&ht, h, &entry) == false) {
+			ck_error("ERROR: Failed to delete existing entry\n");
+		}
+	}
+
+	ck_ht_reset_spmc(&ht);
+	if (ck_ht_count(&ht) != 0) {
+		ck_error("ERROR: Map was not reset.\n");
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_set(&entry, h, test[i], l, test[i]);
+		ck_ht_put_spmc(&ht, h, &entry);
+	}
+
+	for (i = 0; ck_ht_next(&ht, &iterator, &cursor) == true; i++);
+	if (i != 42) {
+		ck_error("ERROR: Incorrect number of entries in table.\n");
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_set(&entry, h, test[i], l, test[i]);
+		ck_ht_set_spmc(&ht, h, &entry);
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_key_set(&entry, test[i], l);
+		if (ck_ht_get_spmc(&ht, h, &entry) == false) {
+			ck_error("ERROR (set): Failed to find [%s]\n", test[i]);
+		} else {
+			void *k, *v;
+
+			k = ck_ht_entry_key(&entry);
+			v = ck_ht_entry_value(&entry);
+
+			if (strcmp(k, test[i]) || strcmp(v, test[i])) {
+				ck_error("ERROR: Mismatch: (%s, %s) != (%s, %s)\n",
+				    (char *)k, (char *)v, test[i], test[i]);
+			}
+		}
+	}
+
+	if (ck_ht_gc(&ht, 0, 27) == false) {
+		ck_error("ck_ht_gc\n");
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_set(&entry, h, test[i], l, "REPLACED");
+		ck_ht_set_spmc(&ht, h, &entry);
+
+		if (strcmp(test[i], "What") == 0)
+			continue;
+
+		if (strcmp(test[i], "down.") == 0)
+			continue;
+
+		if (strcmp(ck_ht_entry_value(&entry), test[i]) != 0) {
+			ck_error("Mismatch detected: %s, expected %s\n",
+				(char *)ck_ht_entry_value(&entry),
+				test[i]);
+		}
+	}
+
+	ck_ht_iterator_init(&iterator);
+	while (ck_ht_next(&ht, &iterator, &cursor) == true) {
+		if (strcmp(ck_ht_entry_value(cursor), "REPLACED") != 0) {
+			ck_error("Mismatch detected: %s, expected REPLACED\n",
+				(char *)ck_ht_entry_value(cursor));
+		}
+	}
+
+	for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
+		l = strlen(test[i]);
+		ck_ht_hash(&h, &ht, test[i], l);
+		ck_ht_entry_key_set(&entry, test[i], l);
+
+		if (ck_ht_get_spmc(&ht, h, &entry) == false)
+			continue;
+
+		if (ck_ht_remove_spmc(&ht, h, &entry) == false) {
+			ck_error("ERROR: Failed to delete existing entry\n");
+		}
+
+		if (ck_ht_get_spmc(&ht, h, &entry) == true)
+			ck_error("ERROR: Able to find [%s] after delete\n", test[i]);
+
+		ck_ht_entry_set(&entry, h, test[i], l, test[i]);
+		if (ck_ht_put_spmc(&ht, h, &entry) == false)
+			ck_error("ERROR: Failed to insert [%s]\n", test[i]);
+
+		if (ck_ht_remove_spmc(&ht, h, &entry) == false) {
+			ck_error("ERROR: Failed to delete existing entry\n");
+		}
+	}
+
+	ck_ht_destroy(&ht);
+	if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, NULL, &my_allocator, 8, 6602834) == false) {
+		perror("ck_ht_init");
+		exit(EXIT_FAILURE);
+	}
+
+	l = 0;
+	for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) {
+		ck_ht_hash_direct(&h, &ht, direct[i]);
+		ck_ht_entry_set_direct(&entry, h, direct[i], (uintptr_t)test[i]);
+		l += ck_ht_put_spmc(&ht, h, &entry) == false;
+	}
+
+	if (l != 7) {
+		ck_error("ERROR: Got %zu failures rather than 7\n", l);
+	}
+
+	for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) {
+		ck_ht_hash_direct(&h, &ht, direct[i]);
+		ck_ht_entry_set_direct(&entry, h, direct[i], (uintptr_t)"REPLACED");
+		l += ck_ht_set_spmc(&ht, h, &entry) == false;
+	}
+
+	ck_ht_iterator_init(&iterator);
+	while (ck_ht_next(&ht, &iterator, &cursor) == true) {
+		if (strcmp(ck_ht_entry_value(cursor), "REPLACED") != 0) {
+			ck_error("Mismatch detected: %s, expected REPLACED\n",
+				(char *)ck_ht_entry_value(cursor));
+		}
+	}
+
+	ck_ht_destroy(&ht);
+	return 0;
+}
+#else
+int
+main(void)
+{
+
+	return 0;
+}
+#endif /* CK_F_HT */
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pflock/benchmark/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pflock/benchmark/Makefile b/lib/ck/regressions/ck_pflock/benchmark/Makefile
new file mode 100644
index 0000000..6f739d9
--- /dev/null
+++ b/lib/ck/regressions/ck_pflock/benchmark/Makefile
@@ -0,0 +1,17 @@
+.PHONY: clean distribution
+
+OBJECTS=latency throughput
+
+all: $(OBJECTS)
+
+latency: latency.c ../../../include/ck_rwlock.h
+	$(CC) $(CFLAGS) -o latency latency.c
+
+throughput: throughput.c ../../../include/ck_rwlock.h
+	$(CC) $(CFLAGS) -o throughput throughput.c
+
+clean:
+	rm -rf *.dSYM *.exe *~ *.o $(OBJECTS)
+
+include ../../../build/regressions.build
+CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pflock/benchmark/latency.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pflock/benchmark/latency.c b/lib/ck/regressions/ck_pflock/benchmark/latency.c
new file mode 100644
index 0000000..52236c5
--- /dev/null
+++ b/lib/ck/regressions/ck_pflock/benchmark/latency.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2011-2014 Samy Al Bahra.
+ * Copyright 2013 John Wittrock.
+ * 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 OTHEPFISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ck_pflock.h>
+#include <inttypes.h>
+#include <stdio.h>
+
+#include "../../common.h"
+
+#ifndef STEPS
+#define STEPS 1000000
+#endif
+
+int
+main(void)
+{
+	uint64_t s_b, e_b, i;
+	ck_pflock_t pflock = CK_PFLOCK_INITIALIZER;
+
+	for (i = 0; i < STEPS; i++) {
+		ck_pflock_write_lock(&pflock);
+		ck_pflock_write_unlock(&pflock);
+	}
+
+	s_b = rdtsc();
+	for (i = 0; i < STEPS; i++) {
+		ck_pflock_write_lock(&pflock);
+		ck_pflock_write_unlock(&pflock);
+	}
+	e_b = rdtsc();
+	printf("WRITE: pflock   %15" PRIu64 "\n", (e_b - s_b) / STEPS);
+
+	for (i = 0; i < STEPS; i++) {
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+	}
+
+	s_b = rdtsc();
+	for (i = 0; i < STEPS; i++) {
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+	}
+	e_b = rdtsc();
+	printf("READ:  pflock   %15" PRIu64 "\n", (e_b - s_b) / STEPS);
+
+	return 0;
+}
+