From patchwork Sat Dec 2 00:08:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13476683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CD26C4167B for ; Sat, 2 Dec 2023 00:08:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E65728D007A; Fri, 1 Dec 2023 19:08:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E14EB8D0001; Fri, 1 Dec 2023 19:08:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D040E8D007A; Fri, 1 Dec 2023 19:08:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C15778D0001 for ; Fri, 1 Dec 2023 19:08:13 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 98BFDA0392 for ; Sat, 2 Dec 2023 00:08:13 +0000 (UTC) X-FDA: 81519940866.04.54A8AF3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id E1E231A000A for ; Sat, 2 Dec 2023 00:08:11 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ftiBRtoD; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701475692; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OsypTyUMi/Yh1aH0wXO7Cp4Fx6Odu0Zkog1frADmOxo=; b=HrxYvKcxrE0RSknSveOsntkD3qIwh0wgqJQ07LeaDzurM0dIj9H0LztAO4VxSfwczexFtB 39zYw3G0Czhi9C/AkMuGHvf0hFtKqIl+rCQ9YBTb4m4KdX2i9oiR/XoZ20SoWswLwKiWpV 1LTdXPgOVxn1FQunYFrkmsqHX8WTc4E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701475692; a=rsa-sha256; cv=none; b=lhP+F6mYXUYGRgx7zK3/pk9BwEQ2mdKGQSz0bgYvzCcW/Hb9Svb71RylO80DDbCy6eZhvZ Kw16bxY/UPxY1hxl8ysaCub1Kwl1oIrh6k8eQH0ryoTJZPH7Q7HPtytagRwIxHmu9axLe1 2X3GYZze7kj4iZWARadTkWY3PtaoF+4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ftiBRtoD; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E791E61761; Sat, 2 Dec 2023 00:08:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C2B1C433C8; Sat, 2 Dec 2023 00:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701475690; bh=GC7hLao6eamt5j9k8hcen8vPzgOkrgeme7Xf5lpgbH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ftiBRtoD5yl3wEraHqbN9wNqd+G6GNBLIgbbxpKOrAHe8oFCL7SBEpqsjBQ3FBZjl kJ0M6ueGJRGdyNixjGCs/yCwrSiN7nBkW5cf+rEdlaQjsoqvMrJtS6mUTqdMYIUrWG duoCJbg0mJe1uhfD2luVEvn0EEQBvfItemXsQ8n24Xxtl1H/RsVHr3Kj0QU4Wz+mUM 9zSYm9L2V6rsZyDO5M2QQmhJldTJuxZGroKBuSpCk5DHoBxirlz8Csr0eOaiPeLFmM MHlCMPu6dHhXS7RgkofjSyJaxpu2deByYIQbzJC6XJolAfJ8xa8JM9pIzZOPL0nDHA LsMkoitTUar3g== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/5] selftests/damon: add a DAMON interface wrapper python module Date: Sat, 2 Dec 2023 00:08:02 +0000 Message-Id: <20231202000806.46210-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202000806.46210-1-sj@kernel.org> References: <20231202000806.46210-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E1E231A000A X-Rspam-User: X-Stat-Signature: giz96gx1x14cap5ns6iwu9swju7uzjhg X-Rspamd-Server: rspam03 X-HE-Tag: 1701475691-896774 X-HE-Meta: U2FsdGVkX1/lZFyYz2eZ9Vii8REi34SvXYE7QEgL1/hQXBcOUIqPvT8TJD6x/8s06qt0nQEU/vQZFMqYIUn9Hd8i86DFLvIlzP4j+fRJBvDH2Xp+wL/6DY7PhN5qdqam7F7hqRdsyZEYboIig+W7/rixOrkmje9mMxjk4qBZV0Sc0djJcd3IQ1d/3gy7Ow4JxOibR4n8z+pZMmUwPULCTIGtmzUMb/iTx7g9ft7WNIVVWOC6QO9gMioJ+SlF8FzGx0ghLP7phw1HRznT0NGp9v8urfDa0ZgVkirfm8S4Hcykr6loZtbncKOC0pkqovFzpwCI34EuKBhvQ3fv0WJyS3OMY1cE85+/W17HSP1EyFdeHmg762dudmOgMyT42bVOtEbtyyRe2Ufo3uGUfiA8K4srZYLnVKv2w/kAingt2G8anT5mijDi8imbWknJvklSy/C0DEwBgPsarBay08AaHYfwgGPYqA51NWVTifpbemgKSE5hUMzgqaupgysnz/X7KIN5ReDK14cxZJ2q2PyL0pELY5HHBUYxAbe+ue/WxzclW+6ozjXH4p10L6VQG3GAvGqZ9Z5iGhEOOaE2abP0zEh0iNJdAPf3949jevKHK8k5cR3D+o5Wj3+9YNhljH42z57aiphpxAFzdDz6ANss3QWegoh03I1GYUe1b5fnx/F4HtMPZ8D5CIknAWzoUiDgJuXZ2ZauHl5Z2E3plLuzZ0AlHy+LvwNAi2dShUZ4xGFReCs8kq3fhbmbT0CKQJDq0IqNS8Lw6GQKV4VsxWkEHWLPeasSf67+tggXxaJiN5MFLEtFJblM8vUbdrJU2KJYAgP4qXVlBWqTmcutffqFjKhUINybmWSZMpH3njyLXnBGj3aW+7a2NEDyAGAGgALqkbQywPwJ0ykCUhMU3P8DMLpVWNN10SqQbw0Rpz9a9wkzKgTJtTuqYk0rwD/N408SvIq82UdpaJ6+eeQcGcH fj4EnSCD CR5XVZJs/B+BFoADvc3ZP4A2BwJmk7LGwJA7xhn4zzjY6lMMollAQTTsnVcnCN0cV75G+lDTlbmPEC8wk2kZqoVo9dfy9rgnexZ5if18hTybsZYJh+oMEo1BCkmjLMLrM9Uo8VI5rgF2CT76j/iK6DMZcBaqjykvyjHXrywDaTpeNG/McZvkYQpCFJwL6zWUvnk5N8DU5cfKogusRhWFbeRmVBIwubJp1taErf+MXNLDF0Ck= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: DAMON sysfs interface supports almost every DAMON functionality. For that, it provides a number of files and hierarchies that not simple to be manually manipulated, or writing shell script every time. For the reason, DAMON is not having good functionality selftests. Adding an existing DAMON user space tool and using it could also be a way, but it would add unnecessarily huge change that not essential for the test purpose. Write a minimum python module that can further extended to be used as an easy-to-use DAMON functionality test purpose DAMON user interface wrapper. Note that this commit is implementing only basic data structures for representing the sysfs files. More operations will be implemented by following commits, as needed for specific real test cases. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon.py | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tools/testing/selftests/damon/_damon.py diff --git a/tools/testing/selftests/damon/_damon.py b/tools/testing/selftests/damon/_damon.py new file mode 100644 index 000000000000..78101846ab66 --- /dev/null +++ b/tools/testing/selftests/damon/_damon.py @@ -0,0 +1,102 @@ +# SPDX-License-Identifier: GPL-2.0 + +class DamosAccessPattern: + size = None + nr_accesses = None + age = None + scheme = None + + def __init__(self, size=None, nr_accesses=None, age=None): + self.size = size + self.nr_accesses = nr_accesses + self.age = age + + if self.size == None: + self.size = [0, 2**64 - 1] + if self.nr_accesses == None: + self.nr_accesses = [0, 2**64 - 1] + if self.age == None: + self.age = [0, 2**64 - 1] + +class Damos: + action = None + access_pattern = None + # todo: Support quotas, watermarks, stats, tried_regions + idx = None + context = None + + def __init__(self, action='stat', access_pattern=DamosAccessPattern()): + self.action = action + self.access_pattern = access_pattern + self.access_pattern.scheme = self + +class DamonTarget: + pid = None + # todo: Support target regions if test is made + idx = None + context = None + + def __init__(self, pid): + self.pid = pid + +class DamonAttrs: + sample_us = None + aggr_us = None + update_us = None + min_nr_regions = None + max_nr_regions = None + context = None + + def __init__(self, sample_us=5000, aggr_us=100000, update_us=1000000, + min_nr_regions=10, max_nr_regions=1000): + self.sample_us = sample_us + self.aggr_us = aggr_us + self.update_us = update_us + self.min_nr_regions = min_nr_regions + self.max_nr_regions = max_nr_regions + +class DamonCtx: + ops = None + monitoring_attrs = None + targets = None + schemes = None + kdamond = None + idx = None + + def __init__(self, ops='paddr', monitoring_attrs=DamonAttrs(), targets=[], + schemes=[]): + self.ops = ops + self.monitoring_attrs = monitoring_attrs + self.monitoring_attrs.context = self + + self.targets = targets + for idx, target in enumerate(self.targets): + target.idx = idx + target.context = self + + self.schemes = schemes + for idx, scheme in enumerate(self.schemes): + scheme.idx = idx + scheme.context = self + +class Kdamond: + state = None + pid = None + contexts = None + idx = None # index of this kdamond between siblings + kdamonds = None # parent + + def __init__(self, contexts=[]): + self.contexts = contexts + for idx, context in enumerate(self.contexts): + context.idx = idx + context.kdamond = self + +class Kdamonds: + kdamonds = [] + + def __init__(self, kdamonds=[]): + self.kdamonds = kdamonds + for idx, kdamond in enumerate(self.kdamonds): + kdamond.idx = idx + kdamond.kdamonds = self