From bthomas@virtualiron.com  Fri Sep  2 17:59:27 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 34FB316A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  2 Sep 2005 17:59:27 +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 CBDD643D45
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  2 Sep 2005 17:59:26 +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:02 -0400
Message-Id: <431892FE.5030302@virtualiron.com>
Date: Fri, 02 Sep 2005 13:59:26 -0400
From: Ben Thomas <bthomas@virtualiron.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] expose cpu info for i386 systems

>Number:         85655
>Category:       i386
>Synopsis:       [i386] [patch] expose cpu info for i386 systems
>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:36 GMT 2005
>Closed-Date:    
>Last-Modified:  Thu Jul  7 19:10:11 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:

This change makes some slight modifications:

- add "packed" attribute to the cpu_info structure to make it a bit smaller
- add the hyperthread index to the structure
- expose the entire structure via a machdep sysctl (I probably should have
  also added an .h file for the user/kernel to agree on the structure format)


This patch is against the 5_4_0_RELEASE code

>How-To-Repeat:
>Fix:

--- mp_machdep.c-DIFF begins here ---
--- /usr/src.original/sys/i386/i386/mp_machdep.c	Sun May  1 01:38:13 2005
+++ /usr/src/sys/i386/i386/mp_machdep.c	Fri Aug 12 17:29:11 2005
@@ -202,9 +202,12 @@
 	int	cpu_present:1;
 	int	cpu_bsp:1;
 	int	cpu_disabled:1;
-} static cpu_info[MAXCPU];
+	unsigned char	cpu_htt;
+} __attribute__((packed)) static cpu_info[MAXCPU];
 static int cpu_apic_ids[MAXCPU];
 
+SYSCTL_OPAQUE(_machdep, OID_AUTO, cpu_info, CTLFLAG_RD, &cpu_info, sizeof(cpu_info), "S,cpu_info", "CPU Information");
+
 /* Holds pending bitmap based IPIs per CPU */
 static volatile u_int cpu_ipi_pending[MAXCPU];
 
@@ -284,7 +287,8 @@
 void
 cpu_add(u_int apic_id, char boot_cpu)
 {
-
+	int	cores;
+	
 	if (apic_id >= MAXCPU) {
 		printf("SMP: CPU %d exceeds maximum CPU %d, ignoring\n",
 		    apic_id, MAXCPU - 1);
@@ -304,7 +308,12 @@
 	if (bootverbose)
 		printf("SMP: Added CPU %d (%s)\n", apic_id, boot_cpu ? "BSP" :
 		    "AP");
-	
+	if ((cpu_feature & CPUID_HTT) == 0)
+	  cores = 1;
+	else
+	  cores = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
+	  
+	cpu_info[apic_id].cpu_htt = apic_id % cores;	
 }
 
 void
--- mp_machdep.c-DIFF ends here ---
>Release-Note:
>Audit-Trail:
Adding to audit trail:

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

Is this still applicable? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85655 
Responsible-Changed-From-To: freebsd-i386->jhb 
Responsible-Changed-By: remko 
Responsible-Changed-When: Wed Mar 30 06:08:54 UTC 2011 
Responsible-Changed-Why:  
Hi John, is this something you might want to have a look at? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85655 

From: John Baldwin <jhb@freebsd.org>
To: bug-followup@freebsd.org,
 bthomas@virtualiron.com
Cc: Attilio Rao <attilio@freebsd.org>,
 Brooks Davis <brooks@freebsd.org>
Subject: Re: i386/85655: [i386] [patch] expose cpu info for i386 systems
Date: Thu, 7 Jul 2011 15:04:29 -0400

 I don't think we want to export cpu_info as raw data in this fashion.  I 
 believe we should be using an MI interface to export information about 
 available CPUs with info about cores/HTT/NUMA domains, etc.  Brooks is aware 
 of an existing API for this sort of thing and Attilio has shown interest in 
 this area in the past.
 
 -- 
 John Baldwin
>Unformatted:
