[Nokia-7215][armhf] Enable Watchdog service (#16612)

Enable CPUWDT service to enable watchdog
This commit is contained in:
Pavan-Nokia 2023-11-30 19:34:53 -05:00 committed by Ying Xie
parent 7d308e340a
commit 451398f801
5 changed files with 115 additions and 30 deletions

View File

@ -0,0 +1,46 @@
#!/usr/bin/python
from sonic_platform.chassis import Chassis
from sonic_py_common import logger
import time
import os
import signal
import sys
TIMEOUT=170
KEEPALIVE=55
sonic_logger = logger.Logger('Watchdog')
sonic_logger.set_min_log_priority_info()
time.sleep(60)
chassis = Chassis()
watchdog = chassis.get_watchdog()
def stopWdtService(signal, frame):
watchdog._disablewatchdog()
sonic_logger.log_notice("CPUWDT Disabled: watchdog armed=%s" % watchdog.is_armed() )
sys.exit()
def main():
signal.signal(signal.SIGHUP, signal.SIG_IGN)
signal.signal(signal.SIGINT, stopWdtService)
signal.signal(signal.SIGTERM, stopWdtService)
watchdog.arm(TIMEOUT)
sonic_logger.log_notice("CPUWDT Enabled: watchdog armed=%s" % watchdog.is_armed() )
while True:
time.sleep(KEEPALIVE)
watchdog._keepalive()
sonic_logger.log_info("CPUWDT keepalive")
done
stopWdtService
return
if __name__ == '__main__':
main()

View File

@ -0,0 +1,8 @@
[Unit]
Description=CPU WDT
After=nokia-7215init.service
[Service]
ExecStart=/usr/local/bin/cpu_wdt.py
[Install]
WantedBy=multi-user.target

View File

@ -8,7 +8,7 @@ provides access to hardware watchdog
import os
import fcntl
import array
import time
from sonic_platform_base.watchdog_base import WatchdogBase
""" ioctl constants """
@ -35,7 +35,7 @@ WDIOS_DISABLECARD = 0x0001
WDIOS_ENABLECARD = 0x0002
""" watchdog sysfs """
WD_SYSFS_PATH = "/sys/class/watchdog/"
WD_SYSFS_PATH = "/sys/class/watchdog/watchdog0/"
WD_COMMON_ERROR = -1
@ -52,16 +52,32 @@ class WatchdogImplBase(WatchdogBase):
@param wd_device_path Path to watchdog device
"""
super(WatchdogImplBase, self).__init__()
self.watchdog=""
self.watchdog_path = wd_device_path
self.watchdog = os.open(self.watchdog_path, os.O_WRONLY)
# Opening a watchdog descriptor starts
# watchdog timer; by default it should be stopped
self._disablewatchdog()
self.armed = False
self.wd_state_reg = WD_SYSFS_PATH+"state"
self.wd_timeout_reg = WD_SYSFS_PATH+"timeout"
self.wd_timeleft_reg = WD_SYSFS_PATH+"timeleft"
self.timeout = self._gettimeout()
def _read_sysfs_file(self, sysfs_file):
# On successful read, returns the value read from given
# reg_name and on failure returns 'ERR'
rv = 'ERR'
if (not os.path.isfile(sysfs_file)):
return rv
try:
with open(sysfs_file, 'r') as fd:
rv = fd.read()
except Exception as e:
rv = 'ERR'
rv = rv.rstrip('\r\n')
rv = rv.lstrip(" ")
return rv
def _disablewatchdog(self):
"""
Turn off the watchdog timer
@ -102,11 +118,10 @@ class WatchdogImplBase(WatchdogBase):
Get watchdog timeout
@return watchdog timeout
"""
timeout=0
timeout=self._read_sysfs_file(self.wd_timeout_reg)
req = array.array('I', [0])
fcntl.ioctl(self.watchdog, WDIOC_GETTIMEOUT, req, True)
return int(req[0])
return timeout
def _gettimeleft(self):
"""
@ -127,15 +142,20 @@ class WatchdogImplBase(WatchdogBase):
ret = WD_COMMON_ERROR
if seconds < 0:
return ret
# Stop the watchdog service to gain access of watchdog file pointer
if self.is_armed():
os.popen("systemctl stop cpu_wdt.service")
time.sleep(2)
if not self.watchdog:
self.watchdog = os.open(self.watchdog_path, os.O_WRONLY)
try:
if self.timeout != seconds:
self.timeout = self._settimeout(seconds)
if self.armed:
if self.is_armed():
self._keepalive()
else:
self._enablewatchdog()
self.armed = True
ret = self.timeout
except IOError:
pass
@ -150,13 +170,17 @@ class WatchdogImplBase(WatchdogBase):
A boolean, True if watchdog is disarmed successfully, False
if not
"""
try:
self._disablewatchdog()
self.armed = False
self.timeout = 0
except IOError:
return False
if self.is_armed():
os.popen("systemctl stop cpu_wdt.service")
time.sleep(2)
if not self.watchdog:
self.watchdog = os.open(self.watchdog_path, os.O_WRONLY)
try:
self._disablewatchdog()
self.timeout = 0
except IOError:
return False
return True
@ -164,8 +188,13 @@ class WatchdogImplBase(WatchdogBase):
"""
Implements is_armed WatchdogBase API
"""
status = False
return self.armed
state = self._read_sysfs_file(self.wd_state_reg)
if (state != 'inactive'):
status = True
return status
def get_remaining_time(self):
"""
@ -174,10 +203,7 @@ class WatchdogImplBase(WatchdogBase):
timeleft = WD_COMMON_ERROR
if self.armed:
try:
timeleft = self._gettimeleft()
except IOError:
pass
if self.is_armed():
timeleft=self._read_sysfs_file(self.wd_timeleft_reg)
return timeleft
return int(timeleft)

View File

@ -1,6 +1,8 @@
nokia-7215_plt_setup.sh usr/sbin
7215/scripts/nokia-7215init.sh usr/local/bin
7215/scripts/cpu_wdt.py usr/local/bin
7215/service/nokia-7215init.service etc/systemd/system
7215/service/cpu_wdt.service etc/systemd/system
7215/service/fstrim.timer/timer-override.conf /lib/systemd/system/fstrim.timer.d
7215/sonic_platform-1.0-py3-none-any.whl usr/share/sonic/device/armhf-nokia_ixs7215_52x-r0
inband_mgmt.sh etc/

View File

@ -7,5 +7,8 @@ sh /usr/sbin/nokia-7215_plt_setup.sh
systemctl enable nokia-7215init.service
systemctl start nokia-7215init.service
systemctl enable cpu_wdt.service
systemctl start cpu_wdt.service
exit 0