isert: Micro-optimization: Use unlikely() macro in appropriate places

Signed-off-by: Yan Burman <yanb@mellanox.com>

git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/iser@5839 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Yan Burman
2014-10-13 12:32:52 +00:00
parent 2277551e22
commit c8c0246d54
5 changed files with 37 additions and 35 deletions
+2 -2
View File
@@ -61,7 +61,7 @@ static int isert_buf_alloc_pg(struct ib_device *ib_dev,
size_t page_len = min_t(size_t, size, PAGE_SIZE);
page = alloc_page(GFP_KERNEL);
if (!page) {
if (unlikely(!page)) {
pr_err("Failed to allocate page\n");
res = -ENOMEM;
goto out_map_failed;
@@ -115,7 +115,7 @@ static int isert_buf_malloc(struct ib_device *ib_dev,
}
isert_buf->addr = kmalloc(size, GFP_KERNEL);
if (!isert_buf->addr) {
if (unlikely(!isert_buf->addr)) {
pr_err("Failed to allocate data buffer\n");
res = -ENOMEM;
goto data_malloc_failed;
@@ -45,7 +45,7 @@ int isert_datamover_init(void)
int err;
err = isert_global_init();
if (err) {
if (unlikely(err)) {
pr_err("iser datamover init failed, err:%d\n", err);
return err;
}
@@ -173,17 +173,18 @@ void isert_release_rx_pdu(struct iscsi_cmnd *iscsi_pdu)
int isert_login_rsp_tx(struct iscsi_cmnd *login_rsp, int last, int discovery)
{
struct isert_connection *isert_conn = (struct isert_connection *)login_rsp->conn;
int err;
if (last && !discovery) {
int err = isert_alloc_conn_resources(isert_conn);
if (err) {
err = isert_alloc_conn_resources(isert_conn);
if (unlikely(err)) {
pr_err("Failed to init conn resources\n");
return err;
}
isert_pdu_free(isert_conn->login_req_pdu);
isert_conn->login_req_pdu = NULL;
} else {
int err = isert_post_recv(isert_conn,
err = isert_post_recv(isert_conn,
&isert_conn->login_req_pdu->wr[0],
1);
if (unlikely(err)) {
+15 -15
View File
@@ -761,7 +761,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
TRACE_ENTRY();
isert_dev = kzalloc(sizeof(*isert_dev), GFP_KERNEL);
if (isert_dev == NULL) {
if (unlikely(isert_dev == NULL)) {
pr_err("Failed to allocate iser dev\n");
err = -ENOMEM;
goto out;
@@ -769,7 +769,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
dev_attr = &isert_dev->device_attr;
err = ib_query_device(ib_dev, dev_attr);
if (err) {
if (unlikely(err)) {
pr_err("Failed to query device, err: %d\n", err);
goto fail_query;
}
@@ -779,14 +779,14 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
isert_dev->cq_qps = kzalloc(sizeof(*isert_dev->cq_qps) * isert_dev->num_cqs,
GFP_KERNEL);
if (isert_dev->cq_qps == NULL) {
if (unlikely(isert_dev->cq_qps == NULL)) {
pr_err("Failed to allocate iser cq_qps\n");
err = -ENOMEM;
goto fail_cq_qps;
}
isert_dev->cq_desc = vmalloc(sizeof(*isert_dev->cq_desc) * isert_dev->num_cqs);
if (isert_dev->cq_desc == NULL) {
if (unlikely(isert_dev->cq_desc == NULL)) {
pr_err("Failed to allocate %ld bytes for iser cq_desc\n",
sizeof(*isert_dev->cq_desc) * isert_dev->num_cqs);
err = -ENOMEM;
@@ -794,14 +794,14 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
}
pd = ib_alloc_pd(ib_dev);
if (IS_ERR(pd)) {
if (unlikely(IS_ERR(pd))) {
err = PTR_ERR(pd);
pr_err("Failed to alloc iser dev pd, err:%d\n", err);
goto fail_pd;
}
mr = ib_get_dma_mr(pd, IB_ACCESS_LOCAL_WRITE);
if (IS_ERR(mr)) {
if (unlikely(IS_ERR(mr))) {
err = PTR_ERR(mr);
pr_err("Failed to get dma mr, err: %d\n", err);
goto fail_mr;
@@ -835,7 +835,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
WQ_MEM_RECLAIM, 1);
#endif
#endif
if (!cq_desc->cq_workqueue) {
if (unlikely(!cq_desc->cq_workqueue)) {
pr_err("Failed to alloc iser cq work queue for dev:%s\n",
ib_dev->name);
err = -ENOMEM;
@@ -848,7 +848,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
cq_desc, /* context */
cqe_num,
i); /* completion vector */
if (IS_ERR(cq)) {
if (unlikely(IS_ERR(cq))) {
err = PTR_ERR(cq);
pr_err("Failed to create iser dev cq, err:%d\n", err);
goto fail_cq;
@@ -856,7 +856,7 @@ static struct isert_device *isert_device_create(struct ib_device *ib_dev)
cq_desc->cq = cq;
err = ib_req_notify_cq(cq, IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS);
if (err) {
if (unlikely(err)) {
pr_err("Failed to request notify cq, err: %d\n", err);
goto fail_cq;
}
@@ -921,17 +921,17 @@ static void isert_device_release(struct isert_device *isert_dev)
#endif
err = ib_destroy_cq(cq_desc->cq);
if (err)
if (unlikely(err))
pr_err("Failed to destroy cq, err:%d\n", err);
destroy_workqueue(cq_desc->cq_workqueue);
}
err = ib_dereg_mr(isert_dev->mr);
if (err)
if (unlikely(err))
pr_err("Failed to destroy mr, err:%d\n", err);
err = ib_dealloc_pd(isert_dev->pd);
if (err)
if (unlikely(err))
pr_err("Failed to destroy pd, err:%d\n", err);
vfree(isert_dev->cq_desc);
@@ -1031,7 +1031,7 @@ static struct isert_connection *isert_conn_create(struct rdma_cm_id *cm_id,
TRACE_ENTRY();
if (!try_module_get(THIS_MODULE)) {
if (unlikely(!try_module_get(THIS_MODULE))) {
err = -EINVAL;
goto fail_get;
}
@@ -1485,7 +1485,7 @@ struct isert_portal *isert_portal_create(void)
struct rdma_cm_id *cm_id;
int err;
if (!try_module_get(THIS_MODULE)) {
if (unlikely(!try_module_get(THIS_MODULE))) {
pr_err("Unable increment module reference\n");
portal = ERR_PTR(-EINVAL);
goto out;
@@ -1612,7 +1612,7 @@ struct isert_portal *isert_portal_start(struct sockaddr *sa, size_t addr_len)
int err;
portal = isert_portal_create();
if (IS_ERR(portal))
if (unlikely(IS_ERR(portal)))
return portal;
err = isert_portal_listen(portal, sa, addr_len);
+3 -2
View File
@@ -481,11 +481,12 @@ static int __init isert_init_module(void)
int ret;
ret = iscsit_reg_transport(&isert_transport);
if (ret)
return ret;
if (unlikely(ret))
goto out;
ret = isert_init_login_devs(isert_nr_devs);
out:
return ret;
}
+12 -12
View File
@@ -357,7 +357,7 @@ static ssize_t isert_listen_read(struct file *filp, char __user *buf,
conn_dev->idx);
++res; /* copy trailing \0 as well */
if (copy_to_user(buf, k_buff, res))
if (unlikely(copy_to_user(buf, k_buff, res)))
res = -EFAULT;
out:
@@ -378,13 +378,13 @@ static long isert_listen_ioctl(struct file *filp, unsigned int cmd,
switch (cmd) {
case SET_LISTEN_ADDR:
rc = copy_from_user(&dev->info, ptr, sizeof(dev->info));
if (rc != 0) {
if (unlikely(rc != 0)) {
PRINT_ERROR("Failed to copy %d user's bytes\n", rc);
res = -EFAULT;
goto out;
}
if (dev->free_portal_idx >= ISERT_MAX_PORTALS) {
if (unlikely(dev->free_portal_idx >= ISERT_MAX_PORTALS)) {
PRINT_ERROR("Maximum number of portals exceeded: %d\n",
ISERT_MAX_PORTALS);
res = -EINVAL;
@@ -654,7 +654,7 @@ static long isert_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (val) {
if (!dev->login_rsp) {
cmnd = isert_alloc_login_rsp_pdu(dev->conn);
if (!cmnd) {
if (unlikely(!cmnd)) {
res = -ENOMEM;
goto out;
}
@@ -667,7 +667,7 @@ static long isert_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
struct iscsi_login_rsp_hdr *rsp;
bool last;
if (!dev->login_rsp) {
if (unlikely(!dev->login_rsp)) {
res = -EINVAL;
goto out;
}
@@ -700,7 +700,7 @@ static long isert_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
goto out;
rc = copy_to_user(ptr, &addr, sizeof(addr));
if (rc)
if (unlikely(rc != 0))
res = -EFAULT;
}
break;
@@ -760,7 +760,7 @@ int isert_login_req_rx(struct iscsi_cmnd *login_req)
switch (dev->state) {
case CS_INIT:
case CS_RSP_FINISHED:
if (dev->login_req != NULL) {
if (unlikely(dev->login_req != NULL)) {
sBUG();
res = -EINVAL;
goto out;
@@ -847,7 +847,7 @@ static void __init isert_setup_cdev(struct isert_conn_dev *dev,
dev->state = CS_INIT;
err = cdev_add(&dev->cdev, dev->devno, 1);
/* Fail gracefully if need be */
if (err)
if (unlikely(err))
PRINT_ERROR("Error %d adding "ISER_CONN_DEV_PREFIX"%d", err,
index);
@@ -875,7 +875,7 @@ static void __init isert_setup_listener_cdev(struct isert_listener_dev *dev)
atomic_set(&dev->available, 1);
err = cdev_add(&dev->cdev, dev->devno, 1);
/* Fail gracefully if need be */
if (err)
if (unlikely(err))
PRINT_ERROR("Error %d adding isert_scst", err);
dev->dev = device_create(isert_class, NULL, dev->devno, NULL,
@@ -897,7 +897,7 @@ int __init isert_init_login_devs(unsigned int ndevs)
"isert_scst");
isert_major = MAJOR(devno);
if (res < 0) {
if (unlikely(res < 0)) {
PRINT_ERROR("isert: can't get major %d\n", isert_major);
goto out;
}
@@ -908,7 +908,7 @@ int __init isert_init_login_devs(unsigned int ndevs)
*/
isert_conn_devices = kzalloc(n_devs * sizeof(struct isert_conn_dev),
GFP_KERNEL);
if (!isert_conn_devices) {
if (unlikely(!isert_conn_devices)) {
res = -ENOMEM;
goto fail; /* Make this more graceful */
}
@@ -922,7 +922,7 @@ int __init isert_init_login_devs(unsigned int ndevs)
isert_setup_cdev(&isert_conn_devices[i], i);
res = isert_datamover_init();
if (res) {
if (unlikely(res)) {
PRINT_ERROR("Unable to initialize datamover: %d\n", res);
goto fail;
}