File: mlx5dv_sched.pyx

package info (click to toggle)
rdma-core 33.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,844 kB
  • sloc: ansic: 145,804; python: 5,688; sh: 2,761; perl: 1,465; makefile: 73
file content (168 lines) | stat: -rw-r--r-- 5,634 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2020 Nvidia, Inc. All rights reserved. See COPYING file

from pyverbs.pyverbs_error import PyverbsRDMAError
cimport pyverbs.providers.mlx5.libmlx5 as dv
from pyverbs.base import PyverbsRDMAErrno
from pyverbs.device cimport Context


cdef class Mlx5dvSchedAttr(PyverbsObject):
    def __init__(self, Mlx5dvSchedNode parent_sched_node=None, bw_share=0,
                 max_avg_bw=0, flags=0, comp_mask=0):
        """
        Create a Schedule attr.
        :param parent_sched_node: The parent Mlx5dvSchedNode. None if this Attr
                                  is for the root node.
        :param flags: Bitmask specifying what attributes in the structure
                      are valid.
        :param bw_share: The relative bandwidth share allocated for this
                         element.
        :param max_avg_bw: The maximal transmission rate allowed for the element,
                           averaged over time.
        :param comp_mask: Reserved for future extension.
        """
        self.parent_sched_node = parent_sched_node
        parent_node = parent_sched_node.sched_node if parent_sched_node \
            else NULL
        self.sched_attr.parent = parent_node
        self.sched_attr.flags = flags
        self.sched_attr.bw_share = bw_share
        self.sched_attr.max_avg_bw = max_avg_bw
        self.sched_attr.comp_mask = comp_mask

    @property
    def bw_share(self):
        return self.sched_attr.bw_share

    @property
    def max_avg_bw(self):
        return self.sched_attr.max_avg_bw

    @property
    def flags(self):
        return self.sched_attr.flags

    @property
    def comp_mask(self):
        return self.sched_attr.comp_mask

    def __str__(self):
        print_format = '{:20}: {:<20}\n'
        return 'Mlx5dvSchedAttr:\n' +\
               print_format.format('BW share', self.bw_share) +\
               print_format.format('Max avgerage BW', self.max_avg_bw) +\
               print_format.format('Flags', self.flags) +\
               print_format.format('Comp mask', self.comp_mask)


cdef class Mlx5dvSchedNode(PyverbsObject):
    def __init__(self, Context context not None, Mlx5dvSchedAttr sched_attr):
        """
        Create a Schedule node.
        :param context: Context to create the schedule resources on.
        :param sched_attr: Mlx5dvSchedAttr, containing the sched attributes.
        """
        self.sched_attr = sched_attr
        self.sched_node = dv.mlx5dv_sched_node_create(context.context,
                                                      &sched_attr.sched_attr)
        if self.sched_node == NULL:
            raise PyverbsRDMAErrno('Failed to create sched node')
        self.context = context
        context.sched_nodes.add(self)

    def modify(self, Mlx5dvSchedAttr sched_attr):
        rc = dv.mlx5dv_sched_node_modify(self.sched_node,
                                         &sched_attr.sched_attr)

    def __str__(self):
        print_format = '{:20}: {:<20}\n'
        return 'Mlx5dvSchedNode:\n' +\
               print_format.format('sched attr', str(self.sched_attr))

    @property
    def sched_attr(self):
        return self.sched_attr

    @property
    def bw_share(self):
        return self.sched_attr.bw_share

    @property
    def max_avg_bw(self):
        return self.sched_attr.max_avg_bw

    @property
    def flags(self):
        return self.sched_attr.flags

    @property
    def comp_mask(self):
        return self.sched_attr.comp_mask

    def __dealloc__(self):
        self.close()

    cpdef close(self):
        if self.sched_node != NULL:
            rc = dv.mlx5dv_sched_node_destroy(self.sched_node)
            if rc != 0:
                raise PyverbsRDMAError('Failed to destroy a sched node', rc)
            self.sched_node = NULL
            self.context = None


cdef class Mlx5dvSchedLeaf(PyverbsObject):
    def __init__(self, Context context not None, Mlx5dvSchedAttr sched_attr):
        """
        Create a Schedule leaf.
        :param context: Context to create the schedule resources on.
        :param sched_attr: Mlx5dvSchedAttr, containing the sched attributes.
        """
        self.sched_attr = sched_attr
        self.sched_leaf = dv.mlx5dv_sched_leaf_create(context.context,
                                                      &sched_attr.sched_attr)
        if self.sched_leaf == NULL:
            raise PyverbsRDMAErrno('Failed to create sched leaf')
        self.context = context
        context.sched_leafs.add(self)

    def modify(self, Mlx5dvSchedAttr sched_attr):
        rc = dv.mlx5dv_sched_leaf_modify(self.sched_leaf,
                                         &sched_attr.sched_attr)

    def __str__(self):
        print_format = '{:20}: {:<20}\n'
        return 'Mlx5dvSchedLeaf:\n' +\
               print_format.format('sched attr', str(self.sched_attr))

    @property
    def sched_attr(self):
        return self.sched_attr

    @property
    def bw_share(self):
        return self.sched_attr.bw_share

    @property
    def max_avg_bw(self):
        return self.sched_attr.max_avg_bw

    @property
    def flags(self):
        return self.sched_attr.flags

    @property
    def comp_mask(self):
        return self.sched_attr.comp_mask

    def __dealloc__(self):
        self.close()

    cpdef close(self):
        if self.sched_leaf != NULL:
            rc = dv.mlx5dv_sched_leaf_destroy(self.sched_leaf)
            if rc != 0:
                raise PyverbsRDMAError('Failed to destroy a sched leaf', rc)
            self.sched_leaf = NULL
            self.context = None