From nobody Fri Jun 17 19:40:08 2022 X-Original-To: dev-commits-src-branches@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 9459F85CAEA; Fri, 17 Jun 2022 19:40:10 +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 4LPqBd31Q8z3hGt; Fri, 17 Jun 2022 19:40:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494810; 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=9QFhmQGQXhiIAQcq4lWDS67MUEDuzbra8ucjMHctUDg=; b=Bow2tx1DZmISXq3TnGP1F1O20UZyAsTVjA6jGRlwWW/vgQj+NL4UHLUrcFw/WWbAnfCGD+ 6fxo1qvr8Z28MucstnDD/sXrLUtR0Xey9NSryVGOGLcRySlTvJVPRJC37ToCqzdSVQMNVu 1YD6S8g4VV6TWz3gGkDRCioa4nan7916mpM4rsuLs+ma9BeduO9aN1wwsFTJ4a+mWn7W5G a6eaIYJ9d6T16mAx7tstJqYFtRlEQ6YWiT8b2DxMWyBK0CstjO+X84wkpTPVkAgrEhneKJ +a/f3uDg/q0l+Jf/5u6s4z3Ig76ZyXIOxSksIsamZ7zGoOlwtS7k0RkFfw4jaA== 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 3616C25C60; Fri, 17 Jun 2022 19:40:08 +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 25HJe8JG019928; Fri, 17 Jun 2022 19:40:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJe8Ug019925; Fri, 17 Jun 2022 19:40:08 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:40:08 GMT Message-Id: <202206171940.25HJe8Ug019925@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: e7a07ad1dbff - stable/13 - linux(4): Implement vdso getcpu for x86. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: e7a07ad1dbffd63f596459596428e4c8390e866b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494810; 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=9QFhmQGQXhiIAQcq4lWDS67MUEDuzbra8ucjMHctUDg=; b=caONAWMHJFF1hfon66cPkuOhL3IbuBycrcD+efcACFd4XHQ3TqngXt8gwIQ6lCmOqHCPtV lGhlgRx3ic+OKRair3D60oZRArOJrflqkjsHoZEulSNsvHwABr54BYd+lGo7m2zCvAxu2J grb8ittIws7qyxrmrGZ1wnZLxGqp87KG21rWnt0gsyn7zNV0c1p5JogpvTQqDgndYPqcpt vtH9gOyjNR23o7ANCnZR1AqyfG5LiYKAY4gKD4nrJ9rpkvC/hbS4cZju0qEf38HrPM/csz WsO3qa8GaU7thm4eHRgaZgVR0tRJXtcwoKBHREUHilS4JXuPK4NYr86EJFxM7A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494810; a=rsa-sha256; cv=none; b=C+Y66GEC57TclD2uCLzI013wwUpHX5TROD+y91sZCfnEzN0J8sIeJ0TK7ye7vGE7SScc/Z F/hQXGvK+akOpoz+xpqQah1eXx9wWa5+PxgTkNcGxkcnwNmKlGhlJytAe8eCH84azJg0fy lOk7mRFoeN82Kh8xjBLMQ8MWF1XZt6nEwz1FYLuIULUpdSqUDyLgCHB3z2/SPRLS63JraU sC+uDQc6fWJL5B1ozFDsyDyI/uNv12s+05e7Hk6FSqS5WgewYZyWPWU5Oi+glttIPb9Jfi PH2y20Yyioo+w20yXIhja8lisepETprFmSHTRTfqWu76YII1CwQv1ZdpyenK6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=e7a07ad1dbffd63f596459596428e4c8390e866b commit e7a07ad1dbffd63f596459596428e4c8390e866b Author: Dmitry Chagin AuthorDate: 2022-05-08 14:20:52 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:35:00 +0000 linux(4): Implement vdso getcpu for x86. This is modeled after f2395455 (by kib@). MFC after: 2 weeks (cherry picked from commit 5a6a4fb284b1a9c4b4105fd6ab8143356f3ef3f7) --- 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 308f6529ad38..cccf0bff1d5b 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 @@ -836,6 +837,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 227cefa92847..04f34a6561df 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); /* @@ -999,6 +1000,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 4662392b65b8..029ec652e0c0 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 @@ -941,6 +942,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_ */