Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ func convertLibcontainerStats(ls *libcontainer.Stats) *types.Stats {
if intelrdt.IsCMTEnabled() {
s.IntelRdt.CMTStats = is.CMTStats
}

s.IntelRdt.Schemata = is.Schemata
}

s.NetworkInterfaces = ls.Interfaces
Expand Down
3 changes: 2 additions & 1 deletion features.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ var featuresCommand = cli.Command{
Enabled: &t,
},
IntelRdt: &features.IntelRdt{
Enabled: &t,
Enabled: &t,
Schemata: &t,
},
MountExtensions: &features.MountExtensions{
IDMap: &features.IDMap{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/moby/sys/userns v0.1.0
github.com/mrunalp/fileutils v0.5.1
github.com/opencontainers/cgroups v0.0.4
github.com/opencontainers/runtime-spec v1.2.2-0.20250401095657-e935f995dd67
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0
github.com/opencontainers/selinux v1.12.0
github.com/seccomp/libseccomp-golang v0.11.1
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ github.com/mrunalp/fileutils v0.5.1 h1:F+S7ZlNKnrwHfSwdlgNSkKo67ReVf8o9fel6C3dkm
github.com/mrunalp/fileutils v0.5.1/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/opencontainers/cgroups v0.0.4 h1:XVj8P/IHVms/j+7eh8ggdkTLAxjz84ZzuFyGoE28DR4=
github.com/opencontainers/cgroups v0.0.4/go.mod h1:s8lktyhlGUqM7OSRL5P7eAW6Wb+kWPNvt4qvVfzA5vs=
github.com/opencontainers/runtime-spec v1.2.2-0.20250401095657-e935f995dd67 h1:Q+KewUGTMamIe6Q39xCD/T1NC1POmaTlWnhjikCrZHA=
github.com/opencontainers/runtime-spec v1.2.2-0.20250401095657-e935f995dd67/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0 h1:RLn0YfUWkiqPGtgUANvJrcjIkCHGRl3jcz/c557M28M=
github.com/opencontainers/runtime-spec v1.2.2-0.20250818071321-383cadbf08c0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.12.0 h1:6n5JV4Cf+4y0KNXW48TLj5DwfXpvWlxXplUkdTrmPb8=
github.com/opencontainers/selinux v1.12.0/go.mod h1:BTPX+bjVbWGXw7ZZWUbdENt8w0htPSrlgOOysQaU62U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
4 changes: 4 additions & 0 deletions libcontainer/configs/intelrdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ type IntelRdt struct {
// The identity for RDT Class of Service
ClosID string `json:"closID,omitempty"`

// Schemata is a generic field to specify schemata file in the resctrl
// filesystem. Each element represents one line written to the schemata file.
Schemata []string `json:"schemata,omitempty"`

// The schema for L3 cache id and capacity bitmask (CBM)
// Format: "L3:<cache_id0>=<cbm0>;<cache_id1>=<cbm1>;..."
L3CacheSchema string `json:"l3_cache_schema,omitempty"`
Expand Down
47 changes: 14 additions & 33 deletions libcontainer/intelrdt/intelrdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,6 @@ func getIntelRdtParamString(path, file string) (string, error) {
return string(bytes.TrimSpace(contents)), nil
}

func writeFile(dir, file, data string) error {
if dir == "" {
return fmt.Errorf("no such directory for %s", file)
}
if err := os.WriteFile(filepath.Join(dir, file), []byte(data+"\n"), 0o600); err != nil {
return newLastCmdError(fmt.Errorf("intelrdt: unable to write %v: %w", data, err))
}
return nil
}

// Get the read-only L3 cache information
func getL3CacheInfo() (*L3CacheInfo, error) {
l3CacheInfo := &L3CacheInfo{}
Expand Down Expand Up @@ -462,11 +452,11 @@ func (m *Manager) Apply(pid int) (err error) {
m.mu.Lock()
defer m.mu.Unlock()

if m.config.IntelRdt.ClosID != "" && m.config.IntelRdt.L3CacheSchema == "" && m.config.IntelRdt.MemBwSchema == "" {
if m.config.IntelRdt.ClosID != "" && m.config.IntelRdt.L3CacheSchema == "" && m.config.IntelRdt.MemBwSchema == "" && len(m.config.IntelRdt.Schemata) == 0 {
// Check that the CLOS exists, i.e. it has been pre-configured to
// conform with the runtime spec
if _, err := os.Stat(path); err != nil {
return fmt.Errorf("clos dir not accessible (must be pre-created when l3CacheSchema and memBwSchema are empty): %w", err)
return fmt.Errorf("clos dir not accessible (must be pre-created when schemata, l3CacheSchema and memBwSchema are empty): %w", err)
}
}

Expand Down Expand Up @@ -534,6 +524,8 @@ func (m *Manager) GetStats() (*Stats, error) {
}
schemaStrings := strings.Split(tmpStrings, "\n")

stats.Schemata = schemaStrings

if IsCATEnabled() {
// The read-only L3 cache information
l3CacheInfo, err := getL3CacheInfo()
Expand Down Expand Up @@ -637,35 +629,24 @@ func (m *Manager) Set(container *configs.Config) error {
// For example, on a two-socket machine, the schema line could be
// "MB:0=5000;1=7000" which means 5000 MBps memory bandwidth limit on
// socket 0 and 7000 MBps memory bandwidth limit on socket 1.
if container.IntelRdt != nil {
path := m.GetPath()
l3CacheSchema := container.IntelRdt.L3CacheSchema
memBwSchema := container.IntelRdt.MemBwSchema

if r := container.IntelRdt; r != nil {
// TODO: verify that l3CacheSchema and/or memBwSchema match the
// existing schemata if ClosID has been specified. This is a more
// involved than reading the file and doing plain string comparison as
// the value written in does not necessarily match what gets read out
// (leading zeros, cache id ordering etc).

// Write a single joint schema string to schemata file
if l3CacheSchema != "" && memBwSchema != "" {
if err := writeFile(path, "schemata", l3CacheSchema+"\n"+memBwSchema); err != nil {
return err
}
}

// Write only L3 cache schema string to schemata file
if l3CacheSchema != "" && memBwSchema == "" {
if err := writeFile(path, "schemata", l3CacheSchema); err != nil {
return err
var schemata strings.Builder
for _, s := range append([]string{r.L3CacheSchema, r.MemBwSchema}, r.Schemata...) {
if s != "" {
schemata.WriteString(s)
schemata.WriteString("\n")
}
}

// Write only memory bandwidth schema string to schemata file
if l3CacheSchema == "" && memBwSchema != "" {
if err := writeFile(path, "schemata", memBwSchema); err != nil {
return err
if schemata.Len() > 0 {
path := filepath.Join(m.GetPath(), "schemata")
if err := os.WriteFile(path, []byte(schemata.String()), 0o600); err != nil {
return newLastCmdError(fmt.Errorf("intelrdt: unable to write %q: %w", schemata.String(), err))
}
}
}
Expand Down
198 changes: 113 additions & 85 deletions libcontainer/intelrdt/intelrdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,125 @@ package intelrdt
import (
"os"
"path/filepath"
"slices"
"strings"
"testing"
)

func TestIntelRdtSetL3CacheSchema(t *testing.T) {
helper := NewIntelRdtTestUtil(t)

const (
l3CacheSchemaBefore = "L3:0=f;1=f0"
l3CacheSchemeAfter = "L3:0=f0;1=f"
)

helper.writeFileContents(map[string]string{
"schemata": l3CacheSchemaBefore + "\n",
})

helper.config.IntelRdt.L3CacheSchema = l3CacheSchemeAfter
intelrdt := newManager(helper.config, "", helper.IntelRdtPath)
if err := intelrdt.Set(helper.config); err != nil {
t.Fatal(err)
}

tmpStrings, err := getIntelRdtParamString(helper.IntelRdtPath, "schemata")
if err != nil {
t.Fatalf("Failed to parse file 'schemata' - %s", err)
}
values := strings.Split(tmpStrings, "\n")
value := values[0]

if value != l3CacheSchemeAfter {
t.Fatal("Got the wrong value, set 'schemata' failed.")
}
}

func TestIntelRdtSetMemBwSchema(t *testing.T) {
helper := NewIntelRdtTestUtil(t)

const (
memBwSchemaBefore = "MB:0=20;1=70"
memBwSchemeAfter = "MB:0=70;1=20"
)

helper.writeFileContents(map[string]string{
"schemata": memBwSchemaBefore + "\n",
})

helper.config.IntelRdt.MemBwSchema = memBwSchemeAfter
intelrdt := newManager(helper.config, "", helper.IntelRdtPath)
if err := intelrdt.Set(helper.config); err != nil {
t.Fatal(err)
}

tmpStrings, err := getIntelRdtParamString(helper.IntelRdtPath, "schemata")
if err != nil {
t.Fatalf("Failed to parse file 'schemata' - %s", err)
}
values := strings.Split(tmpStrings, "\n")
value := values[0]

if value != memBwSchemeAfter {
t.Fatal("Got the wrong value, set 'schemata' failed.")
}
}

func TestIntelRdtSetMemBwScSchema(t *testing.T) {
helper := NewIntelRdtTestUtil(t)

const (
memBwScSchemaBefore = "MB:0=5000;1=7000"
memBwScSchemeAfter = "MB:0=9000;1=4000"
)

helper.writeFileContents(map[string]string{
"schemata": memBwScSchemaBefore + "\n",
})

helper.config.IntelRdt.MemBwSchema = memBwScSchemeAfter
intelrdt := newManager(helper.config, "", helper.IntelRdtPath)
if err := intelrdt.Set(helper.config); err != nil {
t.Fatal(err)
}
"github.com/opencontainers/runc/libcontainer/configs"
)

tmpStrings, err := getIntelRdtParamString(helper.IntelRdtPath, "schemata")
if err != nil {
t.Fatalf("Failed to parse file 'schemata' - %s", err)
func TestIntelRdtSet(t *testing.T) {
tcs := []struct {
name string
config *configs.IntelRdt
schemataAfter []string
}{
{
name: "L3",
config: &configs.IntelRdt{
L3CacheSchema: "L3:0=f0;1=f",
},
schemataAfter: []string{"L3:0=f0;1=f"},
},
{
name: "MemBw",
config: &configs.IntelRdt{
MemBwSchema: "MB:0=70;1=20",
},
schemataAfter: []string{"MB:0=70;1=20"},
},
{
name: "MemBwSc",
config: &configs.IntelRdt{
MemBwSchema: "MB:0=9000;1=4000",
},
schemataAfter: []string{"MB:0=9000;1=4000"},
},
{
name: "L3 and MemBw",
config: &configs.IntelRdt{
L3CacheSchema: "L3:0=f0;1=f",
MemBwSchema: "MB:0=9000;1=4000",
},
schemataAfter: []string{
"L3:0=f0;1=f",
"MB:0=9000;1=4000",
},
},
{
name: "Schemata",
config: &configs.IntelRdt{
Schemata: []string{
"L3CODE:0=ff;1=ff",
"L3DATA:0=f;1=f0",
},
},
schemataAfter: []string{
"L3CODE:0=ff;1=ff",
"L3DATA:0=f;1=f0",
},
},
{
name: "Schemata and L3",
config: &configs.IntelRdt{
L3CacheSchema: "L3:0=f0;1=f",
Schemata: []string{"L2:0=ff00;1=ff"},
},
schemataAfter: []string{
"L3:0=f0;1=f",
"L2:0=ff00;1=ff",
},
},
{
name: "Schemata and MemBw",
config: &configs.IntelRdt{
MemBwSchema: "MB:0=2000;1=4000",
Schemata: []string{"L3:0=ff;1=ff"},
},
schemataAfter: []string{
"MB:0=2000;1=4000",
"L3:0=ff;1=ff",
},
},
{
name: "Schemata, L3 and MemBw",
config: &configs.IntelRdt{
L3CacheSchema: "L3:0=80;1=7f",
MemBwSchema: "MB:0=2000;1=4000",
Schemata: []string{
"L2:0=ff00;1=ff",
"L3:0=c0;1=3f",
},
},
schemataAfter: []string{
"L3:0=80;1=7f",
"MB:0=2000;1=4000",
"L2:0=ff00;1=ff",
"L3:0=c0;1=3f",
},
},
}
values := strings.Split(tmpStrings, "\n")
value := values[0]

if value != memBwScSchemeAfter {
t.Fatal("Got the wrong value, set 'schemata' failed.")
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
helper := NewIntelRdtTestUtil(t)
helper.config.IntelRdt = tc.config

intelrdt := newManager(helper.config, "", helper.IntelRdtPath)
if err := intelrdt.Set(helper.config); err != nil {
t.Fatal(err)
}

tmpStrings, err := getIntelRdtParamString(helper.IntelRdtPath, "schemata")
if err != nil {
t.Fatalf("Failed to parse file 'schemata' - %s", err)
}
values := strings.Split(tmpStrings, "\n")

if slices.Compare(values, tc.schemataAfter) != 0 {
t.Fatalf("Got the wrong value, expected %v, got %v", tc.schemataAfter, values)
}
})
}
}

Expand Down
3 changes: 3 additions & 0 deletions libcontainer/intelrdt/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type Stats struct {
// The memory bandwidth schema in 'container_id' group
MemBwSchema string `json:"mem_bw_schema,omitempty"`

// Schemata contains the full schemata of the ClosID (resctrl group) that the container is assigned to.
Schemata []string `json:"schemata,omitempty"`

// The memory bandwidth monitoring statistics from NUMA nodes in 'container_id' group
MBMStats *[]MBMNumaNodeStats `json:"mbm_stats,omitempty"`

Expand Down
10 changes: 0 additions & 10 deletions libcontainer/intelrdt/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,3 @@ func NewIntelRdtTestUtil(t *testing.T) *intelRdtTestUtil {
}
return &intelRdtTestUtil{config: config, IntelRdtPath: testIntelRdtPath, t: t}
}

// Write the specified contents on the mock of the specified Intel RDT "resource control" files
func (c *intelRdtTestUtil) writeFileContents(fileContents map[string]string) {
for file, contents := range fileContents {
err := writeFile(c.IntelRdtPath, file, contents)
if err != nil {
c.t.Fatal(err)
}
}
}
1 change: 1 addition & 0 deletions libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
if spec.Linux.IntelRdt != nil {
config.IntelRdt = &configs.IntelRdt{
ClosID: spec.Linux.IntelRdt.ClosID,
Schemata: spec.Linux.IntelRdt.Schemata,
L3CacheSchema: spec.Linux.IntelRdt.L3CacheSchema,
MemBwSchema: spec.Linux.IntelRdt.MemBwSchema,
}
Expand Down
3 changes: 3 additions & 0 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ type IntelRdt struct {
// The memory bandwidth schema in 'container_id' group
MemBwSchema string `json:"mem_bw_schema,omitempty"`

// Schemata contains the full schemata of the ClosID (resctrl group) that the container is assigned to.
Schemata []string `json:"schemata,omitempty"`

// The memory bandwidth monitoring statistics from NUMA nodes in 'container_id' group
MBMStats *[]intelrdt.MBMNumaNodeStats `json:"mbm_stats,omitempty"`

Expand Down
Loading