• Alejandro Enedino Hernandez Samaniego's avatar
    tune-skylake.inc: Improve handling the newly introduced skylake tune. · 0bc64c2a
    The skylake tune introduced on 04510bfa
    
    Currently disables qemu-usermode by default, due to the lack
    of support from QEMU to several of the Intel instruction set
    extensions introduced within the few latest generations of
    CPU architectures (e.g. QEMU does not support avx2)
    
    While there is a good reason to perform the removal of qemu-usermode
    from MACHINE_FEATURES, there are several components within the
    build system that rely on it for proper compilation and behavior,
    for example anything that uses gobject data introspection or even
    the components like the chromium web browser require to run a QEMU
    for the target architecture to build successfully.
    
    There is no reason why we can't have those components built without
    sacrificing the cpu (most) optimizations.
    
    The process I followed on meta-chromebook to enable an optimized build
    and whats being upstreamed by this patch is that by doing some
    reverse engineering, I was able to figure out which instruction
    set extensions are not compatible with QEMU Skylake-Client, by
    performing a bit gcc magic from inside QEMU (target) to get the
    available optimizations for the native architecture (which is
    actually our target in this case).
    
    These are all (not surprisingly) the avx2 extensions, listed as
    follows:
    -mno-avx
    -mno-avx2
    -mno-avx512f
    -mno-avx512er
    -mno-avx512cd
    -mno-avx512pf
    -mno-avx512dq
    -mno-avx512bw
    -mno-avx512vl
    -mno-avx512ifma
    -mno-avx512vbmi
    -mno-avx512vbmi2
    -mno-avx512vnni
    -mno-avx512bitalg
    
    Specifically disabling these manually (for now), allows us to build an
    optimized system for the skylake/skylake based architectures (e.g. KabyLake)
    while keeping the capability of using qemu-usermode, as a side note GCC
    does show more unavailable optimization tunes, (hence why there might be
    some warnings), but getting rid of these specifically seems enough to make
    it run happily in qemu-usermode.
    
    Basically the MACHINE_FEATURES variable is able to dictate how we will tune
    the build for our device, if qemu-usermode is present, TUNE_CCARGS will
    expand as follows:
    
    TUNE_CCARGS=" -m64 -march=skylake  -mtune=skylake  -mno-avx -mno-avx2
    -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-avx512dq
    -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-avx512vbmi2
    -mno-avx512vnni -mno-avx512bitalg  -mfpmath=sse"
    
    Whats this means is that the build will be tuned for skylake architectures,
    enabling all possible extensions, (MOVBE, MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1,
    SSE4.2, POPCNT, AES, PCLMUL, FSGSBASE, RDRND, FMA, BMI, BMI2, F16C, RDSEED,
    ADCX, PREFETCHW, CLFLUSHOPT, XSAVEC and XSAVES) minus the ones QEMU is unable
    to run, which will result in an illegal instruction error, notice the tune is
    kept as skylake.
    
    Whilst, if qemu-usermode is not found on MACHINE_FEATURES, TUNE_CCARGS will
    expand to:
    TUNE_CCARGS=" -m64 -march=skylake -mtune=generic -mavx2 -mfpmath=sse"
    
    Which is exactly what its set to with the current tune, so this patch should
    be harmless, and only extend current functionality, we will still keep
    qemu-usermode disabled by default (hence enabling avx2) but the user would
    have the capability to decide how the skylake tune will be handled.
    
    As the GCC manual states, we should really try to avoid using mtune=generic
    when possible, and this patch allows us to do so [1].
    
    This patch also addresses a problem on which the current skylake tune includes
    tune-core2.inc instead of tune-corei7.inc to get the list of AVAILTUNES
    and PACKAGE_EXTRA_ARCHS.
    
    Right now, AVAILTUNES are set as follows:
    AVAILTUNES=" x86 x86-64 x86-64-x32 i586 i686 core2-32 core2-64 core2-64-x32
    skylake-64"
    
    Where the proper set should be (after this patch):
    AVAILTUNES=" x86 x86-64 x86-64-x32 i586 i686 core2-32 core2-64 core2-64-x32
    corei7-32 corei7-64 corei7-64-x32 skylake-64"
    
    When (if), QEMU gains support for the AVX2 instruction set extensions these
    can be easily removed to provide full support for qemu-usermode.
    
    [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/x86-Options.html
    
    
    
    Signed-off-by: default avatarAlejandro Enedino Hernandez Samaniego <aehs29@gmail.com>
    Signed-off-by: default avatarAnuj Mittal <anuj.mittal@intel.com>
    0bc64c2a