added code to better control governor
This commit is contained in:
@@ -9,10 +9,7 @@ from typing import NamedTuple, Optional
|
||||
class TriggerTuple(NamedTuple):
|
||||
name: str
|
||||
interval_in_seconds: int
|
||||
|
||||
|
||||
class MissingConfig(Exception):
|
||||
pass
|
||||
governor: str
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -53,10 +50,12 @@ class Config:
|
||||
for trigger in _triggers:
|
||||
name = trigger.xpath('name').pop().text
|
||||
interval_in_seconds = trigger.xpath('intervalInSeconds').pop().text
|
||||
governor = trigger.xpath('governor').pop().text
|
||||
ret_val.append(
|
||||
TriggerTuple(
|
||||
name=name,
|
||||
interval_in_seconds=int(interval_in_seconds)
|
||||
interval_in_seconds=int(interval_in_seconds),
|
||||
governor=governor
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<trigger>
|
||||
<name>roon</name>
|
||||
<intervalInSeconds>2</intervalInSeconds>
|
||||
<governor>performance</governor>
|
||||
</trigger>
|
||||
</triggers>
|
||||
</cpuGovernorAutoAdjust>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class TriggerImportError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class MissingConfig(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class GovernorNotFound(Exception):
|
||||
pass
|
||||
+27
-3
@@ -1,16 +1,40 @@
|
||||
from app_class import AppClass
|
||||
from config import Config
|
||||
from cpufreq import cpuFreq
|
||||
from cpufreq import cpuFreq, cpufreq
|
||||
from functools import cached_property
|
||||
from mapping import governor_priority_mapping
|
||||
from exceptions import GovernorNotFound
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Governor(AppClass):
|
||||
def __init__(self, _config: Config) -> None:
|
||||
super().__init__(_config)
|
||||
self.log.info("current governor is: %s", self.current_governor)
|
||||
|
||||
@cached_property
|
||||
def _cpufreq(self) -> cpuFreq:
|
||||
return cpuFreq()
|
||||
def _cpufreq(self) -> Optional[cpuFreq]:
|
||||
try:
|
||||
return cpuFreq()
|
||||
except cpufreq.CPUFreqErrorInit:
|
||||
self.log.warning("cpu architecture has no governor support")
|
||||
return None
|
||||
|
||||
@property
|
||||
def current_governor(self) -> Optional[str]:
|
||||
if self._cpufreq is None:
|
||||
return None
|
||||
_governor = set(self._cpufreq.get_governors().values())
|
||||
_governor_to_return = list(_governor)[0]
|
||||
if len(_governor) == 0:
|
||||
raise GovernorNotFound("Unable to retrieve current governor")
|
||||
if len(_governor) > 1:
|
||||
self.log.error("multiple governors have been set, which is not expected.")
|
||||
# returning governor with highest priority based on performance
|
||||
for gov in _governor:
|
||||
if governor_priority_mapping[gov] < governor_priority_mapping[_governor_to_return]:
|
||||
_governor_to_return == gov
|
||||
return _governor_to_return
|
||||
|
||||
def set_governor(self, governor_name: str) -> None:
|
||||
self.log.debug(
|
||||
|
||||
+13
-2
@@ -1,7 +1,18 @@
|
||||
from types import MappingProxyType
|
||||
from triggers import RoonTrigger
|
||||
|
||||
_dict_mapping = {
|
||||
_trigger_mapping = {
|
||||
'roon': RoonTrigger
|
||||
}
|
||||
trigger_mapping = MappingProxyType(_dict_mapping)
|
||||
trigger_mapping = MappingProxyType(_trigger_mapping)
|
||||
|
||||
_governor_priority_mapping = {
|
||||
'performance': 0,
|
||||
'schedutil': 1,
|
||||
'ondemand': 2,
|
||||
'conservative': 3,
|
||||
'userspace': 4,
|
||||
'performance': 5
|
||||
}
|
||||
|
||||
governor_priority_mapping = MappingProxyType(_governor_priority_mapping)
|
||||
|
||||
+2
-5
@@ -1,9 +1,6 @@
|
||||
from app_class import AppClass
|
||||
from config import Config, TriggerTuple, MissingConfig
|
||||
|
||||
|
||||
class TriggerImportError(Exception):
|
||||
pass
|
||||
from config import Config, TriggerTuple
|
||||
from exceptions import MissingConfig, TriggerImportError
|
||||
|
||||
|
||||
class Trigger(AppClass):
|
||||
|
||||
Reference in New Issue
Block a user