def __init__(self, cpu): self.cpu = cpu self._factor = self.units["mhz"] self._settings = {} self._new_settings = {} # Attributes that don't change self._lims = read_freq_lims(cpu) self._governors = read_govs(cpu) self.energy_pref_avail = is_energy_pref_avail(cpu) self.energy_prefs = [] self.update_conf()
def update_conf(self): cpu = self.cpu self._settings["freqs"] = read_freqs(cpu) self._settings["governor"] = read_governor(cpu) self._settings["online"] = is_online(cpu) # In case a new governor has been added self._governors = read_govs(cpu) # If energy performance preferences are available self._settings["energy_pref"] = None if self.energy_pref_avail: self._settings["energy_pref"] = read_energy_pref(cpu) self.energy_prefs = read_available_energy_prefs(cpu) self.reset_conf()
def parse_governor(cpu: int, gov: str): """Return valid governor for cpu from config Args: cpu: The cpu to check as an integer gov: The governor value from config Returns: governor: A valid governor """ if cpu not in cpus_available(): return None governors = read_govs(cpu) if not governors: return None if gov in governors: return gov return governors[0]
def _generate_default_profiles(self): """Generate default profiles based on current hardware. The two profiles generated are 'Balanced' and 'Performance'. The profiles apply either power-saving or performance governor. """ # Get a governor list from first cpu govs = read_govs(0) if not govs: return # generate balanced profile based on powersave/ondemand governor if "powersave" in govs: self._profiles["Balanced"] = DefaultProfile( "Balanced", "powersave") elif "ondemand" in govs: self._profiles["Balanced"] = DefaultProfile("Balanced", "ondemand") # generate performance profile based on performance governor if "performance" in govs: self._profiles["Performance"] = DefaultProfile( "Performance", "performance")