RFC: Adding a hw.features[2] sysctl

Igor Mozolevsky igor at hybrid-lab.co.uk
Mon Jan 14 01:35:36 PST 2008

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 :-)


More information about the freebsd-current mailing list