-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cpuset statistics #2408
Add cpuset statistics #2408
Conversation
@piowag you need to squash your commits |
libcontainer/cgroups/fs/cpuset.go
Outdated
} | ||
|
||
for _, s := range strings.Split(fileContent, ",") { | ||
if strings.Contains(s, "-") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can avoid this check and go right to splitting. If len(splitted) == 1
it means there is no dash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 or 3 could also mean no dash
libcontainer/cgroups/fs/cpuset.go
Outdated
return err | ||
} | ||
if min > max { | ||
return fmt.Errorf("Couldn't parse %s", filepath.Join(path, filename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perpahs invalid values in %s
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied
libcontainer/cgroups/fs/cpuset.go
Outdated
if err != nil { | ||
return err | ||
} | ||
schedRelaxDomainLevel, err := fscommon.GetCgroupParamInt(path, "cpuset.sched_relax_domain_level") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you want to return an error if any of these files do not exist? What if some older kernel do not provide some?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed stat gathering method to try to gather as much as possible instead of quitting at first error
253558c
to
c76d065
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments are not yet acted upon. I do not insist on fixing every nit, but at least explain why you prefer it the way you did it.
@piowag please let us know if you still can / want to work on this one |
Sorry, I was absent a little. Yes I still can and want to work on this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
One thing I don't like about this patch is it requires all the cpuset files being present. On my system (kernel 5.6) I do not have, for example, For example, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to figure out whether to ignore ENOENT
8fe4901
to
a4b3075
Compare
@opencontainers/runc-maintainers PTAL. This has been open so long. |
SchedLoadBalance: 1, | ||
SchedRelaxDomainLevel: -1} | ||
if !reflect.DeepEqual(expectedStats, actualStats.CpusetStats) { | ||
t.Fatalf("Expected Cpuset stats usage %#v but found %#v\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for \n
here.
err := cpuset.GetStats(helper.CgroupPath, &actualStats) | ||
|
||
if err != nil { | ||
t.Errorf(fmt.Sprintf("test case '%s' failed unexpectedly: '%s'", failCase.desc, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need to use fmt.Sprintf
here, as t.Errorf
is perfectly capable of handling %
-style arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use sub-tests for these cases, then it would not be needed to include the name of the failed test in the error?
err := cpuset.GetStats(helper.CgroupPath, &actualStats) | ||
|
||
if err == nil { | ||
t.Errorf(fmt.Sprintf("test case '%s' failed to return expected error", failCase.desc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -72,6 +72,25 @@ func GetCgroupParamUint(path, file string) (uint64, error) { | |||
return res, nil | |||
} | |||
|
|||
// GetCgroupParamInt reads a single int64 value from specidfied cgroup file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: s/specidfied/specified/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few minor comments, overall LGTM
types/events.go
Outdated
@@ -12,6 +12,7 @@ type Event struct { | |||
// stats is the runc specific stats structure for stability when encoding and decoding stats. | |||
type Stats struct { | |||
CPU Cpu `json:"cpu"` | |||
Cpuset Cpuset `json:"cpuset"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be "CPUSet" ?
Cpuset Cpuset `json:"cpuset"` | |
CPUSet CPUSet `json:"cpuset"` |
types/events.go
Outdated
@@ -70,6 +71,20 @@ type Cpu struct { | |||
Throttling Throttling `json:"throttling,omitempty"` | |||
} | |||
|
|||
type Cpuset struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type Cpuset struct { | |
type CPUSet struct { |
types/events.go
Outdated
@@ -70,6 +71,20 @@ type Cpu struct { | |||
Throttling Throttling `json:"throttling,omitempty"` | |||
} | |||
|
|||
type Cpuset struct { | |||
Cpus []uint16 `json:"cpus,omitempty"` | |||
CpuExclusive uint64 `json:"cpu_exclusive"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CpuExclusive uint64 `json:"cpu_exclusive"` | |
CPUExclusive uint64 `json:"cpu_exclusive"` |
types/events.go
Outdated
@@ -70,6 +71,20 @@ type Cpu struct { | |||
Throttling Throttling `json:"throttling,omitempty"` | |||
} | |||
|
|||
type Cpuset struct { | |||
Cpus []uint16 `json:"cpus,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpus []uint16 `json:"cpus,omitempty"` | |
CPUs []uint16 `json:"cpus,omitempty"` |
Not 100% sure if it should be lowercase or uppercase "s"
libcontainer/cgroups/stats.go
Outdated
@@ -121,6 +148,7 @@ type HugetlbStats struct { | |||
|
|||
type Stats struct { | |||
CpuStats CpuStats `json:"cpu_stats,omitempty"` | |||
CpusetStats CpusetStats `json:"cpuset_stats,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally
CpusetStats CpusetStats `json:"cpuset_stats,omitempty"` | |
CPUSetStats CPUSetStats `json:"cpuset_stats,omitempty"` |
But I can see that being inconsistent with the other field; is that something that can still be changed, or would that break many things?
libcontainer/cgroups/stats.go
Outdated
type CpusetStats struct { | ||
// List of the physical numbers of the CPUs on which processes | ||
// in that cpuset are allowed to execute | ||
Cpus []uint16 `json:"cpus,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpus []uint16 `json:"cpus,omitempty"` | |
CPUs []uint16 `json:"cpus,omitempty"` |
libcontainer/cgroups/stats.go
Outdated
// in that cpuset are allowed to execute | ||
Cpus []uint16 `json:"cpus,omitempty"` | ||
// cpu_exclusive flag | ||
CpuExclusive uint64 `json:"cpu_exclusive"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CpuExclusive uint64 `json:"cpu_exclusive"` | |
CPUExclusive uint64 `json:"cpu_exclusive"` |
err := cpuset.GetStats(helper.CgroupPath, &actualStats) | ||
|
||
if err != nil { | ||
t.Errorf(fmt.Sprintf("test case '%s' failed unexpectedly: '%s'", failCase.desc, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use sub-tests for these cases, then it would not be needed to include the name of the failed test in the error?
@Creatone thanks for working on this! Can you please squash the commits? |
00840bf
to
7f30901
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
GitHub web ui says "Required statuses must pass before merging". Seems to need to be rebased again to pick the recent CI changes, sorry |
@cyphar @kolyshkin Can we merge this to master directly without waiting for CI retrigger? |
7f30901
to
3b0d1be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
events.go
Outdated
s.CPUSet.CPUs = cg.CPUSetStats.CPUs | ||
s.CPUSet.CPUExclusive = cg.CPUSetStats.CPUExclusive | ||
s.CPUSet.Mems = cg.CPUSetStats.Mems | ||
s.CPUSet.MemExclusive = cg.CPUSetStats.MemExclusive | ||
s.CPUSet.MemHardwall = cg.CPUSetStats.MemHardwall | ||
s.CPUSet.MemoryMigrate = cg.CPUSetStats.MemoryMigrate | ||
s.CPUSet.MemoryPressure = cg.CPUSetStats.MemoryPressure | ||
s.CPUSet.MemorySpreadPage = cg.CPUSetStats.MemorySpreadPage | ||
s.CPUSet.MemorySpreadSlab = cg.CPUSetStats.MemorySpreadSlab | ||
s.CPUSet.SchedLoadBalance = cg.CPUSetStats.SchedLoadBalance | ||
s.CPUSet.SchedRelaxDomainLevel = cg.CPUSetStats.SchedRelaxDomainLevel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these types are compatible, and this could be simplified to;
s.CPUSet.CPUs = cg.CPUSetStats.CPUs | |
s.CPUSet.CPUExclusive = cg.CPUSetStats.CPUExclusive | |
s.CPUSet.Mems = cg.CPUSetStats.Mems | |
s.CPUSet.MemExclusive = cg.CPUSetStats.MemExclusive | |
s.CPUSet.MemHardwall = cg.CPUSetStats.MemHardwall | |
s.CPUSet.MemoryMigrate = cg.CPUSetStats.MemoryMigrate | |
s.CPUSet.MemoryPressure = cg.CPUSetStats.MemoryPressure | |
s.CPUSet.MemorySpreadPage = cg.CPUSetStats.MemorySpreadPage | |
s.CPUSet.MemorySpreadSlab = cg.CPUSetStats.MemorySpreadSlab | |
s.CPUSet.SchedLoadBalance = cg.CPUSetStats.SchedLoadBalance | |
s.CPUSet.SchedRelaxDomainLevel = cg.CPUSetStats.SchedRelaxDomainLevel | |
s.CPUSet = types.CPUSet(cg.CPUSetStats) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tricky :) Thanks!
Co-authored-by: Piotr Wagner <piotr.wagner@intel.com> Signed-off-by: Paweł Szulik <pawel.szulik@intel.com>
3b0d1be
to
ab27e12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (not a maintainer)
thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds statistics for cpuset cgroup
Signed-off-by: Piotr Wagner piotr.wagner@intel.com