Skip to content

Commit 64e5b82

Browse files
authored
[Nokia-7215][armhf] Enable Watchdog service (#16612) (#17704)
1 parent 04d83c0 commit 64e5b82

File tree

5 files changed

+115
-30
lines changed

5 files changed

+115
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/python
2+
3+
from sonic_platform.chassis import Chassis
4+
from sonic_py_common import logger
5+
import time
6+
import os
7+
import signal
8+
import sys
9+
10+
11+
TIMEOUT=170
12+
KEEPALIVE=55
13+
sonic_logger = logger.Logger('Watchdog')
14+
sonic_logger.set_min_log_priority_info()
15+
time.sleep(60)
16+
chassis = Chassis()
17+
watchdog = chassis.get_watchdog()
18+
19+
def stopWdtService(signal, frame):
20+
watchdog._disablewatchdog()
21+
sonic_logger.log_notice("CPUWDT Disabled: watchdog armed=%s" % watchdog.is_armed() )
22+
sys.exit()
23+
24+
def main():
25+
26+
signal.signal(signal.SIGHUP, signal.SIG_IGN)
27+
signal.signal(signal.SIGINT, stopWdtService)
28+
signal.signal(signal.SIGTERM, stopWdtService)
29+
30+
watchdog.arm(TIMEOUT)
31+
sonic_logger.log_notice("CPUWDT Enabled: watchdog armed=%s" % watchdog.is_armed() )
32+
33+
34+
while True:
35+
time.sleep(KEEPALIVE)
36+
watchdog._keepalive()
37+
sonic_logger.log_info("CPUWDT keepalive")
38+
done
39+
40+
stopWdtService
41+
42+
return
43+
44+
45+
if __name__ == '__main__':
46+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=CPU WDT
3+
After=nokia-7215init.service
4+
[Service]
5+
ExecStart=/usr/local/bin/cpu_wdt.py
6+
7+
[Install]
8+
WantedBy=multi-user.target

platform/marvell-armhf/sonic-platform-nokia/7215/sonic_platform/watchdog.py

+56-30
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import fcntl
1010
import array
11-
11+
import time
1212
from sonic_platform_base.watchdog_base import WatchdogBase
1313

1414
""" ioctl constants """
@@ -35,7 +35,7 @@
3535
WDIOS_ENABLECARD = 0x0002
3636

3737
""" watchdog sysfs """
38-
WD_SYSFS_PATH = "/sys/class/watchdog/"
38+
WD_SYSFS_PATH = "/sys/class/watchdog/watchdog0/"
3939

4040
WD_COMMON_ERROR = -1
4141

@@ -52,16 +52,32 @@ def __init__(self, wd_device_path):
5252
@param wd_device_path Path to watchdog device
5353
"""
5454
super(WatchdogImplBase, self).__init__()
55-
55+
56+
self.watchdog=""
5657
self.watchdog_path = wd_device_path
57-
self.watchdog = os.open(self.watchdog_path, os.O_WRONLY)
58-
59-
# Opening a watchdog descriptor starts
60-
# watchdog timer; by default it should be stopped
61-
self._disablewatchdog()
62-
self.armed = False
58+
self.wd_state_reg = WD_SYSFS_PATH+"state"
59+
self.wd_timeout_reg = WD_SYSFS_PATH+"timeout"
60+
self.wd_timeleft_reg = WD_SYSFS_PATH+"timeleft"
61+
6362
self.timeout = self._gettimeout()
6463

64+
def _read_sysfs_file(self, sysfs_file):
65+
# On successful read, returns the value read from given
66+
# reg_name and on failure returns 'ERR'
67+
rv = 'ERR'
68+
69+
if (not os.path.isfile(sysfs_file)):
70+
return rv
71+
try:
72+
with open(sysfs_file, 'r') as fd:
73+
rv = fd.read()
74+
except Exception as e:
75+
rv = 'ERR'
76+
77+
rv = rv.rstrip('\r\n')
78+
rv = rv.lstrip(" ")
79+
return rv
80+
6581
def _disablewatchdog(self):
6682
"""
6783
Turn off the watchdog timer
@@ -102,11 +118,10 @@ def _gettimeout(self):
102118
Get watchdog timeout
103119
@return watchdog timeout
104120
"""
121+
timeout=0
122+
timeout=self._read_sysfs_file(self.wd_timeout_reg)
105123

106-
req = array.array('I', [0])
107-
fcntl.ioctl(self.watchdog, WDIOC_GETTIMEOUT, req, True)
108-
109-
return int(req[0])
124+
return timeout
110125

111126
def _gettimeleft(self):
112127
"""
@@ -127,15 +142,20 @@ def arm(self, seconds):
127142
ret = WD_COMMON_ERROR
128143
if seconds < 0:
129144
return ret
130-
145+
146+
# Stop the watchdog service to gain access of watchdog file pointer
147+
if self.is_armed():
148+
os.popen("systemctl stop cpu_wdt.service")
149+
time.sleep(2)
150+
if not self.watchdog:
151+
self.watchdog = os.open(self.watchdog_path, os.O_WRONLY)
131152
try:
132153
if self.timeout != seconds:
133154
self.timeout = self._settimeout(seconds)
134-
if self.armed:
155+
if self.is_armed():
135156
self._keepalive()
136157
else:
137158
self._enablewatchdog()
138-
self.armed = True
139159
ret = self.timeout
140160
except IOError:
141161
pass
@@ -150,22 +170,31 @@ def disarm(self):
150170
A boolean, True if watchdog is disarmed successfully, False
151171
if not
152172
"""
153-
154-
try:
155-
self._disablewatchdog()
156-
self.armed = False
157-
self.timeout = 0
158-
except IOError:
159-
return False
173+
174+
if self.is_armed():
175+
os.popen("systemctl stop cpu_wdt.service")
176+
time.sleep(2)
177+
if not self.watchdog:
178+
self.watchdog = os.open(self.watchdog_path, os.O_WRONLY)
179+
try:
180+
self._disablewatchdog()
181+
self.timeout = 0
182+
except IOError:
183+
return False
160184

161185
return True
162186

163187
def is_armed(self):
164188
"""
165189
Implements is_armed WatchdogBase API
166190
"""
191+
status = False
192+
193+
state = self._read_sysfs_file(self.wd_state_reg)
194+
if (state != 'inactive'):
195+
status = True
167196

168-
return self.armed
197+
return status
169198

170199
def get_remaining_time(self):
171200
"""
@@ -174,10 +203,7 @@ def get_remaining_time(self):
174203

175204
timeleft = WD_COMMON_ERROR
176205

177-
if self.armed:
178-
try:
179-
timeleft = self._gettimeleft()
180-
except IOError:
181-
pass
206+
if self.is_armed():
207+
timeleft=self._read_sysfs_file(self.wd_timeleft_reg)
182208

183-
return timeleft
209+
return int(timeleft)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
nokia-7215_plt_setup.sh usr/sbin
22
7215/scripts/nokia-7215init.sh usr/local/bin
3+
7215/scripts/cpu_wdt.py usr/local/bin
34
7215/service/nokia-7215init.service etc/systemd/system
5+
7215/service/cpu_wdt.service etc/systemd/system
46
7215/service/fstrim.timer/timer-override.conf /lib/systemd/system/fstrim.timer.d
57
7215/sonic_platform-1.0-py3-none-any.whl usr/share/sonic/device/armhf-nokia_ixs7215_52x-r0
68
inband_mgmt.sh etc/

platform/marvell-armhf/sonic-platform-nokia/debian/sonic-platform-nokia-7215.postinst

+3
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ sh /usr/sbin/nokia-7215_plt_setup.sh
77
systemctl enable nokia-7215init.service
88
systemctl start nokia-7215init.service
99

10+
systemctl enable cpu_wdt.service
11+
systemctl start cpu_wdt.service
12+
1013
exit 0
1114

0 commit comments

Comments
 (0)