Exemple #1
0
    def test__get_pwr_cores(self):
        class CORE:
            def __init__(self, id):
                self.core_id = id

        CORES_LIST = [CORE(0), CORE(1)]

        with mock.patch("pwr.get_cores",
                        return_value=CORES_LIST) as mock_get_cores:
            assert power_common.get_pwr_cores() == CORES_LIST
            mock_get_cores.assert_called_once()

        with mock.patch("pwr.get_cores", return_value=[]) as mock_get_cores:
            assert not power_common.get_pwr_cores()
            mock_get_cores.assert_called_once()

        with mock.patch("pwr.get_cores", return_value=None) as mock_get_cores:
            assert not power_common.get_pwr_cores()
            mock_get_cores.assert_called_once()

        with mock.patch("pwr.get_cores",
                        side_effect=IOError('Test')) as mock_get_cores:
            assert not power_common.get_pwr_cores()
            mock_get_cores.assert_called_once()

        with mock.patch("pwr.get_cores",
                        side_effect=ValueError('Test')) as mock_get_cores:
            assert not power_common.get_pwr_cores()
            mock_get_cores.assert_called_once()
Exemple #2
0
def _populate_cores():
    """
    Gets HP and STD cores from PWR lib
    """
    cores = power_common.get_pwr_cores()
    if not cores:
        return

    global HP_CORES
    global STD_CORES

    HP_CORES = []
    STD_CORES = []

    for core in cores:
        if core.high_priority:
            HP_CORES.append(core.core_id)
        else:
            STD_CORES.append(core.core_id)
Exemple #3
0
def reset(cores):
    """
    Reset power setting

    Parameters:
        cores: list of core ids
    """
    log.debug(("POWER: Reset on cores {}. Setting to \"default\".").format(cores))

    if not cores:
        return -1

    pwr_cores = power_common.get_pwr_cores()
    if not pwr_cores:
        return -1

    for core in pwr_cores:
        if core.core_id in cores:
            core.commit("default")

    return 0
Exemple #4
0
def _set_freqs_epp(cores, min_freq=None, max_freq=None, epp=None):
    """
     Set minimum, maximum frequency and EPP value

    Parameters:
        cores: list of core ids
        min_freq: min core frequency
        max_freq: max core frequency
        epp: EPP value
    """
    if not cores:
        log.error("POWER: No cores specified!")
        return -1

    if not min_freq and not max_freq and not epp:
        log.error("POWER: No power profile parameters specified!")
        return -1

    log.debug(("POWER: Setting min/max/epp on cores {} to {}/{}/{}")\
                .format(cores, min_freq, max_freq, epp))

    pwr_cores = power_common.get_pwr_cores()
    if not pwr_cores:
        log.error("POWER: Unable to get cores from PWR lib!")
        return -1

    for pwr_core in pwr_cores:
        if pwr_core.core_id in cores:
            if min_freq:
                pwr_core.min_freq = min_freq
            if max_freq:
                pwr_core.max_freq = max_freq
            if epp:
                pwr_core.epp = epp

            pwr_core.commit()

    return 0
Exemple #5
0
def _admission_control_check(data):
    """
    Validate Power Profiles configuration,
    admission control check done on PWR lib side

    Parameters
        data: configuration (dict)
    """

    profiles = {}
    for profile in data['power_profiles']:
        profiles[profile['id']] = deepcopy(profile)
        profiles[profile['id']]['cores'] = []

    for pool in data['pools']:
        if 'power_profile' not in pool:
            continue
        profiles[pool['power_profile']]['cores'].extend(pool['cores'])

    cores = power_common.get_pwr_cores()

    for core in cores:
        for profile in profiles.values():
            if core.core_id in profile['cores']:
                core.min_freq = profile['min_freq']
                core.max_freq = profile['max_freq']
                core.epp = profile['epp']
                break

    pwr_sys = power_common.get_pwr_sys()
    result = pwr_sys.request_config()
    pwr_sys.refresh_all()

    if not result:
        raise AdmissionControlError\
            ("Power Profiles configuration would cause CPU to be oversubscribed.")