コード例 #1
0
ファイル: test_sstbf.py プロジェクト: yuhcaesar/intel-cmt-cat
def test_configure_sstbf():

    cores = []
    for i in range(4):
        core = mock.MagicMock()
        core.P1_FREQ = 99
        core.BASE_FREQ = 123
        core.commit = mock.MagicMock()
        cores.append(core)

    with mock.patch("pwr.get_cores", return_value=cores) as mock_get_cores:
        assert 0 == sstbf.configure_sstbf(True)

        for core in cores:
            core.commit.assert_called_with(sstbf.PWR_CFG_SST_BF_BASE)

        assert 0 == sstbf.configure_sstbf(False)
        for core in cores:
            core.commit.assert_called_with(sstbf.PWR_CFG_BASE)

    for ret_val in [None, []]:
        with mock.patch("pwr.get_cores",
                        return_value=ret_val) as mock_get_cores:
            assert 0 != sstbf.configure_sstbf(True)

    with mock.patch("pwr.get_cores",
                    side_effect=IOError('Test')) as mock_get_cores:
        assert 0 != sstbf.configure_sstbf(True)
        mock_get_cores.assert_called_once()
コード例 #2
0
    def put():
        """
        Handles HTTP PUT /caps/sstbf request.
        Raises BadRequest, InternalError

        Returns:
            response, status code
        """
        json_data = request.get_json()

        # validate app schema
        try:
            schema, resolver = ConfigStore.load_json_schema('modify_sstbf.json')
            jsonschema.validate(json_data, schema, resolver=resolver)
        except (jsonschema.ValidationError, OverflowError) as error:
            raise BadRequest("Request validation failed - %s" % (str(error)))

        if not sstbf.configure_sstbf(json_data['configured']) == 0:
            raise InternalError("Failed to change SST-BF configured state.")

        # update power profile configuration
        power.configure_power()

        res = {'message': "SST-BF caps modified"}
        return res, 200
コード例 #3
0
def test_configure_sstbf():

    sys = mock.MagicMock()
    sys.commit = mock.MagicMock()

    with mock.patch("pwr.get_system", return_value=sys) as mock_get_sys:
        assert 0 == sstbf.configure_sstbf(True)
        mock_get_sys.assert_called_once()
        sys.commit.assert_called_with(sstbf.PWR_CFG_SST_BF)

        assert 0 == sstbf.configure_sstbf(False)
        sys.commit.assert_called_with(sstbf.PWR_CFG_BASE)

    with mock.patch("pwr.get_system", return_value=None) as mock_get_sys:
        assert 0 != sstbf.configure_sstbf(True)
        mock_get_sys.assert_called_once()

    with mock.patch("pwr.get_system", side_effect = IOError('Test')) as mock_get_sys:
        assert 0 != sstbf.configure_sstbf(True)
        mock_get_sys.assert_called_once()
コード例 #4
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