diff --git a/arch/arm64/kernel/cpu.c b/arch/arm64/kernel/cpu.c index f9f933c6..1450743e 100644 --- a/arch/arm64/kernel/cpu.c +++ b/arch/arm64/kernel/cpu.c @@ -869,6 +869,21 @@ unsigned long cpu_enable_interrupt_save(void) return flags; } +#ifdef ENABLE_FUGAKU_HACKS +int cpu_interrupt_disabled(void) +{ + unsigned long flags; + unsigned long masked = ICC_PMR_EL1_MASKED; + + asm volatile( + "mrs_s %0, " __stringify(ICC_PMR_EL1) + : "=&r" (flags) + : + : "memory"); + return (flags == masked); +} +#endif + #else /* defined(CONFIG_HAS_NMI) */ /* @ref.impl arch/arm64/include/asm/irqflags.h::arch_local_irq_enable */ diff --git a/arch/arm64/kernel/include/arch-lock.h b/arch/arm64/kernel/include/arch-lock.h index a9f7c339..1291f379 100644 --- a/arch/arm64/kernel/include/arch-lock.h +++ b/arch/arm64/kernel/include/arch-lock.h @@ -9,6 +9,9 @@ #include "affinity.h" #include #include "config.h" +#ifdef ENABLE_FUGAKU_HACKS +#include +#endif //#define DEBUG_SPINLOCK //#define DEBUG_MCS_RWLOCK @@ -31,6 +34,10 @@ typedef struct { #endif /* __AARCH64EB__ */ } __attribute__((aligned(4))) ihk_spinlock_t; +#ifdef ENABLE_FUGAKU_HACKS +extern ihk_spinlock_t *get_this_cpu_runq_lock(void); +#endif + extern void preempt_enable(void); extern void preempt_disable(void); @@ -98,6 +105,18 @@ static int __ihk_mc_spinlock_trylock_noirq(ihk_spinlock_t *lock) : "memory"); success = !tmp; + +#ifdef ENABLE_FUGAKU_HACKS +#if 0 + if (success) { + if (get_this_cpu_runq_lock() == lock && + !cpu_interrupt_disabled()) { + kprintf("%s: WARNING: runq lock held without IRQs disabled?\n", __func__); \ + } + } +#endif +#endif + if (!success) { preempt_enable(); } @@ -182,6 +201,14 @@ static void __ihk_mc_spinlock_lock_noirq(ihk_spinlock_t *lock) : "=&r" (lockval), "=&r" (newval), "=&r" (tmp), "+Q" (*lock) : "Q" (lock->owner), "I" (1 << TICKET_SHIFT) : "memory"); +#ifdef ENABLE_FUGAKU_HACKS +#if 0 + if (get_this_cpu_runq_lock() == lock && + !cpu_interrupt_disabled()) { + kprintf("%s: WARNING: runq lock held without IRQs disabled?\n", __func__); \ + } +#endif +#endif } #ifdef DEBUG_SPINLOCK diff --git a/kernel/cls.c b/kernel/cls.c index 7771497c..ca5bb1b5 100644 --- a/kernel/cls.c +++ b/kernel/cls.c @@ -120,3 +120,10 @@ void do_backlog(void) } } } + +#ifdef ENABLE_FUGAKU_HACKS +ihk_spinlock_t *get_this_cpu_runq_lock(void) +{ + return &get_this_cpu_local_var()->runq_lock; +} +#endif diff --git a/lib/include/ihk/cpu.h b/lib/include/ihk/cpu.h index 7a1e499e..10ebc7ba 100644 --- a/lib/include/ihk/cpu.h +++ b/lib/include/ihk/cpu.h @@ -23,6 +23,9 @@ extern int num_processors; void cpu_enable_interrupt(void); void cpu_disable_interrupt(void); +#ifdef ENABLE_FUGAKU_HACKS +int cpu_interrupt_disabled(void); +#endif void cpu_halt(void); #ifdef ENABLE_FUGAKU_HACKS void cpu_halt_panic(void);