Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2006



Tip: Looking for answers? Try searching our database.

Determine processor information at runtime...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lefty Bigfoot - 22 Dec 2006 18:44 GMT
How would you determine the CPU type/model information?

If you use things like preprocessor macros (__ppc__, __ppc64__,
etc.) it tells you what compiler options were used, not what's
really there.  If you compile generically on a G5 for example,
it'll tell you it's a 32-bit PPC using this method (broken).

Independent of compiler options, I'd like to know if the
underlying hardware is PPC32, PPC64, IA32, or X86-64 (down the
road).  Something analogous to the Intel CPUID instruction
perhaps?  

Is there a way to determine this with some sort of
platform-dependent sysinfo/sysctl call, or another method?

Google hasn't seen fit to give me a good answer yet, or I
haven't punched in the right search keys.

Also, the sysctl HW_NCPU will tell you the number of CPUs, but
doesn't appear to have a way of telling you if they are
physical, multicore, hyperthreaded, etc.  

Signature

Lefty
All of God's creatures have a place..........
.........right next to the potatoes and gravy.
See also: http://www.gizmodo.com/gadgets/images/iProduct.gif

Gregory Weston - 23 Dec 2006 02:25 GMT
> How would you determine the CPU type/model information?
>
[quoted text clipped - 7 lines]
> road).  Something analogous to the Intel CPUID instruction
> perhaps?  

There's the Mac OS Gestalt() function, an in particular the
gestaltNativeCPUtype selector.

This kind of thing should really only be used for informational
purposes, though. If you're planning on using it as a code path
selector, it's best to find some means to look for whether the
functionality you're looking for is specifically there instead of
inferring one way or the other based on the CPU.

Signature

The best intentions in the world don't make a flawed argument magically valid.

Lefty Bigfoot - 23 Dec 2006 20:49 GMT
Gregory Weston wrote
(in article
<uce-1D1078.21251922122006@comcast.dca.giganews.com>):

>> How would you determine the CPU type/model information?
>>
[quoted text clipped - 10 lines]
> There's the Mac OS Gestalt() function, an in particular the
> gestaltNativeCPUtype selector.

Digging further, it looks like the sysctl() stuff is the most
direct way of getting at all this information.  AIUI, Gestalt()
is just a more convulated way to get to the same basic data, as
provided via sysctl -a from the command line.

> This kind of thing should really only be used for informational
> purposes, though.

Yes, I am writing code specifically to determine the underlying
hardware platform, for informational purposes.

Signature

Lefty
All of God's creatures have a place..........
.........right next to the potatoes and gravy.
See also: http://www.gizmodo.com/gadgets/images/iProduct.gif

Gregory Weston - 24 Dec 2006 01:49 GMT
> >> Independent of compiler options, I'd like to know if the
> >> underlying hardware is PPC32, PPC64, IA32, or X86-64 (down the
[quoted text clipped - 8 lines]
> is just a more convulated way to get to the same basic data, as
> provided via sysctl -a from the command line.

There's some overlap between what can be determined via Gestalt and by
sysctl, but there's a LOT that Gestalt can tell you that sysctl can't
and I _think_ some in the other direction as well. For your particular
question I don't consider Gestalt to be more or less convoluted than
sysctl.

G

Signature

The best intentions in the world don't make a flawed argument magically valid.

David C. - 26 Dec 2006 17:38 GMT
> There's some overlap between what can be determined via Gestalt and by
> sysctl, but there's a LOT that Gestalt can tell you that sysctl can't
> and I _think_ some in the other direction as well. For your particular
> question I don't consider Gestalt to be more or less convoluted than
> sysctl.

Also, note that Gestalt is the preferred MacOS API for this.

sysctl() is the UNIX method, but it is far from portable.  The sysctl()
parameter names used by Mac OS are different from the ones used on (for
example) Linux, Solaris, HP-UX, etc.

On some operating systems, they even vary across different revisions of
the kernel.  (For example, Linux's sysctl() parameters have changed
quite a bit moving from the 2.0 to 2.2 to 2.4 to 2.6 kernels.)

In other words, code that uses sysctl will not be portable to other UNIX
systems, so you really gain nothing over using the Mac OS APIs (that is,
Gestalt).

And Gestalt should be backward-compatible with most earlier versions of
Mac OS (I think it was first introduced in System 7.)

-- David
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.