Skip to content

Commit

Permalink
feature: support IntelRdtL3Cbm in pouch container
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Sun <allensun.shl@alibaba-inc.com>
  • Loading branch information
allencloud committed Feb 22, 2018
1 parent 735e3f7 commit fc3f480
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type container struct {
blkioDeviceWriteBps ThrottleBpsDevice
blkioDeviceReadIOps ThrottleIOpsDevice
blkioDeviceWriteIOps ThrottleIOpsDevice
IntelRdtL3Cbm string
}

func (c *container) config() (*types.ContainerCreateConfig, error) {
Expand All @@ -70,6 +71,11 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
return nil, err
}

intelRdtL3Cbm, err := parseIntelRdt(c.IntelRdtL3Cbm)
if err != nil {
return nil, err
}

deviceMappings, err := parseDeviceMappings(c.devices)
if err != nil {
return nil, err
Expand Down Expand Up @@ -143,6 +149,7 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
BlkioDeviceReadIOps: c.blkioDeviceReadIOps.value(),
BlkioDeviceWriteBps: c.blkioDeviceWriteBps.value(),
BlkioDeviceWriteIOps: c.blkioDeviceWriteIOps.value(),
IntelRdtL3Cbm: intelRdtL3Cbm,
},
EnableLxcfs: c.enableLxcfs,
Privileged: c.privileged,
Expand Down Expand Up @@ -260,6 +267,11 @@ func validateMemorySwappiness(memorySwappiness int64) error {
return nil
}

func parseIntelRdt(intelRdtL3Cbm string) (string, error) {
// FIXME: add Intel RDT L3 Cbm validation
return intelRdtL3Cbm, nil
}

func parseRestartPolicy(restartPolicy string) (*types.RestartPolicy, error) {
policy := &types.RestartPolicy{}

Expand Down
20 changes: 20 additions & 0 deletions cli/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,23 @@ func Test_parseNetwork(t *testing.T) {
assert.Equal(t, testCase.expect.network.mode, mode)
}
}

func Test_parseIntelRdt(t *testing.T) {
type args struct {
intelRdtL3Cbm string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := parseIntelRdt(tt.args.intelRdtL3Cbm); (err != nil) != tt.wantErr {
t.Errorf("parseIntelRdt() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
1 change: 1 addition & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (cc *CreateCommand) addFlags() {
flagSet.Var(&cc.blkioDeviceReadIOps, "device-read-iops", "Limit read rate (IO per second) from a device")
flagSet.Var(&cc.blkioDeviceWriteBps, "device-write-bps", "Limit write rate (bytes per second) from a device")
flagSet.Var(&cc.blkioDeviceWriteIOps, "device-write-iops", "Limit write rate (IO per second) from a device")
flagSet.StringVar(&cc.IntelRdtL3Cbm, "intel-rdt-l3-cbm", "", "Limit container resource for Intel RDT/CAT which introduced in Linux 4.10 kernel")
}

// runCreate is the entry of create command.
Expand Down
1 change: 1 addition & 0 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (rc *RunCommand) addFlags() {
flagSet.Var(&rc.blkioDeviceReadIOps, "device-read-iops", "Limit read rate (IO per second) from a device")
flagSet.Var(&rc.blkioDeviceWriteBps, "device-write-bps", "Limit write rate (bytes per second) from a device")
flagSet.Var(&rc.blkioDeviceWriteIOps, "device-write-iops", "Limit write rate (IO per second) from a device")
flagSet.StringVar(&rc.IntelRdtL3Cbm, "intel-rdt-l3-cbm", "", "Limit container resource for Intel RDT/CAT which introduced in Linux 4.10 kernel")
}

// runRun is the entry of run command.
Expand Down
3 changes: 3 additions & 0 deletions daemon/mgr/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ var setupFunc = []SetupFunc{

// blkio spec
setupBlkio,

// IntelRdtL3Cbm
setupIntelRdt,
}

// Register is used to registe spec setup function.
Expand Down
13 changes: 13 additions & 0 deletions daemon/mgr/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,16 @@ func setupCapabilities(ctx context.Context, meta *ContainerMeta, spec *SpecWrapp

return nil
}

func setupIntelRdt(ctx context.Context, meta *ContainerMeta, spec *SpecWrapper) error {
s := spec.s
if s.Linux.IntelRdt == nil {
s.Linux.IntelRdt = &specs.LinuxIntelRdt{}
}

s.Linux.IntelRdt = &specs.LinuxIntelRdt{
L3CacheSchema: meta.HostConfig.IntelRdtL3Cbm,
}

return nil
}
17 changes: 17 additions & 0 deletions test/cli_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,20 @@ func (suite *PouchCreateSuite) TestCreateWithUser(c *check.C) {
}
c.Assert(result.Config.User, check.Equals, user)
}

// TestCreateWithIntelRdt tests creating container with Intel Rdt.
func (suite *PouchCreateSuite) TestCreateWithIntelRdt(c *check.C) {
name := "TestCreateWithIntelRdt"
intelRdt := "L3:<cache_id0>=<cbm0>"

res := command.PouchRun("create", "--name", name, "--intel-rdt-l3-cbm", intelRdt, busyboxImage)
res.Assert(c, icmd.Success)

output := command.PouchRun("inspect", name).Stdout()

result := &types.ContainerJSON{}
if err := json.Unmarshal([]byte(output), result); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(result.HostConfig.IntelRdtL3Cbm, check.Equals, intelRdt)
}

0 comments on commit fc3f480

Please sign in to comment.