2 # SPDX-License-Identifier: GPL-2.0
9 def test_nr_regions(real_nr_regions
, min_nr_regions
, max_nr_regions
):
11 Create process of the given 'real_nr_regions' regions, monitor it using
12 DAMON with given '{min,max}_nr_regions' monitoring parameter.
14 Exit with non-zero return code if the given {min,max}_nr_regions is not
17 sz_region
= 10 * 1024 * 1024
18 proc
= subprocess
.Popen(['./access_memory_even', '%d' % real_nr_regions
,
21 # stat every monitored regions
22 kdamonds
= _damon_sysfs
.Kdamonds([_damon_sysfs
.Kdamond(
23 contexts
=[_damon_sysfs
.DamonCtx(
24 monitoring_attrs
=_damon_sysfs
.DamonAttrs(
25 min_nr_regions
=min_nr_regions
,
26 max_nr_regions
=max_nr_regions
),
28 targets
=[_damon_sysfs
.DamonTarget(pid
=proc
.pid
)],
29 schemes
=[_damon_sysfs
.Damos(action
='stat',
34 err
= kdamonds
.start()
37 print('kdamond start failed: %s' % err
)
40 collected_nr_regions
= []
41 while proc
.poll() is None:
43 err
= kdamonds
.kdamonds
[0].update_schemes_tried_regions()
46 print('tried regions update failed: %s' % err
)
49 scheme
= kdamonds
.kdamonds
[0].contexts
[0].schemes
[0]
50 if scheme
.tried_regions
is None:
52 print('tried regions is not collected')
55 nr_tried_regions
= len(scheme
.tried_regions
)
56 if nr_tried_regions
<= 0:
58 print('tried regions is not created')
60 collected_nr_regions
.append(nr_tried_regions
)
61 if len(collected_nr_regions
) > 10:
66 test_name
= 'nr_regions test with %d/%d/%d real/min/max nr_regions' % (
67 real_nr_regions
, min_nr_regions
, max_nr_regions
)
68 if (collected_nr_regions
[0] < min_nr_regions
or
69 collected_nr_regions
[-1] > max_nr_regions
):
70 print('fail %s' % test_name
)
71 print('number of regions that collected are:')
72 for nr
in collected_nr_regions
:
75 print('pass %s ' % test_name
)
78 # test min_nr_regions larger than real nr regions
79 test_nr_regions(10, 20, 100)
81 # test max_nr_regions smaller than real nr regions
82 test_nr_regions(15, 3, 10)
84 # test online-tuned max_nr_regions that smaller than real nr regions
85 sz_region
= 10 * 1024 * 1024
86 proc
= subprocess
.Popen(['./access_memory_even', '14', '%d' % sz_region
])
88 # stat every monitored regions
89 kdamonds
= _damon_sysfs
.Kdamonds([_damon_sysfs
.Kdamond(
90 contexts
=[_damon_sysfs
.DamonCtx(
91 monitoring_attrs
=_damon_sysfs
.DamonAttrs(
92 min_nr_regions
=10, max_nr_regions
=1000),
94 targets
=[_damon_sysfs
.DamonTarget(pid
=proc
.pid
)],
95 schemes
=[_damon_sysfs
.Damos(action
='stat',
100 err
= kdamonds
.start()
103 print('kdamond start failed: %s' % err
)
106 # wait until the real regions are found
109 attrs
= kdamonds
.kdamonds
[0].contexts
[0].monitoring_attrs
110 attrs
.min_nr_regions
= 3
111 attrs
.max_nr_regions
= 7
112 err
= kdamonds
.kdamonds
[0].commit()
115 print('commit failed: %s' % err
)
117 # wait for next merge operation is executed
120 err
= kdamonds
.kdamonds
[0].update_schemes_tried_regions()
123 print('tried regions update failed: %s' % err
)
126 scheme
= kdamonds
.kdamonds
[0].contexts
[0].schemes
[0]
127 if scheme
.tried_regions
is None:
129 print('tried regions is not collected')
132 nr_tried_regions
= len(scheme
.tried_regions
)
133 if nr_tried_regions
<= 0:
135 print('tried regions is not created')
139 if nr_tried_regions
> 7:
140 print('fail online-tuned max_nr_regions: %d > 7' % nr_tried_regions
)
142 print('pass online-tuned max_nr_regions')
144 if __name__
== '__main__':