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

[RQD] Fix core detection on Windows platforms #1468

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
76 changes: 62 additions & 14 deletions rqd/rqd/rqmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,20 +631,8 @@ def __initMachineStats(self, pathCpuInfo=None):
hyperthreadingMultiplier = 1

if platform.system() == 'Windows':
# Windows memory information
stat = self.getWindowsMemory()
TEMP_DEFAULT = 1048576
self.__renderHost.total_mcp = TEMP_DEFAULT
self.__renderHost.total_mem = int(stat.ullTotalPhys / 1024)
self.__renderHost.total_swap = int(stat.ullTotalPageFile / 1024)

# Windows CPU information
logical_core_count = psutil.cpu_count(logical=True)
actual_core_count = psutil.cpu_count(logical=False)
hyperthreadingMultiplier = logical_core_count // actual_core_count

__totalCores = logical_core_count * rqd.rqconstants.CORE_VALUE
__numProcs = 1 # TODO: figure out how to count sockets in Python
logicalCoreCount, __numProcs, hyperthreadingMultiplier = self.__initStatsFromWindows()
__totalCores = logicalCoreCount * rqd.rqconstants.CORE_VALUE

# All other systems will just have one proc/core
if not __numProcs or not __totalCores:
Expand Down Expand Up @@ -674,6 +662,66 @@ def __initMachineStats(self, pathCpuInfo=None):
if hyperthreadingMultiplier >= 1:
self.__renderHost.attributes['hyperthreadingMultiplier'] = str(hyperthreadingMultiplier)

def __initStatsFromWindows(self):
"""Init machine stats for Windows platforms.

@rtype: tuple
@return: A 3-items tuple containing:
- the number of logical cores
- the number of physical processors
- the hyper-threading multiplier

Implementation detail.
DiegoTavares marked this conversation as resolved.
Show resolved Hide resolved
"""
# Windows memory information
stat = self.getWindowsMemory()
TEMP_DEFAULT = 1048576
self.__renderHost.total_mcp = TEMP_DEFAULT
self.__renderHost.total_mem = int(stat.ullTotalPhys / 1024)
self.__renderHost.total_swap = int(stat.ullTotalPageFile / 1024)

# Windows CPU information
self.__updateProcsMappingsFromWindows()

logicalCoreCount = psutil.cpu_count(logical=True)
actualCoreCount = psutil.cpu_count(logical=False)
hyperThreadingMultiplier = logicalCoreCount // actualCoreCount

physicalProcessorCount = len(self.__procs_by_physid_and_coreid)

return logicalCoreCount, physicalProcessorCount, hyperThreadingMultiplier

def __updateProcsMappingsFromWindows(self):
"""Update `__procs_by_physid_and_coreid` and `__physid_and_coreid_by_proc` mappings for Windows platforms.
DiegoTavares marked this conversation as resolved.
Show resolved Hide resolved

Implementation detail.
"""
import wmi # Windows-specific

# Reset mappings
self.__procs_by_physid_and_coreid = {}
self.__physid_and_coreid_by_proc = {}

# Connect to the Windows Management Instrumentation (WMI) interface
wmiInstance = wmi.WMI()

# Retrieve CPU information using WMI
for physicalId, processor in enumerate(wmiInstance.Win32_Processor()):

threadPerCore = processor.NumberOfLogicalProcessors // processor.NumberOfCores
procId = 0

for coreId in range(processor.NumberOfCores):
for _ in range(threadPerCore):
self.__procs_by_physid_and_coreid.setdefault(
str(physicalId), {}
).setdefault(str(coreId), set()).add(str(procId))
self.__physid_and_coreid_by_proc[str(procId)] = (
str(physicalId),
str(coreId),
)
procId += 1

anton-ubi marked this conversation as resolved.
Show resolved Hide resolved
def getWindowsMemory(self):
"""Gets information on system memory, Windows compatible version."""
# From
Expand Down
3 changes: 2 additions & 1 deletion rqd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
'grpcio',
'grpcio-tools',
'psutil',
'pywin32; platform_system == "Windows"'
'pywin32; platform_system == "Windows"',
DiegoTavares marked this conversation as resolved.
Show resolved Hide resolved
'wmi==1.5.1; platform_system == "Windows"'
]
)

Loading