← Back to DAGDA | Support | Source: https://github.com/giampaolo/psutil/issues/771
Skip to content

Wrong number of CPU cores detected in Windows Server multi Processor Group environment #771

Closed

Description

@twisniewski78

When running psutil.cpu_count(logical=False) I am getting 60 instead of 120 cores. Similarly when running psutil.cpu_percent(interval=1, percpu=True) I am getting utilization just for half of the CPU cores.
My system has two Processor Groups (each with 60 cores) and it seams that psutil is not processor group aware. On large systems processor resources are split into groups and it requires using special API to get correct numbers.

Activity

  1. added
    bug
    windows
    on Sep 22, 2016
  2. giampaolo commented on Sep 22, 2016

    @giampaolo
    Owner

    Sorry for such a big delay in responding. Can you provide more info about what kind of processors are these? Otherwise I really have no idea what kind of alternative API we could use.

  3. twisniewski78 commented on Sep 22, 2016

    @twisniewski78
    Author

    I have eight Xeons E7-2890 v2 with 15 cores each. My first guess would be NUMA architecture and Processor Group awareness rather then type of CPU. I was having the same issues on different system with 80 cores and different CPU model.

  4. giampaolo commented on Nov 25, 2016

    @giampaolo
    Owner

    Looking back at this: what does len(psutil.cpu_times(percpu=True)) return? 60 or 120?

  5. giampaolo commented on Dec 1, 2016

    @giampaolo
    Owner

    The problem may be here:

    if (ptr->Relationship == RelationProcessorCore)

    As per:
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms686694(v=vs.85).aspx
    ...if (ptr->Relationship == RelationNumaNode) we may have to increment the counter by 1

    Still, that would not match len(psutil.cpu_percent(interval=1, percpu=True)) which according to your report would keep returning half the cores.

    cpu_times(percpu=True) internally relies on dwNumberOfProcessors:

    for (i = 0; i < si.dwNumberOfProcessors; i++) {

    ...which should be "correct", so I'm really not sure what to think.

  6. twisniewski78 commented on Dec 2, 2016

    @twisniewski78
    Author
  7. twisniewski78 commented on Dec 2, 2016

    @twisniewski78
    Author
  8. giampaolo commented on Dec 2, 2016

    @giampaolo
    Owner

    Indeed MS doc states:

    dwNumberOfProcessors
    The number of logical processors in the current group. 
    Note  For information about the physical processors shared by logical processors, 
    call GetLogicalProcessorInformationEx with the RelationshipType parameter set to 
    RelationProcessorPackage (3).
    

    It looks like GetLogicalProcessorInformationEx should give us what we want:

    When this function is called with a relationship type of 
    RelationProcessorCore, it returns a PROCESSOR_RELATIONSHIP 
    structure for every active processor core in every processor group 
    in the system. 
    
  9. giampaolo commented on Dec 2, 2016

    @giampaolo
    Owner

    Main problem is that I don't have the right hardware to test this against.

  10. giampaolo commented on Dec 2, 2016

    @giampaolo
    Owner

    Note: os.cpu_count() on Python 3 relies on GetSystemInfo / dwNumberOfProcessors so it has the same problem.

  11. twisniewski78 commented on Dec 2, 2016

    @twisniewski78
    Author
  12. FJplant commented on Dec 3, 2016

    @FJplant
  13. giampaolo commented on Dec 3, 2016

    @giampaolo
    Owner

    It is (still investigating and not fixed).

  14. FJplant commented on Dec 3, 2016

    @FJplant
  15. 14 remaining items

  16. giampaolo commented on May 16, 2017

    @giampaolo
    Owner

    OK, so can you please file an issue on http://bugs.python.org/?

  17. robbuckley commented on Jun 6, 2017

    @robbuckley
  18. giampaolo commented on Mar 28, 2018

    @giampaolo
    Owner
  19. added
    critical
    on Mar 28, 2018
  20. giampaolo commented on Mar 28, 2018

    @giampaolo
    Owner

    I created a psutil branch using GetLogicalProcessorInformation (not GetLogicalProcessorInformationEx) to determine both logical and physical CPUs:
    #1257
    @twisniewski78 / @robbuckley : can you try it?
    If you don't have Visual Studio I can send you a .whl file for Python 2.7 32 bit.

  21. twisniewski78 commented on Mar 28, 2018

    @twisniewski78
    Author

    Sadly I have no longer access to this environment or anything like it.

  22. giampaolo commented on Apr 13, 2018

    @giampaolo
    Owner

    OK, this should finally be fixed as of #1257.

  23. giampaolo commented on Oct 20, 2018

    @giampaolo
    Owner

    Closing out as fixed.

  24. added
    api-change
    compatibility
    and removed
    critical
    on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-changebugcompatibilitywindows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions