Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/damon/drgn_dump_damon_status: dump DAMOS filters

drgn_dump_damon_status.py is a script for dumping DAMON internal status in
json format. It is being used for seeing if DAMON parameters that are set
using _damon_sysfs.py are actually passed to DAMON in the kernel space.
It is, however, not dumping full DAMON internal status, and it makes
increasing test coverage difficult. Add damos filters dumping for more
tests.

Link: https://lkml.kernel.org/r/20250720171652.92309-12-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
a1d52cd0 eb413daa

+42 -1
+42 -1
tools/testing/selftests/damon/drgn_dump_damon_status.py
··· 135 135 'nr_dests': nr_dests, 136 136 } 137 137 138 + def damos_filter_to_dict(damos_filter): 139 + filter_type_keyword = { 140 + 0: 'anon', 141 + 1: 'active', 142 + 2: 'memcg', 143 + 3: 'young', 144 + 4: 'hugepage_size', 145 + 5: 'unmapped', 146 + 6: 'addr', 147 + 7: 'target' 148 + } 149 + dict_ = { 150 + 'type': filter_type_keyword[int(damos_filter.type)], 151 + 'matching': bool(damos_filter.matching), 152 + 'allow': bool(damos_filter.allow), 153 + } 154 + type_ = dict_['type'] 155 + if type_ == 'memcg': 156 + dict_['memcg_id'] = int(damos_filter.memcg_id) 157 + elif type_ == 'addr': 158 + dict_['addr_range'] = [int(damos_filter.addr_range.start), 159 + int(damos_filter.addr_range.end)] 160 + elif type_ == 'target': 161 + dict_['target_idx'] = int(damos_filter.target_idx) 162 + elif type_ == 'hugeapge_size': 163 + dict_['sz_range'] = [int(damos_filter.sz_range.min), 164 + int(damos_filter.sz_range.max)] 165 + return dict_ 166 + 138 167 def scheme_to_dict(scheme): 139 - return to_dict(scheme, [ 168 + dict_ = to_dict(scheme, [ 140 169 ['pattern', damos_access_pattern_to_dict], 141 170 ['action', int], 142 171 ['apply_interval_us', int], ··· 174 145 ['target_nid', int], 175 146 ['migrate_dests', damos_migrate_dests_to_dict], 176 147 ]) 148 + filters = [] 149 + for f in list_for_each_entry( 150 + 'struct damos_filter', scheme.filters.address_of_(), 'list'): 151 + filters.append(damos_filter_to_dict(f)) 152 + dict_['filters'] = filters 153 + ops_filters = [] 154 + for f in list_for_each_entry( 155 + 'struct damos_filter', scheme.ops_filters.address_of_(), 'list'): 156 + ops_filters.append(damos_filter_to_dict(f)) 157 + dict_['ops_filters'] = ops_filters 158 + 159 + return dict_ 177 160 178 161 def schemes_to_list(schemes): 179 162 return [scheme_to_dict(s)