Re: Detecting CPU Speed
site_archiver@lists.apple.com Delivered-To: installer-dev@lists.apple.com Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-mailer; b=ngeV8Mo9Kk0SqAeH4FtyBHsTgu96IVrizPvdthUQs9F3N5VNE/5fZLAFH/J6PgyV4mn2Uu+2ZsXiBNEwieeI/zZ24lI1R8lXOnSA5bj2qtzFnM5jGQNyp2gTKZZHG9uXDzdq1FMNtg8Tw0ClAbfieT0/5ZCEFsCGOL3qo2BBx9o= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-mailer; b=e932KHOeovl48EMgWleG/xWff71siKUqVLE1RHBC9KmNtfVgkkD10bAGf9CHEfQjtv7eLxMFwrOYIu5uaWZi2QYAeT/XiVte14wRcfwWxK+pzYjXeG4G2PwF8lYAOrNqBHdIQHWJSjhP/dXbfQKmcFoXE0HoOG4ZaEskKsj4Pb0= sub CpuFrequency { ################################################################## # This should work on 10.2 and later: local $value = 0; local @hardware = `system_profiler SPHardwareDataType`; chomp @hardware; foreach ( @hardware ) { # Could say "CPU Speed" or "Processor Speed" # Speed value could contain a decimal or not # Hz could be prefixed with M, G or other if ( m/^\s*(?:CPU|Processor) Speed: (\d+\.*\d*)\s*([MGTPEZY])Hz/ ) { $value = $1; if ( $2 eq "M" ) { $value = $value * (10**6); } elsif ( $2 eq "G") { $value = $value * (10**9); } elsif ( $2 eq "T") { $value = $value * (10**12); } elsif ( $2 eq "P") { $value = $value * (10**15); } elsif ( $2 eq "E") { $value = $value * (10**18); } elsif ( $2 eq "Z") { $value = $value * (10**21); } elsif ( $2 eq "Y") { # We can dream about YHz in our code, right? $value = $value * (10**24); } } } if ( $value == 0 ) { # First method failed -- Get it the "right way" # NOTE: some G4 laptops report slower speed on pre-10.4 using this $value = `sysctl -n hw.cpufrequency`; $value; } return $value; } On Mar 27, 2007, at 3:25 PM, Gary Pederson wrote: sub CpuFrequency { ################################################################## # This should work on 10.2 and later: local $value = 0; local @hardware = `system_profiler SPHardwareDataType`; chomp @hardware; foreach ( @hardware ) { if ( m/^\s*CPU Speed: (\d+) ([MGTPEZY])Hz/ ) { $value = $1.$2; $value =~ s/M/000000/; $value =~ s/G/000000000/; $value =~ s/T/000000000000/; $value =~ s/P/000000000000000/; $value =~ s/E/000000000000000000/; $value =~ s/Z/000000000000000000000/; $value =~ s/Y/000000000000000000000000/; } } return $value; } On Mar 26, 2007, at 9:55 PM, Gary Pederson wrote: The incorrect values are from /usr/sbin/sysctl. On Mar 26, 2007, at 11:52 AM, Luke Bellandi wrote: Gary, On Mar 24, 2007, at 5:55 PM, Gary Pederson wrote: On those systems, sysctl returns hw.cpufrequency: 533333332 hw.cpufrequency_min: 533333332 hw.cpufrequency_max: 533333332 When it should report hw.cpufrequency: 867000000 hw.cpufrequency_min: 533333332 hw.cpufrequency_max: 867000000 - Luke Thanks, Gary Pederson _______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/installer-dev/luke%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/installer-dev/site_archiver%40lists.a... The previous code I posted did not work other systems. Here's an improved subroutine that seems to work on all systems: I tested it and "system_profiler SPHardwareDataType" works on G4 laptops pre-10.4. Here's the perl subroutine I'm using, if anyone else wonders into this (we can dream about YHz in out code, right?): In an earlier email, Daniel Soderberg suggested using the following command: system_profiler SPHardwareDataType | grep Speed I haven't gotten back to those systems to see if it works, but I'll post the results within a few days. I've been detecting CPU speed in my InstallationCheck scripts using `sysctl -n hw.cpufrequency` and `sysctl -n hw.cpufrequency_max` These are returning the correct values on most machines, but the wrong values on other machines (at least 867MHz G4 PowerBooks in 10.3.9) -- So some of our customers get a confusing message about their CPU being too slow. Are these values returned from your Javascript functions in your distribution, or are they the values returned from /usr/sbin/sysctl? If they're coming from your Javascript, check what /usr/sbin/sysctl is returning for that property and let us know if that's correct. Is there a way to accurately detect the maximum cpu speed on all OS X Macs? Or at least on the ones I need to support (G4, G5, x86 -- 10.3.9 and later)? This email sent to luke@apple.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Gary Pederson