From nobody Fri Jan 14 18:10:20 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 12C36194245D; Fri, 14 Jan 2022 18:10:21 +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 4Jb8V44ZHRz4p0C; Fri, 14 Jan 2022 18:10:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642183820; 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=Kjx85EcT1T+Vj4o4/EVL8RFImOoplfE51EdmEOaYGpQ=; b=fWd2tMAaB4APjmvJX8+YDb85ede7SgMSkKqyPHM4c9mQA4ZkXZsyG0sgc1jS1v/J+0nfBo EpNBPlipkXoEedOFKq8XXOvvMRMk69cLlUxqfG1z0ooB36uzNve5mvXSwpAUc2ivUqYPVy Tcfkg6NCAASB6Vw6Xg+eFyK4rj3/5B/jd2wyAD44t7OZqowRtKDq0IxDRbI3OC/QDurvia WzwQlPVJqpTaOML7Pkot5rYmjUGCthNLdVYmc/dQp1jx+nkXCHIDBi+F3JaMuhzuo4QdLa kafgFe0URjhUB4NhS4W9yeLhKZdaXqxhHHHLU37Au7+f5+T5/RBhHIaxylbnxw== 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 48B7C1860E; Fri, 14 Jan 2022 18:10:20 +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 20EIAKvG094434; Fri, 14 Jan 2022 18:10:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EIAK0Q094428; Fri, 14 Jan 2022 18:10:20 GMT (envelope-from git) Date: Fri, 14 Jan 2022 18:10:20 GMT Message-Id: <202201141810.20EIAK0Q094428@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: d3e9527a1063 - stable/13 - x86: provide userspace implementation of sched_getcpu() where possible 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d3e9527a1063ab0e7a111351e7ddeff4e307708b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642183820; 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=Kjx85EcT1T+Vj4o4/EVL8RFImOoplfE51EdmEOaYGpQ=; b=W3Ia+eFAfU+q53R0B/JG5eynEvgAuqkXxZKAcb1BSmfxU88Nqsy7gE4e8AuJX06EbYgVko 6zeOz+t6qeNs1zWzpT8j0fRKfHUYD5H6979nHc/n02J8RTtwoQdr+QWvx/dHW8EZ7vVCsF lQfRmFDbA3xQ+Wo4BwNsHbUQkXiOzgIeaEJPyL9tElryoY2bwIakEu3Z6lxLumkVajCjaE yKkj+rGikSWzvf6evlJ+6Dosh9/rVF9aJaE4+l90nqEvCFjqn26anLbEsLX1Biz5sFbjoR uiVsG17r7Nw3952xptkysMucU50Qwtw5Ly9UcdIBcKK/XvVMQ75w+ZVoQFaFlw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642183820; a=rsa-sha256; cv=none; b=S+VioU9kMbsXdahuY7B6JYvI4Ix88JxDvf5WWhasxfe3px4LYXh9NCLF0k3txVfZcuPqn5 Nw3rGNtHAQXiDss5l1eSYztpmvO6TSDvtk6YPjKP+EE8qM3A8K7HBwvpqXqzybp6mN+qok QTP/WbZnLtaWZN9zOetbZ/5/MkYtmrFAK+uw0bejXcww5ske7q95kV4RS8c/rKsV0IYqNF xu5Movun0+N78G1YQTsNIbGPgzBAxPsctVs/FDRH+Q+9GDtpblW3Ah9JsMMvT4JXJNOeS8 g1YxaPW8VTv72XoOtMtrDPTU12bnNL5baUvx2UHBy/6Ev/4ixrH6KRnWbMHykQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d3e9527a1063ab0e7a111351e7ddeff4e307708b commit d3e9527a1063ab0e7a111351e7ddeff4e307708b Author: Konstantin Belousov AuthorDate: 2021-10-31 01:39:31 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-14 16:17:29 +0000 x86: provide userspace implementation of sched_getcpu() where possible (cherry picked from commit f239545591a821386f9bdb84c02044884ad415b5) --- lib/libc/x86/sys/Makefile.inc | 2 +- lib/libc/x86/sys/sched_getcpu_x86.c | 81 +++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/lib/libc/x86/sys/Makefile.inc b/lib/libc/x86/sys/Makefile.inc index 8aa4948a3295..ef0bfbdbe706 100644 --- a/lib/libc/x86/sys/Makefile.inc +++ b/lib/libc/x86/sys/Makefile.inc @@ -5,7 +5,7 @@ SRCS+= \ __vdso_gettc.c \ pkru.c \ - sched_getcpu_gen.c + sched_getcpu_x86.c MAN+= \ pkru.3 diff --git a/lib/libc/x86/sys/sched_getcpu_x86.c b/lib/libc/x86/sys/sched_getcpu_x86.c new file mode 100644 index 000000000000..13ba18ef5e36 --- /dev/null +++ b/lib/libc/x86/sys/sched_getcpu_x86.c @@ -0,0 +1,81 @@ +/*- + * Copyright (c) 2021 The FreeBSD Foundation + * + * 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 +#include +#include +#include +#include +#include +#include +#include "libc_private.h" + +static int +sched_getcpu_sys(void) +{ + return (__sys_sched_getcpu()); +} + +static int +sched_getcpu_rdpid(void) +{ + register_t res; + + __asm("rdpid %0" : "=r" (res)); + return ((int)res); +} + +static int +sched_getcpu_rdtscp(void) +{ + int res; + + __asm("rdtscp" : "=c" (res) : : "eax", "edx"); + return (res); +} + +DEFINE_UIFUNC(, int, sched_getcpu, (void)) +{ + u_int amd_feature, cpu_exthigh, p[4]; + + if ((cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0) + return (sched_getcpu_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 ? + sched_getcpu_sys : sched_getcpu_rdtscp); +}