hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/linux/cpumask.h
....@@ -10,6 +10,7 @@
1010 #include <linux/kernel.h>
1111 #include <linux/threads.h>
1212 #include <linux/bitmap.h>
13
+#include <linux/atomic.h>
1314 #include <linux/bug.h>
1415
1516 /* Don't assign or return these: may not be this big! */
....@@ -95,8 +96,21 @@
9596 #define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask)
9697 #define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask)
9798
99
+extern atomic_t __num_online_cpus;
100
+
98101 #if NR_CPUS > 1
99
-#define num_online_cpus() cpumask_weight(cpu_online_mask)
102
+/**
103
+ * num_online_cpus() - Read the number of online CPUs
104
+ *
105
+ * Despite the fact that __num_online_cpus is of type atomic_t, this
106
+ * interface gives only a momentary snapshot and is not protected against
107
+ * concurrent CPU hotplug operations unless invoked from a cpuhp_lock held
108
+ * region.
109
+ */
110
+static inline unsigned int num_online_cpus(void)
111
+{
112
+ return atomic_read(&__num_online_cpus);
113
+}
100114 #define num_possible_cpus() cpumask_weight(cpu_possible_mask)
101115 #define num_present_cpus() cpumask_weight(cpu_present_mask)
102116 #define num_active_cpus() cpumask_weight(cpu_active_mask)
....@@ -114,6 +128,8 @@
114128 #define cpu_present(cpu) ((cpu) == 0)
115129 #define cpu_active(cpu) ((cpu) == 0)
116130 #endif
131
+
132
+extern cpumask_t cpus_booted_once_mask;
117133
118134 static inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bits)
119135 {
....@@ -178,14 +194,24 @@
178194 return 0;
179195 }
180196
197
+static inline int cpumask_any_and_distribute(const struct cpumask *src1p,
198
+ const struct cpumask *src2p) {
199
+ return cpumask_next_and(-1, src1p, src2p);
200
+}
201
+
202
+static inline int cpumask_any_distribute(const struct cpumask *srcp)
203
+{
204
+ return cpumask_first(srcp);
205
+}
206
+
181207 #define for_each_cpu(cpu, mask) \
182208 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
183209 #define for_each_cpu_not(cpu, mask) \
184210 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
185211 #define for_each_cpu_wrap(cpu, mask, start) \
186212 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)(start))
187
-#define for_each_cpu_and(cpu, mask, and) \
188
- for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
213
+#define for_each_cpu_and(cpu, mask1, mask2) \
214
+ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2)
189215 #else
190216 /**
191217 * cpumask_first - get the first cpu in a cpumask
....@@ -229,6 +255,9 @@
229255 int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
230256 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
231257 unsigned int cpumask_local_spread(unsigned int i, int node);
258
+int cpumask_any_and_distribute(const struct cpumask *src1p,
259
+ const struct cpumask *src2p);
260
+int cpumask_any_distribute(const struct cpumask *srcp);
232261
233262 /**
234263 * for_each_cpu - iterate over every cpu in a mask
....@@ -274,20 +303,20 @@
274303 /**
275304 * for_each_cpu_and - iterate over every cpu in both masks
276305 * @cpu: the (optionally unsigned) integer iterator
277
- * @mask: the first cpumask pointer
278
- * @and: the second cpumask pointer
306
+ * @mask1: the first cpumask pointer
307
+ * @mask2: the second cpumask pointer
279308 *
280309 * This saves a temporary CPU mask in many places. It is equivalent to:
281310 * struct cpumask tmp;
282
- * cpumask_and(&tmp, &mask, &and);
311
+ * cpumask_and(&tmp, &mask1, &mask2);
283312 * for_each_cpu(cpu, &tmp)
284313 * ...
285314 *
286315 * After the loop, cpu is >= nr_cpu_ids.
287316 */
288
-#define for_each_cpu_and(cpu, mask, and) \
317
+#define for_each_cpu_and(cpu, mask1, mask2) \
289318 for ((cpu) = -1; \
290
- (cpu) = cpumask_next_and((cpu), (mask), (and)), \
319
+ (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \
291320 (cpu) < nr_cpu_ids;)
292321 #endif /* SMP */
293322
....@@ -474,6 +503,20 @@
474503 }
475504
476505 /**
506
+ * cpumask_or_equal - *src1p | *src2p == *src3p
507
+ * @src1p: the first input
508
+ * @src2p: the second input
509
+ * @src3p: the third input
510
+ */
511
+static inline bool cpumask_or_equal(const struct cpumask *src1p,
512
+ const struct cpumask *src2p,
513
+ const struct cpumask *src3p)
514
+{
515
+ return bitmap_or_equal(cpumask_bits(src1p), cpumask_bits(src2p),
516
+ cpumask_bits(src3p), nr_cpumask_bits);
517
+}
518
+
519
+/**
477520 * cpumask_intersects - (*src1p & *src2p) != 0
478521 * @src1p: the first input
479522 * @src2p: the second input
....@@ -633,10 +676,7 @@
633676 */
634677 static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
635678 {
636
- char *nl = strchr(buf, '\n');
637
- unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
638
-
639
- return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
679
+ return bitmap_parse(buf, UINT_MAX, cpumask_bits(dstp), nr_cpumask_bits);
640680 }
641681
642682 /**
....@@ -806,14 +846,7 @@
806846 cpumask_clear_cpu(cpu, &__cpu_present_mask);
807847 }
808848
809
-static inline void
810
-set_cpu_online(unsigned int cpu, bool online)
811
-{
812
- if (online)
813
- cpumask_set_cpu(cpu, &__cpu_online_mask);
814
- else
815
- cpumask_clear_cpu(cpu, &__cpu_online_mask);
816
-}
849
+void set_cpu_online(unsigned int cpu, bool online);
817850
818851 static inline void
819852 set_cpu_active(unsigned int cpu, bool active)