From toasty@armada.dragondata.com  Sat Apr 22 01:14:15 2000
Return-Path: <toasty@armada.dragondata.com>
Received: from armada.dragondata.com (armada.dragondata.com [204.137.237.4])
	by hub.freebsd.org (Postfix) with ESMTP id B3BBB37B711
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 22 Apr 2000 01:14:14 -0700 (PDT)
	(envelope-from toasty@armada.dragondata.com)
Received: (from root@localhost)
	by armada.dragondata.com (8.9.3/8.9.3) id DAA00359;
	Sat, 22 Apr 2000 03:13:16 -0500 (CDT)
	(envelope-from toasty)
Message-Id: <200004220813.DAA00359@armada.dragondata.com>
Date: Sat, 22 Apr 2000 03:13:16 -0500 (CDT)
From: toasty@dragondata.com
Sender: toasty@armada.dragondata.com
Reply-To: toasty@dragondata.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] Add cpu class and features flags sysctls
X-Send-Pr-Version: 3.2

>Number:         18154
>Category:       i386
>Synopsis:       [sysctl] [patch] Add cpu class and features flags sysctls
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 22 01:20:01 PDT 2000
>Closed-Date:    Mon Sep 11 10:07:05 GMT 2006
>Last-Modified:  Mon Sep 11 10:07:05 GMT 2006
>Originator:     Kevin Day
>Release:        FreeBSD 4.0-TOUCHMASTER-RELEASE i386
>Organization:
DragonData Internet Services
>Environment:


>Description:

Add the following sysctls:

hw.cpuclass  (defines are in <machine/cpuclass.h>)
hw.features.mmx
hw.features.3dnow
hw.features.simd


These are useful in deciding what library to use at runtime, when choosing
between C/x86 or plain x86/mmx/simd functions, without having knowledge of
anything CPU related.


Also, fixed a misplaced comment in identcpu.c


>How-To-Repeat:

>Fix:

diff --exclude=*compile* -r -u sys-orig/i386/i386/identcpu.c sys/i386/i386/identcpu.c
--- sys-orig/i386/i386/identcpu.c	Sat Jan 29 01:49:02 2000
+++ sys/i386/i386/identcpu.c	Sat Apr 22 02:23:16 2000
@@ -78,6 +78,9 @@
 
 u_int	cyrix_did;		/* Device ID of Cyrix CPU */
 int cpu_class = CPUCLASS_386;	/* least common denominator */
+SYSCTL_INT(_hw, HW_CPUCLASS, cpu_class, CTLFLAG_RD,
+    &cpu_class, 0, "CPU class");
+
 char machine[] = "i386";
 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, 
     machine, 0, "Machine class");
@@ -86,6 +89,23 @@
 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, 
     cpu_model, 0, "Machine model");
 
+SYSCTL_NODE(_hw, OID_AUTO,  features,  CTLFLAG_RW, 0,
+        "CPU features");
+
+int featuresmmx;
+SYSCTL_INT(_hw_features, OID_AUTO, mmx, CTLFLAG_RD,
+    &featuresmmx, 0, "MMX Support");
+
+int features3dnow;
+SYSCTL_INT(_hw_features, OID_AUTO, 3dnow, CTLFLAG_RD,
+    &features3dnow, 0, "3DNow! Support");
+
+int featuressimd;
+SYSCTL_INT(_hw_features, OID_AUTO, simd, CTLFLAG_RD,
+    &featuressimd, 0, "SIMD Support");
+
+        
+        
 static struct cpu_nameclass i386_cpus[] = {
 	{ "Intel 80286",	CPUCLASS_286 },		/* CPU_286   */
 	{ "i386SX",		CPUCLASS_386 },		/* CPU_386SX */
@@ -580,6 +600,10 @@
 			"\037<b30>"
 			"\040<b31>"
 			);
