Skip to content

Commit f3bfc57

Browse files
committed
libcontainer/intelrdt: support ClosID parameter
Handle ClosID parameter of IntelRdt. Makes it possible to use pre-configured classes/ClosIDs and avoid running out of available IDs which easily happens with per-container classes. Remove validator checks for empty L3CacheSchema and MemBwSchema fields in order to be able to leave them empty, and only specify ClosID for a pre-configured class. Signed-off-by: Markus Lehtonen <[email protected]>
1 parent e47164c commit f3bfc57

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

libcontainer/configs/intelrdt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package configs
22

33
type IntelRdt struct {
4+
// The identity for RDT Class of Service
5+
ClosID string `json:"closID,omitempty"`
6+
47
// The schema for L3 cache id and capacity bitmask (CBM)
58
// Format: "L3:<cache_id0>=<cbm0>;<cache_id1>=<cbm1>;..."
69
L3CacheSchema string `json:"l3_cache_schema,omitempty"`

libcontainer/configs/validate/validator.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,16 @@ func (v *ConfigValidator) intelrdt(config *configs.Config) error {
205205
return errors.New("intelRdt is specified in config, but Intel RDT is not supported or enabled")
206206
}
207207

208+
if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || strings.Contains(config.IntelRdt.ClosID, "/") {
209+
return fmt.Errorf("invalid intelRdt.ClosID %q", config.IntelRdt.ClosID)
210+
}
211+
208212
if !intelrdt.IsCATEnabled() && config.IntelRdt.L3CacheSchema != "" {
209213
return errors.New("intelRdt.l3CacheSchema is specified in config, but Intel RDT/CAT is not enabled")
210214
}
211215
if !intelrdt.IsMBAEnabled() && config.IntelRdt.MemBwSchema != "" {
212216
return errors.New("intelRdt.memBwSchema is specified in config, but Intel RDT/MBA is not enabled")
213217
}
214-
215-
if intelrdt.IsCATEnabled() && config.IntelRdt.L3CacheSchema == "" {
216-
return errors.New("Intel RDT/CAT is enabled and intelRdt is specified in config, but intelRdt.l3CacheSchema is empty")
217-
}
218-
if intelrdt.IsMBAEnabled() && config.IntelRdt.MemBwSchema == "" {
219-
return errors.New("Intel RDT/MBA is enabled and intelRdt is specified in config, but intelRdt.memBwSchema is empty")
220-
}
221218
}
222219

223220
return nil

libcontainer/intelrdt/intelrdt.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,12 @@ func (m *intelRdtManager) getIntelRdtPath() (string, error) {
525525
return "", err
526526
}
527527

528-
return filepath.Join(rootPath, m.id), nil
528+
clos := m.id
529+
if m.config.IntelRdt != nil && m.config.IntelRdt.ClosID != "" {
530+
clos = m.config.IntelRdt.ClosID
531+
}
532+
533+
return filepath.Join(rootPath, clos), nil
529534
}
530535

531536
// Applies Intel RDT configuration to the process with the specified pid
@@ -557,12 +562,17 @@ func (m *intelRdtManager) Apply(pid int) (err error) {
557562

558563
// Destroys the Intel RDT 'container_id' group
559564
func (m *intelRdtManager) Destroy() error {
560-
m.mu.Lock()
561-
defer m.mu.Unlock()
562-
if err := os.RemoveAll(m.GetPath()); err != nil {
563-
return err
565+
// Don't remove resctrl group if closid has been explicitly specified. The
566+
// group is likely externally managed, i.e. by some other entity than us.
567+
// There are probably other containers/tasks sharing the same group.
568+
if m.config.IntelRdt == nil || m.config.IntelRdt.ClosID == "" {
569+
m.mu.Lock()
570+
defer m.mu.Unlock()
571+
if err := os.RemoveAll(m.GetPath()); err != nil {
572+
return err
573+
}
574+
m.path = ""
564575
}
565-
m.path = ""
566576
return nil
567577
}
568578

libcontainer/specconv/spec_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
301301
}
302302
if spec.Linux.IntelRdt != nil {
303303
config.IntelRdt = &configs.IntelRdt{
304+
ClosID: spec.Linux.IntelRdt.ClosID,
304305
L3CacheSchema: spec.Linux.IntelRdt.L3CacheSchema,
305306
MemBwSchema: spec.Linux.IntelRdt.MemBwSchema,
306307
}

0 commit comments

Comments
 (0)