|
Packit Service |
53171b |
/* Test CPU feature data against /proc/cpuinfo.
|
|
Packit Service |
53171b |
This file is part of the GNU C Library.
|
|
Packit Service |
53171b |
Copyright (C) 2012-2020 Free Software Foundation, Inc.
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
53171b |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
53171b |
License as published by the Free Software Foundation; either
|
|
Packit Service |
53171b |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
53171b |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
53171b |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
53171b |
Lesser General Public License for more details.
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
53171b |
License along with the GNU C Library; if not, see
|
|
Packit Service |
53171b |
<https://www.gnu.org/licenses/>. */
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
#include <sys/platform/x86.h>
|
|
Packit Service |
53171b |
#include <stdio.h>
|
|
Packit Service |
53171b |
#include <stdlib.h>
|
|
Packit Service |
53171b |
#include <string.h>
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
static char *cpu_flags;
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
/* Search for flags in /proc/cpuinfo and store line
|
|
Packit Service |
53171b |
in cpu_flags. */
|
|
Packit Service |
53171b |
void
|
|
Packit Service |
53171b |
get_cpuinfo (void)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
FILE *f;
|
|
Packit Service |
53171b |
char *line = NULL;
|
|
Packit Service |
53171b |
size_t len = 0;
|
|
Packit Service |
53171b |
ssize_t read;
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
f = fopen ("/proc/cpuinfo", "r");
|
|
Packit Service |
53171b |
if (f == NULL)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
printf ("cannot open /proc/cpuinfo\n");
|
|
Packit Service |
53171b |
exit (1);
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
while ((read = getline (&line, &len, f)) != -1)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
if (strncmp (line, "flags", 5) == 0)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
cpu_flags = strdup (line);
|
|
Packit Service |
53171b |
break;
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
fclose (f);
|
|
Packit Service |
53171b |
free (line);
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
int
|
|
Packit Service |
53171b |
check_proc (const char *proc_name, int flag, int usable, const char *name)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
int found = 0;
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
printf ("Checking %s:\n", name);
|
|
Packit Service |
53171b |
if (!usable)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
printf (" %s: insufficient usable info, skipped\n", name);
|
|
Packit Service |
53171b |
return 0;
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
printf (" %s: %d\n", name, flag);
|
|
Packit Service |
53171b |
if (strstr (cpu_flags, proc_name) != NULL)
|
|
Packit Service |
53171b |
found = 1;
|
|
Packit Service |
53171b |
printf (" cpuinfo (%s): %d\n", proc_name, found);
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
if (found != flag)
|
|
Packit Service |
53171b |
printf (" *** failure ***\n");
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
return (found != flag);
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
#define CHECK_PROC(str, name) \
|
|
Packit Service |
53171b |
check_proc (#str, HAS_CPU_FEATURE (name), CPU_FEATURE_USABLE (name), \
|
|
Packit Service |
53171b |
"HAS_CPU_FEATURE (" #name ")");
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
static int
|
|
Packit Service |
53171b |
do_test (int argc, char **argv)
|
|
Packit Service |
53171b |
{
|
|
Packit Service |
53171b |
int fails = 0;
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
get_cpuinfo ();
|
|
Packit Service |
53171b |
fails += CHECK_PROC (acpi, ACPI);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (adx, ADX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (apic, APIC);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (aes, AES);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (amx_bf16, AMX_BF16);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (amx_int8, AMX_INT8);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (amx_tile, AMX_TILE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (arch_capabilities, ARCH_CAPABILITIES);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx, AVX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx2, AVX2);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_4fmaps, AVX512_4FMAPS);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_4vnniw, AVX512_4VNNIW);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_bf16, AVX512_BF16);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_bitalg, AVX512_BITALG);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512ifma, AVX512_IFMA);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_vbmi, AVX512_VBMI);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_vbmi2, AVX512_VBMI2);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_vnni, AVX512_VNNI);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_vp2intersect, AVX512_VP2INTERSECT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512_vpopcntdq, AVX512_VPOPCNTDQ);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512bw, AVX512BW);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512cd, AVX512CD);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512er, AVX512ER);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512dq, AVX512DQ);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512f, AVX512F);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512pf, AVX512PF);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (avx512vl, AVX512VL);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (bmi1, BMI1);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (bmi2, BMI2);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (cldemote, CLDEMOTE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (clflushopt, CLFLUSHOPT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (clflush, CLFSH);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (clwb, CLWB);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (cmov, CMOV);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (cx16, CMPXCHG16B);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (cnxt_id, CNXT_ID);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (core_capabilities, CORE_CAPABILITIES);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (cx8, CX8);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (dca, DCA);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (de, DE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (zero_fcs_fds, DEPR_FPU_CS_DS);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ds, DS);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ds_cpl, DS_CPL);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (dtes64, DTES64);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (est, EIST);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (enqcmd, ENQCMD);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (erms, ERMS);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (f16c, F16C);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (fma, FMA);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (fma4, FMA4);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (fpu, FPU);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (fsgsbase, FSGSBASE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (fsrm, FSRM);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (fxsr, FXSR);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (gfni, GFNI);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (hle, HLE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ht, HTT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (hybrid, HYBRID);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ibrs, IBRS_IBPB);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ibt, IBT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (invariant_tsc, INVARIANT_TSC);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (invpcid, INVPCID);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (flush_l1d, L1D_FLUSH);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (lahf_lm, LAHF64_SAHF64);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (lm, LM);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (lwp, LWP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (abm, LZCNT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (mca, MCA);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (mce, MCE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (md_clear, MD_CLEAR);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (mmx, MMX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (monitor, MONITOR);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (movbe, MOVBE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (movdiri, MOVDIRI);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (movdir64b, MOVDIR64B);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (mpx, MPX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (msr, MSR);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (mtrr, MTRR);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (nx, NX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ospke, OSPKE);
|
|
Packit Service |
53171b |
#if 0
|
|
Packit Service |
53171b |
/* NB: /proc/cpuinfo doesn't report this feature. */
|
|
Packit Service |
53171b |
fails += CHECK_PROC (osxsave, OSXSAVE);
|
|
Packit Service |
53171b |
#endif
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pae, PAE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pdpe1gb, PAGE1GB);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pat, PAT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pbe, PBE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pcid, PCID);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pclmulqdq, PCLMULQDQ);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pconfig, PCONFIG);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pdcm, PDCM);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pge, PGE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pks, PKS);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pku, PKU);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (popcnt, POPCNT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (3dnowprefetch, PREFETCHW);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (prefetchwt1, PREFETCHWT1);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pse, PSE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (pse36, PSE_36);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (psn, PSN);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (rdpid, RDPID);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (rdrand, RDRAND);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (rdseed, RDSEED);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (rdt_a, RDT_A);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (cqm, RDT_M);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (rdtscp, RDTSCP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (rtm, RTM);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sdbg, SDBG);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sep, SEP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (serialize, SERIALIZE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sgx, SGX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sgx_lc, SGX_LC);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sha_ni, SHA);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (shstk, SHSTK);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (smap, SMAP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (smep, SMEP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (smx, SMX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ss, SS);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ssbd, SSBD);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sse, SSE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sse2, SSE2);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sse3, SSE3);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sse4_1, SSE4_1);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sse4_2, SSE4_2);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (sse4a, SSE4A);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (ssse3, SSSE3);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (stibp, STIBP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (svm, SVM);
|
|
Packit Service |
53171b |
#ifdef __x86_64__
|
|
Packit Service |
53171b |
/* NB: SYSCALL_SYSRET is 64-bit only. */
|
|
Packit Service |
53171b |
fails += CHECK_PROC (syscall, SYSCALL_SYSRET);
|
|
Packit Service |
53171b |
#endif
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tbm, TBM);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tm, TM);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tm2, TM2);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (intel_pt, TRACE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tsc, TSC);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tsc_adjust, TSC_ADJUST);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tsc_deadline, TSC_DEADLINE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (tsxldtrk, TSXLDTRK);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (umip, UMIP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (vaes, VAES);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (vme, VME);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (vmx, VMX);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (vpclmulqdq, VPCLMULQDQ);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (waitpkg, WAITPKG);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (wbnoinvd, WBNOINVD);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (x2apic, X2APIC);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xfd, XFD);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xgetbv1, XGETBV_ECX_1);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xop, XOP);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xsave, XSAVE);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xsavec, XSAVEC);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xsaveopt, XSAVEOPT);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xsaves, XSAVES);
|
|
Packit Service |
53171b |
fails += CHECK_PROC (xtpr, XTPRUPDCTRL);
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
return (fails != 0);
|
|
Packit Service |
53171b |
}
|
|
Packit Service |
53171b |
|
|
Packit Service |
53171b |
#include "../../../test-skeleton.c"
|