From patchwork Wed Feb 24 09:42:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 8403411 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D336D9F2F0 for ; Wed, 24 Feb 2016 09:43:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 82C16202EC for ; Wed, 24 Feb 2016 09:43:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0893B202EB for ; Wed, 24 Feb 2016 09:43:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751380AbcBXJnp (ORCPT ); Wed, 24 Feb 2016 04:43:45 -0500 Received: from [193.47.165.129] ([193.47.165.129]:33209 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751155AbcBXJnn (ORCPT ); Wed, 24 Feb 2016 04:43:43 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 24 Feb 2016 11:42:46 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id u1O9gkel026465; Wed, 24 Feb 2016 11:42:46 +0200 Received: from vnc17.mtl.labs.mlnx (localhost.localdomain [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id u1O9gkbW031507; Wed, 24 Feb 2016 11:42:46 +0200 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id u1O9gkw2031506; Wed, 24 Feb 2016 11:42:46 +0200 From: Yishai Hadas To: dledford@redhat.com Cc: linux-rdma@vger.kernel.org, yishaih@mellanox.com, matanb@mellanox.com, majd@mellanox.com, talal@mellanox.com, ogerlitz@mellanox.com Subject: [PATCH V1 libibverbs 5/8] Add helper functions to work with the extended WC Date: Wed, 24 Feb 2016 11:42:01 +0200 Message-Id: <1456306924-31298-6-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1456306924-31298-1-git-send-email-yishaih@mellanox.com> References: <1456306924-31298-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matan Barak Add bunch of functions that may help application and drivers to work with the extended WC. (i.e. ibv_wc_ex) It includes: - ibv_wc_ex_get_offsetof_xx functions to get an offset of a specific field. - ibv_wc_ex_getxx functions to get the data of a specific field. - ibv_wc_ex_get_size - function to get ibv_wc_ex size. Those functions uses the CQ's WC creation flags and rely on the order of the fields as described in verbs.h. To implement the above functions this patch uses the __builtin_popcountll functionality to calculate how many bits are set in a given u64. As on some compilers popcountll doesn't exist the patch adds ibv_popcount64 with the required implementation and use it all around. Signed-off-by: Matan Barak Reviewed-by: Yishai Hadas --- Makefile.am | 3 +- include/infiniband/compiler.h | 91 +++++++++++++++++++++++++++++++++++ include/infiniband/verbs.h | 108 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 include/infiniband/compiler.h diff --git a/Makefile.am b/Makefile.am index 4698ecb..a916acb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,7 +44,8 @@ libibverbsincludedir = $(includedir)/infiniband libibverbsinclude_HEADERS = include/infiniband/arch.h include/infiniband/driver.h \ include/infiniband/kern-abi.h include/infiniband/opcode.h include/infiniband/verbs.h \ - include/infiniband/sa-kern-abi.h include/infiniband/sa.h include/infiniband/marshall.h + include/infiniband/sa-kern-abi.h include/infiniband/sa.h include/infiniband/marshall.h \ + include/infiniband/compiler.h man_MANS = man/ibv_asyncwatch.1 man/ibv_devices.1 man/ibv_devinfo.1 \ man/ibv_rc_pingpong.1 man/ibv_uc_pingpong.1 man/ibv_ud_pingpong.1 \ diff --git a/include/infiniband/compiler.h b/include/infiniband/compiler.h new file mode 100644 index 0000000..5d54fbe --- /dev/null +++ b/include/infiniband/compiler.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016 Mellanox, Ltd. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef INFINIBAND_COMPILER_H +#define INFINIBAND_COMPILER_H + +#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +#define ibv_popcount64 __builtin_popcountll +#endif + +#ifndef __has_builtin +#define __has_builtin(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if __has_builtin(__builtin_popcountll) && !defined(ibv_popcount64) +#define ibv_popcount64 __builtin_popcountll +#endif + +#ifndef ibv_popcount64 +/* From FreeBSD: + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + /* Population count of how many bits are set */ +static inline int ibv_popcount64(uint64_t _x) +{ + _x = (_x & 0x5555555555555555) + ((_x & 0xaaaaaaaaaaaaaaaa) >> 1); + _x = (_x & 0x3333333333333333) + ((_x & 0xcccccccccccccccc) >> 2); + _x = (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0f; + _x = (_x + (_x >> 8)); + _x = (_x + (_x >> 16)); + _x = (_x + (_x >> 32)) & 0x000000ff; + return _x; +} +#endif + +#endif diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h index 232b0df..67a2cb1 100644 --- a/include/infiniband/verbs.h +++ b/include/infiniband/verbs.h @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef __cplusplus # define BEGIN_C_DECLS extern "C" { @@ -466,6 +467,113 @@ struct ibv_wc_ex { uint8_t buffer[0]; }; +static inline size_t ibv_wc_ex_get_offsetof64(uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + return ibv_popcount64(cq_creation_wc_flags & + IBV_WC_EX_WITH_64BIT_FIELDS & + (flag - 1)) * sizeof(uint64_t); +} + +static inline size_t ibv_wc_ex_get_offsetof32(uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + return ibv_popcount64(cq_creation_wc_flags & + (IBV_WC_EX_WITH_64BIT_FIELDS)) * + sizeof(uint64_t) + + ibv_popcount64(cq_creation_wc_flags & + IBV_WC_EX_WITH_32BIT_FIELDS & + (flag - 1)) * sizeof(uint32_t); +} + +static inline size_t ibv_wc_ex_get_offsetof16(uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + return ibv_popcount64(cq_creation_wc_flags & + (IBV_WC_EX_WITH_64BIT_FIELDS)) * + sizeof(uint64_t) + + ibv_popcount64(cq_creation_wc_flags & + (IBV_WC_EX_WITH_32BIT_FIELDS)) * + sizeof(uint32_t) + + ibv_popcount64(cq_creation_wc_flags & + IBV_WC_EX_WITH_16BIT_FIELDS & + (flag - 1)) * sizeof(uint16_t); +} + +static inline size_t ibv_wc_ex_get_offsetof8(uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + return ibv_popcount64(cq_creation_wc_flags & + (IBV_WC_EX_WITH_64BIT_FIELDS)) * + sizeof(uint64_t) + + ibv_popcount64(cq_creation_wc_flags & + (IBV_WC_EX_WITH_32BIT_FIELDS)) * + sizeof(uint32_t) + + ibv_popcount64(cq_creation_wc_flags & + (IBV_WC_EX_WITH_16BIT_FIELDS)) * + sizeof(uint16_t) + + ibv_popcount64(cq_creation_wc_flags & + IBV_WC_EX_WITH_8BIT_FIELDS & + (flag - 1)) * sizeof(uint8_t); +} + +static inline uint64_t ibv_wc_ex_get64(const struct ibv_wc_ex *wc_ex, + uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + uint64_t *pdata = (uint64_t *)(wc_ex->buffer + + ibv_wc_ex_get_offsetof64(cq_creation_wc_flags, + flag)); + + return *pdata; +} + +static inline uint32_t ibv_wc_ex_get32(const struct ibv_wc_ex *wc_ex, + uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + uint32_t *pdata = (uint32_t *)(wc_ex->buffer + + ibv_wc_ex_get_offsetof32(cq_creation_wc_flags, + flag)); + + return *pdata; +} + +static inline uint16_t ibv_wc_ex_get16(const struct ibv_wc_ex *wc_ex, + uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + uint16_t *pdata = (uint16_t *)(wc_ex->buffer + + ibv_wc_ex_get_offsetof16(cq_creation_wc_flags, + flag)); + + return *pdata; +} + +static inline uint8_t ibv_wc_ex_get8(const struct ibv_wc_ex *wc_ex, + uint64_t cq_creation_wc_flags, + enum ibv_wc_flags_ex flag) +{ + uint8_t *pdata = (uint8_t *)(wc_ex->buffer + + ibv_wc_ex_get_offsetof8(cq_creation_wc_flags, + flag)); + + return *pdata; +} + +static inline size_t ibv_wc_ex_get_size(uint64_t flags) +{ + return ((ibv_popcount64(flags & IBV_WC_EX_WITH_64BIT_FIELDS) * + sizeof(uint64_t) + + ibv_popcount64(flags & IBV_WC_EX_WITH_32BIT_FIELDS) * + sizeof(uint32_t) + + ibv_popcount64(flags & IBV_WC_EX_WITH_16BIT_FIELDS) * + sizeof(uint16_t) + + ibv_popcount64(flags & IBV_WC_EX_WITH_8BIT_FIELDS) * + sizeof(uint8_t) + (sizeof(uint64_t) - 1)) & + ~(sizeof(uint64_t) - 1)) + sizeof(struct ibv_wc_ex); +} + enum ibv_access_flags { IBV_ACCESS_LOCAL_WRITE = 1, IBV_ACCESS_REMOTE_WRITE = (1<<1),