File: Add-CPU-affinity-to-executed-processes.patch

package info (click to toggle)
golang-github-opencontainers-specs 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704 kB
  • sloc: makefile: 115
file content (107 lines) | stat: -rw-r--r-- 4,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
From 119ae426a12298a57b5d0828017c878f34fb7cf0 Mon Sep 17 00:00:00 2001
From: Kir Kolyshkin <kolyshkin@gmail.com>
Date: Fri, 17 May 2024 18:16:27 -0700
Subject: [PATCH 10/15] 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] https://github.com/opencontainers/runc/issues/3922

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
---
 config.md                 | 17 ++++++++++++++++-
 schema/config-schema.json | 15 ++++++++++++++-
 specs-go/config.go        |  8 ++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/config.md b/config.md
index a1b39ad..b9b5573 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).
+* **`execCPUAffinity`** (object, OPTIONAL) specifies CPU affinity used to execute the process.
+    This setting is not applicable to the container's init process.
+    The following properties are available:
+    * **`initial`** (string, OPTIONAL) 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 the same as
+      for `initial`. If omitted or empty, the container's default CPU affinity,
+      as defined by [cpu.cpus property](./config.md#configLinuxCPUs)), is used.
 
 ### <a name="configUser" />User
 
@@ -416,7 +427,11 @@ _Note: symbolic name for uid and gid, such as uname and gname respectively, are
             "hard": 1024,
             "soft": 1024
         }
-    ]
+    ],
+    "execCPUAffinity": {
+        "initial": "7",
+        "final": "0-3,7"
+    }
 }
 ```
 ### Example (Solaris)
diff --git a/schema/config-schema.json b/schema/config-schema.json
index 4d549bf..cb74342 100644
--- a/schema/config-schema.json
+++ b/schema/config-schema.json
@@ -220,7 +220,20 @@
                             }
                         }
                     }
-                }
+                },
+                "execCPUAffinity": {
+                    "type": "object",
+                    "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 d1236ba..671f0d0 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"`
+	// ExecCPUAffinity specifies CPU affinity for exec processes.
+	ExecCPUAffinity *CPUAffinity `json:"execCPUAffinity,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,omitempty"`
+	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.
-- 
2.45.2