4 Utility to display Lustre cfs_hash tables
5 Copyright (c) 2019 Cray Inc. All Rights Reserved.
8 from pykdump.API import *
11 import lustrelib as ll
13 description_short = 'Displays summary of cfs_hash tables'
15 CFS_HASH_THETA_BITS = 10
17 def cfs_hash_cur_theta(hs):
18 hs_cnt = readSU('atomic_t', hs.hs_count).counter
19 return ((hs_cnt << CFS_HASH_THETA_BITS) >> hs.hs_cur_bits)
21 def cfs_hash_theta_int(theta):
22 return (theta >> CFS_HASH_THETA_BITS)
24 def cfs_hash_theta_frac(theta):
25 frac = ((theta * 1000) >> CFS_HASH_THETA_BITS) - \
26 (cfs_hash_theta_int(theta) * 1000)
29 def cfs_hash_format_theta(theta):
30 val = str(cfs_hash_theta_int(theta)) + \
32 str(cfs_hash_theta_frac(theta))
36 theta = cfs_hash_cur_theta(hs)
37 print("Theta: %d %s" % (theta, cfs_hash_format_theta(theta)))
39 def print_thetas(name, hashtable):
40 hs = readSU('struct cfs_hash', hashtable)
44 def print_separator(count):
46 for idx in xrange(count):
50 def print_hash_labels():
51 print("%-15s %-17s\t %-5s %-5s %-5s %-5s %-5s %-5s %-5s " \
52 "%-5s %-5s %-5s %-5s %-11s %-11s %-11s %-5s" % \
53 ("name", "cfs_hash", "cnt", "rhcnt", "xtr", "cur", "min", "max", "rhash", \
54 "bkt", "nbkt", "nhlst", "flags", "theta", "minT", "maxT", "bktsz"))
56 def print_hash_summary(name, hashtable):
57 hs = readSU('struct cfs_hash', hashtable)
59 hs_cnt = readSU('atomic_t', hs.hs_count).counter
60 hs_ref = readSU('atomic_t', hs.hs_refcount).counter
61 print("%-15s %-17x\t %-5d %-5d %-5d %-5d %-5d %-5d %-5d %-5d %-5d %-5d %-5x %-11s %-11s %-11s %-5d" % \
63 readSU('atomic_t', hs.hs_count).counter, \
71 ll.CFS_HASH_NBKT(hs), \
72 ll.CFS_HASH_BKT_NHLIST(hs), \
74 cfs_hash_format_theta(cfs_hash_cur_theta(hs)), \
75 cfs_hash_format_theta(hs.hs_min_theta), \
76 cfs_hash_format_theta(hs.hs_max_theta), \
77 ll.cfs_hash_bucket_size(hs)))
79 print("%-15s %-17x" % \
82 def obd_print_export_hashes(obd, exp_list, fld):
83 print("\nExport list head %x %s" % (exp_list, fld))
84 for exp in readSUListFromHead(exp_list, fld, 'struct obd_export'):
85 print_hash_summary('exp_lock', exp.exp_lock_hash)
86 print_hash_summary('exp_flock', exp.exp_flock_hash)
88 def obd_print_one_device_hashes(obd):
91 except Exception as e:
94 print("obd_device %-17x %-22s" % (Addr(obd), ll.obd2str(obd)))
97 print_hash_summary("uuid", obd.obd_uuid_hash)
98 print_hash_summary("nid", obd.obd_nid_hash)
99 print_hash_summary("nid_stats", obd.obd_nid_stats_hash)
102 print_hash_summary("lov_pools", obd.u.lov.lov_pools_hash_body)
106 print_hash_summary("cl_quota0", obd.u.cli.cl_quota_hash[0])
107 print_hash_summary("cl_quota1", obd.u.cli.cl_quota_hash[1])
109 # obd_print_export_hashes(obd, obd.obd_exports, 'exp_obd_chain')
110 # obd_print_export_hashes(obd, obd.obd_exports_timed, 'exp_obd_chain_timed')
115 devices = readSymbol('obd_devs')
118 if not obd_print_one_device_hashes(obd) == 0:
122 def ldlm_print_ns_hashes(ns, type):
123 ns_list = readSymbol(ns)
124 print("\n%s namespaces-resources" % type)
126 for ns in readSUListFromHead(ns_list, 'ns_list_chain', 'struct ldlm_namespace'):
127 nm = ll.obd2str(ns.ns_obd)[0:20]
128 print_hash_summary(nm, ns.ns_rs_hash)
130 def ldlm_namespaces_hash():
131 ldlm_print_ns_hashes('ldlm_cli_active_namespace_list', "Client")
132 ldlm_print_ns_hashes('ldlm_cli_inactive_namespace_list', "Inactive")
133 ldlm_print_ns_hashes('ldlm_srv_namespace_list', "Server")
135 def lu_sites_hashes():
136 lu_sites = readSymbol('lu_sites')
138 for site in readSUListFromHead(lu_sites, 'ls_linkage', 'struct lu_site'):
139 print_hash_summary("lu_site_vvp", site.ls_obj_hash)
145 print_hash_summary("conn_hash", readSymbol('conn_hash'))
146 if symbol_exists('jobid_hash'):
147 print_hash_summary("jobid_hash", readSymbol('jobid_hash'))
148 if symbol_exists('cl_env_hash'):
149 print_hash_summary("cl_env_hash", readSymbol('cl_env_hash'))
152 if __name__ == "__main__":
153 description = "Displays summary of hash tables in 'obd_devs'"
154 parser = argparse.ArgumentParser(description=description)
155 args = parser.parse_args()
160 ldlm_namespaces_hash()