summaryrefslogtreecommitdiff
path: root/graphics/MesaLib/patches/patch-src_util_u__thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/MesaLib/patches/patch-src_util_u__thread.h')
-rw-r--r--graphics/MesaLib/patches/patch-src_util_u__thread.h108
1 files changed, 41 insertions, 67 deletions
diff --git a/graphics/MesaLib/patches/patch-src_util_u__thread.h b/graphics/MesaLib/patches/patch-src_util_u__thread.h
index 64db83fb096..d4e6882b489 100644
--- a/graphics/MesaLib/patches/patch-src_util_u__thread.h
+++ b/graphics/MesaLib/patches/patch-src_util_u__thread.h
@@ -1,95 +1,69 @@
-$NetBSD: patch-src_util_u__thread.h,v 1.4 2020/03/08 10:35:03 tnn Exp $
+$NetBSD: patch-src_util_u__thread.h,v 1.5 2022/03/13 15:50:05 tnn Exp $
Oracle Solaris has pthread_setname_np. illumos does not.
+(actually, newer Illumos does have it, but never mind.)
Don't hard error when there's no pthread_setname_np.
handle NetBSD-style pthread_setaffinity_np(3)
---- src/util/u_thread.h.orig 2020-03-05 21:34:32.000000000 +0000
+--- src/util/u_thread.h.orig 2021-08-04 18:49:29.374474500 +0000
+++ src/util/u_thread.h
-@@ -73,7 +73,7 @@ static inline thrd_t u_thread_create(int
+@@ -129,7 +129,7 @@ static inline thrd_t u_thread_create(int
static inline void u_thread_setname( const char *name )
{
#if defined(HAVE_PTHREAD)
-#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS
+#if DETECT_OS_LINUX || DETECT_OS_CYGWIN
- pthread_setname_np(pthread_self(), name);
- #elif DETECT_OS_FREEBSD || DETECT_OS_OPENBSD
- pthread_set_name_np(pthread_self(), name);
-@@ -104,6 +104,17 @@ static inline void
- util_pin_thread_to_L3(thrd_t thread, unsigned L3_index, unsigned cores_per_L3)
+ int ret = pthread_setname_np(pthread_self(), name);
+ if (ret == ERANGE) {
+ char buf[16];
+@@ -169,8 +169,32 @@ util_set_thread_affinity(thrd_t thread,
+ unsigned num_mask_bits)
{
#if defined(HAVE_PTHREAD_SETAFFINITY)
-+#if defined(__NetBSD__)
-+ cpuset_t *cpuset;
+- cpu_set_t cpuset;
++# if defined(__NetBSD__)
++ cpu_set_t *cpuset;
+ cpuset = cpuset_create();
+ if (cpuset == NULL)
+ return;
-+ cpuset_zero(cpuset);
-+ for (unsigned i = 0; i < cores_per_L3; i++)
-+ cpuset_set(L3_index * cores_per_L3 + i, cpuset);
-+ pthread_setaffinity_np(thread, cpuset_size(cpuset), cpuset);
-+ cpuset_destroy(cpuset);
-+#else
- cpu_set_t cpuset;
++ if (old_mask) {
++ if (pthread_getaffinity_np(thread, cpuset_size(cpuset), cpuset) != 0)
++ return false;
- CPU_ZERO(&cpuset);
-@@ -111,6 +122,7 @@ util_pin_thread_to_L3(thrd_t thread, uns
- CPU_SET(L3_index * cores_per_L3 + i, &cpuset);
- pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
- #endif
-+#endif
- }
-
- /**
-@@ -124,6 +136,35 @@ static inline int
- util_get_L3_for_pinned_thread(thrd_t thread, unsigned cores_per_L3)
- {
- #if defined(HAVE_PTHREAD_SETAFFINITY)
-+#if defined(__NetBSD__)
-+ cpuset_t *cpuset;
-+
-+ cpuset = cpuset_create();
-+ if (cpuset == NULL)
-+ return -1;
-+
-+ if (pthread_getaffinity_np(thread, cpuset_size(cpuset), cpuset) == 0) {
-+ int L3_index = -1;
-+
-+ for (unsigned i = 0; i < cpuset_size(cpuset); i++) {
-+ if (cpuset_isset(i, cpuset)) {
-+ int x = i / cores_per_L3;
-+
-+ if (L3_index != x) {
-+ if (L3_index == -1)
-+ L3_index = x;
-+ else {
-+ cpuset_destroy(cpuset);
-+ return -1; /* multiple L3s are set */
-+ }
-+ }
-+ }
++ memset(old_mask, 0, num_mask_bits / 8);
++ for (unsigned i = 0; i < num_mask_bits && i < CPU_SETSIZE; i++) {
++ if (cpuset_isset(i, cpuset))
++ old_mask[i / 32] |= 1u << (i % 32);
+ }
-+ cpuset_destroy(cpuset);
-+ return L3_index;
+ }
++
++ cpuset_zero(cpuset);
++ for (unsigned i = 0; i < num_mask_bits && i < CPU_SETSIZE; i++) {
++ if (mask[i / 32] & (1u << (i % 32)))
++ cpuset_set(i, cpuset);
++ }
++ int err = pthread_setaffinity_np(thread, cpuset_size(cpuset), cpuset);
+ cpuset_destroy(cpuset);
-+#else
- cpu_set_t cpuset;
-
- if (pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset) == 0) {
-@@ -144,6 +185,7 @@ util_get_L3_for_pinned_thread(thrd_t thr
- return L3_index;
++ return err == 0;
++# else
++ cpu_set_t cpuset;
+ if (old_mask) {
+ if (pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset) != 0)
+ return false;
+@@ -188,7 +212,7 @@ util_set_thread_affinity(thrd_t thread,
+ CPU_SET(i, &cpuset);
}
- #endif
-+#endif
- return -1;
- }
+ return pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset) == 0;
+-
++# endif
+ #elif defined(_WIN32) && !defined(__CYGWIN__)
+ DWORD_PTR m = mask[0];
-@@ -155,7 +197,7 @@ util_get_L3_for_pinned_thread(thrd_t thr
+@@ -242,7 +266,7 @@ util_set_current_thread_affinity(const u
static inline int64_t
- u_thread_get_time_nano(thrd_t thread)
+ util_thread_get_time_nano(thrd_t thread)
{
-#if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__)
+#if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__) && !defined(__sun)