mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
selftests/damon/sysfs.py: pause DAMON before dumping status
The sysfs.py test commits DAMON parameters, dump the internal DAMON state, and show if the parameters are committed as expected using the dumped state. While the dumping is ongoing, DAMON is alive. It can make internal changes including addition and removal of regions. It can therefore make a race that can result in false test results. Pause DAMON execution during the state dumping to avoid such races. Link: https://lore.kernel.org/20260427151231.113429-11-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Cc: Brendan Higgins <brendan.higgins@linux.dev> Cc: David Hildenbrand <david@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Liam R. Howlett <liam@infradead.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
e88be73275
commit
cb1a7622c9
|
|
@ -198,18 +198,55 @@ def assert_ctx_committed(ctx, dump):
|
|||
assert_true(dump['pause'] == ctx.pause, 'pause', dump)
|
||||
|
||||
def assert_ctxs_committed(kdamonds):
|
||||
ctxs_paused_for_dump = []
|
||||
kdamonds_paused_for_dump = []
|
||||
# pause for safe state dumping
|
||||
for kd in kdamonds.kdamonds:
|
||||
for ctx in kd.contexts:
|
||||
if ctx.pause is False:
|
||||
ctx.pause = True
|
||||
ctxs_paused_for_dump.append(ctx)
|
||||
if not kd in kdamonds_paused_for_dump:
|
||||
kdamonds_paused_for_dump.append(kd)
|
||||
if kd in kdamonds_paused_for_dump:
|
||||
err = kd.commit()
|
||||
if err is not None:
|
||||
print('pause fail (%s)' % err)
|
||||
kdamonds.stop()
|
||||
exit(1)
|
||||
|
||||
status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid)
|
||||
if err is not None:
|
||||
print(err)
|
||||
kdamonds.stop()
|
||||
exit(1)
|
||||
|
||||
# resume contexts paused for safe state dumping
|
||||
for ctx in ctxs_paused_for_dump:
|
||||
ctx.pause = False
|
||||
for kd in kdamonds_paused_for_dump:
|
||||
err = kd.commit()
|
||||
if err is not None:
|
||||
print('resume fail (%s)' % err)
|
||||
kdamonds.stop()
|
||||
exit(1)
|
||||
|
||||
# restore for comparison
|
||||
for ctx in ctxs_paused_for_dump:
|
||||
ctx.pause = True
|
||||
|
||||
ctxs = kdamonds.kdamonds[0].contexts
|
||||
dump = status['contexts']
|
||||
assert_true(len(ctxs) == len(dump), 'ctxs length', dump)
|
||||
for idx, ctx in enumerate(ctxs):
|
||||
assert_ctx_committed(ctx, dump[idx])
|
||||
|
||||
# restore for the caller
|
||||
for kd in kdamonds.kdamonds:
|
||||
for ctx in kd.contexts:
|
||||
if ctx in ctxs_paused_for_dump:
|
||||
ctx.pause = False
|
||||
|
||||
def main():
|
||||
kdamonds = _damon_sysfs.Kdamonds(
|
||||
[_damon_sysfs.Kdamond(
|
||||
|
|
@ -309,6 +346,7 @@ def main():
|
|||
print('kdamond start failed: %s' % err)
|
||||
exit(1)
|
||||
kdamonds.kdamonds[0].contexts[0].targets[1].obsolete = True
|
||||
kdamonds.kdamonds[0].contexts[0].pause = True
|
||||
kdamonds.kdamonds[0].commit()
|
||||
del kdamonds.kdamonds[0].contexts[0].targets[1]
|
||||
assert_ctxs_committed(kdamonds)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user