Skip to content
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

Merged
merged 1 commit into from
Jan 21, 2021
Merged

Conversation

piowag
Copy link
Contributor

@piowag piowag commented May 15, 2020

Adds statistics for cpuset cgroup

Signed-off-by: Piotr Wagner piotr.wagner@intel.com

@kolyshkin
Copy link
Contributor

@piowag you need to squash your commits

}

for _, s := range strings.Split(fileContent, ",") {
if strings.Contains(s, "-") {
Copy link
Contributor

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.

Copy link
Contributor Author

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

return err
}
if min > max {
return fmt.Errorf("Couldn't parse %s", filepath.Join(path, filename))
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied

if err != nil {
return err
}
schedRelaxDomainLevel, err := fscommon.GetCgroupParamInt(path, "cpuset.sched_relax_domain_level")
Copy link
Contributor

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?

Copy link
Contributor Author

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

@piowag piowag force-pushed the cpuset_getstats branch 3 times, most recently from 253558c to c76d065 Compare May 26, 2020 11:52
Copy link
Contributor

@kolyshkin kolyshkin left a 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.

@kolyshkin
Copy link
Contributor

@piowag please let us know if you still can / want to work on this one

@piowag
Copy link
Contributor Author

piowag commented Jun 16, 2020

Sorry, I was absent a little. Yes I still can and want to work on this one.

@piowag piowag requested a review from kolyshkin June 17, 2020 17:58
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin
Copy link
Contributor

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, cpuset.mem_hardwall. Does that mean that GetStats() will now return an error?

For example, (* BlkioGroup).GetStat ignores the ENOENT, returning no errors if some files are not present.

Copy link
Contributor

@kolyshkin kolyshkin left a 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

AkihiroSuda
AkihiroSuda previously approved these changes Dec 8, 2020
@AkihiroSuda
Copy link
Member

@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",
Copy link
Contributor

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))
Copy link
Contributor

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.

Copy link
Member

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))
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: s/specidfied/specified/

Copy link
Contributor

@kolyshkin kolyshkin left a 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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be "CPUSet" ?

Suggested change
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cpus []uint16 `json:"cpus,omitempty"`
CPUs []uint16 `json:"cpus,omitempty"`

Not 100% sure if it should be lowercase or uppercase "s"

@@ -121,6 +148,7 @@ type HugetlbStats struct {

type Stats struct {
CpuStats CpuStats `json:"cpu_stats,omitempty"`
CpusetStats CpusetStats `json:"cpuset_stats,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally

Suggested change
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?

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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cpus []uint16 `json:"cpus,omitempty"`
CPUs []uint16 `json:"cpus,omitempty"`

// in that cpuset are allowed to execute
Cpus []uint16 `json:"cpus,omitempty"`
// cpu_exclusive flag
CpuExclusive uint64 `json:"cpu_exclusive"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Member

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?

@kolyshkin
Copy link
Contributor

@Creatone thanks for working on this! Can you please squash the commits?

kolyshkin
kolyshkin previously approved these changes Jan 11, 2021
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

AkihiroSuda
AkihiroSuda previously approved these changes Jan 12, 2021
@AkihiroSuda
Copy link
Member

GitHub web ui says "Required statuses must pass before merging".

Seems to need to be rebased again to pick the recent CI changes, sorry

@AkihiroSuda
Copy link
Member

@cyphar @kolyshkin Can we merge this to master directly without waiting for CI retrigger?

@Creatone
Copy link
Contributor

@AkihiroSuda @kolyshkin

AkihiroSuda
AkihiroSuda previously approved these changes Jan 19, 2021
Copy link
Member

@AkihiroSuda AkihiroSuda left a 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
Comment on lines 135 to 145
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
Copy link
Member

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;

Suggested change
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)

Copy link
Contributor

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>
Copy link
Member

@thaJeztah thaJeztah left a 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!

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin kolyshkin merged commit d9751a9 into opencontainers:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants