From bthomas@virtualiron.com  Fri Sep  2 17:59:45 2005
Return-Path: <bthomas@virtualiron.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 43CCB16A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  2 Sep 2005 17:59:45 +0000 (GMT)
	(envelope-from bthomas@virtualiron.com)
Received: from mail.virtualiron.com (mail.virtualiron.com [209.213.88.114])
	by mx1.FreeBSD.org (Postfix) with ESMTP id CD40E43D45
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  2 Sep 2005 17:59:44 +0000 (GMT)
	(envelope-from bthomas@virtualiron.com)
Received: from [10.1.2.26] ([10.1.2.26]) by mail.virtualiron.com with Microsoft SMTPSVC(6.0.3790.1830);
	 Fri, 2 Sep 2005 14:00:20 -0400
Message-Id: <43189310.2050803@virtualiron.com>
Date: Fri, 02 Sep 2005 13:59:44 -0400
From: Ben Thomas <bthomas@virtualiron.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [Fwd: [patch] expose more i386 specific CPU information]

>Number:         85656
>Category:       i386
>Synopsis:       [i386] [patch] expose more i386 specific CPU information
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          feedback
>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:  Wed Mar 30 06:09:48 UTC 2011
>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@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:

From: =?ISO-8859-1?Q?Bj=F6rn_K=F6nig?= <bkoenig@cs.tu-berlin.de>
To: Ben Thomas <bthomas@virtualiron.com>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: i386/85656: [Fwd: [patch] expose more i386 specific CPU information]
Date: Fri, 02 Sep 2005 21:12:10 +0200

 Ben Thomas wrote:
 
 > - 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
 > 
 > [...]
 
 It might be better to use
 
        hw.cpu.type
        hw.cpu.feature
        hw.cpu.efeature
        [...]
 
 instead. This allows you to see all CPU information by calling 'sysctl 
 hw.cpu'. A lot of oids in the format parent.foo_bar has been converted 
 to parent.foo.bar in past.
 
 Regards Bjrn
 

From: Ben Thomas <bthomas@virtualiron.com>
To: =?ISO-8859-1?Q?Bj=F6rn_K=F6nig?= <bkoenig@cs.tu-berlin.de>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: i386/85656: [Fwd: [patch] expose more i386 specific CPU information]
Date: Fri, 02 Sep 2005 15:22:39 -0400

 I completely agree.  It was a quick hack that we use locally and
 could easily be improved.   I considered changing this before
 I submitted the pr, but since it's taken me over a year to get
 around to submitting it at all, I decided to submit the current
 code that I use and not the better version.
 
 Thanks,
 -b
 
 
 Bjrn Knig wrote:
 > Ben Thomas wrote:
 > 
 >> - 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
 >>
 >> [...]
 > 
 > 
 > It might be better to use
 > 
 >       hw.cpu.type
 >       hw.cpu.feature
 >       hw.cpu.efeature
 >       [...]
 > 
 > instead. This allows you to see all CPU information by calling 'sysctl 
 > hw.cpu'. A lot of oids in the format parent.foo_bar has been converted 
 > to parent.foo.bar in past.
 > 
 > Regards Bjrn
 > 
 
 
 -- 
 ------------------------------------------------------------------------
 Ben Thomas                                         Virtual Iron Software
 bthomas@virtualiron.com                            43 Nagog Park
 978-849-1214                                       Acton, MA 01720

Adding to audit trail:

see also i386/85854 and i386/85655 from same author.
State-Changed-From-To: open->feedback 
State-Changed-By: remko 
State-Changed-When: Wed Mar 23 07:21:54 UTC 2011 
State-Changed-Why:  
Hello, 

Is this still applicable? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85656 
Responsible-Changed-From-To: freebsd-i386->jhb 
Responsible-Changed-By: remko 
Responsible-Changed-When: Wed Mar 30 06:09:19 UTC 2011 
Responsible-Changed-Why:  
Hi John, another one I would like to ask you to have a look at. 

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