Skip to content

VM stealtime>0, process.Percent(0) / cpu.Counts(true) is higher than 100% #1978

Description

@hitzhangjie

Describe the bug
We have following code to update the per-cpu usage, it works well in normal machine.

Recently, one of our service instances keep reporting errors. It's deployed in a VM, and that time, the host report stealtime>0. And from our logging, we see the newv here is larger than 100%.

To Reproduce

	ncpu, err := cpu.Counts(true)
	if err != nil {
		logger.Error("load num of CPUs fail ... overload=false", zap.Error(err))
		return false
	}

	use, err := c.process.Percent(0)
	if err != nil {
		logger.Error("load process CPU usage fail ... overload=false", zap.Error(err))
		return false
	}

	oldv := c.percpu.Load()
	newv := use / float64(ncpu)

Expected behavior
process.Percent(0) / cpu.Counts(true) return the right cpu usage.

Environment (please complete the following information):

  • Linux df-cnprod-set212-a-025-nj2 5.4.241-1-tlinux4-0023.1 #1 SMP Tue May 6 19:25:45 CST 2025 x86_64 x86_64 x86_64 GNU/Linux

Additional context
No.

Here's the log:

update per-cpu load {"process": 21012, "oldv": 51.060771011525944, "newv": 354.0590442937935}

And the logic above run every second.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions