Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jan 2008 09:35:32 +0000
From:      "Igor Mozolevsky" <igor@hybrid-lab.co.uk>
To:        "Nathan Lay" <nslay@comcast.net>
Cc:        Kostik Belousov <kostikbel@gmail.com>, Peter Jeremy <peterjeremy@optushome.com.au>, Joe Marcus Clarke <marcus@freebsd.org>, current <current@freebsd.org>
Subject:   Re: RFC: Adding a hw.features[2] sysctl
Message-ID:  <a2b6592c0801140135u60225eddn255a8c0459c12c3e@mail.gmail.com>
In-Reply-To: <478AE0B0.6000505@comcast.net>
References:  <1200197787.67286.13.camel@shumai.marcuscom.com> <20080113064450.GW57756@deviant.kiev.zoral.com.ua> <20080113182457.GN929@server.vk2pj.dyndns.org> <a2b6592c0801131721w25afae5bg3dcf6a90c1a3d2b7@mail.gmail.com> <478AC1F0.10500@comcast.net> <a2b6592c0801131814m353cca38xc26a8bc508fd0778@mail.gmail.com> <478AE0B0.6000505@comcast.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On 14/01/2008, Nathan Lay <nslay@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a2b6592c0801140135u60225eddn255a8c0459c12c3e>