--- zzzz-none-000/linux-4.4.271/arch/arm/include/asm/spinlock.h 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/arch/arm/include/asm/spinlock.h 2023-04-19 10:22:27.000000000 +0000 @@ -5,6 +5,41 @@ #error SMP not supported on pre-ARMv6 CPUs #endif +/*--------------------------------------------------------------------------------*\ +\*--------------------------------------------------------------------------------*/ +#if defined(CONFIG_ENABLE_SPINLOCK_PROFILING_HOOKS) +extern int avm_simple_profiling_is_enabled_func(void); +extern unsigned int avm_get_cycles_func(void); + +#define avm_simple_profiling_spin_lock(lock) ({ \ + if(avm_simple_profiling_is_enabled_func()) { \ + unsigned int avm_simple_profiling_spinlock_endtime = avm_get_cycles_func(); \ + __avm_simple_profiling_spinlock(_RET_IP_, (unsigned int)lock, avm_simple_profiling_spinlock_endtime - avm_simple_profiling_spinlock_starttime, 0); \ + } \ +}) + +#define avm_simple_profiling_spin_trylock(lock, success) ({ \ + if(avm_simple_profiling_is_enabled_func()) { \ + __avm_simple_profiling_spinlock(_RET_IP_, (unsigned int)lock, 0, success ? 1 : 2); \ + } \ +}) + +#define avm_simple_profiling_spin_unlock(lock) ({ \ + if(avm_simple_profiling_is_enabled_func()) { \ + __avm_simple_profiling_spinlock(_RET_IP_, (unsigned int)lock, 0, 3); \ + } \ +}) + +#define avm_simple_profiling_spin_gettime() unsigned int avm_simple_profiling_spinlock_starttime = avm_get_cycles_func() + +extern void __avm_simple_profiling_spinlock(unsigned int addr, unsigned int lock, unsigned int time, unsigned int id); + +#else +static inline void avm_simple_profiling_spin_lock(void *lock __attribute__ ((unused))) { }; +static inline void avm_simple_profiling_spin_trylock(void *lock __attribute__ ((unused)), unsigned int success __attribute__ ((unused))) { }; +static inline void avm_simple_profiling_spin_unlock(void *lock __attribute__ ((unused))) { }; +static inline unsigned int avm_simple_profiling_spin_gettime(void) { return 0; } +#endif #include /* @@ -61,6 +96,7 @@ u32 newval; arch_spinlock_t lockval; + avm_simple_profiling_spin_gettime(); prefetchw(&lock->slock); __asm__ __volatile__( "1: ldrex %0, [%3]\n" @@ -78,6 +114,7 @@ } smp_mb(); + avm_simple_profiling_spin_lock(lock); } static inline int arch_spin_trylock(arch_spinlock_t *lock) @@ -97,7 +134,7 @@ : "r" (&lock->slock), "I" (1 << TICKET_SHIFT) : "cc"); } while (res); - + avm_simple_profiling_spin_trylock(lock, contended); if (!contended) { smp_mb(); return 1; @@ -109,6 +146,8 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock) { smp_mb(); + + avm_simple_profiling_spin_unlock(lock); lock->tickets.owner++; dsb_sev(); }