History

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.

Raed Salem committed 8 years ago

Commit ebb67961 parent 51d7a532 files · +65 −1Browse files

Unified · Split

2 files
  1. drivers/infiniband/core/uverbs_std_types_counters.c +58 −1
  2. include/uapi/rdma/ib_user_ioctl_cmds.h +7 −0
drivers/infiniband/core/uverbs_std_types_counters.c+58−1
@@ -80,6 +80,49 @@ err_create_counters: · 79 unmodified lines
80 return ret;80 return ret;
81}81}
82 82
83static 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
121err_read:
122 kfree(read_attr.counters_buff);
123 return ret;
124}
125
83static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE,126static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE,
84 &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_COUNTERS_HANDLE,127 &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_COUNTERS_HANDLE,
85 UVERBS_OBJECT_COUNTERS,128 UVERBS_OBJECT_COUNTERS,
@@ -93,8 +136,22 @@ static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_COUNTERS_DESTROY, · 7 unmodified lines
93 UVERBS_ACCESS_DESTROY,136 UVERBS_ACCESS_DESTROY,
94 UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)));137 UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)));
95 138
139#define MAX_COUNTERS_BUFF_SIZE USHRT_MAX
140static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_READ,
141 &UVERBS_ATTR_IDR(UVERBS_ATTR_READ_COUNTERS_HANDLE,
142 UVERBS_OBJECT_COUNTERS,
143 UVERBS_ACCESS_READ,
144 UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)),
145 &UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_READ_COUNTERS_BUFF,
146 UVERBS_ATTR_SIZE(0, MAX_COUNTERS_BUFF_SIZE),
147 UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)),
148 &UVERBS_ATTR_PTR_IN(UVERBS_ATTR_READ_COUNTERS_FLAGS,
149 UVERBS_ATTR_TYPE(__u32),
150 UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)));
151
96DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_COUNTERS,152DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_COUNTERS,
97 &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_counters),153 &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_counters),
98 &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_CREATE),154 &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_CREATE),
99 &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY));155 &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY),
156 &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_READ));
100 157
include/uapi/rdma/ib_user_ioctl_cmds.h+7−0
@@ -140,9 +140,16 @@ enum uverbs_attrs_destroy_counters_cmd_attr_ids { · 139 unmodified lines
140 UVERBS_ATTR_DESTROY_COUNTERS_HANDLE,140 UVERBS_ATTR_DESTROY_COUNTERS_HANDLE,
141};141};
142 142
143enum 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
143enum uverbs_methods_actions_counters_ops {149enum uverbs_methods_actions_counters_ops {
144 UVERBS_METHOD_COUNTERS_CREATE,150 UVERBS_METHOD_COUNTERS_CREATE,
145 UVERBS_METHOD_COUNTERS_DESTROY,151 UVERBS_METHOD_COUNTERS_DESTROY,
152 UVERBS_METHOD_COUNTERS_READ,
146};153};
147 154
148#endif155#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t