Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion regressions/ck_barrier/benchmark/throughput.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <ck_pr.h>
#include <ck_barrier.h>
Expand Down Expand Up @@ -99,10 +100,12 @@ main(int argc, char *argv[])
ck_error("ERROR: Could not allocate thread structures\n");
}

counters = calloc(sizeof(struct counter), nthr);
counters = common_aligned_alloc(common_alignof(struct counter),
sizeof(*counters) * nthr);
if (counters == NULL) {
ck_error("ERROR: Could not allocate counters\n");
}
memset(counters, 0, sizeof(*counters) * nthr);

a.delta = atoi(argv[2]);

Expand Down
6 changes: 4 additions & 2 deletions regressions/ck_barrier/validate/barrier_combining.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ main(int argc, char *argv[])
ck_barrier_combining_group_t *init_root;
int i;

init_root = malloc(sizeof(ck_barrier_combining_group_t));
init_root = common_aligned_alloc(common_alignof(ck_barrier_combining_group_t),
sizeof(ck_barrier_combining_group_t));
if (init_root == NULL) {
ck_error("ERROR: Could not allocate initial barrier structure\n");
}
Expand All @@ -110,7 +111,8 @@ main(int argc, char *argv[])
ck_error("ERROR: Number of threads must be greater than 0\n");
}

groupings = malloc(sizeof(ck_barrier_combining_group_t) * ngroups);
groupings = common_aligned_alloc(common_alignof(ck_barrier_combining_group_t),
sizeof(ck_barrier_combining_group_t) * ngroups);
if (groupings == NULL) {
ck_error("Could not allocate thread barrier grouping structures\n");
}
Expand Down
6 changes: 4 additions & 2 deletions regressions/ck_cohort/benchmark/throughput.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ main(int argc, char *argv[])
ck_error("ERROR: Could not allocate thread structures\n");
}

cohorts = malloc(sizeof(struct cohort_record) * n_cohorts);
cohorts = common_aligned_alloc(common_alignof(struct cohort_record),
sizeof(struct cohort_record) * n_cohorts);
if (cohorts == NULL) {
ck_error("ERROR: Could not allocate cohort structures\n");
}
Expand All @@ -185,7 +186,8 @@ main(int argc, char *argv[])
a.delta = atoi(argv[2]);
a.request = 0;

count = malloc(sizeof(*count) * nthr);
count = common_aligned_alloc(common_alignof(struct counters),
sizeof(struct counters) * nthr);
if (count == NULL) {
ck_error("ERROR: Could not create acquisition buffer\n");
}
Expand Down
6 changes: 4 additions & 2 deletions regressions/ck_epoch/validate/ck_epoch_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ read_thread(void *unused CK_CC_UNUSED)
ck_epoch_record_t *record CK_CC_CACHELINE;
ck_stack_entry_t *cursor, *n;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
if (record == NULL)
ck_error("record allocation failure");

Expand Down Expand Up @@ -348,7 +349,8 @@ write_thread(void *unused CK_CC_UNUSED)
ck_epoch_record_t *record;
ck_stack_entry_t *s;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
if (record == NULL)
ck_error("record allocation failure");
ck_epoch_register(&stack_epoch, record, NULL);
Expand Down
6 changes: 4 additions & 2 deletions regressions/ck_epoch/validate/ck_epoch_section_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ read_thread(void *unused CK_CC_UNUSED)
*/
ck_epoch_section_t section[2];

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
assert(record != NULL);
ck_epoch_register(&epoch, record, NULL);

Expand Down Expand Up @@ -162,7 +163,8 @@ write_thread(void *unused CK_CC_UNUSED)
ck_epoch_record_t *record;
unsigned long iterations = 0;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
if (record == NULL)
ck_error("record allocation failure");

