Skip to content

Commit 3041554

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 3041554

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

config.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,31 @@ 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. Speciall 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 affinitized to 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.
344355
This setting is not applicable to the container's init process.
345356
The following properties are available:
346357
* **`initial`** (string, OPTIONAL) is a list of CPUs a runtime parent
347358
process to be run on initially, before the transition to container's
348359
cgroup. This is a a comma-separated list, with dashes to represent
349360
ranges. For example, `0-3,7` represents CPUs 0,1,2,3, and 7.
361+
Deprecated in favor of `execRuntime` in `CPUAffinity`.
350362
* **`final`** (string, OPTIONAL) is a list of CPUs the process will be run
351363
on after the transition to container's cgroup. The format is the same as
352364
for `initial`. If omitted or empty, runtime SHOULD NOT change process'
353365
CPU affinity after the process is moved to container's cgroup, and the
354366
final affinity is determined by the Linux kernel.
367+
Deprecated in favor of `execContainer` in `CPUAffinity`.
355368

356369
### <a name="configZOSProcess" />z/OS Process
357370

@@ -435,9 +448,12 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
435448
"soft": 1024
436449
}
437450
],
438-
"execCPUAffinity": {
439-
"initial": "7",
440-
"final": "0-3,7"
451+
"CPUAffinity": {
452+
"createRuntime": "7",
453+
"createContainer": "all",
454+
"startContainer": "0-3,7",
455+
"execRuntime": "7",
456+
"execContainer": "0-3,7"
441457
}
442458
}
443459
```

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] istead, which allow 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)