diff options
| author | Franck Cuny <franck@fcuny.net> | 2024-12-29 14:20:05 -0800 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2024-12-29 14:23:09 -0800 |
| commit | 0e05e5601d069b15c07a29f7ff5371f8c15a0cc9 (patch) | |
| tree | bdd648a471b5fcbf1370fb10f5f9936cb10fb749 | |
| parent | Merge pull request #1 from fcuny/dependabot/cargo/thiserror-2.0.9 (diff) | |
| download | x-0e05e5601d069b15c07a29f7ff5371f8c15a0cc9.tar.gz | |
report the number of E cores and P cores
Report the CPU and GPU bandwidths for some of the M core models.
Diffstat (limited to '')
| -rw-r--r-- | src/apple_silicon/src/soc.rs | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/src/apple_silicon/src/soc.rs b/src/apple_silicon/src/soc.rs index 8db2e1f..9c761cc 100644 --- a/src/apple_silicon/src/soc.rs +++ b/src/apple_silicon/src/soc.rs @@ -24,9 +24,9 @@ pub struct SocInfo { /// Maximum GPU bandwidth in GB/s (if available) pub gpu_max_bw: Option<Bandwidth>, /// Number of efficiency cores - pub e_core_count: Option<CoreCount>, + pub e_core_count: CoreCount, /// Number of performance cores - pub p_core_count: Option<CoreCount>, + pub p_core_count: CoreCount, } #[derive(Debug, PartialEq)] @@ -48,6 +48,8 @@ enum AppleChip { struct ChipSpecs { cpu_tdp: Watts, gpu_tdp: Watts, + cpu_bw: Bandwidth, + gpu_bw: Bandwidth, } impl AppleChip { @@ -73,23 +75,51 @@ impl AppleChip { AppleChip::M1 => ChipSpecs { cpu_tdp: 20, gpu_tdp: 20, + cpu_bw: 70, + gpu_bw: 70, + }, + AppleChip::M1Pro => ChipSpecs { + cpu_tdp: 30, + gpu_tdp: 30, + cpu_bw: 200, + gpu_bw: 200, + }, + AppleChip::M1Max => ChipSpecs { + cpu_tdp: 30, + gpu_tdp: 60, + cpu_bw: 250, + gpu_bw: 400, + }, + AppleChip::M1Ultra => ChipSpecs { + cpu_tdp: 60, + gpu_tdp: 120, + cpu_bw: 500, + gpu_bw: 800, }, AppleChip::M2 => ChipSpecs { - cpu_tdp: 20, - gpu_tdp: 22, + cpu_tdp: 25, + gpu_tdp: 15, + cpu_bw: 100, + gpu_bw: 100, }, AppleChip::M2Pro => ChipSpecs { cpu_tdp: 30, gpu_tdp: 35, + cpu_bw: 0, + gpu_bw: 0, }, AppleChip::M2Max => ChipSpecs { cpu_tdp: 30, gpu_tdp: 40, + cpu_bw: 0, + gpu_bw: 0, }, // Add more variants as needed _ => ChipSpecs { cpu_tdp: 0, gpu_tdp: 0, + cpu_bw: 0, + gpu_bw: 0, }, } } @@ -97,7 +127,7 @@ impl AppleChip { impl SocInfo { pub fn new() -> Result<SocInfo> { - let (cpu_brand_name, num_cpu_cores) = cpu_info(&RealCommand)?; + let (cpu_brand_name, num_cpu_cores, e_core_count, p_core_count) = cpu_info(&RealCommand)?; let num_gpu_cores = gpu_info(&RealCommand)?; let chip = AppleChip::from_brand_string(&cpu_brand_name); @@ -109,10 +139,10 @@ impl SocInfo { num_gpu_cores, cpu_max_power: Some(specs.cpu_tdp), gpu_max_power: Some(specs.gpu_tdp), - cpu_max_bw: None, - gpu_max_bw: None, - e_core_count: None, - p_core_count: None, + cpu_max_bw: Some(specs.cpu_bw), + gpu_max_bw: Some(specs.gpu_bw), + e_core_count: e_core_count, + p_core_count: p_core_count, }) } } @@ -120,13 +150,15 @@ impl SocInfo { // https://github.com/tlkh/asitop/blob/74ebe2cbc23d5b1eec874aebb1b9bacfe0e670cd/asitop/utils.py#L94 const SYSCTL_PATH: &str = "/usr/sbin/sysctl"; -fn cpu_info(cmd: &impl SystemCommand) -> Result<(String, u16)> { +fn cpu_info(cmd: &impl SystemCommand) -> Result<(String, u16, u16, u16)> { let binary = SYSCTL_PATH; let args = &[ // don't display the variable name "-n", "machdep.cpu.brand_string", "machdep.cpu.core_count", + "hw.perflevel0.logicalcpu", + "hw.perflevel1.logicalcpu", ]; let output = cmd.execute(binary, args)?; @@ -143,7 +175,22 @@ fn cpu_info(cmd: &impl SystemCommand) -> Result<(String, u16)> { None => return Err(Error::Parse(buffer.to_string())), }; - Ok((cpu_brand_name, num_cpu_cores)) + let num_performance_cores = match iter.next() { + Some(s) => s.parse::<u16>()?, + None => return Err(Error::Parse(buffer.to_string())), + }; + + let num_efficiency_cores = match iter.next() { + Some(s) => s.parse::<u16>()?, + None => return Err(Error::Parse(buffer.to_string())), + }; + + Ok(( + cpu_brand_name, + num_cpu_cores, + num_performance_cores, + num_efficiency_cores, + )) } // https://github.com/tlkh/asitop/blob/74ebe2cbc23d5b1eec874aebb1b9bacfe0e670cd/asitop/utils.py#L120 @@ -223,14 +270,16 @@ mod tests { #[test] fn test_cpu_info_success() { - let mock_output = "Apple M2\n8\n"; + let mock_output = "Apple M2\n8\n4\n4\n"; let cmd = MockCommand::new(mock_output); let result = cpu_info(&cmd); assert!(result.is_ok()); - let (brand, cores) = result.unwrap(); + let (brand, cores, p_cores, e_cores) = result.unwrap(); assert_eq!(brand, "Apple M2"); assert_eq!(cores, 8); + assert_eq!(p_cores, 4); + assert_eq!(e_cores, 4); } #[test] |
