IB/uverbs: Allow CQ moderation with modify CQ
authorYonatan Cohen <yonatanc@mellanox.com>
Mon, 13 Nov 2017 08:51:13 +0000 (10:51 +0200)
committerDoug Ledford <dledford@redhat.com>
Mon, 13 Nov 2017 21:59:22 +0000 (16:59 -0500)
Uverbs support in modify_cq for CQ moderation only.
Gives ability to change cq_max_count and cq_period.
CQ moderation enhance performance by moderating the number
of CQEs needed to create an event instead of application
having to suffer from event per-CQE.
To achieve CQ moderation the application needs to set cq_max_count
and cq_period.
cq_max_count - defines the number of CQEs needed to create an event.
cq_period - defines the timeout (micro seconds) between last
            event and a new one that will occur even if
    cq_max_count was not satisfied

Signed-off-by: Yonatan Cohen <yonatanc@mellanox.com>
Reviewed-by: Majd Dibbiny <majd@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/uverbs.h
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/core/uverbs_main.c
include/rdma/ib_verbs.h
include/uapi/rdma/ib_user_verbs.h

index ee2739ae4305065e82fcc3e2ae72993843ce6717..deccefb71a6b294efade714777f5d627345e41b0 100644 (file)
@@ -306,5 +306,6 @@ IB_UVERBS_DECLARE_EX_CMD(destroy_wq);
 IB_UVERBS_DECLARE_EX_CMD(create_rwq_ind_table);
 IB_UVERBS_DECLARE_EX_CMD(destroy_rwq_ind_table);
 IB_UVERBS_DECLARE_EX_CMD(modify_qp);
+IB_UVERBS_DECLARE_EX_CMD(modify_cq);
 
 #endif /* UVERBS_H */
index 8ca36843ef381983ec2e67ad5e853b37dd69201d..3c2673cd40908bd7d4e0705d03dc298ed06d6ab7 100644 (file)
@@ -3856,3 +3856,45 @@ end:
        err = ib_copy_to_udata(ucore, &resp, resp.response_length);
        return err;
 }
+
+int ib_uverbs_ex_modify_cq(struct ib_uverbs_file *file,
+                          struct ib_device *ib_dev,
+                          struct ib_udata *ucore,
+                          struct ib_udata *uhw)
+{
+       struct ib_uverbs_ex_modify_cq cmd = {};
+       struct ib_cq *cq;
+       size_t required_cmd_sz;
+       int ret;
+
+       required_cmd_sz = offsetof(typeof(cmd), reserved) +
+                               sizeof(cmd.reserved);
+       if (ucore->inlen < required_cmd_sz)
+               return -EINVAL;
+
+       /* sanity checks */
+       if (ucore->inlen > sizeof(cmd) &&
+           !ib_is_udata_cleared(ucore, sizeof(cmd),
+                                ucore->inlen - sizeof(cmd)))
+               return -EOPNOTSUPP;
+
+       ret = ib_copy_from_udata(&cmd, ucore, min(sizeof(cmd), ucore->inlen));
+       if (ret)
+               return ret;
+
+       if (!cmd.attr_mask || cmd.reserved)
+               return -EINVAL;
+
+       if (cmd.attr_mask > IB_CQ_MODERATE)
+               return -EOPNOTSUPP;
+
+       cq = uobj_get_obj_read(cq, cmd.cq_handle, file->ucontext);
+       if (!cq)
+               return -EINVAL;
+
+       ret = ib_modify_cq(cq, cmd.attr.cq_count, cmd.attr.cq_period);
+
+       uobj_put_obj_read(cq);
+
+       return ret;
+}
index b5febfd84ee54ea3c72e060236ed893fa2581edd..381fd9c096ae23dd3e7b7e7ec52c75b57cbe6fc8 100644 (file)
@@ -128,6 +128,7 @@ static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file,
        [IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL] = ib_uverbs_ex_create_rwq_ind_table,
        [IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL] = ib_uverbs_ex_destroy_rwq_ind_table,
        [IB_USER_VERBS_EX_CMD_MODIFY_QP]        = ib_uverbs_ex_modify_qp,
+       [IB_USER_VERBS_EX_CMD_MODIFY_CQ]        = ib_uverbs_ex_modify_cq,
 };
 
 static void ib_uverbs_add_one(struct ib_device *device);
index 0b671982bbb37b30f3f84746aa52d0917d8de632..8e0d3780ce4e008c5a6558baab8630919eafaf67 100644 (file)
@@ -311,6 +311,10 @@ struct ib_cq_init_attr {
        u32             flags;
 };
 
+enum ib_cq_attr_mask {
+       IB_CQ_MODERATE = 1 << 0,
+};
+
 struct ib_device_attr {
        u64                     fw_ver;
        __be64                  sys_image_guid;
index d4e0b53bfc75ccdf03585c7b402389a21aba4dca..cfa09d6095d6a22c3caa2532fcc4f80b53f2f332 100644 (file)
@@ -100,7 +100,8 @@ enum {
        IB_USER_VERBS_EX_CMD_MODIFY_WQ,
        IB_USER_VERBS_EX_CMD_DESTROY_WQ,
        IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
-       IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL
+       IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL,
+       IB_USER_VERBS_EX_CMD_MODIFY_CQ
 };
 
 /*
@@ -1150,6 +1151,18 @@ struct ib_uverbs_ex_destroy_rwq_ind_table  {
        __u32 ind_tbl_handle;
 };
 
+struct ib_uverbs_cq_moderation {
+       __u16 cq_count;
+       __u16 cq_period;
+};
+
+struct ib_uverbs_ex_modify_cq {
+       __u32 cq_handle;
+       __u32 attr_mask;
+       struct ib_uverbs_cq_moderation attr;
+       __u32 reserved;
+};
+
 #define IB_DEVICE_NAME_MAX 64
 
 #endif /* IB_USER_VERBS_H */