Skip to content

Commit 5ed586d

Browse files
committed
feat: add cpu max burst support
Signed-off-by: Lucas Jacques <contact@lucasjacques.com>
1 parent d4e976d commit 5ed586d

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

cgroup2/cpu.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ func NewCPUMax(quota *int64, period *uint64) CPUMax {
3232
return CPUMax(strings.Join([]string{max, strconv.FormatUint(*period, 10)}, " "))
3333
}
3434

35+
func NewCPUMaxBurst(burst uint64) string {
36+
return strconv.FormatUint(burst, 10)
37+
}
38+
3539
type CPU struct {
36-
Weight *uint64
37-
Max CPUMax
38-
Cpus string
39-
Mems string
40+
Weight *uint64
41+
Max CPUMax
42+
MaxBurst string
43+
Cpus string
44+
Mems string
4045
}
4146

4247
func (c CPUMax) extractQuotaAndPeriod() (int64, uint64) {
@@ -79,5 +84,12 @@ func (r *CPU) Values() (o []Value) {
7984
value: r.Mems,
8085
})
8186
}
87+
if r.MaxBurst != "" {
88+
o = append(o, Value{
89+
filename: "cpu.max.burst",
90+
value: r.MaxBurst,
91+
})
92+
}
93+
8294
return o
8395
}

cgroup2/cpuv2_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ func TestCgroupv2CpuStats(t *testing.T) {
3232
group := "/cpu-test-cg"
3333
groupPath := fmt.Sprintf("%s-%d", group, os.Getpid())
3434
var (
35+
burst uint64 = 1000
3536
quota int64 = 10000
3637
period uint64 = 8000
3738
weight uint64 = 100
3839
)
3940

4041
c, err := NewManager(defaultCgroup2Path, groupPath, &Resources{
4142
CPU: &CPU{
42-
Weight: &weight,
43-
Max: NewCPUMax(&quota, &period),
44-
Cpus: "0",
45-
Mems: "0",
43+
Weight: &weight,
44+
Max: NewCPUMax(&quota, &period),
45+
Cpus: "0",
46+
Mems: "0",
47+
MaxBurst: NewCPUMaxBurst(burst),
4648
},
4749
})
4850
require.NoError(t, err, "failed to init new cgroup manager")
@@ -54,6 +56,7 @@ func TestCgroupv2CpuStats(t *testing.T) {
5456
checkFileContent(t, c.path, "cpu.max", "10000 8000")
5557
checkFileContent(t, c.path, "cpuset.cpus", "0")
5658
checkFileContent(t, c.path, "cpuset.mems", "0")
59+
checkFileContent(t, c.path, "cpu.max.burst", strconv.FormatUint(burst, 10))
5760
}
5861

5962
func TestSystemdCgroupCpuController(t *testing.T) {

cgroup2/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func ToResources(spec *specs.LinuxResources) *Resources {
172172
if period := cpu.Period; period != nil {
173173
resources.CPU.Max = NewCPUMax(cpu.Quota, period)
174174
}
175+
if burst := cpu.Burst; burst != nil {
176+
resources.CPU.MaxBurst = NewCPUMaxBurst(*burst)
177+
}
175178
}
176179
if mem := spec.Memory; mem != nil {
177180
resources.Memory = &Memory{}

0 commit comments

Comments
 (0)