Skip to content

Commit 306abb6

Browse files
sjp38akpm00
authored andcommitted
selftests/damon: implement a python module for test-purpose DAMON sysfs controls
Patch series "selftests/damon: add Python-written DAMON functionality tests", v2. DAMON exports most of its functionality via its sysfs interface. Hence most DAMON functionality tests could be implemented using the interface. However, because the interfaces require simple but multiple operations for many controls, writing all such tests from the scratch could be repetitive and time consuming. Implement a minimum DAMON sysfs control module, and a couple of DAMON functionality tests using the control module. The first test is for ensuring minimum accuracy of data access monitoring, and the second test is for finding if a previously found and fixed bug is introduced again. Note that the DAMON sysfs control module is only for avoiding duplicating code in tests. For convenient and general control of DAMON, users should use DAMON user-space tools that developed for the purpose, such as damo[1]. [1] https://github.com/damonitor/damo Patches Sequence ---------------- This patchset is constructed with five patches. The first three patches implement a Python-written test implementation-purpose DAMON sysfs control module. The implementation is incrementally done in the sequence of the basic data structure (first patch) first, kdamonds start command (second patch) next, and finally DAMOS tried bytes update command (third patch). Then two patches for implementing selftests using the module follows. The fourth patch implements a basic functionality test of DAMON for working set estimation accuracy. Finally, the fifth patch implements a corner case test for a previously found bug. This patch (of 5): Implement a python module for DAMON sysfs controls. The module is aimed to be useful for writing DAMON functionality tests in future. Nonetheless, this module is only representing a subset of DAMON sysfs files. Following commits will implement more DAMON sysfs controls. Link: https://lkml.kernel.org/r/20231212194810.54457-1-sj@kernel.org Link: https://lkml.kernel.org/r/20231212194810.54457-2-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 d5f6057 commit 306abb6

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
class DamosAccessPattern:
4+
size = None
5+
nr_accesses = None
6+
age = None
7+
scheme = None
8+
9+
def __init__(self, size=None, nr_accesses=None, age=None):
10+
self.size = size
11+
self.nr_accesses = nr_accesses
12+
self.age = age
13+
14+
if self.size == None:
15+
self.size = [0, 2**64 - 1]
16+
if self.nr_accesses == None:
17+
self.nr_accesses = [0, 2**64 - 1]
18+
if self.age == None:
19+
self.age = [0, 2**64 - 1]
20+
21+
class Damos:
22+
action = None
23+
access_pattern = None
24+
# todo: Support quotas, watermarks, stats, tried_regions
25+
idx = None
26+
context = None
27+
28+
def __init__(self, action='stat', access_pattern=DamosAccessPattern()):
29+
self.action = action
30+
self.access_pattern = access_pattern
31+
self.access_pattern.scheme = self
32+
33+
class DamonTarget:
34+
pid = None
35+
# todo: Support target regions if test is made
36+
idx = None
37+
context = None
38+
39+
def __init__(self, pid):
40+
self.pid = pid
41+
42+
class DamonAttrs:
43+
sample_us = None
44+
aggr_us = None
45+
update_us = None
46+
min_nr_regions = None
47+
max_nr_regions = None
48+
context = None
49+
50+
def __init__(self, sample_us=5000, aggr_us=100000, update_us=1000000,
51+
min_nr_regions=10, max_nr_regions=1000):
52+
self.sample_us = sample_us
53+
self.aggr_us = aggr_us
54+
self.update_us = update_us
55+
self.min_nr_regions = min_nr_regions
56+
self.max_nr_regions = max_nr_regions
57+
58+
class DamonCtx:
59+
ops = None
60+
monitoring_attrs = None
61+
targets = None
62+
schemes = None
63+
kdamond = None
64+
idx = None
65+
66+
def __init__(self, ops='paddr', monitoring_attrs=DamonAttrs(), targets=[],
67+
schemes=[]):
68+
self.ops = ops
69+
self.monitoring_attrs = monitoring_attrs
70+
self.monitoring_attrs.context = self
71+
72+
self.targets = targets
73+
for idx, target in enumerate(self.targets):
74+
target.idx = idx
75+
target.context = self
76+
77+
self.schemes = schemes
78+
for idx, scheme in enumerate(self.schemes):
79+
scheme.idx = idx
80+
scheme.context = self
81+
82+
class Kdamond:
83+
state = None
84+
pid = None
85+
contexts = None
86+
idx = None # index of this kdamond between siblings
87+
kdamonds = None # parent
88+
89+
def __init__(self, contexts=[]):
90+
self.contexts = contexts
91+
for idx, context in enumerate(self.contexts):
92+
context.idx = idx
93+
context.kdamond = self
94+
95+
class Kdamonds:
96+
kdamonds = []
97+
98+
def __init__(self, kdamonds=[]):
99+
self.kdamonds = kdamonds
100+
for idx, kdamond in enumerate(self.kdamonds):
101+
kdamond.idx = idx
102+
kdamond.kdamonds = self

0 commit comments

Comments
 (0)