Skip to content

Commit a301269

Browse files
committed
cache: enable setting scheduling params in cached containers
Signed-off-by: Antti Kervinen <antti.kervinen@intel.com>
1 parent 9281388 commit a301269

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

pkg/resmgr/cache/cache.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,25 @@ type Container interface {
265265
// SetMemorySwap sets the swap limit in bytes for the container.
266266
SetMemorySwap(int64)
267267

268+
// SetSchedulingPolicy sets the scheduling policy for the container.
269+
SetSchedulingPolicy(nri.LinuxSchedulerPolicy)
270+
// SetSchedulingNice sets the nice value for the container.
271+
SetSchedulingNice(int32)
272+
// SetSchedulingPriority sets the real-time priority for the container.
273+
SetSchedulingPriority(int32)
274+
// SetSchedulingFlags sets the scheduling flags for the container.
275+
SetSchedulingFlags([]nri.LinuxSchedulerFlag)
276+
// SetSchedulingRuntime sets the runtime for the container in microseconds.
277+
SetSchedulingRuntime(uint64)
278+
// SetSchedulingDeadline sets the deadline for the container in microseconds.
279+
SetSchedulingDeadline(uint64)
280+
// SetSchedulingPeriod sets the scheduling period for the container in microseconds.
281+
SetSchedulingPeriod(uint64)
282+
// SetSchedulingIOClass sets the I/O priority class for the container.
283+
SetSchedulingIOClass(nri.IOPrioClass)
284+
// SetSchedulingIOPriority sets the I/O priority for the container.
285+
SetSchedulingIOPriority(int32)
286+
268287
// GetCPUShares gets the CFS CPU shares of the container.
269288
GetCPUShares() int64
270289
// GetCPUQuota gets the CFS CPU quota of the container.
@@ -340,7 +359,9 @@ type container struct {
340359
ResourceUpdates *v1.ResourceRequirements
341360
request interface{}
342361

343-
Resources *nri.LinuxResources
362+
Resources *nri.LinuxResources
363+
LinuxScheduler *nri.LinuxScheduler
364+
LinuxIOPriority *nri.LinuxIOPriority
344365

345366
TopologyHints topology.Hints // Set of topology hints for all containers within Pod
346367
Tags map[string]string // container tags (local dynamic labels)

pkg/resmgr/cache/container.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,14 @@ func (c *container) GetLinuxResources() *nri.LinuxResources {
601601
return c.Resources
602602
}
603603

604+
func (c *container) GetLinuxScheduler() *nri.LinuxScheduler {
605+
return c.LinuxScheduler
606+
}
607+
608+
func (c *container) GetLinuxIOPriority() *nri.LinuxIOPriority {
609+
return c.LinuxIOPriority
610+
}
611+
604612
func (c *container) GetTopologyHints() topology.Hints {
605613
return c.TopologyHints
606614
}
@@ -687,6 +695,18 @@ func (c *container) ensureLinuxResourcesMemory() {
687695
}
688696
}
689697

698+
func (c *container) ensureLinuxScheduler() {
699+
if c.LinuxScheduler == nil {
700+
c.LinuxScheduler = &nri.LinuxScheduler{}
701+
}
702+
}
703+
704+
func (c *container) ensureLinuxIOPriority() {
705+
if c.LinuxIOPriority == nil {
706+
c.LinuxIOPriority = &nri.LinuxIOPriority{}
707+
}
708+
}
709+
690710
func (c *container) SetCPUShares(value int64) {
691711
switch req := c.getPendingRequest().(type) {
692712
case *nri.ContainerAdjustment:
@@ -806,6 +826,93 @@ func (c *container) SetMemorySwap(value int64) {
806826
c.Ctr.Linux.Resources.Memory.Swap = nri.Int64(value)
807827
}
808828

829+
// Scheduling properties can be set only during container creation.
830+
// setSchedulingOnAdjustment is a helper to set scheduling parameters
831+
func (c *container) setSchedulingOnAdjustment(setter func(sch *nri.LinuxScheduler)) {
832+
switch req := c.getPendingRequest().(type) {
833+
case *nri.ContainerAdjustment:
834+
c.ensureLinuxScheduler()
835+
sch := c.GetLinuxScheduler()
836+
setter(sch)
837+
req.SetLinuxScheduler(sch)
838+
default:
839+
log.Error("%s: can't set scheduling parameter: incorrect pending request type %T",
840+
c.PrettyName(), c.request)
841+
return
842+
}
843+
c.markPending(NRI)
844+
}
845+
846+
func (c *container) SetSchedulingPolicy(value nri.LinuxSchedulerPolicy) {
847+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
848+
sch.Policy = value
849+
})
850+
}
851+
852+
func (c *container) SetSchedulingNice(value int32) {
853+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
854+
sch.Nice = value
855+
})
856+
}
857+
858+
func (c *container) SetSchedulingPriority(value int32) {
859+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
860+
sch.Priority = value
861+
})
862+
}
863+
864+
func (c *container) SetSchedulingFlags(value []nri.LinuxSchedulerFlag) {
865+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
866+
sch.Flags = make([]nri.LinuxSchedulerFlag, len(value))
867+
copy(sch.Flags, value)
868+
})
869+
}
870+
871+
func (c *container) SetSchedulingRuntime(value uint64) {
872+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
873+
sch.Runtime = value
874+
})
875+
}
876+
877+
func (c *container) SetSchedulingDeadline(value uint64) {
878+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
879+
sch.Deadline = value
880+
})
881+
}
882+
883+
func (c *container) SetSchedulingPeriod(value uint64) {
884+
c.setSchedulingOnAdjustment(func(sch *nri.LinuxScheduler) {
885+
sch.Period = value
886+
})
887+
}
888+
889+
func (c *container) setIOPriorityOnAdjustment(setter func(iop *nri.LinuxIOPriority)) {
890+
switch req := c.getPendingRequest().(type) {
891+
case *nri.ContainerAdjustment:
892+
c.ensureLinuxIOPriority()
893+
iop := c.GetLinuxIOPriority()
894+
setter(iop)
895+
req.SetLinuxIOPriority(iop)
896+
default:
897+
log.Error("%s: can't set IO priority parameter: incorrect pending request type %T",
898+
c.PrettyName(), c.request)
899+
return
900+
}
901+
c.markPending(NRI)
902+
}
903+
904+
func (c *container) SetSchedulingIOClass(value nri.IOPrioClass) {
905+
c.setIOPriorityOnAdjustment(func(iop *nri.LinuxIOPriority) {
906+
iop.Class = value
907+
})
908+
}
909+
910+
func (c *container) SetSchedulingIOPriority(value int32) {
911+
c.setIOPriorityOnAdjustment(func(iop *nri.LinuxIOPriority) {
912+
iop.Priority = value
913+
})
914+
}
915+
809916
func (c *container) GetCPUShares() int64 {
810917
return int64(c.Ctr.GetLinux().GetResources().GetCpu().GetShares().GetValue())
811918
}

0 commit comments

Comments
 (0)