| 1 | # RT-Tests |
| 2 | |
| 3 | This repository contains some programs that test various rt-linux features. |
| 4 | |
| 5 | ## Usage |
| 6 | |
| 7 | ### Compile |
| 8 | |
| 9 | sudo apt-get install build-essential libnuma-dev |
| 10 | make |
| 11 | |
| 12 | ### Run tests |
| 13 | |
| 14 | To run one test thread per CPU or per CPU core, each thread on a separate |
| 15 | processor, type |
| 16 | |
| 17 | sudo ./cyclictest -a -t -n -p99 |
| 18 | |
| 19 | On a non-realtime system, you may see something like |
| 20 | |
| 21 | T: 0 ( 3431) P:99 I:1000 C: 100000 Min: 5 Act: 10 Avg: 14 Max: 39242 |
| 22 | T: 1 ( 3432) P:98 I:1500 C: 66934 Min: 4 Act: 10 Avg: 17 Max: 39661 |
| 23 | |
| 24 | The rightmost column contains the most important result, i.e. the worst-case |
| 25 | latency of 39.242 milliseconds. On a realtime-enabled system, the result may |
| 26 | look like |
| 27 | |
| 28 | T: 0 ( 3407) P:99 I:1000 C: 100000 Min: 7 Act: 10 Avg: 10 Max: 18 |
| 29 | T: 1 ( 3408) P:98 I:1500 C: 67043 Min: 7 Act: 8 Avg: 10 Max: 22 |
| 30 | |
| 31 | and, thus, indicate an apparent short-term worst-case latency of 18 |
| 32 | microseconds. |
| 33 | |
| 34 | Running cyclictest only over a short period of time and without creating |
| 35 | appropriate real-time stress conditions is rather meaningless, since the |
| 36 | execution of an asynchronous event from idle state is normally always quite |
| 37 | fast, and every - even non-RT system - can do that. The challenge is to minimize |
| 38 | the latency when reacting to an asynchronuous event, irrespective of what code |
| 39 | path is executed at the time when the external event arrives. |
| 40 | Therefore, specific stress conditions must be present while cyclictest is |
| 41 | running to reliably determine the worst-case latency of a given system. |
| 42 | |
| 43 | ### Latency fighting |
| 44 | |
| 45 | If - as in the above example - a low worst-case latency is measured, and this is |
| 46 | the case even under a system load that is equivalent to the load expected under |
| 47 | production conditions, everything is alright. |
| 48 | Of course, the measurement must last suffciently long, preferably 24 hours or |
| 49 | more to run several hundred million test threads. If possible, the `-i` command |
| 50 | line option (thread interval) should be used to increase the number of test |
| 51 | threads over time. |
| 52 | As a role of thumb, the thread interval should be set to a value twice as long |
| 53 | as the expected worst-case latency. If at the end of such a test period the |
| 54 | worst-cae latency still did not exceed the value that is assumed critical for a |
| 55 | given system, the particular kernel in combination with the hardware in use can |
| 56 | then probably be regarded as real-time capable. |
| 57 | |
| 58 | What, however, if the latency is higher than acceptable? Then, the famous |
| 59 | "*latency fighting*" begins. For this purpose, the cyclictest tool provides the |
| 60 | `--breaktrace` option to halt tracing if the specified latency was exceeded. A |
| 61 | tracer must be configured upfront. The resulting trace can be invastigated in |
| 62 | `/sys/kernel/tracing/trace`, for example: |
| 63 | |
| 64 | echo function > /sys/kernel/tracing/current_tracer |
| 65 | cyclictest -a -t -n -p99 --tracemark --breaktrace 100 |
| 66 | |
| 67 | This causes the program to abort execution, if the latency value exceeds 100 |
| 68 | microseconds; the culprit can then be found in the trace output at |
| 69 | `/sys/kernel/tracing/trace`. |
| 70 | The kernel function that was executed just before a latency of more than 100 |
| 71 | microseconds was detected is marked with an exclamation mark such as |
| 72 | |
| 73 | qemu-30047 2D.h3 742805us : __activate_task+0x42/0x68 <cyclicte-426> (199 1) |
| 74 | qemu-30047 2D.h3 742806us : __trace_start_sched_wakeup+0x40/0x161 <cyclicte-426> (0 -1) |
| 75 | qemu-30047 2DNh3 742806us!: try_to_wake_up+0x422/0x460 <cyclicte-426> (199 -5) |
| 76 | qemu-30047 2DN.1 742939us : __sched_text_start+0xf3/0xdcd (c064e442 0) |
| 77 | |
| 78 | The first column indicates the calling process responsible for triggering the |
| 79 | latency. |
| 80 | |
| 81 | If the trace output is not obvious, it can be submitted to the OSADL Latency |
| 82 | Fight Support Service at |
| 83 | [[email protected]](mailto:[email protected]). |
| 84 | In addition to the output of `cat /sys/kernel/tracing/trace`, the output |
| 85 | of `lspci` and the `.config` file that was used to build the kernel in question |
| 86 | must be submitted. We are sure you understand that OSADL members will be served |
| 87 | first, but we promise to do our best to help everybody to successfully fight |
| 88 | against kernel and driver latencies. |