From cfb61009316ef2a4f68a7f78b2bcc77edc5c44b2 Mon Sep 17 00:00:00 2001
From: Gopi Krishna Nedanuri <gnedanur@codeaurora.org>
Date: Wed, 23 Nov 2016 16:17:08 +0530
Subject: [PATCH] lrdp_v2: Print NS Watchdog related info

   Add parser to print NS Watchdog related info

Change-Id: Ic721758993f046b3c6d0ebb0c18309ebbe9ca9b1
---
 linux-ramdump-parser-v2/watchdog_v2.py | 48 +++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 linux-ramdump-parser-v2/watchdog_v2.py

diff --git a/linux-ramdump-parser-v2/watchdog_v2.py b/linux-ramdump-parser-v2/watchdog_v2.py
old mode 100644
new mode 100755
index 8801d35..a045847
--- a/linux-ramdump-parser-v2/watchdog_v2.py
+++ b/linux-ramdump-parser-v2/watchdog_v2.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
+# Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 and
@@ -13,6 +13,7 @@ import struct
 import re
 from print_out import print_out_str
 from bitops import is_set
+from parser_util import register_parser, RamParser
 
 # name from tz dump, corresponding T32 register, whether or not to
 # print_out_str (the function name)
@@ -820,3 +821,48 @@ class TZRegDump_v2():
         self.sec_regs = TZCpuCtx_v2(self.version, sc_secure,
                                     self.neon_regs, ram_dump)
         return True
+
+
+@register_parser('--watchdog', 'Extracts NS Watchdog related info')
+class Watchdog(RamParser):
+    def parse(self):
+        get_wdog_timing(self.ramdump)
+
+
+def get_wdog_timing(ramdump):
+    jiffies = ramdump.read_word('jiffies')
+    last_jiffies_update = ramdump.read_word('last_jiffies_update')
+    tick_do_timer_cpu = ramdump.read_word('tick_do_timer_cpu')
+    wdog_data_addr = ramdump.read_word('wdog_data')
+    pet_timer_off = ramdump.field_offset(
+        'struct msm_watchdog_data', 'pet_timer')
+    timer_expires_off = ramdump.field_offset('struct timer_list', 'expires')
+    pet_timer_expires = ramdump.read_word(
+        wdog_data_addr + pet_timer_off + timer_expires_off)
+    last_pet_off = ramdump.field_offset('struct msm_watchdog_data', 'last_pet')
+    wdog_last_pet = ramdump.read_word(wdog_data_addr + last_pet_off)
+    timer_expired_off = ramdump.field_offset(
+        'struct msm_watchdog_data', 'timer_expired')
+    pet_timer_expired = ramdump.read_word(wdog_data_addr + timer_expired_off)
+    pet_time_off = ramdump.field_offset('struct msm_watchdog_data', 'pet_time')
+    bark_time_off = ramdump.field_offset(
+        'struct msm_watchdog_data', 'bark_time')
+    pet_time = ramdump.read_int(wdog_data_addr + pet_time_off)
+    bark_time = ramdump.read_int(wdog_data_addr + bark_time_off)
+    print_out_str('Non-secure Watchdog data')
+    print_out_str('Pet time: {0}s'.format(pet_time/1000.0))
+    print_out_str('Bark time: {0}s'.format(bark_time/1000.0))
+    print_out_str('Watchdog last pet: {0}'.format(wdog_last_pet/1000000000.0))
+    if pet_timer_expired == 1:
+        print_out_str('Watchdog pet timer expired')
+    else:
+        print_out_str('Watchdog pet timer not expired')
+        if jiffies > pet_timer_expires:
+            print_out_str('Current jiffies crossed pet_timer expires jiffies')
+    print_out_str('pet_timer_expires: {0}'.format(pet_timer_expires))
+    print_out_str('Current jiffies  : {0}'.format(jiffies))
+    print_out_str(
+        'Timestamp of last timer interrupt(last_jiffies_update): {0}'.format(
+            last_jiffies_update/1000000000.0))
+    print_out_str('Core which updates jiffies(tick_do_timer_cpu): {0}'.format(
+        tick_do_timer_cpu))
-- 
GitLab