Expand Down
6 changes: 4 additions & 2 deletions regressions/ck_epoch/validate/ck_epoch_synchronize.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ read_thread(void *unused CK_CC_UNUSED)
ck_stack_entry_t *n;
unsigned int i;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
if (record == NULL)
ck_error("record allocation failure");
ck_epoch_register(&stack_epoch, record, NULL);
Expand Down Expand Up @@ -151,7 +152,8 @@ write_thread(void *unused CK_CC_UNUSED)
ck_epoch_record_t *record;
ck_stack_entry_t *s;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
if (record == NULL)
ck_error("record allocation failure");
ck_epoch_register(&stack_epoch, record, NULL);
Expand Down
6 changes: 4 additions & 2 deletions regressions/ck_epoch/validate/torture.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ read_thread(void *unused CK_CC_UNUSED)
{
ck_epoch_record_t *record;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
assert(record != NULL);
ck_epoch_register(&epoch, record, NULL);

Expand Down Expand Up @@ -149,7 +150,8 @@ write_thread(void *unused CK_CC_UNUSED)
bool c = ck_pr_faa_uint(&first, 1);
uint64_t ac = 0;

record = malloc(sizeof *record);
record = common_aligned_alloc(common_alignof(ck_epoch_record_t),
sizeof(ck_epoch_record_t));
assert(record != NULL);
ck_epoch_register(&epoch, record, NULL);

Expand Down
22 changes: 16 additions & 6 deletions regressions/ck_fifo/validate/ck_fifo_mpmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ test(void *c)

for (i = 0; i < ITERATIONS; i++) {
for (j = 0; j < size; j++) {
fifo_entry = malloc(sizeof(ck_fifo_mpmc_entry_t));
fifo_entry = common_aligned_alloc(
common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t));
entry = malloc(sizeof(struct entry));
entry->tid = context->tid;
ck_fifo_mpmc_enqueue(&fifo, fifo_entry, entry);
Expand All @@ -93,7 +95,9 @@ test(void *c)

for (i = 0; i < ITERATIONS; i++) {
for (j = 0; j < size; j++) {
fifo_entry = malloc(sizeof(ck_fifo_mpmc_entry_t));
fifo_entry = common_aligned_alloc(
common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t));
entry = malloc(sizeof(struct entry));
entry->tid = context->tid;
while (ck_fifo_mpmc_tryenqueue(&fifo, fifo_entry, entry) == false)
Expand Down Expand Up @@ -187,12 +191,16 @@ main(int argc, char *argv[])
thread = malloc(sizeof(pthread_t) * nthr);
assert(thread);

ck_fifo_mpmc_init(&fifo, malloc(sizeof(ck_fifo_mpmc_entry_t)));
ck_fifo_mpmc_init(&fifo,
common_aligned_alloc(common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t)));
ck_fifo_mpmc_deinit(&fifo, &garbage);
if (garbage == NULL)
ck_error("ERROR: Expected non-NULL stub node on deinit.\n");
free(garbage);
ck_fifo_mpmc_init(&fifo, malloc(sizeof(ck_fifo_mpmc_entry_t)));
common_aligned_free(garbage);
ck_fifo_mpmc_init(&fifo,
common_aligned_alloc(common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t)));

for (i = 0; i < nthr; i++) {
context[i].tid = i;
Expand All @@ -210,7 +218,9 @@ main(int argc, char *argv[])
assert(entry != NULL);
entry->tid = 0;
ck_fifo_mpmc_enqueue(&fifo,
malloc(sizeof(ck_fifo_mpmc_entry_t)), entry);
common_aligned_alloc(common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t)),
entry);
}

ck_pr_store_uint(&barrier, 0);
Expand Down
12 changes: 8 additions & 4 deletions regressions/ck_fifo/validate/ck_fifo_mpmc_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <stdlib.h>
#include <stdio.h>

#include "../../common.h"

