[Mesa-dev] [PATCH] util/u_thread: don't restrict u_thread_get_time_nano() to __linux__
pthread_getcpuclockid() and clock_gettime() are also available on at least OpenBSD, FreeBSD, NetBSD, DragonFly, Cygwin. Signed-off-by: Jonathan Gray --- src/util/u_thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/u_thread.h b/src/util/u_thread.h index 6fc923c10e6..461d30bdd12 100644 --- a/src/util/u_thread.h +++ b/src/util/u_thread.h @@ -149,7 +149,7 @@ util_get_L3_for_pinned_thread(thrd_t thread, unsigned cores_per_L3) static inline int64_t u_thread_get_time_nano(thrd_t thread) { -#if defined(__linux__) && defined(HAVE_PTHREAD) +#if defined(HAVE_PTHREAD) struct timespec ts; clockid_t cid; -- 2.24.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] util/anon_file: add OpenBSD shm_mkstemp() path
memfd_create() is a linux syscall replace the use of it with shm_mkstemp() on OpenBSD. unconditionally include stdlib.h for mkstemp()/mkostemp() Signed-off-by: Jonathan Gray --- src/util/anon_file.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/anon_file.c b/src/util/anon_file.c index bd415adb647..6c8885707f4 100644 --- a/src/util/anon_file.c +++ b/src/util/anon_file.c @@ -33,16 +33,15 @@ #include #include #include +#include -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include #elif defined(HAVE_MEMFD_CREATE) || defined(ANDROID) #include #include -#include #else #include -#include #endif #if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(HAVE_MKOSTEMP) || defined(ANDROID)) @@ -119,6 +118,11 @@ os_create_anonymous_file(off_t size, const char *debug_name) #ifdef __FreeBSD__ (void*)debug_name; fd = shm_open(SHM_ANON, O_CREAT | O_RDWR | O_CLOEXEC, 0600); +#elif defined(__OpenBSD__) + char template[] = "/tmp/mesa-XX"; + fd = shm_mkstemp(template); + if (fd != -1) + shm_unlink(template); #elif defined(HAVE_MEMFD_CREATE) || defined(ANDROID) if (!debug_name) debug_name = "mesa-shared"; -- 2.24.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] util/futex: use futex syscall on OpenBSD
Make use of the futex syscall added in OpenBSD 6.2. Signed-off-by: Jonathan Gray --- src/util/futex.h | 18 ++ 1 file changed, 18 insertions(+) diff --git a/src/util/futex.h b/src/util/futex.h index 268af92882a..cf8dd0206c9 100644 --- a/src/util/futex.h +++ b/src/util/futex.h @@ -85,6 +85,24 @@ static inline int futex_wait(uint32_t *addr, int32_t value, struct timespec *tim return _umtx_op(addr, UMTX_OP_WAIT_UINT, (uint32_t)value, uaddr, uaddr2) == -1 ? errno : 0; } +#elif defined(__OpenBSD__) + +#include +#include + +static inline int futex_wake(uint32_t *addr, int count) +{ + return futex(addr, FUTEX_WAKE, count, NULL, NULL); +} + +static inline int futex_wait(uint32_t *addr, int32_t value, const struct timespec *timeout) +{ + struct timespec tsrel, tsnow; + clock_gettime(CLOCK_MONOTONIC, &tsnow); + timespecsub(timeout, &tsrel, &tsrel); + return futex(addr, FUTEX_WAIT, value, &tsrel, NULL); +} + #endif #endif /* UTIL_FUTEX_H */ -- 2.24.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 2/2] anv: implement OpenBSD get_available_system_memory()
map linux /proc/meminfo "MemAvailable" to uvm free pages Signed-off-by: Jonathan Gray --- src/intel/vulkan/anv_device.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 81e3905ae99..ce93718c106 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -370,6 +370,16 @@ anv_physical_device_free_disk_cache(struct anv_physical_device *device) static uint64_t get_available_system_memory() { +#ifdef __OpenBSD__ + int uvmexp_mib[] = { CTL_VM, VM_UVMEXP }; + struct uvmexp uvmexp; + size_t size; + + size = sizeof(uvmexp); + if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) == -1) + return 0; + return uvmexp.free * uvmexp.pagesize; +#else char *meminfo = os_read_file("/proc/meminfo"); if (!meminfo) return 0; @@ -388,6 +398,7 @@ get_available_system_memory() free(meminfo); return 0; +#endif } static VkResult -- 2.24.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 1/2] anv: get total system memory on OpenBSD
Use sysctl to get total ram on OpenBSD where sysinfo() is not available. Signed-off-by: Jonathan Gray --- src/intel/vulkan/anv_device.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 250f75e9936..81e3905ae99 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -25,7 +25,12 @@ #include #include #include +#ifdef __OpenBSD__ +#include +#include +#else #include +#endif #include #include #include @@ -97,10 +102,19 @@ static uint64_t anv_compute_heap_size(int fd, uint64_t gtt_size) { /* Query the total ram from the system */ +#ifdef __OpenBSD__ + int mib[] = { CTL_HW, HW_PHYSMEM64 }; + int64_t total_ram; + size_t size = sizeof(total_ram); + + if (sysctl(mib, 2, &total_ram, &size, NULL, 0) == -1) + return 0; +#else struct sysinfo info; sysinfo(&info); uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit; +#endif /* We don't want to burn too much ram with the GPU. If the user has 4GiB * or less, we use at most half. If they have more than 4GiB, we use 3/4. -- 2.24.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/2] anv: implement OpenBSD get_available_system_memory()
On Sun, Dec 01, 2019 at 02:21:49AM +1100, Jonathan Gray wrote: > map linux /proc/meminfo "MemAvailable" to uvm free pages On second thought HW_USERMEM64 may be a better fit here. "The amount of available non-kernel memory in bytes" Which ends up being physmem - uvmexp.wired (memory that can't be paged out) instead of the current amount of free memory. > > Signed-off-by: Jonathan Gray > --- > src/intel/vulkan/anv_device.c | 11 +++ > 1 file changed, 11 insertions(+) > > diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c > index 81e3905ae99..ce93718c106 100644 > --- a/src/intel/vulkan/anv_device.c > +++ b/src/intel/vulkan/anv_device.c > @@ -370,6 +370,16 @@ anv_physical_device_free_disk_cache(struct > anv_physical_device *device) > static uint64_t > get_available_system_memory() > { > +#ifdef __OpenBSD__ > + int uvmexp_mib[] = { CTL_VM, VM_UVMEXP }; > + struct uvmexp uvmexp; > + size_t size; > + > + size = sizeof(uvmexp); > + if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) == -1) > + return 0; > + return uvmexp.free * uvmexp.pagesize; > +#else > char *meminfo = os_read_file("/proc/meminfo"); > if (!meminfo) >return 0; > @@ -388,6 +398,7 @@ get_available_system_memory() > > free(meminfo); > return 0; > +#endif > } > > static VkResult > -- > 2.24.0 > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/2] anv: implement OpenBSD get_available_system_memory()
On Sun, Dec 01, 2019 at 03:22:01AM +1100, Jonathan Gray wrote: > On Sun, Dec 01, 2019 at 02:21:49AM +1100, Jonathan Gray wrote: > > map linux /proc/meminfo "MemAvailable" to uvm free pages > > On second thought HW_USERMEM64 may be a better fit here. > > "The amount of available non-kernel memory in bytes" > > Which ends up being physmem - uvmexp.wired (memory that can't be paged > out) instead of the current amount of free memory. Along the lines of this: commit e9d96571d3670de169595c2009e7a49febd7cd2d Author: Jonathan Gray Date: Wed Nov 27 01:01:44 2019 +1100 anv: implement OpenBSD get_available_system_memory() Determine a value for how much memory a process can allocate without failing not exceeding amount of physical memory available to userspace. v2: use the smallest value of available non-kernel physical memory and per process data size limit. Signed-off-by: Jonathan Gray diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 2a2041535c5..eddcf727f8a 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -28,6 +28,7 @@ #ifdef __OpenBSD__ #include #include +#include #else #include #endif @@ -369,6 +370,22 @@ anv_physical_device_free_disk_cache(struct anv_physical_device *device) static uint64_t get_available_system_memory() { +#ifdef __OpenBSD__ + struct rlimit rl; + int mib[] = { CTL_HW, HW_USERMEM64 }; + int64_t mem_available; + size_t size = sizeof(mem_available); + + /* physmem - wired */ + if (sysctl(mib, 2, &mem_available, &size, NULL, 0) == -1) + return 0; + + /* fixed login.conf limit */ + if (getrlimit(RLIMIT_DATA, &rl) == -1) + return 0; + + return MIN2(mem_available, rl.rlim_cur); +#else char *meminfo = os_read_file("/proc/meminfo"); if (!meminfo) return 0; @@ -387,6 +404,7 @@ get_available_system_memory() free(meminfo); return 0; +#endif } static VkResult ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev