From owner-dev-commits-src-all@freebsd.org Tue Feb 9 08:37:02 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3678353650C; Tue, 9 Feb 2021 08:37:02 +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 4DZbpy4pJ8z4gMs; Tue, 9 Feb 2021 08:36:58 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 7FF722789B; Tue, 9 Feb 2021 08:36:57 +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 1198avsB013987; Tue, 9 Feb 2021 08:36:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1198avaj013985; Tue, 9 Feb 2021 08:36:57 GMT (envelope-from git) Date: Tue, 9 Feb 2021 08:36:57 GMT Message-Id: <202102090836.1198avaj013985@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: d1a6826939fb - stable/12 - x86 vdso gettc: reorganize ifunctions. 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/stable/12 X-Git-Reftype: branch X-Git-Commit: d1a6826939fb2bb3fef1a8ea0cb3198248e6bfe8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Feb 2021 08:37:02 -0000 The branch stable/12 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d1a6826939fb2bb3fef1a8ea0cb3198248e6bfe8 commit d1a6826939fb2bb3fef1a8ea0cb3198248e6bfe8 Author: Konstantin Belousov AuthorDate: 2021-01-05 21:14:11 +0000 Commit: Konstantin Belousov CommitDate: 2021-02-09 08:36:15 +0000 x86 vdso gettc: reorganize ifunctions. Tested by: pho (cherry picked from commit de898cb96042a026ef703d81aea6cdf1ffce8f32) --- lib/libc/x86/sys/__vdso_gettc.c | 68 ++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/lib/libc/x86/sys/__vdso_gettc.c b/lib/libc/x86/sys/__vdso_gettc.c index 0781e97e2ce5..f9365eb33cf2 100644 --- a/lib/libc/x86/sys/__vdso_gettc.c +++ b/lib/libc/x86/sys/__vdso_gettc.c @@ -53,57 +53,83 @@ __FBSDID("$FreeBSD$"); #include #include "libc_private.h" -static void -rdtsc_mb_lfence(void) +static inline u_int +rdtsc_low(const struct vdso_timehands *th) { + u_int rv; - lfence(); + __asm __volatile("rdtsc; shrd %%cl, %%edx, %0" + : "=a" (rv) : "c" (th->th_x86_shift) : "edx"); + return (rv); } -static void -rdtsc_mb_mfence(void) +static u_int +rdtsc_low_mb_lfence(const struct vdso_timehands *th) { + lfence(); + return (rdtsc_low(th)); +} +static u_int +rdtsc_low_mb_mfence(const struct vdso_timehands *th) +{ mfence(); + return (rdtsc_low(th)); } -static void -rdtsc_mb_none(void) +static u_int +rdtsc_low_mb_none(const struct vdso_timehands *th) { + return (rdtsc_low(th)); } -DEFINE_UIFUNC(static, void, rdtsc_mb, (void), static) +DEFINE_UIFUNC(static, u_int, __vdso_gettc_rdtsc_low, + (const struct vdso_timehands *th), static) { u_int p[4]; /* Not a typo, string matches our do_cpuid() registers use. */ static const char intel_id[] = "GenuntelineI"; if ((cpu_feature & CPUID_SSE2) == 0) - return (rdtsc_mb_none); + return (rdtsc_low_mb_none); do_cpuid(0, p); return (memcmp(p + 1, intel_id, sizeof(intel_id) - 1) == 0 ? - rdtsc_mb_lfence : rdtsc_mb_mfence); + rdtsc_low_mb_lfence : rdtsc_low_mb_mfence); } static u_int -__vdso_gettc_rdtsc_low(const struct vdso_timehands *th) +rdtsc32_mb_lfence(void) { - u_int rv; - - rdtsc_mb(); - __asm __volatile("rdtsc; shrd %%cl, %%edx, %0" - : "=a" (rv) : "c" (th->th_x86_shift) : "edx"); - return (rv); + lfence(); + return (rdtsc32()); } static u_int -__vdso_rdtsc32(void) +rdtsc32_mb_mfence(void) { + mfence(); + return (rdtsc32()); +} - rdtsc_mb(); +static u_int +rdtsc32_mb_none(void) +{ return (rdtsc32()); } +DEFINE_UIFUNC(static, u_int, __vdso_gettc_rdtsc32, (void), static) +{ + u_int p[4]; + /* Not a typo, string matches our do_cpuid() registers use. */ + static const char intel_id[] = "GenuntelineI"; + + if ((cpu_feature & CPUID_SSE2) == 0) + return (rdtsc32_mb_none); + do_cpuid(0, p); + return (memcmp(p + 1, intel_id, sizeof(intel_id) - 1) == 0 ? + rdtsc32_mb_lfence : rdtsc32_mb_mfence); +} + #define HPET_DEV_MAP_MAX 10 static volatile char *hpet_dev_map[HPET_DEV_MAP_MAX]; @@ -199,7 +225,7 @@ __vdso_hyperv_tsc(struct hyperv_reftsc *tsc_ref, u_int *tc) scale = tsc_ref->tsc_scale; ofs = tsc_ref->tsc_ofs; - rdtsc_mb(); + mfence(); /* XXXKIB */ tsc = rdtsc(); /* ret = ((tsc * scale) >> 64) + ofs */ @@ -231,7 +257,7 @@ __vdso_gettc(const struct vdso_timehands *th, u_int *tc) switch (th->th_algo) { case VDSO_TH_ALGO_X86_TSC: *tc = th->th_x86_shift > 0 ? __vdso_gettc_rdtsc_low(th) : - __vdso_rdtsc32(); + __vdso_gettc_rdtsc32(); return (0); case VDSO_TH_ALGO_X86_HPET: idx = th->th_x86_hpet_idx;