aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2016-01-08 08:15:23 -0500
committerBjoern Brandenburg <bbb@mpi-sws.org>2016-03-20 14:07:44 -0400
commitf7aa7b6c50bfcec67534dbc6a9eec611e155e7fa (patch)
tree720fc3f321991f0fe0dca31ec80615d4020f35db
parente742799900ccb9451ee501ffa614c3f4c8c48b32 (diff)
Add documentation for resctl
-rw-r--r--doc/howto-use-resctl.md144
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
3Recent 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
7The `P-RES` plugin supports *partitioned* uniprocessor reservations.
8
9In 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
11In 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
16To 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
20The current version of the `P-RES` plugin supports three reservation types:
21
22```
23polling-periodic (PP)
24polling-sporadic (PS)
25table-driven (TD)
26```
27
28Additional 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
30The 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
32In the following examples, we use sporadic polling reservations.
33
34### Creating a reservation
35
36Each 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
381. In contrast to PIDs, RIDs are not automatically assigned. Rather, the desired RID must be specified when the reservation is created.
39
402. 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
42Use the following invocation to create a new sporadic polling reservation with RID 123 on core 0:
43
44```
45resctl -n 123 -t polling-sporadic -c 0
46```
47
48Unless there is an error, no output is generated.
49
50The above command created a polling reservation with a default budget of 10ms and a replenishment period of 100ms.
51
52To specify other periods and/or budgets, use the `-p` and `-b` options, respectively.
53
54For 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```
57resctl -n 1000 -t polling-sporadic -c 1 -b 25 -p 50
58```
59
60### Programmatically starting a task in a reservation
61
62To 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
64For 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
66Since 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
68Example:
69
70```C
71int core = 1; // the core the reservation is on
72int rid = 1000; // the RID to attach to
73struct rt_task param;
74
75init_rt_task_param(&param);
76// set up exec_cost, period, etc. as usual
77param.exec_cost = …
78param.period = …
79// attach to the reservation
80param.cpu = rid;
81
82// upload parameters to kernel
83set_rt_task_param(gettid(), &param);
84
85// migrate thread to appropriate core
86be_migrate_to_domain(core);
87
88// transition into real-time mode
89task_mode(LITMUS_RT_TASK);
90```
91
92Error 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
97The `rtspin` test application can be assigned to a pre-existing reservation with the `-r` option.
98
99For 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
107The same options (`-p` and `-r`) are also understood by the `rt_launch` utility.
108
109For example, to launch a `find` process in reservation 1000 on core 1, use the following command:
110
111```
112rt_launch -p 1 -r 1000 10 100 find /
113```
114
115
116### Attaching an already running task to a reservation
117
118It 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
120For example, to move the current shell into reservation 1000 on core 1, execute the following command:
121
122```
123resctl -a $$ -r 1000 -c 1
124```
125
126### Deleting a reservation
127
128There is currently no mechanism to delete individual reservations. Once created, a reservation persists until the scheduler plugin is switched.
129
130To delete *all* reservations, simply switch the active scheduler plugin to Linux and back again.
131
132```
133CUR_PLUGIN=`showsched`
134setsched Linux
135setsched $CUR_PLUGIN
136```
137
138## Listing existing reservations
139
140There 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