#ifdef CK_F_FIFO_MPMC
struct example {
int x;
Expand All @@ -43,13 +45,15 @@ main(void)
struct example *examples;
ck_fifo_mpmc_entry_t *stub, *entries, *entry, *next;

stub = malloc(sizeof(ck_fifo_mpmc_entry_t));
stub = common_aligned_alloc(common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t));
if (stub == NULL)
exit(EXIT_FAILURE);

ck_fifo_mpmc_init(&mpmc_fifo, stub);

entries = malloc(sizeof(ck_fifo_mpmc_entry_t) * length);
entries = common_aligned_alloc(common_alignof(ck_fifo_mpmc_entry_t),
sizeof(ck_fifo_mpmc_entry_t) * length);
if (entries == NULL)
exit(EXIT_FAILURE);

Expand All @@ -76,8 +80,8 @@ main(void)
}

free(examples);
free(entries);
free(stub);
common_aligned_free(entries);
common_aligned_free(stub);

return (0);
}
Expand Down
3 changes: 2 additions & 1 deletion regressions/ck_hp/validate/ck_hp_fifo_donner.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ queue_50_50(void *elements)
unsigned long j, element_count = *(unsigned long *)elements;
unsigned int seed;

record = malloc(sizeof(ck_hp_record_t));
record = common_aligned_alloc(common_alignof(ck_hp_record_t),
sizeof(ck_hp_record_t));
assert(record);

slots = malloc(CK_HP_FIFO_SLOTS_SIZE);
Expand Down
3 changes: 2 additions & 1 deletion regressions/ck_rwcohort/benchmark/throughput.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ main(int argc, char *argv[])
ck_error("ERROR: Could not allocate thread structures\n");
}

cohorts = malloc(sizeof(struct cohort_record) * n_cohorts);
cohorts = common_aligned_alloc(common_alignof(struct cohort_record),
sizeof(struct cohort_record) * n_cohorts);
if (cohorts == NULL) {
ck_error("ERROR: Could not allocate cohort structures\n");
}
Expand Down
3 changes: 2 additions & 1 deletion regressions/ck_spinlock/benchmark/throughput.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ main(int argc, char *argv[])
a.delta = atoi(argv[2]);
a.request = 0;

count = malloc(sizeof(*count) * nthr);
count = common_aligned_alloc(common_alignof(struct counters),
sizeof(struct counters) * nthr);
if (count == NULL) {
ck_error("ERROR: Could not create acquisition buffer\n");
exit(EXIT_FAILURE);
Expand Down
3 changes: 2 additions & 1 deletion regressions/ck_stack/validate/pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ main(int argc, char *argv[])
affinerator.request = 0;
affinerator.delta = d;

bucket = malloc(sizeof(struct entry) * nthr);
bucket = common_aligned_alloc(common_alignof(struct entry),
sizeof(struct entry) * nthr);
assert(bucket != NULL);

thread = malloc(sizeof(pthread_t) * nthr);
Expand Down
31 changes: 31 additions & 0 deletions regressions/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

#if defined(_WIN32)
#include <assert.h>
#include <malloc.h>
#define NOMINMAX
#include <windows.h>
#define DELTA_EPOCH 11644473600000000ULL
Expand Down Expand Up @@ -267,6 +268,36 @@ prefix##_common_win_alarm(void *unused) \
#define COMMON_ALARM_INIT(prefix, alarm_event_name, duration)
#endif

#define common_alignof(T) __alignof__(T)

/*
* Modelled after C11's aligned_alloc. However, these allocations must be freed
* with common_aligned_free(), not free().
*/
CK_CC_INLINE static void *
common_aligned_alloc(size_t alignment, size_t size)
{
#ifdef _WIN32
return _aligned_malloc(size, alignment);
#else
void *p;
if (posix_memalign(&p, alignment, size) != 0) {
return NULL;
}
return p;
#endif
}

CK_CC_INLINE static void
common_aligned_free(void *p)
{
#ifdef _WIN32
_aligned_free(p);
#else
free(p);
#endif
}

struct affinity {
unsigned int delta;
unsigned int request;
Expand Down
Loading