Skip to content

Commit

Permalink
Add znver1 arches with 32-bit + 64-bit variants and proper CPU detection
Browse files Browse the repository at this point in the history
This change adds the ability for RPM to detect systems running with
AMD Ryzen CPUs and allow the installation of packages that are
built specifically for this subarchitecture.

As part of this change, a new %x86_64 macro has been introduced
to alias all 64-bit x86 architecture variants in the same manner
that the %ix86 macro has done for 32-bit x86 architecture variants.

This change was originally written by Bernhard Rosenkränzer for
OpenMandriva to support Ryzen-optimized builds of OpenMandriva with
the OpenMandriva Lx 4.0 release. It has been improved and revised
in OpenMandriva over the past two years and is essentially finalized
now.

Co-authored-by: Neal Gompa <ngompa13@gmail.com>
Co-authored-by: Bernhard Rosenkränzer <bero@lindev.ch>
  • Loading branch information
Conan-Kudo and berolinux committed Feb 2, 2020
1 parent 8896e81 commit a41546a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
38 changes: 37 additions & 1 deletion lib/rpmrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,16 @@ static rpmRC rpmPlatform(rpmrcCtx ctx, const char * platform)
}


# if defined(__linux__) && defined(__x86_64__)
static inline void cpuid(uint32_t op, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
asm volatile (
"cpuid\n"
: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
: "a" (op));
}
# endif

# if defined(__linux__) && defined(__i386__)
#include <setjmp.h>
#include <signal.h>
Expand Down Expand Up @@ -949,6 +959,25 @@ static int is_geode(void)
}
#endif

#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
static int is_ryzen(void) {
uint32_t eax, ebx, ecx, edx;
char vendor[13];
int family;
vendor[12]=0;
cpuid(0, &eax, &ebx, &ecx, &edx);
memcpy(vendor, &ebx, sizeof(ebx));
memcpy(vendor+4, &edx, sizeof(edx));
memcpy(vendor+8, &ecx, sizeof(ecx));
if (!rstreqn(vendor, "AuthenticAMD", 12))
return 0;
cpuid(1, &eax, &ebx, &ecx, &edx);
family = (eax>>8)&0xf;
if(family == 0xf)
family += (eax>>20)&0x7f;
return family >= 0x17;
}
#endif

#if defined(__linux__)
#ifndef AT_HWCAP2 /* glibc < 2.18 */
Expand Down Expand Up @@ -1290,7 +1319,9 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
{
char mclass = (char) (RPMClass() | '0');

if ((mclass == '6' && is_athlon()) || mclass == '7')
if(is_ryzen())
strcpy(un.machine, "znver1_32");
else if ((mclass == '6' && is_athlon()) || mclass == '7')
strcpy(un.machine, "athlon");
else if (is_pentium4())
strcpy(un.machine, "pentium4");
Expand All @@ -1303,6 +1334,11 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
}
# endif

# if defined(__linux__) && defined(__x86_64__)
if (is_ryzen())
strcpy(un.machine, "znver1");
# endif

/* the uname() result goes through the arch_canon table */
canon = lookupInCanonTable(un.machine,
ctx->tables[RPM_MACHTABLE_INSTARCH].canons,
Expand Down
6 changes: 5 additions & 1 deletion macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,11 @@ package or when debugging this package.\
# rpm can use regular expressions against target platforms in macro
# conditionals.
#
%ix86 i386 i486 i586 i686 pentium3 pentium4 athlon geode
%ix86 i386 i486 i586 i686 pentium3 pentium4 athlon geode znver1_32

#------------------------------------------------------------------------------
# arch macro for all supported x86_64 processors
%x86_64 x86_64 znver1 amd64 em64t

#------------------------------------------------------------------------------
# arch macro for all supported ARM processors
Expand Down
11 changes: 11 additions & 0 deletions rpmrc.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ optflags: pentium3 -O2 -g -march=pentium3
optflags: pentium4 -O2 -g -march=pentium4
optflags: athlon -O2 -g -march=athlon
optflags: geode -Os -g -m32 -march=geode
optflags: znver1_32 -O2 -g -march=znver1 -mtune=znver1 -mfpmath=sse
optflags: ia64 -O2 -g
optflags: x86_64 -O2 -g
optflags: znver1 -O2 -g -march=znver1 -mtune=znver1
optflags: amd64 -O2 -g
optflags: ia32e -O2 -g

Expand Down Expand Up @@ -147,6 +149,7 @@ archcolor: s390x 2
archcolor: ia64 2

archcolor: x86_64 2
archcolor: znver1 2

archcolor: sh3 1
archcolor: sh4 1
Expand All @@ -166,7 +169,9 @@ arch_canon: i686: i686 1
arch_canon: i586: i586 1
arch_canon: i486: i486 1
arch_canon: i386: i386 1
arch_canon: znver1_32: znver1_32 1
arch_canon: x86_64: x86_64 1
arch_canon: znver1: znver1 1
arch_canon: amd64: amd64 1
arch_canon: ia32e: ia32e 1
arch_canon: em64t: em64t 1
Expand Down Expand Up @@ -298,6 +303,7 @@ buildarchtranslate: osfmach3_i586: i386
buildarchtranslate: osfmach3_i486: i386
buildarchtranslate: osfmach3_i386: i386

buildarchtranslate: znver1_32: znver1_32
buildarchtranslate: athlon: i386
buildarchtranslate: geode: i386
buildarchtranslate: pentium4: i386
Expand Down Expand Up @@ -378,6 +384,7 @@ buildarchtranslate: ia64: ia64
buildarchtranslate: x86_64: x86_64
buildarchtranslate: amd64: x86_64
buildarchtranslate: ia32e: x86_64
buildarchtranslate: znver1: znver1

buildarchtranslate: sh3: sh3
buildarchtranslate: sh4: sh4
Expand All @@ -398,6 +405,7 @@ arch_compat: alphaev56: alphaev5
arch_compat: alphaev5: alpha
arch_compat: alpha: axp noarch

arch_compat: znver1_32: znver1_32 athlon geode pentium4 pentium3 i686 i586 i486 i386 noarch
arch_compat: athlon: i686
arch_compat: geode: i586
arch_compat: pentium4: pentium3
Expand Down Expand Up @@ -489,6 +497,7 @@ arch_compat: ia64: noarch
arch_compat: x86_64: amd64 em64t athlon noarch
arch_compat: amd64: x86_64 em64t athlon noarch
arch_compat: ia32e: x86_64 em64t athlon noarch
arch_compat: znver1: znver1 amd64 x86_64 em64t noarch

arch_compat: sh3: noarch
arch_compat: sh4: noarch
Expand Down Expand Up @@ -535,6 +544,7 @@ buildarch_compat: aarch64: noarch
buildarch_compat: riscv: noarch
buildarch_compat: riscv64: noarch

buildarch_compat: znver1_32: znver1_32 athlon geode pentium4 pentium3 i686 i586 i486 i386 noarch
buildarch_compat: athlon: i686
buildarch_compat: geode: i586
buildarch_compat: pentium4: pentium3
Expand Down Expand Up @@ -627,6 +637,7 @@ buildarch_compat: ia64: noarch
buildarch_compat: x86_64: noarch
buildarch_compat: amd64: x86_64
buildarch_compat: ia32e: x86_64
buildarch_compat: znver1: znver1 x86_64

buildarch_compat: sh3: noarch
buildarch_compat: sh4: noarch
Expand Down

0 comments on commit a41546a

Please sign in to comment.