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

cat /proc/stat shows a bunch of zeros #9967

Open
thecodingwizard opened this issue Feb 2, 2024 · 3 comments
Open

cat /proc/stat shows a bunch of zeros #9967

thecodingwizard opened this issue Feb 2, 2024 · 3 comments
Labels
type: bug Something isn't working

Comments

@thecodingwizard
Copy link
Contributor

thecodingwizard commented Feb 2, 2024

Description

When I cat /proc/stat in gvisor, I see a bunch of zeros:

cpu  0 0 0 0 0 0 0 0 0 0
cpu0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 0 0 0 0
cpu2 0 0 0 0 0 0 0 0 0 0
cpu3 0 0 0 0 0 0 0 0 0 0
cpu4 0 0 0 0 0 0 0 0 0 0
cpu5 0 0 0 0 0 0 0 0 0 0
cpu6 0 0 0 0 0 0 0 0 0 0
cpu7 0 0 0 0 0 0 0 0 0 0
intr 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 0
btime 1706898049
processes 0
procs_running 0
procs_blocked 0
softirq 0 0 0 0 0 0 0 0 0 0 0

As such, I think tools like htop don't work (the CPU usage shown is just always zero). My goal is mostly to be able to run htop within a runsc container.

Steps to reproduce

docker run --runtime=runsc --rm -it ubuntu cat /proc/stat

You will see a bunch of zeros. Alternatively, run htop within a runsc container; the CPU usage will be zero everywhere.

runsc version

No response

docker version (if using docker)

Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:08:01 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:08:01 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.26
  GitCommit:        3dd1e886e55dd695541fdcd67420c2888645a495
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

uname

Linux ip-10-1-5-239 5.15.0-1048-aws #53~20.04.1-Ubuntu SMP Wed Oct 4 16:44:20 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

kubectl (if using Kubernetes)

No response

repo state (if built from source)

release-20240122.0-27-gac416763d

runsc debug logs (if available)

No response

@thecodingwizard thecodingwizard added the type: bug Something isn't working label Feb 2, 2024
@thecodingwizard thecodingwizard changed the title /proc/stat shows a bunch of zeros cat /proc/stat shows a bunch of zeros Feb 2, 2024
@ayushr2
Copy link
Collaborator

ayushr2 commented Feb 2, 2024

This is a known deficiency:

// TODO(b/37226836): We currently export only zero CPU stats. We could
// at least provide some aggregate stats.
var cpu cpuStats
fmt.Fprintf(buf, "cpu %s\n", cpu)
k := kernel.KernelFromContext(ctx)
for c, max := uint(0), k.ApplicationCores(); c < max; c++ {
fmt.Fprintf(buf, "cpu%d %s\n", c, cpu)
}

I think tools like htop don't work (the CPU usage shown is just always zero), though I'm not 100% sure that /proc/stat is the issue.

Good way to investigate this would be to run strace -f htop on host and see if it opens /proc/stat.

@thecodingwizard
Copy link
Contributor Author

Oh, that's an excellent idea! I verified that there is a syscall to open /proc/stat when running htop. Thanks!

@thecodingwizard
Copy link
Contributor Author

Do you know how difficult this functionality would be to implement? Would the implementation of overall CPU stats be to maintain an exitedCPUStats property in Kernel (updated every time a task exits in task_exit.go) and aggregate k.exitedCPUStats with k.TaskSet().Root.tasks.CPUStats()?

I'm not sure how to get per-core aggregate information...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants