@@ -146,34 +146,27 @@ import (
146146 * }
147147 */
148148
149- type Manager interface {
150- // Applies Intel RDT configuration to the process with the specified pid
151- Apply (pid int ) error
152-
153- // Returns statistics for Intel RDT
154- GetStats () (* Stats , error )
155-
156- // Destroys the Intel RDT container-specific 'container_id' group
157- Destroy () error
158-
159- // Returns Intel RDT path to save in a state file and to be able to
160- // restore the object later
161- GetPath () string
162-
163- // Set Intel RDT "resource control" filesystem as configured.
164- Set (container * configs.Config ) error
165- }
166-
167- // This implements interface Manager
168- type intelRdtManager struct {
149+ // NewManager returns a new instance of Manager, or nil, if the Intel RDT
150+ // functionality is not available from hardware or not enabled in the kernel.
151+ type Manager struct {
169152 mu sync.Mutex
170153 config * configs.Config
171154 id string
172155 path string
173156}
174157
175- func NewManager (config * configs.Config , id string , path string ) Manager {
176- return & intelRdtManager {
158+ func NewManager (config * configs.Config , id string , path string ) * Manager {
159+ if _ , err := Root (); err != nil {
160+ // Intel RDT is not available.
161+ return nil
162+ }
163+ return newManager (config , id , path )
164+ }
165+
166+ // newManager is the same as NewManager, except it does not check if the feature
167+ // is actually available. Used by unit tests that mock intelrdt paths.
168+ func newManager (config * configs.Config , id string , path string ) * Manager {
169+ return & Manager {
177170 config : config ,
178171 id : id ,
179172 path : path ,
@@ -507,7 +500,7 @@ func IsMBAScEnabled() bool {
507500}
508501
509502// Get the path of the clos group in "resource control" filesystem that the container belongs to
510- func (m * intelRdtManager ) getIntelRdtPath () (string , error ) {
503+ func (m * Manager ) getIntelRdtPath () (string , error ) {
511504 rootPath , err := Root ()
512505 if err != nil {
513506 return "" , err
@@ -522,7 +515,7 @@ func (m *intelRdtManager) getIntelRdtPath() (string, error) {
522515}
523516
524517// Applies Intel RDT configuration to the process with the specified pid
525- func (m * intelRdtManager ) Apply (pid int ) (err error ) {
518+ func (m * Manager ) Apply (pid int ) (err error ) {
526519 // If intelRdt is not specified in config, we do nothing
527520 if m .config .IntelRdt == nil {
528521 return nil
@@ -557,7 +550,7 @@ func (m *intelRdtManager) Apply(pid int) (err error) {
557550}
558551
559552// Destroys the Intel RDT container-specific 'container_id' group
560- func (m * intelRdtManager ) Destroy () error {
553+ func (m * Manager ) Destroy () error {
561554 // Don't remove resctrl group if closid has been explicitly specified. The
562555 // group is likely externally managed, i.e. by some other entity than us.
563556 // There are probably other containers/tasks sharing the same group.
@@ -574,15 +567,15 @@ func (m *intelRdtManager) Destroy() error {
574567
575568// Returns Intel RDT path to save in a state file and to be able to
576569// restore the object later
577- func (m * intelRdtManager ) GetPath () string {
570+ func (m * Manager ) GetPath () string {
578571 if m .path == "" {
579572 m .path , _ = m .getIntelRdtPath ()
580573 }
581574 return m .path
582575}
583576
584577// Returns statistics for Intel RDT
585- func (m * intelRdtManager ) GetStats () (* Stats , error ) {
578+ func (m * Manager ) GetStats () (* Stats , error ) {
586579 // If intelRdt is not specified in config
587580 if m .config .IntelRdt == nil {
588581 return nil , nil
@@ -668,7 +661,7 @@ func (m *intelRdtManager) GetStats() (*Stats, error) {
668661}
669662
670663// Set Intel RDT "resource control" filesystem as configured.
671- func (m * intelRdtManager ) Set (container * configs.Config ) error {
664+ func (m * Manager ) Set (container * configs.Config ) error {
672665 // About L3 cache schema:
673666 // It has allocation bitmasks/values for L3 cache on each socket,
674667 // which contains L3 cache id and capacity bitmask (CBM).
0 commit comments