From nobody Sun May 08 14:21:46 2022 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 275261AC4C6A; Sun, 8 May 2022 14:21:47 +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 4Kx61k3kMfz3F3b; Sun, 8 May 2022 14:21:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652019706; 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=V7wwEaJKxASefVKZCyE9m3sYgEuyfyjh1i6VuIkcb/E=; b=ViqBVy4zwN1YQ9prA4k1VqV/I/xZKuSi0dIGxXTdXJGiivm1qfxAucTMEQQnpl38JTMBE0 WSwc9G85YJBWeWrlAJJAvUGnfs6duwmfmRtDyKMtV+SvQYTw6x2Bdn8WjSNVhlnGibUkFi eSSBvENn/CYrlRC4S8uMyUyAorM9gEdYt8yOBfxZ7EFtd5Vi6izSQ7mvdO0+IGrgi/Y3ru g0zXid6spdDfbLbsT1PMWb7HecjLBdpQXH9+jVj5Ex2g/cyTQqSISEe1XsvSxMLz8uT8uP uZ9ZeMUzlJZCxTcJfuOTxtudbRB4RuXUwAif74x/ixZmrhjv1ghIycmdEWjIPA== 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 5815B25C7A; Sun, 8 May 2022 14:21:46 +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 248ELkgp037869; Sun, 8 May 2022 14:21:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 248ELkPv037868; Sun, 8 May 2022 14:21:46 GMT (envelope-from git) Date: Sun, 8 May 2022 14:21:46 GMT Message-Id: <202205081421.248ELkPv037868@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 5a6a4fb284b1 - main - linux(4): Implement vdso getcpu for x86. 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5a6a4fb284b1a9c4b4105fd6ab8143356f3ef3f7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652019706; 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=V7wwEaJKxASefVKZCyE9m3sYgEuyfyjh1i6VuIkcb/E=; b=Vwpt5GLEbYi7XIbAbrA4AS2B8VeM1u5+4CjQL8B2QrlXqBqAccZ62zL1eqVyHGonzDUvEJ V7TvmAGxYJRZ4iHe7ASt8eYzF0oeRkB99LleUhkk9QCkSWN8gDdL2/mE2zRychPH+zJoU+ eBJxgVgTuQYK98r9tO3B1CMPSN++06eAPUOUvYSAZfGn+u7ciP8JDq0mVJ9N8Ekgnv5IxS 6Y0+E88i1Vkp+0uVvKJlX8Rjkcp8ASmiPe434n0O1OG1HBHfpuwuDxtADo53CkJhDTatMz hWOK62QiPh7k/kzGDlMbOUQMj1xzKp/M0/9fnyFcbDLxkUl08S2SKkTEsSW2Ng== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652019706; a=rsa-sha256; cv=none; b=KzeO0lFYOkaQRBQzQqGpbmUBHOkY5XeibM2hC3niuKIffga74BUniJmTjBnDq+f5Vp+zhT O12P95JGmpX4Wv+nV7FWHiXLmEg2hmY57n6FOjqxA4+l4wDg+Eb17c6vRdCG5fi4UNfTCL auDljhhXoJ6gQSQoXdR4Nlmby98rvz+ZRAG1woyJKlGx/GOBvXfVHt9QWf60cEt86nMYrL L2GzME9REtTQzQWV0ak4YQMrfNNf1Kokmzk40Sji5eh/Tfbj47tCOjr4ZsdZKI9BFa5FBL 7U854huFJKDwaAVJ/Ueli1rvh+UyprJZhpwYxY++G5mTws5+eN7zsp/SZ7/u+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=5a6a4fb284b1a9c4b4105fd6ab8143356f3ef3f7 commit 5a6a4fb284b1a9c4b4105fd6ab8143356f3ef3f7 Author: Dmitry Chagin AuthorDate: 2022-05-08 14:20:52 +0000 Commit: Dmitry Chagin CommitDate: 2022-05-08 14:20:52 +0000 linux(4): Implement vdso getcpu for x86. This is modeled after f2395455 (by kib@). MFC after: 2 weeks --- sys/amd64/linux/linux_sysvec.c | 7 +++ sys/amd64/linux/linux_vdso.lds.s | 1 + sys/amd64/linux/linux_vdso_gtod.c | 2 + sys/amd64/linux32/linux32_sysvec.c | 7 +++ sys/amd64/linux32/linux32_vdso.lds.s | 2 + sys/amd64/linux32/linux32_vdso_gtod.c | 17 ++++++ sys/compat/linux/linux_vdso_gtod.inc | 13 ++++- sys/i386/linux/linux_sysvec.c | 7 +++ sys/i386/linux/linux_vdso.lds.s | 2 + sys/i386/linux/linux_vdso_gtod.c | 17 ++++++ sys/modules/linux/Makefile | 2 +- sys/modules/linux64/Makefile | 2 +- sys/x86/linux/linux_vdso_getcpu_x86.inc | 68 ++++++++++++++++++++++ ...sc_selector_x86.c => linux_vdso_selector_x86.c} | 26 ++++++++- sys/x86/linux/linux_x86.h | 5 ++ 15 files changed, 172 insertions(+), 6 deletions(-) diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index aad594ec3130..1ea274da8935 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -172,6 +172,7 @@ LINUX_VDSO_SYM_INTPTR(linux_rt_sigcode); LINUX_VDSO_SYM_CHAR(linux_platform); LINUX_VDSO_SYM_INTPTR(kern_timekeep_base); LINUX_VDSO_SYM_INTPTR(kern_tsc_selector); +LINUX_VDSO_SYM_INTPTR(kern_cpu_selector); /* * If FreeBSD & Linux have a difference of opinion about what a trap @@ -837,6 +838,12 @@ linux_exec_sysvec_init(void *param) *ktsc_selector = linux_vdso_tsc_selector_idx(); if (bootverbose) printf("Linux x86-64 vDSO tsc_selector: %lu\n", *ktsc_selector); + + tkoff = kern_cpu_selector - linux_vdso_base; + ktsc_selector = (l_uintptr_t *)(linux_vdso_mapping + tkoff); + *ktsc_selector = linux_vdso_cpu_selector_idx(); + if (bootverbose) + printf("Linux x86-64 vDSO cpu_selector: %lu\n", *ktsc_selector); } SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY, linux_exec_sysvec_init, &elf_linux_sysvec); diff --git a/sys/amd64/linux/linux_vdso.lds.s b/sys/amd64/linux/linux_vdso.lds.s index ccf7c80565bb..24d8cab162f8 100644 --- a/sys/amd64/linux/linux_vdso.lds.s +++ b/sys/amd64/linux/linux_vdso.lds.s @@ -68,6 +68,7 @@ VERSION linux_platform; kern_timekeep_base; kern_tsc_selector; + kern_cpu_selector; local: *; }; } diff --git a/sys/amd64/linux/linux_vdso_gtod.c b/sys/amd64/linux/linux_vdso_gtod.c index 65e45ce29505..3d18b551e6fb 100644 --- a/sys/amd64/linux/linux_vdso_gtod.c +++ b/sys/amd64/linux/linux_vdso_gtod.c @@ -49,8 +49,10 @@ __FBSDID("$FreeBSD$"); /* The kernel fixup this at vDSO install */ uintptr_t *kern_timekeep_base = NULL; uint32_t kern_tsc_selector = 0; +uint32_t kern_cpu_selector = 0; #include +#include /* for debug purpose */ static int diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 782ab2246061..b57d6f93d94b 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -185,6 +185,7 @@ LINUX_VDSO_SYM_INTPTR(__kernel_sigreturn); LINUX_VDSO_SYM_INTPTR(__kernel_rt_sigreturn); LINUX_VDSO_SYM_INTPTR(kern_timekeep_base); LINUX_VDSO_SYM_INTPTR(kern_tsc_selector); +LINUX_VDSO_SYM_INTPTR(kern_cpu_selector); LINUX_VDSO_SYM_CHAR(linux_platform); /* @@ -1000,6 +1001,12 @@ linux_exec_sysvec_init(void *param) *ktsc_selector = linux_vdso_tsc_selector_idx(); if (bootverbose) printf("Linux i386 vDSO tsc_selector: %u\n", *ktsc_selector); + + tkoff = kern_cpu_selector - linux_vdso_base; + ktsc_selector = (l_uintptr_t *)(linux_vdso_mapping + tkoff); + *ktsc_selector = linux_vdso_cpu_selector_idx(); + if (bootverbose) + printf("Linux i386 vDSO cpu_selector: %u\n", *ktsc_selector); } SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY, linux_exec_sysvec_init, &elf_linux_sysvec); diff --git a/sys/amd64/linux32/linux32_vdso.lds.s b/sys/amd64/linux32/linux32_vdso.lds.s index 0a392e6380b6..cd5b4a20dee0 100644 --- a/sys/amd64/linux32/linux32_vdso.lds.s +++ b/sys/amd64/linux32/linux32_vdso.lds.s @@ -58,6 +58,7 @@ VERSION __vdso_clock_gettime; __vdso_gettimeofday; __vdso_time; + __vdso_getcpu; __vdso_clock_getres; __vdso_clock_gettime64; }; @@ -75,6 +76,7 @@ VERSION linux_platform; kern_timekeep_base; kern_tsc_selector; + kern_cpu_selector; local: *; }; } diff --git a/sys/amd64/linux32/linux32_vdso_gtod.c b/sys/amd64/linux32/linux32_vdso_gtod.c index bbe15e462c09..4f9892af3fa5 100644 --- a/sys/amd64/linux32/linux32_vdso_gtod.c +++ b/sys/amd64/linux32/linux32_vdso_gtod.c @@ -50,8 +50,10 @@ __FBSDID("$FreeBSD$"); /* The kernel fixup this at vDSO install */ uintptr_t *kern_timekeep_base = NULL; uint32_t kern_tsc_selector = 0; +uint32_t kern_cpu_selector = 0; #include +#include static int write(int fd, const void *buf, size_t size) @@ -128,6 +130,21 @@ __vdso_clock_getres_fallback(clockid_t clock_id, struct l_timespec *ts) return (res); } +static int +__vdso_getcpu_fallback(uint32_t *cpu, uint32_t *node, void *cache) +{ + int res; + + __asm__ __volatile__ + ( + "int $0x80" + : "=a"(res) + : "a"(LINUX32_SYS_linux_getcpu), "D"(cpu), "S"(node), "d"(cache) + : "cc", "memory" + ); + return (res); +} + static int __vdso_time_fallback(long *tm) { diff --git a/sys/compat/linux/linux_vdso_gtod.inc b/sys/compat/linux/linux_vdso_gtod.inc index 52fab2bbc5d7..7320ce998d80 100644 --- a/sys/compat/linux/linux_vdso_gtod.inc +++ b/sys/compat/linux/linux_vdso_gtod.inc @@ -352,12 +352,19 @@ int clock_gettime64(clockid_t clock_id, struct l_timespec64 *lts) __attribute__((weak, alias("__vdso_clock_gettime64"))); #endif -#if defined(__amd64__) && !defined(COMPAT_LINUX32) +#if defined(__i386__) || defined(__amd64__) int __vdso_getcpu(uint32_t *cpu, uint32_t *node, void *cache) { - - return (__vdso_getcpu_fallback(cpu, node, cache)); + int ret; + + if (node != NULL) + return (__vdso_getcpu_fallback(cpu, node, cache)); + ret = __vdso_getcpu_try(); + if (ret < 0) + return (__vdso_getcpu_fallback(cpu, node, cache)); + *cpu = ret; + return (0); } #endif diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 7bc7c96e943a..53e55557e6f7 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -160,6 +160,7 @@ LINUX_VDSO_SYM_INTPTR(__kernel_sigreturn); LINUX_VDSO_SYM_INTPTR(__kernel_rt_sigreturn); LINUX_VDSO_SYM_INTPTR(kern_timekeep_base); LINUX_VDSO_SYM_INTPTR(kern_tsc_selector); +LINUX_VDSO_SYM_INTPTR(kern_cpu_selector); /* * If FreeBSD & Linux have a difference of opinion about what a trap @@ -942,6 +943,12 @@ linux_exec_sysvec_init(void *param) *ktsc_selector = linux_vdso_tsc_selector_idx(); if (bootverbose) printf("Linux i386 vDSO tsc_selector: %u\n", *ktsc_selector); + + tkoff = kern_cpu_selector - linux_vdso_base; + ktsc_selector = (l_uintptr_t *)(linux_vdso_mapping + tkoff); + *ktsc_selector = linux_vdso_cpu_selector_idx(); + if (bootverbose) + printf("Linux i386 vDSO cpu_selector: %u\n", *ktsc_selector); } SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY, linux_exec_sysvec_init, &elf_linux_sysvec); diff --git a/sys/i386/linux/linux_vdso.lds.s b/sys/i386/linux/linux_vdso.lds.s index 0a392e6380b6..cd5b4a20dee0 100644 --- a/sys/i386/linux/linux_vdso.lds.s +++ b/sys/i386/linux/linux_vdso.lds.s @@ -58,6 +58,7 @@ VERSION __vdso_clock_gettime; __vdso_gettimeofday; __vdso_time; + __vdso_getcpu; __vdso_clock_getres; __vdso_clock_gettime64; }; @@ -75,6 +76,7 @@ VERSION linux_platform; kern_timekeep_base; kern_tsc_selector; + kern_cpu_selector; local: *; }; } diff --git a/sys/i386/linux/linux_vdso_gtod.c b/sys/i386/linux/linux_vdso_gtod.c index 8619a21cd3f4..20f754bfaa17 100644 --- a/sys/i386/linux/linux_vdso_gtod.c +++ b/sys/i386/linux/linux_vdso_gtod.c @@ -49,8 +49,10 @@ __FBSDID("$FreeBSD$"); /* The kernel fixup this at vDSO install */ uintptr_t *kern_timekeep_base = NULL; uint32_t kern_tsc_selector = 0; +uint32_t kern_cpu_selector = 0; #include +#include static int write(int fd, const void *buf, size_t size) @@ -127,6 +129,21 @@ __vdso_clock_getres_fallback(clockid_t clock_id, struct l_timespec *ts) return (res); } +static int +__vdso_getcpu_fallback(uint32_t *cpu, uint32_t *node, void *cache) +{ + int res; + + __asm__ __volatile__ + ( + "int $0x80" + : "=a"(res) + : "a"(LINUX_SYS_linux_getcpu), "D"(cpu), "S"(node), "d"(cache) + : "cc", "memory" + ); + return (res); +} + static int __vdso_time_fallback(long *tm) { diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile index 9b4453045c09..b94605853743 100644 --- a/sys/modules/linux/Makefile +++ b/sys/modules/linux/Makefile @@ -20,7 +20,7 @@ SRCS= linux_fork.c linux${SFX}_dummy_machdep.c linux_file.c linux_event.c \ opt_inet6.h opt_compat.h opt_posix.h opt_usb.h vnode_if.h \ device_if.h bus_if.h .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" -SRCS+= linux_dummy_x86.c linux_vdso_tsc_selector_x86.c +SRCS+= linux_dummy_x86.c linux_vdso_selector_x86.c VDSODEPS=linux_vdso_gettc_x86.inc .endif .if ${MACHINE_CPUARCH} == "amd64" diff --git a/sys/modules/linux64/Makefile b/sys/modules/linux64/Makefile index 4a4a84d38c73..63ddad878399 100644 --- a/sys/modules/linux64/Makefile +++ b/sys/modules/linux64/Makefile @@ -15,7 +15,7 @@ SRCS= linux_elf64.c linux_fork.c linux_dummy_machdep.c linux_file.c \ vnode_if.h device_if.h bus_if.h \ linux_support.s .if ${MACHINE_CPUARCH} == "amd64" -SRCS+= linux_dummy_x86.c linux_vdso_tsc_selector_x86.c +SRCS+= linux_dummy_x86.c linux_vdso_selector_x86.c .endif DPSRCS= assym.inc linux_genassym.c diff --git a/sys/x86/linux/linux_vdso_getcpu_x86.inc b/sys/x86/linux/linux_vdso_getcpu_x86.inc new file mode 100644 index 000000000000..6cd0e5e78919 --- /dev/null +++ b/sys/x86/linux/linux_vdso_getcpu_x86.inc @@ -0,0 +1,68 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 The FreeBSD Foundation + * Copyright (c) 2022 Dmitry Chagin + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +static int +__vdso_getcpu_rdpid(void) +{ + register_t res; + + __asm("rdpid %0" : "=r" (res)); + return ((int)res); +} + +static int +__vdso_getcpu_rdtscp(void) +{ + int res; + + __asm("rdtscp" : "=c" (res) : : "eax", "edx"); + return (res); +} + +static int +__vdso_getcpu_try(void) +{ + int res; + + switch (kern_cpu_selector) { + case LINUX_VDSO_CPU_RDTSCP: + res = __vdso_getcpu_rdtscp(); + break; + case LINUX_VDSO_CPU_RDPID: + res = __vdso_getcpu_rdpid(); + break; + default: + res = -1; + } + return (res); +} diff --git a/sys/x86/linux/linux_vdso_tsc_selector_x86.c b/sys/x86/linux/linux_vdso_selector_x86.c similarity index 79% rename from sys/x86/linux/linux_vdso_tsc_selector_x86.c rename to sys/x86/linux/linux_vdso_selector_x86.c index a3a65a6d337d..d93b26ed44df 100644 --- a/sys/x86/linux/linux_vdso_tsc_selector_x86.c +++ b/sys/x86/linux/linux_vdso_selector_x86.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2012 Konstantin Belousov - * Copyright (c) 2016, 2017, 2019 The FreeBSD Foundation + * Copyright (c) 2016, 2017, 2019, 2021 The FreeBSD Foundation * Copyright (c) 2021 Dmitry Chagin * * Portions of this software were developed by Konstantin Belousov @@ -36,6 +36,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include int @@ -55,3 +57,25 @@ linux_vdso_tsc_selector_idx() return (2); return (amd_cpu ? 1 : 0); } + +int +linux_vdso_cpu_selector_idx() +{ + u_int amd_feature, cpu_exthigh, p[4]; + + if ((cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0) + return (LINUX_VDSO_CPU_RDPID); + + amd_feature = 0; + if (cpu_feature != 0) { + do_cpuid(0x80000000, p); + cpu_exthigh = p[0]; + if (cpu_exthigh >= 0x80000001) { + do_cpuid(0x80000001, p); + amd_feature = p[3]; + } + } + + return ((amd_feature & AMDID_RDTSCP) == 0 ? + LINUX_VDSO_CPU_DEFAULT : LINUX_VDSO_CPU_RDTSCP); +} diff --git a/sys/x86/linux/linux_x86.h b/sys/x86/linux/linux_x86.h index 73736eb7eb84..79e6e7fbfeec 100644 --- a/sys/x86/linux/linux_x86.h +++ b/sys/x86/linux/linux_x86.h @@ -28,6 +28,11 @@ #ifndef _X86_INCLUDE_LINUX_LINUX_X86_H_ #define _X86_INCLUDE_LINUX_LINUX_X86_H_ +#define LINUX_VDSO_CPU_DEFAULT 0 +#define LINUX_VDSO_CPU_RDPID 1 +#define LINUX_VDSO_CPU_RDTSCP 2 + int linux_vdso_tsc_selector_idx(void); +int linux_vdso_cpu_selector_idx(void); #endif /* _X86_INCLUDE_LINUX_LINUX_X86_H_ */