Skip to content

Commit 75201f3

Browse files
authored
Merge pull request #2653 from xiaochenshen/rdt-IntelRdtManager-refactoring
libcontainer/intelrdt: IntelRdtManager refactoring
2 parents 07e35a7 + 933c4d3 commit 75201f3

File tree

4 files changed

+31
-40
lines changed

4 files changed

+31
-40
lines changed

libcontainer/factory_linux.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,7 @@ func RootlessCgroupfs(l *LinuxFactory) error {
149149
// create and manage Intel RDT resources (e.g., L3 cache, memory bandwidth).
150150
func IntelRdtFs(l *LinuxFactory) error {
151151
l.NewIntelRdtManager = func(config *configs.Config, id string, path string) intelrdt.Manager {
152-
return &intelrdt.IntelRdtManager{
153-
Config: config,
154-
Id: id,
155-
Path: path,
156-
}
152+
return intelrdt.NewManager(config, id, path)
157153
}
158154
return nil
159155
}

libcontainer/intelrdt/intelrdt.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ type Manager interface {
165165
}
166166

167167
// This implements interface Manager
168-
type IntelRdtManager struct {
168+
type intelRdtManager struct {
169169
mu sync.Mutex
170-
Config *configs.Config
171-
Id string
172-
Path string
170+
config *configs.Config
171+
id string
172+
path string
173+
}
174+
175+
func NewManager(config *configs.Config, id string, path string) Manager {
176+
return &intelRdtManager{
177+
config: config,
178+
id: id,
179+
path: path,
180+
}
173181
}
174182

175183
const (
@@ -534,51 +542,51 @@ func GetIntelRdtPath(id string) (string, error) {
534542
}
535543

536544
// Applies Intel RDT configuration to the process with the specified pid
537-
func (m *IntelRdtManager) Apply(pid int) (err error) {
545+
func (m *intelRdtManager) Apply(pid int) (err error) {
538546
// If intelRdt is not specified in config, we do nothing
539-
if m.Config.IntelRdt == nil {
547+
if m.config.IntelRdt == nil {
540548
return nil
541549
}
542-
d, err := getIntelRdtData(m.Config, pid)
550+
d, err := getIntelRdtData(m.config, pid)
543551
if err != nil && !IsNotFound(err) {
544552
return err
545553
}
546554

547555
m.mu.Lock()
548556
defer m.mu.Unlock()
549-
path, err := d.join(m.Id)
557+
path, err := d.join(m.id)
550558
if err != nil {
551559
return err
552560
}
553561

554-
m.Path = path
562+
m.path = path
555563
return nil
556564
}
557565

558566
// Destroys the Intel RDT 'container_id' group
559-
func (m *IntelRdtManager) Destroy() error {
567+
func (m *intelRdtManager) Destroy() error {
560568
m.mu.Lock()
561569
defer m.mu.Unlock()
562570
if err := os.RemoveAll(m.GetPath()); err != nil {
563571
return err
564572
}
565-
m.Path = ""
573+
m.path = ""
566574
return nil
567575
}
568576

569577
// Returns Intel RDT path to save in a state file and to be able to
570578
// restore the object later
571-
func (m *IntelRdtManager) GetPath() string {
572-
if m.Path == "" {
573-
m.Path, _ = GetIntelRdtPath(m.Id)
579+
func (m *intelRdtManager) GetPath() string {
580+
if m.path == "" {
581+
m.path, _ = GetIntelRdtPath(m.id)
574582
}
575-
return m.Path
583+
return m.path
576584
}
577585

578586
// Returns statistics for Intel RDT
579-
func (m *IntelRdtManager) GetStats() (*Stats, error) {
587+
func (m *intelRdtManager) GetStats() (*Stats, error) {
580588
// If intelRdt is not specified in config
581-
if m.Config.IntelRdt == nil {
589+
if m.config.IntelRdt == nil {
582590
return nil, nil
583591
}
584592

@@ -660,7 +668,7 @@ func (m *IntelRdtManager) GetStats() (*Stats, error) {
660668
}
661669

662670
// Set Intel RDT "resource control" filesystem as configured.
663-
func (m *IntelRdtManager) Set(container *configs.Config) error {
671+
func (m *intelRdtManager) Set(container *configs.Config) error {
664672
// About L3 cache schema:
665673
// It has allocation bitmasks/values for L3 cache on each socket,
666674
// which contains L3 cache id and capacity bitmask (CBM).

libcontainer/intelrdt/intelrdt_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ func TestIntelRdtSetL3CacheSchema(t *testing.T) {
2626
})
2727

2828
helper.IntelRdtData.config.IntelRdt.L3CacheSchema = l3CacheSchemeAfter
29-
intelrdt := &IntelRdtManager{
30-
Config: helper.IntelRdtData.config,
31-
Path: helper.IntelRdtPath,
32-
}
29+
intelrdt := NewManager(helper.IntelRdtData.config, "", helper.IntelRdtPath)
3330
if err := intelrdt.Set(helper.IntelRdtData.config); err != nil {
3431
t.Fatal(err)
3532
}
@@ -64,10 +61,7 @@ func TestIntelRdtSetMemBwSchema(t *testing.T) {
6461
})
6562

6663
helper.IntelRdtData.config.IntelRdt.MemBwSchema = memBwSchemeAfter
67-
intelrdt := &IntelRdtManager{
68-
Config: helper.IntelRdtData.config,
69-
Path: helper.IntelRdtPath,
70-
}
64+
intelrdt := NewManager(helper.IntelRdtData.config, "", helper.IntelRdtPath)
7165
if err := intelrdt.Set(helper.IntelRdtData.config); err != nil {
7266
t.Fatal(err)
7367
}
@@ -102,10 +96,7 @@ func TestIntelRdtSetMemBwScSchema(t *testing.T) {
10296
})
10397

10498
helper.IntelRdtData.config.IntelRdt.MemBwSchema = memBwScSchemeAfter
105-
intelrdt := &IntelRdtManager{
106-
Config: helper.IntelRdtData.config,
107-
Path: helper.IntelRdtPath,
108-
}
99+
intelrdt := NewManager(helper.IntelRdtData.config, "", helper.IntelRdtPath)
109100
if err := intelrdt.Set(helper.IntelRdtData.config); err != nil {
110101
t.Fatal(err)
111102
}

update.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,7 @@ other options are ignored.
317317
return err
318318
}
319319
config.IntelRdt = &configs.IntelRdt{}
320-
intelRdtManager := intelrdt.IntelRdtManager{
321-
Config: &config,
322-
Id: container.ID(),
323-
Path: state.IntelRdtPath,
324-
}
320+
intelRdtManager := intelrdt.NewManager(&config, container.ID(), state.IntelRdtPath)
325321
if err := intelRdtManager.Apply(state.InitProcessPid); err != nil {
326322
return err
327323
}

0 commit comments

Comments
 (0)