Skip to content

Commit d1418ab

Browse files
authored
Merge pull request #160 from klihub/devel/linux-scheduler-policy
api,adaptation,generate: allow setting kernel scheduling policy attributes.
2 parents 649a151 + 6a371ac commit d1418ab

File tree

12 files changed

+1946
-846
lines changed

12 files changed

+1946
-846
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ The following pieces of container metadata are available to plugins in NRI:
210210
- Unified cgroup v2 parameter map
211211
- Linux seccomp profile and policy
212212
- Linux network devices
213+
- scheduling policy parameters
213214
- container (init) process ID
214215
- container (init process) exit status
215216
- timestamp of container creation
@@ -260,6 +261,7 @@ container parameters:
260261
- Linux seccomp policy
261262
- Linux network devices
262263
- Linux namespaces
264+
- scheduling policy parameters
263265

264266
### Container Updates
265267

pkg/adaptation/adaptation_suite_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,20 @@ var _ = Describe("Plugin container creation adjustments", func() {
543543
},
544544
)
545545

546+
case "linux scheduler":
547+
a.SetLinuxScheduler(&api.LinuxScheduler{
548+
Policy: api.LinuxSchedulerPolicy_SCHED_FIFO,
549+
Priority: 10,
550+
Flags: []api.LinuxSchedulerFlag{
551+
api.LinuxSchedulerFlag_SCHED_FLAG_RESET_ON_FORK,
552+
},
553+
})
554+
555+
case "clear linux scheduler":
556+
a.SetLinuxScheduler(&api.LinuxScheduler{
557+
Policy: api.LinuxSchedulerPolicy_SCHED_NONE,
558+
})
559+
546560
case "resources/cpu":
547561
a.SetLinuxCPUShares(123)
548562
a.SetLinuxCPUQuota(456)
@@ -801,13 +815,36 @@ var _ = Describe("Plugin container creation adjustments", func() {
801815
},
802816
),
803817

818+
Entry("adjust linux scheduler", "linux scheduler",
819+
&api.ContainerAdjustment{
820+
Linux: &api.LinuxContainerAdjustment{
821+
Scheduler: &api.LinuxScheduler{
822+
Policy: api.LinuxSchedulerPolicy_SCHED_FIFO,
823+
Priority: 10,
824+
Flags: []api.LinuxSchedulerFlag{
825+
api.LinuxSchedulerFlag_SCHED_FLAG_RESET_ON_FORK,
826+
},
827+
},
828+
},
829+
},
830+
),
831+
804832
Entry("clear I/O priority", "clear I/O priority",
805833
&api.ContainerAdjustment{
806834
Linux: &api.LinuxContainerAdjustment{
807835
IoPriority: &api.LinuxIOPriority{},
808836
},
809837
},
810838
),
839+
Entry("clear linux scheduler", "clear linux scheduler",
840+
&api.ContainerAdjustment{
841+
Linux: &api.LinuxContainerAdjustment{
842+
Scheduler: &api.LinuxScheduler{
843+
Policy: api.LinuxSchedulerPolicy_SCHED_NONE,
844+
},
845+
},
846+
},
847+
),
811848

812849
Entry("adjust CPU resources", "resources/cpu",
813850
&api.ContainerAdjustment{
@@ -1071,6 +1108,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
10711108
Entry("adjust resources", "resources/classes", false, true, nil),
10721109

10731110
Entry("adjust I/O priority (conflicts)", "I/O priority", false, true, nil),
1111+
10741112
Entry("adjust linux net devices", "linux net device", true, false,
10751113
&api.ContainerAdjustment{
10761114
Linux: &api.LinuxContainerAdjustment{
@@ -1084,6 +1122,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
10841122
},
10851123
),
10861124
Entry("adjust linux net devices (conflicts)", "linux net device", false, true, nil),
1125+
Entry("adjust linux scheduler (conflicts)", "linux scheduler", false, true, nil),
10871126
)
10881127
})
10891128

pkg/adaptation/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type (
9393
LinuxIOPriority = api.LinuxIOPriority
9494
LinuxSeccomp = api.LinuxSeccomp
9595
LinuxNetDevice = api.LinuxNetDevice
96+
LinuxScheduler = api.LinuxScheduler
97+
LinuxSchedulerPolicy = api.LinuxSchedulerPolicy
98+
LinuxSchedulerFlag = api.LinuxSchedulerFlag
9699
CDIDevice = api.CDIDevice
97100
HugepageLimit = api.HugepageLimit
98101
Hooks = api.Hooks

pkg/adaptation/result.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
245245
if err := r.adjustLinuxNetDevices(rpl.Linux.NetDevices, plugin); err != nil {
246246
return err
247247
}
248+
if err := r.adjustLinuxScheduler(rpl.Linux.Scheduler, plugin); err != nil {
249+
return err
250+
}
248251
}
249252
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
250253
return err
@@ -954,6 +957,23 @@ func (r *result) adjustSeccompPolicy(adjustment *LinuxSeccomp, plugin string) er
954957
return nil
955958
}
956959

960+
func (r *result) adjustLinuxScheduler(sch *LinuxScheduler, plugin string) error {
961+
if sch == nil {
962+
return nil
963+
}
964+
965+
create, id := r.request.create, r.request.create.Container.Id
966+
967+
if err := r.owners.ClaimLinuxScheduler(id, plugin); err != nil {
968+
return err
969+
}
970+
971+
create.Container.Linux.Scheduler = sch
972+
r.reply.adjust.Linux.Scheduler = sch
973+
974+
return nil
975+
}
976+
957977
func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
958978
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
959979
for _, l := range rlimits {

pkg/api/adjustment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ func (a *ContainerAdjustment) SetLinuxSysctl(key, value string) {
337337
a.Linux.Sysctl[key] = value
338338
}
339339

340+
// SetLinuxScheduler records setting the Linux scheduler attributes for a container.
341+
func (a *ContainerAdjustment) SetLinuxScheduler(sch *LinuxScheduler) {
342+
a.initLinux()
343+
a.Linux.Scheduler = sch
344+
}
345+
340346
//
341347
// Initializing a container adjustment and container update.
342348
//

0 commit comments

Comments
 (0)