-
Notifications
You must be signed in to change notification settings - Fork 450
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
Correctly count real vs. total vs. cores on darwin #672
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# | ||
# Author:: Nathan L Smith (<[email protected]>) | ||
# Author:: Tim Smith (<tsmith@limelight.com>) | ||
# Copyright:: Copyright (c) 2013 Opscode, Inc. | ||
# Author:: Tim Smith (<tsmith@chef.io>) | ||
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -22,8 +22,10 @@ | |
|
||
collect_data(:darwin) do | ||
cpu Mash.new | ||
so = shell_out("sysctl -n hw.physicalcpu") | ||
so = shell_out("sysctl -n hw.packages") | ||
cpu[:real] = so.stdout.to_i | ||
so = shell_out("sysctl -n hw.physicalcpu") | ||
cpu[:cores] = so.stdout.to_i | ||
so = shell_out("sysctl -n hw.logicalcpu") | ||
cpu[:total] = so.stdout.to_i | ||
so = shell_out("sysctl -n hw.cpufrequency") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# | ||
# Author:: Nathan L Smith (<[email protected]>) | ||
# Copyright:: Copyright (c) 2013 Opscode, Inc. | ||
# Copyright:: Copyright (c) 2013-2015 Chef Software, Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -23,6 +23,7 @@ | |
before(:each) do | ||
@plugin = get_plugin("darwin/cpu") | ||
allow(@plugin).to receive(:collect_os).and_return(:darwin) | ||
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.packages").and_return(mock_shell_out(0, "1", "")) | ||
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.physicalcpu").and_return(mock_shell_out(0, "4", "")) | ||
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.logicalcpu").and_return(mock_shell_out(0, "8", "")) | ||
allow(@plugin).to receive(:shell_out).with("sysctl -n hw.cpufrequency").and_return(mock_shell_out(0, "2300000000", "")) | ||
|
@@ -35,12 +36,16 @@ | |
@plugin.run | ||
end | ||
|
||
it "should set cpu[:cores] to 4" do | ||
expect(@plugin[:cpu][:cores]).to eq(4) | ||
end | ||
|
||
it "should set cpu[:total] to 8" do | ||
expect(@plugin[:cpu][:total]).to eq(8) | ||
end | ||
|
||
it "should set cpu[:real] to 4" do | ||
expect(@plugin[:cpu][:real]).to eq(4) | ||
it "should set cpu[:real] to 1" do | ||
expect(@plugin[:cpu][:real]).to eq(1) | ||
end | ||
|
||
it "should set cpu[:mhz] to 2300" do | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, this is confusing. at first glance it seems backwards from what i'd expect.
"cores" should be physical cores -- i would expect '4' here
"total" should be the logical cores things like the scheduler sees - i would expect '8' here
"real" should be how many packages i have plugged into the motherboard - i would expect '1' here
i haven't looked at how we define these on linux or what the APIs return on darwin, but your cores and total read backwards from what i would expect.
(and definitely include some comments if things really need to be confusing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked the darwin APIs and they're the way i assumed they be from the names... so the only remaining question is if our ohai APIs are backwards from what i think they should mean...