spinlock/hclh: Strictly follow the algorithm instead of taking shortcuts.

Don't attempt to be to smart, and just follow the algorithm, failing to
do so may lead to getting a thread to wrongly believe it owns the lock
when it does not.
This should fix the random failures reported on PPC with many threads.
awsm
Olivier Houchard 6 years ago
parent 5ff2e9d3e6
commit 0881349657

@ -81,6 +81,8 @@ ck_spinlock_hclh_lock(struct ck_spinlock_hclh **glob_queue,
thread->wait = true; thread->wait = true;
thread->splice = false; thread->splice = false;
thread->cluster_id = (*local_queue)->cluster_id; thread->cluster_id = (*local_queue)->cluster_id;
/* Make sure previous->previous doesn't appear to be NULL */
thread->previous = *local_queue;
/* Serialize with respect to update of local queue. */ /* Serialize with respect to update of local queue. */
ck_pr_fence_store_atomic(); ck_pr_fence_store_atomic();
@ -91,13 +93,15 @@ ck_spinlock_hclh_lock(struct ck_spinlock_hclh **glob_queue,
/* Wait until previous thread from the local queue is done with lock. */ /* Wait until previous thread from the local queue is done with lock. */
ck_pr_fence_load(); ck_pr_fence_load();
if (previous->previous != NULL && if (previous->previous != NULL) {
previous->cluster_id == thread->cluster_id) { while (ck_pr_load_uint(&previous->wait) == true &&
while (ck_pr_load_uint(&previous->wait) == true) ck_pr_load_int(&previous->cluster_id) == thread->cluster_id &&
ck_pr_load_uint(&previous->splice) == false)
ck_pr_stall(); ck_pr_stall();
/* We're head of the global queue, we're done */ /* We're head of the global queue, we're done */
if (ck_pr_load_uint(&previous->splice) == false) if (ck_pr_load_int(&previous->cluster_id) == thread->cluster_id &&
ck_pr_load_uint(&previous->splice) == false)
return; return;
} }

Loading…
Cancel
Save