From c45098b21bae75c8f3efff3b5c9a0c49daf3cf34 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Mon, 10 Sep 2012 17:06:47 -0400 Subject: [PATCH] ck_epoch: Emit fence instructions for TSO, do not emit for recursive calls. Unfortunately, there are still workloads which will not serialize. Recursive calls into ck_epoch_begin have no need for fence instructions. --- include/ck_epoch.h | 11 ++++++++++- src/ck_epoch.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/ck_epoch.h b/include/ck_epoch.h index ce4af9f..1b7d1b5 100644 --- a/include/ck_epoch.h +++ b/include/ck_epoch.h @@ -93,11 +93,20 @@ ck_epoch_begin(ck_epoch_t *epoch, ck_epoch_record_t *record) */ if (record->active == 0) { unsigned int g_epoch = ck_pr_load_uint(&epoch->epoch); + + /* + * It is possible for loads to be re-ordered before the store + * is committed into the caller's epoch and active fields. + * Execute a full barrier to serialize stores with respect to + * loads + */ ck_pr_store_uint(&record->epoch, g_epoch); + ck_pr_store_uint(&record->active, 1); + ck_pr_fence_strict_memory(); + return; } ck_pr_store_uint(&record->active, record->active + 1); - ck_pr_fence_memory(); return; } diff --git a/src/ck_epoch.c b/src/ck_epoch.c index 64426d9..706d1e8 100644 --- a/src/ck_epoch.c +++ b/src/ck_epoch.c @@ -294,7 +294,7 @@ ck_epoch_barrier(struct ck_epoch *global, struct ck_epoch_record *record) * Guarantee any mutations previous to the barrier will be made visible * with respect to epoch snapshots we will read. */ - ck_pr_fence_memory(); + ck_pr_fence_strict_memory(); for (i = 0, cr = NULL; i < CK_EPOCH_GRACE - 1; cr = NULL, i++) { /*