Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 #
0003 # Copyright (c) NXP 2019
0004 
0005 import gdb
0006 import sys
0007 
0008 from linux import utils, lists, constants
0009 
0010 clk_core_type = utils.CachedType("struct clk_core")
0011 
0012 
0013 def clk_core_for_each_child(hlist_head):
0014     return lists.hlist_for_each_entry(hlist_head,
0015             clk_core_type.get_type().pointer(), "child_node")
0016 
0017 
0018 class LxClkSummary(gdb.Command):
0019     """Print clk tree summary
0020 
0021 Output is a subset of /sys/kernel/debug/clk/clk_summary
0022 
0023 No calls are made during printing, instead a (c) if printed after values which
0024 are cached and potentially out of date"""
0025 
0026     def __init__(self):
0027         super(LxClkSummary, self).__init__("lx-clk-summary", gdb.COMMAND_DATA)
0028 
0029     def show_subtree(self, clk, level):
0030         gdb.write("%*s%-*s %7d %8d %8d %11lu%s\n" % (
0031                 level * 3 + 1, "",
0032                 30 - level * 3,
0033                 clk['name'].string(),
0034                 clk['enable_count'],
0035                 clk['prepare_count'],
0036                 clk['protect_count'],
0037                 clk['rate'],
0038                 '(c)' if clk['flags'] & constants.LX_CLK_GET_RATE_NOCACHE else '   '))
0039 
0040         for child in clk_core_for_each_child(clk['children']):
0041             self.show_subtree(child, level + 1)
0042 
0043     def invoke(self, arg, from_tty):
0044         gdb.write("                                 enable  prepare  protect               \n")
0045         gdb.write("   clock                          count    count    count        rate   \n")
0046         gdb.write("------------------------------------------------------------------------\n")
0047         for clk in clk_core_for_each_child(gdb.parse_and_eval("clk_root_list")):
0048             self.show_subtree(clk, 0)
0049         for clk in clk_core_for_each_child(gdb.parse_and_eval("clk_orphan_list")):
0050             self.show_subtree(clk, 0)
0051 
0052 
0053 LxClkSummary()
0054 
0055 
0056 class LxClkCoreLookup(gdb.Function):
0057     """Find struct clk_core by name"""
0058 
0059     def __init__(self):
0060         super(LxClkCoreLookup, self).__init__("lx_clk_core_lookup")
0061 
0062     def lookup_hlist(self, hlist_head, name):
0063         for child in clk_core_for_each_child(hlist_head):
0064             if child['name'].string() == name:
0065                 return child
0066             result = self.lookup_hlist(child['children'], name)
0067             if result:
0068                 return result
0069 
0070     def invoke(self, name):
0071         name = name.string()
0072         return (self.lookup_hlist(gdb.parse_and_eval("clk_root_list"), name) or
0073                 self.lookup_hlist(gdb.parse_and_eval("clk_orphan_list"), name))
0074 
0075 
0076 LxClkCoreLookup()