From owner-freebsd-current@FreeBSD.ORG Mon Jan 14 09:35:36 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5A91016A418 for ; Mon, 14 Jan 2008 09:35:36 +0000 (UTC) (envelope-from mozolevsky@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by mx1.freebsd.org (Postfix) with ESMTP id 651F613C458 for ; Mon, 14 Jan 2008 09:35:34 +0000 (UTC) (envelope-from mozolevsky@gmail.com) Received: by ug-out-1314.google.com with SMTP id y2so1224199uge.37 for ; Mon, 14 Jan 2008 01:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=dhvot3unWCOr90iFf4korYmBLNHYi3KICrA4BrJ8ec8=; b=VbVMt0ts83RrsUfFuosP7evK4u837zUz/V45rvM9gM51RoKyapOFU0cccO70hOgbxmvGICsTR8m1s3u7eO6S9HofmvwKv+Weovd9iMj5UHz0FW7D4eX/6n03Uuu9xld5hV5zKf+18+CkveLWEfdABhbfmFmrEOpuGLzddqxuAao= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=UfBvbwxl4GOq30hkYUWFoG0VS9V4U7FF+SHsAsughXhH+nepsAIwW5WAtYIU4u6Y4ReCqJcJCt//mKc1PdBBYN2PmSMiQ93qg6waaCY7ie7dbwbXNE3eLr4RcBwiKO+XtLrdGvddsMKWZOclKJe5gVFZOmRgFMpJ/vGZfRW3l/o= Received: by 10.66.242.5 with SMTP id p5mr3777502ugh.4.1200303333112; Mon, 14 Jan 2008 01:35:33 -0800 (PST) Received: by 10.66.248.11 with HTTP; Mon, 14 Jan 2008 01:35:32 -0800 (PST) Message-ID: Date: Mon, 14 Jan 2008 09:35:32 +0000 From: "Igor Mozolevsky" Sender: mozolevsky@gmail.com To: "Nathan Lay" In-Reply-To: <478AE0B0.6000505@comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1200197787.67286.13.camel@shumai.marcuscom.com> <20080113064450.GW57756@deviant.kiev.zoral.com.ua> <20080113182457.GN929@server.vk2pj.dyndns.org> <478AC1F0.10500@comcast.net> <478AE0B0.6000505@comcast.net> X-Google-Sender-Auth: 0e9fee25923caeff Cc: Kostik Belousov , Peter Jeremy , Joe Marcus Clarke , current Subject: Re: RFC: Adding a hw.features[2] sysctl X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jan 2008 09:35:36 -0000 On 14/01/2008, Nathan Lay 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, ) ) > LU_factor_( ... ); > else if ( ioctl( fd, CINFOCTL_HAS_FEATURES, ) ) > LU_factor_( ... ); > 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