| 1 |
import unittest |
| 2 |
|
| 3 |
from pyverbs.pyverbs_error import PyverbsRDMAError |
| 4 |
from tests.mlx5_base import Mlx5PyverbsAPITestCase |
| 5 |
from pyverbs.qp import QP, QPInitAttr, QPCap |
| 6 |
from pyverbs.srq import SRQ, SrqInitAttr |
| 7 |
from pyverbs.pd import PD |
| 8 |
from pyverbs.cq import CQ |
| 9 |
import tests.utils as u |
| 10 |
|
| 11 |
|
| 12 |
def huge_pages_supported(): |
| 13 |
try: |
| 14 |
u.huge_pages_supported() |
| 15 |
except unittest.SkipTest: |
| 16 |
return False |
| 17 |
return True |
| 18 |
|
| 19 |
|
| 20 |
class ResourcesOnHugePageTest(Mlx5PyverbsAPITestCase): |
| 21 |
def create_cq(self): |
| 22 |
return CQ(self.ctx, 100, None, None, 0) |
| 23 |
|
| 24 |
def create_qp(self): |
| 25 |
with PD(self.ctx) as pd: |
| 26 |
with self.create_cq() as cq: |
| 27 |
attr = QPInitAttr(scq=cq, rcq=cq, cap=QPCap(max_recv_wr=100, |
| 28 |
max_send_wr=100)) |
| 29 |
QP(pd, attr) |
| 30 |
|
| 31 |
def create_srq(self): |
| 32 |
with PD(self.ctx) as pd: |
| 33 |
SRQ(pd, SrqInitAttr()) |
| 34 |
|
| 35 |
def set_env_alloc_type(self, alloc_type): |
| 36 |
self.set_env_variable('MLX_CQ_ALLOC_TYPE', alloc_type) |
| 37 |
self.set_env_variable('MLX_QP_ALLOC_TYPE', alloc_type) |
| 38 |
self.set_env_variable('MLX_SRQ_ALLOC_TYPE', alloc_type) |
| 39 |
|
| 40 |
def create_objects(self): |
| 41 |
self.create_cq() |
| 42 |
self.create_qp() |
| 43 |
self.create_srq() |
| 44 |
|
| 45 |
def test_prefer_obj_on_huge(self): |
| 46 |
""" |
| 47 |
Test PREFER_HUGE allocation type for srq cq and qp. |
| 48 |
""" |
| 49 |
self.set_env_alloc_type('PREFER_HUGE') |
| 50 |
self.create_objects() |
| 51 |
|
| 52 |
def test_obj_on_huge(self): |
| 53 |
""" |
| 54 |
Test HUGE allocation type for srq cq and qp. |
| 55 |
If there are huge pages in the system expect to success, |
| 56 |
else expect to fail. |
| 57 |
""" |
| 58 |
self.set_env_alloc_type('HUGE') |
| 59 |
if huge_pages_supported() and u.is_root(): |
| 60 |
self.create_objects() |
| 61 |
else: |
| 62 |
with self.assertRaises(PyverbsRDMAError): |
| 63 |
self.create_objects() |