From nobody Sat Mar 11 22:51:17 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PYynx737Fz3wyp2; Sat, 11 Mar 2023 22:51:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PYynx6Q0Hz4HY3; Sat, 11 Mar 2023 22:51:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678575077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wgD86nDcGjS4T/9hXbTCwAw18muH4PT/k8HWrYLU3pI=; b=LBViA6tDuiPXfQXKjUXvRgiyrNV9dg5a8wrS3+TK07jGNJSNfh0PalEAxgmIem7HsG2GC4 zJPR0QV6IJjm4sWnL9mHNrfL+fUYa5JeYZXpi8myVN8YQvJ0CEhM2fza5PP/q5L/DdTLFD yrZk2VGkEpY6ekH0pSFaXJv/lGOdmo4+zF6g7NMWjd+DwBT8nKWkKQeqqg5fHMJ7NnFuSO 6gVgCn9Hx+qccJ/xRhy4RM6DONHSxZBQWKtiJ+uz0LsNGzUnNLB1KfivS7hxLnFnhi9/uB rHR+oqjO6+1Jj46OwpLLDkGjDGy7rsM0XFxuw30lc+njdFxoheJP/CPDaBOoYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678575077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wgD86nDcGjS4T/9hXbTCwAw18muH4PT/k8HWrYLU3pI=; b=dWC0dgisKofk4m4RUCEbRqs1VCj0e2gFuVnzMLBwsRhFQjQovEhuB8rzsmT/ko5s0l0iaE EhrbWwtVW1GDFe4bcQpFJ5FGqfFTNC/ud8okURR4QoC98odiY/4hJ1NuN2MWzeeCqKj56o wGOvsv4k9IwmBPo8wXgXVZsRUnWbyh7AC3zgpmQ/RqhK7291DH6w4aaDR2zHtI/0ap6Mq2 SsYrx7N336P1GyZ70wZRuFIaBloOUGFPACI4s2iK6qJNvrqYcegKzOlVCH2iHqt1fuuUTq NZjNlwWA3ccF8WxBUe/HKJAOQcVPfhBYLGVuV669fnykLTQeY2MdHqPL67Vg6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678575077; a=rsa-sha256; cv=none; b=CR/6/hPzydpo/eVr4dyw+XvnzKRhi0KkN7YmYt2Ayps8n10rz9HiZnKqy8tuosFsXyBRgD qGfDjAwN1mNg4E9rEZQpVwFz+nszJSIs2wH8dgUcUwoUS3WC4C8PObkPb/bLse5M1o0JXN zuI7DusVUdHDyOodWDXh4Mo/1As2bYbfdq78/gXvF/aS/dAzv2v8jC8CPljSxsk3mBQFWF 1SGK7AU7Zu/GpXqNTEc6EH7PBsurXFHn5s0EpvZTLTy5C6ia7m8kJrwLrViCAXOrkCsHgZ 2EU89kYDPPickSAPSlHsraSIrqpFwdo7Lebt6nyNOPBbFKUNN6z9AVi5ivscpQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PYynx5M7pznXL; Sat, 11 Mar 2023 22:51:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32BMpHb1090401; Sat, 11 Mar 2023 22:51:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32BMpHoF090400; Sat, 11 Mar 2023 22:51:17 GMT (envelope-from git) Date: Sat, 11 Mar 2023 22:51:17 GMT Message-Id: <202303112251.32BMpHoF090400@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 0303938539f3 - main - x86: microoptimize static PIE startup List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0303938539f3f12da65128fc67f883efe82dc125 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0303938539f3f12da65128fc67f883efe82dc125 commit 0303938539f3f12da65128fc67f883efe82dc125 Author: Konstantin Belousov AuthorDate: 2022-11-01 01:42:50 +0000 Commit: Konstantin Belousov CommitDate: 2023-03-11 22:50:04 +0000 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 --- lib/libc/csu/amd64/Makefile.inc | 2 +- lib/libc/csu/amd64/reloc.c | 14 ++++++++++---- lib/libc/csu/i386/Makefile.inc | 2 +- lib/libc/csu/i386/reloc.c | 14 ++++++++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/libc/csu/amd64/Makefile.inc b/lib/libc/csu/amd64/Makefile.inc index b3420a638164..f14033217580 100644 --- a/lib/libc/csu/amd64/Makefile.inc +++ b/lib/libc/csu/amd64/Makefile.inc @@ -1,4 +1,4 @@ # CFLAGS+= -DCRT_IRELOC_RELA \ - -DINIT_IRELOCS="" + -DINIT_IRELOCS="init_cpu_features()" diff --git a/lib/libc/csu/amd64/reloc.c b/lib/libc/csu/amd64/reloc.c index adb52e42a32c..0a5a24929954 100644 --- a/lib/libc/csu/amd64/reloc.c +++ b/lib/libc/csu/amd64/reloc.c @@ -29,13 +29,13 @@ __FBSDID("$FreeBSD$"); #include #include +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: diff --git a/lib/libc/csu/i386/Makefile.inc b/lib/libc/csu/i386/Makefile.inc index ac0984df2349..f3f8c2b176ce 100644 --- a/lib/libc/csu/i386/Makefile.inc +++ b/lib/libc/csu/i386/Makefile.inc @@ -1,4 +1,4 @@ # CFLAGS+= -DCRT_IRELOC_REL \ - -DINIT_IRELOCS="" + -DINIT_IRELOCS="init_cpu_features()" diff --git a/lib/libc/csu/i386/reloc.c b/lib/libc/csu/i386/reloc.c index 13438035841d..f99b1089cf47 100644 --- a/lib/libc/csu/i386/reloc.c +++ b/lib/libc/csu/i386/reloc.c @@ -29,13 +29,13 @@ __FBSDID("$FreeBSD$"); #include #include +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: