From nobody Tue Jun 07 14:23:28 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 6DD597CAA77; Tue, 7 Jun 2022 14:23:29 +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 4LHXds1TZqz3r8C; Tue, 7 Jun 2022 14:23:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654611809; 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=oomoAwModeDO//DQR/c4gRTLCSLdbLfPqZSlN50nYRs=; b=qz8vjZJI4l46SkK7Aen7nsGiwm+TCEAbsnDGfrfSw5yiOBuSlvy0hv4BhvjLvgS2sIsBQO eWRt5wUANE22AtIJ+4VsEBy0jNJH6Ns6gIKhjCn8VA11cktVtYIt+k4wmgKJuUcw8fAMTB DP/gf+zDy0HV9e4n2BTpjj64pr5dJ9KW2CftIJk91TVOZ6uwbZmpE/h6lJYxEUtvbDGxLl w8V7y3vfHwSo9+PS6FiGbokPa/qXsDRK7Dx22ueKPqjc9x7B+s/87T5wtnVGOax8zFVawz ciyrsh5/E3b3M2SJMDLCSOKMIloaS0HAEoVAFJBYYMXVnJMaE7mpdP1Ocfm7Vg== 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 E809D1CC03; Tue, 7 Jun 2022 14:23:28 +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 257ENSRb020277; Tue, 7 Jun 2022 14:23:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 257ENSIs020276; Tue, 7 Jun 2022 14:23:28 GMT (envelope-from git) Date: Tue, 7 Jun 2022 14:23:28 GMT Message-Id: <202206071423.257ENSIs020276@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: 6173c7833be4 - stable/13 - Remove PAGE_SIZE from libthr 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6173c7833be4d3bcc8e76031a96c49039a77878e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654611809; 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=oomoAwModeDO//DQR/c4gRTLCSLdbLfPqZSlN50nYRs=; b=MAWtqSsrYHUXpY1nUBIcgazoMZFfkwuv6TVhsjBY8lWecEBSCiMZbFqBP5RhArB56Q7thg okeFy+bjzVC39Nu3aF5/pGA8DyiXDkgJAJkI31Bv1w1NhFXzAbVQ5lE8FyB6pADCmImOnN 87i0cCKQ4Xs0fvBd2S1MUAdLNWjq15T/QFje2KVOjJ92jsNU3+/nDTUXfHn4BQ4ajCt1uZ C1Rh1tNj4NR6gA56pzF8My+CQFxcYj6EOaDF985XNJ6B8v6J/iNxEgc4SKJWYThaoAzNcw fbjdbv4AptNkntB260lagnBt+fZmKvNIdZnoQ5OBApXHy8/qbFOUW/1zloGd7Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1654611809; a=rsa-sha256; cv=none; b=XFao1HavaWygz0UwnKxjcdu8IRvAOMbhLo18ZWvr/5FFXJx4TQB27EXjnU8I8DBtNfpbaG hJZzPltrzIaSM4VbPMqIzOat77Kf2Hd4Bd8zj1m8/PzkUa61iwdaYefQWiF809fTo582MV wAAL6Z8zuC/4RLVPoWUTunFTSU665jACXC/kLy6tPaWH+CHhsQzVtbGECoCyzKFVdn5BhF gJHzU6AwnviPXV1zXylorf7aPaf2SzYdkRWaEApaaSNnKkleAS5aMXwYLwvQZwziKrCEMv LehA/lK1BY05fbJfQtJga6qwuTFjSy3S1yX2dtijEoGo0FL8HQzl156Y2oiyhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=6173c7833be4d3bcc8e76031a96c49039a77878e commit 6173c7833be4d3bcc8e76031a96c49039a77878e Author: Andrew Turner AuthorDate: 2022-04-07 16:24:46 +0000 Commit: Andrew Turner CommitDate: 2022-06-07 14:20:18 +0000 Remove PAGE_SIZE from libthr In libthr we use PAGE_SIZE when allocating memory with mmap and to check various structs will fit into a single page so we can use this allocator for them. Ask the kernel for the page size on init for use by the page allcator and add a new machine dependent macro to hold the smallest page size the architecture supports to check the structure is small enough. This allows us to use the same libthr on arm64 with either 4k or 16k pages. Reviewed by: kib, markj, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34984 (cherry picked from commit c7904405a8d47f64c3b0e73158572e2dc8ef0217) --- lib/libthr/arch/aarch64/include/pthread_md.h | 3 +++ lib/libthr/arch/amd64/include/pthread_md.h | 3 +++ lib/libthr/arch/arm/include/pthread_md.h | 3 +++ lib/libthr/arch/i386/include/pthread_md.h | 3 +++ lib/libthr/arch/powerpc/include/pthread_md.h | 3 +++ lib/libthr/arch/riscv/include/pthread_md.h | 3 +++ lib/libthr/thread/thr_barrier.c | 2 +- lib/libthr/thread/thr_cond.c | 2 +- lib/libthr/thread/thr_malloc.c | 3 +-- lib/libthr/thread/thr_mutex.c | 2 +- lib/libthr/thread/thr_pshared.c | 13 +++++++++---- lib/libthr/thread/thr_pspinlock.c | 2 +- lib/libthr/thread/thr_rwlock.c | 2 +- 13 files changed, 33 insertions(+), 11 deletions(-) diff --git a/lib/libthr/arch/aarch64/include/pthread_md.h b/lib/libthr/arch/aarch64/include/pthread_md.h index f3ce2d0bdbce..2ae5a0d2e808 100644 --- a/lib/libthr/arch/aarch64/include/pthread_md.h +++ b/lib/libthr/arch/aarch64/include/pthread_md.h @@ -41,6 +41,9 @@ #define CPU_SPINWAIT +/* For use in _Static_assert to check structs will fit in a page */ +#define THR_PAGE_SIZE_MIN PAGE_SIZE_4K + static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index d7bf5d5e5753..acfbd551b3de 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -41,6 +41,9 @@ #define CPU_SPINWAIT __asm __volatile("pause") +/* For use in _Static_assert to check structs will fit in a page */ +#define THR_PAGE_SIZE_MIN PAGE_SIZE + static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h index 75570337c627..dfd7e7d951bf 100644 --- a/lib/libthr/arch/arm/include/pthread_md.h +++ b/lib/libthr/arch/arm/include/pthread_md.h @@ -39,6 +39,9 @@ #define CPU_SPINWAIT +/* For use in _Static_assert to check structs will fit in a page */ +#define THR_PAGE_SIZE_MIN PAGE_SIZE + static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index 525a9c4368a3..8940acee6fee 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -41,6 +41,9 @@ #define CPU_SPINWAIT __asm __volatile("pause") +/* For use in _Static_assert to check structs will fit in a page */ +#define THR_PAGE_SIZE_MIN PAGE_SIZE + static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index 10c787ae189a..076c43e1ef43 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -40,6 +40,9 @@ #define CPU_SPINWAIT +/* For use in _Static_assert to check structs will fit in a page */ +#define THR_PAGE_SIZE_MIN PAGE_SIZE + static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/riscv/include/pthread_md.h index 092d40266e1c..7c7b9a787c24 100644 --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/riscv/include/pthread_md.h @@ -46,6 +46,9 @@ #define CPU_SPINWAIT +/* For use in _Static_assert to check structs will fit in a page */ +#define THR_PAGE_SIZE_MIN PAGE_SIZE + static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/thread/thr_barrier.c b/lib/libthr/thread/thr_barrier.c index fa205ad509c9..fc42588cb412 100644 --- a/lib/libthr/thread/thr_barrier.c +++ b/lib/libthr/thread/thr_barrier.c @@ -37,7 +37,7 @@ __FBSDID("$FreeBSD$"); #include "thr_private.h" -_Static_assert(sizeof(struct pthread_barrier) <= PAGE_SIZE, +_Static_assert(sizeof(struct pthread_barrier) <= THR_PAGE_SIZE_MIN, "pthread_barrier is too large for off-page"); __weak_reference(_pthread_barrier_init, pthread_barrier_init); diff --git a/lib/libthr/thread/thr_cond.c b/lib/libthr/thread/thr_cond.c index 9eba3dd437f0..925792a92662 100644 --- a/lib/libthr/thread/thr_cond.c +++ b/lib/libthr/thread/thr_cond.c @@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$"); #include "thr_private.h" -_Static_assert(sizeof(struct pthread_cond) <= PAGE_SIZE, +_Static_assert(sizeof(struct pthread_cond) <= THR_PAGE_SIZE_MIN, "pthread_cond too large"); /* diff --git a/lib/libthr/thread/thr_malloc.c b/lib/libthr/thread/thr_malloc.c index 80a81f9c6c27..b4a627cc55eb 100644 --- a/lib/libthr/thread/thr_malloc.c +++ b/lib/libthr/thread/thr_malloc.c @@ -51,8 +51,7 @@ __thr_malloc_init(void) return; npagesizes = getpagesizes(pagesizes_d, nitems(pagesizes_d)); if (npagesizes == -1) { - npagesizes = 1; - pagesizes_d[0] = PAGE_SIZE; + PANIC("Unable to read page sizes"); } pagesizes = pagesizes_d; _thr_umutex_init(&thr_malloc_umtx); diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index 303386db7fe7..8dccdf4dfa8c 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$"); #include "thr_private.h" -_Static_assert(sizeof(struct pthread_mutex) <= PAGE_SIZE, +_Static_assert(sizeof(struct pthread_mutex) <= THR_PAGE_SIZE_MIN, "pthread_mutex is too large for off-page"); /* diff --git a/lib/libthr/thread/thr_pshared.c b/lib/libthr/thread/thr_pshared.c index 83714785f9b1..d0219d0488f4 100644 --- a/lib/libthr/thread/thr_pshared.c +++ b/lib/libthr/thread/thr_pshared.c @@ -50,12 +50,17 @@ static struct pshared_hash_head pshared_hash[HASH_SIZE]; #define PSHARED_KEY_HASH(key) (((unsigned long)(key) >> 8) % HASH_SIZE) /* XXXKIB: lock could be split to per-hash chain, if appears contested */ static struct urwlock pshared_lock = DEFAULT_URWLOCK; +static int page_size; void __thr_pshared_init(void) { int i; + page_size = getpagesize(); + THR_ASSERT(page_size >= THR_PAGE_SIZE_MIN, + "THR_PAGE_SIZE_MIN is too large"); + _thr_urwlock_init(&pshared_lock); for (i = 0; i < HASH_SIZE; i++) LIST_INIT(&pshared_hash[i]); @@ -112,7 +117,7 @@ pshared_gc(struct pthread *curthread) if (error == 0) continue; LIST_REMOVE(h, link); - munmap(h->val, PAGE_SIZE); + munmap(h->val, page_size); free(h); } } @@ -164,7 +169,7 @@ pshared_insert(void *key, void **val) */ if (h->key == key) { if (h->val != *val) { - munmap(*val, PAGE_SIZE); + munmap(*val, page_size); *val = h->val; } return (1); @@ -204,7 +209,7 @@ pshared_clean(void *key, void *val) { if (val != NULL) - munmap(val, PAGE_SIZE); + munmap(val, page_size); _umtx_op(NULL, UMTX_OP_SHM, UMTX_SHM_DESTROY, key, NULL); } @@ -225,7 +230,7 @@ __thr_pshared_offpage(void *key, int doalloc) UMTX_SHM_LOOKUP, key, NULL); if (fd == -1) return (NULL); - res = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + res = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); if (res == MAP_FAILED) return (NULL); diff --git a/lib/libthr/thread/thr_pspinlock.c b/lib/libthr/thread/thr_pspinlock.c index c71bdbb3f196..d1a53446f654 100644 --- a/lib/libthr/thread/thr_pspinlock.c +++ b/lib/libthr/thread/thr_pspinlock.c @@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$"); #include "thr_private.h" -_Static_assert(sizeof(struct pthread_spinlock) <= PAGE_SIZE, +_Static_assert(sizeof(struct pthread_spinlock) <= THR_PAGE_SIZE_MIN, "pthread_spinlock is too large for off-page"); #define SPIN_COUNT 100000 diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c index 22c6c878b2a5..1d110a7bf285 100644 --- a/lib/libthr/thread/thr_rwlock.c +++ b/lib/libthr/thread/thr_rwlock.c @@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "thr_private.h" -_Static_assert(sizeof(struct pthread_rwlock) <= PAGE_SIZE, +_Static_assert(sizeof(struct pthread_rwlock) <= THR_PAGE_SIZE_MIN, "pthread_rwlock is too large for off-page"); __weak_reference(_thr_rwlock_destroy, pthread_rwlock_destroy);