mirror of
https://github.com/opnsense/src.git
synced 2026-05-14 18:20:21 -04:00
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
This commit is contained in:
parent
86c500937c
commit
c7904405a8
13 changed files with 33 additions and 11 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue