def event_handler(self): """ Handles config_changed event """ # 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() if result != 0: log.error("Failed to apply RDT configuration!") break if caps.sstcp_enabled() and not sstbf.is_sstbf_configured(): result = power.configure_power() if result != 0: log.error( "Failed to apply Power Profiles configuration!") break last_cfg_change_ts = time.time() log.info("New configuration processed")
def __init__(self): self.process = None self.app = Flask(__name__) self.app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 self.api = Api(self.app) # initialize SSL context self.context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) self.context.verify_mode = ssl.CERT_REQUIRED self.context.set_ciphers(':'.join(TLS_CIPHERS)) # allow TLS 1.2 and later self.context.options |= ssl.OP_NO_SSLv2 self.context.options |= ssl.OP_NO_SSLv3 self.context.options |= ssl.OP_NO_TLSv1 self.context.options |= ssl.OP_NO_TLSv1_1 self.api.add_resource(Apps, '/apps') self.api.add_resource(App, '/apps/<int:app_id>') self.api.add_resource(Pools, '/pools') self.api.add_resource(Pool, '/pools/<int:pool_id>') if caps.sstcp_enabled(): self.api.add_resource(Powers, '/power_profiles') self.api.add_resource(Power, '/power_profiles/<int:profile_id>') self.api.add_resource(Stats, '/stats') self.api.add_resource(Caps, '/caps') if caps.sstbf_enabled(): self.api.add_resource(Sstbf, '/caps/sstbf') self.api.add_resource(CapsRdtIface, '/caps/rdt_iface') if caps.mba_supported(): self.api.add_resource(CapsMba, '/caps/mba') self.api.add_resource(CapsMbaCtrl, '/caps/mba_ctrl') self.api.add_resource(Reset, '/reset') self.app.register_error_handler(HTTPException, Server.error_handler)
def __init__(self): self.process = None self.app = Flask(__name__) self.app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 self.api = Api(self.app) # initialize SSL context self.context = ssl.SSLContext(ssl.PROTOCOL_TLS) # allow TLS 1.2 and later self.context.options |= ssl.OP_NO_SSLv2 self.context.options |= ssl.OP_NO_SSLv3 self.context.options |= ssl.OP_NO_TLSv1 self.context.options |= ssl.OP_NO_TLSv1_1 self.api.add_resource(Apps, '/apps') self.api.add_resource(App, '/apps/<int:app_id>') self.api.add_resource(Pools, '/pools') self.api.add_resource(Pool, '/pools/<int:pool_id>') if caps.sstcp_enabled(): self.api.add_resource(Powers, '/power_profiles') self.api.add_resource(Power, '/power_profiles/<int:profile_id>') self.api.add_resource(Stats, '/stats') self.api.add_resource(Caps, '/caps') if caps.sstbf_enabled(): self.api.add_resource(Sstbf, '/caps/sstbf') self.api.add_resource(Reset, '/reset') self.app.register_error_handler(HTTPException, Server.error_handler)
def __init__(self): self.process = None self.app = Flask(__name__) self.app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 self.app.url_map.strict_slashes = False self.api = Api(self.app) # initialize SSL context self.context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) self.context.verify_mode = ssl.CERT_REQUIRED self.context.set_ciphers(':'.join(TLS_CIPHERS)) # allow TLS 1.2 and later self.context.options |= ssl.OP_NO_SSLv2 self.context.options |= ssl.OP_NO_SSLv3 self.context.options |= ssl.OP_NO_TLSv1 self.context.options |= ssl.OP_NO_TLSv1_1 # Apps and Pools API self.api.add_resource(Apps, '/apps') self.api.add_resource(App, '/apps/<int:app_id>') self.api.add_resource(Pools, '/pools') self.api.add_resource(Pool, '/pools/<int:pool_id>') # SST-CP API if caps.sstcp_enabled(): self.api.add_resource(Powers, '/power_profiles') self.api.add_resource(Power, '/power_profiles/<int:profile_id>') # Stats and Capabilities API self.api.add_resource(Stats, '/stats') self.api.add_resource(Caps, '/caps') # SST-BF API if caps.sstbf_enabled(): self.api.add_resource(Sstbf, '/caps/sstbf') # RDT interface API self.api.add_resource(CapsRdtIface, '/caps/rdt_iface') # MBA API if caps.mba_supported(): self.api.add_resource(CapsMba, '/caps/mba') self.api.add_resource(CapsMbaCtrl, '/caps/mba_ctrl') # L3 CAT API if caps.cat_l3_supported(): self.api.add_resource(CapsL3ca, '/caps/' + common.CAT_L3_CAP) # L2 CAT API if caps.cat_l2_supported(): self.api.add_resource(CapsL2ca, '/caps/' + common.CAT_L2_CAP) # Reset API self.api.add_resource(Reset, '/reset') self.app.register_error_handler(HTTPException, Server.error_handler)
def cores_set(self, cores): """ Set Pool's cores Parameters: cores: Pool's cores """ old_cores = self.cores_get() # create a diff, create a list of cores that were removed from current pool removed_cores = [core for core in old_cores if core not in cores] # update pool with new core list Pool.pools[self.pool]['cores'] = cores # updated RDT configuration common.PQOS_API.alloc_assoc_set(cores, self.pool) # process list of removed cores # pylint: disable=consider-using-dict-items for pool_id in Pool.pools: if pool_id == self.pool: continue # check if cores were assigned to another pool, # if they were, remove them from that pool Pool.pools[pool_id]['cores'] = \ [core for core in Pool.pools[pool_id]['cores'] if core not in cores] # filter out cores assigned to other pools removed_cores = \ [core for core in removed_cores if core not in Pool.pools[pool_id]['cores']] # Finally assign removed cores back to COS0/"Default" Pool if removed_cores: log.debug(f"Cores assigned to COS#0 {removed_cores}") common.PQOS_API.release(removed_cores) # Reset power profile settings if caps.sstcp_enabled() and removed_cores: power.reset(removed_cores)
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...")