Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: fix amp hang issue #6623

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions os/arch/arm/src/armv7-a/arm_cpupause.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@ int up_cpu_paused_save(void)

int up_cpu_paused(int cpu)
{
/* Ensure the CPU has been resumed to avoid causing a deadlock */

spin_lock(&g_cpu_resumed[cpu]);
gSahitya-samsung marked this conversation as resolved.
Show resolved Hide resolved

/* Release the g_cpu_paused spinlock to synchronize with the
* requesting CPU.
*/

spin_unlock(&g_cpu_paused[cpu]);

/* Ensure the CPU has been resumed to avoid causing a deadlock */

spin_lock(&g_cpu_resumed[cpu]);

/* Wait for the spinlock to be released. The requesting CPU will release
* the spinlock when the CPU is resumed.
Expand Down
36 changes: 35 additions & 1 deletion os/include/tinyara/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,46 @@ typedef uint8_t spinlock_t;
# define __SP_UNLOCK_FUNCTION 1
#endif

# define spin_is_locked(l) (*(l) == SP_LOCKED)

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

/****************************************************************************
* Name: spin_is_locked
*
* Description:
* check whether spinlock is locked or not.
*
* Input Parameters:
* lock - A reference to the spinlock object.
*
* Returned Value:
* true - if spin is locked
* false - otherwise
*
****************************************************************************/

inline bool spin_is_locked(volatile FAR spinlock_t *lock)
{
/* In multicore env, there is a possibility that up_cpu_pausereq will be
* FALSE in the CPU serving this ISR due to out-of-order memory ops in ARM.
* This can happen when Store operation in up_cpu_pause on the spinlock
* with spin_lock(&g_cpu_paused[cpu]) is observed AFTER the Load operation
* in the below IF condition is checked, this results in an "impossible"
* condition where g_cpu_paused[1] is '1' in CPU0 and g_cpu_paused[1] is
* '0' in CPU1
*
* While the spinlock may be protected with DSB/DMB already, it may not be
* broadcasted to a different core such as the one serving this ISR. Thus,
* we need to ensure latest copy of the lock after Store is observed.
*
* This instruction does not affect operation with only 1 CPU
*/
SP_DMB();
return (*(lock) == SP_LOCKED);
}

/****************************************************************************
* Name: up_testset
*
Expand Down
4 changes: 2 additions & 2 deletions os/kernel/irq/irq_csection.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static bool irq_waitlock(int cpu)
* for the deadlock condition.
*/

while (spin_trylock_wo_note(&g_cpu_irqlock) == SP_LOCKED) {
do {
/* Is a pause request pending? */

if (up_cpu_pausereq(cpu) || up_get_gating_flag_status(cpu) == 1) {
Expand All @@ -136,7 +136,7 @@ static bool irq_waitlock(int cpu)

return false;
}
}
} while(spin_trylock_wo_note(&g_cpu_irqlock) == SP_LOCKED);

/* We have g_cpu_irqlock! */

Expand Down