Skip to content

Commit 2222349

Browse files
committed
api,adaptation,generate: allow setting scheduler attributes.
Allow setting/resetting container linux scheduler attributes. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 5c6533b commit 2222349

File tree

11 files changed

+1691
-687
lines changed

11 files changed

+1691
-687
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ The following pieces of container metadata are available to plugins in NRI:
205205
- cpuset memory
206206
- Block I/O class
207207
- RDT class
208+
- scheduling policy parameters
208209
- container (init) process ID
209210
- container (init process) exit status
210211
- timestamp of container creation
@@ -250,6 +251,7 @@ container parameters:
250251
- cpuset memory
251252
- Block I/O class
252253
- RDT class
254+
- scheduling policy parameters
253255

254256
### Container Updates
255257

pkg/adaptation/adaptation_suite_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,20 @@ var _ = Describe("Plugin container creation adjustments", func() {
514514
},
515515
)
516516

517+
case "linux scheduler":
518+
a.SetLinuxScheduler(&api.LinuxScheduler{
519+
Policy: api.LinuxSchedulerPolicy_SCHED_FIFO,
520+
Priority: 10,
521+
Flags: []api.LinuxSchedulerFlag{
522+
api.LinuxSchedulerFlag_SCHED_FLAG_RESET_ON_FORK,
523+
},
524+
})
525+
526+
case "clear linux scheduler":
527+
a.SetLinuxScheduler(&api.LinuxScheduler{
528+
Policy: api.LinuxSchedulerPolicy_SCHED_NONE,
529+
})
530+
517531
case "resources/cpu":
518532
a.SetLinuxCPUShares(123)
519533
a.SetLinuxCPUQuota(456)
@@ -700,6 +714,28 @@ var _ = Describe("Plugin container creation adjustments", func() {
700714
},
701715
},
702716
),
717+
Entry("adjust linux scheduler", "linux scheduler",
718+
&api.ContainerAdjustment{
719+
Linux: &api.LinuxContainerAdjustment{
720+
Scheduler: &api.LinuxScheduler{
721+
Policy: api.LinuxSchedulerPolicy_SCHED_FIFO,
722+
Priority: 10,
723+
Flags: []api.LinuxSchedulerFlag{
724+
api.LinuxSchedulerFlag_SCHED_FLAG_RESET_ON_FORK,
725+
},
726+
},
727+
},
728+
},
729+
),
730+
Entry("clear linux scheduler", "clear linux scheduler",
731+
&api.ContainerAdjustment{
732+
Linux: &api.LinuxContainerAdjustment{
733+
Scheduler: &api.LinuxScheduler{
734+
Policy: api.LinuxSchedulerPolicy_SCHED_NONE,
735+
},
736+
},
737+
},
738+
),
703739
Entry("adjust CPU resources", "resources/cpu",
704740
&api.ContainerAdjustment{
705741
Linux: &api.LinuxContainerAdjustment{
@@ -921,6 +957,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
921957
},
922958
),
923959
Entry("adjust resources", "resources/classes", false, true, nil),
960+
Entry("adjust linux scheduler (conflicts)", "linux scheduler", false, true, nil),
924961
)
925962
})
926963

pkg/adaptation/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ type (
8989
LinuxMemory = api.LinuxMemory
9090
LinuxDevice = api.LinuxDevice
9191
LinuxDeviceCgroup = api.LinuxDeviceCgroup
92+
LinuxScheduler = api.LinuxScheduler
93+
LinuxSchedulerPolicy = api.LinuxSchedulerPolicy
94+
LinuxSchedulerFlag = api.LinuxSchedulerFlag
9295
CDIDevice = api.CDIDevice
9396
HugepageLimit = api.HugepageLimit
9497
Hooks = api.Hooks

pkg/adaptation/result.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
221221
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
222222
return err
223223
}
224+
if err := r.adjustLinuxScheduler(rpl.Linux.Scheduler, plugin); err != nil {
225+
return err
226+
}
224227
}
225228
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
226229
return err
@@ -773,6 +776,23 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
773776
return nil
774777
}
775778

779+
func (r *result) adjustLinuxScheduler(sch *LinuxScheduler, plugin string) error {
780+
if sch == nil {
781+
return nil
782+
}
783+
784+
create, id := r.request.create, r.request.create.Container.Id
785+
786+
if err := r.owners.ClaimLinuxScheduler(id, plugin); err != nil {
787+
return err
788+
}
789+
790+
create.Container.Linux.Scheduler = sch
791+
r.reply.adjust.Linux.Scheduler = sch
792+
793+
return nil
794+
}
795+
776796
func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
777797
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
778798
for _, l := range rlimits {

pkg/api/adjustment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ func (a *ContainerAdjustment) SetLinuxOomScoreAdj(value *int) {
283283
a.Linux.OomScoreAdj = Int(value) // using Int(value) from ./options.go to optionally allocate a pointer to normalized copy of value
284284
}
285285

286+
// SetLinuxScheduler records setting the Linux scheduler attributes for a container.
287+
func (a *ContainerAdjustment) SetLinuxScheduler(sch *LinuxScheduler) {
288+
a.initLinux()
289+
a.Linux.Scheduler = sch
290+
}
291+
286292
//
287293
// Initializing a container adjustment and container update.
288294
//

0 commit comments

Comments
 (0)