Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/uverbs: Add read counters support

This patch exposes the read counters verb to user space applications. By
that verb the user can read the hardware counters which are associated
with the counters object.

The application needs to provide a sufficient memory to hold the
statistics.

Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Raed Salem <raeds@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Raed Salem and committed by
Leon Romanovsky
ebb6796b 51d7a538

+65 -1
+58 -1
drivers/infiniband/core/uverbs_std_types_counters.c
··· 80 80 return ret; 81 81 } 82 82 83 + static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(struct ib_device *ib_dev, 84 + struct ib_uverbs_file *file, 85 + struct uverbs_attr_bundle *attrs) 86 + { 87 + struct ib_counters_read_attr read_attr = {}; 88 + const struct uverbs_attr *uattr; 89 + struct ib_counters *counters = 90 + uverbs_attr_get_obj(attrs, UVERBS_ATTR_READ_COUNTERS_HANDLE); 91 + int ret; 92 + 93 + if (!ib_dev->read_counters) 94 + return -EOPNOTSUPP; 95 + 96 + if (!atomic_read(&counters->usecnt)) 97 + return -EINVAL; 98 + 99 + ret = uverbs_copy_from(&read_attr.flags, attrs, 100 + UVERBS_ATTR_READ_COUNTERS_FLAGS); 101 + if (ret) 102 + return ret; 103 + 104 + uattr = uverbs_attr_get(attrs, UVERBS_ATTR_READ_COUNTERS_BUFF); 105 + read_attr.ncounters = uattr->ptr_attr.len / sizeof(u64); 106 + read_attr.counters_buff = kcalloc(read_attr.ncounters, 107 + sizeof(u64), GFP_KERNEL); 108 + if (!read_attr.counters_buff) 109 + return -ENOMEM; 110 + 111 + ret = ib_dev->read_counters(counters, 112 + &read_attr, 113 + attrs); 114 + if (ret) 115 + goto err_read; 116 + 117 + ret = uverbs_copy_to(attrs, UVERBS_ATTR_READ_COUNTERS_BUFF, 118 + read_attr.counters_buff, 119 + read_attr.ncounters * sizeof(u64)); 120 + 121 + err_read: 122 + kfree(read_attr.counters_buff); 123 + return ret; 124 + } 125 + 83 126 static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE, 84 127 &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_COUNTERS_HANDLE, 85 128 UVERBS_OBJECT_COUNTERS, ··· 136 93 UVERBS_ACCESS_DESTROY, 137 94 UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); 138 95 96 + #define MAX_COUNTERS_BUFF_SIZE USHRT_MAX 97 + static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_READ, 98 + &UVERBS_ATTR_IDR(UVERBS_ATTR_READ_COUNTERS_HANDLE, 99 + UVERBS_OBJECT_COUNTERS, 100 + UVERBS_ACCESS_READ, 101 + UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), 102 + &UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_READ_COUNTERS_BUFF, 103 + UVERBS_ATTR_SIZE(0, MAX_COUNTERS_BUFF_SIZE), 104 + UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)), 105 + &UVERBS_ATTR_PTR_IN(UVERBS_ATTR_READ_COUNTERS_FLAGS, 106 + UVERBS_ATTR_TYPE(__u32), 107 + UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); 108 + 139 109 DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_COUNTERS, 140 110 &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_counters), 141 111 &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_CREATE), 142 - &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY)); 112 + &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY), 113 + &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_READ)); 143 114
+7
include/uapi/rdma/ib_user_ioctl_cmds.h
··· 140 140 UVERBS_ATTR_DESTROY_COUNTERS_HANDLE, 141 141 }; 142 142 143 + enum uverbs_attrs_read_counters_cmd_attr_ids { 144 + UVERBS_ATTR_READ_COUNTERS_HANDLE, 145 + UVERBS_ATTR_READ_COUNTERS_BUFF, 146 + UVERBS_ATTR_READ_COUNTERS_FLAGS, 147 + }; 148 + 143 149 enum uverbs_methods_actions_counters_ops { 144 150 UVERBS_METHOD_COUNTERS_CREATE, 145 151 UVERBS_METHOD_COUNTERS_DESTROY, 152 + UVERBS_METHOD_COUNTERS_READ, 146 153 }; 147 154 148 155 #endif