| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
| 2 | "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> |
| 6 | <meta name="generator" content="AsciiDoc 8.6.9" /> |
| 7 | <title>Cpuset (cset) Tutorial</title> |
| 8 | <style type="text/css"> |
| 9 | /* Shared CSS for AsciiDoc xhtml11 and html5 backends */ |
| 10 | |
| 11 | /* Default font. */ |
| 12 | body { |
| 13 | font-family: Georgia,serif; |
| 14 | } |
| 15 | |
| 16 | /* Title font. */ |
| 17 | h1, h2, h3, h4, h5, h6, |
| 18 | div.title, caption.title, |
| 19 | thead, p.table.header, |
| 20 | #toctitle, |
| 21 | #author, #revnumber, #revdate, #revremark, |
| 22 | #footer { |
| 23 | font-family: Arial,Helvetica,sans-serif; |
| 24 | } |
| 25 | |
| 26 | body { |
| 27 | margin: 1em 5% 1em 5%; |
| 28 | } |
| 29 | |
| 30 | a { |
| 31 | color: blue; |
| 32 | text-decoration: underline; |
| 33 | } |
| 34 | a:visited { |
| 35 | color: fuchsia; |
| 36 | } |
| 37 | |
| 38 | em { |
| 39 | font-style: italic; |
| 40 | color: navy; |
| 41 | } |
| 42 | |
| 43 | strong { |
| 44 | font-weight: bold; |
| 45 | color: #083194; |
| 46 | } |
| 47 | |
| 48 | h1, h2, h3, h4, h5, h6 { |
| 49 | color: #527bbd; |
| 50 | margin-top: 1.2em; |
| 51 | margin-bottom: 0.5em; |
| 52 | line-height: 1.3; |
| 53 | } |
| 54 | |
| 55 | h1, h2, h3 { |
| 56 | border-bottom: 2px solid silver; |
| 57 | } |
| 58 | h2 { |
| 59 | padding-top: 0.5em; |
| 60 | } |
| 61 | h3 { |
| 62 | float: left; |
| 63 | } |
| 64 | h3 + * { |
| 65 | clear: left; |
| 66 | } |
| 67 | h5 { |
| 68 | font-size: 1.0em; |
| 69 | } |
| 70 | |
| 71 | div.sectionbody { |
| 72 | margin-left: 0; |
| 73 | } |
| 74 | |
| 75 | hr { |
| 76 | border: 1px solid silver; |
| 77 | } |
| 78 | |
| 79 | p { |
| 80 | margin-top: 0.5em; |
| 81 | margin-bottom: 0.5em; |
| 82 | } |
| 83 | |
| 84 | ul, ol, li > p { |
| 85 | margin-top: 0; |
| 86 | } |
| 87 | ul > li { color: #aaa; } |
| 88 | ul > li > * { color: black; } |
| 89 | |
| 90 | .monospaced, code, pre { |
| 91 | font-family: "Courier New", Courier, monospace; |
| 92 | font-size: inherit; |
| 93 | color: navy; |
| 94 | padding: 0; |
| 95 | margin: 0; |
| 96 | } |
| 97 | pre { |
| 98 | white-space: pre-wrap; |
| 99 | } |
| 100 | |
| 101 | #author { |
| 102 | color: #527bbd; |
| 103 | font-weight: bold; |
| 104 | font-size: 1.1em; |
| 105 | } |
| 106 | #email { |
| 107 | } |
| 108 | #revnumber, #revdate, #revremark { |
| 109 | } |
| 110 | |
| 111 | #footer { |
| 112 | font-size: small; |
| 113 | border-top: 2px solid silver; |
| 114 | padding-top: 0.5em; |
| 115 | margin-top: 4.0em; |
| 116 | } |
| 117 | #footer-text { |
| 118 | float: left; |
| 119 | padding-bottom: 0.5em; |
| 120 | } |
| 121 | #footer-badges { |
| 122 | float: right; |
| 123 | padding-bottom: 0.5em; |
| 124 | } |
| 125 | |
| 126 | #preamble { |
| 127 | margin-top: 1.5em; |
| 128 | margin-bottom: 1.5em; |
| 129 | } |
| 130 | div.imageblock, div.exampleblock, div.verseblock, |
| 131 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 132 | div.admonitionblock { |
| 133 | margin-top: 1.0em; |
| 134 | margin-bottom: 1.5em; |
| 135 | } |
| 136 | div.admonitionblock { |
| 137 | margin-top: 2.0em; |
| 138 | margin-bottom: 2.0em; |
| 139 | margin-right: 10%; |
| 140 | color: #606060; |
| 141 | } |
| 142 | |
| 143 | div.content { /* Block element content. */ |
| 144 | padding: 0; |
| 145 | } |
| 146 | |
| 147 | /* Block element titles. */ |
| 148 | div.title, caption.title { |
| 149 | color: #527bbd; |
| 150 | font-weight: bold; |
| 151 | text-align: left; |
| 152 | margin-top: 1.0em; |
| 153 | margin-bottom: 0.5em; |
| 154 | } |
| 155 | div.title + * { |
| 156 | margin-top: 0; |
| 157 | } |
| 158 | |
| 159 | td div.title:first-child { |
| 160 | margin-top: 0.0em; |
| 161 | } |
| 162 | div.content div.title:first-child { |
| 163 | margin-top: 0.0em; |
| 164 | } |
| 165 | div.content + div.title { |
| 166 | margin-top: 0.0em; |
| 167 | } |
| 168 | |
| 169 | div.sidebarblock > div.content { |
| 170 | background: #ffffee; |
| 171 | border: 1px solid #dddddd; |
| 172 | border-left: 4px solid #f0f0f0; |
| 173 | padding: 0.5em; |
| 174 | } |
| 175 | |
| 176 | div.listingblock > div.content { |
| 177 | border: 1px solid #dddddd; |
| 178 | border-left: 5px solid #f0f0f0; |
| 179 | background: #f8f8f8; |
| 180 | padding: 0.5em; |
| 181 | } |
| 182 | |
| 183 | div.quoteblock, div.verseblock { |
| 184 | padding-left: 1.0em; |
| 185 | margin-left: 1.0em; |
| 186 | margin-right: 10%; |
| 187 | border-left: 5px solid #f0f0f0; |
| 188 | color: #888; |
| 189 | } |
| 190 | |
| 191 | div.quoteblock > div.attribution { |
| 192 | padding-top: 0.5em; |
| 193 | text-align: right; |
| 194 | } |
| 195 | |
| 196 | div.verseblock > pre.content { |
| 197 | font-family: inherit; |
| 198 | font-size: inherit; |
| 199 | } |
| 200 | div.verseblock > div.attribution { |
| 201 | padding-top: 0.75em; |
| 202 | text-align: left; |
| 203 | } |
| 204 | /* DEPRECATED: Pre version 8.2.7 verse style literal block. */ |
| 205 | div.verseblock + div.attribution { |
| 206 | text-align: left; |
| 207 | } |
| 208 | |
| 209 | div.admonitionblock .icon { |
| 210 | vertical-align: top; |
| 211 | font-size: 1.1em; |
| 212 | font-weight: bold; |
| 213 | text-decoration: underline; |
| 214 | color: #527bbd; |
| 215 | padding-right: 0.5em; |
| 216 | } |
| 217 | div.admonitionblock td.content { |
| 218 | padding-left: 0.5em; |
| 219 | border-left: 3px solid #dddddd; |
| 220 | } |
| 221 | |
| 222 | div.exampleblock > div.content { |
| 223 | border-left: 3px solid #dddddd; |
| 224 | padding-left: 0.5em; |
| 225 | } |
| 226 | |
| 227 | div.imageblock div.content { padding-left: 0; } |
| 228 | span.image img { border-style: none; vertical-align: text-bottom; } |
| 229 | a.image:visited { color: white; } |
| 230 | |
| 231 | dl { |
| 232 | margin-top: 0.8em; |
| 233 | margin-bottom: 0.8em; |
| 234 | } |
| 235 | dt { |
| 236 | margin-top: 0.5em; |
| 237 | margin-bottom: 0; |
| 238 | font-style: normal; |
| 239 | color: navy; |
| 240 | } |
| 241 | dd > *:first-child { |
| 242 | margin-top: 0.1em; |
| 243 | } |
| 244 | |
| 245 | ul, ol { |
| 246 | list-style-position: outside; |
| 247 | } |
| 248 | ol.arabic { |
| 249 | list-style-type: decimal; |
| 250 | } |
| 251 | ol.loweralpha { |
| 252 | list-style-type: lower-alpha; |
| 253 | } |
| 254 | ol.upperalpha { |
| 255 | list-style-type: upper-alpha; |
| 256 | } |
| 257 | ol.lowerroman { |
| 258 | list-style-type: lower-roman; |
| 259 | } |
| 260 | ol.upperroman { |
| 261 | list-style-type: upper-roman; |
| 262 | } |
| 263 | |
| 264 | div.compact ul, div.compact ol, |
| 265 | div.compact p, div.compact p, |
| 266 | div.compact div, div.compact div { |
| 267 | margin-top: 0.1em; |
| 268 | margin-bottom: 0.1em; |
| 269 | } |
| 270 | |
| 271 | tfoot { |
| 272 | font-weight: bold; |
| 273 | } |
| 274 | td > div.verse { |
| 275 | white-space: pre; |
| 276 | } |
| 277 | |
| 278 | div.hdlist { |
| 279 | margin-top: 0.8em; |
| 280 | margin-bottom: 0.8em; |
| 281 | } |
| 282 | div.hdlist tr { |
| 283 | padding-bottom: 15px; |
| 284 | } |
| 285 | dt.hdlist1.strong, td.hdlist1.strong { |
| 286 | font-weight: bold; |
| 287 | } |
| 288 | td.hdlist1 { |
| 289 | vertical-align: top; |
| 290 | font-style: normal; |
| 291 | padding-right: 0.8em; |
| 292 | color: navy; |
| 293 | } |
| 294 | td.hdlist2 { |
| 295 | vertical-align: top; |
| 296 | } |
| 297 | div.hdlist.compact tr { |
| 298 | margin: 0; |
| 299 | padding-bottom: 0; |
| 300 | } |
| 301 | |
| 302 | .comment { |
| 303 | background: yellow; |
| 304 | } |
| 305 | |
| 306 | .footnote, .footnoteref { |
| 307 | font-size: 0.8em; |
| 308 | } |
| 309 | |
| 310 | span.footnote, span.footnoteref { |
| 311 | vertical-align: super; |
| 312 | } |
| 313 | |
| 314 | #footnotes { |
| 315 | margin: 20px 0 20px 0; |
| 316 | padding: 7px 0 0 0; |
| 317 | } |
| 318 | |
| 319 | #footnotes div.footnote { |
| 320 | margin: 0 0 5px 0; |
| 321 | } |
| 322 | |
| 323 | #footnotes hr { |
| 324 | border: none; |
| 325 | border-top: 1px solid silver; |
| 326 | height: 1px; |
| 327 | text-align: left; |
| 328 | margin-left: 0; |
| 329 | width: 20%; |
| 330 | min-width: 100px; |
| 331 | } |
| 332 | |
| 333 | div.colist td { |
| 334 | padding-right: 0.5em; |
| 335 | padding-bottom: 0.3em; |
| 336 | vertical-align: top; |
| 337 | } |
| 338 | div.colist td img { |
| 339 | margin-top: 0.3em; |
| 340 | } |
| 341 | |
| 342 | @media print { |
| 343 | #footer-badges { display: none; } |
| 344 | } |
| 345 | |
| 346 | #toc { |
| 347 | margin-bottom: 2.5em; |
| 348 | } |
| 349 | |
| 350 | #toctitle { |
| 351 | color: #527bbd; |
| 352 | font-size: 1.1em; |
| 353 | font-weight: bold; |
| 354 | margin-top: 1.0em; |
| 355 | margin-bottom: 0.1em; |
| 356 | } |
| 357 | |
| 358 | div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 359 | margin-top: 0; |
| 360 | margin-bottom: 0; |
| 361 | } |
| 362 | div.toclevel2 { |
| 363 | margin-left: 2em; |
| 364 | font-size: 0.9em; |
| 365 | } |
| 366 | div.toclevel3 { |
| 367 | margin-left: 4em; |
| 368 | font-size: 0.9em; |
| 369 | } |
| 370 | div.toclevel4 { |
| 371 | margin-left: 6em; |
| 372 | font-size: 0.9em; |
| 373 | } |
| 374 | |
| 375 | span.aqua { color: aqua; } |
| 376 | span.black { color: black; } |
| 377 | span.blue { color: blue; } |
| 378 | span.fuchsia { color: fuchsia; } |
| 379 | span.gray { color: gray; } |
| 380 | span.green { color: green; } |
| 381 | span.lime { color: lime; } |
| 382 | span.maroon { color: maroon; } |
| 383 | span.navy { color: navy; } |
| 384 | span.olive { color: olive; } |
| 385 | span.purple { color: purple; } |
| 386 | span.red { color: red; } |
| 387 | span.silver { color: silver; } |
| 388 | span.teal { color: teal; } |
| 389 | span.white { color: white; } |
| 390 | span.yellow { color: yellow; } |
| 391 | |
| 392 | span.aqua-background { background: aqua; } |
| 393 | span.black-background { background: black; } |
| 394 | span.blue-background { background: blue; } |
| 395 | span.fuchsia-background { background: fuchsia; } |
| 396 | span.gray-background { background: gray; } |
| 397 | span.green-background { background: green; } |
| 398 | span.lime-background { background: lime; } |
| 399 | span.maroon-background { background: maroon; } |
| 400 | span.navy-background { background: navy; } |
| 401 | span.olive-background { background: olive; } |
| 402 | span.purple-background { background: purple; } |
| 403 | span.red-background { background: red; } |
| 404 | span.silver-background { background: silver; } |
| 405 | span.teal-background { background: teal; } |
| 406 | span.white-background { background: white; } |
| 407 | span.yellow-background { background: yellow; } |
| 408 | |
| 409 | span.big { font-size: 2em; } |
| 410 | span.small { font-size: 0.6em; } |
| 411 | |
| 412 | span.underline { text-decoration: underline; } |
| 413 | span.overline { text-decoration: overline; } |
| 414 | span.line-through { text-decoration: line-through; } |
| 415 | |
| 416 | div.unbreakable { page-break-inside: avoid; } |
| 417 | |
| 418 | |
| 419 | /* |
| 420 | * xhtml11 specific |
| 421 | * |
| 422 | * */ |
| 423 | |
| 424 | div.tableblock { |
| 425 | margin-top: 1.0em; |
| 426 | margin-bottom: 1.5em; |
| 427 | } |
| 428 | div.tableblock > table { |
| 429 | border: 3px solid #527bbd; |
| 430 | } |
| 431 | thead, p.table.header { |
| 432 | font-weight: bold; |
| 433 | color: #527bbd; |
| 434 | } |
| 435 | p.table { |
| 436 | margin-top: 0; |
| 437 | } |
| 438 | /* Because the table frame attribute is overriden by CSS in most browsers. */ |
| 439 | div.tableblock > table[frame="void"] { |
| 440 | border-style: none; |
| 441 | } |
| 442 | div.tableblock > table[frame="hsides"] { |
| 443 | border-left-style: none; |
| 444 | border-right-style: none; |
| 445 | } |
| 446 | div.tableblock > table[frame="vsides"] { |
| 447 | border-top-style: none; |
| 448 | border-bottom-style: none; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | /* |
| 453 | * html5 specific |
| 454 | * |
| 455 | * */ |
| 456 | |
| 457 | table.tableblock { |
| 458 | margin-top: 1.0em; |
| 459 | margin-bottom: 1.5em; |
| 460 | } |
| 461 | thead, p.tableblock.header { |
| 462 | font-weight: bold; |
| 463 | color: #527bbd; |
| 464 | } |
| 465 | p.tableblock { |
| 466 | margin-top: 0; |
| 467 | } |
| 468 | table.tableblock { |
| 469 | border-width: 3px; |
| 470 | border-spacing: 0px; |
| 471 | border-style: solid; |
| 472 | border-color: #527bbd; |
| 473 | border-collapse: collapse; |
| 474 | } |
| 475 | th.tableblock, td.tableblock { |
| 476 | border-width: 1px; |
| 477 | padding: 4px; |
| 478 | border-style: solid; |
| 479 | border-color: #527bbd; |
| 480 | } |
| 481 | |
| 482 | table.tableblock.frame-topbot { |
| 483 | border-left-style: hidden; |
| 484 | border-right-style: hidden; |
| 485 | } |
| 486 | table.tableblock.frame-sides { |
| 487 | border-top-style: hidden; |
| 488 | border-bottom-style: hidden; |
| 489 | } |
| 490 | table.tableblock.frame-none { |
| 491 | border-style: hidden; |
| 492 | } |
| 493 | |
| 494 | th.tableblock.halign-left, td.tableblock.halign-left { |
| 495 | text-align: left; |
| 496 | } |
| 497 | th.tableblock.halign-center, td.tableblock.halign-center { |
| 498 | text-align: center; |
| 499 | } |
| 500 | th.tableblock.halign-right, td.tableblock.halign-right { |
| 501 | text-align: right; |
| 502 | } |
| 503 | |
| 504 | th.tableblock.valign-top, td.tableblock.valign-top { |
| 505 | vertical-align: top; |
| 506 | } |
| 507 | th.tableblock.valign-middle, td.tableblock.valign-middle { |
| 508 | vertical-align: middle; |
| 509 | } |
| 510 | th.tableblock.valign-bottom, td.tableblock.valign-bottom { |
| 511 | vertical-align: bottom; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /* |
| 516 | * manpage specific |
| 517 | * |
| 518 | * */ |
| 519 | |
| 520 | body.manpage h1 { |
| 521 | padding-top: 0.5em; |
| 522 | padding-bottom: 0.5em; |
| 523 | border-top: 2px solid silver; |
| 524 | border-bottom: 2px solid silver; |
| 525 | } |
| 526 | body.manpage h2 { |
| 527 | border-style: none; |
| 528 | } |
| 529 | body.manpage div.sectionbody { |
| 530 | margin-left: 3em; |
| 531 | } |
| 532 | |
| 533 | @media print { |
| 534 | body.manpage div#toc { display: none; } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | </style> |
| 539 | <script type="text/javascript"> |
| 540 | /*<+'])'); |
| 583 | // Function that scans the DOM tree for header elements (the DOM2 |
| 584 | // nodeIterator API would be a better technique but not supported by all |
| 585 | // browsers). |
| 586 | var iterate = function (el) { |
| 587 | for (var i = el.firstChild; i != null; i = i.nextSibling) { |
| 588 | if (i.nodeType == 1 /* Node.ELEMENT_NODE */) { |
| 589 | var mo = re.exec(i.tagName); |
| 590 | if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") { |
| 591 | result[result.length] = new TocEntry(i, getText(i), mo[1]-1); |
| 592 | } |
| 593 | iterate(i); |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | iterate(el); |
| 598 | return result; |
| 599 | } |
| 600 | |
| 601 | var toc = document.getElementById("toc"); |
| 602 | if (!toc) { |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | // Delete existing TOC entries in case we're reloading the TOC. |
| 607 | var tocEntriesToRemove = []; |
| 608 | var i; |
| 609 | for (i = 0; i < toc.childNodes.length; i++) { |
| 610 | var entry = toc.childNodes[i]; |
| 611 | if (entry.nodeName.toLowerCase() == 'div' |
| 612 | && entry.getAttribute("class") |
| 613 | && entry.getAttribute("class").match(/^toclevel/)) |
| 614 | tocEntriesToRemove.push(entry); |
| 615 | } |
| 616 | for (i = 0; i < tocEntriesToRemove.length; i++) { |
| 617 | toc.removeChild(tocEntriesToRemove[i]); |
| 618 | } |
| 619 | |
| 620 | // Rebuild TOC entries. |
| 621 | var entries = tocEntries(document.getElementById("content"), toclevels); |
| 622 | for (var i = 0; i < entries.length; ++i) { |
| 623 | var entry = entries[i]; |
| 624 | if (entry.element.id == "") |
| 625 | entry.element.id = "_toc_" + i; |
| 626 | var a = document.createElement("a"); |
| 627 | a.href = "#" + entry.element.id; |
| 628 | a.appendChild(document.createTextNode(entry.text)); |
| 629 | var div = document.createElement("div"); |
| 630 | div.appendChild(a); |
| 631 | div.className = "toclevel" + entry.toclevel; |
| 632 | toc.appendChild(div); |
| 633 | } |
| 634 | if (entries.length == 0) |
| 635 | toc.parentNode.removeChild(toc); |
| 636 | }, |
| 637 | |
| 638 | |
| 639 | ///////////////////////////////////////////////////////////////////// |
| 640 | // Footnotes generator |
| 641 | ///////////////////////////////////////////////////////////////////// |
| 642 | |
| 643 | /* Based on footnote generation code from: |
| 644 | * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html |
| 645 | */ |
| 646 | |
| 647 | footnotes: function () { |
| 648 | // Delete existing footnote entries in case we're reloading the footnodes. |
| 649 | var i; |
| 650 | var noteholder = document.getElementById("footnotes"); |
| 651 | if (!noteholder) { |
| 652 | return; |
| 653 | } |
| 654 | var entriesToRemove = []; |
| 655 | for (i = 0; i < noteholder.childNodes.length; i++) { |
| 656 | var entry = noteholder.childNodes[i]; |
| 657 | if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote") |
| 658 | entriesToRemove.push(entry); |
| 659 | } |
| 660 | for (i = 0; i < entriesToRemove.length; i++) { |
| 661 | noteholder.removeChild(entriesToRemove[i]); |
| 662 | } |
| 663 | |
| 664 | // Rebuild footnote entries. |
| 665 | var cont = document.getElementById("content"); |
| 666 | var spans = cont.getElementsByTagName("span"); |
| 667 | var refs = {}; |
| 668 | var n = 0; |
| 669 | for (i=0; i<spans.length; i++) { |
| 670 | if (spans[i].className == "footnote") { |
| 671 | n++; |
| 672 | var note = spans[i].getAttribute("data-note"); |
| 673 | if (!note) { |
| 674 | // Use [\s\S] in place of . so multi-line matches work. |
| 675 | // Because JavaScript has no s (dotall) regex flag. |
| 676 | note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1]; |
| 677 | spans[i].innerHTML = |
| 678 | "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n + |
| 679 | "' title='View footnote' class='footnote'>" + n + "</a>]"; |
| 680 | spans[i].setAttribute("data-note", note); |
| 681 | } |
| 682 | noteholder.innerHTML += |
| 683 | "<div class='footnote' id='_footnote_" + n + "'>" + |
| 684 | "<a href='#_footnoteref_" + n + "' title='Return to text'>" + |
| 685 | n + "</a>. " + note + "</div>"; |
| 686 | var id =spans[i].getAttribute("id"); |
| 687 | if (id != null) refs["#"+id] = n; |
| 688 | } |
| 689 | } |
| 690 | if (n == 0) |
| 691 | noteholder.parentNode.removeChild(noteholder); |
| 692 | else { |
| 693 | // Process footnoterefs. |
| 694 | for (i=0; i<spans.length; i++) { |
| 695 | if (spans[i].className == "footnoteref") { |
| 696 | var href = spans[i].getElementsByTagName("a")[0].getAttribute("href"); |
| 697 | href = href.match(/#.*/)[0]; // Because IE return full URL. |
| 698 | n = refs[href]; |
| 699 | spans[i].innerHTML = |
| 700 | "[<a href='#_footnote_" + n + |
| 701 | "' title='View footnote' class='footnote'>" + n + "</a>]"; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | }, |
| 706 | |
| 707 | install: function(toclevels) { |
| 708 | var timerId; |
| 709 | |
| 710 | function reinstall() { |
| 711 | asciidoc.footnotes(); |
| 712 | if (toclevels) { |
| 713 | asciidoc.toc(toclevels); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | function reinstallAndRemoveTimer() { |
| 718 | clearInterval(timerId); |
| 719 | reinstall(); |
| 720 | } |
| 721 | |
| 722 | timerId = setInterval(reinstall, 500); |
| 723 | if (document.addEventListener) |
| 724 | document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false); |
| 725 | else |
| 726 | window.onload = reinstallAndRemoveTimer; |
| 727 | } |
| 728 | |
| 729 | } |
| 730 | asciidoc.install(4); |
| 731 | /*]]>*/ |
| 732 | </script> |
| 733 | </head> |
| 734 | <body class="article"> |
| 735 | <div id="header"> |
| 736 | <h1>Cpuset (cset) Tutorial</h1> |
| 737 | <div id="toc"> |
| 738 | <div id="toctitle">Table of Contents</div> |
| 739 | <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript> |
| 740 | </div> |
| 741 | </div> |
| 742 | <div id="content"> |
| 743 | <div id="preamble"> |
| 744 | <div class="sectionbody"> |
| 745 | <div class="paragraph"><p>Alex Tsariounov <<a href="mailto:[email protected]">[email protected]</a>><br /> |
| 746 | Copyright (c) 2009-2011 Novell Inc., cset v1.5.8<br /> |
| 747 | Verbatim copying and distribution of this entire article are permitted |
| 748 | worldwide, without royalty, in any medium, provided this notice is preserved.</p></div> |
| 749 | <div class="paragraph"><p>This tutorial describes basic and advanced usage of the <strong>cset</strong> command to |
| 750 | manipulate cpusets on a Linux system. See also the manpages that come with |
| 751 | the <strong>cset</strong> command: cset(1), cset-shield(1), cset-set(1), and cset-proc(1) for |
| 752 | more details. Additionally, the <strong>cset</strong> command has online help.</p></div> |
| 753 | </div> |
| 754 | </div> |
| 755 | <div class="sect1"> |
| 756 | <h2 id="_introduction">1. Introduction</h2> |
| 757 | <div class="sectionbody"> |
| 758 | <div class="paragraph"><p>In the Linux kernel, the cpuset facility provides a mechanism for creating |
| 759 | logical entities called "cpusets" that encompass definitions of CPUs and NUMA |
| 760 | Memory Nodes (if NUMA is available). Cpusets constrain the CPU and Memory |
| 761 | placement of a task to only the resources defined within that cpuset. These |
| 762 | cpusets can then be arranged into a nested hierarchy visible in the "cpuset" |
| 763 | virtual filesystem. Sets of tasks can be assigned to these cpusets to |
| 764 | constrain the resources that they use. The tasks can be moved from one cpuset |
| 765 | to another to utilize other resources defined in those other cpusets.</p></div> |
| 766 | <div class="paragraph"><p>The <strong>cset</strong> command is a Python application that provides a command line front |
| 767 | end for the Linux cpusets functionality. Working with cpusets directly can be |
| 768 | confusing and slightly complex. The <strong>cset</strong> tool hides that complexity behind |
| 769 | an easy-to-use command line interface.</p></div> |
| 770 | <div class="paragraph"><p>There are two distinct use cases for <strong>cset</strong>: the basic shielding use case and |
| 771 | the "advanced" case of using raw <code>set</code> and <code>proc</code> subcommands. The basic |
| 772 | shielding function is accessed with the <code>shield</code> subcommand and described in |
| 773 | the next section. Using the raw <code>set</code> and <code>proc</code> subcommands allows one to |
| 774 | set up arbitrarily complex cpusets and is described in the later sections.</p></div> |
| 775 | <div class="paragraph"><p>Note that in general, one either uses the <code>shield</code> subcommand <em>or</em> a |
| 776 | combination of the <code>set</code> and <code>proc</code> subcommands. One rarely, if ever, uses |
| 777 | all of these subcommands together. Doing so will likely become too |
| 778 | confusing. Additionally, the <code>shield</code> subcommand sets up its required cpusets |
| 779 | with exclusively marked CPUs. This can interfere with your cpuset |
| 780 | strategy. If you find that you need more functionality for your strategy than |
| 781 | <code>shield</code> provides, go ahead and transition to using <code>set</code> and <code>proc</code> |
| 782 | exclusively. It is straightforward to implement what <code>shield</code> does with a few |
| 783 | extra <code>set</code> and <code>proc</code> subcommands.</p></div> |
| 784 | <div class="sect2"> |
| 785 | <h3 id="_obtaining_online_help">1.1. Obtaining Online Help</h3> |
| 786 | <div class="dlist"><dl> |
| 787 | <dt class="hdlist1"> |
| 788 | For a full list of <strong>cset</strong> subcommands |
| 789 | </dt> |
| 790 | <dd> |
| 791 | <p> |
| 792 | <code># cset help</code> |
| 793 | </p> |
| 794 | </dd> |
| 795 | <dt class="hdlist1"> |
| 796 | For in-depth help on individual subcommands |
| 797 | </dt> |
| 798 | <dd> |
| 799 | <p> |
| 800 | <code># cset help <subcommand></code> |
| 801 | </p> |
| 802 | </dd> |
| 803 | <dt class="hdlist1"> |
| 804 | For options of individual subcommands |
| 805 | </dt> |
| 806 | <dd> |
| 807 | <p> |
| 808 | <code># cset <subcommand> (-h | --help)</code> |
| 809 | </p> |
| 810 | </dd> |
| 811 | </dl></div> |
| 812 | </div> |
| 813 | </div> |
| 814 | </div> |
| 815 | <div class="sect1"> |
| 816 | <h2 id="_the_basic_shielding_model">2. The Basic Shielding Model</h2> |
| 817 | <div class="sectionbody"> |
| 818 | <div class="paragraph"><p>Although any set up of cpusets can really be described as "shielding," there |
| 819 | is one prevalent shielding model in use that is so common that <strong>cset</strong> has a |
| 820 | subcommand that is dedicated to its use. This subcommand is called <code>shield</code>.</p></div> |
| 821 | <div class="paragraph"><p>The concept behind this model is the use of three cpusets. The <em>root</em> cpuset |
| 822 | which is always present in all configurations and contains all CPUs. The |
| 823 | <em>system</em> cpuset which contains CPUs which are used for system tasks. These |
| 824 | are the normal tasks that are not "important," but which need to run on the |
| 825 | system. And finally, the <em>user</em> cpuset which contains CPUs which are used for |
| 826 | "important" tasks. The <em>user</em> cpuset is the shield. Only those tasks that |
| 827 | are somehow important, usually tasks whose performance determines the overall |
| 828 | rating for the machine, are run in the <em>user</em> cpuset.</p></div> |
| 829 | <div class="paragraph"><p>The <code>shield</code> subcommand manages all of these cpusets and lets you define the |
| 830 | CPUs and Memory Nodes that are in the <em>shielded</em> and <em>unshielded</em> sets. The |
| 831 | subcommand automatically moves all movable tasks on the system into the |
| 832 | <em>unshielded</em> cpuset on shield activation, and back into the <em>root</em> cpuset on |
| 833 | shield tear down. The subcommand then lets you move tasks into and out of the |
| 834 | shield. Additionally, you can move special tasks (kernel threads) which |
| 835 | normally run in the <em>root</em> cpuset into the <em>unshielded</em> set so that your |
| 836 | shield will have even less disturbance.</p></div> |
| 837 | <div class="paragraph"><p>The <code>shield</code> subcommand abstracts the management of these cpusets away from |
| 838 | you and provides options that drive how the shield is set up, which tasks are |
| 839 | to be shielded and which tasks are not, and status of the shield. In fact, |
| 840 | you need not be bothered with the naming of the required cpusets or even where |
| 841 | the cpuset filesystem is mounted. <strong>Cset</strong> and the <code>shield</code> subcommand takes |
| 842 | care of all that.</p></div> |
| 843 | <div class="paragraph"><p>If you find yourself needing to define more cpusets for your application, then |
| 844 | it is likely that this simple shielding is not a rich enough model for you. |
| 845 | In this case, you should transition to using the <code>set</code> and <code>proc</code> subcommands |
| 846 | described in a later section.</p></div> |
| 847 | <div class="sect2"> |
| 848 | <h3 id="_a_simple_shielding_example">2.1. A Simple Shielding Example</h3> |
| 849 | <div class="paragraph"><p>Assume that we have a 4-way machine that is not NUMA. This means there are 4 |
| 850 | CPUs at our disposal and there is only one Memory Node available. On such |
| 851 | machines, we do not need to specify any memory node parameters to <strong>cset</strong>, it |
| 852 | sets up the only available memory node by default.</p></div> |
| 853 | <div class="paragraph"><p>Usually, one wants to dedicate as many CPUs to the shield as possible and |
| 854 | leave a minimal set of CPUs for normal system processing. The reasoning for |
| 855 | this is because the performance of the important tasks will rule the |
| 856 | performance of the installation as a whole and these important tasks need as |
| 857 | many resources available to them as possible, exclusive of other, unimportant |
| 858 | tasks that are running on the system.</p></div> |
| 859 | <div class="admonitionblock"> |
| 860 | <table><tr> |
| 861 | <td class="icon"> |
| 862 | <div class="title">Note</div> |
| 863 | </td> |
| 864 | <td class="content">I use the word "task" to represent either a process or a thread that is |
| 865 | running on the system.</td> |
| 866 | </tr></table> |
| 867 | </div> |
| 868 | <div class="sect3"> |
| 869 | <h4 id="_setup_and_teardown_of_the_shield">2.1.1. Setup and Teardown of the Shield</h4> |
| 870 | <div class="paragraph"><p>To set up a shield of 3 CPUs with 1 CPU left for low priority system |
| 871 | processing, issue the following command.</p></div> |
| 872 | <div class="listingblock"> |
| 873 | <div class="content"> |
| 874 | <pre><code>[zuul:cpuset-trunk]# cset shield -c 1-3 |
| 875 | cset: --> activating shielding: |
| 876 | cset: moving 176 tasks from root into system cpuset... |
| 877 | [==================================================]% |
| 878 | cset: "system" cpuset of CPUSPEC(0) with 176 tasks running |
| 879 | cset: "user" cpuset of CPUSPEC(1-3) with 0 tasks running</code></pre> |
| 880 | </div></div> |
| 881 | <div class="paragraph"><p>This command does a number of things. First, a <em>user</em> cpuset is created with |
| 882 | what’s called a CPUSPEC (CPU specification) from the <code>-c/--cpu</code> option. This |
| 883 | CPUSPEC specifies to use CPUs 1 through 3 inclusively. Next, the command |
| 884 | creates a <em>system</em> cpuset with a CPUSPEC that is the inverse of the <code>-c</code> |
| 885 | option for the current machine. On this machine that cpuset will only contain |
| 886 | the first CPU, CPU0. Next, all userspace processes running in the <em>root</em> |
| 887 | cpuset are transfered to the <em>system</em> cpuset. This makes all those processes |
| 888 | run only on CPU0. The effect of this is that the shield consists of CPUs 1 |
| 889 | through 3 and they are now idling.</p></div> |
| 890 | <div class="paragraph"><p>Note that the command did not move the kernel threads that are running in the |
| 891 | <em>root</em> cpuset to the <em>system</em> cpuset. This is because you may want these |
| 892 | kernel threads to use all available CPUs. If you do not, the you can use the |
| 893 | <code>-k/--kthread</code> option as described below.</p></div> |
| 894 | <div class="paragraph"><p>The shield setup command above outputs the information of which cpusets were |
| 895 | created and how many tasks are running on each. If you want to see the |
| 896 | current status of the shield again, issue this command:</p></div> |
| 897 | <div class="listingblock"> |
| 898 | <div class="content"> |
| 899 | <pre><code>[zuul:cpuset-trunk]# cset shield |
| 900 | cset: --> shielding system active with |
| 901 | cset: "system" cpuset of CPUSPEC(0) with 176 tasks running |
| 902 | cset: "user" cpuset of CPUSPEC(1-3) with 0 tasks running</code></pre> |
| 903 | </div></div> |
| 904 | <div class="paragraph"><p>Which shows us that the shield is set up and that 176 tasks are running in the |
| 905 | <em>system</em> cpuset—the "unshielded" cpuset.</p></div> |
| 906 | <div class="paragraph"><p>It is important to move all possible tasks from the <em>root</em> cpuset to the |
| 907 | unshielded <em>system</em> cpuset because a task’s cpuset property is inherited by |
| 908 | its children. Since we’ve moved all running tasks (including init) to the |
| 909 | unshielded <em>system</em> cpuset, that means that any new tasks that are spawned |
| 910 | will <strong>also</strong> run in the unshielded <em>system</em> cpuset.</p></div> |
| 911 | <div class="paragraph"><p>Some kernel threads can be moved into the unshielded <em>system</em> cpuset as well. |
| 912 | These are the threads that are not bound to specific CPUs. If a kernel thread |
| 913 | is bound to a specific CPU, then it is generally not a good idea to move that |
| 914 | thread to the <em>system</em> set because at worst it may hang the system and at best |
| 915 | it will slow the system down significantly. These threads are usually the IRQ |
| 916 | threads on a real time Linux kernel, for example, and you may want to not move |
| 917 | these kernel threads into <em>system</em>. If you leave them in the <em>root</em> cpuset, |
| 918 | then they will have access to all CPUs.</p></div> |
| 919 | <div class="paragraph"><p>However, if your application demands an even "quieter" shield, then you can |
| 920 | move all movable kernel threads into the unshielded <em>system</em> set with the |
| 921 | following command.</p></div> |
| 922 | <div class="listingblock"> |
| 923 | <div class="content"> |
| 924 | <pre><code>[zuul:cpuset-trunk]# cset shield -k on |
| 925 | cset: --> activating kthread shielding |
| 926 | cset: kthread shield activated, moving 70 tasks into system cpuset... |
| 927 | [==================================================]% |
| 928 | cset: done</code></pre> |
| 929 | </div></div> |
| 930 | <div class="paragraph"><p>You can see that this moved an additional 70 tasks to the unshielded <em>system</em> |
| 931 | cpuset. Note that the <code>-k/--kthread on</code> parameter can be given at the shield |
| 932 | creation time as well and you do not need to perform these two steps |
| 933 | separately if you know that you will want kernel thread shielding as well. |
| 934 | Executing <strong>cset shield</strong> again shows us the current state of the shield.</p></div> |
| 935 | <div class="listingblock"> |
| 936 | <div class="content"> |
| 937 | <pre><code>[zuul:cpuset-trunk]# cset shield |
| 938 | cset: --> shielding system active with |
| 939 | cset: "system" cpuset of CPUSPEC(0) with 246 tasks running |
| 940 | cset: "user" cpuset of CPUSPEC(1-3) with 0 tasks running</code></pre> |
| 941 | </div></div> |
| 942 | <div class="paragraph"><p>You can get a detailed listing of what is running in the shield by specifying |
| 943 | either <code>-s/--shield</code> or <code>-u/--unshield</code> to the <code>shield</code> subcommand and using |
| 944 | the verbose flag. You will get output similar to the following.</p></div> |
| 945 | <div class="listingblock"> |
| 946 | <div class="content"> |
| 947 | <pre><code>[zuul:cpuset-trunk]# cset shield --unshield -v |
| 948 | cset: "system" cpuset of CPUSPEC(0) with 251 tasks running |
| 949 | USER PID PPID SPPr TASK NAME |
| 950 | -------- ----- ----- ---- --------- |
| 951 | root 1 0 Soth init [5] |
| 952 | root 2 0 Soth [kthreadd] |
| 953 | root 84 2 Sf50 [IRQ-9] |
| 954 | ... |
| 955 | alext 31796 31789 Soth less |
| 956 | root 32653 25222 Roth python ./cset shield --unshield -v</code></pre> |
| 957 | </div></div> |
| 958 | <div class="paragraph"><p>Note that I abbreviated the listing; we do have 251 tasks running in the |
| 959 | <em>system</em> set. The output is self-explanatory; however, the "SPPr" field may |
| 960 | need a little explanation. "SPPr" stands for State, Policy and Priority. You |
| 961 | can see that the initial two tasks are Stopped and running in timeshare |
| 962 | priority, marked as "oth" (for "other"). The [IRQ-9] task is also stopped, |
| 963 | but marked at real time FIFO policy with a priority of 50. The last task in |
| 964 | the listing is the <strong>cset</strong> command itself and is marked as running. Also note |
| 965 | that adding a second <code>-v/--verbose</code> option will not restrict the output to |
| 966 | fit into an 80 character screen.</p></div> |
| 967 | <div class="paragraph"><p>Tear down of the shield, stopping the shield in other words, is done with the |
| 968 | <code>-r/--reset</code> option to the <code>shield</code> subcommand. When this command is issued, |
| 969 | both the <em>system</em> and <em>user</em> cpusets are deleted and any tasks that are |
| 970 | running in both of those cpusets are moved to the <em>root</em> cpuset. Once so |
| 971 | moved, all tasks will have access to all resources on the system. For |
| 972 | example:</p></div> |
| 973 | <div class="listingblock"> |
| 974 | <div class="content"> |
| 975 | <pre><code>[zuul:cpuset-trunk]# cset shield --reset |
| 976 | cset: --> deactivating/reseting shielding |
| 977 | cset: moving 0 tasks from "/user" user set to root set... |
| 978 | cset: moving 250 tasks from "/system" system set to root set... |
| 979 | [==================================================]% |
| 980 | cset: deleting "/user" and "/system" sets |
| 981 | cset: done</code></pre> |
| 982 | </div></div> |
| 983 | </div> |
| 984 | <div class="sect3"> |
| 985 | <h4 id="_moving_interesting_tasks_into_and_out_of_the_shield">2.1.2. Moving Interesting Tasks Into and Out of the Shield</h4> |
| 986 | <div class="paragraph"><p>Now that we have a shield running, the objective is to run our "important" |
| 987 | processes in that shield. These processes can be anything, but usually they |
| 988 | are directly related to the purpose of the machine. There are two ways to run |
| 989 | tasks in the shield:</p></div> |
| 990 | <div class="olist arabic"><ol class="arabic"> |
| 991 | <li> |
| 992 | <p> |
| 993 | Exec a process into the shield |
| 994 | </p> |
| 995 | </li> |
| 996 | <li> |
| 997 | <p> |
| 998 | Move an already running task into the shield |
| 999 | </p> |
| 1000 | </li> |
| 1001 | </ol></div> |
| 1002 | <div class="sect4"> |
| 1003 | <h5 id="_execing_a_process_into_the_shield">Execing a Process into the Shield</h5> |
| 1004 | <div class="paragraph"><p>Running a new process in the shield can be done with the <code>-e/--exec</code> option |
| 1005 | to the <code>shield</code> subcommand. This is the simplest way to get a task to run in |
| 1006 | the shield. For this example, let’s exec a new bash shell into the shield |
| 1007 | with the following commands.</p></div> |
| 1008 | <div class="listingblock"> |
| 1009 | <div class="content"> |
| 1010 | <pre><code>[zuul:cpuset-trunk]# cset shield -s |
| 1011 | cset: "user" cpuset of CPUSPEC(1-3) with 0 tasks running |
| 1012 | cset: done |
| 1013 | |
| 1014 | [zuul:cpuset-trunk]# cset shield -e bash |
| 1015 | cset: --> last message, executed args into cpuset "/user", new pid is: 13300 |
| 1016 | |
| 1017 | [zuul:cpuset-trunk]# cset shield -s -v |
| 1018 | cset: "user" cpuset of CPUSPEC(1-3) with 2 tasks running |
| 1019 | USER PID PPID SPPr TASK NAME |
| 1020 | -------- ----- ----- ---- --------- |
| 1021 | root 13300 8583 Soth bash |
| 1022 | root 13329 13300 Roth python ./cset shield -s -v |
| 1023 | |
| 1024 | [zuul:cpuset-trunk]# exit |
| 1025 | |
| 1026 | [zuul:cpuset-trunk]# cset shield -s |
| 1027 | cset: "user" cpuset of CPUSPEC(1-3) with 0 tasks running |
| 1028 | cset: done</code></pre> |
| 1029 | </div></div> |
| 1030 | <div class="paragraph"><p>The first command above lists the status of the shield. We see that the |
| 1031 | shield is defined as CPUs 1 through 3 inclusive and currently there are no |
| 1032 | tasks running in it.</p></div> |
| 1033 | <div class="paragraph"><p>The second command execs the bash shell into the shield with the <code>-e</code> |
| 1034 | option. The last message of cset lists the PID of the new process.</p></div> |
| 1035 | <div class="admonitionblock"> |
| 1036 | <table><tr> |
| 1037 | <td class="icon"> |
| 1038 | <div class="title">Note</div> |
| 1039 | </td> |
| 1040 | <td class="content"><strong>cset</strong> follows the tradition of separating the tool options from the |
| 1041 | command to be execed options with a double dash (<code>--</code>). This is not shown in |
| 1042 | this simple example, but if the command you want to exec also takes options, |
| 1043 | separate them with the double dash like so: <code># cset shield -e mycommand -- -v</code> |
| 1044 | The <code>-v</code> will be passed to <code>mycommand</code>, and not to <strong>cset</strong>.</td> |
| 1045 | </tr></table> |
| 1046 | </div> |
| 1047 | <div class="paragraph"><p>The next command lists the status of the shield again. You will note that |
| 1048 | there are actually two tasks running shielded: our new shell and the <strong>cset</strong> |
| 1049 | status command itself. Remember that the cpuset property of a task is |
| 1050 | inherited by its children. Since we ran the new shell in the shield, its |
| 1051 | child, which is the status command, also ran in the shield.</p></div> |
| 1052 | <div class="admonitionblock"> |
| 1053 | <table><tr> |
| 1054 | <td class="icon"> |
| 1055 | <div class="title">Tip</div> |
| 1056 | </td> |
| 1057 | <td class="content">Execing a shell into the shield is a useful way to experiment with |
| 1058 | running tasks in the shield since all children of the shell will also run in |
| 1059 | the shield.</td> |
| 1060 | </tr></table> |
| 1061 | </div> |
| 1062 | <div class="paragraph"><p>The last command exits the shell after which we request a shield status again |
| 1063 | and see that once again, it does not contain any tasks.</p></div> |
| 1064 | <div class="paragraph"><p>You may have noticed in the output above that both the new shell and the |
| 1065 | status command are running as the root user. This is because <strong>cset</strong> needs to |
| 1066 | run as root and so all it’s children will also run as root. If you need to |
| 1067 | run a process under a different user and or group, you may use the <code>--user</code> |
| 1068 | and <code>--group</code> options for <code>exec</code> as follows.</p></div> |
| 1069 | <div class="listingblock"> |
| 1070 | <div class="content"> |
| 1071 | <pre><code>[zuul:cpuset-trunk]# cset shield --user=alext --group=users -e bash |
| 1072 | cset: --> last message, executed args into cpuset "/user", new pid is: 14212 |
| 1073 | |
| 1074 | alext@zuul> cset shield -s -v |
| 1075 | cset: "user" cpuset of CPUSPEC(1-3) with 2 tasks running |
| 1076 | USER PID PPID SPPr TASK NAME |
| 1077 | -------- ----- ----- ---- --------- |
| 1078 | alext 14212 8583 Soth bash |
| 1079 | alext 14241 14212 Roth python ./cset shield -s -v</code></pre> |
| 1080 | </div></div> |
| 1081 | </div> |
| 1082 | <div class="sect4"> |
| 1083 | <h5 id="_moving_a_running_task_into_and_out_of_the_shield">Moving a Running Task into and out of the Shield</h5> |
| 1084 | <div class="paragraph"><p>While execing a process into the shield is undoubtably useful, most of the |
| 1085 | time, you’ll want to move already running tasks into and out of the shield. |
| 1086 | The <strong>cset</strong> shield subcommand includes two options for doing this: |
| 1087 | <code>-s/--shield</code> and <code>-u/--unshield</code>. These options require what’s called a |
| 1088 | PIDSPEC (process specification) to also be specified with the <code>-p/--pid</code> |
| 1089 | option. The PIDSPEC defines which tasks get operated on. The PIDSPEC can be |
| 1090 | a single process ID, a list of process IDs separated by commas, and a list of |
| 1091 | process ID ranges separated by dashes, groups of which are separated by |
| 1092 | commas. For example:</p></div> |
| 1093 | <div class="dlist"><dl> |
| 1094 | <dt class="hdlist1"> |
| 1095 | <code>--shield --pid 1234</code> |
| 1096 | </dt> |
| 1097 | <dd> |
| 1098 | <p> |
| 1099 | This PIDSPEC argument specifies that PID 1234 be shielded. |
| 1100 | </p> |
| 1101 | </dd> |
| 1102 | <dt class="hdlist1"> |
| 1103 | <code>--shield --pid 1234,42,1934,15000,15001,15002</code> |
| 1104 | </dt> |
| 1105 | <dd> |
| 1106 | <p> |
| 1107 | This PIDSPEC argument specifies that this list of PIDs only be moved into the |
| 1108 | shield. |
| 1109 | </p> |
| 1110 | </dd> |
| 1111 | <dt class="hdlist1"> |
| 1112 | <code>--unshield -p 5000,5100,6010-7000,9232</code> |
| 1113 | </dt> |
| 1114 | <dd> |
| 1115 | <p> |
| 1116 | This PIDSPEC argument specifies that PIDs 5000,5100 and 9232 be unshielded |
| 1117 | (moved out of the shield) along with any existing PID that is in the range |
| 1118 | 6010 through 7000 inclusive. |
| 1119 | </p> |
| 1120 | </dd> |
| 1121 | </dl></div> |
| 1122 | <div class="admonitionblock"> |
| 1123 | <table><tr> |
| 1124 | <td class="icon"> |
| 1125 | <div class="title">Note</div> |
| 1126 | </td> |
| 1127 | <td class="content">A range in a PIDSPEC does not have to have tasks running for every |
| 1128 | number in that range. In fact, it is not even an error if there are no tasks |
| 1129 | running in that range; none will be moved in that case. The range simply |
| 1130 | specifies to act on any tasks that have a PID or TID that is within that |
| 1131 | range.</td> |
| 1132 | </tr></table> |
| 1133 | </div> |
| 1134 | <div class="paragraph"><p>Use of the appropriate PIDSPEC can thus be handy to move tasks and groups of |
| 1135 | tasks into and out of the shield. Additionally, there is one more option that |
| 1136 | can help with multi-threaded processes, and that is the <code>--threads</code> flag. If |
| 1137 | this flag is present in a <code>shield</code> or <code>unshield</code> command with a PIDSPEC and if |
| 1138 | any of the task IDs in the PIDSPEC belong to a thread in a process container, |
| 1139 | then <strong>all</strong> the sibling threads in that process container will get shielded or |
| 1140 | unshielded as well. This flag provides an easy mechanism to shield/unshield |
| 1141 | all threads of a process by simply specifying one thread in that process.</p></div> |
| 1142 | <div class="paragraph"><p>In the following example, we move the current shell into the shield with a |
| 1143 | range PIDSPEC and back out with the bash variable for the current PID.</p></div> |
| 1144 | <div class="listingblock"> |
| 1145 | <div class="content"> |
| 1146 | <pre><code>[zuul:cpuset-trunk]# echo $$ |
| 1147 | 22018 |
| 1148 | |
| 1149 | [zuul:cpuset-trunk]# cset shield -s -p 22010-22020 |
| 1150 | cset: --> shielding following pidspec: 22010-22020 |
| 1151 | cset: done |
| 1152 | |
| 1153 | [zuul:cpuset-trunk]# cset shield -s -v |
| 1154 | cset: "user" cpuset of CPUSPEC(1-3) with 2 tasks running |
| 1155 | USER PID PPID SPPr TASK NAME |
| 1156 | -------- ----- ----- ---- --------- |
| 1157 | root 3770 22018 Roth python ./cset shield -s -v |
| 1158 | root 22018 5034 Soth bash |
| 1159 | cset: done |
| 1160 | |
| 1161 | [zuul:cpuset-trunk]# cset shield -u -p $$ |
| 1162 | cset: --> unshielding following pidspec: 22018 |
| 1163 | cset: done |
| 1164 | |
| 1165 | [zuul:cpuset-trunk]# cset shield -s |
| 1166 | cset: "user" cpuset of CPUSPEC(1-3) with 0 tasks running |
| 1167 | cset: done</code></pre> |
| 1168 | </div></div> |
| 1169 | <div class="admonitionblock"> |
| 1170 | <table><tr> |
| 1171 | <td class="icon"> |
| 1172 | <div class="title">Note</div> |
| 1173 | </td> |
| 1174 | <td class="content">Ordinarily, the <code>shield</code> option will shield a PIDSPEC only if it is |
| 1175 | currently running in the <em>system</em> set—the unshielded set. The <code>unshield</code> |
| 1176 | option will unshield a PIDSPEC only if it is currently running in the <em>user</em> |
| 1177 | set—the shielded set. If you want to <code>shield/unshield</code> a process that |
| 1178 | happens to be running in the <em>root</em> set (not common), then use the <code>--force</code> |
| 1179 | option for these commands.</td> |
| 1180 | </tr></table> |
| 1181 | </div> |
| 1182 | </div> |
| 1183 | </div> |
| 1184 | </div> |
| 1185 | </div> |
| 1186 | </div> |
| 1187 | <div class="sect1"> |
| 1188 | <h2 id="_full_featured_cpuset_manipulation_commands">3. Full Featured Cpuset Manipulation Commands</h2> |
| 1189 | <div class="sectionbody"> |
| 1190 | <div class="paragraph"><p>While basic shielding as described above is useful and a common use model for |
| 1191 | <strong>cset</strong>, there comes a time when more functionality will be desired to |
| 1192 | implement your strategy. To implement this, <strong>cset</strong> provides two subcommands: |
| 1193 | <code>set</code>, which allows you to manipulate cpusets; and <code>proc</code>, which allows you to |
| 1194 | manipulate processes within those cpusets.</p></div> |
| 1195 | <div class="sect2"> |
| 1196 | <h3 id="_the_set_subcommand">3.1. The Set Subcommand</h3> |
| 1197 | <div class="paragraph"><p>In order to do anything with cpusets, you must be able to create, adjust, |
| 1198 | rename, move and destroy them. The <code>set</code> subcommand allows the management of |
| 1199 | cpusets in such a manner.</p></div> |
| 1200 | <div class="sect3"> |
| 1201 | <h4 id="_creating_and_destroying_cpusets_with_set">3.1.1. Creating and Destroying Cpusets with Set</h4> |
| 1202 | <div class="paragraph"><p>The basic syntax of <code>set</code> for cpuset creation is:</p></div> |
| 1203 | <div class="listingblock"> |
| 1204 | <div class="content"> |
| 1205 | <pre><code>[zuul:cpuset-trunk]# cset set -c 1-3 -s my_cpuset1 |
| 1206 | cset: --> created cpuset "my_cpuset1"</code></pre> |
| 1207 | </div></div> |
| 1208 | <div class="paragraph"><p>This creates a cpuset named "my_cpuset1" with a CPUSPEC of CPU1, CPU2 and |
| 1209 | CPU3. The CPUSPEC is the same concept as described in the "Setup and |
| 1210 | Teardown of the Shield" section above. The <code>set</code> subcommand also takes a |
| 1211 | <code>-m/--mem</code> option that lets you specify the memory nodes the set will use as |
| 1212 | well as flags to make the CPUs and MEMs exclusive to the cpuset. If you are |
| 1213 | on a non-NUMA machine, just leave the <code>-m</code> option out and the default memory |
| 1214 | node 0 will be used.</p></div> |
| 1215 | <div class="paragraph"><p>Just like with <code>shield</code>, you can adjust the CPUs and MEMs with subsequent |
| 1216 | calls to <code>set</code>. If, for example, you wish to adjust the "my_cpuset1" cpuset |
| 1217 | to only use CPUs 1 and 3 (and omit CPU2), then issue the following command.</p></div> |
| 1218 | <div class="listingblock"> |
| 1219 | <div class="content"> |
| 1220 | <pre><code>[zuul:cpuset-trunk]# cset set -c 1,3 -s my_cpuset1 |
| 1221 | cset: --> modified cpuset "my_cpuset</code></pre> |
| 1222 | </div></div> |
| 1223 | <div class="paragraph"><p><strong>cset</strong> will then adjust the CPUs that are assigned to the "my_cpuset1" set to |
| 1224 | only use CPU1 and CPU3.</p></div> |
| 1225 | <div class="paragraph"><p>To rename a cpuset, use the <code>-n/--newname</code> option. For example:</p></div> |
| 1226 | <div class="listingblock"> |
| 1227 | <div class="content"> |
| 1228 | <pre><code>[zuul:cpuset-trunk]# cset set -s my_cpuset1 -n super_set |
| 1229 | cset: --> renaming "/cpusets/my_cpuset1" to "super_set"</code></pre> |
| 1230 | </div></div> |
| 1231 | <div class="paragraph"><p>Renames the cpuset called "my_cpuset1" to "super_set".</p></div> |
| 1232 | <div class="paragraph"><p>To destroy a cpuset, use the <code>-d/--destroy</code> option as follows.</p></div> |
| 1233 | <div class="listingblock"> |
| 1234 | <div class="content"> |
| 1235 | <pre><code>[zuul:cpuset-trunk]# cset set -d super_set |
| 1236 | cset: --> processing cpuset "super_set", moving 0 tasks to parent "/"... |
| 1237 | cset: --> deleting cpuset "/super_set" |
| 1238 | cset: done</code></pre> |
| 1239 | </div></div> |
| 1240 | <div class="paragraph"><p>This command destroys the newly created cpuset called "super_set". When a |
| 1241 | cpuset is destroyed, all the tasks running in it are moved to the parent |
| 1242 | cpuset. The <em>root</em> cpuset, which always exists and always contains all CPUs, |
| 1243 | can not be destroyed. You may also give the <code>--destroy</code> option a list of |
| 1244 | cpusets to destroy.</p></div> |
| 1245 | <div class="admonitionblock"> |
| 1246 | <table><tr> |
| 1247 | <td class="icon"> |
| 1248 | <div class="title">Note</div> |
| 1249 | </td> |
| 1250 | <td class="content">The <strong>cset</strong> subcommand creates the cpusets based on a mounted cpuset |
| 1251 | filesystem. You do not need to know where that filesystem is mounted, |
| 1252 | although it is easy to figure out (by default it’s on <em>/cpusets</em>). When you |
| 1253 | give the <code>set</code> subcommand a name for a new cpuset, it is created wherever the |
| 1254 | cpuset filesystem is mounted at.</td> |
| 1255 | </tr></table> |
| 1256 | </div> |
| 1257 | <div class="paragraph"><p>If you want to create a cpuset hierarchy, then you must give a path to the |
| 1258 | <strong>cset</strong> <code>set</code> subcommand. This path will always begin with the <em>root</em> cpuset, |
| 1259 | for which the path is <em>/</em>. For example.</p></div> |
| 1260 | <div class="listingblock"> |
| 1261 | <div class="content"> |
| 1262 | <pre><code>[zuul:cpuset-trunk]# cset set -c 1,3 -s top_set |
| 1263 | cset: --> created cpuset "top_set" |
| 1264 | |
| 1265 | [zuul:cpuset-trunk]# cset set -c 3 -s /top_set/sub_set |
| 1266 | cset: --> created cpuset "/top_set/sub_set"</code></pre> |
| 1267 | </div></div> |
| 1268 | <div class="paragraph"><p>These commands created two cpusets: <em>top_set</em> and <em>sub_set</em>. The <em>top_set</em> |
| 1269 | uses CPU1 and CPU3. It has a subset of <em>sub_set</em> which only uses CPU3. Once |
| 1270 | you have created a subset with a path, then if the name is unique, you do not |
| 1271 | have to specify the path in order to affect it. If the name is not unique, |
| 1272 | then <strong>cset</strong> will complain and ask you to use the path. For example:</p></div> |
| 1273 | <div class="listingblock"> |
| 1274 | <div class="content"> |
| 1275 | <pre><code>[zuul:cpuset-trunk]# cset set -c 1,3 -s sub_set |
| 1276 | cset: --> modified cpuset "sub_set</code></pre> |
| 1277 | </div></div> |
| 1278 | <div class="paragraph"><p>This command adds CPU1 to the <em>sub_set</em> cpuset for it’s use. Note that using |
| 1279 | the path in this case is optional.</p></div> |
| 1280 | <div class="paragraph"><p>If you attempt to destroy a cpuset which has sub-cpusets, <strong>cset</strong> will complain |
| 1281 | and not do it unless you use the <code>-r/--recurse</code> and the <code>--force</code> options. |
| 1282 | If you do use <code>--force</code>, then all the tasks running in all subsets of the |
| 1283 | deletion target cpuset will be moved to the target’s parent cpuset and all |
| 1284 | cpusets.</p></div> |
| 1285 | <div class="paragraph"><p>Moving a cpuset from under a certain cpuset to a different location is |
| 1286 | currently not implemented and is slated for a later release of <strong>cset</strong>.</p></div> |
| 1287 | </div> |
| 1288 | <div class="sect3"> |
| 1289 | <h4 id="_listing_cpusets_with_set">3.1.2. Listing Cpusets with Set</h4> |
| 1290 | <div class="paragraph"><p>To list cpusets, use the <code>set</code> subcommand with the <em>-l/--list</em> option. For |
| 1291 | example:</p></div> |
| 1292 | <div class="listingblock"> |
| 1293 | <div class="content"> |
| 1294 | <pre><code>[zuul:cpuset-trunk]# cset set -l |
| 1295 | cset: |
| 1296 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1297 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1298 | root 0-3 y 0 y 320 1 / |
| 1299 | one 3 n 0 n 0 1 /one</code></pre> |
| 1300 | </div></div> |
| 1301 | <div class="paragraph"><p>This shows that there is currently one cpuset present called <em>one</em>. (Of course |
| 1302 | that there is also the <em>root</em> set, which is always present.) The output shows |
| 1303 | that the <em>one</em> cpuset has no tasks running in it. The <em>root</em> cpuset has 320 |
| 1304 | tasks running. The "-X" for "CPUs" and "MEMs" fields denotes whether the CPUs |
| 1305 | and MEMs in the cpusets are marked exclusive to those cpusets. Note that the |
| 1306 | <em>one</em> cpuset has subsets as indicated by a 1 in the <em>Subs</em> field. You can |
| 1307 | specify a cpuset to list with the <code>set</code> subcommand as follows.</p></div> |
| 1308 | <div class="listingblock"> |
| 1309 | <div class="content"> |
| 1310 | <pre><code>[zuul:cpuset-trunk]# cset set -l -s one |
| 1311 | cset: |
| 1312 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1313 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1314 | one 3 n 0 n 0 1 /one |
| 1315 | two 3 n 0 n 0 1 /one/two</code></pre> |
| 1316 | </div></div> |
| 1317 | <div class="paragraph"><p>This output shows that there is a cpuset called <em>two</em> in cpuset <em>one</em> and it |
| 1318 | also has subset. You can also ask for a recursive listing as follows.</p></div> |
| 1319 | <div class="listingblock"> |
| 1320 | <div class="content"> |
| 1321 | <pre><code>[zuul:cpuset-trunk]# cset set -l -r |
| 1322 | cset: |
| 1323 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1324 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1325 | root 0-3 y 0 y 320 1 / |
| 1326 | one 3 n 0 n 0 1 /one |
| 1327 | two 3 n 0 n 0 1 /one/two |
| 1328 | three 3 n 0 n 0 0 /one/two/three</code></pre> |
| 1329 | </div></div> |
| 1330 | <div class="paragraph"><p>This command lists all cpusets existing on the system since it asks for a |
| 1331 | recursive listing beginning at the <em>root</em> cpuset. Incidentally, should you |
| 1332 | need to specify the <em>root</em> cpuset you can use either <code>root</code> or <code>/</code> to specify it |
| 1333 | explicitely—just remember that the <em>root</em> cpuset cannot be deleted or modified.</p></div> |
| 1334 | </div> |
| 1335 | </div> |
| 1336 | <div class="sect2"> |
| 1337 | <h3 id="_the_proc_subcommand">3.2. The Proc Subcommand</h3> |
| 1338 | <div class="paragraph"><p>Now that we know how to create, rename and destroy cpusets with the <code>set</code> |
| 1339 | subcommand, the next step is to manage threads and processes in those |
| 1340 | cpusets. The subcommand to do this is called <code>proc</code> and it allows you to exec |
| 1341 | processes into a cpuset, move existing tasks around existing cpusets, and list |
| 1342 | tasks running in specified cpusets. For the following examples, let us |
| 1343 | assume a cpuset setup of two sets as follows:</p></div> |
| 1344 | <div class="listingblock"> |
| 1345 | <div class="content"> |
| 1346 | <pre><code>[zuul:cpuset-trunk]# cset set -l |
| 1347 | cset: |
| 1348 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1349 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1350 | root 0-3 y 0 y 309 2 / |
| 1351 | two 2 n 0 n 3 0 /two |
| 1352 | three 3 n 0 n 10 0 /three</code></pre> |
| 1353 | </div></div> |
| 1354 | <div class="sect3"> |
| 1355 | <h4 id="_listing_tasks_with_proc">3.2.1. Listing Tasks with Proc</h4> |
| 1356 | <div class="paragraph"><p>Operation of the <code>proc</code> subcommand follows the same model as the <code>set</code> |
| 1357 | subcommand. For example, to list tasks in a cpuset, you need to use the |
| 1358 | <code>-l/--list</code> option and specify the cpuset by name or, if the name exists |
| 1359 | multiple times in the cpuset hierarchy, by path. For example:</p></div> |
| 1360 | <div class="listingblock"> |
| 1361 | <div class="content"> |
| 1362 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s two |
| 1363 | cset: "two" cpuset of CPUSPEC(2) with 3 tasks running |
| 1364 | USER PID PPID SPPr TASK NAME |
| 1365 | -------- ----- ----- ---- --------- |
| 1366 | root 16141 4300 Soth bash |
| 1367 | root 16171 16141 Soth bash |
| 1368 | root 16703 16171 Roth python ./cset proc -l two</code></pre> |
| 1369 | </div></div> |
| 1370 | <div class="paragraph"><p>This output shows us that the cpuset called <em>two</em> has CPU2 only attached to it |
| 1371 | and is running three tasks: two shells and the python command to list it. |
| 1372 | Note that cpusets are inherited so that if a process is contained in a cpuset, |
| 1373 | then any children it spawns also run within that set. In this case, the |
| 1374 | python command to list set <em>two</em> was run from a shell already running in set |
| 1375 | <em>two</em>. This can be seen by the PPID (parent process ID) of the python |
| 1376 | command matching the PID of the shell.</p></div> |
| 1377 | <div class="paragraph"><p>Additionally, the "SPPr" field needs explanation. "SPPr" stands for State, |
| 1378 | Policy and Priority. You can see that the initial two tasks are Stopped and |
| 1379 | running in timeshare priority, marked as "oth" (for "other"). The last task |
| 1380 | is marked as running, "R" and also at timeshare priority, "oth." If any of |
| 1381 | these tasks would have been at real time priority, then the policy would be |
| 1382 | shown as "f" for FIFO or "r" for round robin, and the priority would be a |
| 1383 | number from 1 to 99. See below for an example.</p></div> |
| 1384 | <div class="listingblock"> |
| 1385 | <div class="content"> |
| 1386 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s root | head -7 |
| 1387 | cset: "root" cpuset of CPUSPEC(0-3) with 309 tasks running |
| 1388 | USER PID PPID SPPr TASK NAME |
| 1389 | -------- ----- ----- ---- --------- |
| 1390 | root 1 0 Soth init [5] |
| 1391 | root 2 0 Soth [kthreadd] |
| 1392 | root 3 2 Sf99 [migration/0] |
| 1393 | root 4 2 Sf99 [posix_cpu_timer]</code></pre> |
| 1394 | </div></div> |
| 1395 | <div class="paragraph"><p>This output shows the first few tasks in the <em>root</em> cpuset. Note that both |
| 1396 | <em>init</em> and <em>[kthread]</em> are running at timeshare; however, the <em>[migration/0]</em> |
| 1397 | and <em>[posix_cpu_timer]</em> kernel threads are running at real time policy of FIFO |
| 1398 | and priority of 99. Incidentally, this output is from a system running the |
| 1399 | real time Linux kernel which runs some kernel threads at real time |
| 1400 | priorities. And finally, note that you can of course use <strong>cset</strong> as any other |
| 1401 | Linux tool and include it in pipelines as in the example above.</p></div> |
| 1402 | <div class="paragraph"><p>Taking a peek into the third cpuset called <em>three</em>, we see:</p></div> |
| 1403 | <div class="listingblock"> |
| 1404 | <div class="content"> |
| 1405 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s three |
| 1406 | cset: "three" cpuset of CPUSPEC(3) with 10 tasks running |
| 1407 | USER PID PPID SPPr TASK NAME |
| 1408 | -------- ----- ----- ---- --------- |
| 1409 | alext 16165 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1410 | alext 16169 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1411 | alext 16170 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1412 | alext 16237 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1413 | alext 16491 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1414 | alext 16492 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1415 | alext 16493 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1416 | alext 17243 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1417 | alext 17244 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1418 | alext 17265 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -...</code></pre> |
| 1419 | </div></div> |
| 1420 | <div class="paragraph"><p>This output shows that a lot of <em>beagled</em> tasks are running in this cpuset and |
| 1421 | it also shows an ellipsis (…) at the end of their listings. If you see this |
| 1422 | ellipsis, that means that the command was too long to fit onto an 80 character |
| 1423 | screen. To see the entire commandline, use the <code>-v/--verbose</code> flag, as per |
| 1424 | following.</p></div> |
| 1425 | <div class="listingblock"> |
| 1426 | <div class="content"> |
| 1427 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s three -v | head -4 |
| 1428 | cset: "three" cpuset of CPUSPEC(3) with 10 tasks running |
| 1429 | USER PID PPID SPPr TASK NAME |
| 1430 | -------- ----- ----- ---- --------- |
| 1431 | alext 16165 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg --autostarted --indexing-delay 300</code></pre> |
| 1432 | </div></div> |
| 1433 | </div> |
| 1434 | <div class="sect3"> |
| 1435 | <h4 id="_execing_tasks_with_proc">3.2.2. Execing Tasks with Proc</h4> |
| 1436 | <div class="paragraph"><p>To exec a task into a cpuset, the <code>proc</code> subcommand needs to be employed with |
| 1437 | the <code>-e/--exec</code> option. Let’s exec a shell into the cpuset named <em>two</em> in |
| 1438 | our set. First we check to see what is running that set:</p></div> |
| 1439 | <div class="listingblock"> |
| 1440 | <div class="content"> |
| 1441 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s two |
| 1442 | cset: "two" cpuset of CPUSPEC(2) with 0 tasks running |
| 1443 | |
| 1444 | [zuul:cpuset-trunk]# cset proc -s two -e bash |
| 1445 | cset: --> last message, executed args into cpuset "/two", new pid is: 20955 |
| 1446 | |
| 1447 | [zuul:cpuset-trunk]# cset proc -l -s two |
| 1448 | cset: "two" cpuset of CPUSPEC(2) with 2 tasks running |
| 1449 | USER PID PPID SPPr TASK NAME |
| 1450 | -------- ----- ----- ---- --------- |
| 1451 | root 20955 19253 Soth bash |
| 1452 | root 20981 20955 Roth python ./cset proc -l two</code></pre> |
| 1453 | </div></div> |
| 1454 | <div class="paragraph"><p>You can see that initially, <em>two</em> had nothing running in it. After the |
| 1455 | completion of the second command, we list <em>two</em> again and see that there are |
| 1456 | two tasks running: the shell which we execed and the python <strong>cset</strong> command |
| 1457 | that is listing the cpuset. The reason for the second task is that the cpuset |
| 1458 | property of a running task is inherited by all its children. Since we |
| 1459 | executed the listing command from the new shell which was bound to cpuset |
| 1460 | <em>two</em>, the resulting process for the listing is also bound to cpuset <em>two</em>. |
| 1461 | Let’s test that by just running a new shell with no prefixed <strong>cset</strong> command.</p></div> |
| 1462 | <div class="listingblock"> |
| 1463 | <div class="content"> |
| 1464 | <pre><code>[zuul:cpuset-trunk]# bash |
| 1465 | |
| 1466 | [zuul:cpuset-trunk]# cset proc -l -s two |
| 1467 | cset: "two" cpuset of CPUSPEC(2) with 3 tasks running |
| 1468 | USER PID PPID SPPr TASK NAME |
| 1469 | -------- ----- ----- ---- --------- |
| 1470 | root 20955 19253 Soth bash |
| 1471 | root 21118 20955 Soth bash |
| 1472 | root 21147 21118 Roth python ./cset proc -l two</code></pre> |
| 1473 | </div></div> |
| 1474 | <div class="paragraph"><p>Here again we see that the second shell, PID 21118, has a parent PID of 20955 |
| 1475 | which is the first shell. Both shells as well as the listing command are |
| 1476 | running in the <em>two</em> cpuset.</p></div> |
| 1477 | <div class="admonitionblock"> |
| 1478 | <table><tr> |
| 1479 | <td class="icon"> |
| 1480 | <div class="title">Note</div> |
| 1481 | </td> |
| 1482 | <td class="content"><strong>cset</strong> follows the tradition of separating the tool options from the |
| 1483 | command to be execed options with a double dash (<code>--</code>). This is not shown in |
| 1484 | this simple example, but if the command you want to exec also takes options, |
| 1485 | separate them with the double dash like so: <code># cset proc -s myset -e mycommand |
| 1486 | -- -v</code> The <code>-v</code> will be passed to <code>mycommand</code>, and not to <strong>cset</strong>.</td> |
| 1487 | </tr></table> |
| 1488 | </div> |
| 1489 | <div class="admonitionblock"> |
| 1490 | <table><tr> |
| 1491 | <td class="icon"> |
| 1492 | <div class="title">Tip</div> |
| 1493 | </td> |
| 1494 | <td class="content">Execing a shell into a cpuset is a useful way to experiment with running |
| 1495 | tasks in that cpuset since all children of the shell will also run in the same |
| 1496 | cpuset.</td> |
| 1497 | </tr></table> |
| 1498 | </div> |
| 1499 | <div class="paragraph"><p>Finally, if you misspell the command to be execed, the result may be |
| 1500 | puzzling. For example:</p></div> |
| 1501 | <div class="listingblock"> |
| 1502 | <div class="content"> |
| 1503 | <pre><code>[zuul:cpuset-trunk]# cset proc -s two -e blah-blah |
| 1504 | cset: --> last message, executed args into cpuset "/two", new pid is: 21655 |
| 1505 | cset: **> [Errno 2] No such file or directory</code></pre> |
| 1506 | </div></div> |
| 1507 | <div class="paragraph"><p>The result is no new process even though a new PID is output. The reason for |
| 1508 | the message is of course that the <strong>cset</strong> process forked in preparation for |
| 1509 | exec, but the command <code>blah-blah</code> was not found in order to exec it.</p></div> |
| 1510 | </div> |
| 1511 | <div class="sect3"> |
| 1512 | <h4 id="_moving_tasks_with_proc">3.2.3. Moving Tasks with Proc</h4> |
| 1513 | <div class="paragraph"><p>Although the ability to exec a task into a cpuset is fundamental, you will |
| 1514 | most likely be moving tasks between cpusets more often. Moving tasks is |
| 1515 | accomplished with the <code>-m/--move</code> and <code>-p/--pid</code> options to the <code>proc</code> |
| 1516 | subcommand of <strong>cset</strong>. The move option tells the <code>proc</code> subcommand that a task |
| 1517 | move is requested. The <code>-p/--pid</code> option takes an argument called a PIDSPEC |
| 1518 | (PID Specification). The PIDSPEC defines which tasks get operated on.</p></div> |
| 1519 | <div class="paragraph"><p>The PIDSPEC can be a single process ID, a list of process IDs separated by |
| 1520 | commas, and a list of process ID ranges also separated by commas. For |
| 1521 | example:</p></div> |
| 1522 | <div class="dlist"><dl> |
| 1523 | <dt class="hdlist1"> |
| 1524 | <code>--move --pid 1234</code> |
| 1525 | </dt> |
| 1526 | <dd> |
| 1527 | <p> |
| 1528 | This PIDSPEC argument specifies that task 1234 be moved. |
| 1529 | </p> |
| 1530 | </dd> |
| 1531 | <dt class="hdlist1"> |
| 1532 | <code>--move --pid 1234,42,1934,15000,15001,15002</code> |
| 1533 | </dt> |
| 1534 | <dd> |
| 1535 | <p> |
| 1536 | This PIDSPEC argument specifies that this list of tasks only be moved. |
| 1537 | </p> |
| 1538 | </dd> |
| 1539 | <dt class="hdlist1"> |
| 1540 | <code>--move --pid 5000,5100,6010-7000,9232</code> |
| 1541 | </dt> |
| 1542 | <dd> |
| 1543 | <p> |
| 1544 | This PIDSPEC argument specifies that tasks 5000,5100 and 9232 be moved along |
| 1545 | with any existing task that is in the range 6010 through 7000 inclusive. |
| 1546 | </p> |
| 1547 | </dd> |
| 1548 | </dl></div> |
| 1549 | <div class="admonitionblock"> |
| 1550 | <table><tr> |
| 1551 | <td class="icon"> |
| 1552 | <div class="title">Note</div> |
| 1553 | </td> |
| 1554 | <td class="content">A range in a PIDSPEC does not have to have running tasks for every |
| 1555 | number in that range. In fact, it is not even an error if there are no tasks |
| 1556 | running in that range; none will be moved in that case. The range simply |
| 1557 | specifies to act on any tasks that have a PID or TID that is within that |
| 1558 | range.</td> |
| 1559 | </tr></table> |
| 1560 | </div> |
| 1561 | <div class="paragraph"><p>In the following example, we move the current shell into the cpuset named |
| 1562 | <em>two</em> with a range PIDSPEC and back out to the <em>root</em> cpuset with the bash |
| 1563 | variable for the current PID.</p></div> |
| 1564 | <div class="listingblock"> |
| 1565 | <div class="content"> |
| 1566 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s two |
| 1567 | cset: "two" cpuset of CPUSPEC(2) with 0 tasks running |
| 1568 | |
| 1569 | [zuul:cpuset-trunk]# echo $$ |
| 1570 | 19253 |
| 1571 | |
| 1572 | [zuul:cpuset-trunk]# cset proc -m -p 19250-19260 -t two |
| 1573 | cset: moving following pidspec: 19253 |
| 1574 | cset: moving 1 userspace tasks to /two |
| 1575 | cset: done |
| 1576 | |
| 1577 | [zuul:cpuset-trunk]# cset proc -l -s two |
| 1578 | cset: "two" cpuset of CPUSPEC(2) with 2 tasks running |
| 1579 | USER PID PPID SPPr TASK NAME |
| 1580 | -------- ----- ----- ---- --------- |
| 1581 | root 19253 16447 Roth bash |
| 1582 | root 29456 19253 Roth python ./cset proc -l -s two |
| 1583 | |
| 1584 | [zuul:cpuset-trunk]# cset proc -m -p $$ -t root |
| 1585 | cset: moving following pidspec: 19253 |
| 1586 | cset: moving 1 userspace tasks to / |
| 1587 | cset: done |
| 1588 | |
| 1589 | [zuul:cpuset-trunk]# cset proc -l -s two |
| 1590 | cset: "two" cpuset of CPUSPEC(2) with 0 tasks running</code></pre> |
| 1591 | </div></div> |
| 1592 | <div class="paragraph"><p>Use of the appropriate PIDSPEC can thus be handy to move tasks and groups of |
| 1593 | tasks. Additionally, there is one more option that can help with |
| 1594 | multi-threaded processes, and that is the <code>--threads</code> flag. If this flag is |
| 1595 | present in a <code>proc</code> move command with a PIDSPEC and if any of the task IDs in |
| 1596 | the PIDSPEC belongs to a thread in a process container, then <strong>all</strong> the sibling |
| 1597 | threads in that process container will also get moved. This flag provides an |
| 1598 | easy mechanism to move all threads of a process by simply specifying one |
| 1599 | thread in that process. In the following example, we move all the threads |
| 1600 | running in cpuset <em>three</em> to cpuset <em>two</em> by using the <code>--threads</code> flag.</p></div> |
| 1601 | <div class="listingblock"> |
| 1602 | <div class="content"> |
| 1603 | <pre><code>[zuul:cpuset-trunk]# cset set two three |
| 1604 | cset: |
| 1605 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1606 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1607 | two 2 n 0 n 0 0 /two |
| 1608 | three 3 n 0 n 10 0 /three |
| 1609 | |
| 1610 | [zuul:cpuset-trunk]# cset proc -l -s three |
| 1611 | cset: "three" cpuset of CPUSPEC(3) with 10 tasks running |
| 1612 | USER PID PPID SPPr TASK NAME |
| 1613 | -------- ----- ----- ---- --------- |
| 1614 | alext 16165 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1615 | alext 16169 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1616 | alext 16170 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1617 | alext 16237 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1618 | alext 16491 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1619 | alext 16492 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1620 | alext 16493 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1621 | alext 17243 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1622 | alext 17244 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1623 | alext 27133 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1624 | |
| 1625 | [zuul:cpuset-trunk]# cset proc -m -p 16165 --threads -t two |
| 1626 | cset: moving following pidspec: 16491,16493,16492,16170,16165,16169,27133,17244,17243,16237 |
| 1627 | cset: moving 10 userspace tasks to /two |
| 1628 | [==================================================]% |
| 1629 | cset: done |
| 1630 | |
| 1631 | [zuul:cpuset-trunk]# cset set two three |
| 1632 | cset: |
| 1633 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1634 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1635 | two 2 n 0 n 10 0 /two |
| 1636 | three 3 n 0 n 0 0 /three</code></pre> |
| 1637 | </div></div> |
| 1638 | <div class="sect4"> |
| 1639 | <h5 id="_moving_all_tasks_from_one_cpuset_to_another">Moving All Tasks from one Cpuset to Another</h5> |
| 1640 | <div class="paragraph"><p>There is a special case for moving all tasks currently running in one cpuset |
| 1641 | to another. This can be a common use case, and when you need to do it, |
| 1642 | specifying a PIDSPEC with <code>-p</code> is not necessary <em>so long as</em> you use the |
| 1643 | <code>-f/--fromset</code> <strong>and</strong> the <code>-t/--toset</code> options.</p></div> |
| 1644 | <div class="paragraph"><p>In the following example, we move all 10 <code>beagled</code> threads back to cpuset |
| 1645 | <em>three</em> with this method.</p></div> |
| 1646 | <div class="listingblock"> |
| 1647 | <div class="content"> |
| 1648 | <pre><code>[zuul:cpuset-trunk]# cset proc -l two three |
| 1649 | cset: "two" cpuset of CPUSPEC(2) with 10 tasks running |
| 1650 | USER PID PPID SPPr TASK NAME |
| 1651 | -------- ----- ----- ---- --------- |
| 1652 | alext 16165 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1653 | alext 16169 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1654 | alext 16170 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1655 | alext 16237 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1656 | alext 16491 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1657 | alext 16492 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1658 | alext 16493 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1659 | alext 17243 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1660 | alext 17244 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1661 | alext 27133 1 Soth beagled /usr/lib64/beagle/BeagleDaemon.exe --bg -... |
| 1662 | cset: "three" cpuset of CPUSPEC(3) with 0 tasks running |
| 1663 | |
| 1664 | [zuul:cpuset-trunk]# cset proc -m -f two -t three |
| 1665 | cset: moving all tasks from two to /three |
| 1666 | cset: moving 10 userspace tasks to /three |
| 1667 | [==================================================]% |
| 1668 | cset: done |
| 1669 | |
| 1670 | [zuul:cpuset-trunk]# cset set two three |
| 1671 | cset: |
| 1672 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1673 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1674 | two 2 n 0 n 0 0 /two |
| 1675 | three 3 n 0 n 10 0 /three</code></pre> |
| 1676 | </div></div> |
| 1677 | </div> |
| 1678 | <div class="sect4"> |
| 1679 | <h5 id="_moving_kernel_threads_with_proc">Moving Kernel Threads with Proc</h5> |
| 1680 | <div class="paragraph"><p>Kernel threads are special and <strong>cset</strong> detects tasks that are kernel threads |
| 1681 | and will refuse to move them unless you also add a <code>-k/--kthread</code> option to |
| 1682 | your <code>proc</code> move command. Even if you include <code>-k</code>, <strong>cset</strong> will <em>still</em> |
| 1683 | refuse to move the kernel thread if they are bound to specific CPUs. The |
| 1684 | reason for this is system protection.</p></div> |
| 1685 | <div class="paragraph"><p>A number of kernel threads, especially on the real time Linux kernel, are |
| 1686 | bound to specific CPUs and depend on per-CPU kernel variables. If you move |
| 1687 | these threads to a different CPU than what they are bound to, you risk at best |
| 1688 | that the system will become horribly slow, and at worst a system hang. If you |
| 1689 | still insist to move those threads (after all, <strong>cset</strong> needs to give the |
| 1690 | knowledgeable user access to the keys), then you need to use the <code>--force</code> |
| 1691 | option additionally.</p></div> |
| 1692 | <div class="admonitionblock"> |
| 1693 | <table><tr> |
| 1694 | <td class="icon"> |
| 1695 | <div class="title">Warning</div> |
| 1696 | </td> |
| 1697 | <td class="content">Overriding a task move command with <code>--force</code> can have dire |
| 1698 | consequences for the system. Please be sure of the command before you force |
| 1699 | it.</td> |
| 1700 | </tr></table> |
| 1701 | </div> |
| 1702 | <div class="paragraph"><p>In the following example, we move all unbound kernel threads running in the |
| 1703 | <em>root</em> cpuset to the cpuset named <em>two</em> by using the <code>-k</code> option.</p></div> |
| 1704 | <div class="listingblock"> |
| 1705 | <div class="content"> |
| 1706 | <pre><code>[zuul:cpuset-trunk]# cset proc -k -f root -t two |
| 1707 | cset: moving all kernel threads from / to /two |
| 1708 | cset: moving 70 kernel threads to: /two |
| 1709 | cset: --> not moving 76 threads (not unbound, use --force) |
| 1710 | [==================================================]% |
| 1711 | cset: done</code></pre> |
| 1712 | </div></div> |
| 1713 | <div class="paragraph"><p>You will note that we used the fromset→toset facility of the <code>proc</code> |
| 1714 | subcommand and we only specified the <code>-k</code> option (not the <code>-m</code> option). This |
| 1715 | has the effect of moving all kernel threads only.</p></div> |
| 1716 | <div class="paragraph"><p>Note that only 70 actual kernel threads were moved and 76 were not. The |
| 1717 | reason that 76 kernel threads were not moved was because they are bound to |
| 1718 | specific CPUs. Now, let’s move those kernel threads back to <em>root</em>.</p></div> |
| 1719 | <div class="listingblock"> |
| 1720 | <div class="content"> |
| 1721 | <pre><code>[zuul:cpuset-trunk]# cset proc -k -f two -t root |
| 1722 | cset: moving all kernel threads from /two to / |
| 1723 | cset: ** no task matched move criteria |
| 1724 | cset: **> kernel tasks are bound, use --force if ok |
| 1725 | |
| 1726 | [zuul:cpuset-trunk]# cset set -l -s two |
| 1727 | cset: |
| 1728 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1729 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1730 | two 2 n 0 n 70 0 /two</code></pre> |
| 1731 | </div></div> |
| 1732 | <div class="paragraph"><p>Ah! What’s this? <strong>Cset</strong> refused to move the kernel threads back to <em>root</em> |
| 1733 | because it says that they are "bound." Let’s check this with the Linux |
| 1734 | taskset command.</p></div> |
| 1735 | <div class="listingblock"> |
| 1736 | <div class="content"> |
| 1737 | <pre><code>[zuul:cpuset-trunk]# cset proc -l -s two | head -5 |
| 1738 | cset: "two" cpuset of CPUSPEC(2) with 70 tasks running |
| 1739 | USER PID PPID SPPr TASK NAME |
| 1740 | -------- ----- ----- ---- --------- |
| 1741 | root 2 0 Soth [kthreadd] |
| 1742 | root 55 2 Soth [khelper] |
| 1743 | |
| 1744 | [zuul:cpuset-trunk]# taskset -p 2 |
| 1745 | pid 2's current affinity mask: 4 |
| 1746 | |
| 1747 | [zuul:cpuset-trunk]# cset set -l -s two |
| 1748 | cset: |
| 1749 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1750 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1751 | two 2 n 0 n 70 0 /two</code></pre> |
| 1752 | </div></div> |
| 1753 | <div class="paragraph"><p>Of course, since the cpuset named <em>two</em> only has CPU2 assigned to it, once we |
| 1754 | moved the unbound kernel threads from <em>root</em> to <em>two</em>, their affinity masks |
| 1755 | got automatically changed to only use CPU2. This is evident from the |
| 1756 | <code>taskset</code> output which is a hex value. To really move these threads back to |
| 1757 | <em>root</em>, we need to force the move as follows.</p></div> |
| 1758 | <div class="listingblock"> |
| 1759 | <div class="content"> |
| 1760 | <pre><code>[zuul:cpuset-trunk]# cset proc -k -f two -t root --force |
| 1761 | cset: moving all kernel threads from /two to / |
| 1762 | cset: moving 70 kernel threads to: / |
| 1763 | [==================================================]% |
| 1764 | cset: done</code></pre> |
| 1765 | </div></div> |
| 1766 | </div> |
| 1767 | </div> |
| 1768 | <div class="sect3"> |
| 1769 | <h4 id="_destroying_tasks">3.2.4. Destroying Tasks</h4> |
| 1770 | <div class="paragraph"><p>There actually is no <strong>cset</strong> subcommand or option to destroy tasks—it’s not |
| 1771 | really needed. Tasks exist and are accessible on the system as normal, even |
| 1772 | if they happen to be running in one cpuset or another. To destroy tasks, use |
| 1773 | the usual ^C method or by using the <strong>kill(1)</strong> command.</p></div> |
| 1774 | </div> |
| 1775 | </div> |
| 1776 | <div class="sect2"> |
| 1777 | <h3 id="_implementing_shielding_with_set_and_proc">3.3. Implementing "Shielding" with Set and Proc</h3> |
| 1778 | <div class="paragraph"><p>With the preceding material on the <code>set</code> and <code>proc</code> subcommands, we now have |
| 1779 | the background to implement the basic shielding model, just like the <code>shield</code> |
| 1780 | subcommand.</p></div> |
| 1781 | <div class="paragraph"><p>One may pose the question as to why we want to do this, especially since |
| 1782 | <code>shield</code> already does it? The answer is that sometimes one needs more |
| 1783 | functionality than <code>shield</code> has to implement one’s shielding strategy. In |
| 1784 | those case you need to first stop using <code>shield</code> since that subcommand will |
| 1785 | interfere with the further application of <code>set</code> and <code>proc</code>; however, you will |
| 1786 | still need to implement the functionality of <code>shield</code> in order to implement |
| 1787 | successful shielding.</p></div> |
| 1788 | <div class="paragraph"><p>Remember from the above sections describing <code>shield</code>, that shielding has at |
| 1789 | minimum three cpusets: <em>root</em>, which is always present and contains all CPUs; |
| 1790 | <em>system</em> which is the "non-shielded" set of CPUs and runs unimportant system |
| 1791 | tasks; and <em>user</em>, which is the "shielded" set of CPUs and runs your important |
| 1792 | tasks. Remember also that <code>shield</code> moves all movable tasks into <em>system</em> |
| 1793 | and, optionally, moves unbound kernel threads into <em>system</em> as well.</p></div> |
| 1794 | <div class="paragraph"><p>We start first by creating the <em>system</em> and <em>user</em> cpusets as follows. We |
| 1795 | assume that the machine is a four-CPU machine without NUMA memory features. |
| 1796 | The <em>system</em> cpuset should hold only CPU0 while the <em>user</em> cpuset should hold |
| 1797 | the rest of the CPUs.</p></div> |
| 1798 | <div class="listingblock"> |
| 1799 | <div class="content"> |
| 1800 | <pre><code>[zuul:cpuset-trunk]# cset set -c 0 -s system |
| 1801 | cset: --> created cpuset "system" |
| 1802 | |
| 1803 | [zuul:cpuset-trunk]# cset set -c 1-3 -s user |
| 1804 | cset: --> created cpuset "user" |
| 1805 | |
| 1806 | [zuul:cpuset-trunk]# cset set -l |
| 1807 | cset: |
| 1808 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1809 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1810 | root 0-3 y 0 y 333 2 / |
| 1811 | user 1-3 n 0 n 0 0 /user |
| 1812 | system 0 n 0 n 0 0 /system</code></pre> |
| 1813 | </div></div> |
| 1814 | <div class="paragraph"><p>Now, we need to move all running user processes into the <em>system</em> cpuset.</p></div> |
| 1815 | <div class="listingblock"> |
| 1816 | <div class="content"> |
| 1817 | <pre><code>[zuul:cpuset-trunk]# cset proc -m -f root -t system |
| 1818 | cset: moving all tasks from root to /system |
| 1819 | cset: moving 188 userspace tasks to /system |
| 1820 | [==================================================]% |
| 1821 | cset: done |
| 1822 | |
| 1823 | [zuul:cpuset-trunk]# cset set -l |
| 1824 | cset: |
| 1825 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1826 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1827 | root 0-3 y 0 y 146 2 / |
| 1828 | user 1-3 n 0 n 0 0 /user |
| 1829 | system 0 n 0 n 187 0 /system</code></pre> |
| 1830 | </div></div> |
| 1831 | <div class="paragraph"><p>We now have the basic shielding set up. Since all userspace tasks are running |
| 1832 | in <em>system</em>, anything that is spawned from them will also run in <em>system</em>. |
| 1833 | The <em>user</em> cpuset has nothing running in it unless you put tasks there with |
| 1834 | the <code>proc</code> subcommand as described above. If you also want to move movable |
| 1835 | kernel threads from <em>root</em> to <em>system</em> (in order to achieve a form of |
| 1836 | "interrupt shielding" on a real time Linux kernel for example), you would |
| 1837 | execute the following command as well.</p></div> |
| 1838 | <div class="listingblock"> |
| 1839 | <div class="content"> |
| 1840 | <pre><code>[zuul:cpuset-trunk]# cset proc -k -f root -t system |
| 1841 | cset: moving all kernel threads from / to /system |
| 1842 | cset: moving 70 kernel threads to: /system |
| 1843 | cset: --> not moving 76 threads (not unbound, use --force) |
| 1844 | [==================================================]% |
| 1845 | cset: done |
| 1846 | |
| 1847 | [zuul:cpuset-trunk]# cset set -l |
| 1848 | cset: |
| 1849 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1850 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1851 | root 0-3 y 0 y 76 2 / |
| 1852 | user 1-3 n 0 n 0 0 /user |
| 1853 | system 0 n 0 n 257 0 /system</code></pre> |
| 1854 | </div></div> |
| 1855 | <div class="paragraph"><p>At this point, you have achieved the simple shielding model that the <code>shield</code> |
| 1856 | subcommand provides. You can now add other cpuset definitions to expand your |
| 1857 | shielding strategy beyond that simple model.</p></div> |
| 1858 | </div> |
| 1859 | <div class="sect2"> |
| 1860 | <h3 id="_implementing_hierarchy_with_set_and_proc">3.4. Implementing Hierarchy with Set and Proc</h3> |
| 1861 | <div class="paragraph"><p>One popular extended "shielding" model is based on hierarchical cpusets, each |
| 1862 | with diminishing numbers of CPUs. This model is used to create "priority |
| 1863 | cpusets" that allow assignment of CPU resources to tasks based on some |
| 1864 | arbitrary priority definition. The idea being that a higher priority task |
| 1865 | will get access to more CPU resources than a lower priority task.</p></div> |
| 1866 | <div class="paragraph"><p>The example provided here once again assumes a machine with four CPUs and no |
| 1867 | NUMA memory features. This base serves to illustrate the point well; however, |
| 1868 | note that if your machine has (many) more CPUs, then strategies such as this |
| 1869 | and others get more interesting.</p></div> |
| 1870 | <div class="paragraph"><p>We define a shielding set up as in the previous section where we have a |
| 1871 | <em>system</em> cpuset with just CPU0 that takes care of "unimportant" system tasks. |
| 1872 | One usually requires this type of cpuset since it forms the basis of |
| 1873 | shielding. We modify the strategy to not use a <em>user</em> cpuset, instead we |
| 1874 | create a number of new cpusets each holding one more CPU than the other. |
| 1875 | These cpusets will be called <em>prio_low</em> with one CPU, <em>prio_med</em> with two |
| 1876 | CPUs, <em>prio_high</em> with three CPUs, and <em>prio_all</em> with all CPUs.</p></div> |
| 1877 | <div class="admonitionblock"> |
| 1878 | <table><tr> |
| 1879 | <td class="icon"> |
| 1880 | <div class="title">Note</div> |
| 1881 | </td> |
| 1882 | <td class="content">One may ask, why create a <em>prio_all</em> with all CPUs when that is |
| 1883 | substantially the definition of the <em>root</em> cpuset? The answer is that it is |
| 1884 | best to keep a separation between the <em>root</em> cpuset and everything else, even |
| 1885 | if a particular cpuset duplicates <em>root</em> exactly. Usually, one builds |
| 1886 | automation on top of a cpuset strategy. In these cases, it is best to avoid |
| 1887 | using invariant names of cpusets, such as <em>root</em> for example, in this |
| 1888 | automation.</td> |
| 1889 | </tr></table> |
| 1890 | </div> |
| 1891 | <div class="paragraph"><p>All of these <em>prio_*</em> cpusets can be created under root, in a flat way; |
| 1892 | however, it is advantageous to create them as a hierarchy. The reasoning for |
| 1893 | this is twofold: first, if a cpuset is destroyed, all its tasks are moved to |
| 1894 | its parent; second, one can use exclusive CPUs in a hierarchy.</p></div> |
| 1895 | <div class="paragraph"><p>There is a planned addition to the <code>proc</code> subcommand that will allow moving a |
| 1896 | specified PIDSPEC of tasks running in a specified cpuset to its parent. This |
| 1897 | addition will ease the automation burden.</p></div> |
| 1898 | <div class="paragraph"><p>If a cpuset has CPUs that are exclusive to it, then other cpusets may not make |
| 1899 | use of those CPUs unless they are children of that cpuset. This has more |
| 1900 | relevance to machines with many CPUs and more complex strategies.</p></div> |
| 1901 | <div class="paragraph"><p>Now, we start with a clean slate and build the appropriate cpusets as |
| 1902 | follows.</p></div> |
| 1903 | <div class="listingblock"> |
| 1904 | <div class="content"> |
| 1905 | <pre><code>[zuul:cpuset-trunk]# cset set -r |
| 1906 | cset: |
| 1907 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1908 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1909 | root 0-3 y 0 y 344 0 / |
| 1910 | |
| 1911 | [zuul:cpuset-trunk]# cset set -c 0-3 prio_all |
| 1912 | cset: --> created cpuset "prio_all" |
| 1913 | |
| 1914 | [zuul:cpuset-trunk]# cset set -c 1-3 /prio_all/prio_high |
| 1915 | cset: --> created cpuset "/prio_all/prio_high" |
| 1916 | |
| 1917 | [zuul:cpuset-trunk]# cset set -c 2-3 /prio_all/prio_high/prio_med |
| 1918 | cset: --> created cpuset "/prio_all/prio_high/prio_med" |
| 1919 | |
| 1920 | [zuul:cpuset-trunk]# cset set -c 3 /prio_all/prio_high/prio_med/prio_low |
| 1921 | cset: --> created cpuset "/prio_all/prio_high/prio_med/prio_low" |
| 1922 | |
| 1923 | [zuul:cpuset-trunk]# cset set -c 0 system |
| 1924 | cset: --> created cpuset "system" |
| 1925 | |
| 1926 | [zuul:cpuset-trunk]# cset set -l -r |
| 1927 | cset: |
| 1928 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1929 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1930 | root 0-3 y 0 y 344 2 / |
| 1931 | system 0 n 0 n 0 0 /system |
| 1932 | prio_all 0-3 n 0 n 0 1 /prio_all |
| 1933 | prio_high 1-3 n 0 n 0 1 /prio_all/prio_high |
| 1934 | prio_med 2-3 n 0 n 0 1 /prio_all/prio_high/prio_med |
| 1935 | prio_low 3 n 0 n 0 0 /prio_all/pr...rio_med/prio_low</code></pre> |
| 1936 | </div></div> |
| 1937 | <div class="admonitionblock"> |
| 1938 | <table><tr> |
| 1939 | <td class="icon"> |
| 1940 | <div class="title">Note</div> |
| 1941 | </td> |
| 1942 | <td class="content">We used the <code>-r/--recurse</code> switch to list all the sets in the last |
| 1943 | command above. If we had not, then the <em>prio_med</em> and <em>prio_low</em> cpusets |
| 1944 | would not have been listed.</td> |
| 1945 | </tr></table> |
| 1946 | </div> |
| 1947 | <div class="paragraph"><p>The strategy is now implemented and we now move all userspace tasks as well as |
| 1948 | all movable kernel threads into the <em>system</em> cpuset to activate the shield.</p></div> |
| 1949 | <div class="listingblock"> |
| 1950 | <div class="content"> |
| 1951 | <pre><code>[zuul:cpuset-trunk]# cset proc -m -k -f root -t system |
| 1952 | cset: moving all tasks from root to /system |
| 1953 | cset: moving 198 userspace tasks to /system |
| 1954 | cset: moving 70 kernel threads to: /system |
| 1955 | cset: --> not moving 76 threads (not unbound, use --force) |
| 1956 | [==================================================]% |
| 1957 | cset: done |
| 1958 | |
| 1959 | [zuul:cpuset-trunk]# cset set -l -r |
| 1960 | cset: |
| 1961 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1962 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1963 | root 0-3 y 0 y 76 2 / |
| 1964 | system 0 n 0 n 268 0 /system |
| 1965 | prio_all 0-3 n 0 n 0 1 /prio_all |
| 1966 | prio_high 1-3 n 0 n 0 1 /prio_all/prio_high |
| 1967 | prio_med 2-3 n 0 n 0 1 /prio_all/prio_high/prio_med |
| 1968 | prio_low 3 n 0 n 0 0 /prio_all/pr...rio_med/prio_low</code></pre> |
| 1969 | </div></div> |
| 1970 | <div class="paragraph"><p>The shield is now active. Since the <em>prio_*</em> cpuset names are unique, one can |
| 1971 | assign tasks to them either via either their simple name, or their full path |
| 1972 | (as described in the <code>proc</code> section above).</p></div> |
| 1973 | <div class="paragraph"><p>You may have noted that there is an ellipsis in the path of the <em>prio_low</em> |
| 1974 | cpuset in the listing above. This is done in order to fit the output onto an |
| 1975 | 80 character screen. If you want to see the entire line, then you need to use |
| 1976 | the <code>-v/--verbose</code> flag as follows.</p></div> |
| 1977 | <div class="listingblock"> |
| 1978 | <div class="content"> |
| 1979 | <pre><code>[zuul:cpuset-trunk]# cset set -l -r -v |
| 1980 | cset: |
| 1981 | Name CPUs-X MEMs-X Tasks Subs Path |
| 1982 | ------------ ---------- - ------- - ----- ---- ---------- |
| 1983 | root 0-3 y 0 y 76 2 / |
| 1984 | system 0 n 0 n 268 0 /system |
| 1985 | prio_all 0-3 n 0 n 0 1 /prio_all |
| 1986 | prio_high 1-3 n 0 n 0 1 /prio_all/prio_high |
| 1987 | prio_med 2-3 n 0 n 0 1 /prio_all/prio_high/prio_med |
| 1988 | prio_low 3 n 0 n 0 0 /prio_all/prio_high/prio_med/prio_low</code></pre> |
| 1989 | </div></div> |
| 1990 | </div> |
| 1991 | </div> |
| 1992 | </div> |
| 1993 | <div class="sect1"> |
| 1994 | <h2 id="_using_shortcuts">4. Using Shortcuts</h2> |
| 1995 | <div class="sectionbody"> |
| 1996 | <div class="paragraph"><p>The commands listed in the previous sections always used all the required |
| 1997 | options. <strong>Cset</strong> however does have a shortcut facility that will execute |
| 1998 | certain commands without specifying all options. An effort has been made to |
| 1999 | do this with the "principle of least surprise." This means that if you do not |
| 2000 | specify options, but do specify parameters, then the outcome of the command |
| 2001 | should be intuitive. As much as possible.</p></div> |
| 2002 | <div class="paragraph"><p>Using shortcuts is of course not necessary. In fact, you can not only not use |
| 2003 | shortcuts, but you can use long options instead of short, in case you really |
| 2004 | enjoy typing… All kidding aside, using long options and not using shortcuts |
| 2005 | does have a use case: when you write a script intended to be self-documenting, |
| 2006 | or perhaps when you generate <strong>cset</strong> documentation.</p></div> |
| 2007 | <div class="paragraph"><p>To begin, the subcommands <code>shield</code>, <code>set</code> and <code>proc</code> can themselves be |
| 2008 | shortened to the fewest number of characters that are unambiguous. For |
| 2009 | example, the following commands are identical:</p></div> |
| 2010 | <div class="listingblock"> |
| 2011 | <div class="content"> |
| 2012 | <pre><code># cset shield -s -p 1234 <--> # cset sh -s -p 1234 |
| 2013 | # cset set -c 1,3 -s newset <--> # cset se -c 1,3 -s newset |
| 2014 | # cset proc -s newset -e bash <--> # cset p -s newset -e bash</code></pre> |
| 2015 | </div></div> |
| 2016 | <div class="paragraph"><p>Note that <code>proc</code> can be shortened to just <code>p</code>, while <code>shield</code> and <code>set</code> need |
| 2017 | two letters to disambiguate.</p></div> |
| 2018 | <div class="sect2"> |
| 2019 | <h3 id="_shield_subcommand_shortcuts">4.1. Shield Subcommand Shortcuts</h3> |
| 2020 | <div class="paragraph"><p>The <code>shield</code> subcommand supports two areas with shortcuts: the case when there |
| 2021 | is no options given where to <em>shield</em> is the common use case, and making the |
| 2022 | <code>-p/--pid</code> option <em>optional</em> for the <code>-s/--shield</code> and <code>-u/--unshield</code> |
| 2023 | options.</p></div> |
| 2024 | <div class="paragraph"><p>For the common use case of actually <em>shielding</em> either a PIDSPEC or execing a |
| 2025 | command into the shield, the following <strong>cset</strong> commands are equivalent.</p></div> |
| 2026 | <div class="listingblock"> |
| 2027 | <div class="content"> |
| 2028 | <pre><code># cset shield -s -p 1234,500-649 <--> # cset sh 1234,500-649 |
| 2029 | # cset shield -s -e bash <--> # cset sh bash</code></pre> |
| 2030 | </div></div> |
| 2031 | <div class="paragraph"><p>When using the <code>-s</code> or <code>-u</code> shield/unshield options, it is optional to use the |
| 2032 | <code>-p</code> option to specify a PIDSPEC. For example:</p></div> |
| 2033 | <div class="listingblock"> |
| 2034 | <div class="content"> |
| 2035 | <pre><code># cset shield -s -p 1234 <--> # cset sh -s 1234 |
| 2036 | # cset shield -u -p 1234 <--> # cset sh -u 1234</code></pre> |
| 2037 | </div></div> |
| 2038 | </div> |
| 2039 | <div class="sect2"> |
| 2040 | <h3 id="_set_subcommand_shortcuts">4.2. Set Subcommand Shortcuts</h3> |
| 2041 | <div class="paragraph"><p>The <code>set</code> subcommand has a limited number of shortcuts. Basically, the |
| 2042 | <code>-s/--set</code> option is optional in most cases and the <code>-l/--list</code> option is |
| 2043 | also optional if you want to list sets. For example, these commands are |
| 2044 | equivalent.</p></div> |
| 2045 | <div class="listingblock"> |
| 2046 | <div class="content"> |
| 2047 | <pre><code># cset set -l -s myset <--> # cset se -l myset |
| 2048 | # cset se -l myset <--> # cset se myset |
| 2049 | |
| 2050 | # cset set -c 1,2,3 -s newset <--> # cset se -c 1,2,3 newset |
| 2051 | # cset set -d -s newset <--> # cset se -d newset |
| 2052 | |
| 2053 | # cset set -n newname -s oldname <--> # cset se -n newname oldname</code></pre> |
| 2054 | </div></div> |
| 2055 | <div class="paragraph"><p>In fact, if you want to apply either the list or the destroy options to |
| 2056 | multiple cpusets with one <strong>cset</strong> command, you’ll need to not use the <code>-s</code> |
| 2057 | option. For example:</p></div> |
| 2058 | <div class="listingblock"> |
| 2059 | <div class="content"> |
| 2060 | <pre><code># cset se -d myset yourset ourset |
| 2061 | --> destroys cpusets: myset, yourset and ourset |
| 2062 | |
| 2063 | # cset se -l prio_high prio_med prio_low |
| 2064 | --> lists only cpusets prio_high, prio_med and prio_low |
| 2065 | --> the -l is optional in this case since list is default</code></pre> |
| 2066 | </div></div> |
| 2067 | </div> |
| 2068 | <div class="sect2"> |
| 2069 | <h3 id="_proc_subcommand_shortcuts">4.3. Proc Subcommand Shortcuts</h3> |
| 2070 | <div class="paragraph"><p>For the <code>proc</code> subcommand, the <code>-s</code>, <code>-t</code> and <code>-f</code> options to specify the |
| 2071 | cpuset, the origination cpuset and the destination cpuset, can sometimes be |
| 2072 | optional. For example, the following commands are equivalent.</p></div> |
| 2073 | <div class="listingblock"> |
| 2074 | <div class="content"> |
| 2075 | <pre><code>To list tasks in cpusets: |
| 2076 | # cset proc -l -s myset \ |
| 2077 | # cset proc -l -f myset --> # cset p -l myset |
| 2078 | # cset proc -l -t myset / |
| 2079 | |
| 2080 | # cset p -l myset <--> # cset p myset |
| 2081 | |
| 2082 | # cset proc -l -s one two <--> # cset p -l one two |
| 2083 | # cset p -l one two <--> # cset p one two |
| 2084 | |
| 2085 | To exec a process into a cpuset: |
| 2086 | # cset proc -s myset -e bash <--> # cset p myset -e bash</code></pre> |
| 2087 | </div></div> |
| 2088 | <div class="paragraph"><p>Movement of tasks into and out of cpusets have the following shortcuts.</p></div> |
| 2089 | <div class="listingblock"> |
| 2090 | <div class="content"> |
| 2091 | <pre><code>To move a PIDSPEC into a cpuset: |
| 2092 | # cset proc -m -p 4242,4243 -s myset <--> # cset p -m 4242,4243 myset |
| 2093 | # cset proc -m -p 12 -t myset <--> # cset p -m 12 myset |
| 2094 | |
| 2095 | To move all tasks from one cpuset to another: |
| 2096 | # cset proc -m -f set1 -t set2 \ |
| 2097 | # cset proc -m -s set1 -t set2 --> # cset p -m set1 set2 |
| 2098 | # cset proc -m -f set1 -s set2 /</code></pre> |
| 2099 | </div></div> |
| 2100 | </div> |
| 2101 | </div> |
| 2102 | </div> |
| 2103 | <div class="sect1"> |
| 2104 | <h2 id="_what_to_do_if_there_are_problems">5. What To Do if There are Problems</h2> |
| 2105 | <div class="sectionbody"> |
| 2106 | <div class="paragraph"><p>If you encounter problems with the <strong>cset</strong> application, the best option is to |
| 2107 | log a bug with the <strong>cset</strong> bugzilla instance found here:</p></div> |
| 2108 | <div class="literalblock"> |
| 2109 | <div class="content"> |
| 2110 | <pre><code>https://github.com/SUSE/cpuset/issues</code></pre> |
| 2111 | </div></div> |
| 2112 | <div class="paragraph"><p>If you are using <strong>cset</strong> on a supported operating system such as SLES or SLERT |
| 2113 | from Novell, then please use that bugzilla instead at:</p></div> |
| 2114 | <div class="literalblock"> |
| 2115 | <div class="content"> |
| 2116 | <pre><code>https://bugzilla.suse.com</code></pre> |
| 2117 | </div></div> |
| 2118 | <div class="paragraph"><p>If the problem is repeatable, there is an excellent chance that it will get |
| 2119 | fixed quickly. Also, <strong>cset</strong> contains a logging facility that is invaluable |
| 2120 | for the developers to diagnose problems. To create a log of a run, use the |
| 2121 | <code>-l/--log</code> option with a filename as an argument to the main <strong>cset</strong> |
| 2122 | application. For example.</p></div> |
| 2123 | <div class="listingblock"> |
| 2124 | <div class="content"> |
| 2125 | <pre><code># cset -l logfile.txt set -n newname oldname</code></pre> |
| 2126 | </div></div> |
| 2127 | <div class="paragraph"><p>That command saves a lot of debugging information in the <em>logfile.txt</em> file. |
| 2128 | Please attach this file to the bug.</p></div> |
| 2129 | </div> |
| 2130 | </div> |
| 2131 | </div> |
| 2132 | <div id="footnotes"><hr /></div> |
| 2133 | <div id="footer"> |
| 2134 | <div id="footer-text"> |
| 2135 | Last updated |
| 2136 | 2017-12-06 10:59:31 CET |
| 2137 | </div> |
| 2138 | </div> |
| 2139 | </body> |
| 2140 | </html> |