Skip to content

Incorrect physical processor count on Linux #900

Closed

Description

@cycchow

Environment: Docker container tomcat:9

test fail during building.

[INFO] Running oshi.hardware.CentralProcessorTest [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.532 s <<< FAILURE! - in oshi.hardware.CentralProcessorTest [ERROR] testCentralProcessor Time elapsed: 0.531 s <<< FAILURE! java.lang.AssertionError at oshi.hardware.CentralProcessorTest.testCentralProcessor(CentralProcessorTest.java:83)

Activity

  1. dbwiddis commented on Jun 28, 2019

    @dbwiddis
    Member

    Line 83 is:
    assertTrue(p.getPhysicalProcessorCount() >= p.getPhysicalPackageCount());
    These numbers are populated by counting values in /proc/cpuinfo.

    Can you provide the output of cat /proc/cpuinfo run from inside the container?

  2. cycchow commented on Jun 28, 2019

    @cycchow
    Author

    processor : 0
    vendor_id : GenuineIntel
    cpu family : 6
    model : 158
    model name : Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    stepping : 9
    cpu MHz : 4200.000
    cache size : 8192 KB
    physical id : 0
    siblings : 1
    core id : 0
    cpu cores : 1
    apicid : 0
    initial apicid : 0
    fpu : yes
    fpu_exception : yes
    cpuid level : 22
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht pbe syscall nx pdpe1gb lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq dtes64 ds_cpl ssse3 sdbg fma cx16 xtpr pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch kaiser fsgsbase bmi1 hle avx2 bmi2 erms rtm xsaveopt arat
    bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
    bogomips : 8400.00
    clflush size : 64
    cache_alignment : 64
    address sizes : 39 bits physical, 48 bits virtual
    power management:

    processor : 1
    vendor_id : GenuineIntel
    cpu family : 6
    model : 158
    model name : Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    stepping : 9
    cpu MHz : 4200.000
    cache size : 8192 KB
    physical id : 1
    siblings : 1
    core id : 0
    cpu cores : 1
    apicid : 1
    initial apicid : 1
    fpu : yes
    fpu_exception : yes
    cpuid level : 22
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht pbe syscall nx pdpe1gb lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq dtes64 ds_cpl ssse3 sdbg fma cx16 xtpr pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch kaiser fsgsbase bmi1 hle avx2 bmi2 erms rtm xsaveopt arat
    bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
    bogomips : 8979.59
    clflush size : 64
    cache_alignment : 64
    address sizes : 39 bits physical, 48 bits virtual
    power management:

    processor : 2
    vendor_id : GenuineIntel
    cpu family : 6
    model : 158
    model name : Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    stepping : 9
    cpu MHz : 4200.000
    cache size : 8192 KB
    physical id : 2
    siblings : 1
    core id : 0
    cpu cores : 1
    apicid : 2
    initial apicid : 2
    fpu : yes
    fpu_exception : yes
    cpuid level : 22
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht pbe syscall nx pdpe1gb lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq dtes64 ds_cpl ssse3 sdbg fma cx16 xtpr pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch kaiser fsgsbase bmi1 hle avx2 bmi2 erms rtm xsaveopt arat
    bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
    bogomips : 8364.34
    clflush size : 64
    cache_alignment : 64
    address sizes : 39 bits physical, 48 bits virtual
    power management:

    processor : 3
    vendor_id : GenuineIntel
    cpu family : 6
    model : 158
    model name : Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    stepping : 9
    cpu MHz : 4200.000
    cache size : 8192 KB
    physical id : 3
    siblings : 1
    core id : 0
    cpu cores : 1
    apicid : 3
    initial apicid : 3
    fpu : yes
    fpu_exception : yes
    cpuid level : 22
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht pbe syscall nx pdpe1gb lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq dtes64 ds_cpl ssse3 sdbg fma cx16 xtpr pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch kaiser fsgsbase bmi1 hle avx2 bmi2 erms rtm xsaveopt arat
    bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
    bogomips : 8988.29
    clflush size : 64
    cache_alignment : 64
    address sizes : 39 bits physical, 48 bits virtual
    power management:

  3. dbwiddis commented on Jun 28, 2019

    @dbwiddis
    Member

    Hmm. I see what's happening and am surprised this hasn't been reported before now.

    OSHI is counting up the 4 unique physical id values (0, 1, 2, 3) and assuming 4 cpu sockets/packages, but is only seeing one value for core id. In LinuxCentralProcessor starting on line 145, we do this:

            Set<Integer> physProcs = new HashSet<>();
            Set<Integer> physPkgs = new HashSet<>();
            for (LogicalProcessor logProc : logProcs) {
                physProcs.add(logProc.getPhysicalProcessorNumber());
                physPkgs.add(logProc.getPhysicalPackageNumber());
            }
    

    This is clearly a bug: physical processor 0 on package 0 is a distinct CPU from physical processor 0 on package 1 but using a Set to count only distinct values of the core id is wrong. We need to count distinct pairs of physical id+core id.

  4. added
    confirmed bug
    good first issue
    on Jun 28, 2019
  5. changed the title [-]Fail to build in docker container[/-] [+]Incorrect physical processor count on Linux[/+] on Jun 28, 2019
  6. dbwiddis commented on Jun 28, 2019

    @dbwiddis
    Member

    I'm marking this issue for first-timers-only. That means that I will only accept a PR for this one from someone who's never contributed to open source before. This one is easy (but don't make that statement make you feel bad if you have a hard time with it, there's more to contributing to open source than changing lines of code, especially if it's your first time). I'll hold your hand through this if you need me to. :-) Here are the steps to get a PR merged here.

    • Read the CONTRIBUTING file for reference. I'll walk you through anything you don't understand.
    • Find the LinuxCentralProcessor.java class. Beginning at Line 145, the code populates the physical processor count by counting unique values of logProc.getPhysicalProcessorNumber() added to a Set.
    • Alter the code to instead count unique pairs of logProc.getPhysicalPackageNumber() and logProc.getPhysicalProcessorNumber(). One option is to combine these two integers into a String using some delimiter, and storing the unique String values in the set. Another option would be to create a 64-bit Long out of the two 32-bit values. Other options would include better ways of counting unique pairs, that don't involve using a Set. Note the package counting is still correct, you only have to alter the physical processor count by including the package-core combination rather than just the core.
    • The same bug exists in SolarisCentralProcessor.java at line 91, and FreeBsdCentralProcessor.java at line 139. Fix these similarly.
    • Fork the project, commit your changes to your fork, create a PR, and get it merged
    • Celebrate
  7. added
    first-timers-only
    on Jun 28, 2019
  8. ellemcfarlane commented on Jun 28, 2019

    @ellemcfarlane
    Contributor

    Hi, I'd like to start working on this (never contributed to open source before), but I am having trouble with cloning the url indicated in the CONTRIBUTING file. It says to clone https://github.com/contributor/oshi.git, but this webpage doesn't exist. Should I instead clone https://github.com/oshi/oshi.git?

  9. spyhunter99 commented on Jun 28, 2019

    @spyhunter99
    Collaborator

    yes

  10. ellemcfarlane commented on Jun 28, 2019

    @ellemcfarlane
    Contributor

    Cool--thanks.

  11. dbwiddis commented on Jun 28, 2019

    @dbwiddis
    Member

    Actually, rereading this question, let me clarify. If you clone the OSHI repository you won't be able to commit directly to it. Where it says contributor you should put your user name.

    So the first step is to fork the repository on the GitHub website, into your own account. Then you will be able to clone (from the command line) https://github.com/ellesummer/oshi.git

    You can then make the changes, and push to your own repository; when you're ready for the PR you'll do that from your own fork on GitHub.

  12. ellemcfarlane commented on Jun 29, 2019

    @ellemcfarlane
    Contributor

    Ah okay, will do!

  13. ellemcfarlane commented on Jun 29, 2019

    @ellemcfarlane
    Contributor

    I have a mac, so when I run tests, it uses the mac code. Any advice on how to reproduce this bug from the linux/unix code, so I can make sure my code actually fixes it? Should I use VirtualBox?

  14. dbwiddis commented on Jun 29, 2019

    @dbwiddis
    Member

    Virtualbox or some other vm is the best. Travis tests run on Linux. Ideally @cycchow can test on the same hardware that was reported here.

  15. dbwiddis commented on Jun 29, 2019

    @dbwiddis
    Member

    One suggestion is to test the changed code on a “main” method in the class and run it locally. Save the /proc/cpuinfo extract above to a file on your Mac in that location.

  16. ellemcfarlane commented on Jun 29, 2019

    @ellemcfarlane
    Contributor

    Okay, I am having real trouble reproducing the error.. However, my travis tests show an unspecified error for oracle jdk 11, which may be due to an old link as it doesn't get past downloading the jdk--although I see the travis script should automatically update this link. Anyway, should I just do a PR now and if approved, have @cycchow test it?

  17. dbwiddis commented on Jun 29, 2019

    @dbwiddis
    Member

    In order to reproduce the error you need to be on hardware with multiple CPU sockets. You should be able to reproduce the CPU count values by reading in from the text file rather than the real /proc/cpu. In any case, go ahead and submit the PR and we can review it!

  18. ellemcfarlane commented on Jun 29, 2019

    @ellemcfarlane
    Contributor

    Didn't realize I could do that--makes sense. Just submitted the PR!

  19. dbwiddis commented on Jun 30, 2019

    @dbwiddis
    Member

    Fixed in #901

  20. added
    containers
    on Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed bugcontainersfirst-timers-onlygood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions