From patchwork Sun Mar 24 14:10:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 10867447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E69D91390 for ; Sun, 24 Mar 2019 14:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D37652940A for ; Sun, 24 Mar 2019 14:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C80E4294B6; Sun, 24 Mar 2019 14:11:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E7BD2940A for ; Sun, 24 Mar 2019 14:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727111AbfCXOL3 (ORCPT ); Sun, 24 Mar 2019 10:11:29 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:53764 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726889AbfCXOL3 (ORCPT ); Sun, 24 Mar 2019 10:11:29 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 24 Mar 2019 16:11:25 +0200 Received: from reg-l-vrt-059-009.mtl.labs.mlnx (reg-l-vrt-059-009.mtl.labs.mlnx [10.135.59.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x2OEAxHx028186; Sun, 24 Mar 2019 16:11:25 +0200 From: Noa Osherovich To: leon@kernel.org, jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich Subject: [PATCH rdma-core 5/6] Documentation: Document creation of CQs using pyverbs Date: Sun, 24 Mar 2019 16:10:39 +0200 Message-Id: <20190324141040.22204-6-noaos@mellanox.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190324141040.22204-1-noaos@mellanox.com> References: <20190324141040.22204-1-noaos@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add code snippets to demonstrate creation of a CQ and an extended CQ. Signed-off-by: Noa Osherovich Reviewed-by: Maor Gottlieb Reviewed-by: Leon Romanovsky --- Documentation/pyverbs.md | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Documentation/pyverbs.md b/Documentation/pyverbs.md index 112d806d9f2b..3a20b7a95769 100644 --- a/Documentation/pyverbs.md +++ b/Documentation/pyverbs.md @@ -225,3 +225,59 @@ with d.Context(name='mlx5_0') as ctx: dm_mr = DmMr(pd, dm_mr_len, e.IBV_ACCESS_ZERO_BASED, dm=dm, offset=0) ``` + +##### CQ +The following snippets show how to create CQs using pyverbs. Pyverbs supports +both CQ and extended CQ (CQEX). +As in C, a completion queue can be created with or without a completion +channel, the snippets show that. +CQ's 3rd parameter is cq_context, a user-defined context. We're using None in +our snippets. +```python +import random + +from pyverbs.cq import CompChannel, CQ +import pyverbs.device as d + +with d.Context(name='mlx5_0') as ctx: + num_cqes = random.randint(0, 200) # Just arbitrary values. Max value can be + # found in device attributes + comp_vector = 0 # An arbitrary value. comp_vector is limited by the + # context's num_comp_vectors + if random.choice([True, False]): + with CompChannel(ctx) as cc: + cq = CQ(ctx, num_cqes, None, cc, comp_vector) + else: + cq = CQ(ctx, num_cqes, None, None, comp_vector) + print(cq) +CQ +Handle : 0 +CQEs : 63 +``` + +```python +import random + +from pyverbs.cq import CqInitAttrEx, CQEX +import pyverbs.device as d +import pyverbs.enums as e + +with d.Context(name='mlx5_0') as ctx: + num_cqe = random.randint(0, 200) + wc_flags = e.IBV_WC_EX_WITH_CVLAN + comp_mask = 0 # Not using flags in this example + # completion channel is not used in this example + attrs = CqInitAttrEx(cqe=num_cqe, wc_flags=wc_flags, comp_mask=comp_mask, + flags=0) + print(attrs) + cq_ex = CQEX(ctx, attrs) + print(cq_ex) + Number of CQEs : 10 +WC flags : IBV_WC_EX_WITH_CVLAN +comp mask : 0 +flags : 0 + +Extended CQ: +Handle : 0 +CQEs : 15 +``` \ No newline at end of file