Skip to content

Commit

Permalink
Merge pull request #7 from paul-chambers/main
Browse files Browse the repository at this point in the history
Merging polish from @paul-chambers
  • Loading branch information
viega authored Mar 6, 2023
2 parents 41b9be0 + 99e9240 commit 168089e
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ examples_array_CFLAGS = -Wall -Wextra -I./include
examples_array_LDADD = ./libhatrack.a

include_HEADERS = include/hatrack.h
pkginclude_HEADERS = include/hatrack/xxhash.h include/hatrack/ballcap.h include/hatrack/config.h include/hatrack/counters.h include/hatrack/debug.h include/hatrack/dict.h include/hatrack/set.h include/hatrack/duncecap.h include/hatrack/hash.h include/hatrack/hatomic.h include/hatrack/hatrack_common.h include/hatrack/hatrack_config.h include/hatrack/hatvtable.h include/hatrack/hihat.h include/hatrack/lohat-a.h include/hatrack/lohat.h include/hatrack/lohat_common.h include/hatrack/mmm.h include/hatrack/newshat.h include/hatrack/oldhat.h include/hatrack/refhat.h include/hatrack/swimcap.h include/hatrack/tophat.h include/hatrack/witchhat.h include/hatrack/woolhat.h include/hatrack/crown.h include/hatrack/tiara.h include/hatrack/queue.h include/hatrack/hq.h include/hatrack/capq.h include/hatrack/flexarray.h include/hatrack/llstack.h include/hatrack/stack.h include/hatrack/hatring.h include/hatrack/logring.h include/hatrack/helpmanager.h include/hatrack/vector.h
pkginclude_HEADERS = include/hatrack/xxhash.h include/hatrack/ballcap.h include/hatrack/config.h include/hatrack/counters.h include/hatrack/debug.h include/hatrack/gate.h include/hatrack/dict.h include/hatrack/set.h include/hatrack/duncecap.h include/hatrack/hash.h include/hatrack/hatomic.h include/hatrack/hatrack_common.h include/hatrack/hatrack_config.h include/hatrack/hatvtable.h include/hatrack/hihat.h include/hatrack/lohat-a.h include/hatrack/lohat.h include/hatrack/lohat_common.h include/hatrack/mmm.h include/hatrack/newshat.h include/hatrack/oldhat.h include/hatrack/refhat.h include/hatrack/swimcap.h include/hatrack/tophat.h include/hatrack/witchhat.h include/hatrack/woolhat.h include/hatrack/crown.h include/hatrack/tiara.h include/hatrack/queue.h include/hatrack/hq.h include/hatrack/capq.h include/hatrack/flexarray.h include/hatrack/llstack.h include/hatrack/stack.h include/hatrack/hatring.h include/hatrack/logring.h include/hatrack/helpmanager.h include/hatrack/vector.h

test: check
remake: clean all
Expand Down
7 changes: 7 additions & 0 deletions automake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

mkdir -p autotools
aclocal
autoheader
autoconf
automake
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ AC_CACHE_CHECK([to see if atomic_fetch_add(ptr, 1) adds sizeof(ptr)],
[AC_RUN_IFELSE([
AC_LANG_PROGRAM([[#include <stdatomic.h>
typedef struct s { int a; int b; int c; } foo_t;
_Atomic(foo_t *) x = ATOMIC_VAR_INIT(NULL);]],
_Atomic(foo_t *) x = NULL;]],
[[atomic_fetch_add(&x, 1);
if ((intptr_t)(atomic_load(&x)) == sizeof(foo_t)) { return 0; }
return 1;]] )],
Expand Down
7 changes: 4 additions & 3 deletions examples/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ get_fill_value(uint64_t i)
}

void *
fill_array(void *unused)
fill_array(void * unused)
{
(void)unused;
uint64_t i;

for (i = 0; i < NUM_ITERS; i++) {
Expand Down Expand Up @@ -96,8 +97,8 @@ main(void)
sum2 += (item & MASK);
}

printf("Expected sum: %lld\n", sum1);
printf("Computed sum: %lld\n", sum2);
printf("Expected sum: %ld\n", sum1);
printf("Computed sum: %ld\n", sum2);

return 0;
}
16 changes: 8 additions & 8 deletions examples/hashable.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ dict_example(int argc, ex_str_t *argv[])

