From nobody Wed Aug 23 00:07:35 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 4RVmkJ17jDz4qfdX; Wed, 23 Aug 2023 00:07:36 +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 4RVmkJ0fpbz4ZX7; Wed, 23 Aug 2023 00:07:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692749256; 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=oaTFZa5MKhlGxSRBelCY4g0z5yt2+aDdEzTKVYNzQ4s=; b=NZRGWqAXg8qRhB7f5H8WV9AvGgbmOWZIFMloaSyHr0LCmKvTbGRmimZu/pSSjnhemx6+gN tNIUKU0+jTE8S5VvPmZ9YMOcg/7HO5v78qRU2zm3IA2dVfPsdWBKs4tSN/wSVlSTC59CVx n/liVUhkXVq3PuVCvXfPXrpVMAZAQQFQ2CwbeepMv2H/AEjm55VO28tDE/ZJtfZ46mIi2d 4ON2PgcCpmKgUq3svQXmgzQCR1k/g3peP5hWDbw5QZIxA7gaoNyLwA35EyUHd5OI6zPCmh h6D8eR/5x9AMUHJWHkkshlRBOVE9JmDFtRiISIbLrmnkLyLOQC7aS395gD8npw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692749256; 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=oaTFZa5MKhlGxSRBelCY4g0z5yt2+aDdEzTKVYNzQ4s=; b=JqxuZt/KO2KL5K0zTXrl9/4CAMjEhn+Z5ukx5+m+N7Yy+G+moDmyvCKaYOjq2tEksZl6aB 5sMjRG25yVh9W+Kp/lpg89YCca19vyUoFb9jrZ/Z8rsaQTChDaUlt2PbDm/WT61ITEBY32 pbWPA+qYcGttIpKeuzb3dsDinWLxjEmlAWrlVKmmIx+l1sXkU1dNFh2/jmBP/bp6kZJid+ yb7P36AFPbyyzyjDfDrE1aHtVEh5Ib7Q1SaWi5XYdbys3k+HQA9H4RgD3CVb46+ksjUhoI faqfGiWkC0c+sUhtikrKiFZU1yX4ES0Zz5xoE+24uxjoCEcTm86KFscWKepADA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692749256; a=rsa-sha256; cv=none; b=HnbI9tUty+Nir47zep0/J9/pDPdxFPHPVlGFqt+S42Zf3kjU6BVuh3wgBYX6kYvfdoO0Y6 aq4RnMUS2cc4P8kjbRnsapvW2YUIxmp+9CMCCT7FKCCUnV1JvduuLYVR+7k08bUOZrk7jA bSrKnZtFE//Xa8qUHI5ulhrM/VuIPeW4JEhUlya/qN8ldzRytCNAH6zk+AHTWQ5Vl2rkX7 fE12yvObUmfV/1v19OtOgJmZJHHK0wpemz/IZo7WWClYMFoTZw9/Ss7NG+BhqyapTFeEA0 Ad1iilJvSPcL1ET5ei4pJ7Vn425DHPALxAx7Oza+butMKXb1ddu0Gs7qO2RoYg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RVmkH6rXYz8cs; Wed, 23 Aug 2023 00:07:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37N07ZPJ082836; Wed, 23 Aug 2023 00:07:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37N07ZCX082833; Wed, 23 Aug 2023 00:07:35 GMT (envelope-from git) Date: Wed, 23 Aug 2023 00:07:35 GMT Message-Id: <202308230007.37N07ZCX082833@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: 8882b7852acf - main - add pmap_active_cpus() 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: 8882b7852acf2588d87ccb6d4c6bf7694511fc56 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8882b7852acf2588d87ccb6d4c6bf7694511fc56 commit 8882b7852acf2588d87ccb6d4c6bf7694511fc56 Author: Konstantin Belousov AuthorDate: 2021-10-07 22:25:54 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-23 00:02:21 +0000 add pmap_active_cpus() For amd64, i386, arm, and riscv, i.e. all architectures except arm64, the custom implementation is provided since we maintain the bitmask of active CPUs anyway. Arm64 uses somewhat naive iteration over CPUs and match current vmspace' pmap with the argument. It is not guaranteed that vmspace->pmap is the same as the active pmap, but the inaccuracy should be toleratable. Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32360 --- sys/amd64/amd64/pmap.c | 6 ++++++ sys/arm/arm/pmap-v6.c | 6 ++++++ sys/arm64/include/pmap.h | 2 ++ sys/i386/i386/pmap_base.c | 6 ++++++ sys/powerpc/powerpc/pmap_dispatch.c | 6 ++++++ sys/riscv/riscv/pmap.c | 6 ++++++ sys/vm/pmap.h | 2 ++ sys/vm/vm_kern.c | 26 ++++++++++++++++++++++++++ 8 files changed, 60 insertions(+) diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index c7151fa59b91..b10997fd657b 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -10256,6 +10256,12 @@ pmap_activate_boot(pmap_t pmap) PCPU_SET(ucr3, PMAP_NO_CR3); } +void +pmap_active_cpus(pmap_t pmap, cpuset_t *res) +{ + *res = pmap->pm_active; +} + void pmap_sync_icache(pmap_t pm, vm_offset_t va, vm_size_t sz) { diff --git a/sys/arm/arm/pmap-v6.c b/sys/arm/arm/pmap-v6.c index 5aa8eb169cad..719851432203 100644 --- a/sys/arm/arm/pmap-v6.c +++ b/sys/arm/arm/pmap-v6.c @@ -6194,6 +6194,12 @@ pmap_activate(struct thread *td) critical_exit(); } +void +pmap_active_cpus(pmap_t pmap, cpuset_t *res) +{ + *res = pmap->pm_active; +} + /* * Perform the pmap work for mincore(2). If the page is not both referenced and * modified by this pmap, returns its physical address so that the caller can diff --git a/sys/arm64/include/pmap.h b/sys/arm64/include/pmap.h index fd8dc8d33f38..1789588210c3 100644 --- a/sys/arm64/include/pmap.h +++ b/sys/arm64/include/pmap.h @@ -129,6 +129,8 @@ extern struct pmap kernel_pmap_store; (uint64_t)(asid) << TTBR_ASID_SHIFT; \ }) +#define PMAP_WANT_ACTIVE_CPUS_NAIVE + extern vm_offset_t virtual_avail; extern vm_offset_t virtual_end; diff --git a/sys/i386/i386/pmap_base.c b/sys/i386/i386/pmap_base.c index b0c3413d1735..50229ee40caa 100644 --- a/sys/i386/i386/pmap_base.c +++ b/sys/i386/i386/pmap_base.c @@ -944,6 +944,12 @@ pmap_kremove(vm_offset_t va) pmap_methods_ptr->pm_kremove(va); } +void +pmap_active_cpus(pmap_t pmap, cpuset_t *res) +{ + *res = pmap->pm_active; +} + extern struct pmap_methods pmap_pae_methods, pmap_nopae_methods; int pae_mode; SYSCTL_INT(_vm_pmap, OID_AUTO, pae_mode, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, diff --git a/sys/powerpc/powerpc/pmap_dispatch.c b/sys/powerpc/powerpc/pmap_dispatch.c index ebf81551fa07..3f1ac937433f 100644 --- a/sys/powerpc/powerpc/pmap_dispatch.c +++ b/sys/powerpc/powerpc/pmap_dispatch.c @@ -253,3 +253,9 @@ pmap_is_valid_memattr(pmap_t pmap __unused, vm_memattr_t mode) return (FALSE); } } + +void +pmap_active_cpus(pmap_t pmap, cpuset_t *res) +{ + *res = pmap->pm_active; +} diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index 20e6ccd22b62..49ee54b37918 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -4687,6 +4687,12 @@ pmap_activate_boot(pmap_t pmap) PCPU_SET(curpmap, pmap); } +void +pmap_active_cpus(pmap_t pmap, cpuset_t *res) +{ + *res = pmap->pm_active; +} + void pmap_sync_icache(pmap_t pmap, vm_offset_t va, vm_size_t sz) { diff --git a/sys/vm/pmap.h b/sys/vm/pmap.h index 7272882132e0..65e909df9b8f 100644 --- a/sys/vm/pmap.h +++ b/sys/vm/pmap.h @@ -90,6 +90,7 @@ typedef struct pmap_statistics *pmap_statistics_t; #include #ifdef _KERNEL +#include struct thread; /* @@ -118,6 +119,7 @@ extern vm_offset_t kernel_vm_end; #define PMAP_TS_REFERENCED_MAX 5 void pmap_activate(struct thread *td); +void pmap_active_cpus(pmap_t pmap, cpuset_t *res); void pmap_advise(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, int advice); void pmap_align_superpage(vm_object_t, vm_ooffset_t, vm_offset_t *, diff --git a/sys/vm/vm_kern.c b/sys/vm/vm_kern.c index c3695b5c94eb..f94200d77c47 100644 --- a/sys/vm/vm_kern.c +++ b/sys/vm/vm_kern.c @@ -78,6 +78,7 @@ #include #include #include +#include #include #include #include @@ -907,6 +908,31 @@ kmem_bootstrap_free(vm_offset_t start, vm_size_t size) #endif } +#ifdef PMAP_WANT_ACTIVE_CPUS_NAIVE +void +pmap_active_cpus(pmap_t pmap, cpuset_t *res) +{ + struct thread *td; + struct proc *p; + struct vmspace *vm; + int c; + + CPU_ZERO(res); + CPU_FOREACH(c) { + td = cpuid_to_pcpu[c]->pc_curthread; + p = td->td_proc; + if (p == NULL) + continue; + vm = vmspace_acquire_ref(p); + if (vm == NULL) + continue; + if (pmap == vmspace_pmap(vm)) + CPU_SET(c, res); + vmspace_free(vm); + } +} +#endif + /* * Allow userspace to directly trigger the VM drain routine for testing * purposes.