@@ -326,16 +326,6 @@ func getIntelRdtParamString(path, file string) (string, error) {
326326 return string (bytes .TrimSpace (contents )), nil
327327}
328328
329- func writeFile (dir , file , data string ) error {
330- if dir == "" {
331- return fmt .Errorf ("no such directory for %s" , file )
332- }
333- if err := os .WriteFile (filepath .Join (dir , file ), []byte (data + "\n " ), 0o600 ); err != nil {
334- return newLastCmdError (fmt .Errorf ("intelrdt: unable to write %v: %w" , data , err ))
335- }
336- return nil
337- }
338-
339329// Get the read-only L3 cache information
340330func getL3CacheInfo () (* L3CacheInfo , error ) {
341331 l3CacheInfo := & L3CacheInfo {}
@@ -462,11 +452,11 @@ func (m *Manager) Apply(pid int) (err error) {
462452 m .mu .Lock ()
463453 defer m .mu .Unlock ()
464454
465- if m .config .IntelRdt .ClosID != "" && m .config .IntelRdt .L3CacheSchema == "" && m .config .IntelRdt .MemBwSchema == "" {
455+ if m .config .IntelRdt .ClosID != "" && m .config .IntelRdt .L3CacheSchema == "" && m .config .IntelRdt .MemBwSchema == "" && len ( m . config . IntelRdt . Schemata ) == 0 {
466456 // Check that the CLOS exists, i.e. it has been pre-configured to
467457 // conform with the runtime spec
468458 if _ , err := os .Stat (path ); err != nil {
469- return fmt .Errorf ("clos dir not accessible (must be pre-created when l3CacheSchema and memBwSchema are empty): %w" , err )
459+ return fmt .Errorf ("clos dir not accessible (must be pre-created when schemata, l3CacheSchema and memBwSchema are empty): %w" , err )
470460 }
471461 }
472462
@@ -637,35 +627,24 @@ func (m *Manager) Set(container *configs.Config) error {
637627 // For example, on a two-socket machine, the schema line could be
638628 // "MB:0=5000;1=7000" which means 5000 MBps memory bandwidth limit on
639629 // socket 0 and 7000 MBps memory bandwidth limit on socket 1.
640- if container .IntelRdt != nil {
641- path := m .GetPath ()
642- l3CacheSchema := container .IntelRdt .L3CacheSchema
643- memBwSchema := container .IntelRdt .MemBwSchema
644-
630+ if r := container .IntelRdt ; r != nil {
645631 // TODO: verify that l3CacheSchema and/or memBwSchema match the
646632 // existing schemata if ClosID has been specified. This is a more
647633 // involved than reading the file and doing plain string comparison as
648634 // the value written in does not necessarily match what gets read out
649635 // (leading zeros, cache id ordering etc).
650-
651- // Write a single joint schema string to schemata file
652- if l3CacheSchema != "" && memBwSchema != "" {
653- if err := writeFile (path , "schemata" , l3CacheSchema + "\n " + memBwSchema ); err != nil {
654- return err
655- }
656- }
657-
658- // Write only L3 cache schema string to schemata file
659- if l3CacheSchema != "" && memBwSchema == "" {
660- if err := writeFile (path , "schemata" , l3CacheSchema ); err != nil {
661- return err
636+ var schemata strings.Builder
637+ for _ , s := range append ([]string {r .L3CacheSchema , r .MemBwSchema }, r .Schemata ... ) {
638+ if s != "" {
639+ schemata .WriteString (s )
640+ schemata .WriteString ("\n " )
662641 }
663642 }
664643
665- // Write only memory bandwidth schema string to schemata file
666- if l3CacheSchema == "" && memBwSchema != "" {
667- if err := writeFile (path , " schemata" , memBwSchema ); err != nil {
668- return err
644+ if schemata . Len () > 0 {
645+ path := filepath . Join ( m . GetPath (), "schemata" )
646+ if err := os . WriteFile (path , [] byte ( schemata . String ()), 0o600 ); err != nil {
647+ return newLastCmdError ( fmt . Errorf ( "intelrdt: unable to write %q: %w" , schemata . String (), err ))
669648 }
670649 }
671650 }
0 commit comments