From 5414d68161dba3afc379b0047637a82d6ed9a38e Mon Sep 17 00:00:00 2001 From: "Masatoshi.Tateishi" Date: Thu, 21 Dec 2017 13:26:22 +0900 Subject: [PATCH 1/2] arch/arm/src/lc823450: Add SP_DMB() into lc823450_testset.c In lc823450, ldrex and strex are not supported. So we implemented up_testset() with H/W Mutex. However, there was a bug in memory access order. This change ensures correct memory access order in up_testset() for lc823450. Signed-off-by: Masayuki Ishikawa --- arch/arm/src/lc823450/lc823450_testset.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm/src/lc823450/lc823450_testset.c b/arch/arm/src/lc823450/lc823450_testset.c index 2093b42f40..826150285e 100644 --- a/arch/arm/src/lc823450/lc823450_testset.c +++ b/arch/arm/src/lc823450/lc823450_testset.c @@ -95,12 +95,15 @@ spinlock_t up_testset(volatile FAR spinlock_t *lock) } while (getreg32(MUTEX_REG_MUTEX0) != val); + SP_DMB(); + ret = *lock; if (ret == SP_UNLOCKED) { *lock = SP_LOCKED; } + SP_DMB(); val = (up_cpu_index() << 16) | 0x0; putreg32(val, MUTEX_REG_MUTEX0); From e1f71f988b4e8733c0c0139135d8f50d6e548183 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 21 Dec 2017 17:26:36 +0900 Subject: [PATCH 2/2] sched/semaphore/spinlock.c: Add memory barrier operations in spin_unlock() In ARM document regarding memory barrires, SP_DMB() must be issued before changing a spinlock state to SP_UNLOCKED. However, we found that SP_DSB() is also needed to ensure that spin_unlock() works correctly for network streaming aging test. Signed-off-by: Masayuki Ishikawa --- sched/semaphore/spinlock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sched/semaphore/spinlock.c b/sched/semaphore/spinlock.c index fc46f05aae..674ebb6b52 100644 --- a/sched/semaphore/spinlock.c +++ b/sched/semaphore/spinlock.c @@ -165,8 +165,9 @@ void spin_unlock(FAR volatile spinlock_t *lock) sched_note_spinunlock(this_task(), lock); #endif - *lock = SP_UNLOCKED; SP_DMB(); + *lock = SP_UNLOCKED; + SP_DSB(); } #endif