diff --git a/config.md b/config.md index a1b39adf4..b6725071d 100644 --- a/config.md +++ b/config.md @@ -340,6 +340,17 @@ 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 a runtime parent + process to be run on initially, before the transition to container's + cgroup. This is a a comma-separated list, with dashes to represent + ranges. For example, `0-3,7` represents CPUs 0,1,2,3, and 7. + * **`final`** (string, OPTIONAL) is a list of CPUs the process will be run + on after the transition to container's cgroup. The format is either the + same as for `initial`, or a special value `cgroup` which means container's + CPU affinity, as defined by [cpu.cpus property](./config.md#configLinuxCPUs)). + If omitted or empty, the `initial` setting is kept. ### User @@ -416,7 +427,11 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are "hard": 1024, "soft": 1024 } - ] + ], + "cpuAffinity": { + "initial": "7", + "final": "0-3,7" + } } ``` ### Example (Solaris) diff --git a/schema/config-schema.json b/schema/config-schema.json index 8f2bff772..d52d8ed03 100644 --- a/schema/config-schema.json +++ b/schema/config-schema.json @@ -220,7 +220,23 @@ } } } - } + }, + "cpuAffinity": { + "type": "object", + "required": [ + "initial" + ], + "properties": { + "initial": { + "type": "string", + "pattern": "^[0-9, -]*$" + }, + "final": { + "type": "string", + "pattern": "^[0-9, -]*$" + } + } + } } }, "linux": { diff --git a/specs-go/config.go b/specs-go/config.go index d1236ba72..00bf946e7 100644 --- a/specs-go/config.go +++ b/specs-go/config.go @@ -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. @@ -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,omitempty"` +} + // 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.