~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/damon/damos_quota.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/usr/bin/env python3
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 import subprocess
  5 import time
  6 
  7 import _damon_sysfs
  8 
  9 def main():
 10     # access two 10 MiB memory regions, 2 second per each
 11     sz_region = 10 * 1024 * 1024
 12     proc = subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '2000'])
 13 
 14     # Set quota up to 1 MiB per 100 ms
 15     sz_quota = 1024 * 1024 # 1 MiB
 16     quota_reset_interval = 100 # 100 ms
 17     kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
 18             contexts=[_damon_sysfs.DamonCtx(
 19                 ops='vaddr',
 20                 targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
 21                 schemes=[_damon_sysfs.Damos(
 22                     access_pattern=_damon_sysfs.DamosAccessPattern(
 23                         # >= 25% access rate, >= 200ms age
 24                         nr_accesses=[5, 20], age=[2, 2**64 - 1]),
 25                     quota=_damon_sysfs.DamosQuota(
 26                         sz=sz_quota, reset_interval_ms=quota_reset_interval)
 27                     )] # schemes
 28                 )] # contexts
 29             )]) # kdamonds
 30 
 31     err = kdamonds.start()
 32     if err != None:
 33         print('kdamond start failed: %s' % err)
 34         exit(1)
 35 
 36     wss_collected = []
 37     nr_quota_exceeds = 0
 38     while proc.poll() == None:
 39         time.sleep(0.1)
 40         err = kdamonds.kdamonds[0].update_schemes_tried_bytes()
 41         if err != None:
 42             print('tried bytes update failed: %s' % err)
 43             exit(1)
 44         err = kdamonds.kdamonds[0].update_schemes_stats()
 45         if err != None:
 46             print('stats update failed: %s' % err)
 47             exit(1)
 48 
 49         scheme = kdamonds.kdamonds[0].contexts[0].schemes[0]
 50         wss_collected.append(scheme.tried_bytes)
 51         nr_quota_exceeds = scheme.stats.qt_exceeds
 52 
 53     wss_collected.sort()
 54     for wss in wss_collected:
 55         if wss > sz_quota:
 56             print('quota is not kept: %s > %s' % (wss, sz_quota))
 57             print('collected samples are as below')
 58             print('\n'.join(['%d' % wss for wss in wss_collected]))
 59             exit(1)
 60 
 61     if nr_quota_exceeds < len(wss_collected):
 62         print('quota is not always exceeded: %d > %d' %
 63               (len(wss_collected), nr_quota_exceeds))
 64         exit(1)
 65 
 66 if __name__ == '__main__':
 67     main()

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php