Skip to content

Commit 88604c3

Browse files
committed
libcontainer/intelrdt: add support for EnableMonitoring field
The linux.intelRdt.enableMonitoring field enables the creation of a per-container monitoring group. The monitoring group is removed when the container is destroyed. Signed-off-by: Markus Lehtonen <[email protected]>
1 parent 703e2d4 commit 88604c3

File tree

7 files changed

+247
-43
lines changed

7 files changed

+247
-43
lines changed

features.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ var featuresCommand = cli.Command{
5656
Enabled: &t,
5757
},
5858
IntelRdt: &features.IntelRdt{
59-
Enabled: &t,
59+
Enabled: &t,
60+
Monitoring: &t,
6061
},
6162
MountExtensions: &features.MountExtensions{
6263
IDMap: &features.IDMap{

libcontainer/configs/intelrdt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ type IntelRdt struct {
1313
// The unit of memory bandwidth is specified in "percentages" by
1414
// default, and in "MBps" if MBA Software Controller is enabled.
1515
MemBwSchema string `json:"memBwSchema,omitempty"`
16+
17+
// Create a monitoring group for the container.
18+
EnableMonitoring bool `json:"enableMonitoring,omitempty"`
1619
}

libcontainer/configs/validate/intelrdt_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,24 @@ func TestValidateIntelRdt(t *testing.T) {
1919
isErr bool
2020
}{
2121
{
22-
name: "rdt not supported, no config",
23-
rdtEnabled: false,
24-
config: nil,
25-
isErr: false,
22+
name: "rdt not supported, no config",
2623
},
2724
{
28-
name: "rdt not supported, with config",
29-
rdtEnabled: false,
30-
config: &configs.IntelRdt{},
31-
isErr: true,
25+
name: "rdt not supported, with config",
26+
config: &configs.IntelRdt{},
27+
isErr: true,
3228
},
3329
{
3430
name: "empty config",
3531
rdtEnabled: true,
3632
config: &configs.IntelRdt{},
37-
isErr: false,
3833
},
3934
{
4035
name: "root clos",
4136
rdtEnabled: true,
4237
config: &configs.IntelRdt{
4338
ClosID: "/",
4439
},
45-
isErr: false,
4640
},
4741
{
4842
name: "invalid ClosID (.)",
@@ -71,7 +65,6 @@ func TestValidateIntelRdt(t *testing.T) {
7165
{
7266
name: "cat not supported",
7367
rdtEnabled: true,
74-
catEnabled: false,
7568
config: &configs.IntelRdt{
7669
L3CacheSchema: "0=ff",
7770
},
@@ -80,7 +73,6 @@ func TestValidateIntelRdt(t *testing.T) {
8073
{
8174
name: "mba not supported",
8275
rdtEnabled: true,
83-
mbaEnabled: false,
8476
config: &configs.IntelRdt{
8577
MemBwSchema: "0=100",
8678
},
@@ -96,7 +88,6 @@ func TestValidateIntelRdt(t *testing.T) {
9688
L3CacheSchema: "0=ff",
9789
MemBwSchema: "0=100",
9890
},
99-
isErr: false,
10091
},
10192
}
10293
for _, tc := range testCases {

libcontainer/container_linux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ type State struct {
7373

7474
// Intel RDT "resource control" filesystem path.
7575
IntelRdtPath string `json:"intel_rdt_path,omitempty"`
76+
77+
// Path of the container specific monitoring group in resctrl filesystem.
78+
// Empty if the container does not have aindividual dedicated monitoring
79+
// group.
80+
IntelRdtMonPath string `json:"intel_rdt_mon_path,omitempty"`
7681
}
7782

7883
// ID returns the container's unique ID
@@ -938,8 +943,10 @@ func (c *Container) currentState() *State {
938943
}
939944

940945
intelRdtPath := ""
946+
intelRdtMonPath := ""
941947
if c.intelRdtManager != nil {
942948
intelRdtPath = c.intelRdtManager.GetPath()
949+
intelRdtMonPath = c.intelRdtManager.GetMonPath()
943950
}
944951
state := &State{
945952
BaseState: BaseState{
@@ -952,6 +959,7 @@ func (c *Container) currentState() *State {
952959
Rootless: c.config.RootlessEUID && c.config.RootlessCgroups,
953960
CgroupPaths: c.cgroupManager.GetPaths(),
954961
IntelRdtPath: intelRdtPath,
962+
IntelRdtMonPath: intelRdtMonPath,
955963
NamespacePaths: make(map[configs.NamespaceType]string),
956964
ExternalDescriptors: externalDescriptors,
957965
}

libcontainer/intelrdt/intelrdt.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,16 @@ func (m *Manager) Apply(pid int) (err error) {
478478
return newLastCmdError(err)
479479
}
480480

481+
// Create MON group
482+
if monPath := m.GetMonPath(); monPath != "" {
483+
if err := os.Mkdir(monPath, 0o755); err != nil && !os.IsExist(err) {
484+
return newLastCmdError(err)
485+
}
486+
if err := WriteIntelRdtTasks(monPath, pid); err != nil {
487+
return newLastCmdError(err)
488+
}
489+
}
490+
481491
m.path = path
482492
return nil
483493
}
@@ -487,13 +497,21 @@ func (m *Manager) Destroy() error {
487497
// Don't remove resctrl group if closid has been explicitly specified. The
488498
// group is likely externally managed, i.e. by some other entity than us.
489499
// There are probably other containers/tasks sharing the same group.
490-
if m.config.IntelRdt != nil && m.config.IntelRdt.ClosID == "" {
491-
m.mu.Lock()
492-
defer m.mu.Unlock()
493-
if err := os.Remove(m.GetPath()); err != nil && !os.IsNotExist(err) {
494-
return err
500+
if m.config.IntelRdt != nil {
501+
if m.config.IntelRdt.ClosID == "" {
502+
m.mu.Lock()
503+
defer m.mu.Unlock()
504+
if err := os.Remove(m.GetPath()); err != nil && !os.IsNotExist(err) {
505+
return err
506+
}
507+
m.path = ""
508+
} else if monPath := m.GetMonPath(); monPath != "" {
509+
// If ClosID is not specified the possible monintoring group was
510+
// removed with the CLOS above.
511+
if err := os.Remove(monPath); err != nil && !os.IsNotExist(err) {
512+
return err
513+
}
495514
}
496-
m.path = ""
497515
}
498516
return nil
499517
}
@@ -504,6 +522,21 @@ func (m *Manager) GetPath() string {
504522
return m.path
505523
}
506524

525+
// GetMonPath returns path of the monitoring group of the container. Returns an
526+
// empty string if the container does not have a individual dedicated
527+
// monitoring group.
528+
func (m *Manager) GetMonPath() string {
529+
if !m.config.IntelRdt.EnableMonitoring {
530+
return ""
531+
}
532+
closPath := m.GetPath()
533+
if closPath == "" {
534+
return ""
535+
}
536+
537+
return filepath.Join(closPath, "mon_groups", m.id)
538+
}
539+
507540
// GetStats returns statistics for Intel RDT.
508541
func (m *Manager) GetStats() (*Stats, error) {
509542
// If intelRdt is not specified in config
@@ -581,7 +614,16 @@ func (m *Manager) GetStats() (*Stats, error) {
581614
}
582615

583616
if IsMBMEnabled() || IsCMTEnabled() {
584-
err = getMonitoringStats(containerPath, stats)
617+
monPath := m.GetMonPath()
618+
if monPath == "" {
619+
// NOTE: If per-container monitoring is not enabled, the monitoring
620+
// data we get here might have little to do with this container as
621+
// there might be anything from this single container to the half
622+
// of the system assigned in the group. Should consider not
623+
// exposing stats in this case(?)
624+
monPath = containerPath
625+
}
626+
err = getMonitoringStats(monPath, stats)
585627
if err != nil {
586628
return nil, err
587629
}

0 commit comments

Comments
 (0)