| 1 |
cset-shield(1) |
| 2 |
============== |
| 3 |
Alex Tsariounov <[email protected]> |
| 4 |
v1.6, December 2018 |
| 5 |
|
| 6 |
NAME |
| 7 |
---- |
| 8 |
cset-shield - cpuset supercommand which implements cpu shielding |
| 9 |
|
| 10 |
SYNOPSIS |
| 11 |
-------- |
| 12 |
[verse] |
| 13 |
'cset' [cset options] 'shield' [shield options] [args] |
| 14 |
'cset' shield --help |
| 15 |
'cset' shield |
| 16 |
'cset' shield --cpu 1-7 |
| 17 |
'cset' shield --cpu 1-7 --kthread=on |
| 18 |
'cset' shield --exec /opt/software/myapp/doit --my_opt1 --my_opt2 |
| 19 |
'cset' shield --user appuser --exec run_benchmark.sh |
| 20 |
'cset' shield --shield --pid 1024,2048,5000-1000 |
| 21 |
'cset' shield --unshield --pid 6000-8500 |
| 22 |
'cset' shield --kthread=off |
| 23 |
'cset' shield --kthread=on |
| 24 |
'cset' shield --shield bash |
| 25 |
|
| 26 |
OPTIONS |
| 27 |
------- |
| 28 |
-h, --help:: |
| 29 |
prints the list of options for this command |
| 30 |
|
| 31 |
-c CPUSPEC, --cpu=CPUSPEC:: |
| 32 |
modifies or initializes the shield cpusets |
| 33 |
|
| 34 |
-r, --reset:: |
| 35 |
destroys the shield |
| 36 |
|
| 37 |
-e, --exec:: |
| 38 |
executes args in the shield |
| 39 |
|
| 40 |
--user=USER:: |
| 41 |
use this USER for --exec (id or name) |
| 42 |
|
| 43 |
--group=GROUP:: |
| 44 |
use this GROUP for --exec (id or name) |
| 45 |
|
| 46 |
-s, --shield:: |
| 47 |
shield PIDSPEC specified with -p/--pid of processes or threads |
| 48 |
|
| 49 |
-u, --unshield:: |
| 50 |
remove PIDSPEC specified with -p/--pid of processes or threads from |
| 51 |
the shield, the tasks keep running in the unshielded cpuset |
| 52 |
|
| 53 |
--threads:: |
| 54 |
if specified, any processes found in the PIDSPEC to have multiple |
| 55 |
threads will automatically have all their threads added to the |
| 56 |
PIDSPEC (use to shield or unshield all related threads) |
| 57 |
|
| 58 |
-k on|off, --kthread=on|off:: |
| 59 |
shield from unbound interrupt threads as well |
| 60 |
|
| 61 |
-f, --force:: |
| 62 |
force operation, use with care |
| 63 |
|
| 64 |
-v, --verbose:: |
| 65 |
prints more detailed output, additive |
| 66 |
|
| 67 |
--sysset=SYSSET:: |
| 68 |
optionally specify system cpuset name |
| 69 |
|
| 70 |
--userset=USERSET:: |
| 71 |
optionally specify user cpuset name |
| 72 |
|
| 73 |
DESCRIPTION |
| 74 |
----------- |
| 75 |
This is a supercommand that creates basic cpu shielding. The |
| 76 |
normal cset commands can of course be used to create this basic |
| 77 |
shield, but the shield command combines many such commands to |
| 78 |
create and manage a common type of cpu shielding setup. |
| 79 |
|
| 80 |
The concept of shielding implies at minimum three cpusets, for |
| 81 |
example: root, user and system. The root cpuset always exists in |
| 82 |
all implementations of cpusets and contains all available CPUs on |
| 83 |
the machine. The system cpuset is so named because normal system |
| 84 |
tasks are made to run on it. The user cpuset is so named because |
| 85 |
that is the "shielded" cpuset on which you would run your tasks |
| 86 |
of interest. |
| 87 |
|
| 88 |
Usually, CPU zero would be in the system set and the rest of the |
| 89 |
CPUs would be in the user set. After creation of the cpusets, |
| 90 |
all processes running in the root cpuset are moved to the system |
| 91 |
cpuset. Thus any new processes or threads spawned from these |
| 92 |
processes will also run the system cpuset. |
| 93 |
|
| 94 |
If the optional --kthread=on option is given to the shield |
| 95 |
command, then all kernel threads (with exception of the per-CPU |
| 96 |
bound interrupt kernel threads) are also moved to the system set. |
| 97 |
|
| 98 |
One executes processes on the shielded user cpuset with the |
| 99 |
--exec subcommand or moves processes or threads to the shielded |
| 100 |
cpuset with the --shield subcommand with a --pid option. |
| 101 |
|
| 102 |
NOTE: You do not need to specify which cpuset a process or thread |
| 103 |
is running in initially when using the --shield subcommand. |
| 104 |
|
| 105 |
To create a shield, you would execute the shield command with the |
| 106 |
--cpu option that specifies CPUSPEC argument that assigns CPUs to |
| 107 |
be under the shield (this means assigned to the user cpuset, all |
| 108 |
other cpus will be assigned to the system set). |
| 109 |
|
| 110 |
For example: |
| 111 |
|
| 112 |
*+# cset shield --cpu=1-3+* |
| 113 |
|
| 114 |
On a 4-way machine, this command will dedicate the first |
| 115 |
processor, CPU0, for the system set (unshielded) and the last |
| 116 |
three processors, CPU1, CPU2, CPU3, for the user set (shielded). |
| 117 |
|
| 118 |
The CPUSPEC will accept a comma separated list of CPUs and |
| 119 |
inclusive range specifications. For example, --cpu=1,3,5-7 will |
| 120 |
assign CPU1, CPU3, CPU5, CPU6, and CPU7 to the user (or shielded) |
| 121 |
cpuset and the inverse of that to the system (or unshielded) |
| 122 |
cpuset. |
| 123 |
|
| 124 |
If you do not like the names "system" and "user" for the |
| 125 |
unshielded and shielded sets respectively, or if those names are |
| 126 |
used already, then use the --sysset and --userset options. |
| 127 |
|
| 128 |
For example: |
| 129 |
|
| 130 |
*+# cset shield --sysset=free --userset=cage --cpu=2,3 --kthread=on+* |
| 131 |
|
| 132 |
The above command will use the name "free" for the unshielded |
| 133 |
system cpuset, the name "cage" for the shielded user cpuset, |
| 134 |
initialize these cpusets and dedicate CPU0 and CPU1 to the "free" |
| 135 |
set and (on a 4-way machine) dedicate CPU2 and CPU3 to the "cage" |
| 136 |
set. Further, the command moves all processes and threads, |
| 137 |
including kernel threads from the root cpuset to the "free" |
| 138 |
cpuset. |
| 139 |
|
| 140 |
NOTE: If you do use the --sysset/--userset options, then you must |
| 141 |
continue to use those for every invocation of the shield supercommand. |
| 142 |
|
| 143 |
After initialization, you can run the process of interest on the |
| 144 |
shielded cpuset with the --exec subcommand, or move processes or |
| 145 |
threads already running to the shielded cpuset with the --shield |
| 146 |
subcommand and the --pid option. |
| 147 |
|
| 148 |
Note that if your execed command takes options, then use the |
| 149 |
traditional "--" marker to separate cset's options from your |
| 150 |
command's options. |
| 151 |
|
| 152 |
For example: |
| 153 |
|
| 154 |
*+# cset shield --exec -- ls -l+* |
| 155 |
|
| 156 |
This command will execute "ls -l" inside the shield. |
| 157 |
|
| 158 |
The PIDSPEC argument taken for the --pid (or -p) option is a |
| 159 |
comma separated list of PIDs or TIDs. The list can also include |
| 160 |
brackets of PIDs or TIDs that are inclusive of the endpoints. |
| 161 |
|
| 162 |
For example: |
| 163 |
|
| 164 |
1,2,5 Means processes 1, 2 and 5 |
| 165 |
1,2,600-700 Means processes 1, 2 and from 600 to 700 |
| 166 |
|
| 167 |
*+# cset shield --shield --pid=50-65+* |
| 168 |
|
| 169 |
The above command moves all processes and threads with PID or TID |
| 170 |
in the range 50-65 inclusive, from the system cpuset into the |
| 171 |
shielded user cpuset. If they are running in the root cpuset, |
| 172 |
you must use the --force option to actually move them into the |
| 173 |
shield. |
| 174 |
|
| 175 |
NOTE: The range of PIDs or TIDs does not need to have every |
| 176 |
position populated. In other words, for the example above, if |
| 177 |
there is only one process, say PID 57, in the range of 50-65, |
| 178 |
then only that process will be moved. |
| 179 |
|
| 180 |
The --unshield (or -u) subcommand will remove the specified |
| 181 |
processes or threads from the shielded cpuset and move them into |
| 182 |
the unshielded (or system) cpuset. This command is also used in |
| 183 |
conjunction with a -p/--pid option that specifies a PIDSPEC |
| 184 |
argument, the same as for the --shield subcommand. |
| 185 |
|
| 186 |
Both the --shield and the --unshield commands will also finally |
| 187 |
output the number of tasks running in the shield and out of the |
| 188 |
shield if you do not specify a PIDSPEC with --pid. By specifying |
| 189 |
also a --verbose in addition, then you will get a listing of |
| 190 |
every task that is running in either the shield or out of the |
| 191 |
shield. |
| 192 |
|
| 193 |
Using no subcommand, ie. only "cset shield", will output the |
| 194 |
status of both shield and non-shield. Tasks will be listed if |
| 195 |
--verbose is used. |
| 196 |
|
| 197 |
You can adjust which CPUs are in the shielded cpuset by issuing |
| 198 |
the --cpu subcommand again anytime after the shield has been |
| 199 |
initialized. |
| 200 |
|
| 201 |
For example if the original shield contained CPU0 and CPU1 in the |
| 202 |
system set and CPU2 and CPU3 in the user set, if you then issue |
| 203 |
the following command: |
| 204 |
|
| 205 |
*+# cset shield --cpu=1,2,3+* |
| 206 |
|
| 207 |
then that command will move CPU1 into the shielded "user" cpuset. |
| 208 |
Any processes or threads that were running on CPU1 that belonged |
| 209 |
to the unshielded "system" cpuset are migrated to CPU0 by the |
| 210 |
system. |
| 211 |
|
| 212 |
The --reset subcommand will in essence destroy the shield. For |
| 213 |
example, if there was a shield on a 4-way machine with CPU0 in |
| 214 |
system and CPUs 1-3 in user with processes running on the user |
| 215 |
cpuset (i.e. in the shield), and a --reset subcommand was issued, |
| 216 |
then all processes running in both system and user cpusets would |
| 217 |
be migrated to the root cpuset (which has access to all CPUs and |
| 218 |
never goes away), after which both system and user cpusets would |
| 219 |
be destroyed. |
| 220 |
|
| 221 |
NOTE: Even though you can mix general usage of cpusets with |
| 222 |
the shielding concepts described here, you generally will not |
| 223 |
want to. For more complex shielding or usage scenarios, one |
| 224 |
would generally use the normal cpuset commands (i.e. cset set |
| 225 |
and proc) directly. |
| 226 |
|
| 227 |
LICENSE |
| 228 |
------- |
| 229 |
Cpuset is licensed under the GNU GPL V2 only. |
| 230 |
|
| 231 |
COPYRIGHT |
| 232 |
--------- |
| 233 |
Copyright (c) 2008-2011 Novell Inc. |
| 234 |
|
| 235 |
AUTHOR |
| 236 |
------ |
| 237 |
Written by Alex Tsariounov <\[email protected]>. |
| 238 |
|
| 239 |
SEE ALSO |
| 240 |
-------- |
| 241 |
cset(1), cset-set(1), cset-proc(1) |
| 242 |
|
| 243 |
/usr/share/doc/packages/cpuset/html/tutorial.html |
| 244 |
|
| 245 |
taskset(1), chrt(1) |
| 246 |
|
| 247 |
/usr/src/linux/Documentation/cpusets.txt |