Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9444658

Browse files
committed
Add CPU affinity to executed processes
This allows to set initial and final CPU affinity for a process being run in a container, which is needed to solve the issue described in [1]. [1] opencontainers/runc#3922 Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9f1fec3 commit 9444658

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

config.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ 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+
* **`cpuAffinity`** (object, OPTIONAL) specifies CPU affinity used to execute the process.
344+
The following properties are available:
345+
* **`initial`** (string, REQUIRED) is a list of CPUs a runtime parent
346+
process to be run on initially, before the transition to container's
347+
cgroup. This is a a comma-separated list, with dashes to represent
348+
ranges. For example, `0-3,7` represents CPUs 0,1,2,3, and 7.
349+
* **`final`** (string, OPTIONAL) is a list of CPUs the process will be run
350+
on after the transition to container's cgroup. The format is the same as
351+
for `initial`. If omitted or empty, the container's default CPU affinity,
352+
as defined by [cpu.cpus property](./config.md#configLinuxCPUs)), is used.
343353

344354
### <a name="configUser" />User
345355

@@ -416,7 +426,11 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
416426
"hard": 1024,
417427
"soft": 1024
418428
}
419-
]
429+
],
430+
"cpuAffinity": {
431+
"initial": "7",
432+
"final": "0-3,7"
433+
}
420434
}
421435
```
422436
### Example (Solaris)

schema/config-schema.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,23 @@
220220
}
221221
}
222222
}
223-
}
223+
},
224+
"cpuAffinity": {
225+
"type": "object",
226+
"required": [
227+
"initial"
228+
],
229+
"properties": {
230+
"initial": {
231+
"type": "string",
232+
"pattern": "^[0-9, -]*$"
233+
},
234+
"final": {
235+
"type": "string",
236+
"pattern": "^[0-9, -]*$"
237+
}
238+
}
239+
}
224240
}
225241
},
226242
"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+
// CPUAffinity specifies CPU affinity for the process.
98+
CPUAffinity *CPUAffinity `json:"cpuAffinity,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"`
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)