]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpuset: add ha_cpuset_isset() to check for the presence of a CPU in a set
authorWilly Tarreau <w@1wt.eu>
Thu, 6 Jul 2023 14:39:08 +0000 (16:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 4 Sep 2023 17:39:17 +0000 (19:39 +0200)
This function will be convenient to test for the presence of a given CPU
in a set.

include/haproxy/cpuset.h
src/cpuset.c

index 4f795f2643ae4a4f12746e03aa0b287c91a1914b..dd1043ef556876a6f792b4c3a41b9581f31d5964 100644 (file)
@@ -23,6 +23,9 @@ int ha_cpuset_clr(struct hap_cpuset *set, int cpu);
  */
 void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src);
 
+/* returns non-zero if CPU index <cpu> is set in <set>, otherwise 0. */
+int ha_cpuset_isset(const struct hap_cpuset *set, int cpu);
+
 /* Returns the count of set index in <set>.
  */
 int ha_cpuset_count(const struct hap_cpuset *set);
index 4e1c537620a718fd072067858d6628ad2538f522..b89433a4d034039471655bd6eb6ee010bad4eaf5 100644 (file)
@@ -60,6 +60,21 @@ void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src)
 #endif
 }
 
+int ha_cpuset_isset(const struct hap_cpuset *set, int cpu)
+{
+       if (cpu >= ha_cpuset_size())
+               return 0;
+
+#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)
+       return CPU_ISSET(cpu, &set->cpuset);
+
+#elif defined(CPUSET_USE_ULONG)
+       return !!(set->cpuset & (0x1 << cpu));
+#else
+       return 0;
+#endif
+}
+
 int ha_cpuset_count(const struct hap_cpuset *set)
 {
 #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)