Skip to content

Commit a1d52cd

Browse files
sjp38akpm00
authored andcommitted
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>
1 parent eb413da commit a1d52cd

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

tools/testing/selftests/damon/drgn_dump_damon_status.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,37 @@ def damos_migrate_dests_to_dict(dests):
135135
'nr_dests': nr_dests,
136136
}
137137

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+
138167
def scheme_to_dict(scheme):
139-
return to_dict(scheme, [
168+
dict_ = to_dict(scheme, [
140169
['pattern', damos_access_pattern_to_dict],
141170
['action', int],
142171
['apply_interval_us', int],
@@ -145,6 +174,18 @@ def scheme_to_dict(scheme):
145174
['target_nid', int],
146175
['migrate_dests', damos_migrate_dests_to_dict],
147176
])
177+
filters = []
178+
for f in list_for_each_entry(
179+
'struct damos_filter', scheme.filters.address_of_(), 'list'):
180+
filters.append(damos_filter_to_dict(f))
181+
dict_['filters'] = filters
182+
ops_filters = []
183+
for f in list_for_each_entry(
184+
'struct damos_filter', scheme.ops_filters.address_of_(), 'list'):
185+
ops_filters.append(damos_filter_to_dict(f))
186+
dict_['ops_filters'] = ops_filters
187+
188+
return dict_
148189

149190
def schemes_to_list(schemes):
150191
return [scheme_to_dict(s)

0 commit comments

Comments
 (0)