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 macOS collection of CPU data #7429

Merged
merged 2 commits into from
Sep 25, 2019
Merged

Conversation

alexcrichton
Copy link
Member

@alexcrichton alexcrichton commented Sep 25, 2019

There's very little documentation on host_processor_info from what I can tell, so I'm just cribbing examples I've found elsewhere on the internet. Turns out two things were wrong:

  • One is that host_processor_info returns allocated memory we need to deallocate. Who knew!
  • Next is that one of the out parameters, cpu_info_cnt, is only somehow related to the size of the return, but all example code appears to just read data regardless of what it is.

In any case this commit reads libuv's implementation which if good enough for node.js is probably good enough for us.

Closes #7427

Apparently StackOverflow doesn't have all the answers. The examples
there I lifted this from didn't account to call `vm_deallocate` because
it looks like we're handed allocated memory! Indeed running the previous
state capture in a loop it infinitely allocated memory, but now it holds
steady when called in a loop.
There's very little documentation on `host_processor_info` from what I
can tell, so I'm just cribbing examples I've found elsewhere on the
internet. It appears that I've misinterpreted one of the out parameters
of `host_processor_info` as the number of elements of an array, but it
actually is just something forwarded to `vm_deallocate`.
@ehuss
Copy link
Contributor

ehuss commented Sep 25, 2019

Seems to match what I can find as well.

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 25, 2019

📌 Commit 0c812db has been approved by ehuss

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 25, 2019
bors added a commit that referenced this pull request Sep 25, 2019
Fix macOS collection of CPU data

There's very little documentation on `host_processor_info` from what I can tell, so I'm just cribbing examples I've found elsewhere on the internet. Turns out two things were wrong:

* One is that `host_processor_info` returns allocated memory we need to deallocate. Who knew!
* Next is that one of the out parameters, `cpu_info_cnt`, is only somehow related to the size of the return, but all example code appears to just read data regardless of what it is.

In any case this commit reads [libuv's implementation](https://github.com/libuv/libuv/blob/040543eebf4983b1459a1e0e0e26dae68b80cc28/src/unix/darwin.c#L174-L225) which if good enough for node.js is probably good enough for us.

Closes #7427
@bors
Copy link
Collaborator

bors commented Sep 25, 2019

⌛ Testing commit 0c812db with merge ab6fa89...

@bors
Copy link
Collaborator

bors commented Sep 25, 2019

☀️ Test successful - checks-azure
Approved by: ehuss
Pushing ab6fa89 to master...

@bors bors merged commit 0c812db into rust-lang:master Sep 25, 2019
@bors bors deleted the fix-osx-cpu branch September 25, 2019 17:26
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 25, 2019
4 commits in aa6b7e01abce30091cc594cb23a15c46cead6e24..ab6fa8908c9b6c8f7e2249231c395eebfbc49891
2019-09-24 17:19:12 +0000 to 2019-09-25 17:00:56 +0000
- Fix macOS collection of CPU data (rust-lang/cargo#7429)
- Don't ever capture CPU state if timings are disabled (rust-lang/cargo#7428)
- Change build-std to use --sysroot (rust-lang/cargo#7421)
- set -Zmtime_on_use from config or ENV (rust-lang/cargo#7411)
bors added a commit to rust-lang/rust that referenced this pull request Sep 25, 2019
Update cargo

4 commits in aa6b7e01abce30091cc594cb23a15c46cead6e24..ab6fa8908c9b6c8f7e2249231c395eebfbc49891
2019-09-24 17:19:12 +0000 to 2019-09-25 17:00:56 +0000
- Fix macOS collection of CPU data (rust-lang/cargo#7429)
- Don't ever capture CPU state if timings are disabled (rust-lang/cargo#7428)
- Change build-std to use --sysroot (rust-lang/cargo#7421)
- set -Zmtime_on_use from config or ENV (rust-lang/cargo#7411)
@HeroicKatora HeroicKatora mentioned this pull request Sep 25, 2019
4 tasks
@ehuss ehuss added this to the 1.40.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crash while downloading sources on osx: index out of bounds: the len is 2 but the index is 2 in cpu.rs
3 participants