Skip to content

Commit d14d6b0

Browse files
sjp38akpm00
authored andcommitted
selftests/damon/_damon_sysfs: support quota goals
Patch series "selftests/damon: add DAMOS quota goal test". Extend DAMON selftest-purpose sysfs wrapper to support DAMOS quota goal, and implement a simple selftest for the feature using it. This patch (of 2): The DAMON sysfs test purpose wrapper, _damon_sysfs.py, is not supporting quota goals. Implement the support for testing the feature. The test will be implemented and added by the following commit. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 447bac3 commit d14d6b0

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

tools/testing/selftests/damon/_damon_sysfs.py

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,56 @@ def stage(self):
7070
if err != None:
7171
return err
7272

73+
qgoal_metric_user_input = 'user_input'
74+
qgoal_metric_some_mem_psi_us = 'some_mem_psi_us'
75+
qgoal_metrics = [qgoal_metric_user_input, qgoal_metric_some_mem_psi_us]
76+
77+
class DamosQuotaGoal:
78+
metric = None
79+
target_value = None
80+
current_value = None
81+
effective_bytes = None
82+
quota = None # owner quota
83+
idx = None
84+
85+
def __init__(self, metric, target_value=10000, current_value=0):
86+
self.metric = metric
87+
self.target_value = target_value
88+
self.current_value = current_value
89+
90+
def sysfs_dir(self):
91+
return os.path.join(self.quota.sysfs_dir(), 'goals', '%d' % self.idx)
92+
93+
def stage(self):
94+
err = write_file(os.path.join(self.sysfs_dir(), 'target_metric'),
95+
self.metric)
96+
if err is not None:
97+
return err
98+
err = write_file(os.path.join(self.sysfs_dir(), 'target_value'),
99+
self.target_value)
100+
if err is not None:
101+
return err
102+
err = write_file(os.path.join(self.sysfs_dir(), 'current_value'),
103+
self.current_value)
104+
if err is not None:
105+
return err
106+
return None
107+
73108
class DamosQuota:
74109
sz = None # size quota, in bytes
75110
ms = None # time quota
111+
goals = None # quota goals
76112
reset_interval_ms = None # quota reset interval
77113
scheme = None # owner scheme
78114

79-
def __init__(self, sz=0, ms=0, reset_interval_ms=0):
115+
def __init__(self, sz=0, ms=0, goals=None, reset_interval_ms=0):
80116
self.sz = sz
81117
self.ms = ms
82118
self.reset_interval_ms = reset_interval_ms
119+
self.goals = goals if goals is not None else []
120+
for idx, goal in enumerate(self.goals):
121+
goal.idx = idx
122+
goal.quota = self
83123

84124
def sysfs_dir(self):
85125
return os.path.join(self.scheme.sysfs_dir(), 'quotas')
@@ -96,6 +136,20 @@ def stage(self):
96136
if err != None:
97137
return err
98138

139+
nr_goals_file = os.path.join(self.sysfs_dir(), 'goals', 'nr_goals')
140+
content, err = read_file(nr_goals_file)
141+
if err is not None:
142+
return err
143+
if int(content) != len(self.goals):
144+
err = write_file(nr_goals_file, len(self.goals))
145+
if err is not None:
146+
return err
147+
for goal in self.goals:
148+
err = goal.stage()
149+
if err is not None:
150+
return err
151+
return None
152+
99153
class DamosStats:
100154
nr_tried = None
101155
sz_tried = None
@@ -361,6 +415,34 @@ def update_schemes_stats(self):
361415
stat_values.append(int(content))
362416
scheme.stats = DamosStats(*stat_values)
363417

418+
def update_schemes_effective_quotas(self):
419+
err = write_file(os.path.join(self.sysfs_dir(), 'state'),
420+
'update_schemes_effective_quotas')
421+
if err is not None:
422+
return err
423+
for context in self.contexts:
424+
for scheme in context.schemes:
425+
for goal in scheme.quota.goals:
426+
content, err = read_file(
427+
os.path.join(scheme.quota.sysfs_dir(),
428+
'effective_bytes'))
429+
if err is not None:
430+
return err
431+
goal.effective_bytes = int(content)
432+
return None
433+
434+
def commit_schemes_quota_goals(self):
435+
for context in self.contexts:
436+
for scheme in context.schemes:
437+
for goal in scheme.quota.goals:
438+
err = goal.stage()
439+
if err is not None:
440+
print('commit_schemes_quota_goals failed stagign: %s'%
441+
err)
442+
exit(1)
443+
return write_file(os.path.join(self.sysfs_dir(), 'state'),
444+
'commit_schemes_quota_goals')
445+
364446
class Kdamonds:
365447
kdamonds = []
366448

0 commit comments

Comments
 (0)