Date: Sat, 22 Apr 2000 03:13:16 -0500 (CDT) From: toasty@dragondata.com To: FreeBSD-gnats-submit@freebsd.org Subject: i386/18154: [PATCH] Add cpu class and features flags sysctls Message-ID: <200004220813.DAA00359@armada.dragondata.com>
next in thread | raw e-mail | index | archive | help
>Number: 18154
>Category: i386
>Synopsis: [PATCH] Add cpu class and features flags sysctls
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat Apr 22 01:20:01 PDT 2000
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004220813.DAA00359>
