@@ -1,3 +1,22 @@
+2016-03-10 Piotr Henryk Dabrowski <ultr@ultr.pl>
+
+ * misc/common_cpuid.h: Common cpuid wrappers
+ * sysdeps/generic/local_cpuid.h: Common cpuid wrappers
+ * sysdeps/unix/sysv/linux/x86/local_cpuid.h: use SYS_cpuid if available
+ * sysdeps/x86/cpu-features.c: Use local_cpuid.h
+ * sysdeps/x86/fpu/test-fenv-clear-sse.c: Use local_cpuid.h
+ * sysdeps/x86/fpu/test-fenv-sse-2.c: Use local_cpuid.h
+ * sysdeps/x86/fpu/test-fenv-sse.c: Use local_cpuid.h
+ * sysdeps/x86_64/cacheinfo.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-audit10.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-audit4.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-audit6.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-auditmod10b.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-auditmod4b.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-auditmod6b.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-auditmod6c.c: Use local_cpuid.h
+ * sysdeps/x86_64/tst-auditmod7b.c: Use local_cpuid.h
+
2016-03-09 Aurelien Jarno <aurelien@aurel32.net>
[BZ #19792]
new file mode 100644
@@ -0,0 +1,73 @@
+/* CPUID wrapper functions.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Piotr Henryk Dabrowski (ultr@ultr.pl), 2016.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LOCAL_CPUID_H
+# error "Do not use <misc/common_cpuid.h> directly; include <local_cpuid.h> instead."
+#endif
+
+#ifndef _COMMON_CPUID_H
+#define _COMMON_CPUID_H 1
+
+#include <cpuid.h>
+#include <errno.h>
+
+#define get_cpuid_max __get_cpuid_max
+
+/* NOTE: for new Linux kernels these functions try to use kernel-adjusted
+ values for cpuid returned by the SYS_cpuid sys call.
+ Otherwise they fallback to native cpuid implementation. */
+
+/* Return cpuid data for requested cpuid level (eax) and count register (ecx),
+ as found in returned eax, ebx, ecx and edx registers.
+ All pointers are required to be non-null.
+ Implementation is system dependant. */
+static inline void
+cpuid_count (unsigned int level, unsigned int count,
+ unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx);
+
+/* Return cpuid data for requested cpuid level (eax),
+ as found in returned eax, ebx, ecx and edx registers.
+ All pointers are required to be non-null. */
+static inline void
+cpuid (unsigned int level,
+ unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+ cpuid_count (level, 0, eax, ebx, ecx, edx);
+}
+
+/* Return cpuid data for requested cpuid level (eax),
+ as found in returned eax, ebx, ecx and edx registers.
+ The function checks if cpuid is supported and returns 1 for valid cpuid
+ information or 0 for unsupported cpuid level.
+ All pointers are required to be non-null. */
+static inline int
+get_cpuid (unsigned int level,
+ unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+ unsigned int ext = level & 0x80000000;
+ if (get_cpuid_max (ext, 0) < level)
+ return 0;
+ cpuid (level, eax, ebx, ecx, edx);
+ return 1;
+}
+
+#endif /* common_cpuid.h */
new file mode 100644
@@ -0,0 +1,33 @@
+/* CPUID wrapper functions.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Piotr Henryk Dabrowski (ultr@ultr.pl), 2016.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LOCAL_CPUID_H
+#define _LOCAL_CPUID_H 1
+
+#include <misc/common_cpuid.h>
+
+static inline void
+cpuid_count (unsigned int level, unsigned int count,
+ unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+ __cpuid_count (level, count, *eax, *ebx, *ecx, *edx);
+}
+
+#endif /* local_cpuid.h */
new file mode 100644
@@ -0,0 +1,40 @@
+/* CPUID wrapper functions.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Piotr Henryk Dabrowski (ultr@ultr.pl), 2016.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LOCAL_CPUID_H
+#define _LOCAL_CPUID_H 1
+
+#include <misc/common_cpuid.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+
+static inline void
+cpuid_count (unsigned int level, unsigned int count,
+ unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+#ifdef __NR_cpuid
+ if (INLINE_SYSCALL (cpuid, 6, level, count, eax, ebx, ecx, edx) == 0)
+ return;
+#endif
+ __cpuid_count (level, count, *eax, *ebx, *ecx, *edx);
+}
+
+#endif /* local_cpuid.h */
@@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <cpu-features.h>
static inline void
@@ -25,9 +25,9 @@ get_common_indeces (struct cpu_features *cpu_features,
unsigned int *extended_model)
{
unsigned int eax;
- __cpuid (1, eax, cpu_features->cpuid[COMMON_CPUID_INDEX_1].ebx,
- cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx,
- cpu_features->cpuid[COMMON_CPUID_INDEX_1].edx);
+ cpuid (1, &eax, &(cpu_features->cpuid[COMMON_CPUID_INDEX_1].ebx),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_1].edx));
GLRO(dl_x86_cpu_features).cpuid[COMMON_CPUID_INDEX_1].eax = eax;
*family = (eax >> 8) & 0x0f;
*model = (eax >> 4) & 0x0f;
@@ -42,20 +42,21 @@ get_common_indeces (struct cpu_features *cpu_features,
static inline void
init_cpu_features (struct cpu_features *cpu_features)
{
- unsigned int ebx, ecx, edx;
+ unsigned int eax, ebx, ecx, edx;
unsigned int family = 0;
unsigned int model = 0;
enum cpu_features_kind kind;
#if !HAS_CPUID
- if (__get_cpuid_max (0, 0) == 0)
+ if (get_cpuid_max (0, 0) == 0)
{
kind = arch_kind_other;
goto no_cpuid;
}
#endif
- __cpuid (0, cpu_features->max_cpuid, ebx, ecx, edx);
+ cpuid (0, &eax, &ebx, &ecx, &edx);
+ cpu_features->max_cpuid = eax;
/* This spells out "GenuineIntel". */
if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
@@ -147,13 +148,13 @@ init_cpu_features (struct cpu_features *cpu_features)
ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
unsigned int eax;
- __cpuid (0x80000000, eax, ebx, ecx, edx);
+ cpuid (0x80000000, &eax, &ebx, &ecx, &edx);
if (eax >= 0x80000001)
- __cpuid (0x80000001,
- cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
- cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
- cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
- cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
+ cpuid (0x80000001,
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx));
if (family == 0x15)
{
@@ -175,11 +176,11 @@ init_cpu_features (struct cpu_features *cpu_features)
cpu_features->feature[index_I686] |= bit_I686;
if (cpu_features->max_cpuid >= 7)
- __cpuid_count (7, 0,
- cpu_features->cpuid[COMMON_CPUID_INDEX_7].eax,
- cpu_features->cpuid[COMMON_CPUID_INDEX_7].ebx,
- cpu_features->cpuid[COMMON_CPUID_INDEX_7].ecx,
- cpu_features->cpuid[COMMON_CPUID_INDEX_7].edx);
+ cpuid_count (7, 0,
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_7].eax),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_7].ebx),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_7].ecx),
+ &(cpu_features->cpuid[COMMON_CPUID_INDEX_7].edx));
/* Can we call xgetbv? */
if (HAS_CPU_FEATURE (OSXSAVE))
@@ -17,7 +17,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <stdbool.h>
static bool
@@ -25,7 +25,7 @@ have_sse2 (void)
{
unsigned int eax, ebx, ecx, edx;
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
+ if (!get_cpuid (1, &eax, &ebx, &ecx, &edx))
return false;
return (edx & bit_SSE2) != 0;
@@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <fenv.h>
#include <float.h>
#include <stdbool.h>
@@ -28,7 +28,7 @@ have_sse2 (void)
{
unsigned int eax, ebx, ecx, edx;
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
+ if (!get_cpuid (1, &eax, &ebx, &ecx, &edx))
return false;
return (edx & bit_SSE2) != 0;
@@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <fenv.h>
#include <float.h>
#include <stdbool.h>
@@ -27,7 +27,7 @@ have_sse2 (void)
{
unsigned int eax, ebx, ecx, edx;
- if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
+ if (!get_cpuid (1, &eax, &ebx, &ecx, &edx))
return false;
return (edx & bit_SSE2) != 0;
@@ -20,7 +20,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <init-arch.h>
#define is_intel GLRO(dl_x86_cpu_features).kind == arch_kind_intel
@@ -162,7 +162,7 @@ intel_check_word (int name, unsigned int value, bool *has_level_2,
unsigned int round = 0;
while (1)
{
- __cpuid_count (4, round, eax, ebx, ecx, edx);
+ cpuid_count (4, round, &eax, &ebx, &ecx, &edx);
enum { null = 0, data = 1, inst = 2, uni = 3 } type = eax & 0x1f;
if (type == null)
@@ -275,7 +275,7 @@ handle_intel (int name, unsigned int maxidx)
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
- __cpuid (2, eax, ebx, ecx, edx);
+ cpuid (2, &eax, &ebx, &ecx, &edx);
/* The low byte of EAX in the first round contain the number of
rounds we have to make. At least one, the one we are already
@@ -319,7 +319,7 @@ handle_amd (int name)
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
- __cpuid (0x80000000, eax, ebx, ecx, edx);
+ cpuid (0x80000000, &eax, &ebx, &ecx, &edx);
/* No level 4 cache (yet). */
if (name > _SC_LEVEL3_CACHE_LINESIZE)
@@ -329,7 +329,7 @@ handle_amd (int name)
if (eax < fn)
return 0;
- __cpuid (fn, eax, ebx, ecx, edx);
+ cpuid (fn, &eax, &ebx, &ecx, &edx);
if (name < _SC_LEVEL1_DCACHE_SIZE)
{
@@ -479,7 +479,7 @@ init_cacheinfo (void)
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
- int max_cpuid_ex;
+ unsigned int max_cpuid_ex;
long int data = -1;
long int shared = -1;
unsigned int level;
@@ -512,7 +512,7 @@ init_cacheinfo (void)
/* Query until desired cache level is enumerated. */
do
{
- __cpuid_count (4, i++, eax, ebx, ecx, edx);
+ cpuid_count (4, i++, &eax, &ebx, &ecx, &edx);
/* There seems to be a bug in at least some Pentium Ds
which sometimes fail to iterate all cache parameters.
@@ -536,7 +536,7 @@ init_cacheinfo (void)
i = 0;
while (1)
{
- __cpuid_count (11, i++, eax, ebx, ecx, edx);
+ cpuid_count (11, i++, &eax, &ebx, &ecx, &edx);
int shipped = ebx & 0xff;
int type = ecx & 0xff0;
@@ -598,7 +598,7 @@ init_cacheinfo (void)
shared = handle_amd (_SC_LEVEL3_CACHE_SIZE);
/* Get maximum extended function. */
- __cpuid (0x80000000, max_cpuid_ex, ebx, ecx, edx);
+ cpuid (0x80000000, &max_cpuid_ex, &ebx, &ecx, &edx);
if (shared <= 0)
/* No shared L3 cache. All we have is the L2 cache. */
@@ -609,7 +609,7 @@ init_cacheinfo (void)
if (max_cpuid_ex >= 0x80000008)
{
/* Get width of APIC ID. */
- __cpuid (0x80000008, max_cpuid_ex, ebx, ecx, edx);
+ cpuid (0x80000008, &max_cpuid_ex, &ebx, &ecx, &edx);
threads = 1 << ((ecx >> 12) & 0x0f);
}
@@ -617,7 +617,7 @@ init_cacheinfo (void)
{
/* If APIC ID width is not available, use logical
processor count. */
- __cpuid (0x00000001, max_cpuid_ex, ebx, ecx, edx);
+ cpuid (0x00000001, &max_cpuid_ex, &ebx, &ecx, &edx);
if ((edx & (1 << 28)) != 0)
threads = (ebx >> 16) & 0xff;
@@ -635,7 +635,7 @@ init_cacheinfo (void)
#ifndef DISABLE_PREFETCHW
if (max_cpuid_ex >= 0x80000001)
{
- __cpuid (0x80000001, eax, ebx, ecx, edx);
+ cpuid (0x80000001, &eax, &ebx, &ecx, &edx);
/* PREFETCHW || 3DNow! */
if ((ecx & 0x100) || (edx & 0x80000000))
__x86_prefetchw = -1;
@@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <cpu-features.h>
int tst_audit10_aux (void);
@@ -26,11 +26,11 @@ avx512_enabled (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
|| (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE))
return 0;
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ cpuid_count (7, 0, &eax, &ebx, &ecx, &edx);
if (!(ebx & bit_AVX512F))
return 0;
@@ -16,7 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <cpuid.h>
+#include <local_cpuid.h>
int tst_audit4_aux (void);
@@ -25,7 +25,7 @@ avx_enabled (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
|| (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE))
return 0;
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
#include <emmintrin.h>
extern __m128i audit_test (__m128i, __m128i, __m128i, __m128i,
@@ -14,7 +14,7 @@ avx_enabled (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
|| (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE))
return 0;
@@ -125,18 +125,18 @@ la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
#ifdef __AVX512F__
#include <immintrin.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
static int
check_avx512 (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
|| (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE))
return 0;
- __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ cpuid_count (7, 0, &eax, &ebx, &ecx, &edx);
if (!(ebx & bit_AVX512F))
return 0;
@@ -108,7 +108,7 @@ la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
#ifdef __AVX__
#include <immintrin.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
static int avx = -1;
@@ -120,7 +120,7 @@ check_avx (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx)
&& (ecx & bit_AVX))
avx = 1;
else
@@ -108,7 +108,7 @@ la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
#ifdef __AVX__
#include <immintrin.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
static int avx = -1;
@@ -120,7 +120,7 @@ check_avx (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx)
&& (ecx & bit_AVX))
avx = 1;
else
@@ -108,7 +108,7 @@ la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
#ifdef __AVX__
#include <immintrin.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
static int avx = -1;
@@ -120,7 +120,7 @@ check_avx (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx)
&& (ecx & bit_AVX))
avx = 1;
else
@@ -108,7 +108,7 @@ la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
#ifdef __AVX__
#include <immintrin.h>
-#include <cpuid.h>
+#include <local_cpuid.h>
static int avx = -1;
@@ -120,7 +120,7 @@ check_avx (void)
{
unsigned int eax, ebx, ecx, edx;
- if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
+ if (get_cpuid (1, &eax, &ebx, &ecx, &edx)
&& (ecx & bit_AVX))
avx = 1;
else