From owner-freebsd-hackers@FreeBSD.ORG Sun May 5 23:37:05 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C2E7EABE for ; Sun, 5 May 2013 23:37:05 +0000 (UTC) (envelope-from sbrabez@gmail.com) Received: from mail-wi0-x229.google.com (mail-wi0-x229.google.com [IPv6:2a00:1450:400c:c05::229]) by mx1.freebsd.org (Postfix) with ESMTP id 58DBB243 for ; Sun, 5 May 2013 23:37:05 +0000 (UTC) Received: by mail-wi0-f169.google.com with SMTP id h11so2195116wiv.0 for ; Sun, 05 May 2013 16:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=luSyUsX89WCfSVKFQTjm2xxvSIPBvuE8EB2txYq8VCg=; b=X62npEWc1cZwOSETvpYTay+rYQMuL5fFx+gvi0FsBIr+5YxkXmLMLG0ZkcTd8UlGyN LdyupI/qhQKb6O13YcKg/vvI2GSUhucW/zMLAcqHzwSRheKexdSA+RQk0JDhgp4nDrvr u3rOA+QdL532xb0sh8KiYdbZR6vQnOjNj4rVdUTLlUJCFdLPSQER7tdbGO4Ns1F8eSFk uYi3zNld8iHl0pQlDLjNgEVqr0uaNw8BWKP4BkDJJtR3CY1aaxJuPJY7ngT6e+V0v+Bk TGc0yM0RHSKyP68QU8+0TTH+IQjkt7KRhepWFjPJfS/lkDQc4yH+PKdANZy7pp0NmDeL lj0w== X-Received: by 10.180.104.197 with SMTP id gg5mr6055396wib.13.1367797024549; Sun, 05 May 2013 16:37:04 -0700 (PDT) Received: from ogoshi.int.nbs-system.com ([2a01:e35:2ee4:8db0:a11:96ff:fe8c:77ec]) by mx.google.com with ESMTPSA id m14sm10608254wij.9.2013.05.05.16.37.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 16:37:03 -0700 (PDT) Sender: Sofian Brabez Date: Mon, 6 May 2013 01:37:01 +0200 From: Sofian Brabez To: freebsd-hackers@FreeBSD.org Subject: [patch] export CPU physical and virtual address sizes in sysctl oids using do_cpuid Message-ID: <20130505233701.GA2957@ogoshi.int.nbs-system.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="24zk1gE8NUlDmwG9" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 May 2013 23:37:05 -0000 --24zk1gE8NUlDmwG9 Content-Type: multipart/mixed; boundary="h31gzZEtNLTqOjlF" Content-Disposition: inline --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This patch uses do_cpuid function to fetch CPU Physical and Virtual address= sizes and adds 2 new sysctl machine dependant OIDs (machdep.cpu_physical_address_= bits and machdep.cpu_virtual_address_bits). In order to retrieve the information, it calls do_cpuid by setting eax regi= ster to 0x80000008 value like referenced in chapter 5.2.7 in the CPUID specifica= tion [1] Apple, Inc. in xnu kernel do the same thing but they created a specific nod= e called 'machdep.cpu' to store CPU Vendor information, the sysctls are machdep.cpu.address_bits.virtual and machdep.cpu.address_bits.virtual. I really would like to see this patch in our operating system because it's a valuable information nowdays and should be provided like others. Thus, I would like advices to see if before to be imported it needs modific= ation to fit like Apple (i.e using a new sysctl node) or stay like that. Also, I profited of this changes to patch sys/modules/linprocfs in order to display the address sizes values in the output of /usr/compat/linux/proc/cp= uinfo like it's done in Linux procfs [2]. I filled a pr referenced as amd64/178357=A0[3]. My kernel was rebuilt witho= ut any problems in r250287 and it works as expected. You could find details here [4] and patch in attachment. Regards [1] http://www.intel.com/content/dam/www/public/us/en/documents/application= -notes/processor-identification-cpuid-instruction-note.pdf [2] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/ar= ch/x86/kernel/cpu/proc.c#n113 [3] http://www.freebsd.org/cgi/query-pr.cgi?pr=3D178357 [4] http://people.freebsd.org/~sbz/cpu/ -- Sofian Brabez --h31gzZEtNLTqOjlF Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="address_sizes.diff" Content-Transfer-Encoding: quoted-printable Index: amd64/amd64/identcpu.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- amd64/amd64/identcpu.c (revision 250287) +++ amd64/amd64/identcpu.c (working copy) @@ -109,6 +109,12 @@ SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,=20 &hw_clockrate, 0, "CPU instruction clock rate"); =20 +SYSCTL_UINT(_machdep, OID_AUTO, cpu_physical_address_bits, CTLFLAG_RD, + &cpu_pma_bits, 0, "CPU physical address bits"); + +SYSCTL_UINT(_machdep, OID_AUTO, cpu_virtual_address_bits, CTLFLAG_RD, + &cpu_vma_bits, 0, "CPU virtual address bits"); + static eventhandler_tag tsc_post_tag; =20 static char cpu_brand[48]; @@ -516,6 +522,16 @@ cpu_feature =3D regs[3]; cpu_feature2 =3D regs[2]; =20 + /* Intel CPUID Specification chapter 5.2.7=20 + * eax=3D0x80000008 + * */ + do_cpuid(0x80000008, regs); + + /* upper bits are virtual size */ + cpu_vma_bits =3D ((regs[0] >> 8) & 0xFF); + /* lower bits are physical size */ + cpu_pma_bits =3D (regs[0] & 0xFF); + /* * Clear "Limit CPUID Maxval" bit and get the largest standard CPUID * function number again if it is set from BIOS. It is necessary Index: amd64/amd64/initcpu.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- amd64/amd64/initcpu.c (revision 250287) +++ amd64/amd64/initcpu.c (working copy) @@ -66,10 +66,12 @@ u_int cpu_high; /* Highest arg to CPUID */ u_int cpu_exthigh; /* Highest arg to extended CPUID */ u_int cpu_id; /* Stepping ID */ +u_int cpu_pma_bits; /* CPU physical address bits */ u_int cpu_procinfo; /* HyperThreading Info / Brand Index / CLFUSH */ u_int cpu_procinfo2; /* Multicore info */ char cpu_vendor[20]; /* CPU Origin code */ u_int cpu_vendor_id; /* CPU vendor ID */ +u_int cpu_vma_bits; /* CPU virtual address bits */ u_int cpu_fxsr; /* SSE enabled */ u_int cpu_mxcsr_mask; /* Valid bits in mxcsr */ u_int cpu_clflush_line_size =3D 32; Index: amd64/include/md_var.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- amd64/include/md_var.h (revision 250287) +++ amd64/include/md_var.h (working copy) @@ -54,10 +54,12 @@ extern u_int cpu_id; extern u_int cpu_max_ext_state_size; extern u_int cpu_mxcsr_mask; +extern u_int cpu_pma_bits; extern u_int cpu_procinfo; extern u_int cpu_procinfo2; extern char cpu_vendor[]; extern u_int cpu_vendor_id; +extern u_int cpu_vma_bits; extern char ctx_switch_xsave[]; extern char kstack[]; extern char sigcode[]; Index: compat/linprocfs/linprocfs.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- compat/linprocfs/linprocfs.c (revision 250287) +++ compat/linprocfs/linprocfs.c (working copy) @@ -310,6 +310,12 @@ fqmhz, fqkhz, fqmhz, fqkhz); } =20 + if (cpu_vma_bits !=3D 0 && cpu_vma_bits !=3D 0) { + sbuf_printf(sb, + "address sizes\t: %u bits physical, %u bits virtual\n", + cpu_pma_bits, cpu_vma_bits); + } + return (0); } #endif /* __i386__ || __amd64__ */ --h31gzZEtNLTqOjlF-- --24zk1gE8NUlDmwG9 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlGG7R0ACgkQc2NR9CSH5X7WEwCgp4LSWcm2LT/TL0+VQGX4466c M7oAnR+gZFM9keiZH59ThP3zq6/SQMV+ =lRyH -----END PGP SIGNATURE----- --24zk1gE8NUlDmwG9--