@@ -72,7 +72,7 @@ import (
7272 * |-- ...
7373 * |-- schemata
7474 * |-- tasks
75- * |-- <container_id >
75+ * |-- <clos >
7676 * |-- ...
7777 * |-- schemata
7878 * |-- tasks
@@ -155,7 +155,7 @@ type Manager interface {
155155 // Returns statistics for Intel RDT
156156 GetStats () (* Stats , error )
157157
158- // Destroys the Intel RDT 'container_id' group
158+ // Destroys the Intel RDT container-specific 'container_id' group
159159 Destroy () error
160160
161161 // Returns Intel RDT path to save in a state file and to be able to
@@ -205,9 +205,7 @@ var (
205205)
206206
207207type intelRdtData struct {
208- root string
209208 config * configs.Config
210- pid int
211209}
212210
213211// Check if Intel RDT sub-features are enabled in featuresInit()
@@ -405,18 +403,6 @@ func writeFile(dir, file, data string) error {
405403 return nil
406404}
407405
408- func getIntelRdtData (c * configs.Config , pid int ) (* intelRdtData , error ) {
409- rootPath , err := getIntelRdtRoot ()
410- if err != nil {
411- return nil , err
412- }
413- return & intelRdtData {
414- root : rootPath ,
415- config : c ,
416- pid : pid ,
417- }, nil
418- }
419-
420406// Get the read-only L3 cache information
421407func getL3CacheInfo () (* L3CacheInfo , error ) {
422408 l3CacheInfo := & L3CacheInfo {}
@@ -531,15 +517,19 @@ func IsMBAScEnabled() bool {
531517 return mbaScEnabled
532518}
533519
534- // Get the 'container_id' path in Intel RDT "resource control" filesystem
535- func GetIntelRdtPath ( id string ) (string , error ) {
520+ // Get the path of the clos group in "resource control" filesystem that the container belongs to
521+ func ( m * intelRdtManager ) getIntelRdtPath ( ) (string , error ) {
536522 rootPath , err := getIntelRdtRoot ()
537523 if err != nil {
538524 return "" , err
539525 }
540526
541- path := filepath .Join (rootPath , id )
542- return path , nil
527+ clos := m .id
528+ if m .config .IntelRdt != nil && m .config .IntelRdt .ClosID != "" {
529+ clos = m .config .IntelRdt .ClosID
530+ }
531+
532+ return filepath .Join (rootPath , clos ), nil
543533}
544534
545535// Applies Intel RDT configuration to the process with the specified pid
@@ -548,38 +538,56 @@ func (m *intelRdtManager) Apply(pid int) (err error) {
548538 if m .config .IntelRdt == nil {
549539 return nil
550540 }
551- d , err := getIntelRdtData (m .config , pid )
541+
542+ path , err := m .getIntelRdtPath ()
552543 if err != nil {
553544 return err
554545 }
555546
556547 m .mu .Lock ()
557548 defer m .mu .Unlock ()
558- path , err := d .join (m .id )
559- if err != nil {
560- return err
549+
550+ if m .config .IntelRdt .ClosID != "" && m .config .IntelRdt .L3CacheSchema == "" && m .config .IntelRdt .MemBwSchema == "" {
551+ // Check that the CLOS exists, i.e. it has been pre-configured to
552+ // conform with the runtime spec
553+ if _ , err := os .Stat (path ); err != nil {
554+ return fmt .Errorf ("clos dir not accessible (must be pre-created when l3CacheSchema and memBwSchema are empty): %w" , err )
555+ }
556+ }
557+
558+ if err := os .MkdirAll (path , 0o755 ); err != nil {
559+ return newLastCmdError (err )
560+ }
561+
562+ if err := WriteIntelRdtTasks (path , pid ); err != nil {
563+ return newLastCmdError (err )
561564 }
562565
563566 m .path = path
564567 return nil
565568}
566569
567- // Destroys the Intel RDT 'container_id' group
570+ // Destroys the Intel RDT container-specific 'container_id' group
568571func (m * intelRdtManager ) Destroy () error {
569- m .mu .Lock ()
570- defer m .mu .Unlock ()
571- if err := os .RemoveAll (m .GetPath ()); err != nil {
572- return err
572+ // Don't remove resctrl group if closid has been explicitly specified. The
573+ // group is likely externally managed, i.e. by some other entity than us.
574+ // There are probably other containers/tasks sharing the same group.
575+ if m .config .IntelRdt == nil || m .config .IntelRdt .ClosID == "" {
576+ m .mu .Lock ()
577+ defer m .mu .Unlock ()
578+ if err := os .RemoveAll (m .GetPath ()); err != nil {
579+ return err
580+ }
581+ m .path = ""
573582 }
574- m .path = ""
575583 return nil
576584}
577585
578586// Returns Intel RDT path to save in a state file and to be able to
579587// restore the object later
580588func (m * intelRdtManager ) GetPath () string {
581589 if m .path == "" {
582- m .path , _ = GetIntelRdtPath ( m . id )
590+ m .path , _ = m . getIntelRdtPath ( )
583591 }
584592 return m .path
585593}
@@ -606,7 +614,7 @@ func (m *intelRdtManager) GetStats() (*Stats, error) {
606614 }
607615 schemaRootStrings := strings .Split (tmpRootStrings , "\n " )
608616
609- // The L3 cache and memory bandwidth schemata in 'container_id' group
617+ // The L3 cache and memory bandwidth schemata in container's clos group
610618 containerPath := m .GetPath ()
611619 tmpStrings , err := getIntelRdtParamString (containerPath , "schemata" )
612620 if err != nil {
@@ -629,7 +637,7 @@ func (m *intelRdtManager) GetStats() (*Stats, error) {
629637 }
630638 }
631639
632- // The L3 cache schema in 'container_id' group
640+ // The L3 cache schema in container's clos group
633641 for _ , schema := range schemaStrings {
634642 if strings .Contains (schema , "L3" ) {
635643 stats .L3CacheSchema = strings .TrimSpace (schema )
@@ -652,7 +660,7 @@ func (m *intelRdtManager) GetStats() (*Stats, error) {
652660 }
653661 }
654662
655- // The memory bandwidth schema in 'container_id' group
663+ // The memory bandwidth schema in container's clos group
656664 for _ , schema := range schemaStrings {
657665 if strings .Contains (schema , "MB" ) {
658666 stats .MemBwSchema = strings .TrimSpace (schema )
@@ -722,6 +730,12 @@ func (m *intelRdtManager) Set(container *configs.Config) error {
722730 l3CacheSchema := container .IntelRdt .L3CacheSchema
723731 memBwSchema := container .IntelRdt .MemBwSchema
724732
733+ // TODO: verify that l3CacheSchema and/or memBwSchema match the
734+ // existing schemata if ClosID has been specified. This is a more
735+ // involved than reading the file and doing plain string comparison as
736+ // the value written in does not necessarily match what gets read out
737+ // (leading zeros, cache id ordering etc).
738+
725739 // Write a single joint schema string to schemata file
726740 if l3CacheSchema != "" && memBwSchema != "" {
727741 if err := writeFile (path , "schemata" , l3CacheSchema + "\n " + memBwSchema ); err != nil {
@@ -747,18 +761,6 @@ func (m *intelRdtManager) Set(container *configs.Config) error {
747761 return nil
748762}
749763
750- func (raw * intelRdtData ) join (id string ) (string , error ) {
751- path := filepath .Join (raw .root , id )
752- if err := os .MkdirAll (path , 0o755 ); err != nil {
753- return "" , newLastCmdError (err )
754- }
755-
756- if err := WriteIntelRdtTasks (path , raw .pid ); err != nil {
757- return "" , err
758- }
759- return path , nil
760- }
761-
762764func newLastCmdError (err error ) error {
763765 status , err1 := getLastCmdStatus ()
764766 if err1 == nil {
0 commit comments