if (!hatrack_dict_add(dict, s, (void *)i)) {
fprintf(stderr,
"Detected duplicate argument at argv[%lld]: %s\n",
(long long)i,
"Detected duplicate argument at argv[%ld]: %s\n",
i,
argv[i]->bytes);
}
else {
Expand All @@ -218,7 +218,7 @@ dict_example(int argc, ex_str_t *argv[])

for (i = 0; i < num; i++) {
s = (ex_str_t *)items[i].key;
printf("%s (@ arg #%lld)\n", s->bytes, (long long)items[i].value);
printf("%s (@ arg #%ld)\n", s->bytes, (long)items[i].value);

printf("decref %s from view since we're done w/ it (@%p)\n",
s->bytes,
Expand Down Expand Up @@ -263,18 +263,18 @@ set_example(int argc, ex_str_t *argv[])
s = argv[i];

if (s->hv) {
printf("Found cached hash value: %016llx%016llx\n",
(long long)(s->hv & 0xffffffffffffffff),
(long long)(s->hv >> 64));
printf("Found cached hash value: %016lx%016lx\n",
(long)(s->hv & 0xffffffffffffffff),
(long)(s->hv >> 64));
}
else {
printf("Uh-oh, didn't find a cached hash value :-(\n");
}

if (!hatrack_set_add(set, s)) {
fprintf(stderr,
"Detected duplicate argument at argv[%lld]: %s\n",
(long long)i,
"Detected duplicate argument at argv[%ld]: %s\n",
(long)i,
argv[i]->bytes);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions examples/logringex.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ output_logs(void)
view = logring_view(ring, false);

while (logring_dequeue(ring, &log, &len)) {
printf("tid=%llu; mid=%llu; msg=%s\n", log.tid, log.mid, log.msg);
printf("tid=%lu; mid=%lu; msg=%s\n", log.tid, log.mid, log.msg);
}

printf("----------------------------\n");

while ((msg = (log_msg_t *)logring_view_next(view, &len))) {
printf("tid=%llu; mid=%llu; msg=%s\n", msg->tid, msg->mid, msg->msg);
printf("tid=%lu; mid=%lu; msg=%s\n", msg->tid, msg->mid, msg->msg);
free(msg);
}

Expand Down
14 changes: 7 additions & 7 deletions examples/old_queue_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ time_diff(struct timespec *end, struct timespec *start)
}

static struct timespec stop_times[HATRACK_THREADS_MAX];
static basic_gate_t starting_gate = ATOMIC_VAR_INIT(0);
static basic_gate_t starting_gate = 0;
static queue_t *mt_queue;

static void
Expand Down Expand Up @@ -148,10 +148,10 @@ multi_threaded_v1(int num_threads)
}

fprintf(stderr,
"mt1(%d threads): %.4f sec; Ops/sec: %llu\n",
"mt1(%d threads): %.4f sec; Ops/sec: %lu\n",
num_threads,
max,
(unsigned long long)((2 * (double)TOTAL_ENQUEUES) / max));
(unsigned long)((2 * (double)TOTAL_ENQUEUES) / max));

return;
}
Expand Down Expand Up @@ -183,9 +183,9 @@ single_threaded_v1(void)

diff = time_diff(&stop_time, &start_time);

printf("Test 1: %.4f sec; Ops/sec: %llu\n",
printf("Test 1: %.4f sec; Ops/sec: %lu\n",
diff,
(unsigned long long)(((double)(TOTAL_ENQUEUES * 2)) / diff));
(unsigned long)(((double)(TOTAL_ENQUEUES * 2)) / diff));

queue_delete(queue);

Expand Down Expand Up @@ -216,9 +216,9 @@ single_threaded_v2(void)

diff = time_diff(&stop_time, &start_time);

printf("Test 2: %.4f sec; Ops/sec: %llu\n",
printf("Test 2: %.4f sec; Ops/sec: %lu\n",
diff,
(unsigned long long)(((double)(TOTAL_ENQUEUES * 2)) / diff));
(unsigned long)(((double)(TOTAL_ENQUEUES * 2)) / diff));

queue_delete(queue);

Expand Down
6 changes: 3 additions & 3 deletions examples/qperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ test_queue(test_info_t *test_info)
err = false;

fprintf(stdout,
"%8s, prealloc = %c, # threads = %2llu, bundle size = %2llu -> ",
"%8s, prealloc = %c, # threads = %2lu, bundle size = %2lu -> ",
test_info->implementation->name,
test_info->prealloc ? 'Y' : 'N',
test_info->num_threads,
Expand Down Expand Up @@ -265,8 +265,8 @@ format_results(test_info_t *tests, int num_tests, int row_size)
}
printf("%-13s", tests[i].implementation->name);
printf("%-12s", tests[i].prealloc ? "yes" : "no");
printf("%-12llu", tests[i].num_threads);
printf("%-12llu", tests[i].enqueues_per_bundle);
printf("%-12lu", tests[i].num_threads);
printf("%-12lu", tests[i].enqueues_per_bundle);
printf("%-.4f\n", (tests[i].num_ops / tests[i].elapsed) / 1000000);
}
}
Expand Down
14 changes: 7 additions & 7 deletions examples/qtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ test_queue(test_info_t *test_info)
err = false;

