Example #1
0
def detect_supported_caps():
    """
    Generates list of supported caps

    Returns
        list of supported caps
    """
    result = []
    # generate list of supported capabilities

    # Intel RDT L3 CAT
    if common.PQOS_API.is_l3_cat_supported():
        result.append(common.CAT_CAP)

    # Intel RDT MBA
    if common.PQOS_API.is_mba_supported():
        result.append(common.MBA_CAP)

    if sstbf.is_sstbf_enabled():
        result.append(common.SSTBF_CAP)

    if power.is_sstcp_enabled():
        result.append(common.POWER_CAP)

    return result
Example #2
0
def test_is_sstbf_enabled():
    class SYS:
        def __init__(self, enabled):
            self.sst_bf_enabled = enabled

    with mock.patch("pwr.get_system", return_value=SYS(True)) as mock_get_system:
        assert sstbf.is_sstbf_enabled()
        mock_get_system.assert_called_once()

    with mock.patch("pwr.get_system", return_value=SYS(False)) as mock_get_system:
        assert not sstbf.is_sstbf_enabled()
        mock_get_system.assert_called_once()

    with mock.patch("pwr.get_system", return_value=None) as mock_get_system:
        assert not sstbf.is_sstbf_enabled()
        mock_get_system.assert_called_once()

    with mock.patch("pwr.get_system", side_effect = IOError('Test')) as mock_get_system:
        assert not sstbf.is_sstbf_enabled()
        mock_get_system.assert_called_once()
Example #3
0
def test_is_sstbf_enabled():
    class CPU:
        def __init__(self, enabled):
            self.sst_bf_enabled = enabled

        def read_capabilities(self, core=None):
            return

    with mock.patch("pwr.get_cpus", return_value=[CPU(True),
                                                  CPU(True)]) as mock_get_cpus:
        assert sstbf.is_sstbf_enabled()
        mock_get_cpus.assert_called_once()

    with mock.patch("pwr.get_cpus",
                    return_value=[CPU(True), CPU(False)]) as mock_get_cpus:
        assert not sstbf.is_sstbf_enabled()
        mock_get_cpus.assert_called_once()

    with mock.patch("pwr.get_cpus",
                    return_value=[CPU(False), CPU(False)]) as mock_get_cpus:
        assert not sstbf.is_sstbf_enabled()
        mock_get_cpus.assert_called_once()

    with mock.patch("pwr.get_cpus", return_value=None) as mock_get_cpus:
        assert not sstbf.is_sstbf_enabled()
        mock_get_cpus.assert_called_once()

    with mock.patch("pwr.get_cpus", return_value=[]) as mock_get_cpus:
        assert not sstbf.is_sstbf_enabled()
        mock_get_cpus.assert_called_once()

    with mock.patch("pwr.get_cpus",
                    side_effect=IOError('Test')) as mock_get_cpus:
        assert not sstbf.is_sstbf_enabled()
        mock_get_cpus.assert_called_once()
Example #4
0
def test_is_sstbf_enabled():
    with mock.patch("sstbf.is_sstbf_supported", return_value=True) as mock_supp,\
         mock.patch("sstbf._get_all_cores", return_value=[0,5,10,15]) as mock_all_cores,\
         mock.patch("sstbf._get_core_freqs", return_value=(2000,2000,2000)) as mock_get_freq:

        assert sstbf.is_sstbf_enabled()
        mock_supp.assert_called_once()
        mock_all_cores.assert_called_once()

        calls = [mock.call(0), mock.call(5), mock.call(10), mock.call(15)]
        mock_get_freq.assert_has_calls(calls, any_order=True)

        mock_supp.return_value = False
        assert not sstbf.is_sstbf_enabled()

        mock_supp.return_value = True

        mock_all_cores.return_value = []
        assert not sstbf.is_sstbf_enabled()

        mock_all_cores.return_value = None
        assert not sstbf.is_sstbf_enabled()

        mock_all_cores.return_value = [0, 5, 10, 15]

        mock_get_freq.return_value = (2700, 2300, 2300)
        assert not sstbf.is_sstbf_enabled()

        mock_get_freq.return_value = (2000, 2000, 2000)

        assert sstbf.is_sstbf_enabled()
Example #5
0
    def get():
        """
        Handles HTTP GET /caps/sstbf request.
        Retrieve SST-BF capabilities details

        Returns:
            response, status code
        """
        res = {
            'enabled': sstbf.is_sstbf_enabled(),
            'hp_cores': sstbf.get_hp_cores(),
            'std_cores': sstbf.get_std_cores()
        }
        return res, 200
Example #6
0
    def run(self, args):
        """
        Runs main loop.

        Parameters:
            args: command line arguments
        """

        # load config file
        try:
            common.CONFIG_STORE.from_file(args.config)
        except IOError as ex:
            log.error("Error reading from config file {}... ".format(
                args.config))
            log.error(ex)
            return
        except (ValueError, ValidationError, KeyError) as ex:
            log.error("Could not parse config file {}... ".format(args.config))
            log.error(ex)
            return

        log.debug("Cores controlled: {}".\
            format(common.CONFIG_STORE.get_pool_attr('cores', None)))

        data = common.CONFIG_STORE.get_config()
        for pool in data['pools']:
            log.debug("Pool: {}/{} Cores: {}, Apps: {}".format(pool.get('name'),\
                pool.get('id'), pool.get('cores'), pool.get('apps')))

        # set initial SST-BF configuration
        if caps.sstbf_supported():
            result = sstbf.configure_sstbf()
            if result != 0:
                log.error(
                    "Failed to apply initial SST-BF configuration, terminating..."
                )
                return

            log.info("SST-BF enabled, {}configured.".\
                format("not " if not sstbf.is_sstbf_enabled() else ""))
            log.info("SST-BF HP cores: {}".format(sstbf.get_hp_cores()))
            log.info("SST-BF STD cores: {}".format(sstbf.get_std_cores()))
        else:
            log.info("SST-BF not enabled")

        # set initial RDT configuration
        log.info("Configuring RDT")
        result = cache_ops.configure_rdt()
        if result != 0:
            log.error(
                "Failed to apply initial RDT configuration, terminating...")
            return

        # set CTRL+C sig handler
        signal.signal(signal.SIGINT, self.signal_handler)

        # rate limiting
        last_cfg_change_ts = 0
        min_time_diff = 1 / common.RATE_LIMIT

        while not self.stop_event.is_set():
            if common.CONFIG_STORE.is_config_changed():

                time_diff = time.time() - last_cfg_change_ts
                if time_diff < min_time_diff:
                    log.info("Rate Limiter, sleeping " \
                        + str(round((min_time_diff - time_diff) * 1000)) + "ms...")
                    time.sleep(min_time_diff - time_diff)

                log.info("Configuration changed, processing new config...")
                result = cache_ops.configure_rdt()

                last_cfg_change_ts = time.time()

                if result != 0:
                    log.error("Failed to apply RDT configuration!")
                    break

        log.info("Terminating...")

        return