VirtualBox

Ignore:
Timestamp:
Oct 4, 2019 1:41:17 AM (5 years ago)
Author:
vboxsync
Message:

common/utils.py: Added getPresentCpuCount method. bugref:9501

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r79908 r81107  
    300300    return sVersion;
    301301
     302def getPresentCpuCount():
     303    """
     304    Gets the number of CPUs present in the system.
     305
     306    This differs from multiprocessor.cpu_count() and os.cpu_count() on windows in
     307    that we return the active count rather than the maximum count.  If we don't,
     308    we will end up thinking testboxmem1 has 512 CPU threads, which it doesn't and
     309    never will have.
     310
     311    @todo This is probably not exactly what we get on non-windows...
     312    """
     313
     314    if getHostOs() == 'win':
     315        fnGetActiveProcessorCount = getattr(ctypes.windll.kernel32, 'GetActiveProcessorCount', None);
     316        if fnGetActiveProcessorCount:
     317            cCpus = fnGetActiveProcessorCount(ctypes.c_ushort(0xffff));
     318            if cCpus > 0:
     319                return cCpus;
     320
     321    import multiprocessor;
     322    return multiprocessor.cpu_count();
     323
     324
    302325#
    303326# File system.
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette