Skip to content

Commit 7017384

Browse files
authored
Merge pull request #1253 from kolyshkin/exec-aff
Add CPU affinity to executed processes
2 parents 5d5d921 + 119ae42 commit 7017384

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

config-linux.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ The following parameters can be specified to set up the controller:
395395
* **`period`** *(uint64, OPTIONAL)* - specifies a period of time in microseconds for how regularly a cgroup's access to CPU resources should be reallocated (CFS scheduler only)
396396
* **`realtimeRuntime`** *(int64, OPTIONAL)* - specifies a period of time in microseconds for the longest continuous period in which the tasks in a cgroup have access to CPU resources
397397
* **`realtimePeriod`** *(uint64, OPTIONAL)* - same as **`period`** but applies to realtime scheduler only
398-
* **`cpus`** *(string, OPTIONAL)* - list of CPUs the container will run in
399-
* **`mems`** *(string, OPTIONAL)* - list of Memory Nodes the container will run in
398+
* **`cpus`** *(string, OPTIONAL)* - list of CPUs the container will run on. This is a comma-separated list, with dashes to represent ranges. For example, `0-3,7` represents CPUs 0,1,2,3, and 7.
399+
* **`mems`** *(string, OPTIONAL)* - list of memory nodes the container will run on. This is a comma-separated list, with dashes to represent ranges. For example, `0-3,7` represents memory nodes 0,1,2,3, and 7.
400400
* **`idle`** *(int64, OPTIONAL)* - cgroups are configured with minimum weight, 0: default behavior, 1: SCHED_IDLE.
401401

402402
#### Example

config.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ For Linux-based systems, the `process` object supports the following process-spe
340340

341341
* **`class`** (string, REQUIRED) specifies the I/O scheduling class. Possible values are `IOPRIO_CLASS_RT`, `IOPRIO_CLASS_BE`, and `IOPRIO_CLASS_IDLE`.
342342
* **`priority`** (int, REQUIRED) specifies the priority level within the class. The value should be an integer ranging from 0 (highest) to 7 (lowest).
343+
* **`execCPUAffinity`** (object, OPTIONAL) specifies CPU affinity used to execute the process.
344+
This setting is not applicable to the container's init process.
345+
The following properties are available:
346+
* **`initial`** (string, OPTIONAL) is a list of CPUs a runtime parent
347+
process to be run on initially, before the transition to container's
348+
cgroup. This is a a comma-separated list, with dashes to represent
349+
ranges. For example, `0-3,7` represents CPUs 0,1,2,3, and 7.
350+
* **`final`** (string, OPTIONAL) is a list of CPUs the process will be run
351+
on after the transition to container's cgroup. The format is the same as
352+
for `initial`. If omitted or empty, the container's default CPU affinity,
353+
as defined by [cpu.cpus property](./config.md#configLinuxCPUs)), is used.
343354

344355
### <a name="configUser" />User
345356

@@ -416,7 +427,11 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
416427
"hard": 1024,
417428
"soft": 1024
418429
}
419-
]
430+
],
431+
"execCPUAffinity": {
432+
"initial": "7",
433+
"final": "0-3,7"
434+
}
420435
}
421436
```
422437
### Example (Solaris)

schema/config-schema.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@
220220
}
221221
}
222222
}
223-
}
223+
},
224+
"execCPUAffinity": {
225+
"type": "object",
226+
"properties": {
227+
"initial": {
228+
"type": "string",
229+
"pattern": "^[0-9, -]*$"
230+
},
231+
"final": {
232+
"type": "string",
233+
"pattern": "^[0-9, -]*$"
234+
}
235+
}
236+
}
224237
}
225238
},
226239
"linux": {

specs-go/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ type Process struct {
9494
SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
9595
// IOPriority contains the I/O priority settings for the cgroup.
9696
IOPriority *LinuxIOPriority `json:"ioPriority,omitempty" platform:"linux"`
97+
// ExecCPUAffinity specifies CPU affinity for exec processes.
98+
ExecCPUAffinity *CPUAffinity `json:"execCPUAffinity,omitempty" platform:"linux"`
9799
}
98100

99101
// LinuxCapabilities specifies the list of allowed capabilities that are kept for a process.
@@ -127,6 +129,12 @@ const (
127129
IOPRIO_CLASS_IDLE IOPriorityClass = "IOPRIO_CLASS_IDLE"
128130
)
129131

132+
// CPUAffinity specifies process' CPU affinity.
133+
type CPUAffinity struct {
134+
Initial string `json:"initial,omitempty"`
135+
Final string `json:"final,omitempty"`
136+
}
137+
130138
// Box specifies dimensions of a rectangle. Used for specifying the size of a console.
131139
type Box struct {
132140
// Height is the vertical dimension of a box.

0 commit comments

Comments
 (0)