fix: cleanup lock API

main
Sean McBride 4 years ago
parent 69aa03d68f
commit bf6b5d3c61

@ -24,24 +24,23 @@ typedef ck_spinlock_mcs_t lock_t;
/** /**
* Locks a lock, keeping track of overhead * Locks a lock, keeping track of overhead
* @param lock - the address of the lock * @param lock - the address of the lock
* @param hygienic_prefix - a unique prefix to hygienically namespace an associated lock/unlock pair * @param unique_variable_name - a unique prefix to hygienically namespace an associated lock/unlock pair
*/ */
#define LOCK_LOCK_WITH_BOOKKEEPING(lock, hygienic_prefix) \ #define LOCK_LOCK_WITH_BOOKKEEPING(lock, unique_variable_name) \
bool hygienic_prefix##_is_interruptable = software_interrupt_is_enabled(); \ assert(!runtime_is_worker() || !software_interrupt_is_enabled()); \
if (hygienic_prefix##_is_interruptable) software_interrupt_disable(); \ struct ck_spinlock_mcs unique_variable_name##_node; \
struct ck_spinlock_mcs hygienic_prefix##_node; \ uint64_t unique_variable_name##_pre = __getcycles(); \
uint64_t hygienic_prefix##_pre = __getcycles(); \ ck_spinlock_mcs_lock((lock), &(unique_variable_name##_node)); \
ck_spinlock_mcs_lock((lock), &(hygienic_prefix##_node)); \ worker_thread_lock_duration += (__getcycles() - unique_variable_name##_pre);
worker_thread_lock_duration += (__getcycles() - hygienic_prefix##_pre);
/** /**
* Unlocks a lock * Unlocks a lock
* @param lock - the address of the lock * @param lock - the address of the lock
* @param hygienic_prefix - a unique prefix to hygienically namespace an associated lock/unlock pair * @param unique_variable_name - a unique prefix to hygienically namespace an associated lock/unlock pair
*/ */
#define LOCK_UNLOCK_WITH_BOOKKEEPING(lock, hygienic_prefix) \ #define LOCK_UNLOCK_WITH_BOOKKEEPING(lock, unique_variable_name) \
ck_spinlock_mcs_unlock(lock, &(hygienic_prefix##_node)); \ assert(!runtime_is_worker() || !software_interrupt_is_enabled()); \
if (hygienic_prefix##_is_interruptable) software_interrupt_enable(); ck_spinlock_mcs_unlock(lock, &(unique_variable_name##_node));
/** /**
* Locks a lock, keeping track of overhead * Locks a lock, keeping track of overhead

@ -217,7 +217,9 @@ void
local_runqueue_minheap_initialize() local_runqueue_minheap_initialize()
{ {
/* Initialize local state */ /* Initialize local state */
software_interrupt_disable();
priority_queue_initialize(&local_runqueue_minheap, sandbox_get_priority); priority_queue_initialize(&local_runqueue_minheap, sandbox_get_priority);
software_interrupt_enable();
/* Register Function Pointers for Abstract Scheduling API */ /* Register Function Pointers for Abstract Scheduling API */
struct local_runqueue_config config = { .add_fn = local_runqueue_minheap_add, struct local_runqueue_config config = { .add_fn = local_runqueue_minheap_add,

@ -22,6 +22,8 @@ static inline int
priority_queue_append(struct priority_queue *self, void *new_item) priority_queue_append(struct priority_queue *self, void *new_item)
{ {
assert(self != NULL); assert(self != NULL);
assert(new_item != NULL);
assert(LOCK_IS_LOCKED(&self->lock)); assert(LOCK_IS_LOCKED(&self->lock));
int rc; int rc;
@ -105,6 +107,8 @@ priority_queue_percolate_down(struct priority_queue *self, int parent_index)
assert(self != NULL); assert(self != NULL);
assert(self->get_priority_fn != NULL); assert(self->get_priority_fn != NULL);
assert(LOCK_IS_LOCKED(&self->lock)); assert(LOCK_IS_LOCKED(&self->lock));
assert(runtime_is_worker());
assert(!software_interrupt_is_enabled());
int left_child_index = 2 * parent_index; int left_child_index = 2 * parent_index;
while (left_child_index >= 2 && left_child_index < self->first_free) { while (left_child_index >= 2 && left_child_index < self->first_free) {
@ -133,6 +137,8 @@ priority_queue_is_empty_locked(struct priority_queue *self)
{ {
assert(self != NULL); assert(self != NULL);
assert(LOCK_IS_LOCKED(&self->lock)); assert(LOCK_IS_LOCKED(&self->lock));
assert(!runtime_is_worker() || !software_interrupt_is_enabled());
return self->first_free == 1; return self->first_free == 1;
} }
@ -150,6 +156,7 @@ priority_queue_initialize(struct priority_queue *self, priority_queue_get_priori
{ {
assert(self != NULL); assert(self != NULL);
assert(get_priority_fn != NULL); assert(get_priority_fn != NULL);
assert(!runtime_is_worker() || !software_interrupt_is_enabled());
memset(self->items, 0, sizeof(void *) * MAX); memset(self->items, 0, sizeof(void *) * MAX);
@ -169,6 +176,8 @@ int
priority_queue_length(struct priority_queue *self) priority_queue_length(struct priority_queue *self)
{ {
assert(self != NULL); assert(self != NULL);
assert(runtime_is_worker());
assert(!software_interrupt_is_enabled());
LOCK_LOCK(&self->lock); LOCK_LOCK(&self->lock);
int length = self->first_free - 1; int length = self->first_free - 1;
@ -185,6 +194,8 @@ int
priority_queue_enqueue(struct priority_queue *self, void *value) priority_queue_enqueue(struct priority_queue *self, void *value)
{ {
assert(self != NULL); assert(self != NULL);
assert(value != NULL);
assert(!runtime_is_worker() || !software_interrupt_is_enabled());
int rc; int rc;
@ -218,6 +229,9 @@ int
priority_queue_delete(struct priority_queue *self, void *value) priority_queue_delete(struct priority_queue *self, void *value)
{ {
assert(self != NULL); assert(self != NULL);
assert(value != NULL);
assert(runtime_is_worker());
assert(!software_interrupt_is_enabled());
LOCK_LOCK(&self->lock); LOCK_LOCK(&self->lock);
@ -260,6 +274,8 @@ priority_queue_dequeue_if_earlier(struct priority_queue *self, void **dequeued_e
assert(self != NULL); assert(self != NULL);
assert(dequeued_element != NULL); assert(dequeued_element != NULL);
assert(self->get_priority_fn != NULL); assert(self->get_priority_fn != NULL);
assert(runtime_is_worker());
assert(!software_interrupt_is_enabled());
int return_code; int return_code;
@ -303,6 +319,8 @@ priority_queue_top(struct priority_queue *self, void **dequeued_element)
assert(self != NULL); assert(self != NULL);
assert(dequeued_element != NULL); assert(dequeued_element != NULL);
assert(self->get_priority_fn != NULL); assert(self->get_priority_fn != NULL);
assert(runtime_is_worker());
assert(!software_interrupt_is_enabled());
int return_code; int return_code;

Loading…
Cancel
Save