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

Fix calculation of # CPU cores (FreeBSD/DragonFly) #3707

Merged

Conversation

mneumann
Copy link
Contributor

@mneumann mneumann commented Feb 6, 2021

  • On both FreeBSD and DragonFly, sysctl hw.ncpu returns the number of
    logical CPUs, NOT the number of physical CPU cores.

  • FreeBSD has sysctl kern.smp.cores.

  • DragonFly has sysctl's hw.cpu_topology_core_ids and
    hw.cpu_topology_phys_ids. Both multiplied together results in the
    number of cores.

  • If kern.smp.cores (FreeBSD) or hw.cpu_topology_* (DragonFly) is
    not available, use hw.ncpu instead.

  • For example on FreeBSD 12.2p3 running a i7-8565U:

    sysctl hw.ncpu # => 8
    sysctl kern.smp.cores # => 4

  • For example on DragonFly 5.9-DEVELOPMENT with Xeon E5-1620:

    sysctl hw.ncpu # => 8
    sysctl hw.cpu_topology_phys_ids # => 1
    sysctl hw.cpu_topology_core_ids # => 4
    sysctl hw.cpu_topology_ht_ids # => 2

  • I found this by running a HTTP benchmark on a FreeBSD system
    (i7-8565U, 4 cores / 8 logical CPUs), where setting --ponymaxthreads=4
    improved latency significantly over the default value "8" (hw.ncpu).
    And I was wondering why I could set --ponymaxthreads to 8, even so the
    documentation explicitly states that it cannot be set to anything
    above the number of CPU cores.

* On both FreeBSD and DragonFly, `sysctl hw.ncpu` returns the number of
  logical CPUs, NOT the number of physical CPU cores.

* FreeBSD has sysctl `kern.smp.cores`.

* DragonFly has sysctl's `hw.cpu_topology_core_ids` and
  `hw.cpu_topology_phys_ids`. Both multiplied together results in the
  number of cores.

* If `kern.smp.cores` (FreeBSD) or `hw.cpu_topology_*` (DragonFly) is
  not available, use `hw.ncpu` instead.

* For example on FreeBSD 12.2p3 running a i7-8565U:

  sysctl hw.ncpu # => 8
  sysctl kern.smp.cores # => 4

* For example on DragonFly 5.9-DEVELOPMENT with Xeon E5-1620:

  sysctl hw.ncpu # => 8
  sysctl hw.cpu_topology_phys_ids # => 1
  sysctl hw.cpu_topology_core_ids # => 4
  sysctl hw.cpu_topology_ht_ids   # => 2

* I found this by running a HTTP benchmark on a FreeBSD system
  (i7-8565U, 4 cores / 8 logical CPUs), where setting --ponymaxthreads=4
  improved latency significantly over the default value "8" (hw.ncpu).
  And I was wondering why I could set --ponymaxthreads to 8, even so the
  documentation explicitly states that it cannot be set to anything
  above the number of CPU cores.
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Feb 6, 2021
@ponylang-main
Copy link
Contributor

Hi @mneumann,

The changelog - fixed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 3707.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

@mneumann
Copy link
Contributor Author

mneumann commented Feb 6, 2021

@ponylang-main I added an entry in .release-notes. Thanks!

@SeanTAllen
Copy link
Member

Thanks @mneumann. This will go out in the next ponyc release at the end of the month.

@SeanTAllen SeanTAllen merged commit 7e7c263 into ponylang:master Feb 6, 2021
github-actions bot pushed a commit that referenced this pull request Feb 6, 2021
github-actions bot pushed a commit that referenced this pull request Feb 6, 2021
@mneumann mneumann deleted the fix-number-of-cores-freebsd-dragonfly branch February 7, 2021 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants