Skip to content

Commit 4693fae

Browse files
Merge pull request #1590 from xiaochenshen/rdt-cat-support-update-command
libcontainer: intelrdt: add update command support
2 parents f53ad9c + 65918b0 commit 4693fae

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

libcontainer/factory_linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
213213
newgidmapPath: l.NewgidmapPath,
214214
cgroupManager: l.NewCgroupsManager(config.Cgroups, nil),
215215
}
216-
c.intelRdtManager = nil
217-
if intelrdt.IsEnabled() && c.config.IntelRdt != nil {
216+
if intelrdt.IsEnabled() {
218217
c.intelRdtManager = l.NewIntelRdtManager(config, id, "")
219218
}
220219
c.state = &stoppedState{c: c}
@@ -256,8 +255,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
256255
if err := c.refreshState(); err != nil {
257256
return nil, err
258257
}
259-
c.intelRdtManager = nil
260-
if intelrdt.IsEnabled() && c.config.IntelRdt != nil {
258+
if intelrdt.IsEnabled() {
261259
c.intelRdtManager = l.NewIntelRdtManager(&state.Config, id, state.IntelRdtPath)
262260
}
263261
return c, nil

libcontainer/intelrdt/intelrdt.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ func GetIntelRdtPath(id string) (string, error) {
401401

402402
// Applies Intel RDT configuration to the process with the specified pid
403403
func (m *IntelRdtManager) Apply(pid int) (err error) {
404+
// If intelRdt is not specified in config, we do nothing
405+
if m.Config.IntelRdt == nil {
406+
return nil
407+
}
404408
d, err := getIntelRdtData(m.Config, pid)
405409
if err != nil && !IsNotFound(err) {
406410
return err

update.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strconv"
1010

1111
"github.com/docker/go-units"
12+
"github.com/opencontainers/runc/libcontainer/configs"
13+
"github.com/opencontainers/runc/libcontainer/intelrdt"
1214
"github.com/opencontainers/runtime-spec/specs-go"
1315
"github.com/urfave/cli"
1416
)
@@ -112,6 +114,10 @@ other options are ignored.
112114
Name: "pids-limit",
113115
Usage: "Maximum number of pids allowed in the container",
114116
},
117+
cli.StringFlag{
118+
Name: "l3-cache-schema",
119+
Usage: "The string of Intel RDT/CAT L3 cache schema",
120+
},
115121
},
116122
Action: func(context *cli.Context) error {
117123
if err := checkArgs(context, 1, exactArgs); err != nil {
@@ -254,6 +260,34 @@ other options are ignored.
254260
config.Cgroups.Resources.MemorySwap = *r.Memory.Swap
255261
config.Cgroups.Resources.PidsLimit = r.Pids.Limit
256262

263+
// Update Intel RDT/CAT
264+
if val := context.String("l3-cache-schema"); val != "" {
265+
if !intelrdt.IsEnabled() {
266+
return fmt.Errorf("Intel RDT: l3 cache schema is not enabled")
267+
}
268+
269+
// If intelRdt is not specified in original configuration, we just don't
270+
// Apply() to create intelRdt group or attach tasks for this container.
271+
// In update command, we could re-enable through IntelRdtManager.Apply()
272+
// and then update intelrdt constraint.
273+
if config.IntelRdt == nil {
274+
state, err := container.State()
275+
if err != nil {
276+
return err
277+
}
278+
config.IntelRdt = &configs.IntelRdt{}
279+
intelRdtManager := intelrdt.IntelRdtManager{
280+
Config: &config,
281+
Id: container.ID(),
282+
Path: state.IntelRdtPath,
283+
}
284+
if err := intelRdtManager.Apply(state.InitProcessPid); err != nil {
285+
return err
286+
}
287+
}
288+
config.IntelRdt.L3CacheSchema = val
289+
}
290+
257291
return container.Set(config)
258292
},
259293
}

0 commit comments

Comments
 (0)