Skip to content

Commit d05dd81

Browse files
marquizklihub
andcommitted
pkg/adaptation: support new RDT fields
Add support for direct manipulation of the intelRdt object of the container config. Co-authored-by: Krisztian Litkey <[email protected]> Signed-off-by: Markus Lehtonen <[email protected]>
1 parent 725289b commit d05dd81

3 files changed

Lines changed: 96 additions & 8 deletions

File tree

pkg/adaptation/adaptation_suite_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ var _ = Describe("Plugin container creation adjustments", func() {
608608
return api.FromOCILinuxSeccomp(&seccomp)
609609
}(),
610610
)
611+
case "rdt":
612+
if overwrite {
613+
a.SetLinuxRDTClosID(p.name)
614+
} else {
615+
a.SetLinuxRDTSchemata([]string{"L3:0=ff", "MB:0=50"})
616+
a.SetLinuxRDTEnableMonitoring(true)
617+
}
611618
}
612619

613620
return a, nil, nil
@@ -948,6 +955,16 @@ var _ = Describe("Plugin container creation adjustments", func() {
948955
},
949956
},
950957
),
958+
Entry("adjust RDT", "rdt",
959+
&api.ContainerAdjustment{
960+
Linux: &api.LinuxContainerAdjustment{
961+
Rdt: &api.LinuxRdt{
962+
Schemata: api.RepeatedString([]string{"L3:0=ff", "MB:0=50"}),
963+
EnableMonitoring: api.Bool(true),
964+
},
965+
},
966+
},
967+
),
951968
)
952969
})
953970

@@ -1121,8 +1138,22 @@ var _ = Describe("Plugin container creation adjustments", func() {
11211138
},
11221139
},
11231140
),
1141+
11241142
Entry("adjust linux net devices (conflicts)", "linux net device", false, true, nil),
11251143
Entry("adjust linux scheduler (conflicts)", "linux scheduler", false, true, nil),
1144+
1145+
Entry("adjust RDT (conflicts)", "rdt", false, true, nil),
1146+
Entry("adjust RDT", "rdt", true, false,
1147+
&api.ContainerAdjustment{
1148+
Linux: &api.LinuxContainerAdjustment{
1149+
Rdt: &api.LinuxRdt{
1150+
ClosId: api.String("foo"),
1151+
Schemata: api.RepeatedString([]string{"L3:0=ff", "MB:0=50"}),
1152+
EnableMonitoring: api.Bool(true),
1153+
},
1154+
},
1155+
},
1156+
),
11261157
)
11271158
})
11281159

pkg/adaptation/api.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type (
9696
LinuxScheduler = api.LinuxScheduler
9797
LinuxSchedulerPolicy = api.LinuxSchedulerPolicy
9898
LinuxSchedulerFlag = api.LinuxSchedulerFlag
99+
LinuxRdt = api.LinuxRdt
99100
CDIDevice = api.CDIDevice
100101
HugepageLimit = api.HugepageLimit
101102
Hooks = api.Hooks
@@ -156,14 +157,15 @@ type (
156157

157158
// Aliased functions for api/optional.go.
158159
var (
159-
String = api.String
160-
Int = api.Int
161-
Int32 = api.Int32
162-
UInt32 = api.UInt32
163-
Int64 = api.Int64
164-
UInt64 = api.UInt64
165-
Bool = api.Bool
166-
FileMode = api.FileMode
160+
String = api.String
161+
RepeatedString = api.RepeatedString
162+
Int = api.Int
163+
Int32 = api.Int32
164+
UInt32 = api.UInt32
165+
Int64 = api.Int64
166+
UInt64 = api.UInt64
167+
Bool = api.Bool
168+
FileMode = api.FileMode
167169
)
168170

169171
// Aliased functions for api/types.go.

pkg/adaptation/result.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
248248
if err := r.adjustLinuxScheduler(rpl.Linux.Scheduler, plugin); err != nil {
249249
return err
250250
}
251+
if err := r.adjustRdt(rpl.Linux.Rdt, plugin); err != nil {
252+
return err
253+
}
251254
}
255+
252256
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
253257
return err
254258
}
@@ -499,6 +503,37 @@ func (r *result) adjustSysctl(sysctl map[string]string, plugin string) error {
499503
return nil
500504
}
501505

506+
func (r *result) adjustRdt(rdt *LinuxRdt, plugin string) error {
507+
if r == nil {
508+
return nil
509+
}
510+
511+
r.initAdjustRdt()
512+
513+
id := r.request.create.Container.Id
514+
515+
if v := rdt.GetClosId(); v != nil {
516+
if err := r.owners.ClaimRdtClosID(id, plugin); err != nil {
517+
return err
518+
}
519+
r.reply.adjust.Linux.Rdt.ClosId = String(v.GetValue())
520+
}
521+
if v := rdt.GetSchemata(); v != nil {
522+
if err := r.owners.ClaimRdtSchemata(id, plugin); err != nil {
523+
return err
524+
}
525+
r.reply.adjust.Linux.Rdt.Schemata = RepeatedString(v.GetValue())
526+
}
527+
if v := rdt.GetEnableMonitoring(); v != nil {
528+
if err := r.owners.ClaimRdtEnableMonitoring(id, plugin); err != nil {
529+
return err
530+
}
531+
r.reply.adjust.Linux.Rdt.EnableMonitoring = Bool(v.GetValue())
532+
}
533+
534+
return nil
535+
}
536+
502537
func (r *result) adjustCDIDevices(devices []*CDIDevice, plugin string) error {
503538
if len(devices) == 0 {
504539
return nil
@@ -1131,3 +1166,23 @@ func (r *result) getContainerUpdate(u *ContainerUpdate, plugin string) (*Contain
11311166

11321167
return update, nil
11331168
}
1169+
1170+
func (r *result) initAdjust() {
1171+
if r.reply.adjust == nil {
1172+
r.reply.adjust = &ContainerAdjustment{}
1173+
}
1174+
}
1175+
1176+
func (r *result) initAdjustLinux() {
1177+
r.initAdjust()
1178+
if r.reply.adjust.Linux == nil {
1179+
r.reply.adjust.Linux = &LinuxContainerAdjustment{}
1180+
}
1181+
}
1182+
1183+
func (r *result) initAdjustRdt() {
1184+
r.initAdjustLinux()
1185+
if r.reply.adjust.Linux.Rdt == nil {
1186+
r.reply.adjust.Linux.Rdt = &LinuxRdt{}
1187+
}
1188+
}

0 commit comments

Comments
 (0)