]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: thread: implement the detection of forced cpu affinity
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 31 Mar 2021 14:57:39 +0000 (16:57 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 23 Apr 2021 14:06:49 +0000 (16:06 +0200)
Create a function thread_cpu_mask_forced. Its purpose is to report if a
restrictive cpu mask is active for the current proces, for example due
to a taskset invocation. It is only implemented for the linux platform
currently.

include/haproxy/thread.h
src/thread.c

index e7d6d2cba290e3582b98a3c6eda34c0b94d66207..6a4b400f873ba61872e3e2c110763e3d5c793811 100644 (file)
@@ -277,6 +277,10 @@ static inline unsigned long thread_isolated()
        return threads_want_rdv_mask & ~threads_harmless_mask & tid_bit;
 }
 
+/* Returns 1 if the cpu set is currently restricted for the process else 0.
+ * Currently only implemented for the Linux platform.
+ */
+int thread_cpu_mask_forced();
 
 #if !defined(DEBUG_THREAD) && !defined(DEBUG_FULL)
 
index 07017dd1891a5adc5055025eb11dd2c0680000ab..fd9e6b632ee2b03ff5f04a8cc5e2b878af8ff6cf 100644 (file)
@@ -193,6 +193,19 @@ static int thread_cpus_enabled()
        return ret;
 }
 
+/* Returns 1 if the cpu set is currently restricted for the process else 0.
+ * Currently only implemented for the Linux platform.
+ */
+int thread_cpu_mask_forced()
+{
+#if defined(__linux__)
+       const int cpus_avail = sysconf(_SC_NPROCESSORS_ONLN);
+       return cpus_avail != thread_cpus_enabled();
+#else
+       return 0;
+#endif
+}
+
 /* Depending on the platform and how libpthread was built, pthread_exit() may
  * involve some code in libgcc_s that would be loaded on exit for the first
  * time, causing aborts if the process is chrooted. It's harmless bit very