Ejemplo n.º 1
0
    def test_get(self, lib):
        "Tests get() method."
        # pylint: disable=invalid-name

        def pqos_l3ca_get_mock(socket, cos_num, num_ca_ref, l3cas):
            "Mock pqos_l3ca_get()."

            self.assertEqual(socket, 1)
            self.assertEqual(cos_num, 2)

            cos_c = CPqosL3Ca(class_id=0, u=CPqosL3CaMask(ways_mask=0x01fe))
            cos2_c = CPqosL3Ca(class_id=1, u=CPqosL3CaMask(ways_mask=0x003f))
            cos_arr_c = ctypes_build_array([cos_c, cos2_c])

            ctypes.memmove(l3cas, cos_arr_c, ctypes.sizeof(cos_arr_c))
            ctypes_ref_set_int(num_ca_ref, len(cos_arr_c))

            return 0


        lib.pqos_l3ca_get = MagicMock(side_effect=pqos_l3ca_get_mock)

        l3ca = PqosCatL3()

        with patch('pqos.l3ca.PqosCap') as PqosCapMock:
            PqosCapMock.return_value.get_l3ca_cos_num.return_value = 2
            coses = l3ca.get(1)

        lib.pqos_l3ca_get.assert_called_once()

        self.assertEqual(len(coses), 2)
        self.assertEqual(coses[0].class_id, 0)
        self.assertEqual(coses[0].mask, 0x01fe)
        self.assertEqual(coses[1].class_id, 1)
        self.assertEqual(coses[1].mask, 0x003f)
Ejemplo n.º 2
0
    def init(self, iface, force_iface=False):
        """
        Initializes libpqos

        Returns:
            0 on success
            -1 otherwise
        """

        if not force_iface and not iface in self.supported_iface():
            log.error("RDT does not support '%s' interface!" % (iface))
            return -1

        # deinitialize lib first
        if self.shared_dict['current_iface']:
            self.fini()

        # umount restcrl to improve caps detection
        if platform.system() == 'FreeBSD':
            result = os.system(
                "/sbin/umount -a -t resctrl")  # nosec - string literal
        else:
            result = os.system(
                "/bin/umount -a -t resctrl")  # nosec - string literal
        if result:
            log.error("Failed to umount resctrl fs! status code: %d"\
                    % (os.WEXITSTATUS(result)))
            return -1

        # attempt to initialize libpqos
        try:
            self.pqos.init(iface.upper())
            self.cap = PqosCap()
            self.l3ca = PqosCatL3()
            self.mba = PqosMba()
            self.alloc = PqosAlloc()
            self.cpuinfo = PqosCpuInfo()
        except Exception as ex:
            log.error(str(ex))
            return -1

        # save current interface type in shared dict
        self.shared_dict['current_iface'] = iface

        # Reread MBA BW status from libpqos
        self.refresh_mba_bw_status()

        return 0
Ejemplo n.º 3
0
    def test_get_min_cbm_bits(self, lib):
        "Tests get_min_cbm_bits() method."

        def pqos_l3ca_get_min_cbm_bits_mock(min_cbm_bits_ref):
            "Mock pqos_l3ca_get_min_cbm_bits()."

            ctypes_ref_set_int(min_cbm_bits_ref, 2)
            return 0

        func_mock = MagicMock(side_effect=pqos_l3ca_get_min_cbm_bits_mock)
        lib.pqos_l3ca_get_min_cbm_bits = func_mock

        l3ca = PqosCatL3()
        min_bits = l3ca.get_min_cbm_bits()

        self.assertEqual(min_bits, 2)
Ejemplo n.º 4
0
def set_allocation_class(sockets, class_id, mask):
    """
    Sets up allocation classes of service on selected CPU sockets

    Parameters:
        sockets: a list of socket IDs
        class_id: class of service ID
        mask: COS bitmask
    """

    l3ca = PqosCatL3()
    cos = l3ca.COS(class_id, mask)

    for socket in sockets:
        try:
            l3ca.set(socket, [cos])
        except:
            print("Setting up cache allocation class of service failed!")
Ejemplo n.º 5
0
    def init(self):
        """
        Initializes libpqos

        Returns:
            0 on success
            -1 otherwise
        """

        try:
            self.pqos.init('MSR')
            self.cap = PqosCap()
            self.l3ca = PqosCatL3()
            self.mba = PqosMba()
            self.alloc = PqosAlloc()
            self.cpuinfo = PqosCpuInfo()
        except Exception as ex:
            log.error(str(ex))
            return -1

        return 0
Ejemplo n.º 6
0
def print_allocation_config(sockets):
    """
    Prints allocation configuration.

    Parameters:
        sockets: a list of socket IDs
    """

    l3ca = PqosCatL3()

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

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

            for cos in coses:
                cos_params = (cos.class_id, cos.mask)
                print("    L3CA COS%u => MASK 0x%x" % cos_params)
        except:
            print("Error")
            raise
Ejemplo n.º 7
0
def print_allocation_config():
    """
    Prints allocation configuration.
    """

    l3ca = PqosCatL3()
    alloc = PqosAlloc()
    cpuinfo = PqosCpuInfo()
    sockets = cpuinfo.get_sockets()

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

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

            for cos in coses:
                cos_params = (cos.class_id, cos.mask)
                print("    L3CA COS%u => MASK 0x%x" % cos_params)
        except:
            print("Error")
            raise

    for socket in sockets:
        try:
            print("Core information for socket %u:" % socket)

            cores = cpuinfo.get_cores(socket)

            for core in cores:
                class_id = alloc.assoc_get(core)
                try:
                    print("    Core %u => COS%u" % (core, class_id))
                except:
                    print("    Core %u => ERROR" % core)
        except:
            print("Error")
            raise
Ejemplo n.º 8
0
    def test_set(self, lib):
        "Tests set() method."

        def pqos_l3ca_set_mock(socket, num_ca, l3_ca_arr):
            "Mock pqos_l3ca_set()."

            self.assertEqual(socket, 0)
            self.assertEqual(num_ca, 1)

            cos = l3_ca_arr[0]
            self.assertEqual(cos.class_id, 4)
            self.assertEqual(cos.cdp, 1)
            self.assertEqual(cos.u.s.data_mask, 0x0f)
            self.assertEqual(cos.u.s.code_mask, 0x1f)

            return 0

        lib.pqos_l3ca_set = MagicMock(side_effect=pqos_l3ca_set_mock)

        l3ca = PqosCatL3()
        cos = l3ca.COS(4, data_mask=u'0x0f', code_mask=0x1f)
        l3ca.set(0, [cos])

        lib.pqos_l3ca_set.assert_called_once()
Ejemplo n.º 9
0
    def test_cos_no_masks(self):
        "Tests PqosCatL3.COS class construction when no masks are given."

        with self.assertRaises(ValueError):
            PqosCatL3.COS(1)
Ejemplo n.º 10
0
pqos = Pqos()
pqos.init('MSR')

# Check if L3 CAT is supported
cap = PqosCap()
l3ca_supported = False
try:
    cap.get_type('l3ca')
    l3ca_supported = True
except:
    pass

print('Is L3 CAT supported? %s' % ('Yes' if l3ca_supported else 'No'))

if l3ca_supported:
    l3ca = PqosCatL3()

    # Read L3 CAT configuration for socket 0
    coses = l3ca.get(0)
    for cos in coses:
        print(cos)

    # Configure L3 CAT
    # Build configuration for COS 0 and COS 1
    cos1 = l3ca.COS(0, 0x0007)
    cos2 = l3ca.COS(1, 0x00f8)

    # Set L3 CAT configuration for socket 0
    l3ca.set(0, [cos1, cos2])

# Finalize PQoS library