Skip to content

Commit

Permalink
ck_epoch: introduce ck_epoch_deferred
Browse files Browse the repository at this point in the history
Allow for deferral to occur outside epoch poll critical loop (which may access per-CPU structures).
  • Loading branch information
mattmacy authored and sbahra committed May 17, 2018
1 parent 9587bbb commit deca119
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/ck_epoch.h
Expand Up @@ -266,6 +266,7 @@ void ck_epoch_register(ck_epoch_t *, ck_epoch_record_t *, void *);
void ck_epoch_unregister(ck_epoch_record_t *);

bool ck_epoch_poll(ck_epoch_record_t *);
bool ck_epoch_poll_deferred(struct ck_epoch_record *record, ck_stack_t *deferred);
void ck_epoch_synchronize(ck_epoch_record_t *);
void ck_epoch_synchronize_wait(ck_epoch_t *, ck_epoch_wait_cb_t *, void *);
void ck_epoch_barrier(ck_epoch_record_t *);
Expand Down
22 changes: 16 additions & 6 deletions src/ck_epoch.c
Expand Up @@ -349,7 +349,7 @@ ck_epoch_scan(struct ck_epoch *global,
}

static void
ck_epoch_dispatch(struct ck_epoch_record *record, unsigned int e)
ck_epoch_dispatch(struct ck_epoch_record *record, unsigned int e, ck_stack_t *deferred)
{
unsigned int epoch = e & (CK_EPOCH_LENGTH - 1);
ck_stack_entry_t *head, *next, *cursor;
Expand All @@ -362,7 +362,10 @@ ck_epoch_dispatch(struct ck_epoch_record *record, unsigned int e)
ck_epoch_entry_container(cursor);

next = CK_STACK_NEXT(cursor);
entry->function(entry);
if (deferred != NULL)
ck_stack_push_spnc(deferred, &entry->stack_entry);
else
entry->function(entry);
i++;
}

Expand Down Expand Up @@ -390,7 +393,7 @@ ck_epoch_reclaim(struct ck_epoch_record *record)
unsigned int epoch;

for (epoch = 0; epoch < CK_EPOCH_LENGTH; epoch++)
ck_epoch_dispatch(record, epoch);
ck_epoch_dispatch(record, epoch, NULL);

return;
}
Expand Down Expand Up @@ -551,7 +554,7 @@ ck_epoch_barrier_wait(struct ck_epoch_record *record, ck_epoch_wait_cb_t *cb,
* is far from ideal too.
*/
bool
ck_epoch_poll(struct ck_epoch_record *record)
ck_epoch_poll_deferred(struct ck_epoch_record *record, ck_stack_t *deferred)
{
bool active;
unsigned int epoch;
Expand All @@ -572,14 +575,21 @@ ck_epoch_poll(struct ck_epoch_record *record)
if (active == false) {
record->epoch = epoch;
for (epoch = 0; epoch < CK_EPOCH_LENGTH; epoch++)
ck_epoch_dispatch(record, epoch);
ck_epoch_dispatch(record, epoch, deferred);

return true;
}

/* If an active thread exists, rely on epoch observation. */
(void)ck_pr_cas_uint(&global->epoch, epoch, epoch + 1);

ck_epoch_dispatch(record, epoch + 1);
ck_epoch_dispatch(record, epoch + 1, deferred);
return true;
}

bool
ck_epoch_poll(struct ck_epoch_record *record)
{

return ck_epoch_poll_deferred(record, NULL);
}

0 comments on commit deca119

Please sign in to comment.