Skip to content

Commit 8947849

Browse files
committed
spec: add scheduler entity
extend the process struct to represent scheduling attributes for a process based on the sched_setattr(2) syscall. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 5bc62f1 commit 8947849

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

config.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,33 @@ For Linux-based systems, the `process` object supports the following process-spe
291291

292292
This is a per-process setting, where as [`disableOOMKiller`](config-linux.md#memory) is scoped for a memory cgroup.
293293
For more information on how these two settings work together, see [the memory cgroup documentation section 10. OOM Contol][cgroup-v1-memory_2].
294+
* **`scheduler`** (object, OPTIONAL) is an object describing the scheduler properties for the process. The `scheduler` contains the following properties:
295+
296+
* **`policy`** (string, REQUIRED) represents the scheduling policy. A valid list of values is:
297+
298+
* `SCHED_OTHER`
299+
* `SCHED_FIFO`
300+
* `SCHED_RR`
301+
* `SCHED_BATCH`
302+
* `SCHED_ISO`
303+
* `SCHED_IDLE`
304+
* `SCHED_DEADLINE`
305+
306+
* **`nice`** (int32, OPTIONAL) is the nice value for the process, affecting its priority. A lower nice value corresponds to a higher priority. If not set, the runtime must use the value 0.
307+
* **`priority`** (int32, OPTIONAL) represents the static priority of the process, used by real-time policies like SCHED_FIFO and SCHED_RR. If not set, the runtime must use the value 0.
308+
* **`flags`** (array of strings, OPTIONAL) is an array of strings representing scheduling flags. A valid list of values is:
309+
310+
* `SCHED_FLAG_RESET_ON_FORK`
311+
* `SCHED_FLAG_RECLAIM`
312+
* `SCHED_FLAG_DL_OVERRUN`
313+
* `SCHED_FLAG_KEEP_POLICY`
314+
* `SCHED_FLAG_KEEP_PARAMS`
315+
* `SCHED_FLAG_UTIL_CLAMP_MIN`
316+
* `SCHED_FLAG_UTIL_CLAMP_MAX`
317+
318+
* **`runtime`** (uint64, OPTIONAL) represents the amount of time in nanoseconds during which the process is allowed to run in a given period, used by the deadline scheduler. If not set, the runtime must use the value 0.
319+
* **`deadline`** (uint64, OPTIONAL) represents the absolute deadline for the process to complete its execution, used by the deadline scheduler. If not set, the runtime must use the value 0.
320+
* **`period`** (uint64, OPTIONAL) represents the length of the period in nanoseconds used for determining the process runtime, used by the deadline scheduler. If not set, the runtime must use the value 0.
294321
* **`selinuxLabel`** (string, OPTIONAL) specifies the SELinux label for the process.
295322
For more information about SELinux, see [SELinux documentation][selinux].
296323

schema/config-schema.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,38 @@
147147
"noNewPrivileges": {
148148
"type": "boolean"
149149
},
150+
"scheduler": {
151+
"type": "object",
152+
"required": [
153+
"policy"
154+
],
155+
"properties": {
156+
"policy": {
157+
"$ref": "defs-linux.json#/definitions/SchedulerPolicy"
158+
},
159+
"nice": {
160+
"$ref": "defs.json#/definitions/int32"
161+
},
162+
"priority": {
163+
"$ref": "defs.json#/definitions/int32"
164+
},
165+
"flags": {
166+
"type": "array",
167+
"items": {
168+
"$ref": "defs-linux.json#/definitions/SchedulerFlag"
169+
}
170+
},
171+
"runtime": {
172+
"$ref": "defs.json#/definitions/uint64"
173+
},
174+
"deadline": {
175+
"$ref": "defs.json#/definitions/uint64"
176+
},
177+
"period": {
178+
"$ref": "defs.json#/definitions/uint64"
179+
}
180+
}
181+
},
150182
"rlimits": {
151183
"type": "array",
152184
"items": {

schema/defs-linux.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,30 @@
323323
"$ref": "defs.json#/definitions/uint32"
324324
}
325325
}
326+
},
327+
"SchedulerPolicy": {
328+
"type": "string",
329+
"enum": [
330+
"SCHED_OTHER",
331+
"SCHED_FIFO",
332+
"SCHED_RR",
333+
"SCHED_BATCH",
334+
"SCHED_ISO",
335+
"SCHED_IDLE",
336+
"SCHED_DEADLINE"
337+
]
338+
},
339+
"SchedulerFlag": {
340+
"type": "string",
341+
"enum": [
342+
"SCHED_FLAG_RESET_ON_FORK",
343+
"SCHED_FLAG_RECLAIM",
344+
"SCHED_FLAG_DL_OVERRUN",
345+
"SCHED_FLAG_KEEP_POLICY",
346+
"SCHED_FLAG_KEEP_PARAMS",
347+
"SCHED_FLAG_UTIL_CLAMP_MIN",
348+
"SCHED_FLAG_UTIL_CLAMP_MAX"
349+
]
326350
}
327351
}
328352
}

