@@ -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+
604612func (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+
690710func (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+
809916func (c * container ) GetCPUShares () int64 {
810917 return int64 (c .Ctr .GetLinux ().GetResources ().GetCpu ().GetShares ().GetValue ())
811918}
0 commit comments