\rsphinx.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_rtappmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/zh_TW/trace/rv/monitor_rtappmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/it_IT/trace/rv/monitor_rtappmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/ja_JP/trace/rv/monitor_rtappmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/ko_KR/trace/rv/monitor_rtappmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/sp_SP/trace/rv/monitor_rtappmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hReal-time application monitorsh]hReal-time application monitors}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhD/var/lib/git/docbuild/linux/Documentation/trace/rv/monitor_rtapp.rsthKubh bullet_list)}(hhh](h list_item)}(h Name: rtapph]h paragraph)}(hhh]h Name: rtapp}(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: Nam Cao h]h)}(h&Author: Nam Cao h](hAuthor: Nam Cao <}(hhhhhNhNubh reference)}(hnamcao@linutronix.deh]hnamcao@linutronix.de}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:namcao@linutronix.deuh1hhhubh>}(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&]uh1hhj$hhhhhK ubh)}(hReal-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]hReal-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:}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj$hhubh 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 threadh]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 threadh]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}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjLubah}(h]h ]h"]h$]h&]uh1hhjIubh)}(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.}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjdubah}(h]h ]h"]h$]h&]uh1hhjIubeh}(h]h ]h"]h$]h&]j"j#uh1hhhhKhjEubah}(h]h ]h"]h$]h&]uh1jChhhKhj$hhubh)}(hThe `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](hThe }(hjhhhNhNubhtitle_reference)}(h`rtapp`h]hrtapp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh 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.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj$hhubh)}(hhh](h)}(hMonitor pagefaulth]hMonitor pagefault}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h[The `pagefault` monitor reports real-time tasks raising page faults. Its specification is::h](hThe }(hjhhhNhNubj)}(h `pagefault`h]h pagefault}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhK monitor reports real-time tasks raising page faults. Its specification is:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hjhhubh literal_block)}(h&RULE = always (RT imply not PAGEFAULT)h]h&RULE = always (RT imply not PAGEFAULT)}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhK#hjhhubh)}(hvTo 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, }(hjhhhNhNubj)}(h `mlockall()`h]h mlockall()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh or }(hjhhhNhNubj)}(h `mlock()`h]hmlock()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh3 can be used to ensure physical backing for memory.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK%hjhhubh)}(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 `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 }(hjhhhNhNubj)}(h9`ptr = malloc(SIZE_OF_RAM); memset(ptr, 0, SIZE_OF_RAM);`h]h7ptr = malloc(SIZE_OF_RAM); memset(ptr, 0, SIZE_OF_RAM);}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhc) so that the kernel executes aggressive strategies to recycle as much physical memory as possible.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK(hjhhubeh}(h]monitor-pagefaultah ]h"]monitor pagefaultah$]h&]uh1hhj$hhhhhKubh)}(hhh](h)}(h Monitor sleeph]h Monitor sleep}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGhhhhhK0ubh)}(hThe `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](hThe }(hjXhhhNhNubj)}(h`sleep`h]hsleep}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjXubh 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:}(hjXhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK2hjGhhubjD)}(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) and `CLOCK_MONOTONIC` (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. h]h)}(hhh](h)}(hXuCyclic 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) and `CLOCK_MONOTONIC` (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)}(hXuCyclic 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) and `CLOCK_MONOTONIC` (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](hYCyclic work: real-time thread sleeps waiting for the next cycle. For this case, only the }(hjhhhNhNubj)}(h`clock_nanosleep`h]hclock_nanosleep}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh syscall should be used with }(hjhhhNhNubj)}(h`TIMER_ABSTIME`h]h TIMER_ABSTIME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh (to avoid time drift) and }(hjhhhNhNubj)}(h`CLOCK_MONOTONIC`h]hCLOCK_MONOTONIC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh (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.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK6hjubah}(h]h ]h"]h$]h&]uh1hhj|ubh)}(hXfReal-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.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK