1

On my system with 32 physical cores I'm constantly spawning 100 threads that run for anywhere between 0 and 3 seconds. After all are finished, the next batch is spawned.

I'd like to get correct average cpu usage, i.e. to what percentage are these cores used on a say 1 minute average. If they are idle for 30% of the time, that value should be 0.7

When using htop, I get a load average of more than 40 which higher than the number of cores However, as can be seen in this video, the CPU cores are not always used to 100%. This is what I expect as all 100 threads have to finish before new ones are generated.

How can I get a more precise measurement of CPU usage?

4
  • Does your system support hyperthreading? If so, you might be running two threads on each core.
    – Qudit
    Commented Jun 7, 2015 at 19:58
  • Nope, it's definitely disabled / not even supported.
    – helm
    Commented Jun 7, 2015 at 20:07
  • What kind of average? I suspect you want mean, but it could also be median (or possibly even mode). Commented Jun 7, 2015 at 20:57
  • It's the mean I want.
    – helm
    Commented Jun 7, 2015 at 21:23

1 Answer 1

1

Load average is not the cpu usage per say. This is an often cited explanation of what Load Average means. So a load average of 40 seems pretty reasonable for 100 threads that don't quite use 100% of a core.

To measure the actual CPU usage, I would look into using perf which can read hardware performance counters. Perf is a pretty powerful tool and can measure many things, in your case I might try:

perf stat -e cycles ./your_executable

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .