18c2ecf20Sopenharmony_ci=======================
28c2ecf20Sopenharmony_ciIRQ-flags state tracing
38c2ecf20Sopenharmony_ci=======================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci:Author: started by Ingo Molnar <mingo@redhat.com>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciThe "irq-flags tracing" feature "traces" hardirq and softirq state, in
88c2ecf20Sopenharmony_cithat it gives interested subsystems an opportunity to be notified of
98c2ecf20Sopenharmony_cievery hardirqs-off/hardirqs-on, softirqs-off/softirqs-on event that
108c2ecf20Sopenharmony_cihappens in the kernel.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciCONFIG_TRACE_IRQFLAGS_SUPPORT is needed for CONFIG_PROVE_SPIN_LOCKING
138c2ecf20Sopenharmony_ciand CONFIG_PROVE_RW_LOCKING to be offered by the generic lock debugging
148c2ecf20Sopenharmony_cicode. Otherwise only CONFIG_PROVE_MUTEX_LOCKING and
158c2ecf20Sopenharmony_ciCONFIG_PROVE_RWSEM_LOCKING will be offered on an architecture - these
168c2ecf20Sopenharmony_ciare locking APIs that are not used in IRQ context. (the one exception
178c2ecf20Sopenharmony_cifor rwsems is worked around)
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciArchitecture support for this is certainly not in the "trivial"
208c2ecf20Sopenharmony_cicategory, because lots of lowlevel assembly code deal with irq-flags
218c2ecf20Sopenharmony_cistate changes. But an architecture can be irq-flags-tracing enabled in a
228c2ecf20Sopenharmony_cirather straightforward and risk-free manner.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciArchitectures that want to support this need to do a couple of
258c2ecf20Sopenharmony_cicode-organizational changes first:
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci- add and enable TRACE_IRQFLAGS_SUPPORT in their arch level Kconfig file
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciand then a couple of functional changes are needed as well to implement
308c2ecf20Sopenharmony_ciirq-flags-tracing support:
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci- in lowlevel entry code add (build-conditional) calls to the
338c2ecf20Sopenharmony_ci  trace_hardirqs_off()/trace_hardirqs_on() functions. The lock validator
348c2ecf20Sopenharmony_ci  closely guards whether the 'real' irq-flags matches the 'virtual'
358c2ecf20Sopenharmony_ci  irq-flags state, and complains loudly (and turns itself off) if the
368c2ecf20Sopenharmony_ci  two do not match. Usually most of the time for arch support for
378c2ecf20Sopenharmony_ci  irq-flags-tracing is spent in this state: look at the lockdep
388c2ecf20Sopenharmony_ci  complaint, try to figure out the assembly code we did not cover yet,
398c2ecf20Sopenharmony_ci  fix and repeat. Once the system has booted up and works without a
408c2ecf20Sopenharmony_ci  lockdep complaint in the irq-flags-tracing functions arch support is
418c2ecf20Sopenharmony_ci  complete.
428c2ecf20Sopenharmony_ci- if the architecture has non-maskable interrupts then those need to be
438c2ecf20Sopenharmony_ci  excluded from the irq-tracing [and lock validation] mechanism via
448c2ecf20Sopenharmony_ci  lockdep_off()/lockdep_on().
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciIn general there is no risk from having an incomplete irq-flags-tracing
478c2ecf20Sopenharmony_ciimplementation in an architecture: lockdep will detect that and will
488c2ecf20Sopenharmony_citurn itself off. I.e. the lock validator will still be reliable. There
498c2ecf20Sopenharmony_cishould be no crashes due to irq-tracing bugs. (except if the assembly
508c2ecf20Sopenharmony_cichanges break other code by modifying conditions or registers that
518c2ecf20Sopenharmony_cishouldn't be)
528c2ecf20Sopenharmony_ci
53