Re: RFC: Adding a hw.features[2] sysctl

From: Igor Mozolevsky <igor_at_hybrid-lab.co.uk>
Date: Mon, 14 Jan 2008 09:35:32 +0000
On 14/01/2008, Nathan Lay <nslay_at_comcast.net> wrote:

> Yes, but suppose a program needs to make these queries more than
> once...for whatever reason?  For example, a closed source math code
> might need to figure out which version of a function to execute at run
> time based on available CPU features.  It will likely have to issue
> these ioctl() calls more than once (even with OR).
>
> For example:
>
> if ( ioctl( fd, CINFOCTL_HAS_FEATURES, <OR'd features> ) )
> LU_factor_<features>( ... );
> else if ( ioctl( fd, CINFOCTL_HAS_FEATURES, <other OR'd features> ) )
> LU_factor_<other features>( ... );
> etc...
>
> If the ioctl returns a bitmask with all available CPU features, then
> only one ioctl() call is needed.  The features can easily be queried
> from the bitmask.  One can make it even easier and more readable by
> making a macro like FD_ISSET to do such queries.
>
> A rough example:
>
> cpu_features_t mask;
>
> fd = open( "/dev/cpuinfo", O_RDONLY );
> ioctl( fd, SIOCGCPUFEATURES, (caddr_t)&mask );
> close( fd );
>
> if ( CPU_HAS_FEATURES(mask, CPU_SSE|CPU_SSE2) ) { ... }
> ...
> if ( CPU_HAS_FEATURES(mask, ... ) ) ...
>
> Or something like that

Your example is good if you want to query the features more than once,
but if you're only doing it once there's not reason not to ioctl for a
specific feature. Bare in mind that all of this *should* only be done
once at the start-time. I'm all up for your idea, don't get me wrong,
but I don't like having the developers' choice limited by system's
designers. Although, a huge API is not helping anyone either :-)


Igor
Received on Mon Jan 14 2008 - 08:35:36 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:25 UTC