€•Ñ|Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ*/translations/zh_CN/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/zh_TW/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/it_IT/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/ja_JP/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/ko_KR/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/pt_BR/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/sp_SP/trace/rv/monitor_rtapp”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒReal-time application monitors”h]”hŒReal-time application monitors”…””}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒD/var/lib/git/docbuild/linux/Documentation/trace/rv/monitor_rtapp.rst”h´KubhŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒ Name: rtapp”h]”hŒ paragraph”“”)”}”(hhÔh]”hŒ Name: rtapp”…””}”(hhØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´KhhÒubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhhÍh²hh³hÊh´NubhÑ)”}”(hŒ%Type: container for multiple monitors”h]”h×)”}”(hhíh]”hŒ%Type: container for multiple monitors”…””}”(hhïh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´Khhëubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhhÍh²hh³hÊh´NubhÑ)”}”(hŒ'Author: Nam Cao ”h]”h×)”}”(hŒ&Author: Nam Cao ”h]”(hŒAuthor: Nam Cao <”…””}”(hjh²hh³Nh´NubhŒ reference”“”)”}”(hŒnamcao@linutronix.de”h]”hŒnamcao@linutronix.de”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:namcao@linutronix.de”uh1jhjubhŒ>”…””}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´Khjubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhhÍh²hh³hÊh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1hËh³hÊh´Khh·h²hubh¶)”}”(hhh]”(h»)”}”(hŒ Description”h]”hŒ Description”…””}”(hj;h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj8h²hh³hÊh´K ubh×)”}”(hŒ­Real-time applications may have design flaws such that they experience unexpected latency and fail to meet their time requirements. Often, these flaws follow a few patterns:”h]”hŒ­Real-time applications may have design flaws such that they experience unexpected latency and fail to meet their time requirements. Often, these flaws follow a few patterns:”…””}”(hjIh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K hj8h²hubhŒ block_quote”“”)”}”(hX—- Page faults: A real-time thread may access memory that does not have a mapped physical backing or must first be copied (such as for copy-on-write). Thus a page fault is raised and the kernel must first perform the expensive action. This causes significant delays to the real-time thread - Priority inversion: A real-time thread blocks waiting for a lower-priority thread. This causes the real-time thread to effectively take on the scheduling priority of the lower-priority thread. For example, the real-time thread needs to access a shared resource that is protected by a non-pi-mutex, but the mutex is currently owned by a non-real-time thread. ”h]”hÌ)”}”(hhh]”(hÑ)”}”(hXPage faults: A real-time thread may access memory that does not have a mapped physical backing or must first be copied (such as for copy-on-write). Thus a page fault is raised and the kernel must first perform the expensive action. This causes significant delays to the real-time thread”h]”h×)”}”(hXPage faults: A real-time thread may access memory that does not have a mapped physical backing or must first be copied (such as for copy-on-write). Thus a page fault is raised and the kernel must first perform the expensive action. This causes significant delays to the real-time thread”h]”hXPage faults: A real-time thread may access memory that does not have a mapped physical backing or must first be copied (such as for copy-on-write). Thus a page fault is raised and the kernel must first perform the expensive action. This causes significant delays to the real-time thread”…””}”(hjdh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´Khj`ubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhj]ubhÑ)”}”(hXfPriority inversion: A real-time thread blocks waiting for a lower-priority thread. This causes the real-time thread to effectively take on the scheduling priority of the lower-priority thread. For example, the real-time thread needs to access a shared resource that is protected by a non-pi-mutex, but the mutex is currently owned by a non-real-time thread. ”h]”h×)”}”(hXePriority inversion: A real-time thread blocks waiting for a lower-priority thread. This causes the real-time thread to effectively take on the scheduling priority of the lower-priority thread. For example, the real-time thread needs to access a shared resource that is protected by a non-pi-mutex, but the mutex is currently owned by a non-real-time thread.”h]”hXePriority inversion: A real-time thread blocks waiting for a lower-priority thread. This causes the real-time thread to effectively take on the scheduling priority of the lower-priority thread. For example, the real-time thread needs to access a shared resource that is protected by a non-pi-mutex, but the mutex is currently owned by a non-real-time thread.”…””}”(hj|h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´Khjxubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhj]ubeh}”(h]”h ]”h"]”h$]”h&]”j6j7uh1hËh³hÊh´KhjYubah}”(h]”h ]”h"]”h$]”h&]”uh1jWh³hÊh´Khj8h²hubh×)”}”(hŒÖThe `rtapp` monitor detects these patterns. It aids developers to identify reasons for unexpected latency with real-time applications. It is a container of multiple sub-monitors described in the following sections.”h]”(hŒThe ”…””}”(hjœh²hh³Nh´NubhŒtitle_reference”“”)”}”(hŒ`rtapp`”h]”hŒrtapp”…””}”(hj¦h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hjœubhŒË monitor detects these patterns. It aids developers to identify reasons for unexpected latency with real-time applications. It is a container of multiple sub-monitors described in the following sections.”…””}”(hjœh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´Khj8h²hubh¶)”}”(hhh]”(h»)”}”(hŒMonitor pagefault”h]”hŒMonitor pagefault”…””}”(hjÁh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj¾h²hh³hÊh´Kubh×)”}”(hŒ[The `pagefault` monitor reports real-time tasks raising page faults. Its specification is::”h]”(hŒThe ”…””}”(hjÏh²hh³Nh´Nubj¥)”}”(hŒ `pagefault`”h]”hŒ pagefault”…””}”(hj×h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hjÏubhŒK monitor reports real-time tasks raising page faults. Its specification is:”…””}”(hjÏh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K hj¾h²hubhŒ literal_block”“”)”}”(hŒ&RULE = always (RT imply not PAGEFAULT)”h]”hŒ&RULE = always (RT imply not PAGEFAULT)”…””}”hjñsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jïh³hÊh´K#hj¾h²hubh×)”}”(hŒvTo fix warnings reported by this monitor, `mlockall()` or `mlock()` can be used to ensure physical backing for memory.”h]”(hŒ*To fix warnings reported by this monitor, ”…””}”(hjh²hh³Nh´Nubj¥)”}”(hŒ `mlockall()`”h]”hŒ mlockall()”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hjubhŒ or ”…””}”(hjh²hh³Nh´Nubj¥)”}”(hŒ `mlock()`”h]”hŒmlock()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hjubhŒ3 can be used to ensure physical backing for memory.”…””}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K%hj¾h²hubh×)”}”(hX£This monitor may have false negatives because the pages used by the real-time threads may just happen to be directly available during testing. To minimize this, the system can be put under memory pressure (e.g. invoking the OOM killer using a program that does `ptr = malloc(SIZE_OF_RAM); memset(ptr, 0, SIZE_OF_RAM);`) so that the kernel executes aggressive strategies to recycle as much physical memory as possible.”h]”(hXThis monitor may have false negatives because the pages used by the real-time threads may just happen to be directly available during testing. To minimize this, the system can be put under memory pressure (e.g. invoking the OOM killer using a program that does ”…””}”(hj3h²hh³Nh´Nubj¥)”}”(hŒ9`ptr = malloc(SIZE_OF_RAM); memset(ptr, 0, SIZE_OF_RAM);`”h]”hŒ7ptr = malloc(SIZE_OF_RAM); memset(ptr, 0, SIZE_OF_RAM);”…””}”(hj;h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hj3ubhŒc) so that the kernel executes aggressive strategies to recycle as much physical memory as possible.”…””}”(hj3h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K(hj¾h²hubeh}”(h]”Œmonitor-pagefault”ah ]”h"]”Œmonitor pagefault”ah$]”h&]”uh1hµhj8h²hh³hÊh´Kubh¶)”}”(hhh]”(h»)”}”(hŒ Monitor sleep”h]”hŒ Monitor sleep”…””}”(hj^h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhj[h²hh³hÊh´K0ubh×)”}”(hŒËThe `sleep` monitor reports real-time threads sleeping in a manner that may cause undesirable latency. Real-time applications should only put a real-time thread to sleep for one of the following reasons:”h]”(hŒThe ”…””}”(hjlh²hh³Nh´Nubj¥)”}”(hŒ`sleep`”h]”hŒsleep”…””}”(hjth²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hjlubhŒÀ monitor reports real-time threads sleeping in a manner that may cause undesirable latency. Real-time applications should only put a real-time thread to sleep for one of the following reasons:”…””}”(hjlh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K2hj[h²hubjX)”}”(hX¡- Cyclic work: real-time thread sleeps waiting for the next cycle. For this case, only the `clock_nanosleep` syscall should be used with `TIMER_ABSTIME` (to avoid time drift). Additionally, `CLOCK_REALTIME` should not be used (to avoid the clock being changed). No other method is safe for real-time. For example, threads waiting for timerfd can be woken by softirq which provides no real-time guarantee. - Real-time thread waiting for something to happen (e.g. another thread releasing shared resources, or a completion signal from another thread). In this case, only futexes (FUTEX_LOCK_PI, FUTEX_LOCK_PI2 or one of FUTEX_WAIT_*) should be used. Applications usually do not use futexes directly, but use PI mutexes and PI condition variables which are built on top of futexes. Be aware that the C library might not implement conditional variables as safe for real-time. As an alternative, the librtpi library exists to provide a conditional variable implementation that is correct for real-time applications in Linux. - Real-time thread waiting for events using `epoll_wait`, which is a real-time-safe syscall for sleeping as it uses PI-aware locking. ”h]”hÌ)”}”(hhh]”(hÑ)”}”(hX’Cyclic work: real-time thread sleeps waiting for the next cycle. For this case, only the `clock_nanosleep` syscall should be used with `TIMER_ABSTIME` (to avoid time drift). Additionally, `CLOCK_REALTIME` should not be used (to avoid the clock being changed). No other method is safe for real-time. For example, threads waiting for timerfd can be woken by softirq which provides no real-time guarantee.”h]”h×)”}”(hX’Cyclic work: real-time thread sleeps waiting for the next cycle. For this case, only the `clock_nanosleep` syscall should be used with `TIMER_ABSTIME` (to avoid time drift). Additionally, `CLOCK_REALTIME` should not be used (to avoid the clock being changed). No other method is safe for real-time. For example, threads waiting for timerfd can be woken by softirq which provides no real-time guarantee.”h]”(hŒYCyclic work: real-time thread sleeps waiting for the next cycle. For this case, only the ”…””}”(hj—h²hh³Nh´Nubj¥)”}”(hŒ`clock_nanosleep`”h]”hŒclock_nanosleep”…””}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hj—ubhŒ syscall should be used with ”…””}”(hj—h²hh³Nh´Nubj¥)”}”(hŒ`TIMER_ABSTIME`”h]”hŒ TIMER_ABSTIME”…””}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hj—ubhŒ& (to avoid time drift). Additionally, ”…””}”(hj—h²hh³Nh´Nubj¥)”}”(hŒ`CLOCK_REALTIME`”h]”hŒCLOCK_REALTIME”…””}”(hjÃh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hj—ubhŒÆ should not be used (to avoid the clock being changed). No other method is safe for real-time. For example, threads waiting for timerfd can be woken by softirq which provides no real-time guarantee.”…””}”(hj—h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K6hj“ubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhjubhÑ)”}”(hXeReal-time thread waiting for something to happen (e.g. another thread releasing shared resources, or a completion signal from another thread). In this case, only futexes (FUTEX_LOCK_PI, FUTEX_LOCK_PI2 or one of FUTEX_WAIT_*) should be used. Applications usually do not use futexes directly, but use PI mutexes and PI condition variables which are built on top of futexes. Be aware that the C library might not implement conditional variables as safe for real-time. As an alternative, the librtpi library exists to provide a conditional variable implementation that is correct for real-time applications in Linux.”h]”h×)”}”(hXeReal-time thread waiting for something to happen (e.g. another thread releasing shared resources, or a completion signal from another thread). In this case, only futexes (FUTEX_LOCK_PI, FUTEX_LOCK_PI2 or one of FUTEX_WAIT_*) should be used. Applications usually do not use futexes directly, but use PI mutexes and PI condition variables which are built on top of futexes. Be aware that the C library might not implement conditional variables as safe for real-time. As an alternative, the librtpi library exists to provide a conditional variable implementation that is correct for real-time applications in Linux.”h]”hXeReal-time thread waiting for something to happen (e.g. another thread releasing shared resources, or a completion signal from another thread). In this case, only futexes (FUTEX_LOCK_PI, FUTEX_LOCK_PI2 or one of FUTEX_WAIT_*) should be used. Applications usually do not use futexes directly, but use PI mutexes and PI condition variables which are built on top of futexes. Be aware that the C library might not implement conditional variables as safe for real-time. As an alternative, the librtpi library exists to provide a conditional variable implementation that is correct for real-time applications in Linux.”…””}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´K=hjáubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhjubhÑ)”}”(hŒ„Real-time thread waiting for events using `epoll_wait`, which is a real-time-safe syscall for sleeping as it uses PI-aware locking. ”h]”h×)”}”(hŒƒReal-time thread waiting for events using `epoll_wait`, which is a real-time-safe syscall for sleeping as it uses PI-aware locking.”h]”(hŒ*Real-time thread waiting for events using ”…””}”(hjýh²hh³Nh´Nubj¥)”}”(hŒ `epoll_wait`”h]”hŒ epoll_wait”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j¤hjýubhŒM, which is a real-time-safe syscall for sleeping as it uses PI-aware locking.”…””}”(hjýh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´KFhjùubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhjubeh}”(h]”h ]”h"]”h$]”h&]”j6j7uh1hËh³hÊh´K6hjŒubah}”(h]”h ]”h"]”h$]”h&]”uh1jWh³hÊh´K6hj[h²hubh×)”}”(hŒaBeside the reason for sleeping, the eventual waker should also be real-time-safe. Namely, one of:”h]”hŒaBeside the reason for sleeping, the eventual waker should also be real-time-safe. Namely, one of:”…””}”(hj/h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´KIhj[h²hubjX)”}”(hŒ_- An equal-or-higher-priority thread - Hard interrupt handler - Non-maskable interrupt handler ”h]”hÌ)”}”(hhh]”(hÑ)”}”(hŒ"An equal-or-higher-priority thread”h]”h×)”}”(hjFh]”hŒ"An equal-or-higher-priority thread”…””}”(hjHh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´KLhjDubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhjAubhÑ)”}”(hŒHard interrupt handler”h]”h×)”}”(hj]h]”hŒHard interrupt handler”…””}”(hj_h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´KMhj[ubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhjAubhÑ)”}”(hŒNon-maskable interrupt handler ”h]”h×)”}”(hŒNon-maskable interrupt handler”h]”hŒNon-maskable interrupt handler”…””}”(hjvh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÖh³hÊh´KNhjrubah}”(h]”h ]”h"]”h$]”h&]”uh1hÐhjAubeh}”(h]”h ]”h"]”h$]”h&]”j6j7uh1hËh³hÊh´KLhj=ubah}”(h]”h ]”h"]”h$]”h&]”uh1jWh³hÊh´KLhj[h²hubh×)”}”(hŒ:This monitor's warning usually means one of the following:”h]”hŒ