Message ID | 1484132033-3346-6-git-send-email-matanb@mellanox.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On Wed, Jan 11, 2017 at 12:53:51PM +0200, Matan Barak wrote: > In order to initialize and destroy types in a generic way, we need to > provide information about the allocation size, release function and > order. This is done through a macro based DSL (domain specific > language). This patch adds macros to initialize a type and a type > group. > > When we transform the write based commands to use this new locking and > allocation schema, we use these types declarations. > > Signed-off-by: Matan Barak <matanb@mellanox.com> > Reviewed-by: Yishai Hadas <yishaih@mellanox.com> > include/rdma/uverbs_ioctl.h | 50 +++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 48 insertions(+), 2 deletions(-) None of this makes any sense to me at this point in the series. Just use a sane meta-class type and the 'usual' linux static const initializer scheme. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Jan 12, 2017 at 2:10 AM, Jason Gunthorpe <jgunthorpe@obsidianresearch.com> wrote: > On Wed, Jan 11, 2017 at 12:53:51PM +0200, Matan Barak wrote: >> In order to initialize and destroy types in a generic way, we need to >> provide information about the allocation size, release function and >> order. This is done through a macro based DSL (domain specific >> language). This patch adds macros to initialize a type and a type >> group. >> >> When we transform the write based commands to use this new locking and >> allocation schema, we use these types declarations. >> >> Signed-off-by: Matan Barak <matanb@mellanox.com> >> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> >> include/rdma/uverbs_ioctl.h | 50 +++++++++++++++++++++++++++++++++++++++++++-- >> 1 file changed, 48 insertions(+), 2 deletions(-) > > None of this makes any sense to me at this point in the series. > > Just use a sane meta-class type and the 'usual' linux static const > initializer scheme. > I could of course drop this patch and use static initializes. However, this mean we'll re-write the next patch using macro language in the next patch (as we introduce actions there). I also think the declarations themselves look pretty tidy this way. > Jason Matan > -- > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jan 17, 2017 at 07:25:22PM +0200, Matan Barak wrote: > On Thu, Jan 12, 2017 at 2:10 AM, Jason Gunthorpe > <jgunthorpe@obsidianresearch.com> wrote: > > On Wed, Jan 11, 2017 at 12:53:51PM +0200, Matan Barak wrote: > >> In order to initialize and destroy types in a generic way, we need to > >> provide information about the allocation size, release function and > >> order. This is done through a macro based DSL (domain specific > >> language). This patch adds macros to initialize a type and a type > >> group. > >> > >> When we transform the write based commands to use this new locking and > >> allocation schema, we use these types declarations. > >> > >> Signed-off-by: Matan Barak <matanb@mellanox.com> > >> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> > >> include/rdma/uverbs_ioctl.h | 50 +++++++++++++++++++++++++++++++++++++++++++-- > >> 1 file changed, 48 insertions(+), 2 deletions(-) > > > > None of this makes any sense to me at this point in the series. > > > > Just use a sane meta-class type and the 'usual' linux static const > > initializer scheme. > > I could of course drop this patch and use static > initializes. However, this mean we'll re-write the next patch using > macro language in the next patch (as we introduce actions there). I > also think the declarations themselves look pretty tidy this way. Why would it be rewritten? The per-object static initializer should be basically good indefinately? The next series will introduce macros to add per-type functions but that shouldn't disturb the initializer. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index a8b0ff9..4b569ae 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -34,8 +34,7 @@ #define _UVERBS_IOCTL_ #include <linux/kernel.h> - -struct ib_uobject; +#include <rdma/ib_verbs.h> enum uverbs_attr_type { UVERBS_ATTR_TYPE_IDR, @@ -79,4 +78,51 @@ struct uverbs_root { size_t num_groups; }; +#define UVERBS_BUILD_BUG_ON(cond) (sizeof(char[1 - 2 * !!(cond)]) - \ + sizeof(char)) +#define UVERBS_TYPE_ALLOC_FD(_order, _obj_size, _free_fn, _fops, _name, _flags)\ + ((const struct uverbs_type_alloc_action) \ + {.type = UVERBS_ATTR_TYPE_FD, \ + .order = _order, \ + .obj_size = (_obj_size) + \ + UVERBS_BUILD_BUG_ON((_obj_size) < sizeof(struct ib_uobject)), \ + .free_fn = _free_fn, \ + .fd = {.fops = _fops, \ + .name = _name, \ + .flags = _flags} }) +#define UVERBS_TYPE_ALLOC_IDR_SZ(_size, _order, _free_fn) \ + ((const struct uverbs_type_alloc_action) \ + {.type = UVERBS_ATTR_TYPE_IDR, \ + .order = _order, \ + .free_fn = _free_fn, \ + .obj_size = (_size) + \ + UVERBS_BUILD_BUG_ON((_size) < sizeof(struct ib_uobject)),}) +#define UVERBS_TYPE_ALLOC_IDR(_order, _free_fn) \ + UVERBS_TYPE_ALLOC_IDR_SZ(sizeof(struct ib_uobject), _order, _free_fn) +#define DECLARE_UVERBS_TYPE(name, _alloc) \ + const struct uverbs_type name = { \ + .alloc = _alloc, \ + } +#define _UVERBS_TYPE_SZ(...) \ + (sizeof((const struct uverbs_type *[]){__VA_ARGS__}) / \ + sizeof(const struct uverbs_type *)) +#define ADD_UVERBS_TYPE(type_idx, type_ptr) \ + [type_idx] = ((const struct uverbs_type * const)&(type_ptr)) +#define UVERBS_TYPES(...) ((const struct uverbs_type_group) \ + {.num_types = _UVERBS_TYPE_SZ(__VA_ARGS__), \ + .types = (const struct uverbs_type *[]){__VA_ARGS__} }) +#define DECLARE_UVERBS_TYPES(name, ...) \ + const struct uverbs_type_group name = UVERBS_TYPES(__VA_ARGS__) + +#define _UVERBS_TYPES_SZ(...) \ + (sizeof((const struct uverbs_type_group *[]){__VA_ARGS__}) / \ + sizeof(const struct uverbs_type_group *)) + +#define UVERBS_TYPES_GROUP(...) \ + ((const struct uverbs_root){ \ + .type_groups = (const struct uverbs_type_group *[]){__VA_ARGS__},\ + .num_groups = _UVERBS_TYPES_SZ(__VA_ARGS__)}) +#define DECLARE_UVERBS_TYPES_GROUP(name, ...) \ + const struct uverbs_root name = UVERBS_TYPES_GROUP(__VA_ARGS__) + #endif