fprintf(stdout,
"%8s, prealloc = %c, # enqueuers = %2llu, # dequeuers = %2llu -> ",
"%8s, prealloc = %c, # enqueuers = %2lu, # dequeuers = %2lu -> ",
test_info->implementation->name,
test_info->prealloc ? 'Y' : 'N',
test_info->producers,
Expand Down Expand Up @@ -316,8 +316,8 @@ test_queue(test_info_t *test_info)

if (write_total != read_total) {
fprintf(stdout,
"\n Error: enqueue total (%llu) != dequeue total (%llu); "
"diff = %llu\n",
"\n Error: enqueue total (%lu) != dequeue total (%lu); "
"diff = %lu\n",
write_total,
read_total,
write_total > read_total ?
Expand All @@ -329,13 +329,13 @@ test_queue(test_info_t *test_info)

if (num_ops != successful_dequeues) {
fprintf(stdout,
"\n Error: # enqueues (%llu) != # dequeues (%llu)\n",
"\n Error: # enqueues (%lu) != # dequeues (%lu)\n",
num_ops,
successful_dequeues);
err = true;
}

fprintf(stdout, "nil dequeue()s: %-9llu ", failed_dequeues);
fprintf(stdout, "nil dequeue()s: %-9lu ", failed_dequeues);

test_info->elapsed = max;
test_info->num_ops = (num_ops * 2);
Expand Down Expand Up @@ -366,8 +366,8 @@ format_results(test_info_t *tests, int num_tests, int row_size)
}
printf("%-13s", tests[i].implementation->name);
printf("%-12s", tests[i].prealloc ? "yes" : "no");
printf("%-12llu", tests[i].producers);
printf("%-12llu", tests[i].consumers);
printf("%-12lu", tests[i].producers);
printf("%-12lu", tests[i].consumers);
printf("%-.4f\n", (tests[i].num_ops / tests[i].elapsed) / 1000000);
}
}
Expand Down
16 changes: 8 additions & 8 deletions examples/ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ run_one_ring_test(uint64_t enqueuers, uint64_t dequeuers, uint64_t ring_size)
{
uint64_t i;
uint64_t ops_per_thread;
uint64_t total_ops;
// uint64_t total_ops;
thread_info_t *info;
double max;

fprintf(stdout,
"#e= %2llu, #d= %2llu, sz= %05llu -> ",
"#e= %2lu, #d= %2lu, sz= %05lu -> ",
enqueuers,
dequeuers,
ring_size);
Expand All @@ -150,7 +150,7 @@ run_one_ring_test(uint64_t enqueuers, uint64_t dequeuers, uint64_t ring_size)

ring = hatring_new(ring_size);
ops_per_thread = num_ops / enqueuers;
total_ops = num_ops * enqueuers;
// total_ops = num_ops * enqueuers;

#ifdef CONSISTENCY_CHECK
hatring_set_drop_handler(ring, handle_eject);
Expand Down Expand Up @@ -187,9 +187,9 @@ run_one_ring_test(uint64_t enqueuers, uint64_t dequeuers, uint64_t ring_size)
max = gate_close(gate);
hatring_delete(ring);

fprintf(stdout, "Qs=%llu; ", num_ops);
fprintf(stdout, "DQs=%llu; ", successful_dequeues);
fprintf(stdout, "(⊥=%llu in ", failed_dequeues);
fprintf(stdout, "Qs=%lu; ", num_ops);
fprintf(stdout, "DQs=%lu; ", successful_dequeues);
fprintf(stdout, "(⊥=%lu in ", failed_dequeues);
fprintf(stdout, "%.3f sec ", max);
fprintf(stdout, "(%.3f MOp/s, ",
(((double)(num_ops + successful_dequeues))/1000000.) / max);
Expand All @@ -200,8 +200,8 @@ run_one_ring_test(uint64_t enqueuers, uint64_t dequeuers, uint64_t ring_size)

#ifdef CONSISTENCY_CHECK
fprintf(stdout,
"pushed value: %llu; dq + eject: %llu; "
"diff: %lld\n",
"pushed value: %lu; dq + eject: %lu; "
"diff: %ld\n",
enqueue_result,
dequeue_result + eject_result,
enqueue_result - (dequeue_result + eject_result)
Expand Down
2 changes: 1 addition & 1 deletion examples/set1.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ dec_output_int64_t(int64_t n, FILE *f)

#else

#define dec_outf(n, f) fprintf(f, "%lld", (long long)n);
#define dec_outf(n, f) fprintf(f, "%ld", (long long)n);

#endif

Expand Down
2 changes: 1 addition & 1 deletion include/hatrack/counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#ifndef __COUNTERS_H__
#define __COUNTERS_H__

#include <hatrack_config.h>
#include <hatrack/hatrack_config.h>

#include <stdint.h>
#include <stdalign.h>
Expand Down
4 changes: 2 additions & 2 deletions include/hatrack/gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#ifndef __GATE_H__
#define __GATE_H__

#include <mmm.h>
#include <hatrack/mmm.h>
#include <strings.h>

typedef struct {
Expand Down Expand Up @@ -65,7 +65,7 @@ gate_init(gate_t *gate, uint64_t max_threads)
bzero(gate->end_times, sizeof(struct timespec) * max_threads);

gate->max_threads = max_threads;
gate->count = ATOMIC_VAR_INIT(0);
gate->count = 0;
gate->elapsed_time = 0;

return;
Expand Down
2 changes: 1 addition & 1 deletion src/hash/ballcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ballcap_init_size(ballcap_t *self, char size)

len = 1 << size;
store = ballcap_store_new(len);
self->item_count = ATOMIC_VAR_INIT(0);
self->item_count = 0;
self->store_current = store;

pthread_mutex_init(&self->migrate_mutex, NULL);
Expand Down
4 changes: 2 additions & 2 deletions src/hash/newshat.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ newshat_init_size(newshat_t *self, char size)

len = 1 << size;
store = newshat_store_new(len);
self->item_count = ATOMIC_VAR_INIT(0);
self->next_epoch = ATOMIC_VAR_INIT(1); // 0 is for empty buckets.
self->item_count = 0;
self->next_epoch = 1; // 0 is for empty buckets.
self->store_current = store;

pthread_mutex_init(&self->migrate_mutex, NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/queue/capq.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ capq_init_size(capq_t *self, uint64_t size)
}

self->store = capq_new_store(size);
self->len = ATOMIC_VAR_INIT(0);
self->len = 0;

self->store->dequeue_index = ATOMIC_VAR_INIT(1L<<32);
self->store->enqueue_index = ATOMIC_VAR_INIT(1L<<32);
self->store->dequeue_index = 1L<<32;
self->store->enqueue_index = 1L<<32;

return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/queue/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

hatrack_debug_record_t __hatrack_debug[HATRACK_DEBUG_RING_SIZE] = {};

_Atomic uint64_t __hatrack_debug_sequence = ATOMIC_VAR_INIT(0);
_Atomic uint64_t __hatrack_debug_sequence = 0;
const char __hatrack_hex_conversion_table[] = "0123456789abcdef";

/* debug_dump()
Expand Down
6 changes: 3 additions & 3 deletions src/queue/hq.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ hq_init_size(hq_t *self, uint64_t size)
}

self->store = hq_new_store(size);
self->len = ATOMIC_VAR_INIT(0);
self->len = 0;

self->store->dequeue_index = ATOMIC_VAR_INIT(size);
self->store->enqueue_index = ATOMIC_VAR_INIT(size);
self->store->dequeue_index = size;
self->store->enqueue_index = size;

return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/queue/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ queue_enqueue(queue_t *self, void *item)
}

new_segment = queue_new_segment(new_size);
new_segment->enqueue_index = ATOMIC_VAR_INIT(1);
new_segment->enqueue_index = 1;
expected_segment = NULL;

atomic_store(&new_segment->cells[0], candidate);
Expand Down
2 changes: 1 addition & 1 deletion src/queue/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ hatstack_new_store(uint64_t num_cells)
alloc_len = sizeof(stack_store_t) + num_cells * sizeof(stack_cell_t);
ret = (stack_store_t *)mmm_alloc_committed(alloc_len);
ret->num_cells = num_cells;
ret->head_state = ATOMIC_VAR_INIT(head_candidate_new_epoch(0, 0));
ret->head_state = head_candidate_new_epoch(0, 0);

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/support/mmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// clang-format off
__thread mmm_header_t *mmm_retire_list = NULL;
__thread pthread_once_t mmm_inited = PTHREAD_ONCE_INIT;
_Atomic uint64_t mmm_epoch = ATOMIC_VAR_INIT(HATRACK_EPOCH_FIRST);
_Atomic uint64_t mmm_nexttid = ATOMIC_VAR_INIT(0);
_Atomic uint64_t mmm_epoch = HATRACK_EPOCH_FIRST;
_Atomic uint64_t mmm_nexttid = 0;
__thread int64_t mmm_mytid = -1;
__thread uint64_t mmm_retire_ctr = 0;

Expand Down
2 changes: 1 addition & 1 deletion tests/performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static uint32_t key_mod_mask;
* readiness, and then wait for a signal from the controller thread
* that all threads are ready, and that they should start!
*/
static basic_gate_t starting_gate = ATOMIC_VAR_INIT(0);
static basic_gate_t starting_gate = 0;

/*
* The table for the current test.
Expand Down

0 comments on commit 168089e

Please sign in to comment.