コード例 #1
0
    def configure():
        """
        Configure Apps, based on config content.
        """

        config = common.CONFIG_STORE.get_config()

        if 'apps' not in config:
            return 0

        # set pid affinity
        for app in config['apps']:
            if 'pids' not in app:
                continue

            app_cores = app['cores'] if 'cores' in app else []
            pool_id = common.CONFIG_STORE.app_to_pool(app['id'])
            pool_cores = common.CONFIG_STORE.get_pool_attr('cores', pool_id)

            # if there are no cores configured for App, or cores configured are
            # not a subset of Pool cores, revert to all Pool cores
            if not app_cores or not set(app_cores).issubset(pool_cores):
                app_cores = pool_cores

            if not app_cores:
                continue

            set_affinity(app['pids'], app_cores)

        return 0
コード例 #2
0
    def pids_set(self, pids):
        """
        Set Pool's PIDs

        Parameters:
            pids: Pool's PIDs
        """
        old_pids = self.pids_get()

        # change core affinity for PIDs not assigned to any pool
        removed_pids = [pid for pid in old_pids if pid not in pids]

        # skip pids assigned to any pool e.g.: apps moved to other pool
        # pylint: disable=consider-using-dict-items
        for pool_id in Pool.pools:
            if pool_id == self.pool:
                continue
            removed_pids = \
                [pid for pid in removed_pids if pid not in Pool.pools[pool_id]['pids']]

        # remove pid form old pool
        if old_pids:
            # pylint: disable=consider-using-dict-items
            for pool_id in Pool.pools:
                if pool_id == self.pool:
                    continue

                pids_moved_from_other_pool = \
                    [pid for pid in Pool.pools[pool_id]['pids'] if pid in pids]

                if pids_moved_from_other_pool:
                    log.debug(
                        f"PIDs moved from other pools {pids_moved_from_other_pool}"
                    )

                # update other pool PIDs
                Pool.pools[pool_id]['pids'] = \
                    [pid for pid in Pool.pools[pool_id]['pids'] if pid not in pids]

        Pool.pools[self.pool]['pids'] = pids

        # set affinity of removed pids to default
        if removed_pids:
            log.debug(
                f"PIDs to be set to core affinity to 'Default' CPUs {removed_pids}"
            )

            # get cores for Default Pool #0
            cores = common.CONFIG_STORE.get_pool_attr('cores', 0)
            set_affinity(removed_pids, cores)