162306a36Sopenharmony_ci======================= 262306a36Sopenharmony_ciIRQ-flags state tracing 362306a36Sopenharmony_ci======================= 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci:Author: started by Ingo Molnar <mingo@redhat.com> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciThe "irq-flags tracing" feature "traces" hardirq and softirq state, in 862306a36Sopenharmony_cithat it gives interested subsystems an opportunity to be notified of 962306a36Sopenharmony_cievery hardirqs-off/hardirqs-on, softirqs-off/softirqs-on event that 1062306a36Sopenharmony_cihappens in the kernel. 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciCONFIG_TRACE_IRQFLAGS_SUPPORT is needed for CONFIG_PROVE_SPIN_LOCKING 1362306a36Sopenharmony_ciand CONFIG_PROVE_RW_LOCKING to be offered by the generic lock debugging 1462306a36Sopenharmony_cicode. Otherwise only CONFIG_PROVE_MUTEX_LOCKING and 1562306a36Sopenharmony_ciCONFIG_PROVE_RWSEM_LOCKING will be offered on an architecture - these 1662306a36Sopenharmony_ciare locking APIs that are not used in IRQ context. (the one exception 1762306a36Sopenharmony_cifor rwsems is worked around) 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciArchitecture support for this is certainly not in the "trivial" 2062306a36Sopenharmony_cicategory, because lots of lowlevel assembly code deal with irq-flags 2162306a36Sopenharmony_cistate changes. But an architecture can be irq-flags-tracing enabled in a 2262306a36Sopenharmony_cirather straightforward and risk-free manner. 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciArchitectures that want to support this need to do a couple of 2562306a36Sopenharmony_cicode-organizational changes first: 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci- add and enable TRACE_IRQFLAGS_SUPPORT in their arch level Kconfig file 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciand then a couple of functional changes are needed as well to implement 3062306a36Sopenharmony_ciirq-flags-tracing support: 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci- in lowlevel entry code add (build-conditional) calls to the 3362306a36Sopenharmony_ci trace_hardirqs_off()/trace_hardirqs_on() functions. The lock validator 3462306a36Sopenharmony_ci closely guards whether the 'real' irq-flags matches the 'virtual' 3562306a36Sopenharmony_ci irq-flags state, and complains loudly (and turns itself off) if the 3662306a36Sopenharmony_ci two do not match. Usually most of the time for arch support for 3762306a36Sopenharmony_ci irq-flags-tracing is spent in this state: look at the lockdep 3862306a36Sopenharmony_ci complaint, try to figure out the assembly code we did not cover yet, 3962306a36Sopenharmony_ci fix and repeat. Once the system has booted up and works without a 4062306a36Sopenharmony_ci lockdep complaint in the irq-flags-tracing functions arch support is 4162306a36Sopenharmony_ci complete. 4262306a36Sopenharmony_ci- if the architecture has non-maskable interrupts then those need to be 4362306a36Sopenharmony_ci excluded from the irq-tracing [and lock validation] mechanism via 4462306a36Sopenharmony_ci lockdep_off()/lockdep_on(). 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciIn general there is no risk from having an incomplete irq-flags-tracing 4762306a36Sopenharmony_ciimplementation in an architecture: lockdep will detect that and will 4862306a36Sopenharmony_citurn itself off. I.e. the lock validator will still be reliable. There 4962306a36Sopenharmony_cishould be no crashes due to irq-tracing bugs. (except if the assembly 5062306a36Sopenharmony_cichanges break other code by modifying conditions or registers that 5162306a36Sopenharmony_cishouldn't be) 5262306a36Sopenharmony_ci 53