From nobody Tue May 03 10:05:53 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 958291ACDF90; Tue, 3 May 2022 10:05:53 +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 4KswZn3bjxz4bMW; Tue, 3 May 2022 10:05:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651572353; 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=QXMh9jxl5WKbrlAbJhXXLXdQ21M8N8cL6rIOS3ktsUw=; b=r4pcna00Y+PtK1aXocgO+C5UFvc/ASxUfMWgD7m5snoCZlCPnd81objap0F1j+oHvuYtTR kRWlALyd17zd/bV9zT2BjSlzrvhKuPgrdJvzjgCOqlhlE0pwms3K8A1qp9LIO5bLsjpaiV A6hpnjUjKMWQ6ipbgWcPZ0GlvSjgMve1jMf5JI1jqDFJJ6AZzeIm64HMxvuoYm+QZEXiPL xoEipyZKUyLxNhMpISIXqyJCMJQ+o6oVuYPgQ5WLHijuVcdekqB1j1pkZK0WLSMByZaHCH n7SwkGb/G74ymJrum58WdLAM8ExakwD1Zn/w6NHpBqaPRArUL1h4hZyuBY7F0w== 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 5AB511C49B; Tue, 3 May 2022 10:05:53 +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 243A5rcP053550; Tue, 3 May 2022 10:05:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 243A5rYK053549; Tue, 3 May 2022 10:05:53 GMT (envelope-from git) Date: Tue, 3 May 2022 10:05:53 GMT Message-Id: <202205031005.243A5rYK053549@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: c7904405a8d4 - main - 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/main X-Git-Reftype: branch X-Git-Commit: c7904405a8d47f64c3b0e73158572e2dc8ef0217 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651572353; 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=QXMh9jxl5WKbrlAbJhXXLXdQ21M8N8cL6rIOS3ktsUw=; b=IbWbshSbWqzT4uMTnxmKSe7B4dV0cGdtKX/tiXCUxgWi71qliJnRp8Bqi5AP541I6elmQB R2fU/YpfhVLIAS3rocu60MvZrg9/P5yTdqcsMZXObgSFbw6ZrYa1aQMCyxPY5R1JhUXg/I jB85rtqA1o2j4fLk8PVC4yycu1hIRKXqtL3QsV7baH2tBv6BmwZtajRpKtrSnatDRGBC7b AchuSGnXrt0TrPDV34OV+4Jk2EiT7Xlb6r/Z9EsnJy6YacGaemhLsCnct79eSp+wk9m6fU EWMxApgi5eXgYRY6vxaN3GYmG2abOqsCRsT7uEQr61A7eMUICvDXSISe1BG3FQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651572353; a=rsa-sha256; cv=none; b=nPpKo5ZuF7XZnO1ZLaTtTEg/X2zz1LYswlgK+i/gFysAWNBI9vzN/dz9Iko8+YQMZCsA9D eCUQH0dhSwNTY6JDDL/65c9/Lk1CCy8n7ZDDeoKUN7b1Bmo/RvpTcFouJWicWshqO1vAV2 TZ6ahZ4vMb8d1CJ+ntAQl/N0pqU699qucx4p6bKLMSNHzopsIGAESqR1A3N5lXhoQyVKSi m5DI6OMuQgM/apqu8sdCUR9n3XpobIHEmFNO9UGeXUSVk6V8LMd4zJJ0I1lKPeDs/+xedi PMyR57XHzFdFEKB5d1P8Oo92Bcx7pXGRuZOu8pOjoiErmElp8Kwwjy27yS6y3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=c7904405a8d47f64c3b0e73158572e2dc8ef0217 commit c7904405a8d47f64c3b0e73158572e2dc8ef0217 Author: Andrew Turner AuthorDate: 2022-04-07 16:24:46 +0000 Commit: Andrew Turner CommitDate: 2022-05-03 10:04:41 +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 --- 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);