Skip to content

Commit 4f17036

Browse files
committed
Introduce cpuAffinity process property instead of execCPUAffinity
This change introduces more generic `cpuAffinity` property of `Process` to specify desired CPU affinities while performing operations on create, start and exec operations. Signed-off-by: Alexander Kanevskiy <[email protected]>
1 parent fd25dd3 commit 4f17036

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

config.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,35 @@ 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.
343+
* **`cpuAffinity`** (object, OPTIONAL) specifies CPU affinity used to execute processes in the runtime and the container.
344+
All the properties in this setting expects as argument a string that contain a comma-separated list, with dashes to represent ranges.
345+
For example, `0-3,7` represents CPUs 0,1,2,3, and 7. Special value `all` can be used to reset CPU affinity to the value that includes all possible CPUs in the system.
346+
If omitted or empty for particular [lifecycle](runtime.md#lifecycle) stage, the runtime SHOULD NOT change process' CPU affinity, and the actual affinity is determined by the Linux kernel.
347+
The following properties are available:
348+
* **`createRuntime`** (string, OPTIONAL) is a list of CPUs the runtime parent process should run on during the runtime creation stage, before entering the container's namespaces or cgroups.
349+
CPU affinity should be applied on early stages of container creation, so that any potential CPU consuming operations inside runtime (e.g. [`createRuntime` hooks](#createRuntime-hooks)) will be run on the specified list of CPUs.
350+
* **`createContainer`** (string, OPTIONAL) is a list of CPUs the process should run on during the container creation stage, after entering the container's namespaces but before the user process or any of [`createContainer` hooks](#createContainer-hooks) are executed.
351+
* **`startContainer`** (string, OPTIONAL) is a list of CPUs the process should be run on during the container start stage, inside the container's namespace during `start` operation. The affinity should be applied before executing [`startContainer` hooks](#startContainer-hooks).
352+
* **`execRuntime`** (string, OPTIONAL) is a list of CPUs the runtime parent process to be run during `exec` operation, before the transition to container's cgroup.
353+
* **`execContainer`** (string, OPTIONAL) is a list of CPUs the process will be run on during `exec` operationon after the transition to container's cgroup.
354+
* **`execCPUAffinity`** (object, OPTIONAL, **DEPRECATED**) specifies CPU affinity used to execute the process.
355+
356+
Note: `execCPUAffinity` is deprecated in favor of `cpuAffinity`. If `cpuAffinity` is specified and supported by the runtime, the content of `execCPUAffinity` should be ignored.
357+
344358
This setting is not applicable to the container's init process.
345359
The following properties are available:
346360
* **`initial`** (string, OPTIONAL) is a list of CPUs a runtime parent
347361
process to be run on initially, before the transition to container's
348362
cgroup. This is a a comma-separated list, with dashes to represent
349363
ranges. For example, `0-3,7` represents CPUs 0,1,2,3, and 7.
364+
Deprecated in favor of `execRuntime` in `cpuAffinity`.
350365
* **`final`** (string, OPTIONAL) is a list of CPUs the process will be run
351366
on after the transition to container's cgroup. The format is the same as
352367
for `initial`. If omitted or empty, runtime SHOULD NOT change process'
353368
CPU affinity after the process is moved to container's cgroup, and the
354369
final affinity is determined by the Linux kernel.
370+
Deprecated in favor of `execContainer` in `cpuAffinity`.
371+
355372

356373
### <a name="configZOSProcess" />z/OS Process
357374

@@ -435,9 +452,12 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
435452
"soft": 1024
436453
}
437454
],
438-
"execCPUAffinity": {
439-
"initial": "7",
440-
"final": "0-3,7"
455+
"cpuAffinity": {
456+
"createRuntime": "7",
457+
"createContainer": "all",
458+
"startContainer": "0-3,7",
459+
"execRuntime": "7",
460+
"execContainer": "0-3,7"
441461
}
442462
}
443463
```

schema/config-schema.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,31 @@
221221
}
222222
}
223223
},
224+
"cpuAffinity": {
225+
"type": "object",
226+
"properties": {
227+
"createRuntime": {
228+
"type": "string",
229+
"pattern": "^([0-9, -]*|all)$"
230+
},
231+
"createContainer": {
232+
"type": "string",
233+
"pattern": "^([0-9, -]*|all)$"
234+
},
235+
"startContainer": {
236+
"type": "string",
237+
"pattern": "^([0-9, -]*|all)$"
238+
},
239+
"execRuntime": {
240+
"type": "string",
241+
"pattern": "^([0-9, -]*|all)$"
242+
},
243+
"execContainer": {
244+
"type": "string",
245+
"pattern": "^([0-9, -]*|all)$"
246+
}
247+
}
248+
},
224249
"execCPUAffinity": {
225250
"type": "object",
226251
"properties": {

specs-go/config.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ type Process struct {
9696
SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
9797
// IOPriority contains the I/O priority settings for the cgroup.
9898
IOPriority *LinuxIOPriority `json:"ioPriority,omitempty" platform:"linux"`
99-
// ExecCPUAffinity specifies CPU affinity for exec processes.
100-
ExecCPUAffinity *CPUAffinity `json:"execCPUAffinity,omitempty" platform:"linux"`
99+
// ExecCPUAffinity is Deprecated. ExecCPUAffinity specifies CPU affinity for exec processes.
100+
//
101+
// Deprecated: use [Process.CPUAffinity] instead, which allows more granular control
102+
// during the create, start and exec phases.
103+
ExecCPUAffinity *ExecCPUAffinity `json:"execCPUAffinity,omitempty" platform:"linux"`
104+
// CPUAffinity specifies CPU affinity for executing processes
105+
CPUAffinity *CPUAffinity `json:"cpuAffinity,omitempty" platform:"linux"`
101106
}
102107

103108
// LinuxCapabilities specifies the list of allowed capabilities that are kept for a process.
@@ -131,12 +136,21 @@ const (
131136
IOPRIO_CLASS_IDLE IOPriorityClass = "IOPRIO_CLASS_IDLE"
132137
)
133138

134-
// CPUAffinity specifies process' CPU affinity.
135-
type CPUAffinity struct {
139+
// ExecCPUAffinity specifies process' CPU affinity during runtime exec operation.
140+
type ExecCPUAffinity struct {
136141
Initial string `json:"initial,omitempty"`
137142
Final string `json:"final,omitempty"`
138143
}
139144

145+
// CPUAffinity specifies process' CPU affinity.
146+
type CPUAffinity struct {
147+
CreateRuntime string `json:"createRuntime,omitempty"`
148+
CreateContainer string `json:"createContainer,omitempty"`
149+
StartContainer string `json:"startContainer,omitempty"`
150+
ExecRuntime string `json:"execRuntime,omitempty"`
151+
ExecContainer string `json:"execContainer,omitempty"`
152+
}
153+
140154
// Box specifies dimensions of a rectangle. Used for specifying the size of a console.
141155
type Box struct {
142156
// Height is the vertical dimension of a box.

0 commit comments

Comments
 (0)