From nobody Wed Oct 8 10:56:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C87224501B; Sat, 28 Jun 2025 16:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126673; cv=none; b=WXRyofDbv2fBVTH2JnsBzKTN/3I4qN5osy/NsORGOicLuvOCXkIGvTpBMxTq6Mw2GU0yLN+5e12bXNHhL31fETv1QxNJ2+D7bK7IWCyKKdaJup1zlpVUA4wqwO203s7QRtI+qiSs7QD4Uzo2J6AL7CqLY7WFb59S4DD5hq3K+jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126673; c=relaxed/simple; bh=LQYj+y4NHRcCBylThRwztooldZRKZFHtpfiwZ2j/m2o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=udRS7Duzhc+RMI+kmWt3gPQBt8blwM+88wXTF6mdAas1sQu8AyJhgTRXR7Ei7dR1wjWrNWI1thYPoT1k+YUyDtsMTVlE9D2pzR9uV6j0Jvm+Ovg7JFj7DvOJg/4q2lKh+DUozg/wZimdvN2CPNzH8xiL0fW1DKAQZ1rZjdfAMPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cSNgq90N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cSNgq90N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02B30C4AF09; Sat, 28 Jun 2025 16:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751126673; bh=LQYj+y4NHRcCBylThRwztooldZRKZFHtpfiwZ2j/m2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cSNgq90NiT1h2PlAU76fonhPwvTnVpXfKhea107Zxg/WgkS1m5B0HUbuX8v6xv3pc /Ks1xCGwDd+yjkcOLjTlVLxZ9PQrRHbGjrSPjnj6452nybIeFmYt88tSn8z2xrDqRu 97akYhFZwrTKu5jVQA6TBZdf9PSSZ+ldmVhvXb+FxakSVTKDCXLQy9PipwzrOj/dTP jVa3PNyMtH4+Kzo8dFOsubWQExw6shD4CjdasLe5GCiRHNMeTS8whyf6uCrKbfHPNL 0Kp1LVjAQtRb17pRT1e4SZ7Atee/57JankmYtNoCvtIXmwyw9GtYx5gxr43oLtfofo tbqWAxBs7Q+CQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/6] selftests/damon: add drgn script for extracting damon status Date: Sat, 28 Jun 2025 09:04:23 -0700 Message-Id: <20250628160428.53115-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628160428.53115-1-sj@kernel.org> References: <20250628160428.53115-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 'drgn' is a useful tool for extracting kernel internal data structures such as DAMON's parameter and running status. Add a 'drgn' script that extracts such DAMON internal data at runtime, for using it as a tool for seeing if a test input has made expected results in the kernel. The script saves or prints out the DAMON internal data as a json file or string. This is for making use of it not very depends on 'drgn'. If 'drgn' is not available on a test setup and we find alternative tools for doing that, the json-based tests can be updated to use an alternative tool in future. Note that the script is tested with 'drgn v0.0.22'. Signed-off-by: SeongJae Park --- .../selftests/damon/drgn_dump_damon_status.py | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 tools/testing/selftests/damon/drgn_dump_damon_status.py diff --git a/tools/testing/selftests/damon/drgn_dump_damon_status.py b/tool= s/testing/selftests/damon/drgn_dump_damon_status.py new file mode 100755 index 000000000000..333a0d0c4bff --- /dev/null +++ b/tools/testing/selftests/damon/drgn_dump_damon_status.py @@ -0,0 +1,161 @@ +#!/usr/bin/env drgn +# SPDX-License-Identifier: GPL-2.0 + +''' +Read DAMON context data and dump as a json string. +''' +import drgn +from drgn import FaultError, NULL, Object, cast, container_of, execscript,= offsetof, reinterpret, sizeof +from drgn.helpers.common import * +from drgn.helpers.linux import * + +import json +import sys + +if "prog" not in globals(): + try: + prog =3D drgn.get_default_prog() + except drgn.NoDefaultProgramError: + prog =3D drgn.program_from_kernel() + drgn.set_default_prog(prog) + +def to_dict(object, attr_name_converter): + d =3D {} + for attr_name, converter in attr_name_converter: + d[attr_name] =3D converter(getattr(object, attr_name)) + return d + +def intervals_goal_to_dict(goal): + return to_dict(goal, [ + ['access_bp', int], + ['aggrs', int], + ['min_sample_us', int], + ['max_sample_us', int], + ]) + +def attrs_to_dict(attrs): + return to_dict(attrs, [ + ['sample_interval', int], + ['aggr_interval', int], + ['ops_update_interval', int], + ['intervals_goal', intervals_goal_to_dict], + ['min_nr_regions', int], + ['max_nr_regions', int], + ]) + +def addr_range_to_dict(addr_range): + return to_dict(addr_range, [ + ['start', int], + ['end', int], + ]) + +def region_to_dict(region): + return to_dict(region, [ + ['ar', addr_range_to_dict], + ['sampling_addr', int], + ['nr_accesses', int], + ['nr_accesses_bp', int], + ['age', int], + ]) + +def regions_to_list(regions): + return [region_to_dict(r) + for r in list_for_each_entry( + 'struct damon_region', regions.address_of_(), 'list')] + +def target_to_dict(target): + return to_dict(target, [ + ['pid', int], + ['nr_regions', int], + ['regions_list', regions_to_list], + ]) + +def targets_to_list(targets): + return [target_to_dict(t) + for t in list_for_each_entry( + 'struct damon_target', targets.address_of_(), 'list')] + +def damos_access_pattern_to_dict(pattern): + return to_dict(pattern, [ + ['min_sz_region', int], + ['max_sz_region', int], + ['min_nr_accesses', int], + ['max_nr_accesses', int], + ['min_age_region', int], + ['max_age_region', int], + ]) + +def damos_quota_goal_to_dict(goal): + return to_dict(goal, [ + ['metric', int], + ['target_value', int], + ['current_value', int], + ['last_psi_total', int], + ['nid', int], + ]) + +def damos_quota_goals_to_list(goals): + return [damos_quota_goal_to_dict(g) + for g in list_for_each_entry( + 'struct damos_quota_goal', goals.address_of_(), 'list')] + +def damos_quota_to_dict(quota): + return to_dict(quota, [ + ['reset_interval', int], + ['ms', int], ['sz', int], + ['goals', damos_quota_goals_to_list], + ['esz', int], + ['weight_sz', int], + ['weight_nr_accesses', int], + ['weight_age', int], + ]) + +def damos_watermarks_to_dict(watermarks): + return to_dict(watermarks, [ + ['metric', int], + ['interval', int], + ['high', int], ['mid', int], ['low', int], + ]) + +def scheme_to_dict(scheme): + return to_dict(scheme, [ + ['pattern', damos_access_pattern_to_dict], + ['action', int], + ['apply_interval_us', int], + ['quota', damos_quota_to_dict], + ['wmarks', damos_watermarks_to_dict], + ['target_nid', int], + ]) + +def schemes_to_list(schemes): + return [scheme_to_dict(s) + for s in list_for_each_entry( + 'struct damos', schemes.address_of_(), 'list')] + +def damon_ctx_to_dict(ctx): + return to_dict(ctx, [ + ['attrs', attrs_to_dict], + ['adaptive_targets', targets_to_list], + ['schemes', schemes_to_list], + ]) + +def main(): + if len(sys.argv) < 3: + print('Usage: %s ' % sys.argv[0]) + exit(1) + + pid =3D int(sys.argv[1]) + file_to_store =3D sys.argv[2] + + kthread_data =3D cast('struct kthread *', + find_task(prog, pid).worker_private).data + ctx =3D cast('struct damon_ctx *', kthread_data) + status =3D {'contexts': [damon_ctx_to_dict(ctx)]} + if file_to_store =3D=3D 'stdout': + print(json.dumps(status, indent=3D4)) + else: + with open(file_to_store, 'w') as f: + json.dump(status, f, indent=3D4) + +if __name__ =3D=3D '__main__': + main() --=20 2.39.5 From nobody Wed Oct 8 10:56:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DC6224A046; Sat, 28 Jun 2025 16:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126674; cv=none; b=tevsHdau7IvmTmZ/Q7XjQ1k6rO8tEpUl0KYWeRjE8vB+XoZk7uBFs5tShFeWdQUSnbNNGekcGujMKNf4S4EZzVoZRWRUOPm981Dg7FppGCNaILuc09caSCnYug2x60vhXCzTMLjBJVqqiSMuTiE93rWXCwio1efa4YoqFjhbHEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126674; c=relaxed/simple; bh=/RUstGJfkJjRI+Pr6WW5egPsetwstPl+AsaLyBk7JE4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o5S7z9Spk5Z60uL2MFB9fqO21IJz5/zdIub9ADyppnwJGIZF3KDMwc2fZqQD56q0ZUCEOkaO8NjS2xmMkDe5c4wVB6pAe3I+NvIQ16VxrJoiJu4mqcadVcgmNi4FDpGt8u/19jTv7g/V2fM9Yg9gLDz6qnRLxJqyB+M8NfqmvEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AL3CjV8R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AL3CjV8R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B039C4CEF0; Sat, 28 Jun 2025 16:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751126674; bh=/RUstGJfkJjRI+Pr6WW5egPsetwstPl+AsaLyBk7JE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AL3CjV8RIxzxWxM0CBi6GhgIMqaf9qt6luLN0tmydUTgFd+kG6t/FoisMMGa+eE/7 sT34yBMVuQTiXpRS7fxFl6+/bzgfvu3Xp4VcdlVWLUM00qeumc63oD3hbfNntsc6tA uxPFbiM/CqYQHJNsuH6CX1SWnn2ilDD3htKqZFui/qo7Qnm/LQqIjR+XPqLBEUaTfX zHUHKT4zKiJs45m1KEvgkG24rlK5H3yI8hkbM/ZSd7ZP64/uNDuj3HHvGNzlVmzBsA 2enrh9+qZoK2oNklSK1BRvbaHgH9d2kvsjfI6ON0/mMvOzjB+l3sj8DfFX8WNfqbGK XNW4o+oz7ABVQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/6] selftests/damon/_damon_sysfs: set Kdamond.pid in start() Date: Sat, 28 Jun 2025 09:04:24 -0700 Message-Id: <20250628160428.53115-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628160428.53115-1-sj@kernel.org> References: <20250628160428.53115-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" _damon_sysfs.py is a Python module for reading and writing DAMON sysfs for testing. It is not reading resulting kdamond pids. Read and update those when starting kdamonds. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/= selftests/damon/_damon_sysfs.py index 5b1cb6b3ce4e..f587e117472e 100644 --- a/tools/testing/selftests/damon/_damon_sysfs.py +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -408,6 +408,9 @@ class Kdamond: if err is not None: return err err =3D write_file(os.path.join(self.sysfs_dir(), 'state'), 'on') + if err is not None: + return err + self.pid, err =3D read_file(os.path.join(self.sysfs_dir(), 'pid')) return err =20 def stop(self): --=20 2.39.5 From nobody Wed Oct 8 10:56:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B657024E4D4; Sat, 28 Jun 2025 16:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126677; cv=none; b=EFGk9NEon6Eic3Vti8ROF3QGvRmlSqbszMdk1ljV/RD4dV0x9JGC247+yqev0KaEqxZcFkqZI5kbJOyMVD6+Z61582JLS9H3lMePa81OkqP9L5C2phLsEisayuW8k8MQHcZaO0/WlyWKB5T0FNDtSOd1zMtSBjHnrjEFXl79ZBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126677; c=relaxed/simple; bh=pHn9v+99jI3xSiVYbi8lj20xdzjr33kYRD7kjoO8nBY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=juJ0+eAQLS9fI+Wt/nEY1vAYkTwPfAX4r6G9R48IpFiBK+zLraiuqHwLOly646UXnVEhNyprO1o4d1lk0GcttpyKm+q2Xm5LaDy6ICLZbwrg19aYsI4r2k7ncZ/ZXOPTkCvyWk/+qjbPal1F4GiImC48upmfh+BGNRATUEx50pc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nWThUJGM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nWThUJGM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FB55C4CEED; Sat, 28 Jun 2025 16:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751126675; bh=pHn9v+99jI3xSiVYbi8lj20xdzjr33kYRD7kjoO8nBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWThUJGMxmZ9QzBclE+lbiYiSfrIsn1T9tlYlp/FqQuMJEPPDcqepJN5XeHpDzReE PbqAfvW6Tz0uWXRMGKGVWitby+edQLBAdIX+OM6V5Z6hcz/OHdQqhqMqmfWemabo8E ohCL68eUSjTEY3Pl3v5tmov4J7y2Px5Qkr3MV5BcXBLeydm1fsxgWvl/8U2mlqb8KA /Mw03VzTki158ViwLNhGTTYnawJ3IjsesAyW7bSZsnhdG7nZEEZuRSHxMJCDvFNqF/ /KJlLrAYYf58jIK+TlENvlqR463iTv4F7uu9le17ti5hEpp6FINPJeOw70IX7owwYT b2yu8eZO/kzPA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/6] selftests/damon: add python and drgn-based DAMON sysfs test Date: Sat, 28 Jun 2025 09:04:25 -0700 Message-Id: <20250628160428.53115-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628160428.53115-1-sj@kernel.org> References: <20250628160428.53115-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a python-written DAMON sysfs functionality selftest. It sets DAMON parameters using Python module _damon_sysfs, reads updated kernel internal DAMON status and parameters using a 'drgn' script, namely drgn_dump_damon_status.py, and compare if the resulted DAMON internal status is as expected. The test is very minimum at the moment. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/Makefile | 1 + tools/testing/selftests/damon/sysfs.py | 42 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 tools/testing/selftests/damon/sysfs.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftes= ts/damon/Makefile index e888455e3cf8..5b230deb19e8 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -7,6 +7,7 @@ TEST_FILES =3D _damon_sysfs.py =20 # functionality tests TEST_PROGS +=3D sysfs.sh +TEST_PROGS +=3D sysfs.py TEST_PROGS +=3D sysfs_update_schemes_tried_regions_wss_estimation.py TEST_PROGS +=3D damos_quota.py damos_quota_goal.py damos_apply_interval.py TEST_PROGS +=3D damos_tried_regions.py damon_nr_regions.py diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftes= ts/damon/sysfs.py new file mode 100755 index 000000000000..4ff99db0d247 --- /dev/null +++ b/tools/testing/selftests/damon/sysfs.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import json +import os +import subprocess + +import _damon_sysfs + +def dump_damon_status_dict(pid): + file_dir =3D os.path.dirname(os.path.abspath(__file__)) + dump_script =3D os.path.join(file_dir, 'drgn_dump_damon_status.py') + rc =3D subprocess.call(['drgn', dump_script, pid, 'damon_dump_output'], + stderr=3Dsubprocess.DEVNULL) + if rc !=3D 0: + return None, 'drgn fail' + try: + with open('damon_dump_output', 'r') as f: + return json.load(f), None + except Exception as e: + return None, 'json.load fail (%s)' % e + +def main(): + kdamonds =3D _damon_sysfs.Kdamonds( + [_damon_sysfs.Kdamond(contexts=3D[_damon_sysfs.DamonCtx()])]) + err =3D kdamonds.start() + if err is not None: + print('kdamond start failed: %s' % err) + exit(1) + + status, err =3D dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print(err) + exit(1) + + if len(status['contexts']) !=3D 1: + print('number of contexts: %d' % len(status['contexts'])) + exit(1) + kdamonds.stop() + +if __name__ =3D=3D '__main__': + main() --=20 2.39.5 From nobody Wed Oct 8 10:56:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BDFF253B59; Sat, 28 Jun 2025 16:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126676; cv=none; b=Rll4Q+xVd0s3tMMuuMkSn5S9J3kkdtDQBRjez7nj6Kzi2H0vabhGEyCLEqe/i9dH829JfOO7nflxaATDuRG49fgi1rXGVdRNzVoH1tK0auantPHOITLidD501YsmJiqsjKO+pU24PXbOfNgqVFFx8O/saA0xz7Me5Lg9A8PdkS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126676; c=relaxed/simple; bh=miTM6A3QV73RUDWnpfCOrpusoocXXvQwskQZDbdPk1E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oQipQA3r/+CC72s1BsnbQrnaVbuBtHDfRXu33+7x9Dx4s+PKfh2usBx1tWCNX6SOBh2OrztKjqOcoy6XGxUOX5NeQ0ung9JvWwRp3bcMeSeaKwBSTv3yWSrBnOaOwYBr/gUjuI+VZQ7pWEQcxmyxccshbKxQFpAVdWOC4Vc15J8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kYU/71lJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kYU/71lJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07606C4CEEA; Sat, 28 Jun 2025 16:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751126676; bh=miTM6A3QV73RUDWnpfCOrpusoocXXvQwskQZDbdPk1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kYU/71lJwh92l6aB/jcxuGPjkDyUhJHP2n6X2qLYacnBgfxpk8Xd0zT96ptt7ggg9 1IB8R6GUq/YVcrTd+Ij2w9a9VbPK1a50qs9o7bk5ioR6UTZGTnUj2si86Y+PeBx+fE tX2BW/34/4AOSzVFgh/l7DpSUkPkw/3N+M5FxhcWwqIdcVPi+NltK7PBN4pv4drmIN xSNnAp/WKZ7LVqXOdyiJP7HZbWz20/ftu+23XSUtbt5SwrqiNqo2LTq6fJPtIVYRNL U/hNrqf5QrHkY+Sj3GWOzwR4/tiZK1LlsY6TziYppW+D7NxAbfE7UQALuS2uhLxLoB f8rzMNWQaX93g== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/6] selftests/damon/sysfs.py: test monitoring attribute parameters Date: Sat, 28 Jun 2025 09:04:26 -0700 Message-Id: <20250628160428.53115-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628160428.53115-1-sj@kernel.org> References: <20250628160428.53115-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add DAMON sysfs interface functionality tests for DAMON monitoring attribute parameters, including intervals, intervals tuning goals, and min/max number of regions. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.py | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftes= ts/damon/sysfs.py index 4ff99db0d247..a721901a880d 100755 --- a/tools/testing/selftests/damon/sysfs.py +++ b/tools/testing/selftests/damon/sysfs.py @@ -20,6 +20,11 @@ def dump_damon_status_dict(pid): except Exception as e: return None, 'json.load fail (%s)' % e =20 +def fail(expectation, status): + print('unexpected %s' % expectation) + print(json.dumps(status, indent=3D4)) + exit(1) + def main(): kdamonds =3D _damon_sysfs.Kdamonds( [_damon_sysfs.Kdamond(contexts=3D[_damon_sysfs.DamonCtx()])]) @@ -34,8 +39,33 @@ def main(): exit(1) =20 if len(status['contexts']) !=3D 1: - print('number of contexts: %d' % len(status['contexts'])) - exit(1) + fail('number of contexts', status) + + ctx =3D status['contexts'][0] + attrs =3D ctx['attrs'] + if attrs['sample_interval'] !=3D 5000: + fail('sample interval', status) + if attrs['aggr_interval'] !=3D 100000: + fail('aggr interval', status) + if attrs['ops_update_interval'] !=3D 1000000: + fail('ops updte interval', status) + + if attrs['intervals_goal'] !=3D { + 'access_bp': 0, 'aggrs': 0, + 'min_sample_us': 0, 'max_sample_us': 0}: + fail('intervals goal') + + if attrs['min_nr_regions'] !=3D 10: + fail('min_nr_regions') + if attrs['max_nr_regions'] !=3D 1000: + fail('max_nr_regions') + + if ctx['adaptive_targets'] !=3D []: + fail('adaptive_targets') + + if ctx['schemes'] !=3D []: + fail('schemes') + kdamonds.stop() =20 if __name__ =3D=3D '__main__': --=20 2.39.5 From nobody Wed Oct 8 10:56:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B650424A046; Sat, 28 Jun 2025 16:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126677; cv=none; b=Nzbb64+tffr1jWBIthLyAVWPzOLBEnVMFYyy9VkuxdiMFCTpafzBhxI7c0Ye1cdBnT4IMtYQ6xejXzbRmkyNis2BPxELYBWQz+uTqoIW7nmILQ97crf/OMUYs8blXykwqHo2aqArHIpn1DUZGsuYMVRIk3ZpcU7fE27Jo6WGt8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126677; c=relaxed/simple; bh=wq56Vg1wiYwnpAsrjZ3THKuY4FAoz9PHZqmw/hYGZ0Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cK8T4D5eXdNksEE8I3rBb/qGN1lygw8vlh/WKHkFWq2b5liNVLG9ec7e78FEzrn3jLgKV6pN0h2jOOlIONahWMH7xxzoH3XMiXPzXDlPw4UV3+PTHjdDS4a8ySUji3Ru1ezJpoOMmLbu+HLQg8AP9oA856PS+0izzw3eLxKU8S4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GqacQgdf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GqacQgdf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19389C4CEEA; Sat, 28 Jun 2025 16:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751126677; bh=wq56Vg1wiYwnpAsrjZ3THKuY4FAoz9PHZqmw/hYGZ0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GqacQgdfGAfSTiVWwh8Hf4WAzqL0w7VEwuQRy4PDoA+3fr7Y1nfPvCuB0QcULDgAV qwUvXKNBUN5SeuirbpZ2z/wy1Axj+N2ePqQ9ff7u647IxlVdraxthss4B2MuuwjBl4 NGGVDbOqOAVgjAXXxy2cpBtvOUetAMGDi8oaMI1o6jiO5dtc2Pt0aZHh8obhC+PEGh hxznqYVavAcNdlVS4rbyvl3sheHFLGt8gr0KZt/VZSDBv/TDvIB5+o3fiCq6tIM6nN +1d6FNLK62oJ/zTA6FCfAtcP+t0CEApLiUg0anoekolkZdwJVxdSjVY3Kc15VuxQDE AB6Bfzv8VfF6g== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/6] selftests/damon/sysfs.py: test adaptive targets parameter Date: Sat, 28 Jun 2025 09:04:27 -0700 Message-Id: <20250628160428.53115-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628160428.53115-1-sj@kernel.org> References: <20250628160428.53115-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add DAMON sysfs interface functionality tests for setup of basic adaptive targets parameters. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftes= ts/damon/sysfs.py index a721901a880d..3b085268f342 100755 --- a/tools/testing/selftests/damon/sysfs.py +++ b/tools/testing/selftests/damon/sysfs.py @@ -27,7 +27,9 @@ def fail(expectation, status): =20 def main(): kdamonds =3D _damon_sysfs.Kdamonds( - [_damon_sysfs.Kdamond(contexts=3D[_damon_sysfs.DamonCtx()])]) + [_damon_sysfs.Kdamond( + contexts=3D[_damon_sysfs.DamonCtx( + targets=3D[_damon_sysfs.DamonTarget(pid=3D-1)])])]) err =3D kdamonds.start() if err is not None: print('kdamond start failed: %s' % err) @@ -60,8 +62,9 @@ def main(): if attrs['max_nr_regions'] !=3D 1000: fail('max_nr_regions') =20 - if ctx['adaptive_targets'] !=3D []: - fail('adaptive_targets') + if ctx['adaptive_targets'] !=3D [ + { 'pid': 0, 'nr_regions': 0, 'regions_list': []}]: + fail('adaptive targets', status) =20 if ctx['schemes'] !=3D []: fail('schemes') --=20 2.39.5 From nobody Wed Oct 8 10:56:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72DEA2580C7; Sat, 28 Jun 2025 16:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126678; cv=none; b=TcCBq0MkXamWzzh2Gs2+3SmeYBA57K+s7i2TXtE99zUL5YzAJk0nE/mgMrYdpLB1xIGFzvOavJQvo2j8v414euKSEh0TNdWdfLSTzTsnP61pwVk8dj9yvra47bZ3fMqvJOJUNs/JO+Wg2iwn2tNgnAc+TNV9UKOiWkg3wNGgAxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751126678; c=relaxed/simple; bh=CR4mzDVLH9lzs9or4TF7dOJ0izoFCJ1YoukXbycwrC8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cXDku1Zzrf9LQap7KJ6mgl/271Irjbai8YhpIfUfPtNv15GCw8SkU5CnVJOGPVyT6cyRI7tydWWGKkjI2DnzMO1SDt0Pye9f5rInAdTPyGoh9f8tTDzxsKVEwJnxBCFIjnt2YbJhy4GLkCH0IqGMZ+FTVJfi9ZH9sVKaBfkKH/0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K6oAy2GB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K6oAy2GB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B283C4CEF0; Sat, 28 Jun 2025 16:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751126678; bh=CR4mzDVLH9lzs9or4TF7dOJ0izoFCJ1YoukXbycwrC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K6oAy2GBVbt4l+KFZyXRM8kh35N4U8lVQGix7E1seh2aEqJWlJnZKqAT1/hKE6Fx6 6pKD9W5+k1YYTdaN3DtWzS+tLrS/itSXxtF9SMV0Dui13mWa9hDvjiJP/xdfltRrt5 uTZk3Gqgbw03Fsedi5/hL1Qpf+q0ULC8pPBhHEzSw2fsI+Coz9r8Ig5VsNDFVmQcK1 PzozoYQ8DBmTx5Mnc/15svxPZWDwvxI0xGcsLrLYVpNvtC//zGtDu1cSxBzHtl053D BYST/3m3APnENUjq2cdRbZd/O2NaN9kJ0bA1yr1Cheox4+em/UK5KkEu0Rq5MlLpYb Z+n8MXWtNKIgQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 6/6] selftests/damon/sysfs.py: test DAMOS schemes parameters setup Date: Sat, 28 Jun 2025 09:04:28 -0700 Message-Id: <20250628160428.53115-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250628160428.53115-1-sj@kernel.org> References: <20250628160428.53115-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add DAMON sysfs interface functionality tests for basic DAMOS schemes parameters setup. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.py | 46 ++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftes= ts/damon/sysfs.py index 3b085268f342..e67008fd055d 100755 --- a/tools/testing/selftests/damon/sysfs.py +++ b/tools/testing/selftests/damon/sysfs.py @@ -29,7 +29,9 @@ def main(): kdamonds =3D _damon_sysfs.Kdamonds( [_damon_sysfs.Kdamond( contexts=3D[_damon_sysfs.DamonCtx( - targets=3D[_damon_sysfs.DamonTarget(pid=3D-1)])])]) + targets=3D[_damon_sysfs.DamonTarget(pid=3D-1)], + schemes=3D[_damon_sysfs.Damos()], + )])]) err =3D kdamonds.start() if err is not None: print('kdamond start failed: %s' % err) @@ -66,8 +68,46 @@ def main(): { 'pid': 0, 'nr_regions': 0, 'regions_list': []}]: fail('adaptive targets', status) =20 - if ctx['schemes'] !=3D []: - fail('schemes') + if len(ctx['schemes']) !=3D 1: + fail('number of schemes', status) + + scheme =3D ctx['schemes'][0] + if scheme['pattern'] !=3D { + 'min_sz_region': 0, + 'max_sz_region': 2**64 - 1, + 'min_nr_accesses': 0, + 'max_nr_accesses': 2**32 - 1, + 'min_age_region': 0, + 'max_age_region': 2**32 - 1, + }: + fail('damos pattern', status) + if scheme['action'] !=3D 9: # stat + fail('damos action', status) + if scheme['apply_interval_us'] !=3D 0: + fail('damos apply interval', status) + if scheme['target_nid'] !=3D -1: + fail('damos target nid', status) + + if scheme['quota'] !=3D { + 'reset_interval': 0, + 'ms': 0, + 'sz': 0, + 'goals': [], + 'esz': 0, + 'weight_sz': 0, + 'weight_nr_accesses': 0, + 'weight_age': 0, + }: + fail('damos quota', status) + + if scheme['wmarks'] !=3D { + 'metric': 0, + 'interval': 0, + 'high': 0, + 'mid': 0, + 'low': 0, + }: + fail('damos wmarks', status) =20 kdamonds.stop() =20 --=20 2.39.5