Allow reporting cpu physical core count.
cpu.Info() reports a list of cpus and the list will be double in length when hyperthreading is enabled. This difference also scales cpu utilization.
New config property: cpu.stats.physicalcore.enabled Default set to false to allow opt-in usage. When set to true domainmgr will: Take the last cpu.InfoStat's CoreID Add 1 (since CoreID starts at 0) Set HostMemory.Ncpus to that value.
@eriknordmark yeah the intent for this PR is to scale cpu utilization differently. The use case is an eve node which may have 4 physical cores and has hyperthreading enabled leading to 8 threads. A vm app is deployed with 2 cpus and the vm running some cpu stress utility like "stress-ng --cpu 2". In this case the vm will see 100% cpu utilization and in existing cpu accounting the utilization is scaled by 8 threads and top level eve node cpu utilization reports 25% utilization. With this config property enabled the utilization would instead be scaled by 4 cores and report 50% utilization.
This PR is not linked to the existing kubevirt PRs.
@OhmSpectator I started with an alternate option which did a simple scan through the list to find the highest CoreId. I removed that to hopefully skip a loop, it could certainly be reimplemented.
@eriknordmark yeah the intent for this PR is to scale cpu utilization differently. The use case is an eve node which may have 4 physical cores and has hyperthreading enabled leading to 8 threads. A vm app is deployed with 2 cpus and the vm running some cpu stress utility like "stress-ng --cpu 2". In this case the vm will see 100% cpu utilization and in existing cpu accounting the utilization is scaled by 8 threads and top level eve node cpu utilization reports 25% utilization. With this config property enabled the utilization would instead be scaled by 4 cores and report 50% utilization.
But if everything is busy including the hyperthreads, then it will might report up to 200% CPU usage for the edge node. Isn't that going to be confusing? Note that users who don't care about hyperthreading can disable it in the BIOS AFAIK.
@andrewd-zededa , is still not clear to me why do we need to care about logical vs physical cores. IIUC the issue is when the device model was generated, let's say, with hyperthreading disabled and then at some point is enabled leading to a different number of CPUs vs what is present in the model... is that correct? I think this is a kind of configuration that shouldn't change over the time. If so, then is up to the user to update the device model accordingly.... from the OS perspective logical cores will be pretty much the same as physical cores... we shouldn't care about it....
I think the comment on top of HostMemory about Ncpus needs to be updated to reflect the changes.
// HostMemory reports global stats. Published under "global" key
// Note that Ncpus is the set of physical CPUs which is different
// than the set of CPUs assigned to dom0
type HostMemory struct {
TotalMemoryMB uint64
FreeMemoryMB uint64
UsedEveMB uint64
KmemUsedEveMB uint64
Ncpus uint32
}