diff mbox series

[rdma-core,3/4] pyverbs: Document ParentDomain class and add a simple example

Message ID 20191114093732.12637-4-noaos@mellanox.com (mailing list archive)
State Not Applicable
Headers show
Series pyverbs: Introduce parent domain | expand

Commit Message

Noa Osherovich Nov. 14, 2019, 9:37 a.m. UTC
From: Edward Srouji <edwards@mellanox.com>

Add a documentation for ParentDomain with a simple code snippet
demonstrating the creation of the object with Python defined allocators.

Signed-off-by: Edward Srouji <edwards@mellanox.com>
Reviewd-by: Noa Osherovich <noaos@mellanox.com>
---
 Documentation/pyverbs.md | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/Documentation/pyverbs.md b/Documentation/pyverbs.md
index 29ab9592c53c..db6c6b99905e 100755
--- a/Documentation/pyverbs.md
+++ b/Documentation/pyverbs.md
@@ -390,3 +390,30 @@  srq_attr.comp_mask = e.IBV_SRQ_INIT_ATTR_TYPE | e.IBV_SRQ_INIT_ATTR_PD | \
                      e.IBV_SRQ_INIT_ATTR_CQ | e.IBV_SRQ_INIT_ATTR_XRCD
 srq = SRQ(ctx, srq_attr)
 ```
+
+##### ParentDomain
+The following code demonstrates the creation of Parent Domain object.
+In this example, a simple Python allocator is defined. It uses MemAlloc class to
+allocate aligned memory using a C style aligned_alloc.
+```python
+from pyverbs.pd import PD, ParentDomainInitAttr, ParentDomain, \
+    ParentDomainContext
+from pyverbs.device import Context
+from pyverbs.base import MemAlloc
+
+
+def alloc_p_func(pd, context, size, alignment, resource_type):
+    p = MemAlloc.aligned_alloc(size, alignment)
+    return p
+
+
+def free_p_func(pd, context, ptr, resource_type):
+    MemAlloc.free(ptr)
+
+
+ctx = Context(name='rocep0s8f0')
+pd = PD(ctx)
+pd_ctx = ParentDomainContext(pd, alloc_p_func, free_p_func)
+pd_attr = ParentDomainInitAttr(pd=pd, pd_context=pd_ctx)
+parent_domain = ParentDomain(ctx, attr=pd_attr)
+```