Tue Apr 14 17:15:02 2020 UTC ()
Pull up following revision(s) (requested by msaitoh in ticket #833):

	usr.sbin/cpuctl/arch/i386.c: revision 1.109
	sys/arch/x86/include/specialreg.h: revision 1.159
	usr.sbin/cpuctl/arch/i386.c: revision 1.110
	sys/arch/x86/include/specialreg.h: revision 1.160
	sys/arch/x86/include/specialreg.h: revision 1.161
	sys/arch/x86/x86/tsc.c: revision 1.40
	sys/arch/x86/x86/procfs_machdep.c: revision 1.35
	sys/arch/x86/x86/procfs_machdep.c: revision 1.36

  Add Fast Short Rep Mov(fsrm).

Add AVX512_VP2INTERSECT, SERIALIZE and TSXLDTRK(TSX suspend load addr tracking)

  CPUID Fn00000001 %edx bit 8 is printed as "TSC", so rename CPUID Fn8000_0007
%edx bit 8 from "TSC" to "ITSC" (Invariant TSC) to avoid confusion.

  Rename CPUID_APM_TSC to CPUID_APM_ITSC. No functional change.

  Remove ci_max_ext_cpuid because it's the same as ci_cpuid_extlevel.

  Print CPUID 0x80000007 %edx on both Intel and AMD.


(martin)
diff -r1.150.2.5 -r1.150.2.6 src/sys/arch/x86/include/specialreg.h
diff -r1.33.2.1 -r1.33.2.2 src/sys/arch/x86/x86/procfs_machdep.c
diff -r1.37 -r1.37.8.1 src/sys/arch/x86/x86/tsc.c
diff -r1.104.2.4 -r1.104.2.5 src/usr.sbin/cpuctl/arch/i386.c

cvs diff -r1.150.2.5 -r1.150.2.6 src/sys/arch/x86/include/specialreg.h (expand / switch to unified diff)

--- src/sys/arch/x86/include/specialreg.h 2019/11/19 13:15:57 1.150.2.5
+++ src/sys/arch/x86/include/specialreg.h 2020/04/14 17:15:02 1.150.2.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: specialreg.h,v 1.150.2.5 2019/11/19 13:15:57 martin Exp $ */ 1/* $NetBSD: specialreg.h,v 1.150.2.6 2020/04/14 17:15:02 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2014-2019 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014-2019 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -465,42 +465,46 @@ @@ -465,42 +465,46 @@
465 "b\0PREFETCHWT1\0" "b\1AVX512_VBMI\0" "b\2UMIP\0" "b\3PKU\0" \ 465 "b\0PREFETCHWT1\0" "b\1AVX512_VBMI\0" "b\2UMIP\0" "b\3PKU\0" \
466 "b\4OSPKE\0" "b\5WAITPKG\0" "b\6AVX512_VBMI2\0" "b\7CET_SS\0" \ 466 "b\4OSPKE\0" "b\5WAITPKG\0" "b\6AVX512_VBMI2\0" "b\7CET_SS\0" \
467 "b\10GFNI\0" "b\11VAES\0" "b\12VPCLMULQDQ\0" "b\13AVX512_VNNI\0"\ 467 "b\10GFNI\0" "b\11VAES\0" "b\12VPCLMULQDQ\0" "b\13AVX512_VNNI\0"\
468 "b\14AVX512_BITALG\0" "b\16AVX512_VPOPCNTDQ\0" \ 468 "b\14AVX512_BITALG\0" "b\16AVX512_VPOPCNTDQ\0" \
469 "f\21\5MAWAU\0" \ 469 "f\21\5MAWAU\0" \
470 "b\26RDPID\0" \ 470 "b\26RDPID\0" \
471 "b\31CLDEMOTE\0" "b\33MOVDIRI\0" \ 471 "b\31CLDEMOTE\0" "b\33MOVDIRI\0" \
472 "b\34MOVDIR64B\0" "b\36SGXLC\0" 472 "b\34MOVDIR64B\0" "b\36SGXLC\0"
473 473
474/* %edx */ 474/* %edx */
475#define CPUID_SEF_AVX512_4VNNIW __BIT(2) 475#define CPUID_SEF_AVX512_4VNNIW __BIT(2)
476#define CPUID_SEF_AVX512_4FMAPS __BIT(3) 476#define CPUID_SEF_AVX512_4FMAPS __BIT(3)
477#define CPUID_SEF_FSREP_MOV __BIT(4) /* Fast Short REP MOV */ 477#define CPUID_SEF_FSREP_MOV __BIT(4) /* Fast Short REP MOV */
 478#define CPUID_SEF_AVX512_VP2INTERSECT __BIT(8)
478#define CPUID_SEF_MD_CLEAR __BIT(10) 479#define CPUID_SEF_MD_CLEAR __BIT(10)
479#define CPUID_SEF_TSX_FORCE_ABORT __BIT(13) /* MSR_TSX_FORCE_ABORT bit 0 */ 480#define CPUID_SEF_TSX_FORCE_ABORT __BIT(13) /* MSR_TSX_FORCE_ABORT bit 0 */
 481#define CPUID_SEF_SERIALIZE __BIT(14)
480#define CPUID_SEF_HYBRID __BIT(15) /* Hybrid part */ 482#define CPUID_SEF_HYBRID __BIT(15) /* Hybrid part */
 483#define CPUID_SEF_TSXLDTRK __BIT(16) /* TSX suspend load addr tracking */
481#define CPUID_SEF_CET_IBT __BIT(20) /* CET Indirect Branch Tracking */ 484#define CPUID_SEF_CET_IBT __BIT(20) /* CET Indirect Branch Tracking */
482#define CPUID_SEF_IBRS __BIT(26) /* IBRS / IBPB Speculation Control */ 485#define CPUID_SEF_IBRS __BIT(26) /* IBRS / IBPB Speculation Control */
483#define CPUID_SEF_STIBP __BIT(27) /* STIBP Speculation Control */ 486#define CPUID_SEF_STIBP __BIT(27) /* STIBP Speculation Control */
484#define CPUID_SEF_L1D_FLUSH __BIT(28) /* IA32_FLUSH_CMD MSR */ 487#define CPUID_SEF_L1D_FLUSH __BIT(28) /* IA32_FLUSH_CMD MSR */
485#define CPUID_SEF_ARCH_CAP __BIT(29) /* IA32_ARCH_CAPABILITIES */ 488#define CPUID_SEF_ARCH_CAP __BIT(29) /* IA32_ARCH_CAPABILITIES */
486#define CPUID_SEF_CORE_CAP __BIT(30) /* IA32_CORE_CAPABILITIES */ 489#define CPUID_SEF_CORE_CAP __BIT(30) /* IA32_CORE_CAPABILITIES */
487#define CPUID_SEF_SSBD __BIT(31) /* Speculative Store Bypass Disable */ 490#define CPUID_SEF_SSBD __BIT(31) /* Speculative Store Bypass Disable */
488 491
489#define CPUID_SEF_FLAGS2 "\20" \ 492#define CPUID_SEF_FLAGS2 "\20" \
490 "\3" "AVX512_4VNNIW" "\4" "AVX512_4FMAPS" \ 493 "\3" "AVX512_4VNNIW" "\4" "AVX512_4FMAPS" \
491 "\5" "FSREP_MOV" \ 494 "\5" "FSREP_MOV" \
492 "\13" "MD_CLEAR" \ 495 "\11" "VP2INTERSECT" "\13" "MD_CLEAR" \
493 "\16" "TSX_FORCE_ABORT" "\20" "HYBRID" \ 496 "\16TSX_FORCE_ABORT" "\17SERIALIZE" "\20HYBRID" \
 497 "\21" "TSXLDTRK" \
494 "\25" "CET_IBT" \ 498 "\25" "CET_IBT" \
495 "\33" "IBRS" "\34" "STIBP" \ 499 "\33" "IBRS" "\34" "STIBP" \
496 "\35" "L1D_FLUSH" "\36" "ARCH_CAP" "\37CORE_CAP" "\40" "SSBD" 500 "\35" "L1D_FLUSH" "\36" "ARCH_CAP" "\37CORE_CAP" "\40" "SSBD"
497 501
498/* 502/*
499 * Intel CPUID Architectural Performance Monitoring Fn0000000a 503 * Intel CPUID Architectural Performance Monitoring Fn0000000a
500 * 504 *
501 * See also src/usr.sbin/tprof/arch/tprof_x86.c 505 * See also src/usr.sbin/tprof/arch/tprof_x86.c
502 */ 506 */
503 507
504/* %eax */ 508/* %eax */
505#define CPUID_PERF_VERSION __BITS(7, 0) /* Version ID */ 509#define CPUID_PERF_VERSION __BITS(7, 0) /* Version ID */
506#define CPUID_PERF_NGPPC __BITS(15, 8) /* Num of G.P. perf counter */ 510#define CPUID_PERF_NGPPC __BITS(15, 8) /* Num of G.P. perf counter */
@@ -683,49 +687,51 @@ @@ -683,49 +687,51 @@
683 687
684#define CPUID_AMD_FLAGS4 "\20" \ 688#define CPUID_AMD_FLAGS4 "\20" \
685 "\1" "LAHF" "\2" "CMPLEGACY" "\3" "SVM" "\4" "EAPIC" \ 689 "\1" "LAHF" "\2" "CMPLEGACY" "\3" "SVM" "\4" "EAPIC" \
686 "\5" "ALTMOVCR0" "\6" "LZCNT" "\7" "SSE4A" "\10" "MISALIGNSSE" \ 690 "\5" "ALTMOVCR0" "\6" "LZCNT" "\7" "SSE4A" "\10" "MISALIGNSSE" \
687 "\11" "3DNOWPREFETCH" \ 691 "\11" "3DNOWPREFETCH" \
688 "\12" "OSVW" "\13" "IBS" "\14" "XOP" \ 692 "\12" "OSVW" "\13" "IBS" "\14" "XOP" \
689 "\15" "SKINIT" "\16" "WDT" "\17" "B14" "\20" "LWP" \ 693 "\15" "SKINIT" "\16" "WDT" "\17" "B14" "\20" "LWP" \
690 "\21" "FMA4" "\22" "TCE" "\23" "B18" "\24" "NodeID" \ 694 "\21" "FMA4" "\22" "TCE" "\23" "B18" "\24" "NodeID" \
691 "\25" "B20" "\26" "TBM" "\27" "TopoExt" "\30" "PCExtC" \ 695 "\25" "B20" "\26" "TBM" "\27" "TopoExt" "\30" "PCExtC" \
692 "\31" "PCExtNB" "\32" "StrmPM" "\33" "DBExt" "\34" "PerfTsc" \ 696 "\31" "PCExtNB" "\32" "StrmPM" "\33" "DBExt" "\34" "PerfTsc" \
693 "\35" "L2IPERFC" "\36" "MWAITX" "\37" "B30" "\40" "B31" 697 "\35" "L2IPERFC" "\36" "MWAITX" "\37" "B30" "\40" "B31"
694 698
695/* 699/*
696 * AMD Advanced Power Management 700 * Advanced Power Management
697 * CPUID Fn8000_0007 %edx 701 * CPUID Fn8000_0007 %edx
 702 *
 703 * Only ITSC is for both Intel and AMD. Others are only for AMD.
698 */ 704 */
699#define CPUID_APM_TS 0x00000001 /* Temperature Sensor */ 705#define CPUID_APM_TS 0x00000001 /* Temperature Sensor */
700#define CPUID_APM_FID 0x00000002 /* Frequency ID control */ 706#define CPUID_APM_FID 0x00000002 /* Frequency ID control */
701#define CPUID_APM_VID 0x00000004 /* Voltage ID control */ 707#define CPUID_APM_VID 0x00000004 /* Voltage ID control */
702#define CPUID_APM_TTP 0x00000008 /* THERMTRIP (PCI F3xE4 register) */ 708#define CPUID_APM_TTP 0x00000008 /* THERMTRIP (PCI F3xE4 register) */
703#define CPUID_APM_HTC 0x00000010 /* Hardware thermal control (HTC) */ 709#define CPUID_APM_HTC 0x00000010 /* Hardware thermal control (HTC) */
704#define CPUID_APM_STC 0x00000020 /* Software thermal control (STC) */ 710#define CPUID_APM_STC 0x00000020 /* Software thermal control (STC) */
705#define CPUID_APM_100 0x00000040 /* 100MHz multiplier control */ 711#define CPUID_APM_100 0x00000040 /* 100MHz multiplier control */
706#define CPUID_APM_HWP 0x00000080 /* HW P-State control */ 712#define CPUID_APM_HWP 0x00000080 /* HW P-State control */
707#define CPUID_APM_TSC 0x00000100 /* TSC invariant */ 713#define CPUID_APM_ITSC 0x00000100 /* invariant TSC */
708#define CPUID_APM_CPB 0x00000200 /* Core performance boost */ 714#define CPUID_APM_CPB 0x00000200 /* Core performance boost */
709#define CPUID_APM_EFF 0x00000400 /* Effective Frequency (read-only) */ 715#define CPUID_APM_EFF 0x00000400 /* Effective Frequency (read-only) */
710#define CPUID_APM_PROCFI 0x00000800 /* Proc Feedback Interface */ 716#define CPUID_APM_PROCFI 0x00000800 /* Proc Feedback Interface */
711#define CPUID_APM_PROCPR 0x00001000 /* Proc Power Reporting */ 717#define CPUID_APM_PROCPR 0x00001000 /* Proc Power Reporting */
712#define CPUID_APM_CONNSTBY 0x00002000 /* Connected Standby */ 718#define CPUID_APM_CONNSTBY 0x00002000 /* Connected Standby */
713#define CPUID_APM_RAPL 0x00004000 /* Running Average Power Limit */ 719#define CPUID_APM_RAPL 0x00004000 /* Running Average Power Limit */
714 720
715#define CPUID_APM_FLAGS "\20" \ 721#define CPUID_APM_FLAGS "\20" \
716 "\1" "TS" "\2" "FID" "\3" "VID" "\4" "TTP" \ 722 "\1" "TS" "\2" "FID" "\3" "VID" "\4" "TTP" \
717 "\5" "HTC" "\6" "STC" "\7" "100" "\10" "HWP" \ 723 "\5" "HTC" "\6" "STC" "\7" "100" "\10" "HWP" \
718 "\11" "TSC" "\12" "CPB" "\13" "EffFreq" "\14" "PROCFI" \ 724 "\11" "ITSC" "\12" "CPB" "\13" "EffFreq" "\14" "PROCFI" \
719 "\15" "PROCPR" "\16" "CONNSTBY" "\17" "RAPL" 725 "\15" "PROCPR" "\16" "CONNSTBY" "\17" "RAPL"
720 726
721/* 727/*
722 * AMD Processor Capacity Parameters and Extended Features 728 * AMD Processor Capacity Parameters and Extended Features
723 * CPUID Fn8000_0008 729 * CPUID Fn8000_0008
724 * %eax: Long Mode Size Identifiers 730 * %eax: Long Mode Size Identifiers
725 * %ebx: Extended Feature Identifiers 731 * %ebx: Extended Feature Identifiers
726 * %ecx: Size Identifiers 732 * %ecx: Size Identifiers
727 */ 733 */
728 734
729/* %ebx */ 735/* %ebx */
730#define CPUID_CAPEX_CLZERO __BIT(0) /* CLZERO instruction */ 736#define CPUID_CAPEX_CLZERO __BIT(0) /* CLZERO instruction */
731#define CPUID_CAPEX_IRPERF __BIT(1) /* InstRetCntMsr */ 737#define CPUID_CAPEX_IRPERF __BIT(1) /* InstRetCntMsr */

cvs diff -r1.33.2.1 -r1.33.2.2 src/sys/arch/x86/x86/procfs_machdep.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/procfs_machdep.c 2019/10/17 18:56:25 1.33.2.1
+++ src/sys/arch/x86/x86/procfs_machdep.c 2020/04/14 17:15:02 1.33.2.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: procfs_machdep.c,v 1.33.2.1 2019/10/17 18:56:25 martin Exp $ */ 1/* $NetBSD: procfs_machdep.c,v 1.33.2.2 2020/04/14 17:15:02 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc. 4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Frank van der Linden and Jason R. Thorpe for 7 * Written by Frank van der Linden and Jason R. Thorpe for
8 * Wasabi Systems, Inc. 8 * Wasabi Systems, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE. 36 * POSSIBILITY OF SUCH DAMAGE.
37 */ 37 */
38 38
39/* 39/*
40 * NOTE: We simply use the primary CPU's cpuid_level and tsc_freq 40 * NOTE: We simply use the primary CPU's cpuid_level and tsc_freq
41 * here. Might want to change this later. 41 * here. Might want to change this later.
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.33.2.1 2019/10/17 18:56:25 martin Exp $"); 45__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.33.2.2 2020/04/14 17:15:02 martin Exp $");
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49#include <sys/mount.h> 49#include <sys/mount.h>
50#include <sys/stat.h> 50#include <sys/stat.h>
51#include <sys/vnode.h> 51#include <sys/vnode.h>
52 52
53#include <miscfs/procfs/procfs.h> 53#include <miscfs/procfs/procfs.h>
54 54
55#include <machine/cpu.h> 55#include <machine/cpu.h>
56#include <machine/reg.h> 56#include <machine/reg.h>
57#include <machine/specialreg.h> 57#include <machine/specialreg.h>
58#include <x86/cputypes.h> 58#include <x86/cputypes.h>
@@ -178,28 +178,28 @@ static const char * const x86_features[] @@ -178,28 +178,28 @@ static const char * const x86_features[]
178 "ospke", "waitpkg", "avx512_vbmi2", NULL, 178 "ospke", "waitpkg", "avx512_vbmi2", NULL,
179 "gfni", "vaes", "vpclmulqdq", "avx512_vnni", 179 "gfni", "vaes", "vpclmulqdq", "avx512_vnni",
180 "avx512_bitalg", "tme", "avx512_vpopcntdq", NULL, 180 "avx512_bitalg", "tme", "avx512_vpopcntdq", NULL,
181 "la57", NULL, NULL, NULL, NULL, NULL, "rdpid", NULL, 181 "la57", NULL, NULL, NULL, NULL, NULL, "rdpid", NULL,
182 NULL, "cldemote", NULL, "movdiri", "movdir64b", NULL, NULL, NULL}, 182 NULL, "cldemote", NULL, "movdiri", "movdir64b", NULL, NULL, NULL},
183 183
184 { /* (17) 0x80000007 ebx */ 184 { /* (17) 0x80000007 ebx */
185 "overflow_recov", "succor", NULL, "smca", NULL, NULL, NULL, NULL, 185 "overflow_recov", "succor", NULL, "smca", NULL, NULL, NULL, NULL,
186 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 186 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
187 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 187 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
188 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, 188 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
189 189
190 { /* (18) Intel 0x00000007 edx */ 190 { /* (18) Intel 0x00000007 edx */
191 NULL, NULL, "avx512_4vnniw", "avx512_4fmaps", NULL, NULL, NULL, NULL, 191 NULL, NULL, "avx512_4vnniw", "avx512_4fmaps", "fsrm", NULL, NULL, NULL,
192 NULL, NULL, "md_clear", NULL, NULL, NULL, NULL, NULL, 192 "vp2intersect", NULL, "md_clear", NULL, NULL, NULL, NULL, NULL,
193 NULL, NULL, "pconfig", NULL, NULL, NULL, NULL, NULL, 193 NULL, NULL, "pconfig", NULL, NULL, NULL, NULL, NULL,
194 NULL, NULL, NULL, NULL, 194 NULL, NULL, NULL, NULL,
195 "flush_l1d", "arch_capabilities", NULL, "ssbd"}, 195 "flush_l1d", "arch_capabilities", NULL, "ssbd"},
196}; 196};
197 197
198static int procfs_getonecpu(int, struct cpu_info *, char *, size_t *); 198static int procfs_getonecpu(int, struct cpu_info *, char *, size_t *);
199 199
200/* 200/*
201 * Linux-style /proc/cpuinfo. 201 * Linux-style /proc/cpuinfo.
202 * Only used when procfs is mounted with -o linux. 202 * Only used when procfs is mounted with -o linux.
203 * 203 *
204 * In the multiprocessor case, this should be a loop over all CPUs. 204 * In the multiprocessor case, this should be a loop over all CPUs.
205 */ 205 */

