Skip to content

Commit

Permalink
Add CPU affinity to executed processes
Browse files Browse the repository at this point in the history
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 <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed May 18, 2024
1 parent 2d3f72e commit 50f9f1a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ For Linux-based systems, the `process` object supports the following process-spe

* **`class`** (string, REQUIRED) specifies the I/O scheduling class. Possible values are `IOPRIO_CLASS_RT`, `IOPRIO_CLASS_BE`, and `IOPRIO_CLASS_IDLE`.
* **`priority`** (int, REQUIRED) specifies the priority level within the class. The value should be an integer ranging from 0 (highest) to 7 (lowest).
* **`cpuAffinity`** (object, OPTIONAL) specifies CPU affinity used to execute the process.
The following properties are available:
* **`initial`** (string, REQUIRED) is a list of CPUs the process will be run on initially, before the transition to container's cgroup.
* **`final`** (string, OPTIONAL) is a list of CPUs the process will be run on after the transition to container's cgroup. Empty string means to keep the initial setting. A special value `cgroup` means container's CPU affinity (as defined by [cpu.cpus property](./config.md#configLinuxCPUs)).

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

Expand Down
18 changes: 17 additions & 1 deletion schema/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,23 @@
}
}
}
}
},
"cpuAffinity": {
"type": "object",
"required": [
"initial"
],
"properties": {
"initial": {
"type": "string",
"pattern": "^[0-9, -]*$"
},
"final": {
"type": "string",
"pattern": "^[0-9, -]*$"
}
}
}
}
},
"linux": {
Expand Down
8 changes: 8 additions & 0 deletions specs-go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type Process struct {
SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
// IOPriority contains the I/O priority settings for the cgroup.
IOPriority *LinuxIOPriority `json:"ioPriority,omitempty" platform:"linux"`
// CPUAffinity specifies CPU affinity for the process.
CPUAffinity *CPUAffinity `json:"cpuAffinity,omitempty" platform:"linux"`
}

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

// CPUAffinity specifies process' CPU affinity.
type CPUAffinity struct {
Initial string `json:"initial"`
Final string `json:"final"`
}

// Box specifies dimensions of a rectangle. Used for specifying the size of a console.
type Box struct {
// Height is the vertical dimension of a box.
Expand Down

0 comments on commit 50f9f1a

Please sign in to comment.