Re: [PATCH v2 15/20] rv: Convert the opid monitor to a hybrid automaton
From: Nam Cao
Date: Fri Oct 10 2025 - 10:29:25 EST
Gabriele Monaco <gmonaco@xxxxxxxxxx> writes:
> - | sched_need_resched
> - | sched_waking
> - | irq_entry
> - | +--------------------+
> - v v |
> - +------------------------------------------------------+
> - +----------- | disabled | <+
> - | +------------------------------------------------------+ |
> - | | ^ |
> - | | preempt_disable sched_need_resched |
> - | preempt_enable | +--------------------+ |
> - | v | v | |
> - | +------------------------------------------------------+ |
> - | | irq_disabled | |
> - | +------------------------------------------------------+ |
> - | | | ^ |
> - | irq_entry irq_entry | | |
> - | sched_need_resched v | irq_disable |
> - | sched_waking +--------------+ | | |
> - | +----- | | irq_enable | |
> - | | | in_irq | | | |
> - | +----> | | | | |
> - | +--------------+ | | irq_disable
> - | | | | |
> - | irq_enable | irq_enable | | |
> - | v v | |
> - | #======================================================# |
> - | H enabled H |
> - | #======================================================# |
> - | | ^ ^ preempt_enable | |
> - | preempt_disable preempt_enable +--------------------+ |
> - | v | |
> - | +------------------+ | |
> - +----------> | preempt_disabled | -+ |
> - +------------------+ |
> - | |
> - +-------------------------------------------------------+
> -
> +
> + |
> + |
> + v
> + #=========# sched_need_resched;irq_off == 1
> + H H sched_waking;irq_off == 1 && preempt_off == 1
> + H any H ------------------------------------------------+
> + H H |
> + H H <-----------------------------------------------+
> + #=========#
Nice!
> + * If CONFIG_PREEMPTION is enabled, then the tracepoint itself disables
> + * preemption (adding one to the preempt_count). Since we are
> + * interested in the preempt_count at the time the tracepoint was
> + * hit, we consider 1 as still enabled.
> + */
> + if (IS_ENABLED(CONFIG_PREEMPTION))
> + return (preempt_count() & PREEMPT_MASK) > 1;
FYI, there is plan to keep preemption enabled during tracepoint
handling. So keep that in mind when this monitor breaks.
Nam