Skip to content

Commit 5c09aa9

Browse files
authored
Merge pull request #3978 from kolyshkin/1.1-rtd-fix
[1.1] fix intelrdt
2 parents 9c15e56 + f44190e commit 5c09aa9

File tree

9 files changed

+106
-470
lines changed

9 files changed

+106
-470
lines changed

libcontainer/container_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type linuxContainer struct {
4040
root string
4141
config *configs.Config
4242
cgroupManager cgroups.Manager
43-
intelRdtManager intelrdt.Manager
43+
intelRdtManager *intelrdt.Manager
4444
initPath string
4545
initArgs []string
4646
initProcess parentProcess

libcontainer/container_linux_test.go

Lines changed: 4 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@ import (
77

88
"github.com/opencontainers/runc/libcontainer/cgroups"
99
"github.com/opencontainers/runc/libcontainer/configs"
10-
"github.com/opencontainers/runc/libcontainer/intelrdt"
1110
"github.com/opencontainers/runc/libcontainer/system"
1211
)
1312

1413
type mockCgroupManager struct {
1514
pids []int
1615
allPids []int
17-
stats *cgroups.Stats
1816
paths map[string]string
1917
}
2018

21-
type mockIntelRdtManager struct {
22-
stats *intelrdt.Stats
23-
path string
24-
}
25-
2619
func (m *mockCgroupManager) GetPids() ([]int, error) {
2720
return m.pids, nil
2821
}
@@ -32,7 +25,7 @@ func (m *mockCgroupManager) GetAllPids() ([]int, error) {
3225
}
3326

3427
func (m *mockCgroupManager) GetStats() (*cgroups.Stats, error) {
35-
return m.stats, nil
28+
return nil, nil
3629
}
3730

3831
func (m *mockCgroupManager) Apply(pid int) error {
@@ -76,30 +69,6 @@ func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) {
7669
return configs.Thawed, nil
7770
}
7871

79-
func (m *mockIntelRdtManager) Apply(pid int) error {
80-
return nil
81-
}
82-
83-
func (m *mockIntelRdtManager) GetStats() (*intelrdt.Stats, error) {
84-
return m.stats, nil
85-
}
86-
87-
func (m *mockIntelRdtManager) Destroy() error {
88-
return nil
89-
}
90-
91-
func (m *mockIntelRdtManager) GetPath() string {
92-
return m.path
93-
}
94-
95-
func (m *mockIntelRdtManager) Set(container *configs.Config) error {
96-
return nil
97-
}
98-
99-
func (m *mockIntelRdtManager) GetCgroups() (*configs.Cgroup, error) {
100-
return nil, nil
101-
}
102-
10372
type mockProcess struct {
10473
_pid int
10574
started uint64
@@ -173,61 +142,11 @@ func TestGetContainerPids(t *testing.T) {
173142
}
174143
}
175144

176-
func TestGetContainerStats(t *testing.T) {
177-
container := &linuxContainer{
178-
id: "myid",
179-
config: &configs.Config{},
180-
cgroupManager: &mockCgroupManager{
181-
pids: []int{1, 2, 3},
182-
stats: &cgroups.Stats{
183-
MemoryStats: cgroups.MemoryStats{
184-
Usage: cgroups.MemoryData{
185-
Usage: 1024,
186-
},
187-
},
188-
},
189-
},
190-
intelRdtManager: &mockIntelRdtManager{
191-
stats: &intelrdt.Stats{
192-
L3CacheSchema: "L3:0=f;1=f0",
193-
MemBwSchema: "MB:0=20;1=70",
194-
},
195-
},
196-
}
197-
stats, err := container.Stats()
198-
if err != nil {
199-
t.Fatal(err)
200-
}
201-
if stats.CgroupStats == nil {
202-
t.Fatal("cgroup stats are nil")
203-
}
204-
if stats.CgroupStats.MemoryStats.Usage.Usage != 1024 {
205-
t.Fatalf("expected memory usage 1024 but received %d", stats.CgroupStats.MemoryStats.Usage.Usage)
206-
}
207-
if intelrdt.IsCATEnabled() {
208-
if stats.IntelRdtStats == nil {
209-
t.Fatal("intel rdt stats are nil")
210-
}
211-
if stats.IntelRdtStats.L3CacheSchema != "L3:0=f;1=f0" {
212-
t.Fatalf("expected L3CacheSchema L3:0=f;1=f0 but received %s", stats.IntelRdtStats.L3CacheSchema)
213-
}
214-
}
215-
if intelrdt.IsMBAEnabled() {
216-
if stats.IntelRdtStats == nil {
217-
t.Fatal("intel rdt stats are nil")
218-
}
219-
if stats.IntelRdtStats.MemBwSchema != "MB:0=20;1=70" {
220-
t.Fatalf("expected MemBwSchema MB:0=20;1=70 but received %s", stats.IntelRdtStats.MemBwSchema)
221-
}
222-
}
223-
}
224-
225145
func TestGetContainerState(t *testing.T) {
226146
var (
227-
pid = os.Getpid()
228-
expectedMemoryPath = "/sys/fs/cgroup/memory/myid"
229-
expectedNetworkPath = fmt.Sprintf("/proc/%d/ns/net", pid)
230-
expectedIntelRdtPath = "/sys/fs/resctrl/myid"
147+
pid = os.Getpid()
148+
expectedMemoryPath = "/sys/fs/cgroup/memory/myid"
149+
expectedNetworkPath = fmt.Sprintf("/proc/%d/ns/net", pid)
231150
)
232151
container := &linuxContainer{
233152
id: "myid",
@@ -248,24 +167,10 @@ func TestGetContainerState(t *testing.T) {
248167
},
249168
cgroupManager: &mockCgroupManager{
250169
pids: []int{1, 2, 3},
251-
stats: &cgroups.Stats{
252-
MemoryStats: cgroups.MemoryStats{
253-
Usage: cgroups.MemoryData{
254-
Usage: 1024,
255-
},
256-
},
257-
},
258170
paths: map[string]string{
259171
"memory": expectedMemoryPath,
260172
},
261173
},
262-
intelRdtManager: &mockIntelRdtManager{
263-
stats: &intelrdt.Stats{
264-
L3CacheSchema: "L3:0=f0;1=f",
265-
MemBwSchema: "MB:0=70;1=20",
266-
},
267-
path: expectedIntelRdtPath,
268-
},
269174
}
270175
container.state = &createdState{c: container}
271176
state, err := container.State()
@@ -285,15 +190,6 @@ func TestGetContainerState(t *testing.T) {
285190
if memPath := paths["memory"]; memPath != expectedMemoryPath {
286191
t.Fatalf("expected memory path %q but received %q", expectedMemoryPath, memPath)
287192
}
288-
if intelrdt.IsCATEnabled() || intelrdt.IsMBAEnabled() {
289-
intelRdtPath := state.IntelRdtPath
290-
if intelRdtPath == "" {
291-
t.Fatal("intel rdt path should not be empty")
292-
}
293-
if intelRdtPath != expectedIntelRdtPath {
294-
t.Fatalf("expected intel rdt path %q but received %q", expectedIntelRdtPath, intelRdtPath)
295-
}
296-
}
297193
for _, ns := range container.config.Namespaces {
298194
path := state.NamespacePaths[ns.Type]
299195
if path == "" {

libcontainer/factory_linux.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ func InitArgs(args ...string) func(*LinuxFactory) error {
4848
}
4949
}
5050

51-
// IntelRdtfs is an options func to configure a LinuxFactory to return
52-
// containers that use the Intel RDT "resource control" filesystem to
53-
// create and manage Intel RDT resources (e.g., L3 cache, memory bandwidth).
54-
func IntelRdtFs(l *LinuxFactory) error {
55-
if !intelrdt.IsCATEnabled() && !intelrdt.IsMBAEnabled() {
56-
l.NewIntelRdtManager = nil
57-
} else {
58-
l.NewIntelRdtManager = func(config *configs.Config, id string, path string) intelrdt.Manager {
59-
return intelrdt.NewManager(config, id, path)
60-
}
61-
}
62-
return nil
63-
}
64-
6551
// TmpfsRoot is an option func to mount LinuxFactory.Root to tmpfs.
6652
func TmpfsRoot(l *LinuxFactory) error {
6753
mounted, err := mountinfo.Mounted(l.Root)
@@ -136,9 +122,6 @@ type LinuxFactory struct {
136122

137123
// Validator provides validation to container configurations.
138124
Validator validate.Validator
139-
140-
// NewIntelRdtManager returns an initialized Intel RDT manager for a single container.
141-
NewIntelRdtManager func(config *configs.Config, id string, path string) intelrdt.Manager
142125
}
143126

144127
func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, error) {
@@ -208,18 +191,16 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
208191
return nil, err
209192
}
210193
c := &linuxContainer{
211-
id: id,
212-
root: containerRoot,
213-
config: config,
214-
initPath: l.InitPath,
215-
initArgs: l.InitArgs,
216-
criuPath: l.CriuPath,
217-
newuidmapPath: l.NewuidmapPath,
218-
newgidmapPath: l.NewgidmapPath,
219-
cgroupManager: cm,
220-
}
221-
if l.NewIntelRdtManager != nil {
222-
c.intelRdtManager = l.NewIntelRdtManager(config, id, "")
194+
id: id,
195+
root: containerRoot,
196+
config: config,
197+
initPath: l.InitPath,
198+
initArgs: l.InitArgs,
199+
criuPath: l.CriuPath,
200+
newuidmapPath: l.NewuidmapPath,
201+
newgidmapPath: l.NewgidmapPath,
202+
cgroupManager: cm,
203+
intelRdtManager: intelrdt.NewManager(config, id, ""),
223204
}
224205
c.state = &stoppedState{c: c}
225206
return c, nil
@@ -261,12 +242,10 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
261242
newuidmapPath: l.NewuidmapPath,
262243
newgidmapPath: l.NewgidmapPath,
263244
cgroupManager: cm,
245+
intelRdtManager: intelrdt.NewManager(&state.Config, id, state.IntelRdtPath),
264246
root: containerRoot,
265247
created: state.Created,
266248
}
267-
if l.NewIntelRdtManager != nil {
268-
c.intelRdtManager = l.NewIntelRdtManager(&state.Config, id, state.IntelRdtPath)
269-
}
270249
c.state = &loadedState{c: c}
271250
if err := c.refreshState(); err != nil {
272251
return nil, err

libcontainer/factory_linux_test.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,6 @@ func TestFactoryNew(t *testing.T) {
3737
}
3838
}
3939

40-
func TestFactoryNewIntelRdt(t *testing.T) {
41-
root := t.TempDir()
42-
factory, err := New(root, IntelRdtFs)
43-
if err != nil {
44-
t.Fatal(err)
45-
}
46-
if factory == nil {
47-
t.Fatal("factory should not be nil")
48-
}
49-
lfactory, ok := factory.(*LinuxFactory)
50-
if !ok {
51-
t.Fatal("expected linux factory returned on linux based systems")
52-
}
53-
if lfactory.Root != root {
54-
t.Fatalf("expected factory root to be %q but received %q", root, lfactory.Root)
55-
}
56-
57-
if factory.Type() != "libcontainer" {
58-
t.Fatalf("unexpected factory type: %q, expected %q", factory.Type(), "libcontainer")
59-
}
60-
}
61-
6240
func TestFactoryNewTmpfs(t *testing.T) {
6341
root := t.TempDir()
6442
factory, err := New(root, TmpfsRoot)
@@ -157,7 +135,7 @@ func TestFactoryLoadContainer(t *testing.T) {
157135
if err := marshal(filepath.Join(root, id, stateFilename), expectedState); err != nil {
158136
t.Fatal(err)
159137
}
160-
factory, err := New(root, IntelRdtFs)
138+
factory, err := New(root)
161139
if err != nil {
162140
t.Fatal(err)
163141
}

0 commit comments

Comments
 (0)