hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
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,19 @@
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
+
181202 #define for_each_cpu(cpu, mask) \
182203 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
183204 #define for_each_cpu_not(cpu, mask) \
184205 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
185206 #define for_each_cpu_wrap(cpu, mask, start) \
186207 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)
208
+#define for_each_cpu_and(cpu, mask1, mask2) \
209
+ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2)
189210 #else
190211 /**
191212 * cpumask_first - get the first cpu in a cpumask
....@@ -229,6 +250,8 @@
229250 int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
230251 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
231252 unsigned int cpumask_local_spread(unsigned int i, int node);
253
+int cpumask_any_and_distribute(const struct cpumask *src1p,
254
+ const struct cpumask *src2p);
232255
233256 /**
234257 * for_each_cpu - iterate over every cpu in a mask
....@@ -274,20 +297,20 @@
274297 /**
275298 * for_each_cpu_and - iterate over every cpu in both masks
276299 * @cpu: the (optionally unsigned) integer iterator
277
- * @mask: the first cpumask pointer
278
- * @and: the second cpumask pointer
300
+ * @mask1: the first cpumask pointer
301
+ * @mask2: the second cpumask pointer
279302 *
280303 * This saves a temporary CPU mask in many places. It is equivalent to:
281304 * struct cpumask tmp;
282
- * cpumask_and(&tmp, &mask, &and);
305
+ * cpumask_and(&tmp, &mask1, &mask2);
283306 * for_each_cpu(cpu, &tmp)
284307 * ...
285308 *
286309 * After the loop, cpu is >= nr_cpu_ids.
287310 */
288
-#define for_each_cpu_and(cpu, mask, and) \
311
+#define for_each_cpu_and(cpu, mask1, mask2) \
289312 for ((cpu) = -1; \
290
- (cpu) = cpumask_next_and((cpu), (mask), (and)), \
313
+ (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \
291314 (cpu) < nr_cpu_ids;)
292315 #endif /* SMP */
293316
....@@ -474,6 +497,20 @@
474497 }
475498
476499 /**
500
+ * cpumask_or_equal - *src1p | *src2p == *src3p
501
+ * @src1p: the first input
502
+ * @src2p: the second input
503
+ * @src3p: the third input
504
+ */
505
+static inline bool cpumask_or_equal(const struct cpumask *src1p,
506
+ const struct cpumask *src2p,
507
+ const struct cpumask *src3p)
508
+{
509
+ return bitmap_or_equal(cpumask_bits(src1p), cpumask_bits(src2p),
510
+ cpumask_bits(src3p), nr_cpumask_bits);
511
+}
512
+
513
+/**
477514 * cpumask_intersects - (*src1p & *src2p) != 0
478515 * @src1p: the first input
479516 * @src2p: the second input
....@@ -633,10 +670,7 @@
633670 */
634671 static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
635672 {
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);
673
+ return bitmap_parse(buf, UINT_MAX, cpumask_bits(dstp), nr_cpumask_bits);
640674 }
641675
642676 /**
....@@ -806,14 +840,7 @@
806840 cpumask_clear_cpu(cpu, &__cpu_present_mask);
807841 }
808842
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
-}
843
+void set_cpu_online(unsigned int cpu, bool online);
817844
818845 static inline void
819846 set_cpu_active(unsigned int cpu, bool active)