-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client/fingerprint: correctly fingerprint E/P cores of Apple Silicon …
…chips This PR adds detection of asymetric core types (Power & Efficiency) (P/E) when running on M1/M2 Apple Silicon CPUs. This functionality is provided by shoenig/go-m1cpu which makes use of the Apple IOKit framework to read undocumented registers containing CPU performance data. Currently working on getting that functionality merged upstream into gopsutil, but gopsutil would still not support detecting P vs E cores like this PR does. Also refactors the CPUFingerprinter code to handle the mixed core types, now setting power vs efficiency cpu attributes. For now the scheduler is still unaware of mixed core types - on Apple platforms tasks cannot reserve cores anyway so it doesn't matter, but at least now the total CPU shares available will be correct. Future work should include adding support for detecting P/E cores on the latest and upcoming Intel chips, where computation of total cpu shares is currently incorrect. For that, we should also include updating the scheduler to be core-type aware, so that tasks of resources.cores on Linux platforms can be assigned the correct number of CPU shares for the core type(s) they have been assigned. node attributes before cpu.arch = arm64 cpu.modelname = Apple M2 Pro cpu.numcores = 12 cpu.reservablecores = 0 cpu.totalcompute = 1000 node attributes after cpu.arch = arm64 cpu.frequency.efficiency = 2424 cpu.frequency.power = 3504 cpu.modelname = Apple M2 Pro cpu.numcores.efficiency = 4 cpu.numcores.power = 8 cpu.reservablecores = 0 cpu.totalcompute = 37728
- Loading branch information
Showing
14 changed files
with
294 additions
and
146 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//go:build darwin && arm64 && cgo | ||
|
||
package fingerprint | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/ci" | ||
"github.com/hashicorp/nomad/client/config" | ||
"github.com/hashicorp/nomad/helper/testlog" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
func TestCPUFingerprint_AppleSilicon(t *testing.T) { | ||
ci.Parallel(t) | ||
|
||
f := NewCPUFingerprint(testlog.HCLogger(t)) | ||
node := &structs.Node{Attributes: make(map[string]string)} | ||
|
||
request := &FingerprintRequest{Config: new(config.Config), Node: node} | ||
var response FingerprintResponse | ||
|
||
err := f.Fingerprint(request, &response) | ||
must.NoError(t, err) | ||
|
||
must.True(t, response.Detected) | ||
|
||
attributes := response.Attributes | ||
must.NotNil(t, attributes) | ||
must.MapContainsKey(t, attributes, "cpu.modelname") | ||
must.MapContainsKey(t, attributes, "cpu.numcores.power") | ||
must.MapContainsKey(t, attributes, "cpu.numcores.efficiency") | ||
must.MapContainsKey(t, attributes, "cpu.frequency.power") | ||
must.MapContainsKey(t, attributes, "cpu.frequency.efficiency") | ||
must.MapContainsKey(t, attributes, "cpu.totalcompute") | ||
must.Positive(t, response.Resources.CPU) | ||
must.Positive(t, response.NodeResources.Cpu.CpuShares) | ||
must.Positive(t, response.NodeResources.Cpu.SharesPerCore()) | ||
must.SliceEmpty(t, response.NodeResources.Cpu.ReservableCpuCores) | ||
|
||
// not included for mixed core types (that we can detect) | ||
must.MapNotContainsKey(t, attributes, "cpu.numcores") | ||
must.MapNotContainsKey(t, attributes, "cpu.frequency") | ||
} |
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
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
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
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
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
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
Oops, something went wrong.