kernel: fix arch_mem_coherent() call in spinlock

The call to arch_mem_coherent() inside spinlock.h
when spinlock validation and memory coherence enabled
is causing build error as spinlock.h does not include
kernel_arch_func.h directly. However, simply including
that file does not work either as this creates
the chicken-or-egg in the chain of include files.
In order to make spin validation work with kernel
coherence enabled, a separate function is created
to break the circular dependencies of include files.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2021-02-02 16:35:15 -08:00 committed by Anas Nashif
commit d1495e98e2
2 changed files with 14 additions and 1 deletions

View file

@ -66,6 +66,11 @@ bool z_spin_lock_valid(struct k_spinlock *l);
bool z_spin_unlock_valid(struct k_spinlock *l); bool z_spin_unlock_valid(struct k_spinlock *l);
void z_spin_lock_set_owner(struct k_spinlock *l); void z_spin_lock_set_owner(struct k_spinlock *l);
BUILD_ASSERT(CONFIG_MP_NUM_CPUS <= 4, "Too many CPUs for mask"); BUILD_ASSERT(CONFIG_MP_NUM_CPUS <= 4, "Too many CPUs for mask");
# ifdef CONFIG_KERNEL_COHERENCE
bool z_spin_lock_mem_coherent(struct k_spinlock *l);
# endif /* CONFIG_KERNEL_COHERENCE */
#endif /* CONFIG_SPIN_VALIDATE */ #endif /* CONFIG_SPIN_VALIDATE */
/** /**
@ -123,7 +128,7 @@ static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
#ifdef CONFIG_SPIN_VALIDATE #ifdef CONFIG_SPIN_VALIDATE
__ASSERT(z_spin_lock_valid(l), "Recursive spinlock %p", l); __ASSERT(z_spin_lock_valid(l), "Recursive spinlock %p", l);
# ifdef KERNEL_COHERENCE # ifdef KERNEL_COHERENCE
__ASSERT_NO_MSG(arch_mem_coherent(l)); __ASSERT_NO_MSG(z_spin_lock_mem_coherent(l));
# endif # endif
#endif #endif

View file

@ -883,6 +883,14 @@ void z_spin_lock_set_owner(struct k_spinlock *l)
{ {
l->thread_cpu = _current_cpu->id | (uintptr_t)_current; l->thread_cpu = _current_cpu->id | (uintptr_t)_current;
} }
#ifdef CONFIG_KERNEL_COHERENCE
bool z_spin_lock_mem_coherent(struct k_spinlock *l)
{
return arch_mem_coherent((void *)l);
}
#endif /* CONFIG_KERNEL_COHERENCE */
#endif /* CONFIG_SPIN_VALIDATE */ #endif /* CONFIG_SPIN_VALIDATE */
int z_impl_k_float_disable(struct k_thread *thread) int z_impl_k_float_disable(struct k_thread *thread)