From edeb1726ba987847744175cca4fa0eaddad58449 Mon Sep 17 00:00:00 2001 From: Oleksandr Shamray Date: Mon, 16 Oct 2023 19:42:49 +0300 Subject: [PATCH] hw-mgmt: thermal: Fix issue "RuntimeError: reentrant call inside" Fix issue: Logging Error in TC Log writing dmesg: RuntimeError: reentrant call inside Bug: 3630148 Signed-off-by: Oleksandr Shamray --- usr/usr/bin/hw_management_thermal_control.py | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/usr/usr/bin/hw_management_thermal_control.py b/usr/usr/bin/hw_management_thermal_control.py index 668929d1e..77c5b0784 100755 --- a/usr/usr/bin/hw_management_thermal_control.py +++ b/usr/usr/bin/hw_management_thermal_control.py @@ -482,6 +482,7 @@ def __init__(self, use_syslog=False, log_file=None, verbosity=20): self.logger.setLevel(logging.DEBUG) self.logger.propagate = False self.logger_fh = None + self.logger_emit = True self.set_param(use_syslog, log_file, verbosity) @@ -535,6 +536,13 @@ def stop(self): for handler in handler_list: handler.close() self.logger.removeHandler(handler) + self.logger_emit = False + + def close_tc_log_handler(self): + if self.logger_fh: + self.logger_fh.flush() + self.logger_fh.close() + self.logger.removeHandler(self.logger_fh) def set_loglevel(self, verbosity): """ @@ -551,6 +559,10 @@ def debug(self, msg="", syslog=0): Log "debug" message. @param msg: message to save to log """ + if not self.logger_emit: + return + self.logger_emit = False + msg_prefix = "" if syslog: msg_prefix = "@syslog " @@ -559,6 +571,7 @@ def debug(self, msg="", syslog=0): self.logger.debug(msg_prefix + msg) except: pass + self.logger_emit = True def info(self, msg="", syslog=0): """ @@ -566,6 +579,10 @@ def info(self, msg="", syslog=0): Log "info" message. @param msg: message to save to log """ + if not self.logger_emit: + return + self.logger_emit = False + msg_prefix = "" if syslog: msg_prefix = "@syslog " @@ -574,6 +591,7 @@ def info(self, msg="", syslog=0): self.logger.info(msg_prefix + msg) except: pass + self.logger_emit = True def notice(self, msg="", syslog=0): """ @@ -581,6 +599,10 @@ def notice(self, msg="", syslog=0): Log "notice" message. @param msg: message to save to log """ + if not self.logger_emit: + return + self.logger_emit = False + msg_prefix = "" if syslog: msg_prefix = "@syslog " @@ -589,6 +611,7 @@ def notice(self, msg="", syslog=0): self.logger.log(logging.INFO + 5, msg_prefix + msg) except: pass + self.logger_emit = True def warn(self, msg="", syslog=0): """ @@ -596,6 +619,10 @@ def warn(self, msg="", syslog=0): Log "warn" message. @param msg: message to save to log """ + if not self.logger_emit: + return + self.logger_emit = False + msg_prefix = "" if syslog: msg_prefix = "@syslog " @@ -604,6 +631,7 @@ def warn(self, msg="", syslog=0): self.logger.warning(msg_prefix + msg) except: pass + self.logger_emit = True def error(self, msg="", syslog=0): """ @@ -611,6 +639,10 @@ def error(self, msg="", syslog=0): Log "error" message. @param msg: message to save to log """ + if not self.logger_emit: + return + self.logger_emit = False + msg_prefix = "" if syslog: msg_prefix = "@syslog " @@ -619,6 +651,7 @@ def error(self, msg="", syslog=0): self.logger.error(msg_prefix + msg) except: pass + self.logger_emit = True class RepeatedTimer(object): @@ -2591,12 +2624,13 @@ def sig_handler(self, sig, *_): """ if sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP]: self.exit_flag = True + self.log.close_tc_log_handler() if self.sys_config.get("platform_support", 1): self.stop(reason="SIG {}".format(sig)) self.log.notice("Thermal control stopped", 1) + self.log.logger_emit = False self.log.stop() - time.sleep(200 / 1000) os._exit(0) # ---------------------------------------------------------------------- @@ -2843,6 +2877,7 @@ def stop(self, reason=""): self.log.notice("Thermal control state changed {} -> {} reason:{}".format(self.state, CONST.STOPPED, reason), 1) self.state = CONST.STOPPED self._set_pwm(CONST.PWM_MAX, reason="TC stop") + self.log.notice("Set FAN PWM {}".format(self.pwm_target), 1) # ---------------------------------------------------------------------- def run(self):