8sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget*/translations/zh_CN/trace/rv/monitor_schedmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/zh_TW/trace/rv/monitor_schedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/it_IT/trace/rv/monitor_schedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/ja_JP/trace/rv/monitor_schedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/ko_KR/trace/rv/monitor_schedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/sp_SP/trace/rv/monitor_schedmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hScheduler monitorsh]hScheduler monitors}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhD/var/lib/git/docbuild/linux/Documentation/trace/rv/monitor_sched.rsthKubh bullet_list)}(hhh](h list_item)}(h Name: schedh]h paragraph)}(hhh]h Name: sched}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h%Type: container for multiple monitorsh]h)}(hhh]h%Type: container for multiple monitors}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h^Author: Gabriele Monaco , Daniel Bristot de Oliveira h]h)}(h]Author: Gabriele Monaco , Daniel Bristot de Oliveira h](hAuthor: Gabriele Monaco <}(hhhhhNhNubh reference)}(hgmonaco@redhat.comh]hgmonaco@redhat.com}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:gmonaco@redhat.comuh1hhhubh>, Daniel Bristot de Oliveira <}(hhhhhNhNubh)}(hbristot@kernel.orgh]hbristot@kernel.org}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:bristot@kernel.orguh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1hhhhKhhhhubh)}(hhh](h)}(h Descriptionh]h Description}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj8hhhhhK ubh)}(hXMonitors describing complex systems, such as the scheduler, can easily grow to the point where they are just hard to understand because of the many possible state transitions. Often it is possible to break such descriptions into smaller monitors, sharing some or all events. Enabling those smaller monitors concurrently is, in fact, testing the system as if we had one single larger monitor. Splitting models into multiple specification is not only easier to understand, but gives some more clues when we see errors.h]hXMonitors describing complex systems, such as the scheduler, can easily grow to the point where they are just hard to understand because of the many possible state transitions. Often it is possible to break such descriptions into smaller monitors, sharing some or all events. Enabling those smaller monitors concurrently is, in fact, testing the system as if we had one single larger monitor. Splitting models into multiple specification is not only easier to understand, but gives some more clues when we see errors.}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj8hhubh)}(hThe sched monitor is a set of specifications to describe the scheduler behaviour. It includes several per-cpu and per-task monitors that work independently to verify different specifications the scheduler should follow.h]hThe sched monitor is a set of specifications to describe the scheduler behaviour. It includes several per-cpu and per-task monitors that work independently to verify different specifications the scheduler should follow.}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj8hhubh)}(hXkTo make this system as straightforward as possible, sched specifications are *nested* monitors, whereas sched itself is a *container*. From the interface perspective, sched includes other monitors as sub-directories, enabling/disabling or setting reactors to sched, propagates the change to all monitors, however single monitors can be used independently as well.h](hMTo make this system as straightforward as possible, sched specifications are }(hjehhhNhNubhemphasis)}(h*nested*h]hnested}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1jmhjeubh% monitors, whereas sched itself is a }(hjehhhNhNubjn)}(h *container*h]h container}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jmhjeubh. From the interface perspective, sched includes other monitors as sub-directories, enabling/disabling or setting reactors to sched, propagates the change to all monitors, however single monitors can be used independently as well.}(hjehhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj8hhubh)}(hIt is important that future modules are built after their container (sched, in this case), otherwise the linker would not respect the order and the nesting wouldn't work as expected. To do so, simply add them after sched in the Makefile.h]hIt is important that future modules are built after their container (sched, in this case), otherwise the linker would not respect the order and the nesting wouldn’t work as expected. To do so, simply add them after sched in the Makefile.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj8hhubeh}(h] descriptionah ]h"] descriptionah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hSpecificationsh]hSpecifications}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK$ubh)}(h}The specifications included in sched are currently a work in progress, adapting the ones defined in by Daniel Bristot in [1].h]h}The specifications included in sched are currently a work in progress, adapting the ones defined in by Daniel Bristot in [1].}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjhhubh)}(h$Currently we included the following:h]h$Currently we included the following:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hjhhubh)}(hhh](h)}(h Monitor scoh]h Monitor sco}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK,ubh)}(hoThe scheduling context operations (sco) monitor ensures changes in a task state happen only in thread context::h]hnThe scheduling context operations (sco) monitor ensures changes in a task state happen only in thread context:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjhhubh literal_block)}(hX | | v sched_set_state +------------------+ +------------------ | | | | thread_context | +-----------------> | | <+ +------------------+ | | | | schedule_entry | schedule_exit v | | scheduling_context -+h]hX | | v sched_set_state +------------------+ +------------------ | | | | thread_context | +-----------------> | | <+ +------------------+ | | | | schedule_entry | schedule_exit v | | scheduling_context -+}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhK2hjhhubeh}(h] monitor-scoah ]h"] monitor scoah$]h&]uh1hhjhhhhhK,ubh)}(hhh](h)}(h Monitor snroch]h Monitor snroc}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKAubh)}(hThe set non runnable on its own context (snroc) monitor ensures changes in a task state happens only in the respective task's context. This is a per-task monitor::h]hThe set non runnable on its own context (snroc) monitor ensures changes in a task state happens only in the respective task’s context. This is a per-task monitor:}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjhhubj)}(hX  | | v +------------------+ | other_context | <+ +------------------+ | | | | sched_switch_in | sched_switch_out v | sched_set_state | +------------------ | | own_context | +-----------------> -+h]hX  | | v +------------------+ | other_context | <+ +------------------+ | | | | sched_switch_in | sched_switch_out v | sched_set_state | +------------------ | | own_context | +-----------------> -+}hj4sbah}(h]h ]h"]h$]h&]j j uh1jhhhKGhjhhubeh}(h] monitor-snrocah ]h"] monitor snrocah$]h&]uh1hhjhhhhhKAubh)}(hhh](h)}(h Monitor scpdh]h Monitor scpd}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJhhhhhKVubh)}(hqThe schedule called with preemption disabled (scpd) monitor ensures schedule is called with preemption disabled::h]hpThe schedule called with preemption disabled (scpd) monitor ensures schedule is called with preemption disabled:}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhjJhhubj)}(hX) | | v +------------------+ | cant_sched | <+ +------------------+ | | | | preempt_disable | preempt_enable v | schedule_entry | schedule_exit | +----------------- can_sched | | | +----------------> -+h]hX) | | v +------------------+ | cant_sched | <+ +------------------+ | | | | preempt_disable | preempt_enable v | schedule_entry | schedule_exit | +----------------- can_sched | | | +----------------> -+}hjisbah}(h]h ]h"]h$]h&]j j uh1jhhhK[hjJhhubeh}(h] monitor-scpdah ]h"] monitor scpdah$]h&]uh1hhjhhhhhKVubh)}(hhh](h)}(h Monitor sneph]h Monitor snep}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKkubh)}(hhThe schedule does not enable preempt (snep) monitor ensures a schedule call does not enable preemption::h]hgThe schedule does not enable preempt (snep) monitor ensures a schedule call does not enable preemption:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKmhjhhubj)}(hXo | | v preempt_disable +------------------------+ preempt_enable | | +------------------ | non_scheduling_context | | | | +-----------------> | | <+ +------------------------+ | | | | schedule_entry | schedule_exit v | | scheduling_contex -+h]hXo | | v preempt_disable +------------------------+ preempt_enable | | +------------------ | non_scheduling_context | | | | +-----------------> | | <+ +------------------------+ | | | | schedule_entry | schedule_exit v | | scheduling_contex -+}hjsbah}(h]h ]h"]h$]h&]j j uh1jhhhKphjhhubeh}(h] monitor-snepah ]h"] monitor snepah$]h&]uh1hhjhhhhhKkubh)}(hhh](h)}(h Monitor stsh]h Monitor sts}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXThe schedule implies task switch (sts) monitor ensures a task switch happens only in scheduling context and up to once, as well as scheduling occurs with interrupts enabled but no task switch can happen before interrupts are disabled. When the next task picked for execution is the same as the previously running one, no real task switch occurs but interrupts are disabled nonetheless::h]hXThe schedule implies task switch (sts) monitor ensures a task switch happens only in scheduling context and up to once, as well as scheduling occurs with interrupts enabled but no task switch can happen before interrupts are disabled. When the next task picked for execution is the same as the previously running one, no real task switch occurs but interrupts are disabled nonetheless:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX irq_entry | +----+ | v | v +------------+ irq_enable #===================# irq_disable | | ------------> H H irq_entry | cant_sched | <------------ H H irq_enable | | irq_disable H can_sched H --------------+ +------------+ H H | H H | +---------------> H H <-------------+ | #===================# | | schedule_exit | schedule_entry | v | +-------------------+ irq_enable | | scheduling | <---------------+ | +-------------------+ | | | | | | irq_disable +--------+ irq_entry | v | | --------+ | +-------------------+ irq_entry | in_irq | | | | | -----------> | | <-------+ | | disable_to_switch | +--------+ | | | --+ | +-------------------+ | | | | | | sched_switch | | v | | +-------------------+ | | | switching | | irq_enable | +-------------------+ | | | | | | irq_enable | | v | | +-------------------+ | +-- | enable_to_exit | <-+ +-------------------+ ^ | irq_disable | | irq_entry +---------------+ irq_enableh]hX irq_entry | +----+ | v | v +------------+ irq_enable #===================# irq_disable | | ------------> H H irq_entry | cant_sched | <------------ H H irq_enable | | irq_disable H can_sched H --------------+ +------------+ H H | H H | +---------------> H H <-------------+ | #===================# | | schedule_exit | schedule_entry | v | +-------------------+ irq_enable | | scheduling | <---------------+ | +-------------------+ | | | | | | irq_disable +--------+ irq_entry | v | | --------+ | +-------------------+ irq_entry | in_irq | | | | | -----------> | | <-------+ | | disable_to_switch | +--------+ | | | --+ | +-------------------+ | | | | | | sched_switch | | v | | +-------------------+ | | | switching | | irq_enable | +-------------------+ | | | | | | irq_enable | | v | | +-------------------+ | +-- | enable_to_exit | <-+ +-------------------+ ^ | irq_disable | | irq_entry +---------------+ irq_enable}hjsbah}(h]h ]h"]h$]h&]j j uh1jhhhKhjhhubeh}(h] monitor-stsah ]h"] monitor stsah$]h&]uh1hhjhhhhhKubeh}(h]specificationsah ]h"]specificationsah$]h&]uh1hhhhhhhhK$ubh)}(hhh](h)}(h Monitor nrph]h Monitor nrp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXThe need resched preempts (nrp) monitor ensures preemption requires ``need_resched``. Only kernel preemption is considered, since preemption while returning to userspace, for this monitor, is indistinguishable from ``sched_switch_yield`` (described in the sssw monitor). A kernel preemption is whenever ``__schedule`` is called with the preemption flag set to true (e.g. from preempt_enable or exiting from interrupts). This type of preemption occurs after the need for ``rescheduling`` has been set. This is not valid for the *lazy* variant of the flag, which causes only userspace preemption. A ``schedule_entry_preempt`` may involve a task switch or not, in the latter case, a task goes through the scheduler from a preemption context but it is picked as the next task to run. Since the scheduler runs, this clears the need to reschedule. The ``any_thread_running`` state does not imply the monitored task is not running as this monitor does not track the outcome of scheduling.h](hDThe need resched preempts (nrp) monitor ensures preemption requires }(hjhhhNhNubhliteral)}(h``need_resched``h]h need_resched}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. Only kernel preemption is considered, since preemption while returning to userspace, for this monitor, is indistinguishable from }(hjhhhNhNubj )}(h``sched_switch_yield``h]hsched_switch_yield}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhB (described in the sssw monitor). A kernel preemption is whenever }(hjhhhNhNubj )}(h``__schedule``h]h __schedule}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh is called with the preemption flag set to true (e.g. from preempt_enable or exiting from interrupts). This type of preemption occurs after the need for }(hjhhhNhNubj )}(h``rescheduling``h]h rescheduling}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh) has been set. This is not valid for the }(hjhhhNhNubjn)}(h*lazy*h]hlazy}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jmhjubh@ variant of the flag, which causes only userspace preemption. A }(hjhhhNhNubj )}(h``schedule_entry_preempt``h]hschedule_entry_preempt}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh may involve a task switch or not, in the latter case, a task goes through the scheduler from a preemption context but it is picked as the next task to run. Since the scheduler runs, this clears the need to reschedule. The }(hjhhhNhNubj )}(h``any_thread_running``h]hany_thread_running}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhq state does not imply the monitored task is not running as this monitor does not track the outcome of scheduling.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hIn theory, a preemption can only occur after the ``need_resched`` flag is set. In practice, however, it is possible to see a preemption where the flag is not set. This can happen in one specific condition::h](h1In theory, a preemption can only occur after the }(hjhhhNhNubj )}(h``need_resched``h]h need_resched}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh flag is set. In practice, however, it is possible to see a preemption where the flag is not set. This can happen in one specific condition:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hneed_resched preempt_schedule() preempt_schedule_irq() __schedule() !need_resched __schedule()h]hneed_resched preempt_schedule() preempt_schedule_irq() __schedule() !need_resched __schedule()}hjsbah}(h]h ]h"]h$]h&]j j uh1jhhhKhjhhubh)}(hXIn the situation above, standard preemption starts (e.g. from preempt_enable when the flag is set), an interrupt occurs before scheduling and, on its exit path, it schedules, which clears the ``need_resched`` flag. When the preempted task runs again, the standard preemption started earlier resumes, although the flag is no longer set. The monitor considers this a ``nested_preemption``, this allows another preemption without re-setting the flag. This condition relaxes the monitor constraints and may catch false negatives (i.e. no real ``nested_preemptions``) but makes the monitor more robust and able to validate other scenarios. For simplicity, the monitor starts in ``preempt_irq``, although no interrupt occurred, as the situation above is hard to pinpoint::h](hIn the situation above, standard preemption starts (e.g. from preempt_enable when the flag is set), an interrupt occurs before scheduling and, on its exit path, it schedules, which clears the }(hjhhhNhNubj )}(h``need_resched``h]h need_resched}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh flag. When the preempted task runs again, the standard preemption started earlier resumes, although the flag is no longer set. The monitor considers this a }(hjhhhNhNubj )}(h``nested_preemption``h]hnested_preemption}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, this allows another preemption without re-setting the flag. This condition relaxes the monitor constraints and may catch false negatives (i.e. no real }(hjhhhNhNubj )}(h``nested_preemptions``h]hnested_preemptions}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhp) but makes the monitor more robust and able to validate other scenarios. For simplicity, the monitor starts in }(hjhhhNhNubj )}(h``preempt_irq``h]h preempt_irq}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhM, although no interrupt occurred, as the situation above is hard to pinpoint:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX schedule_entry irq_entry #===========================================# +-------------------------- H H | H H +-------------------------> H any_thread_running H H H +-------------------------> H H | #===========================================# | schedule_entry | ^ | schedule_entry_preempt | sched_need_resched | schedule_entry | | schedule_entry_preempt | v | | +----------------------+ | | +--- | | | | sched_need_resched | | rescheduling | -+ | +--> | | | +----------------------+ | | irq_entry | v | +----------------------+ | | | ---+ | ---> | | | sched_need_resched | | preempt_irq | | irq_entry | | | <--+ | | | <--+ | +----------------------+ | | | schedule_entry | sched_need_resched | | schedule_entry_preempt | | v | | +-----------------------+ | +-------------------------- | nested_preempt | --+ +-----------------------+ ^ irq_entry | +-------------------+h]hX schedule_entry irq_entry #===========================================# +-------------------------- H H | H H +-------------------------> H any_thread_running H H H +-------------------------> H H | #===========================================# | schedule_entry | ^ | schedule_entry_preempt | sched_need_resched | schedule_entry | | schedule_entry_preempt | v | | +----------------------+ | | +--- | | | | sched_need_resched | | rescheduling | -+ | +--> | | | +----------------------+ | | irq_entry | v | +----------------------+ | | | ---+ | ---> | | | sched_need_resched | | preempt_irq | | irq_entry | | | <--+ | | | <--+ | +----------------------+ | | | schedule_entry | sched_need_resched | | schedule_entry_preempt | | v | | +-----------------------+ | +-------------------------- | nested_preempt | --+ +-----------------------+ ^ irq_entry | +-------------------+}hjsbah}(h]h ]h"]h$]h&]j j uh1jhhhKhjhhubh)}(hXDue to how the ``need_resched`` flag on the preemption count works on arm64, this monitor is unstable on that architecture, as it often records preemption when the flag is not set, even in presence of the workaround above. For the time being, the monitor is disabled by default on arm64.h](hDue to how the }(hj"hhhNhNubj )}(h``need_resched``h]h need_resched}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj"ubhX flag on the preemption count works on arm64, this monitor is unstable on that architecture, as it often records preemption when the flag is not set, even in presence of the workaround above. For the time being, the monitor is disabled by default on arm64.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] monitor-nrpah ]h"] monitor nrpah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Monitor ssswh]h Monitor sssw}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJhhhhhMubh)}(hThe set state sleep and wakeup (sssw) monitor ensures ``set_state`` to sleepable leads to sleeping and sleeping tasks require wakeup. It includes the following types of switch:h](h6The set state sleep and wakeup (sssw) monitor ensures }(hj[hhhNhNubj )}(h ``set_state``h]h set_state}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1j hj[ubhm to sleepable leads to sleeping and sleeping tasks require wakeup. It includes the following types of switch:}(hj[hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjJhhubh)}(hhh](h)}(hXT``switch_suspend``: a task puts itself to sleep, this can happen only after explicitly setting the task to ``sleepable``. After a task is suspended, it needs to be woken up (``waking`` state) before being switched in again. Setting the task's state to ``sleepable`` can be reverted before switching if it is woken up or set to ``runnable``.h]h)}(hXT``switch_suspend``: a task puts itself to sleep, this can happen only after explicitly setting the task to ``sleepable``. After a task is suspended, it needs to be woken up (``waking`` state) before being switched in again. Setting the task's state to ``sleepable`` can be reverted before switching if it is woken up or set to ``runnable``.h](j )}(h``switch_suspend``h]hswitch_suspend}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhY: a task puts itself to sleep, this can happen only after explicitly setting the task to }(hjhhhNhNubj )}(h ``sleepable``h]h sleepable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh6. After a task is suspended, it needs to be woken up (}(hjhhhNhNubj )}(h ``waking``h]hwaking}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhF state) before being switched in again. Setting the task’s state to }(hjhhhNhNubj )}(h ``sleepable``h]h sleepable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh> can be reverted before switching if it is woken up or set to }(hjhhhNhNubj )}(h ``runnable``h]hrunnable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj~ubah}(h]h ]h"]h$]h&]uh1hhj{hhhhhNubh)}(hX``switch_blocking``: a special case of a ``switch_suspend`` where the task is waiting on a sleeping RT lock (``PREEMPT_RT`` only), it is common to see wakeup and set state events racing with each other and this leads the model to perceive this type of switch when the task is not set to sleepable. This is a limitation of the model in SMP system and workarounds may slow down the system.h]h)}(hX``switch_blocking``: a special case of a ``switch_suspend`` where the task is waiting on a sleeping RT lock (``PREEMPT_RT`` only), it is common to see wakeup and set state events racing with each other and this leads the model to perceive this type of switch when the task is not set to sleepable. This is a limitation of the model in SMP system and workarounds may slow down the system.h](j )}(h``switch_blocking``h]hswitch_blocking}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh: a special case of a }(hjhhhNhNubj )}(h``switch_suspend``h]hswitch_suspend}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh2 where the task is waiting on a sleeping RT lock (}(hjhhhNhNubj )}(h``PREEMPT_RT``h]h PREEMPT_RT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhX only), it is common to see wakeup and set state events racing with each other and this leads the model to perceive this type of switch when the task is not set to sleepable. This is a limitation of the model in SMP system and workarounds may slow down the system.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1hhj{hhhhhNubh)}(hq``switch_preempt``: a task switch as a result of kernel preemption (``schedule_entry_preempt`` in the nrp model).h]h)}(hq``switch_preempt``: a task switch as a result of kernel preemption (``schedule_entry_preempt`` in the nrp model).h](j )}(h``switch_preempt``h]hswitch_preempt}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj:ubh2: a task switch as a result of kernel preemption (}(hj:hhhNhNubj )}(h``schedule_entry_preempt``h]hschedule_entry_preempt}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj:ubh in the nrp model).}(hj:hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj6ubah}(h]h ]h"]h$]h&]uh1hhj{hhhhhNubh)}(hX``switch_yield``: a task explicitly calls the scheduler or is preempted while returning to userspace. It can happen after a ``yield`` system call, from the idle task or if the ``need_resched`` flag is set. By definition, a task cannot yield while ``sleepable`` as that would be a suspension. A special case of a yield occurs when a task in ``TASK_INTERRUPTIBLE`` calls the scheduler while a signal is pending. The task doesn't go through the usual blocking/waking and is set back to runnable, the resulting switch (if there) looks like a yield to the ``signal_wakeup`` state and is followed by the signal delivery. From this state, the monitor expects a signal even if it sees a wakeup event, although not necessary, to rule out false negatives. h]h)}(hX``switch_yield``: a task explicitly calls the scheduler or is preempted while returning to userspace. It can happen after a ``yield`` system call, from the idle task or if the ``need_resched`` flag is set. By definition, a task cannot yield while ``sleepable`` as that would be a suspension. A special case of a yield occurs when a task in ``TASK_INTERRUPTIBLE`` calls the scheduler while a signal is pending. The task doesn't go through the usual blocking/waking and is set back to runnable, the resulting switch (if there) looks like a yield to the ``signal_wakeup`` state and is followed by the signal delivery. From this state, the monitor expects a signal even if it sees a wakeup event, although not necessary, to rule out false negatives.h](j )}(h``switch_yield``h]h switch_yield}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubhl: a task explicitly calls the scheduler or is preempted while returning to userspace. It can happen after a }(hjrhhhNhNubj )}(h ``yield``h]hyield}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubh+ system call, from the idle task or if the }(hjrhhhNhNubj )}(h``need_resched``h]h need_resched}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubh7 flag is set. By definition, a task cannot yield while }(hjrhhhNhNubj )}(h ``sleepable``h]h sleepable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubhP as that would be a suspension. A special case of a yield occurs when a task in }(hjrhhhNhNubj )}(h``TASK_INTERRUPTIBLE``h]hTASK_INTERRUPTIBLE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubh calls the scheduler while a signal is pending. The task doesn’t go through the usual blocking/waking and is set back to runnable, the resulting switch (if there) looks like a yield to the }(hjrhhhNhNubj )}(h``signal_wakeup``h]h signal_wakeup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubh state and is followed by the signal delivery. From this state, the monitor expects a signal even if it sees a wakeup event, although not necessary, to rule out false negatives.}(hjrhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjnubah}(h]h ]h"]h$]h&]uh1hhj{hhhhhNubeh}(h]h ]h"]h$]h&]j6*uh1hhhhM hjJhhubh)}(hXThis monitor doesn't include a running state, ``sleepable`` and ``runnable`` are only referring to the task's desired state, which could be scheduled out (e.g. due to preemption). However, it does include the event ``sched_switch_in`` to represent when a task is allowed to become running. This can be triggered also by preemption, but cannot occur after the task got to ``sleeping`` before a ``wakeup`` occurs::h](h0This monitor doesn’t include a running state, }(hjhhhNhNubj )}(h ``sleepable``h]h sleepable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``runnable``h]hrunnable}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh are only referring to the task’s desired state, which could be scheduled out (e.g. due to preemption). However, it does include the event }(hjhhhNhNubj )}(h``sched_switch_in``h]hsched_switch_in}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh to represent when a task is allowed to become running. This can be triggered also by preemption, but cannot occur after the task got to }(hjhhhNhNubj )}(h ``sleeping``h]hsleeping}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh before a }(hjhhhNhNubj )}(h ``wakeup``h]hwakeup}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh occurs:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM$hjJhhubj)}(hX +--------------------------------------------------------------------------+ | | | | | switch_suspend | | | switch_blocking | | v v | +----------+ #==========================# set_state_runnable | | | H H wakeup | | | H H switch_in | | | H H switch_yield | | sleeping | H H switch_preempt | | | H H signal_deliver | | | switch_ H H ------+ | | | _blocking H runnable H | | | | <----------- H H <-----+ | +----------+ H H | | wakeup H H | +---------------------> H H | H H | +---------> H H | | #==========================# | | | ^ | | | | set_state_runnable | | | | wakeup | | set_state_sleepable | +------------------------+ | v | | | +--------------------------+ set_state_sleepable | | | switch_in | | | switch_preempt signal_deliver | sleepable | signal_deliver | | | ------+ | | | | | | | <-----+ | +--------------------------+ | | ^ | switch_yield | set_state_sleepable | v | | +---------------+ | +---------- | signal_wakeup | -+ +---------------+ ^ | switch_in | | switch_preempt | | switch_yield +-----------+ wakeuph]hX +--------------------------------------------------------------------------+ | | | | | switch_suspend | | | switch_blocking | | v v | +----------+ #==========================# set_state_runnable | | | H H wakeup | | | H H switch_in | | | H H switch_yield | | sleeping | H H switch_preempt | | | H H signal_deliver | | | switch_ H H ------+ | | | _blocking H runnable H | | | | <----------- H H <-----+ | +----------+ H H | | wakeup H H | +---------------------> H H | H H | +---------> H H | | #==========================# | | | ^ | | | | set_state_runnable | | | | wakeup | | set_state_sleepable | +------------------------+ | v | | | +--------------------------+ set_state_sleepable | | | switch_in | | | switch_preempt signal_deliver | sleepable | signal_deliver | | | ------+ | | | | | | | <-----+ | +--------------------------+ | | ^ | switch_yield | set_state_sleepable | v | | +---------------+ | +---------- | signal_wakeup | -+ +---------------+ ^ | switch_in | | switch_preempt | | switch_yield +-----------+ wakeup}hj]sbah}(h]h ]h"]h$]h&]j j uh1jhhhM+hjJhhubeh}(h] monitor-ssswah ]h"] monitor ssswah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(h Monitor opidh]h Monitor opid}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjshhhhhMYubh)}(hXThe operations with preemption and irq disabled (opid) monitor ensures operations like ``wakeup`` and ``need_resched`` occur with interrupts and preemption disabled or during interrupt context, in such case preemption may not be disabled explicitly. ``need_resched`` can be set by some RCU internals functions, in which case it doesn't match a task wakeup and might occur with only interrupts disabled::h](hWThe operations with preemption and irq disabled (opid) monitor ensures operations like }(hjhhhNhNubj )}(h ``wakeup``h]hwakeup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``need_resched``h]h need_resched}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh occur with interrupts and preemption disabled or during interrupt context, in such case preemption may not be disabled explicitly. }(hjhhhNhNubj )}(h``need_resched``h]h need_resched}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh can be set by some RCU internals functions, in which case it doesn’t match a task wakeup and might occur with only interrupts disabled:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM[hjshhubj)}(hX- | 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 | -+ | +------------------+ | | | +-------------------------------------------------------+h]hX- | 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 | -+ | +------------------+ | | | +-------------------------------------------------------+}hjsbah}(h]h ]h"]h$]h&]j j uh1jhhhMbhjshhubh)}(hXThis monitor is designed to work on ``PREEMPT_RT`` kernels, the special case of events occurring in interrupt context is a shortcut to identify valid scenarios where the preemption tracepoints might not be visible, during interrupts preemption is always disabled. On non- ``PREEMPT_RT`` kernels, the interrupts might invoke a softirq to set ``need_resched`` and wake up a task. This is another special case that is currently not supported by the monitor.h](h$This monitor is designed to work on }(hjhhhNhNubj )}(h``PREEMPT_RT``h]h PREEMPT_RT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh kernels, the special case of events occurring in interrupt context is a shortcut to identify valid scenarios where the preemption tracepoints might not be visible, during interrupts preemption is always disabled. On non- }(hjhhhNhNubj )}(h``PREEMPT_RT``h]h PREEMPT_RT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh7 kernels, the interrupts might invoke a softirq to set }(hjhhhNhNubj )}(h``need_resched``h]h need_resched}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubha and wake up a task. This is another special case that is currently not supported by the monitor.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjshhubeh}(h] monitor-opidah ]h"] monitor opidah$]h&]uh1hhhhhhhhMYubh)}(hhh](h)}(h Referencesh]h References}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj"hhhhhMubh)}(h)[1] - https://bristot.me/linux-task-modelh](h[1] - }(hj3hhhNhNubh)}(h#https://bristot.me/linux-task-modelh]h#https://bristot.me/linux-task-model}(hj;hhhNhNubah}(h]h ]h"]h$]h&]refurij=uh1hhj3ubeh}(h]h ]h"]h$]h&]uh1hhhhMhj"hhubeh}(h] referencesah ]h"] referencesah$]h&]uh1hhhhhhhhMubeh}(h]scheduler-monitorsah ]h"]scheduler monitorsah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j]jZjjjjjjjGjDj|jyjjjjjGjDjpjmjjjUjRu nametypes}(j]jjjjGj|jjjGjpjjUuh}(jZhjj8jjjjjDjjyjJjjjjjDjjmjJjjsjRj"u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.