mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 15:16:33 +00:00
Detect host support for CPU realtime + add an option for enable it (#2602)
This commit is contained in:
parent
785dc64787
commit
e421284471
@ -68,6 +68,7 @@ ENV_SUPERVISOR_DEV = "SUPERVISOR_DEV"
|
|||||||
ENV_SUPERVISOR_MACHINE = "SUPERVISOR_MACHINE"
|
ENV_SUPERVISOR_MACHINE = "SUPERVISOR_MACHINE"
|
||||||
ENV_SUPERVISOR_NAME = "SUPERVISOR_NAME"
|
ENV_SUPERVISOR_NAME = "SUPERVISOR_NAME"
|
||||||
ENV_SUPERVISOR_SHARE = "SUPERVISOR_SHARE"
|
ENV_SUPERVISOR_SHARE = "SUPERVISOR_SHARE"
|
||||||
|
ENV_SUPERVISOR_CPU_RT = "SUPERVISOR_CPU_RT"
|
||||||
|
|
||||||
REQUEST_FROM = "HASSIO_FROM"
|
REQUEST_FROM = "HASSIO_FROM"
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from ipaddress import IPv4Address
|
from ipaddress import IPv4Address
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
@ -13,6 +15,7 @@ from ..const import (
|
|||||||
ATTR_REGISTRIES,
|
ATTR_REGISTRIES,
|
||||||
DNS_SUFFIX,
|
DNS_SUFFIX,
|
||||||
DOCKER_NETWORK,
|
DOCKER_NETWORK,
|
||||||
|
ENV_SUPERVISOR_CPU_RT,
|
||||||
FILE_HASSIO_DOCKER,
|
FILE_HASSIO_DOCKER,
|
||||||
SOCKET_DOCKER,
|
SOCKET_DOCKER,
|
||||||
)
|
)
|
||||||
@ -55,6 +58,13 @@ class DockerInfo:
|
|||||||
"""Return true, if docker version is supported."""
|
"""Return true, if docker version is supported."""
|
||||||
return self.version >= MIN_SUPPORTED_DOCKER
|
return self.version >= MIN_SUPPORTED_DOCKER
|
||||||
|
|
||||||
|
@property
|
||||||
|
def support_cpu_realtime(self) -> bool:
|
||||||
|
"""Return true, if CONFIG_RT_GROUP_SCHED is loaded."""
|
||||||
|
if not Path("/sys/fs/cgroup/cpu.rt_runtime_us").exists():
|
||||||
|
return False
|
||||||
|
return bool(os.environ.get(ENV_SUPERVISOR_CPU_RT, 0))
|
||||||
|
|
||||||
|
|
||||||
class DockerConfig(JsonConfig):
|
class DockerConfig(JsonConfig):
|
||||||
"""Home Assistant core object for Docker configuration."""
|
"""Home Assistant core object for Docker configuration."""
|
||||||
|
@ -276,6 +276,10 @@ class DockerAddon(DockerInterface):
|
|||||||
@property
|
@property
|
||||||
def cpu_rt_runtime(self) -> Optional[int]:
|
def cpu_rt_runtime(self) -> Optional[int]:
|
||||||
"""Limit CPU real-time runtime in microseconds."""
|
"""Limit CPU real-time runtime in microseconds."""
|
||||||
|
if not self.sys_docker.info.support_cpu_realtime:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If need CPU RT
|
||||||
if self.addon.with_realtime:
|
if self.addon.with_realtime:
|
||||||
return 950000
|
return 950000
|
||||||
return None
|
return None
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Audio docker object."""
|
"""Audio docker object."""
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, List
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
|
|
||||||
@ -61,6 +61,13 @@ class DockerAudio(DockerInterface, CoreSysAttributes):
|
|||||||
"""Generate ulimits for audio."""
|
"""Generate ulimits for audio."""
|
||||||
return [docker.types.Ulimit(name="rtprio", soft=99)]
|
return [docker.types.Ulimit(name="rtprio", soft=99)]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cpu_rt_runtime(self) -> Optional[int]:
|
||||||
|
"""Limit CPU real-time runtime in microseconds."""
|
||||||
|
if not self.sys_docker.info.support_cpu_realtime:
|
||||||
|
return None
|
||||||
|
return 950000
|
||||||
|
|
||||||
def _run(self) -> None:
|
def _run(self) -> None:
|
||||||
"""Run Docker image.
|
"""Run Docker image.
|
||||||
|
|
||||||
@ -83,7 +90,7 @@ class DockerAudio(DockerInterface, CoreSysAttributes):
|
|||||||
detach=True,
|
detach=True,
|
||||||
cap_add=self.capabilities,
|
cap_add=self.capabilities,
|
||||||
ulimits=self.ulimits,
|
ulimits=self.ulimits,
|
||||||
cpu_rt_runtime=950000,
|
cpu_rt_runtime=self.cpu_rt_runtime,
|
||||||
device_cgroup_rules=self.cgroups_rules,
|
device_cgroup_rules=self.cgroups_rules,
|
||||||
environment={ENV_TIME: self.sys_config.timezone},
|
environment={ENV_TIME: self.sys_config.timezone},
|
||||||
volumes=self.volumes,
|
volumes=self.volumes,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user