specs-go/config.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ type Spec struct {
3333
ZOS *ZOS `json:"zos,omitempty" platform:"zos"`
3434
}
3535

36+
// Scheduler represents the scheduling attributes for a process. It is based on
37+
// the Linux sched_setattr(2) syscall.
38+
type Scheduler struct {
39+
// Policy represents the scheduling policy (e.g., SCHED_FIFO, SCHED_RR, SCHED_OTHER).
40+
Policy LinuxSchedulerPolicy `json:"policy"`
41+
42+
// Nice is the nice value for the process, which affects its priority.
43+
Nice int32 `json:"nice,omitempty"`
44+
45+
// Priority represents the static priority of the process.
46+
Priority int32 `json:"priority,omitempty"`
47+
48+
// Flags is an array of scheduling flags.
49+
Flags []LinuxSchedulerFlag `json:"flags,omitempty"`
50+
51+
// The following ones are used by the DEADLINE scheduler.
52+
53+
// Runtime is the amount of time in nanoseconds during which the process
54+
// is allowed to run in a given period.
55+
Runtime uint64 `json:"runtime,omitempty"`
56+
57+
// Deadline is the absolute deadline for the process to complete its execution.
58+
Deadline uint64 `json:"deadline,omitempty"`
59+
60+
// Period is the length of the period in nanoseconds used for determining the process runtime.
61+
Period uint64 `json:"period,omitempty"`
62+
}
63+
3664
// Process contains information to start a specific application inside the container.
3765
type Process struct {
3866
// Terminal creates an interactive terminal for the container.
@@ -60,6 +88,8 @@ type Process struct {
6088
ApparmorProfile string `json:"apparmorProfile,omitempty" platform:"linux"`
6189
// Specify an oom_score_adj for the container.
6290
OOMScoreAdj *int `json:"oomScoreAdj,omitempty" platform:"linux"`
91+
// Scheduler specifies the scheduling attributes for a process
92+
Scheduler *Scheduler `json:"scheduler,omitempty" platform:"linux"`
6393
// SelinuxLabel specifies the selinux context that the container process is run as.
6494
SelinuxLabel string `json:"selinuxLabel,omitempty" platform:"linux"`
6595
}
@@ -789,3 +819,43 @@ type ZOSDevice struct {
789819
// Gid of the device.
790820
GID *uint32 `json:"gid,omitempty"`
791821
}
822+
823+
// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
824+
type LinuxSchedulerPolicy string
825+
826+
const (
827+
// SchedOther is the default scheduling policy
828+
SchedOther LinuxSchedulerPolicy = "SCHED_OTHER"
829+
// SchedFIFO is the First-In-First-Out scheduling policy
830+
SchedFIFO LinuxSchedulerPolicy = "SCHED_FIFO"
831+
// SchedRR is the Round-Robin scheduling policy
832+
SchedRR LinuxSchedulerPolicy = "SCHED_RR"
833+
// SchedBatch is the Batch scheduling policy
834+
SchedBatch LinuxSchedulerPolicy = "SCHED_BATCH"
835+
// SchedISO is the Isolation scheduling policy
836+
SchedISO LinuxSchedulerPolicy = "SCHED_ISO"
837+
// SchedIdle is the Idle scheduling policy
838+
SchedIdle LinuxSchedulerPolicy = "SCHED_IDLE"
839+
// SchedDeadline is the Deadline scheduling policy
840+
SchedDeadline LinuxSchedulerPolicy = "SCHED_DEADLINE"
841+
)
842+
843+
// LinuxSchedulerFlag represents the flags used by the Linux Scheduler.
844+
type LinuxSchedulerFlag string
845+
846+
const (
847+
// SchedFlagResetOnFork represents the reset on fork scheduling flag
848+
SchedFlagResetOnFork LinuxSchedulerFlag = "SCHED_FLAG_RESET_ON_FORK"
849+
// SchedFlagReclaim represents the reclaim scheduling flag
850+
SchedFlagReclaim LinuxSchedulerFlag = "SCHED_FLAG_RECLAIM"
851+
// SchedFlagDLOverrun represents the deadline overrun scheduling flag
852+
SchedFlagDLOverrun LinuxSchedulerFlag = "SCHED_FLAG_DL_OVERRUN"
853+
// SchedFlagKeepPolicy represents the keep policy scheduling flag
854+
SchedFlagKeepPolicy LinuxSchedulerFlag = "SCHED_FLAG_KEEP_POLICY"
855+
// SchedFlagKeepParams represents the keep parameters scheduling flag
856+
SchedFlagKeepParams LinuxSchedulerFlag = "SCHED_FLAG_KEEP_PARAMS"
857+
// SchedFlagUtilClampMin represents the utilization clamp minimum scheduling flag
858+
SchedFlagUtilClampMin LinuxSchedulerFlag = "SCHED_FLAG_UTIL_CLAMP_MIN"
859+
// SchedFlagUtilClampMin represents the utilization clamp maximum scheduling flag
860+
SchedFlagUtilClampMax LinuxSchedulerFlag = "SCHED_FLAG_UTIL_CLAMP_MAX"
861+
)

0 commit comments

Comments
 (0)