Path: blob/master/tools/testing/selftests/damon/damos_apply_interval.py
29268 views
#!/usr/bin/env python31# SPDX-License-Identifier: GPL-2.023import subprocess4import time56import _damon_sysfs78def main():9# access two 10 MiB memory regions, 2 second per each10sz_region = 10 * 1024 * 102411proc = subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '2000'])1213# Set quota up to 1 MiB per 100 ms14kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(15contexts=[_damon_sysfs.DamonCtx(16ops='vaddr',17targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],18schemes=[19_damon_sysfs.Damos(20access_pattern=_damon_sysfs.DamosAccessPattern(21# >= 25% access rate, >= 200ms age22nr_accesses=[5, 20], age=[2, 2**64 - 1]),23# aggregation interval (100 ms) is used24apply_interval_us=0),25# use 10ms apply interval26_damon_sysfs.Damos(27access_pattern=_damon_sysfs.DamosAccessPattern(28# >= 25% access rate, >= 200ms age29nr_accesses=[5, 20], age=[2, 2**64 - 1]),30# explicitly set 10 ms apply interval31apply_interval_us=10 * 1000)32] # schemes33)] # contexts34)]) # kdamonds3536err = kdamonds.start()37if err != None:38print('kdamond start failed: %s' % err)39exit(1)4041wss_collected = []42nr_quota_exceeds = 043while proc.poll() == None:44time.sleep(0.1)45err = kdamonds.kdamonds[0].update_schemes_stats()46if err != None:47print('stats update failed: %s' % err)48exit(1)49schemes = kdamonds.kdamonds[0].contexts[0].schemes50nr_tried_stats = [s.stats.nr_tried for s in schemes]51if nr_tried_stats[0] == 0 or nr_tried_stats[1] == 0:52print('scheme(s) are not tried')53exit(1)5455# Because the second scheme was having the apply interval that is ten times56# lower than that of the first scheme, the second scheme should be tried57# about ten times more frequently than the first scheme. For possible58# timing errors, check if it was at least nine times more freuqnetly tried.59ratio = nr_tried_stats[1] / nr_tried_stats[0]60if ratio < 9:61print('%d / %d = %f (< 9)' %62(nr_tried_stats[1], nr_tried_stats[0], ratio))63exit(1)6465if __name__ == '__main__':66main()676869