cvs diff -r1.37 -r1.37.8.1 src/sys/arch/x86/x86/tsc.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/tsc.c 2017/10/02 19:23:16 1.37
+++ src/sys/arch/x86/x86/tsc.c 2020/04/14 17:15:02 1.37.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tsc.c,v 1.37 2017/10/02 19:23:16 maxv Exp $ */ 1/* $NetBSD: tsc.c,v 1.37.8.1 2020/04/14 17:15:02 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.37 2017/10/02 19:23:16 maxv Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.37.8.1 2020/04/14 17:15:02 martin Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/time.h> 34#include <sys/time.h>
35#include <sys/timetc.h> 35#include <sys/timetc.h>
36#include <sys/lwp.h> 36#include <sys/lwp.h>
37#include <sys/atomic.h> 37#include <sys/atomic.h>
38#include <sys/kernel.h> 38#include <sys/kernel.h>
39#include <sys/cpu.h> 39#include <sys/cpu.h>
40#include <sys/xcall.h> 40#include <sys/xcall.h>
41 41
42#include <machine/cpu_counter.h> 42#include <machine/cpu_counter.h>
43#include <machine/cpuvar.h> 43#include <machine/cpuvar.h>
@@ -125,27 +125,27 @@ tsc_is_invariant(void) @@ -125,27 +125,27 @@ tsc_is_invariant(void)
125 */ 125 */
126 } 126 }
127 127
128 /* 128 /*
129 * The best way to check whether the TSC counter is invariant or not 129 * The best way to check whether the TSC counter is invariant or not
130 * is to check CPUID 80000007. 130 * is to check CPUID 80000007.
131 */ 131 */
132 family = CPUID_TO_BASEFAMILY(ci->ci_signature); 132 family = CPUID_TO_BASEFAMILY(ci->ci_signature);
133 if (((cpu_vendor == CPUVENDOR_INTEL) || (cpu_vendor == CPUVENDOR_AMD)) 133 if (((cpu_vendor == CPUVENDOR_INTEL) || (cpu_vendor == CPUVENDOR_AMD))
134 && ((family == 0x06) || (family == 0x0f))) { 134 && ((family == 0x06) || (family == 0x0f))) {
135 x86_cpuid(0x80000000, descs); 135 x86_cpuid(0x80000000, descs);
136 if (descs[0] >= 0x80000007) { 136 if (descs[0] >= 0x80000007) {
137 x86_cpuid(0x80000007, descs); 137 x86_cpuid(0x80000007, descs);
138 invariant = (descs[3] & CPUID_APM_TSC) != 0; 138 invariant = (descs[3] & CPUID_APM_ITSC) != 0;
139 } 139 }
140 } 140 }
141 141
142 return invariant; 142 return invariant;
143} 143}
144 144
145void 145void
146tsc_tc_init(void) 146tsc_tc_init(void)
147{ 147{
148 struct cpu_info *ci; 148 struct cpu_info *ci;
149 bool invariant; 149 bool invariant;
150 150
151 if (!cpu_hascounter()) 151 if (!cpu_hascounter())

cvs diff -r1.104.2.4 -r1.104.2.5 src/usr.sbin/cpuctl/arch/i386.c (expand / switch to unified diff)

--- src/usr.sbin/cpuctl/arch/i386.c 2019/11/19 13:15:57 1.104.2.4
+++ src/usr.sbin/cpuctl/arch/i386.c 2020/04/14 17:15:02 1.104.2.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: i386.c,v 1.104.2.4 2019/11/19 13:15:57 martin Exp $ */ 1/* $NetBSD: i386.c,v 1.104.2.5 2020/04/14 17:15:02 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden, and by Jason R. Thorpe. 8 * by Frank van der Linden, and by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -47,27 +47,27 @@ @@ -47,27 +47,27 @@
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE. 55 * SUCH DAMAGE.
56 */ 56 */
57 57
58#include <sys/cdefs.h> 58#include <sys/cdefs.h>
59#ifndef lint 59#ifndef lint
60__RCSID("$NetBSD: i386.c,v 1.104.2.4 2019/11/19 13:15:57 martin Exp $"); 60__RCSID("$NetBSD: i386.c,v 1.104.2.5 2020/04/14 17:15:02 martin Exp $");
61#endif /* not lint */ 61#endif /* not lint */
62 62
63#include <sys/types.h> 63#include <sys/types.h>
64#include <sys/param.h> 64#include <sys/param.h>
65#include <sys/bitops.h> 65#include <sys/bitops.h>
66#include <sys/sysctl.h> 66#include <sys/sysctl.h>
67#include <sys/ioctl.h> 67#include <sys/ioctl.h>
68#include <sys/cpuio.h> 68#include <sys/cpuio.h>
69 69
70#include <errno.h> 70#include <errno.h>
71#include <string.h> 71#include <string.h>
72#include <stdio.h> 72#include <stdio.h>
73#include <stdlib.h> 73#include <stdlib.h>
@@ -109,27 +109,26 @@ struct cpu_info { @@ -109,27 +109,26 @@ struct cpu_info {
109 * [7] structure ext. feat. %edx 109 * [7] structure ext. feat. %edx
110 * [8] XCR0 bits (d:0 %eax) 110 * [8] XCR0 bits (d:0 %eax)
111 * [9] xsave flags (d:1 %eax) 111 * [9] xsave flags (d:1 %eax)
112 */ 112 */
113 uint32_t ci_cpu_class; /* CPU class */ 113 uint32_t ci_cpu_class; /* CPU class */
114 uint32_t ci_brand_id; /* Intel brand id */ 114 uint32_t ci_brand_id; /* Intel brand id */
115 uint32_t ci_vendor[4]; /* vendor string */ 115 uint32_t ci_vendor[4]; /* vendor string */
116 uint32_t ci_cpu_serial[3]; /* PIII serial number */ 116 uint32_t ci_cpu_serial[3]; /* PIII serial number */
117 uint64_t ci_tsc_freq; /* cpu cycles/second */ 117 uint64_t ci_tsc_freq; /* cpu cycles/second */
118 uint8_t ci_packageid; 118 uint8_t ci_packageid;
119 uint8_t ci_coreid; 119 uint8_t ci_coreid;
120 uint8_t ci_smtid; 120 uint8_t ci_smtid;
121 uint32_t ci_initapicid; 121 uint32_t ci_initapicid;
122 uint32_t ci_max_ext_cpuid; 
123 122
124 uint32_t ci_cur_xsave; 123 uint32_t ci_cur_xsave;
125 uint32_t ci_max_xsave; 124 uint32_t ci_max_xsave;
126 125
127 struct x86_cache_info ci_cinfo[CAI_COUNT]; 126 struct x86_cache_info ci_cinfo[CAI_COUNT];
128 void (*ci_info)(struct cpu_info *); 127 void (*ci_info)(struct cpu_info *);
129}; 128};
130 129
131struct cpu_nocpuid_nameclass { 130struct cpu_nocpuid_nameclass {
132 int cpu_vendor; 131 int cpu_vendor;
133 const char *cpu_vendorname; 132 const char *cpu_vendorname;
134 const char *cpu_name; 133 const char *cpu_name;
135 int cpu_class; 134 int cpu_class;
@@ -1934,27 +1933,27 @@ identifycpu_cpuids_amd(struct cpu_info * @@ -1934,27 +1933,27 @@ identifycpu_cpuids_amd(struct cpu_info *
1934 int n, cpu_family, apic_id, smt_bits, core_bits = 0; 1933 int n, cpu_family, apic_id, smt_bits, core_bits = 0;
1935 uint32_t descs[4]; 1934 uint32_t descs[4];
1936 1935
1937 apic_id = ci->ci_initapicid; 1936 apic_id = ci->ci_initapicid;
1938 cpu_family = CPUID_TO_FAMILY(ci->ci_signature); 1937 cpu_family = CPUID_TO_FAMILY(ci->ci_signature);
1939 1938
1940 if (cpu_family < 0xf) 1939 if (cpu_family < 0xf)
1941 return; 1940 return;
1942 1941
1943 if ((ci->ci_feat_val[0] & CPUID_HTT) != 0) { 1942 if ((ci->ci_feat_val[0] & CPUID_HTT) != 0) {
1944 x86_cpuid(1, descs); 1943 x86_cpuid(1, descs);
1945 lp_max = __SHIFTOUT(descs[1], CPUID_HTT_CORES); 1944 lp_max = __SHIFTOUT(descs[1], CPUID_HTT_CORES);
1946 1945
1947 if (cpu_family >= 0x10 && ci->ci_max_ext_cpuid >= 0x8000008) { 1946 if (cpu_family >= 0x10 && ci->ci_cpuid_extlevel >= 0x8000008) {
1948 x86_cpuid(0x8000008, descs); 1947 x86_cpuid(0x8000008, descs);
1949 core_max = (descs[2] & 0xff) + 1; 1948 core_max = (descs[2] & 0xff) + 1;
1950 n = (descs[2] >> 12) & 0x0f; 1949 n = (descs[2] >> 12) & 0x0f;
1951 if (n != 0) 1950 if (n != 0)
1952 core_bits = n; 1951 core_bits = n;
1953 } 1952 }
1954 } else { 1953 } else {
1955 lp_max = 1; 1954 lp_max = 1;
1956 } 1955 }
1957 core_max = lp_max; 1956 core_max = lp_max;
1958 1957
1959 smt_bits = ilog2((lp_max / core_max) - 1) + 1; 1958 smt_bits = ilog2((lp_max / core_max) - 1) + 1;
1960 if (core_bits == 0) 1959 if (core_bits == 0)
@@ -2277,52 +2276,48 @@ identifycpu(int fd, const char *cpuname) @@ -2277,52 +2276,48 @@ identifycpu(int fd, const char *cpuname)
2277 || (cpu_vendor == CPUVENDOR_AMD))) { 2276 || (cpu_vendor == CPUVENDOR_AMD))) {
2278 x86_cpuid(6, descs); 2277 x86_cpuid(6, descs);
2279 print_bits(cpuname, "DSPM-eax", CPUID_DSPM_FLAGS, descs[0]); 2278 print_bits(cpuname, "DSPM-eax", CPUID_DSPM_FLAGS, descs[0]);
2280 print_bits(cpuname, "DSPM-ecx", CPUID_DSPM_FLAGS1, descs[2]); 2279 print_bits(cpuname, "DSPM-ecx", CPUID_DSPM_FLAGS1, descs[2]);
2281 } 2280 }
2282 if ((ci->ci_cpuid_level >= 7) 2281 if ((ci->ci_cpuid_level >= 7)
2283 && ((cpu_vendor == CPUVENDOR_INTEL) 2282 && ((cpu_vendor == CPUVENDOR_INTEL)
2284 || (cpu_vendor == CPUVENDOR_AMD))) { 2283 || (cpu_vendor == CPUVENDOR_AMD))) {
2285 x86_cpuid(7, descs); 2284 x86_cpuid(7, descs);
2286 aprint_verbose("%s: SEF highest subleaf %08x\n", 2285 aprint_verbose("%s: SEF highest subleaf %08x\n",
2287 cpuname, descs[0]); 2286 cpuname, descs[0]);
2288 } 2287 }
2289 2288
2290 if (cpu_vendor == CPUVENDOR_AMD) { 2289 if ((cpu_vendor == CPUVENDOR_INTEL) || (cpu_vendor == CPUVENDOR_AMD))
2291 x86_cpuid(0x80000000, descs); 2290 if (ci->ci_cpuid_extlevel >= 0x80000007)
2292 if (descs[0] >= 0x80000000) 
2293 ci->ci_max_ext_cpuid = descs[0]; 
2294 else 
2295 ci->ci_max_ext_cpuid = 0; 
2296 if (ci->ci_max_ext_cpuid >= 0x80000007) 
2297 powernow_probe(ci); 2291 powernow_probe(ci);
2298 2292
2299 if (ci->ci_max_ext_cpuid >= 0x80000008) { 2293 if (cpu_vendor == CPUVENDOR_AMD) {
 2294 if (ci->ci_cpuid_extlevel >= 0x80000008) {
2300 x86_cpuid(0x80000008, descs); 2295 x86_cpuid(0x80000008, descs);
2301 print_bits(cpuname, "AMD Extended features", 2296 print_bits(cpuname, "AMD Extended features",
2302 CPUID_CAPEX_FLAGS, descs[1]); 2297 CPUID_CAPEX_FLAGS, descs[1]);
2303 } 2298 }
2304 2299
2305 if ((ci->ci_max_ext_cpuid >= 0x8000000a) 2300 if ((ci->ci_cpuid_extlevel >= 0x8000000a)
2306 && (ci->ci_feat_val[3] & CPUID_SVM) != 0) { 2301 && (ci->ci_feat_val[3] & CPUID_SVM) != 0) {
2307 x86_cpuid(0x8000000a, descs); 2302 x86_cpuid(0x8000000a, descs);
2308 aprint_verbose("%s: SVM Rev. %d\n", cpuname, 2303 aprint_verbose("%s: SVM Rev. %d\n", cpuname,
2309 descs[0] & 0xf); 2304 descs[0] & 0xf);
2310 aprint_verbose("%s: SVM NASID %d\n", cpuname, 2305 aprint_verbose("%s: SVM NASID %d\n", cpuname,
2311 descs[1]); 2306 descs[1]);
2312 print_bits(cpuname, "SVM features", 2307 print_bits(cpuname, "SVM features",
2313 CPUID_AMD_SVM_FLAGS, descs[3]); 2308 CPUID_AMD_SVM_FLAGS, descs[3]);
2314 } 2309 }
2315 if (ci->ci_max_ext_cpuid >= 0x8000001f) { 2310 if (ci->ci_cpuid_extlevel >= 0x8000001f) {
2316 x86_cpuid(0x8000001f, descs); 2311 x86_cpuid(0x8000001f, descs);
2317 print_bits(cpuname, "Encrypted Memory features", 2312 print_bits(cpuname, "Encrypted Memory features",
2318 CPUID_AMD_ENCMEM_FLAGS, descs[0]); 2313 CPUID_AMD_ENCMEM_FLAGS, descs[0]);
2319 } 2314 }
2320 } else if (cpu_vendor == CPUVENDOR_INTEL) { 2315 } else if (cpu_vendor == CPUVENDOR_INTEL) {
2321 int32_t bi_index; 2316 int32_t bi_index;
2322 2317
2323 for (bi_index = 1; bi_index <= ci->ci_cpuid_level; bi_index++) { 2318 for (bi_index = 1; bi_index <= ci->ci_cpuid_level; bi_index++) {
2324 x86_cpuid(bi_index, descs); 2319 x86_cpuid(bi_index, descs);
2325 switch (bi_index) { 2320 switch (bi_index) {
2326 case 0x0a: 2321 case 0x0a:
2327 print_bits(cpuname, "Perfmon-eax", 2322 print_bits(cpuname, "Perfmon-eax",
2328 CPUID_PERF_FLAGS0, descs[0]); 2323 CPUID_PERF_FLAGS0, descs[0]);
@@ -2562,28 +2557,27 @@ x86_print_cache_and_tlb_info(struct cpu_ @@ -2562,28 +2557,27 @@ x86_print_cache_and_tlb_info(struct cpu_
2562 aprint_verbose("\n"); 2557 aprint_verbose("\n");
2563 } 2558 }
2564} 2559}
2565 2560
2566static void 2561static void
2567powernow_probe(struct cpu_info *ci) 2562powernow_probe(struct cpu_info *ci)
2568{ 2563{
2569 uint32_t regs[4]; 2564 uint32_t regs[4];
2570 char buf[256]; 2565 char buf[256];
2571 2566
2572 x86_cpuid(0x80000007, regs); 2567 x86_cpuid(0x80000007, regs);
2573 2568
2574 snprintb(buf, sizeof(buf), CPUID_APM_FLAGS, regs[3]); 2569 snprintb(buf, sizeof(buf), CPUID_APM_FLAGS, regs[3]);
2575 aprint_normal_dev(ci->ci_dev, "AMD Power Management features: %s\n", 2570 aprint_normal_dev(ci->ci_dev, "Power Management features: %s\n", buf);
2576 buf); 
2577} 2571}
2578 2572
2579bool 2573bool
2580identifycpu_bind(void) 2574identifycpu_bind(void)
2581{ 2575{
2582 2576
2583 return true; 2577 return true;
2584} 2578}
2585 2579
2586int 2580int
2587ucodeupdate_check(int fd, struct cpu_ucode *uc) 2581ucodeupdate_check(int fd, struct cpu_ucode *uc)
2588{ 2582{
2589 struct cpu_info ci; 2583 struct cpu_info ci;