linux/tools/testing/selftests/damon/damos_quota_goal.py
SeongJae Park 349db086a6 selftests/damon/damos_quota_goal: handle minimum quota that cannot be further reduced
damos_quota_goal.py selftest see if DAMOS quota goals tuning feature
increases or reduces the effective size quota for given score as expected.
The tuning feature sets the minimum quota size as one byte, so if the
effective size quota is already one, we cannot expect it further be
reduced.  However the test is not aware of the edge case, and fails since
it shown no expected change of the effective quota.  Handle the case by
updating the failure logic for no change to see if it was the case, and
simply skips to next test input.

Link: https://lkml.kernel.org/r/20250217182304.45215-1-sj@kernel.org
Fixes: f1c07c0a16 ("selftests/damon: add a test for DAMOS quota goal")
Signed-off-by: SeongJae Park <sj@kernel.org>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202502171423.b28a918d-lkp@intel.com
Cc: Shuah Khan <shuah@kernel.org>
Cc: <stable@vger.kernel.org>	[6.10.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-03-05 21:36:12 -08:00

80 lines
2.8 KiB
Python
Executable file

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
import subprocess
import time
import _damon_sysfs
def main():
# access two 10 MiB memory regions, 2 second per each
sz_region = 10 * 1024 * 1024
proc = subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '2000'])
goal = _damon_sysfs.DamosQuotaGoal(
metric=_damon_sysfs.qgoal_metric_user_input, target_value=10000)
kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
contexts=[_damon_sysfs.DamonCtx(
ops='vaddr',
targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
schemes=[_damon_sysfs.Damos(
action='stat',
quota=_damon_sysfs.DamosQuota(
goals=[goal], reset_interval_ms=100),
)] # schemes
)] # contexts
)]) # kdamonds
err = kdamonds.start()
if err != None:
print('kdamond start failed: %s' % err)
exit(1)
score_values_to_test = [0, 15000, 5000, 18000]
while proc.poll() == None:
if len(score_values_to_test) == 0:
time.sleep(0.1)
continue
goal.current_value = score_values_to_test.pop(0)
expect_increase = goal.current_value < goal.target_value
err = kdamonds.kdamonds[0].commit_schemes_quota_goals()
if err is not None:
print('commit_schemes_quota_goals failed: %s' % err)
exit(1)
err = kdamonds.kdamonds[0].update_schemes_effective_quotas()
if err is not None:
print('before-update_schemes_effective_quotas failed: %s' % err)
exit(1)
last_effective_bytes = goal.effective_bytes
time.sleep(0.5)
err = kdamonds.kdamonds[0].update_schemes_effective_quotas()
if err is not None:
print('after-update_schemes_effective_quotas failed: %s' % err)
exit(1)
print('score: %s, effective quota: %d -> %d (%.3fx)' % (
goal.current_value, last_effective_bytes, goal.effective_bytes,
goal.effective_bytes / last_effective_bytes
if last_effective_bytes != 0 else -1.0))
if last_effective_bytes == goal.effective_bytes:
# effective quota was already minimum that cannot be more reduced
if expect_increase is False and last_effective_bytes == 1:
continue
print('efective bytes not changed: %d' % goal.effective_bytes)
exit(1)
increased = last_effective_bytes < goal.effective_bytes
if expect_increase != increased:
print('expectation of increase (%s) != increased (%s)' %
(expect_increase, increased))
exit(1)
last_effective_bytes = goal.effective_bytes
if __name__ == '__main__':
main()