From: H.J. Lu Date: Thu, 4 Feb 2021 18:39:34 +0000 (-0800) Subject: x86: Add PTWRITE feature detection [BZ #27346] X-Git-Tag: upstream/2.34~974 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ab25c88758810269607a066fcac399e29863510;p=platform%2Fupstream%2Fglibc.git x86: Add PTWRITE feature detection [BZ #27346] 1. Add CPUID_INDEX_14_ECX_0 for CPUID leaf 0x14 to detect PTWRITE feature in EBX of CPUID leaf 0x14 with ECX == 0. 2. Add PTWRITE detection to CPU feature tests. 3. Add 2 static CPU feature tests. --- diff --git a/manual/platform.texi b/manual/platform.texi index 6caf68d..a0b204b 100644 --- a/manual/platform.texi +++ b/manual/platform.texi @@ -488,6 +488,9 @@ extended state management using XSAVE/XRSTOR. @code{PSN} -- Processor Serial Number. @item +@code{PTWRITE} -- PTWRITE instruction. + +@item @code{RDPID} -- RDPID instruction. @item diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index dd82674..e1f9379 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -8,8 +8,11 @@ sysdep-dl-routines += dl-get-cpu-features sysdep_headers += sys/platform/x86.h tests += tst-get-cpu-features tst-get-cpu-features-static \ - tst-cpu-features-cpuinfo tst-cpu-features-supports -tests-static += tst-get-cpu-features-static + tst-cpu-features-cpuinfo tst-cpu-features-cpuinfo-static \ + tst-cpu-features-supports tst-cpu-features-supports-static +tests-static += tst-get-cpu-features-static \ + tst-cpu-features-cpuinfo-static \ + tst-cpu-features-supports-static ifeq (yes,$(have-ifunc)) tests += \ tst-ifunc-isa-1 \ diff --git a/sysdeps/x86/bits/platform/x86.h b/sysdeps/x86/bits/platform/x86.h index 8f423ae..c4850fc 100644 --- a/sysdeps/x86/bits/platform/x86.h +++ b/sysdeps/x86/bits/platform/x86.h @@ -29,7 +29,8 @@ enum CPUID_INDEX_80000007, CPUID_INDEX_80000008, CPUID_INDEX_7_ECX_1, - CPUID_INDEX_19 + CPUID_INDEX_19, + CPUID_INDEX_14_ECX_0 }; struct cpuid_feature @@ -295,5 +296,11 @@ enum + cpuid_register_index_ebx * 8 * sizeof (unsigned int)), x86_cpu_AESKLE = x86_cpu_index_19_ebx, - x86_cpu_WIDE_KL = x86_cpu_index_19_ebx + 2 + x86_cpu_WIDE_KL = x86_cpu_index_19_ebx + 2, + + x86_cpu_index_14_ecx_0_ebx + = (CPUID_INDEX_14_ECX_0 * 8 * 4 * sizeof (unsigned int) + + cpuid_register_index_ebx * 8 * sizeof (unsigned int)), + + x86_cpu_PTWRITE = x86_cpu_index_14_ecx_0_ebx + 4 }; diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 7996ed0..d7248cb 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -97,6 +97,7 @@ update_usable (struct cpu_features *cpu_features) CPU_FEATURE_SET_USABLE (cpu_features, FZLRM); CPU_FEATURE_SET_USABLE (cpu_features, FSRS); CPU_FEATURE_SET_USABLE (cpu_features, FSRCS); + CPU_FEATURE_SET_USABLE (cpu_features, PTWRITE); /* Can we call xgetbv? */ if (CPU_FEATURES_CPU_P (cpu_features, OSXSAVE)) @@ -359,6 +360,13 @@ get_common_indices (struct cpu_features *cpu_features, cpu_features->features[CPUID_INDEX_D_ECX_1].cpuid.ecx, cpu_features->features[CPUID_INDEX_D_ECX_1].cpuid.edx); + if (cpu_features->basic.max_cpuid >= 0x14) + __cpuid_count (0x14, 0, + cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.eax, + cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.ebx, + cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.ecx, + cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.edx); + if (cpu_features->basic.max_cpuid >= 0x19) __cpuid_count (0x19, 0, cpu_features->features[CPUID_INDEX_19].cpuid.eax, diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h index 475e877..dabe6b9 100644 --- a/sysdeps/x86/include/cpu-features.h +++ b/sysdeps/x86/include/cpu-features.h @@ -29,7 +29,7 @@ enum { - CPUID_INDEX_MAX = CPUID_INDEX_19 + 1 + CPUID_INDEX_MAX = CPUID_INDEX_14_ECX_0 + 1 }; enum @@ -307,6 +307,11 @@ enum #define bit_cpu_AESKLE (1u << 0) #define bit_cpu_WIDE_KL (1u << 2) +/* CPUID_INDEX_14_ECX_0. */ + +/* EBX. */ +#define bit_cpu_PTWRITE (1u << 4) + /* CPUID_INDEX_1. */ /* ECX. */ @@ -532,6 +537,11 @@ enum #define index_cpu_AESKLE CPUID_INDEX_19 #define index_cpu_WIDE_KL CPUID_INDEX_19 +/* CPUID_INDEX_14_ECX_0. */ + +/* EBX. */ +#define index_cpu_PTWRITE CPUID_INDEX_14_ECX_0 + /* CPUID_INDEX_1. */ /* ECX. */ @@ -757,6 +767,11 @@ enum #define reg_AESKLE ebx #define reg_WIDE_KL ebx +/* CPUID_INDEX_14_ECX_0. */ + +/* EBX. */ +#define reg_PTWRITE ebx + /* PREFERRED_FEATURE_INDEX_1. */ #define bit_arch_I586 (1u << 0) #define bit_arch_I686 (1u << 1) diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo-static.c b/sysdeps/x86/tst-cpu-features-cpuinfo-static.c new file mode 100644 index 0000000..993a1a9 --- /dev/null +++ b/sysdeps/x86/tst-cpu-features-cpuinfo-static.c @@ -0,0 +1 @@ +#include "tst-cpu-features-cpuinfo.c" diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c index 3c2fa7d..75e7eb9 100644 --- a/sysdeps/x86/tst-cpu-features-cpuinfo.c +++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c @@ -199,6 +199,7 @@ do_test (int argc, char **argv) fails += CHECK_PROC (popcnt, POPCNT); fails += CHECK_PROC (3dnowprefetch, PREFETCHW); fails += CHECK_PROC (prefetchwt1, PREFETCHWT1); + fails += CHECK_PROC (ptwrite, PTWRITE); fails += CHECK_PROC (pse, PSE); fails += CHECK_PROC (pse36, PSE_36); fails += CHECK_PROC (psn, PSN); diff --git a/sysdeps/x86/tst-cpu-features-supports-static.c b/sysdeps/x86/tst-cpu-features-supports-static.c new file mode 100644 index 0000000..38f4046 --- /dev/null +++ b/sysdeps/x86/tst-cpu-features-supports-static.c @@ -0,0 +1 @@ +#include "tst-cpu-features-supports.c" diff --git a/sysdeps/x86/tst-cpu-features-supports.c b/sysdeps/x86/tst-cpu-features-supports.c index 79d803e..ce78a7d 100644 --- a/sysdeps/x86/tst-cpu-features-supports.c +++ b/sysdeps/x86/tst-cpu-features-supports.c @@ -149,6 +149,7 @@ do_test (int argc, char **argv) fails += CHECK_SUPPORTS (popcnt, POPCNT); #if __GNUC_PREREQ (11, 0) fails += CHECK_SUPPORTS (prefetchwt1, PREFETCHWT1); + fails += CHECK_SUPPORTS (ptwrite, PTWRITE); fails += CHECK_SUPPORTS (rdpid, RDPID); fails += CHECK_SUPPORTS (rdrnd, RDRAND); fails += CHECK_SUPPORTS (rdseed, RDSEED); diff --git a/sysdeps/x86/tst-get-cpu-features.c b/sysdeps/x86/tst-get-cpu-features.c index b5e7f6e..583e1e6 100644 --- a/sysdeps/x86/tst-get-cpu-features.c +++ b/sysdeps/x86/tst-get-cpu-features.c @@ -203,6 +203,7 @@ do_test (void) CHECK_CPU_FEATURE (LAM); CHECK_CPU_FEATURE (AESKLE); CHECK_CPU_FEATURE (WIDE_KL); + CHECK_CPU_FEATURE (PTWRITE); printf ("Usable CPU features:\n"); CHECK_CPU_FEATURE_USABLE (SSE3); @@ -364,6 +365,7 @@ do_test (void) CHECK_CPU_FEATURE_USABLE (FSRCS); CHECK_CPU_FEATURE_USABLE (AESKLE); CHECK_CPU_FEATURE_USABLE (WIDE_KL); + CHECK_CPU_FEATURE_USABLE (PTWRITE); return 0; }