+			if (cpu_feature & 0x800000)
+			    featuresmmx = 1;
+			if (cpu_feature & 0x2000000)
+			    features3dnow = 1;	
 		}
 		if (strcmp(cpu_vendor, "AuthenticAMD") == 0 &&
 		    nreg >= 0x80000001)
@@ -987,7 +1011,9 @@
 		"\034<b27>"
 		"\035<b28>"
 		"\036<b29>"
-		"\037DSP"	/* AMD 3DNow! Instruction Extensions */
-		"\0403DNow!"
+		"\037DSP"
+		"\0403DNow!"	/* AMD 3DNow! Instruction Extensions */
 		);
+		if (regs[3] & 0x80000000)
+		    features3dnow = 1;
 }
diff --exclude=*compile* -r -u sys-orig/sys/sysctl.h sys/sys/sysctl.h
--- sys-orig/sys/sysctl.h	Thu Feb 10 12:51:58 2000
+++ sys/sys/sysctl.h	Sat Apr 22 02:29:57 2000
@@ -346,7 +346,8 @@
 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
 #define	HW_FLOATINGPT	10		/* int: has HW floating point? */
 #define	HW_MACHINE_ARCH	11		/* string: machine architecture */
-#define	HW_MAXID	12		/* number of valid hw ids */
+#define	HW_CPUCLASS	12		/* int: class of cpu <machine/cpuclass.h> */
+#define	HW_MAXID	13		/* number of valid hw ids */
 
 #define CTL_HW_NAMES { \
 	{ 0, 0 }, \
@@ -360,6 +361,8 @@
 	{ "disknames", CTLTYPE_STRUCT }, \
 	{ "diskstats", CTLTYPE_STRUCT }, \
 	{ "floatingpoint", CTLTYPE_INT }, \
+	{ "machinearch", CTLTYPE_STRING }, \
+	{ "cpuclass", CTLTYPE_INT }, \
 }
 
 /*

>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: toasty@dragondata.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: i386/18154: [PATCH] Add cpu class and features flags sysctls
Date: Sat, 22 Apr 2000 10:22:43 -0400 (EDT)

 <<On Sat, 22 Apr 2000 03:13:16 -0500 (CDT), toasty@dragondata.com said:
 
 > hw.features.mmx
 > hw.features.3dnow
 
 Sine these features are unlikely to be shared by other architectures
 FreeBSD runs on, they should be in the machdep.* branch and not hw.
 
 -GAWollman
 
 

From: Kevin Day <toasty@dragondata.com>
To: wollman@khavrinen.lcs.mit.edu (Garrett Wollman)
Cc: toasty@dragondata.com, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: i386/18154: [PATCH] Add cpu class and features flags sysctls
Date: Sat, 22 Apr 2000 10:15:03 -0500 (CDT)

 > > hw.features.mmx
 > > hw.features.3dnow
 > 
 > Sine these features are unlikely to be shared by other architectures
 > FreeBSD runs on, they should be in the machdep.* branch and not hw.
 > 
 > -GAWollman
 > 
 > 
 
 Ok, I wasn't quite sure where the line was drawn. My thoughts there could be
 a hw.features node for all architectures, and what was under it could vary.
 But, I see the the argument either way. Doesn't really matter to me. :)
 
 -- Kevin
 
State-Changed-From-To: open->feedback 
State-Changed-By: remko 
State-Changed-When: Tue Sep 5 10:57:15 UTC 2006 
State-Changed-Why:  
Is this still an ongoing item? It had been a long time since 
the PR got filed and someone responded.  Thanks for letting 
me know in advance! 


Responsible-Changed-From-To: freebsd-i386->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Tue Sep 5 10:57:15 UTC 2006 
Responsible-Changed-Why:  
Grab the PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18154 
State-Changed-From-To: feedback->closed 
State-Changed-By: remko 
State-Changed-When: Mon Sep 11 10:07:04 UTC 2006 
State-Changed-Why:  
feedback timeout 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18154 
>Unformatted:
