x86: microoptimize static PIE startup

Do not call CPUID on each ireloc, instead call it once and cache
results, similar to how it is done on powerpc64.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	3 weeks
Differential revision:	https://reviews.freebsd.org/D37220
This commit is contained in:
Konstantin Belousov 2022-11-01 03:42:50 +02:00
parent 51015e6d0f
commit 0303938539
4 changed files with 22 additions and 10 deletions

View file

@ -1,4 +1,4 @@
#
CFLAGS+= -DCRT_IRELOC_RELA \
-DINIT_IRELOCS=""
-DINIT_IRELOCS="init_cpu_features()"

View file

@ -29,13 +29,13 @@ __FBSDID("$FreeBSD$");
#include <machine/specialreg.h>
#include <machine/cpufunc.h>
static uint32_t cpu_feature, cpu_feature2;
static uint32_t cpu_stdext_feature, cpu_stdext_feature2;
static void
crt1_handle_rela(const Elf_Rela *r)
init_cpu_features(void)
{
Elf_Addr *ptr, *where, target;
u_int p[4];
uint32_t cpu_feature, cpu_feature2;
uint32_t cpu_stdext_feature, cpu_stdext_feature2;
do_cpuid(1, p);
cpu_feature = p[3];
@ -49,6 +49,12 @@ crt1_handle_rela(const Elf_Rela *r)
cpu_stdext_feature = 0;
cpu_stdext_feature2 = 0;
}
}
static void
crt1_handle_rela(const Elf_Rela *r)
{
Elf_Addr *ptr, *where, target;
switch (ELF_R_TYPE(r->r_info)) {
case R_X86_64_IRELATIVE:

View file

@ -1,4 +1,4 @@
#
CFLAGS+= -DCRT_IRELOC_REL \
-DINIT_IRELOCS=""
-DINIT_IRELOCS="init_cpu_features()"

View file

@ -29,13 +29,13 @@ __FBSDID("$FreeBSD$");
#include <machine/specialreg.h>
#include <machine/cpufunc.h>
static uint32_t cpu_feature, cpu_feature2;
static uint32_t cpu_stdext_feature, cpu_stdext_feature2;
static void
crt1_handle_rel(const Elf_Rel *r)
init_cpu_features(void)
{
Elf_Addr *where, target;
u_int cpuid_supported, p[4];
uint32_t cpu_feature, cpu_feature2;
uint32_t cpu_stdext_feature, cpu_stdext_feature2;
__asm __volatile(
" pushfl\n"
@ -72,6 +72,12 @@ crt1_handle_rel(const Elf_Rel *r)
cpu_stdext_feature = 0;
cpu_stdext_feature2 = 0;
}
}
static void
crt1_handle_rel(const Elf_Rel *r)
{
Elf_Addr *where, target;
switch (ELF_R_TYPE(r->r_info)) {
case R_386_IRELATIVE: