diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-01-08 08:15:23 -0500 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-03-20 14:07:44 -0400 |
| commit | f7aa7b6c50bfcec67534dbc6a9eec611e155e7fa (patch) | |
| tree | 720fc3f321991f0fe0dca31ec80615d4020f35db | |
| parent | e742799900ccb9451ee501ffa614c3f4c8c48b32 (diff) | |
Add documentation for resctl
| -rw-r--r-- | doc/howto-use-resctl.md | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/doc/howto-use-resctl.md b/doc/howto-use-resctl.md new file mode 100644 index 0000000..a781203 --- /dev/null +++ b/doc/howto-use-resctl.md | |||
| @@ -0,0 +1,144 @@ | |||
| 1 | # HOWTO: Working with Reservations | ||
| 2 | |||
| 3 | Recent versions of LITMUS^RT support proper **reservation-based scheduling**, and in particular the *partitioned reservation* (`P-RES`) plugin. This guide explains how to work with reservations in LITMUS^RT. | ||
| 4 | |||
| 5 | ## The P-RES Plugin | ||
| 6 | |||
| 7 | The `P-RES` plugin supports *partitioned* uniprocessor reservations. | ||
| 8 | |||
| 9 | In the current version, the plugin does not support the LITMUS^RT synchronization API. However, there exists an implementation of the [MC-IPC](https://www.mpi-sws.org/~bbb/papers/pdf/rtss14b.pdf), a synchronous IPC protocol with strong temporal isolation properties, on top of the `P-RES` plugin in a separate development branch. | ||
| 10 | |||
| 11 | In contrast to older LITMUS^RT plugins, reservations are first-class entities in `P-RES` that exist independently of tasks. In particular, they must be created *before* any task can be launched, and they continue to exist even after all tasks have terminated. Multiple tasks or threads can be assigned to the same reservation. If a task forks, both the parent and the child remain in the same partition. | ||
| 12 | |||
| 13 | |||
| 14 | ## Partitioned Reservations | ||
| 15 | |||
| 16 | To create new reservations, use the tool `resctl`. The tool has an online help message that can be triggered with `resctl -h`, which explains all options. In the following, we explain how to create partitioned, per-processor reservations. | ||
| 17 | |||
| 18 | ### Reservation Types | ||
| 19 | |||
| 20 | The current version of the `P-RES` plugin supports three reservation types: | ||
| 21 | |||
| 22 | ``` | ||
| 23 | polling-periodic (PP) | ||
| 24 | polling-sporadic (PS) | ||
| 25 | table-driven (TD) | ||
| 26 | ``` | ||
| 27 | |||
| 28 | Additional common reservations types (e.g., CBS, sporadic servers, etc.) have been developed in a separate branch and will be released in a later version. | ||
| 29 | |||
| 30 | The most simple reservation type is the polling reservation, which comes in two flavors: classic *periodic polling reservations* (PP), and more flexible *sporadic polling reservations* (SP). The latter is ideally suited for encapsulating sporadic and periodic real-time tasks, whereas the former is useful primarily if there is a need for fixed, known replenishment times. | ||
| 31 | |||
| 32 | In the following examples, we use sporadic polling reservations. | ||
| 33 | |||
| 34 | ### Creating a reservation | ||
| 35 | |||
| 36 | Each reservation is identified by a **reservation ID (RID)**, which is simply a non-negative number (like a PID). However, there are two important differences between PIDs and RIDs: | ||
| 37 | |||
| 38 | 1. In contrast to PIDs, RIDs are not automatically assigned. Rather, the desired RID must be specified when the reservation is created. | ||
| 39 | |||
| 40 | 2. The same RID may be used on multiple processors (i.e., RIDs are not unique systemwide). Hence it is important to specify the processor both when creating reservations and when attaching processes to reservations. | ||
| 41 | |||
| 42 | Use the following invocation to create a new sporadic polling reservation with RID 123 on core 0: | ||
| 43 | |||
| 44 | ``` | ||
| 45 | resctl -n 123 -t polling-sporadic -c 0 | ||
| 46 | ``` | ||
| 47 | |||
| 48 | Unless there is an error, no output is generated. | ||
| 49 | |||
| 50 | The above command created a polling reservation with a default budget of 10ms and a replenishment period of 100ms. | ||
| 51 | |||
| 52 | To specify other periods and/or budgets, use the `-p` and `-b` options, respectively. | ||
| 53 | |||
| 54 | For instance, use the following invocation to create a sporadic polling reservation with RID 1000 on core 1 with a budget of 25ms and a replenishment period of 50ms: | ||
| 55 | |||
| 56 | ``` | ||
| 57 | resctl -n 1000 -t polling-sporadic -c 1 -b 25 -p 50 | ||
| 58 | ``` | ||
| 59 | |||
| 60 | ### Programmatically starting a task in a reservation | ||
| 61 | |||
| 62 | To attach a task to a previously created reservation, simply use the RID as the task’s assigned processor (i.e., the RID identifies a *virtual processor*). | ||
| 63 | |||
| 64 | For example, to associate the current thread with RID 1000 on core 1 when setting up the thread’s real-time parameters, set the `cpu` field of the `struct rt_task` structure to 1000 prior to calling `set_rt_task_param()`. | ||
| 65 | |||
| 66 | Since the same RID may be used on multiple cores, make sure to migrate to the target core (with `be_migrate_to_domain()`) before calling `task_mode(LITMUS_RT_TASK)`. | ||
| 67 | |||
| 68 | Example: | ||
| 69 | |||
| 70 | ```C | ||
| 71 | int core = 1; // the core the reservation is on | ||
| 72 | int rid = 1000; // the RID to attach to | ||
| 73 | struct rt_task param; | ||
| 74 | |||
| 75 | init_rt_task_param(¶m); | ||
| 76 | // set up exec_cost, period, etc. as usual | ||
| 77 | param.exec_cost = … | ||
| 78 | param.period = … | ||
| 79 | // attach to the reservation | ||
| 80 | param.cpu = rid; | ||
| 81 | |||
| 82 | // upload parameters to kernel | ||
| 83 | set_rt_task_param(gettid(), ¶m); | ||
| 84 | |||
| 85 | // migrate thread to appropriate core | ||
| 86 | be_migrate_to_domain(core); | ||
| 87 | |||
| 88 | // transition into real-time mode | ||
| 89 | task_mode(LITMUS_RT_TASK); | ||
| 90 | ``` | ||
| 91 | |||
| 92 | Error checking has been omitted in this example to avoid clutter. However, each of these calls can fail and the return code must be checked. | ||
| 93 | |||
| 94 | |||
| 95 | ### Launching `rtspin` in a reservation | ||
| 96 | |||
| 97 | The `rtspin` test application can be assigned to a pre-existing reservation with the `-r` option. | ||
| 98 | |||
| 99 | For example, to assign an `rtspin` process that runs for three seconds with period 100 and execution time 10 to reservation 1000 on core 1, launch `rtspin` like this: | ||
| 100 | |||
| 101 | ``` | ||
| 102 | rtspin -p 1 -r 1000 10 100 3 | ||
| 103 | ``` | ||
| 104 | |||
| 105 | ### Launching any task in a reservation | ||
| 106 | |||
| 107 | The same options (`-p` and `-r`) are also understood by the `rt_launch` utility. | ||
| 108 | |||
| 109 | For example, to launch a `find` process in reservation 1000 on core 1, use the following command: | ||
| 110 | |||
| 111 | ``` | ||
| 112 | rt_launch -p 1 -r 1000 10 100 find / | ||
| 113 | ``` | ||
| 114 | |||
| 115 | |||
| 116 | ### Attaching an already running task to a reservation | ||
| 117 | |||
| 118 | It is also possible to assign an already running, non-real-time task or thread to a reservation. This can be accomplished with the `-a` (attach) option of `resctl`. | ||
| 119 | |||
| 120 | For example, to move the current shell into reservation 1000 on core 1, execute the following command: | ||
| 121 | |||
| 122 | ``` | ||
| 123 | resctl -a $$ -r 1000 -c 1 | ||
| 124 | ``` | ||
| 125 | |||
| 126 | ### Deleting a reservation | ||
| 127 | |||
| 128 | There is currently no mechanism to delete individual reservations. Once created, a reservation persists until the scheduler plugin is switched. | ||
| 129 | |||
| 130 | To delete *all* reservations, simply switch the active scheduler plugin to Linux and back again. | ||
| 131 | |||
| 132 | ``` | ||
| 133 | CUR_PLUGIN=`showsched` | ||
| 134 | setsched Linux | ||
| 135 | setsched $CUR_PLUGIN | ||
| 136 | ``` | ||
| 137 | |||
| 138 | ## Listing existing reservations | ||
| 139 | |||
| 140 | There is currently no way to obtain a list of already created reservations from user space. | ||
| 141 | |||
| 142 | (Ideally, this information would be exported via `/sys` or `/proc`, or even better by integrating with Linux's `cgroup` subsystem. Patches welcome.) | ||
| 143 | |||
| 144 | |||
