History

IB/uverbs: Add create/destroy counters support

User space application which uses counters functionality, is expected to allocate/release the counters resources by calling create/destroy verbs and in turn get a unique handle that can be used to attach the counters to its counted type.

Raed Salem committed 8 years ago

Commit d9a5a641 parent fa9b1805 files · +118 −2Browse files

Unified · Split

5 files
  1. drivers/infiniband/core/Makefile +1 −1
  2. drivers/infiniband/core/uverbs.h +1 −0
  3. drivers/infiniband/core/uverbs_std_types.c +2 −1
  4. drivers/infiniband/core/uverbs_std_types_counters.c +100 −0
  5. include/uapi/rdma/ib_user_ioctl_cmds.h +14 −0
drivers/infiniband/core/Makefile+1−1
@@ -36,4 +36,4 @@ ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o \ · 35 unmodified lines
3636 rdma_core.o uverbs_std_types.o uverbs_ioctl.o \
3737 uverbs_ioctl_merge.o uverbs_std_types_cq.o \
3838 uverbs_std_types_flow_action.o uverbs_std_types_dm.o \
39− uverbs_std_types_mr.o
39+ uverbs_std_types_mr.o uverbs_std_types_counters.o
drivers/infiniband/core/uverbs.h+1−0
@@ -287,6 +287,7 @@ extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_RWQ_IND_TBL); · 286 unmodified lines
287287 extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_XRCD);
288288 extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION);
289289 extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DM);
290+extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS);
290291
291292 #define IB_UVERBS_DECLARE_CMD(name) \
292293 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
drivers/infiniband/core/uverbs_std_types.c+2−1
@@ -302,7 +302,8 @@ static DECLARE_UVERBS_OBJECT_TREE(uverbs_default_objects, · 301 unmodified lines
302302 &UVERBS_OBJECT(UVERBS_OBJECT_RWQ_IND_TBL),
303303 &UVERBS_OBJECT(UVERBS_OBJECT_XRCD),
304304 &UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION),
305− &UVERBS_OBJECT(UVERBS_OBJECT_DM));
305+ &UVERBS_OBJECT(UVERBS_OBJECT_DM),
306+ &UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS));
306307
307308 const struct uverbs_object_tree_def *uverbs_default_get_objects(void)
308309 {
drivers/infiniband/core/uverbs_std_types_counters.c+100−0
@@ -0,0 +1,100 @@
1+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+/*
3+ * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.
4+ *
5+ * This software is available to you under a choice of one of two
6+ * licenses. You may choose to be licensed under the terms of the GNU
7+ * General Public License (GPL) Version 2, available from the file
8+ * COPYING in the main directory of this source tree, or the
9+ * OpenIB.org BSD license below:
10+ *
11+ * Redistribution and use in source and binary forms, with or
12+ * without modification, are permitted provided that the following
13+ * conditions are met:
14+ *
15+ * - Redistributions of source code must retain the above
16+ * copyright notice, this list of conditions and the following
17+ * disclaimer.
18+ *
19+ * - Redistributions in binary form must reproduce the above
20+ * copyright notice, this list of conditions and the following
21+ * disclaimer in the documentation and/or other materials
22+ * provided with the distribution.
23+ *
24+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+ * SOFTWARE.
32+ */
33+
34+#include "uverbs.h"
35+#include <rdma/uverbs_std_types.h>
36+
37+static int uverbs_free_counters(struct ib_uobject *uobject,
38+ enum rdma_remove_reason why)
39+{
40+ struct ib_counters *counters = uobject->object;
41+
42+ if (why == RDMA_REMOVE_DESTROY &&
43+ atomic_read(&counters->usecnt))
44+ return -EBUSY;
45+
46+ return counters->device->destroy_counters(counters);
47+}
48+
49+static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_dev,
50+ struct ib_uverbs_file *file,
51+ struct uverbs_attr_bundle *attrs)
52+{
53+ struct ib_counters *counters;
54+ struct ib_uobject *uobj;
55+ int ret;
56+
57+ /*
58+ * This check should be removed once the infrastructure
59+ * have the ability to remove methods from parse tree once
60+ * such condition is met.
61+ */
62+ if (!ib_dev->create_counters)
63+ return -EOPNOTSUPP;
64+
65+ uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_COUNTERS_HANDLE);
66+ counters = ib_dev->create_counters(ib_dev, attrs);
67+ if (IS_ERR(counters)) {
68+ ret = PTR_ERR(counters);
69+ goto err_create_counters;
70+ }
71+
72+ counters->device = ib_dev;
73+ counters->uobject = uobj;
74+ uobj->object = counters;
75+ atomic_set(&counters->usecnt, 0);
76+
77+ return 0;
78+
79+err_create_counters:
80+ return ret;
81+}
82+
83+static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE,
84+ &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_COUNTERS_HANDLE,
85+ UVERBS_OBJECT_COUNTERS,
86+ UVERBS_ACCESS_NEW,
87+ UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)));
88+
89+static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_COUNTERS_DESTROY,
90+ uverbs_destroy_def_handler,
91+ &UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_COUNTERS_HANDLE,
92+ UVERBS_OBJECT_COUNTERS,
93+ UVERBS_ACCESS_DESTROY,
94+ UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY)));
95+
96+DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_COUNTERS,
97+ &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_counters),
98+ &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_CREATE),
99+ &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY));
100+
include/uapi/rdma/ib_user_ioctl_cmds.h+14−0
@@ -55,6 +55,7 @@ enum uverbs_default_objects { · 54 unmodified lines
5555 UVERBS_OBJECT_WQ,
5656 UVERBS_OBJECT_FLOW_ACTION,
5757 UVERBS_OBJECT_DM,
58+ UVERBS_OBJECT_COUNTERS,
5859 };
5960
6061 enum {
@@ -131,4 +132,17 @@ enum uverbs_methods_mr { · 70 unmodified lines
131132 UVERBS_METHOD_DM_MR_REG,
132133 };
133134
135+enum uverbs_attrs_create_counters_cmd_attr_ids {
136+ UVERBS_ATTR_CREATE_COUNTERS_HANDLE,
137+};
138+
139+enum uverbs_attrs_destroy_counters_cmd_attr_ids {
140+ UVERBS_ATTR_DESTROY_COUNTERS_HANDLE,
141+};
142+
143+enum uverbs_methods_actions_counters_ops {
144+ UVERBS_METHOD_COUNTERS_CREATE,
145+ UVERBS_METHOD_COUNTERS_DESTROY,
146+};
147+
134148 #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