proc_stats: fix vcio ioctl logging spam
Use the low level os.open() method to open the vcio device. This resolves "unknown ioctl" spamming of the kernel log. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b8ce199edd
commit
2641fc54d6
|
@ -35,6 +35,7 @@ if TYPE_CHECKING:
|
||||||
STAT_CALLBACK = Callable[[int], Optional[Awaitable]]
|
STAT_CALLBACK = Callable[[int], Optional[Awaitable]]
|
||||||
|
|
||||||
VC_GEN_CMD_FILE = "/usr/bin/vcgencmd"
|
VC_GEN_CMD_FILE = "/usr/bin/vcgencmd"
|
||||||
|
VCIO_PATH = "/dev/vcio"
|
||||||
STATM_FILE_PATH = "/proc/self/smaps_rollup"
|
STATM_FILE_PATH = "/proc/self/smaps_rollup"
|
||||||
NET_DEV_PATH = "/proc/net/dev"
|
NET_DEV_PATH = "/proc/net/dev"
|
||||||
TEMPERATURE_PATH = "/sys/class/thermal/thermal_zone0/temp"
|
TEMPERATURE_PATH = "/sys/class/thermal/thermal_zone0/temp"
|
||||||
|
@ -65,7 +66,7 @@ class ProcStats:
|
||||||
self.stat_update_timer = self.event_loop.register_timer(
|
self.stat_update_timer = self.event_loop.register_timer(
|
||||||
self._handle_stat_update)
|
self._handle_stat_update)
|
||||||
self.vcgencmd: Optional[VCGenCmd] = None
|
self.vcgencmd: Optional[VCGenCmd] = None
|
||||||
if os.path.exists(VC_GEN_CMD_FILE):
|
if os.path.exists(VC_GEN_CMD_FILE) and os.path.exists(VCIO_PATH):
|
||||||
logging.info("Detected 'vcgencmd', throttle checking enabled")
|
logging.info("Detected 'vcgencmd', throttle checking enabled")
|
||||||
self.vcgencmd = VCGenCmd()
|
self.vcgencmd = VCGenCmd()
|
||||||
self.server.register_notification("proc_stats:cpu_throttled")
|
self.server.register_notification("proc_stats:cpu_throttled")
|
||||||
|
@ -345,7 +346,6 @@ class VCGenCmd:
|
||||||
state. This should be less resource intensive than calling "vcgencmd"
|
state. This should be less resource intensive than calling "vcgencmd"
|
||||||
in a subprocess.
|
in a subprocess.
|
||||||
"""
|
"""
|
||||||
VCIO_PATH = pathlib.Path("/dev/vcio")
|
|
||||||
MAX_STRING_SIZE = 1024
|
MAX_STRING_SIZE = 1024
|
||||||
GET_RESULT_CMD = 0x00030080
|
GET_RESULT_CMD = 0x00030080
|
||||||
UINT_SIZE = struct.calcsize("@I")
|
UINT_SIZE = struct.calcsize("@I")
|
||||||
|
@ -356,7 +356,8 @@ class VCGenCmd:
|
||||||
self.err_logged: bool = False
|
self.err_logged: bool = False
|
||||||
|
|
||||||
def run(self, cmd: str = "get_throttled") -> str:
|
def run(self, cmd: str = "get_throttled") -> str:
|
||||||
with self.VCIO_PATH.open("rb") as f:
|
try:
|
||||||
|
fd = os.open(VCIO_PATH, os.O_RDWR)
|
||||||
self.cmd_struct.pack_into(
|
self.cmd_struct.pack_into(
|
||||||
self.cmd_buf, 0,
|
self.cmd_buf, 0,
|
||||||
self.cmd_struct.size,
|
self.cmd_struct.size,
|
||||||
|
@ -368,13 +369,14 @@ class VCGenCmd:
|
||||||
cmd.encode("utf-8"),
|
cmd.encode("utf-8"),
|
||||||
0x00000000
|
0x00000000
|
||||||
)
|
)
|
||||||
try:
|
fcntl.ioctl(fd, self.mailbox_req, self.cmd_buf)
|
||||||
fcntl.ioctl(f.fileno(), self.mailbox_req, self.cmd_buf)
|
|
||||||
except OSError:
|
except OSError:
|
||||||
if not self.err_logged:
|
if not self.err_logged:
|
||||||
logging.exception("VCIO gcgencmd failed")
|
logging.exception("VCIO vcgencmd failed")
|
||||||
self.err_logged = True
|
self.err_logged = True
|
||||||
return ""
|
return ""
|
||||||
|
finally:
|
||||||
|
os.close(fd)
|
||||||
result = self.cmd_struct.unpack_from(self.cmd_buf)
|
result = self.cmd_struct.unpack_from(self.cmd_buf)
|
||||||
ret: int = result[5]
|
ret: int = result[5]
|
||||||
if ret:
|
if ret:
|
||||||
|
|
Loading…
Reference in New Issue