From 84d47c358b1d07b9155474d7075e082c52147ebc Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Fri, 16 Aug 2019 20:02:37 +0200 Subject: Replace some barrier()s with local atomic fences --- kern/thread.c | 4 +++- kern/thread.h | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/kern/thread.c b/kern/thread.c index 71943c04..0bad0752 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -96,6 +96,7 @@ #include #include #include +#include #include #include #include @@ -674,7 +675,9 @@ thread_runq_schedule(struct thread_runq *runq) * and locking the run queue again is equivalent to a full memory * barrier. */ + latomic_fence(LATOMIC_ACQ_REL); tcb_switch(&prev->tcb, &next->tcb); + latomic_fence(LATOMIC_ACQ_REL); /* * The thread is dispatched on a processor once again. @@ -685,7 +688,6 @@ thread_runq_schedule(struct thread_runq *runq) * referenced any more. * - The current thread may have been migrated to another processor. */ - barrier(); thread_runq_schedule_load(prev); next = NULL; diff --git a/kern/thread.h b/kern/thread.h index 0c8c1014..d77b35f3 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -548,7 +549,7 @@ thread_pin(void) thread = thread_self(); thread->pin_level++; assert(thread->pin_level != 0); - barrier(); + latomic_fence(LATOMIC_ACQ_REL); } /* @@ -561,7 +562,7 @@ thread_unpin(void) { struct thread *thread; - barrier(); + latomic_fence(LATOMIC_ACQ_REL); thread = thread_self(); assert(thread->pin_level != 0); thread->pin_level--; @@ -595,7 +596,7 @@ thread_preempt_disable(void) thread = thread_self(); thread->preempt_level++; assert(thread->preempt_level != 0); - barrier(); + latomic_fence(LATOMIC_ACQ_REL); } /* @@ -613,7 +614,7 @@ thread_preempt_enable_no_resched(void) { struct thread *thread; - barrier(); + latomic_fence(LATOMIC_ACQ_REL); thread = thread_self(); assert(thread->preempt_level != 0); thread->preempt_level--; @@ -713,7 +714,7 @@ thread_intr_enter(void) thread->intr_level++; assert(thread->intr_level != 0); - barrier(); + latomic_fence(LATOMIC_ACQ_REL); } /* @@ -726,7 +727,7 @@ thread_intr_leave(void) { struct thread *thread; - barrier(); + latomic_fence(LATOMIC_ACQ_REL); thread = thread_self(); assert(thread->intr_level != 0); thread->intr_level--; -- cgit v1.2.3