@@ -478,6 +478,16 @@ func (m *Manager) Apply(pid int) (err error) {
478
478
return newLastCmdError (err )
479
479
}
480
480
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
+
481
491
m .path = path
482
492
return nil
483
493
}
@@ -487,13 +497,21 @@ func (m *Manager) Destroy() error {
487
497
// Don't remove resctrl group if closid has been explicitly specified. The
488
498
// group is likely externally managed, i.e. by some other entity than us.
489
499
// 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
+ }
495
514
}
496
- m .path = ""
497
515
}
498
516
return nil
499
517
}
@@ -504,6 +522,21 @@ func (m *Manager) GetPath() string {
504
522
return m .path
505
523
}
506
524
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
+
507
540
// GetStats returns statistics for Intel RDT.
508
541
func (m * Manager ) GetStats () (* Stats , error ) {
509
542
// If intelRdt is not specified in config
@@ -581,7 +614,16 @@ func (m *Manager) GetStats() (*Stats, error) {
581
614
}
582
615
583
616
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 )
585
627
if err != nil {
586
628
return nil , err
587
629
}
0 commit comments