def test_init_sstbf(): for cfgd_value in [True, False]: with mock.patch("common.CONFIG_STORE.get_config", return_value={'sstbf' : {'configured' : cfgd_value}}) as mock_get_cfg,\ mock.patch("sstbf.configure_sstbf", return_value=0) as mock_cfg: assert 0 == sstbf.init_sstbf() mock_get_cfg.assert_called_once() mock_cfg.assert_called_once_with(cfgd_value)
def run(self): """ Runs main loop. """ # process/validate already loaded config file try: common.CONFIG_STORE.process_config() except Exception as ex: log.error("Invalid config file... ") 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_enabled(): result = sstbf.init_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_configured() 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 SST-CP configuration if SST-BF is not configured if caps.sstcp_enabled(): if sstbf.is_sstbf_configured(): log.info( "Power Profiles/SST-CP enabled, not configured, SST-BF is configured" ) else: log.info("Power Profiles/SST-CP enabled.") # set initial POWER configuration result = power.configure_power() if result != 0: log.error("Failed to apply initial Power Profiles configuration,"\ " terminating...") return else: log.info("Power Profiles/EPP not enabled") # set initial RDT configuration log.info("Configuring RDT") # Configure MBA CTRL if caps.mba_supported(): result = common.PQOS_API.enable_mba_bw( common.CONFIG_STORE.get_mba_ctrl_enabled()) if result != 0: log.error( "libpqos MBA CTRL initialization failed, Terminating...") return log.info("RDT MBA CTRL %sabled"\ % ("en" if common.PQOS_API.is_mba_bw_enabled() else "dis")) 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) self.event_handler() log.info("Terminating...")
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 Exception as ex: log.error("Invalid 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_enabled(): result = sstbf.init_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_configured() 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 SST-CP configuration if SST-BF is not configured if caps.sstcp_enabled(): if sstbf.is_sstbf_configured(): log.info("Power Profiles/SST-CP enabled, not configured, SST-BF is configured") else: log.info("Power Profiles/SST-CP enabled.") # set initial POWER configuration result = power.configure_power() if result != 0: log.error("Failed to apply initial Power Profiles configuration,"\ " terminating...") return else: log.info("Power Profiles/EPP 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) self.event_handler() log.info("Terminating...")
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_enabled(): result = sstbf.init_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