Beispiel #1
0
    def test_get(self, lib):
        "Tests get() method."

        def pqos_mba_cos_num_mock(_p_cap, num_cos_ref):
            "Mock pqos_mba_get_cos_num()."

            ctypes_ref_set_int(num_cos_ref, 2)
            return 0

        def pqos_mba_get_mock(socket, max_num_cos, num_cos_ref, cos_arr):
            "Mock pqos_mba_get()."

            self.assertEqual(socket, 1)
            self.assertEqual(max_num_cos, 2)
            self.assertEqual(len(cos_arr), max_num_cos)

            ctypes_ref_set_int(num_cos_ref, 2)

            cos_arr[0].class_id = 0
            cos_arr[0].mb_max = 4000
            cos_arr[0].ctrl = 1

            cos_arr[1].class_id = 1
            cos_arr[1].mb_max = 8000
            cos_arr[1].ctrl = 1

            return 0

        lib.pqos_cap_get = MagicMock(return_value=0)
        lib.pqos_mba_get_cos_num = MagicMock(side_effect=pqos_mba_cos_num_mock)
        lib.pqos_mba_get = MagicMock(side_effect=pqos_mba_get_mock)

        mba = PqosMba()
        coses = mba.get(1)

        self.assertEqual(len(coses), 2)

        self.assertEqual(coses[0].class_id, 0)
        self.assertEqual(coses[0].mb_max, 4000)
        self.assertTrue(coses[0].ctrl)

        self.assertEqual(coses[1].class_id, 1)
        self.assertEqual(coses[1].mb_max, 8000)
        self.assertTrue(coses[1].ctrl)

        lib.pqos_mba_get.assert_called_once()
        lib.pqos_mba_get_cos_num.assert_called_once()
Beispiel #2
0
    def test_get(self, lib):
        "Tests get() method."

        def pqos_mba_cos_num_mock(_p_cap, num_cos_ref):
            "Mock pqos_mba_get_cos_num()."

            ctypes_ref_set_int(num_cos_ref, 2)
            return 0

        def pqos_mba_get_mock(socket, max_num_cos, num_cos_ref, cos_arr):
            "Mock pqos_mba_get()."

            self.assertEqual(socket, 1)
            self.assertEqual(max_num_cos, 2)
            self.assertEqual(len(cos_arr), max_num_cos)

            ctypes_ref_set_int(num_cos_ref, 2)

            cos_arr[0].class_id = 0
            cos_arr[0].mb_max = 4000
            cos_arr[0].ctrl = 1

            cos_arr[1].class_id = 1
            cos_arr[1].mb_max = 8000
            cos_arr[1].ctrl = 1

            return 0

        lib.pqos_cap_get = MagicMock(return_value=0)
        lib.pqos_mba_get_cos_num = MagicMock(side_effect=pqos_mba_cos_num_mock)
        lib.pqos_mba_get = MagicMock(side_effect=pqos_mba_get_mock)

        mba = PqosMba()
        coses = mba.get(1)

        self.assertEqual(len(coses), 2)

        self.assertEqual(coses[0].class_id, 0)
        self.assertEqual(coses[0].mb_max, 4000)
        self.assertTrue(coses[0].ctrl)

        self.assertEqual(coses[1].class_id, 1)
        self.assertEqual(coses[1].mb_max, 8000)
        self.assertTrue(coses[1].ctrl)

        lib.pqos_mba_get.assert_called_once()
        lib.pqos_mba_get_cos_num.assert_called_once()
Beispiel #3
0
def print_allocation_config(sockets):
    """
    Prints allocation configuration.

    Parameters:
        sockets: array with socket IDs
    """

    mba = PqosMba()

    for socket in sockets:
        try:
            coses = mba.get(socket)

            print("MBA COS definitions for Socket %u:" % socket)

            for cos in coses:
                cos_params = (cos.class_id, cos.mb_max)
                print("    MBA COS%u => %u%% available" % cos_params)
        except:
            print("Error")
            raise
Beispiel #4
0
# Check if MBA is supported
cap = PqosCap()
mba_supported = False
try:
    cap.get_type('mba')
    mba_supported = True
except:
    pass

print('Is MBA supported? %s' % ('Yes' if mba_supported else 'No'))

if mba_supported:
    mba = PqosMba()

    # Get MBA configuration for socket 0
    coses = mba.get(0)

    print('MBA configuration for socket 0:')
    for cos in coses:
        print('COS: %d' % cos.class_id)
        print('MB max: %d' % cos.mb_max)
        print('CTRL: %s' % cos.ctrl)
        print('')

    # Configure MBA, 50% of available bandwidth for COS 0
    cos = mba.COS(0, 50)
    # Apply for socket 0
    actual = mba.set(0, [cos])

    print('Trying to set %d%%...' % cos.mb_max)
    print('Actually set: %d%%' % actual[0].mb_max)
Beispiel #5
0
# Check if MBA is supported
cap = PqosCap()
mba_supported = False
try:
    cap.get_type('mba')
    mba_supported = True
except:
    pass

print('Is MBA supported? %s' % ('Yes' if mba_supported else 'No'))

if mba_supported:
    mba = PqosMba()

    # Get MBA configuration for socket 0
    coses = mba.get(0)

    print('MBA configuration for socket 0:')
    for cos in coses:
        print('COS: %d' % cos.class_id)
        print('MB max: %d' % cos.mb_max)
        print('CTRL: %s' % cos.ctrl)
        print('')

    # Configure MBA, 50% of available bandwidth for COS 0
    cos = mba.COS(0, 50)
    # Apply for socket 0
    actual = mba.set(0, [cos])

    print('Trying to set %d%%...' % cos.mb_max)
    print('Actually set: %d%%' % actual[0].mb_max)