mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #97378 from hwdef/master
kubelet: Fix the bug of getting the number of windows cpu
This commit is contained in:
commit
c2ad998811
@ -26,6 +26,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
@ -52,8 +53,11 @@ type MemoryStatusEx struct {
|
||||
var (
|
||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
|
||||
procGetActiveProcessorCount = modkernel32.NewProc("GetActiveProcessorCount")
|
||||
)
|
||||
|
||||
const allProcessorGroups = 0xFFFF
|
||||
|
||||
// NewPerfCounterClient creates a client using perf counters
|
||||
func NewPerfCounterClient() (Client, error) {
|
||||
// Initialize the cache
|
||||
@ -140,13 +144,33 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo,
|
||||
}
|
||||
|
||||
return &cadvisorapi.MachineInfo{
|
||||
NumCores: runtime.NumCPU(),
|
||||
NumCores: processorCount(),
|
||||
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
|
||||
MachineID: hostname,
|
||||
SystemUUID: systemUUID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// runtime.NumCPU() will only return the information for a single Processor Group.
|
||||
// Since a single group can only hold 64 logical processors, this
|
||||
// means when there are more they will be divided into multiple groups.
|
||||
// For the above reason, procGetActiveProcessorCount is used to get the
|
||||
// cpu count for all processor groups of the windows node.
|
||||
// more notes for this issue:
|
||||
// same issue in moby: https://github.com/moby/moby/issues/38935#issuecomment-744638345
|
||||
// solution in hcsshim: https://github.com/microsoft/hcsshim/blob/master/internal/processorinfo/processor_count.go
|
||||
func processorCount() int {
|
||||
if amount := getActiveProcessorCount(allProcessorGroups); amount != 0 {
|
||||
return int(amount)
|
||||
}
|
||||
return runtime.NumCPU()
|
||||
}
|
||||
|
||||
func getActiveProcessorCount(groupNumber uint16) int {
|
||||
r0, _, _ := syscall.Syscall(procGetActiveProcessorCount.Addr(), 1, uintptr(groupNumber), 0, 0)
|
||||
return int(r0)
|
||||
}
|
||||
|
||||
func (p *perfCounterNodeStatsClient) getVersionInfo() (*cadvisorapi.VersionInfo, error) {
|
||||
return &cadvisorapi.VersionInfo{
|
||||
KernelVersion: p.nodeInfo.kernelVersion,
|
||||
|
Loading…
Reference in New Issue
Block a user