Skip to content

Commit 9b51d9d

Browse files
committed
cpumask: replace cpumask_next_* with cpumask_first_* where appropriate
cpumask_first() is a more effective analogue of 'next' version if n == -1 (which means start == 0). This patch replaces 'next' with 'first' where things look trivial. There's no cpumask_first_zero() function, so create it. Signed-off-by: Yury Norov <[email protected]> Tested-by: Wolfram Sang <[email protected]>
1 parent 4ade081 commit 9b51d9d

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2967,7 +2967,7 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)
29672967
static inline bool blk_mq_last_cpu_in_hctx(unsigned int cpu,
29682968
struct blk_mq_hw_ctx *hctx)
29692969
{
2970-
if (cpumask_next_and(-1, hctx->cpumask, cpu_online_mask) != cpu)
2970+
if (cpumask_first_and(hctx->cpumask, cpu_online_mask) != cpu)
29712971
return false;
29722972
if (cpumask_next_and(cpu, hctx->cpumask, cpu_online_mask) < nr_cpu_ids)
29732973
return false;

drivers/net/virtio_net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,7 @@ static void virtnet_set_affinity(struct virtnet_info *vi)
21012101
stragglers = num_cpu >= vi->curr_queue_pairs ?
21022102
num_cpu % vi->curr_queue_pairs :
21032103
0;
2104-
cpu = cpumask_next(-1, cpu_online_mask);
2104+
cpu = cpumask_first(cpu_online_mask);
21052105

21062106
for (i = 0; i < vi->curr_queue_pairs; i++) {
21072107
group_size = stride + (i < stragglers ? 1 : 0);

drivers/soc/fsl/qbman/bman_portal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int bman_portal_probe(struct platform_device *pdev)
155155
}
156156

157157
spin_lock(&bman_lock);
158-
cpu = cpumask_next_zero(-1, &portal_cpus);
158+
cpu = cpumask_first_zero(&portal_cpus);
159159
if (cpu >= nr_cpu_ids) {
160160
__bman_portals_probed = 1;
161161
/* unassigned portal, skip init */

drivers/soc/fsl/qbman/qman_portal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static int qman_portal_probe(struct platform_device *pdev)
248248
pcfg->pools = qm_get_pools_sdqcr();
249249

250250
spin_lock(&qman_lock);
251-
cpu = cpumask_next_zero(-1, &portal_cpus);
251+
cpu = cpumask_first_zero(&portal_cpus);
252252
if (cpu >= nr_cpu_ids) {
253253
__qman_portals_probed = 1;
254254
/* unassigned portal, skip init */

include/linux/cpumask.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
123123
return 0;
124124
}
125125

126+
static inline unsigned int cpumask_first_zero(const struct cpumask *srcp)
127+
{
128+
return 0;
129+
}
130+
126131
static inline unsigned int cpumask_first_and(const struct cpumask *srcp1,
127132
const struct cpumask *srcp2)
128133
{
@@ -201,6 +206,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
201206
return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits);
202207
}
203208

209+
/**
210+
* cpumask_first_zero - get the first unset cpu in a cpumask
211+
* @srcp: the cpumask pointer
212+
*
213+
* Returns >= nr_cpu_ids if all cpus are set.
214+
*/
215+
static inline unsigned int cpumask_first_zero(const struct cpumask *srcp)
216+
{
217+
return find_first_zero_bit(cpumask_bits(srcp), nr_cpumask_bits);
218+
}
219+
204220
/**
205221
* cpumask_first_and - return the first cpu from *srcp1 & *srcp2
206222
* @src1p: the first input

kernel/time/clocksource.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static void clocksource_verify_choose_cpus(void)
257257
return;
258258

259259
/* Make sure to select at least one CPU other than the current CPU. */
260-
cpu = cpumask_next(-1, cpu_online_mask);
260+
cpu = cpumask_first(cpu_online_mask);
261261
if (cpu == smp_processor_id())
262262
cpu = cpumask_next(cpu, cpu_online_mask);
263263
if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
@@ -279,7 +279,7 @@ static void clocksource_verify_choose_cpus(void)
279279
cpu = prandom_u32() % nr_cpu_ids;
280280
cpu = cpumask_next(cpu - 1, cpu_online_mask);
281281
if (cpu >= nr_cpu_ids)
282-
cpu = cpumask_next(-1, cpu_online_mask);
282+
cpu = cpumask_first(cpu_online_mask);
283283
if (!WARN_ON_ONCE(cpu >= nr_cpu_ids))
284284
cpumask_set_cpu(cpu, &cpus_chosen);
285285
}

0 commit comments

Comments
 (0)