Skip to content

Commit 2a402aa

Browse files
committed
ibmvnic: simplify ibmvnic_set_queue_affinity()
A loop based on cpumask_next_wrap() opencodes the dedicated macro for_each_online_cpu_wrap(). Use it as it improves readability and simplifies maintenance. This also helps to drop cpumask handling code in the caller function. Signed-off-by: Yury Norov <[email protected]> Tested-by: Nick Child <[email protected]>
1 parent f02f2a1 commit 2a402aa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/net/ethernet/ibm/ibmvnic.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,17 @@ static int ibmvnic_set_queue_affinity(struct ibmvnic_sub_crq_queue *queue,
234234
(*stragglers)--;
235235
}
236236
/* atomic write is safer than writing bit by bit directly */
237-
for (i = 0; i < stride; i++) {
238-
cpumask_set_cpu(*cpu, mask);
239-
*cpu = cpumask_next_wrap(*cpu, cpu_online_mask,
240-
nr_cpu_ids, false);
237+
for_each_online_cpu_wrap(i, *cpu) {
238+
if (!stride--) {
239+
/* For the next queue we start from the first
240+
* unused CPU in this queue
241+
*/
242+
*cpu = i;
243+
break;
244+
}
245+
cpumask_set_cpu(i, mask);
241246
}
247+
242248
/* set queue affinity mask */
243249
cpumask_copy(queue->affinity_mask, mask);
244250
rc = irq_set_affinity_and_hint(queue->irq, queue->affinity_mask);
@@ -256,7 +262,7 @@ static void ibmvnic_set_affinity(struct ibmvnic_adapter *adapter)
256262
int num_rxqs = adapter->num_active_rx_scrqs, i_rxqs = 0;
257263
int num_txqs = adapter->num_active_tx_scrqs, i_txqs = 0;
258264
int total_queues, stride, stragglers, i;
259-
unsigned int num_cpu, cpu;
265+
unsigned int num_cpu, cpu = 0;
260266
bool is_rx_queue;
261267
int rc = 0;
262268

@@ -274,8 +280,6 @@ static void ibmvnic_set_affinity(struct ibmvnic_adapter *adapter)
274280
stride = max_t(int, num_cpu / total_queues, 1);
275281
/* number of leftover cpu's */
276282
stragglers = num_cpu >= total_queues ? num_cpu % total_queues : 0;
277-
/* next available cpu to assign irq to */
278-
cpu = cpumask_next(-1, cpu_online_mask);
279283

280284
for (i = 0; i < total_queues; i++) {
281285
is_rx_queue = false;

0 commit comments

Comments
 (0)