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_NAME = "SUPERVISOR_NAME"
|
||||
ENV_SUPERVISOR_SHARE = "SUPERVISOR_SHARE"
|
||||
ENV_SUPERVISOR_CPU_RT = "SUPERVISOR_CPU_RT"
|
||||
|
||||
REQUEST_FROM = "HASSIO_FROM"
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
from contextlib import suppress
|
||||
from ipaddress import IPv4Address
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import attr
|
||||
@ -13,6 +15,7 @@ from ..const import (
|
||||
ATTR_REGISTRIES,
|
||||
DNS_SUFFIX,
|
||||
DOCKER_NETWORK,
|
||||
ENV_SUPERVISOR_CPU_RT,
|
||||
FILE_HASSIO_DOCKER,
|
||||
SOCKET_DOCKER,
|
||||
)
|
||||
@ -55,6 +58,13 @@ class DockerInfo:
|
||||
"""Return true, if docker version is supported."""
|
||||
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):
|
||||
"""Home Assistant core object for Docker configuration."""
|
||||
|
@ -276,6 +276,10 @@ class DockerAddon(DockerInterface):
|
||||
@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
|
||||
|
||||
# If need CPU RT
|
||||
if self.addon.with_realtime:
|
||||
return 950000
|
||||
return None
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Audio docker object."""
|
||||
import logging
|
||||
from typing import Dict, List
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import docker
|
||||
|
||||
@ -61,6 +61,13 @@ class DockerAudio(DockerInterface, CoreSysAttributes):
|
||||
"""Generate ulimits for audio."""
|
||||
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:
|
||||
"""Run Docker image.
|
||||
|
||||
@ -83,7 +90,7 @@ class DockerAudio(DockerInterface, CoreSysAttributes):
|
||||
detach=True,
|
||||
cap_add=self.capabilities,
|
||||
ulimits=self.ulimits,
|
||||
cpu_rt_runtime=950000,
|
||||
cpu_rt_runtime=self.cpu_rt_runtime,
|
||||
device_cgroup_rules=self.cgroups_rules,
|
||||
environment={ENV_TIME: self.sys_config.timezone},
|
||||
volumes=self.volumes,
|
||||
|
Loading…
x
Reference in New Issue
Block a user