i386/85656: [Fwd: [patch] expose more i386 specific CPU information]

Ben Thomas bthomas at virtualiron.com
Fri Sep 2 18:00:41 GMT 2005


>Number:         85656
>Category:       i386
>Synopsis:       [patch] expose more i386 specific CPU information
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-i386
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 02 18:00:37 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Ben Thomas
>Release:        FreeBSD 5.4-RELEASE i386
>Organization:
Virtual Iron Software
>Environment:
System: FreeBSD bthomas4.katana-technology.com 5.4-RELEASE FreeBSD 5.4-RELEASE #10: Sun Aug 28 13:48:00 EDT 2005 ben at bthomas4.katana-technology.com:/usr/obj/usr/home/ben/BSD/RELENG_5_4_0_RELEASE/src/sys/BEN i386


>Description:

Add some i386 specific information and make a lot of it available
to user programs via sysctl.  We've had this change in our kernels
for some time.  Some appears to have moved into the 6.0 code, but
for what it's worth, here's the entire suggested change:

- add cpu extended features capture and output during boot

- add sysctls to expose a number of i386 information:
      hw.cpu_type
      hw.cpu_feature
      hw.cpu_efeature
      hw.cpu_high
      hw.cpu_id
      hw.cpu_procinfo
      hw.cpu_brand

This patch is against the 5_4_0_RELEASE code


>How-To-Repeat:
>Fix:

	


--- initcpu.c-DIFF begins here ---
--- /usr/src.original/sys/i386/i386/initcpu.c	Mon Nov 10 10:48:30 2003
+++ /usr/src/sys/i386/i386/initcpu.c	Fri Aug 12 17:36:30 2005
@@ -79,6 +79,7 @@
 /* Must *NOT* be BSS or locore will bzero these after setting them */
 int	cpu = 0;		/* Are we 386, 386sx, 486, etc? */
 u_int	cpu_feature = 0;	/* Feature flags */
+u_int	cpu_efeature = 0;	/* Extended feature flag */
 u_int	cpu_high = 0;		/* Highest arg to CPUID */
 u_int	cpu_id = 0;		/* Stepping ID */
 u_int	cpu_procinfo = 0;	/* HyperThreading Info / Brand Index / CLFUSH */
@@ -87,6 +88,13 @@
 #ifdef CPU_ENABLE_SSE
 u_int	cpu_fxsr;		/* SSE enabled */
 #endif
+
+SYSCTL_INT (_hw, OID_AUTO, cpu_type,     CTLFLAG_RD, &cpu, 0, "CPU type");
+SYSCTL_UINT(_hw, OID_AUTO, cpu_feature,  CTLFLAG_RD, &cpu_feature, 0, "CPU features");
+SYSCTL_UINT(_hw, OID_AUTO, cpu_efeature, CTLFLAG_RD, &cpu_efeature, 0, "CPU extended features");
+SYSCTL_UINT(_hw, OID_AUTO, cpu_high,     CTLFLAG_RD, &cpu_high, 0, "CPU high CPUID index");
+SYSCTL_UINT(_hw, OID_AUTO, cpu_id,       CTLFLAG_RD, &cpu_id, 0, "CPU id");
+SYSCTL_UINT(_hw, OID_AUTO, cpu_procinfo, CTLFLAG_RD, &cpu_procinfo, 0, "CPU processor information");
 
 #ifdef I486_CPU
 /*
--- initcpu.c-DIFF ends here ---

--- md_var.h-DIFF begins here ---
--- /usr/src.original/sys/i386/include/md_var.h	Thu Jun 10 16:30:58 2004
+++ /usr/src/sys/i386/include/md_var.h	Fri Aug 12 17:32:43 2005
@@ -46,6 +46,7 @@
 extern	int	busdma_swi_pending;
 extern	u_int	cpu_exthigh;
 extern	u_int	cpu_feature;
+extern	u_int	cpu_efeature;
 extern	u_int	cpu_fxsr;
 extern	u_int	cpu_high;
 extern	u_int	cpu_id;
--- md_var.h-DIFF ends here ---

--- identcpu.c-DIFF begins here ---
--- /usr/src.original/sys/i386/i386/identcpu.c	Thu Jun  3 17:14:53 2004
+++ /usr/src/sys/i386/i386/identcpu.c	Fri Aug 12 17:33:47 2005
@@ -100,6 +100,7 @@
 
 #if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
 static char cpu_brand[48];
+SYSCTL_STRING(_hw, OID_AUTO, cpu_brand, CTLFLAG_RD, cpu_brand, 0, "CPU brand");
 
 #define	MAX_BRAND_INDEX	8
 
@@ -690,6 +691,16 @@
 			"\036TM"	/* Thermal Monitor clock slowdown */
 			"\037IA64"	/* CPU can execute IA64 instructions */
 			"\040PBE"	/* Pending Break Enable */
+			);
+
+			printf("\n  Extended features=0x%b", cpu_efeature,
+			"\020"
+			"\001PNI"   /* Prescott new instructions */
+			"\004MMW"   /* MONITOR/MWAIT instruction */
+			"\005DSCPL" /* CPL-qualified debug store */
+			"\010EST"   /* Enhanced SpeedStep */
+			"\011TM2"   /* Thermal Monitor 2 */
+			"\013L1CXT" /* L1 Context ID */
 			);
 
 			/*
--- identcpu.c-DIFF ends here ---

--- locore.s-DIFF begins here ---
--- /usr/src.original/sys/i386/i386/locore.s	Fri Feb  4 20:01:40 2005
+++ /usr/src/sys/i386/i386/locore.s	Fri Aug 12 17:32:52 2005
@@ -680,6 +680,7 @@
 	cpuid					# cpuid 1
 	movl	%eax,R(cpu_id)			# store cpu_id
 	movl	%ebx,R(cpu_procinfo)		# store cpu_procinfo
+	movl	%ecx,R(cpu_efeature)		# store cpu extended features
 	movl	%edx,R(cpu_feature)		# store cpu_feature
 	rorl	$8,%eax				# extract family type
 	andl	$15,%eax
--- locore.s-DIFF ends here ---

--- specialreg.h-DIFF begins here ---
--- /usr/src.original/sys/i386/include/specialreg.h	Wed Apr  7 16:46:05 2004
+++ /usr/src/sys/i386/include/specialreg.h	Fri Aug 12 17:35:01 2005
@@ -108,6 +108,16 @@
 #define	CPUID_PBE	0x80000000
 
 /*
+ * CPUID instruction extended features register
+ */
+#define	CPUID_PNI   0x00000001  /* Prescott new instructions */
+#define	CPUID_MMW   0x00000008  /* MONITOR/MWAIT instruction */
+#define CPUID_DSCPL 0x00000010  /* CPL-qualified debug store */
+#define CPUID_EST   0x00000080  /* Enhanced SpeedStep */
+#define CPUID_TM2   0x00000100  /* Thermal Monitor 2 */
+#define CPUID_L1CXT 0x00000400  /* L1 Context ID */
+
+/*
  * CPUID instruction 1 ebx info
  */
 #define	CPUID_BRAND_INDEX	0x000000ff
--- specialreg.h-DIFF ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-i386 mailing list