forked from amir/filehasher
Align the MPMC queue to pagesize
This commit is contained in:
16
lf_mpmc.h
16
lf_mpmc.h
@@ -58,15 +58,13 @@ typedef struct {
|
||||
/* INIT */
|
||||
/* ----------------------------------------------------------- */
|
||||
static void mpmc_init(MPMCQueue *q, size_t max_capacity) {
|
||||
if ((max_capacity & (max_capacity - 1)) != 0) {
|
||||
fprintf(stderr, "capacity must be power of two\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
q->capacity = max_capacity;
|
||||
q->mask = max_capacity - 1;
|
||||
|
||||
size_t bytes = sizeof(MPMCSlot) * max_capacity;
|
||||
u32 pagesize = plat_get_pagesize();
|
||||
|
||||
size_t bytes = ALIGN_UP_POW2(sizeof(MPMCSlot) * max_capacity, pagesize);
|
||||
|
||||
q->slots = (MPMCSlot *)plat_mem_reserve(bytes);
|
||||
|
||||
@@ -75,12 +73,16 @@ static void mpmc_init(MPMCQueue *q, size_t max_capacity) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
q->commit_step = (64ull * 1024 * 1024) / sizeof(MPMCSlot);
|
||||
u64 commit_bytes = pagesize;
|
||||
commit_bytes = ALIGN_UP_POW2(commit_bytes, pagesize);
|
||||
|
||||
q->commit_step = commit_bytes / sizeof(MPMCSlot);
|
||||
|
||||
atomic_flag_clear(&q->commit_lock);
|
||||
|
||||
q->committed = q->commit_step;
|
||||
|
||||
plat_mem_commit(q->slots, q->commit_step * sizeof(MPMCSlot));
|
||||
plat_mem_commit(q->slots, commit_bytes);
|
||||
|
||||
for (size_t i = 0; i < q->committed; i++) {
|
||||
atomic_init(&q->slots[i].seq, i);
|
||||
|
||||
Reference in New Issue
Block a user