Skip to content

Commit be2f76e

Browse files
RDS: IB: Add vector spreading for cqs
Based on available device vectors, allocate cqs accordingly to get better spread of completion vectors which helps performace great deal.. Signed-off-by: Santosh Shilimkar <[email protected]>
1 parent 09b2b8f commit be2f76e

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

net/rds/ib.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ static void rds_ib_dev_free(struct work_struct *work)
111111
kfree(i_ipaddr);
112112
}
113113

114+
if (rds_ibdev->vector_load)
115+
kfree(rds_ibdev->vector_load);
116+
114117
kfree(rds_ibdev);
115118
}
116119

@@ -159,6 +162,14 @@ static void rds_ib_add_one(struct ib_device *device)
159162
rds_ibdev->max_initiator_depth = device->attrs.max_qp_init_rd_atom;
160163
rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom;
161164

165+
rds_ibdev->vector_load = kzalloc(sizeof(int) * device->num_comp_vectors,
166+
GFP_KERNEL);
167+
if (!rds_ibdev->vector_load) {
168+
pr_err("RDS/IB: %s failed to allocate vector memory\n",
169+
__func__);
170+
goto put_dev;
171+
}
172+
162173
rds_ibdev->dev = device;
163174
rds_ibdev->pd = ib_alloc_pd(device, 0);
164175
if (IS_ERR(rds_ibdev->pd)) {

net/rds/ib.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ struct rds_ib_connection {
185185

186186
/* Endpoint role in connection */
187187
bool i_active_side;
188+
189+
/* Send/Recv vectors */
190+
int i_scq_vector;
191+
int i_rcq_vector;
188192
};
189193

190194
/* This assumes that atomic_t is at least 32 bits */
@@ -227,6 +231,7 @@ struct rds_ib_device {
227231
spinlock_t spinlock; /* protect the above */
228232
atomic_t refcount;
229233
struct work_struct free_work;
234+
int *vector_load;
230235
};
231236

232237
#define ibdev_to_node(ibdev) dev_to_node(ibdev->dma_device)

net/rds/ib_cm.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,28 @@ static void rds_ib_cq_comp_handler_send(struct ib_cq *cq, void *context)
358358
tasklet_schedule(&ic->i_send_tasklet);
359359
}
360360

361+
static inline int ibdev_get_unused_vector(struct rds_ib_device *rds_ibdev)
362+
{
363+
int min = rds_ibdev->vector_load[rds_ibdev->dev->num_comp_vectors - 1];
364+
int index = rds_ibdev->dev->num_comp_vectors - 1;
365+
int i;
366+
367+
for (i = rds_ibdev->dev->num_comp_vectors - 1; i >= 0; i--) {
368+
if (rds_ibdev->vector_load[i] < min) {
369+
index = i;
370+
min = rds_ibdev->vector_load[i];
371+
}
372+
}
373+
374+
rds_ibdev->vector_load[index]++;
375+
return index;
376+
}
377+
378+
static inline void ibdev_put_vector(struct rds_ib_device *rds_ibdev, int index)
379+
{
380+
rds_ibdev->vector_load[index]--;
381+
}
382+
361383
/*
362384
* This needs to be very careful to not leave IS_ERR pointers around for
363385
* cleanup to trip over.
@@ -399,25 +421,30 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
399421
/* Protection domain and memory range */
400422
ic->i_pd = rds_ibdev->pd;
401423

424+
ic->i_scq_vector = ibdev_get_unused_vector(rds_ibdev);
402425
cq_attr.cqe = ic->i_send_ring.w_nr + fr_queue_space + 1;
403-
426+
cq_attr.comp_vector = ic->i_scq_vector;
404427
ic->i_send_cq = ib_create_cq(dev, rds_ib_cq_comp_handler_send,
405428
rds_ib_cq_event_handler, conn,
406429
&cq_attr);
407430
if (IS_ERR(ic->i_send_cq)) {
408431
ret = PTR_ERR(ic->i_send_cq);
409432
ic->i_send_cq = NULL;
433+
ibdev_put_vector(rds_ibdev, ic->i_scq_vector);
410434
rdsdebug("ib_create_cq send failed: %d\n", ret);
411435
goto out;
412436
}
413437

438+
ic->i_rcq_vector = ibdev_get_unused_vector(rds_ibdev);
414439
cq_attr.cqe = ic->i_recv_ring.w_nr;
440+
cq_attr.comp_vector = ic->i_rcq_vector;
415441
ic->i_recv_cq = ib_create_cq(dev, rds_ib_cq_comp_handler_recv,
416442
rds_ib_cq_event_handler, conn,
417443
&cq_attr);
418444
if (IS_ERR(ic->i_recv_cq)) {
419445
ret = PTR_ERR(ic->i_recv_cq);
420446
ic->i_recv_cq = NULL;
447+
ibdev_put_vector(rds_ibdev, ic->i_rcq_vector);
421448
rdsdebug("ib_create_cq recv failed: %d\n", ret);
422449
goto out;
423450
}
@@ -780,10 +807,17 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path *cp)
780807
/* first destroy the ib state that generates callbacks */
781808
if (ic->i_cm_id->qp)
782809
rdma_destroy_qp(ic->i_cm_id);
783-
if (ic->i_send_cq)
810+
if (ic->i_send_cq) {
811+
if (ic->rds_ibdev)
812+
ibdev_put_vector(ic->rds_ibdev, ic->i_scq_vector);
784813
ib_destroy_cq(ic->i_send_cq);
785-
if (ic->i_recv_cq)
814+
}
815+
816+
if (ic->i_recv_cq) {
817+
if (ic->rds_ibdev)
818+
ibdev_put_vector(ic->rds_ibdev, ic->i_rcq_vector);
786819
ib_destroy_cq(ic->i_recv_cq);
820+
}
787821

788822
/* then free the resources that ib callbacks use */
789823
if (ic->i_send_hdrs)

0 commit comments

Comments
 (0)