From patchwork Tue Dec 12 19:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13489787 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 A83E9C4332F for ; Tue, 12 Dec 2023 19:12:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E3766B033B; Tue, 12 Dec 2023 14:12:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 796936B033D; Tue, 12 Dec 2023 14:12:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60DDA6B033E; Tue, 12 Dec 2023 14:12:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4B7416B033B for ; Tue, 12 Dec 2023 14:12:22 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 25C7EA1EA1 for ; Tue, 12 Dec 2023 19:12:22 +0000 (UTC) X-FDA: 81559112124.08.4CBCC4E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf23.hostedemail.com (Postfix) with ESMTP id D5953140019 for ; Tue, 12 Dec 2023 19:12:19 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LRYglFPH; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 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=1702408340; 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=Llj595fCp/6fkqvOsmjH1Ip3cww+RZOnknJ+I9nFpd4=; b=P5hJrLUaMpkhGPuo7/S5ZbTadOvAgDU7qyoFuOok1G+0lEZt+ae0btxWEptBXfdghf5bV8 W0m8f6vVIl5VuXmd2DstkBMQwpAWbw6JbZ31sI3YG7+wo+hORpF9KFYe04xExdDNYxA78r /m7dR9hoAu8q255HoaqlzNfvrBrNUGE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702408340; a=rsa-sha256; cv=none; b=jZnFLVpGsjGWKNIwx+OsPo5T1BDTwbcLW62EOUJYpD/bvMdJavFUKXJXkUCgUSiId0BTzW c+aRo3E4lRNvg6tEbgNdSRnfTgaP0CH37RbfoQiJImTqVYQFINRjAsWxwlWjnH4oeVHlIT xdzOdF7kTZDvJ5qCJAEKS7/C/inqU98= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LRYglFPH; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 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 sin.source.kernel.org (Postfix) with ESMTP id 1C3FCCE1B96; Tue, 12 Dec 2023 19:12:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0459C433CA; Tue, 12 Dec 2023 19:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702408335; bh=DR2Fa3ovjeZyoem+oDl1suN899iJhJUC8UTSzsABCII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LRYglFPHtFeydr48Km9Sa9erA75e8UthD942v4D8hIgASGiY2dwkC4QPS0tMb9Gcr 9e2sSgB1CAt6n4QLv8UCVbDWbcOw6TbbftaAttRkPsNY82glveOXuyIzrqT3T85D8c isiteR6bbcdJbOmGNTNw4+eY0U/SNqwAnB2f0vaneU2EigtbDeED26FrMoPMcIEHwe 3vstJeiNPH1GEP96vBMXZ6C0hZ2L9Y1ZlrfwWCqZEFyUvc0HyyBG4a9plrX1lETL7F /QYp97YiJKgnXVIy0g5DDefUk3RrahxMjmtj6c4K/VEoC7nXueQd0yeepxcdwX0uHe Et1+MU2vMFUUw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] selftests/damon/_damon_sysfs: implement kdamonds start function Date: Tue, 12 Dec 2023 19:12:03 +0000 Message-Id: <20231212191206.52917-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212191206.52917-1-sj@kernel.org> References: <20231212191206.52917-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D5953140019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: p83mhoaa5xzwmgcgn6713mf6g6tqbckb X-HE-Tag: 1702408339-867582 X-HE-Meta: U2FsdGVkX1+QwijRgRdqYOHNnxZw2zfY80ef/qYRTJWZekPcLy2SdO9cZQL55g00Nw491c2lBtWQsCeQCa9JpkDUH1FU0wImBkD+rNTQdfKq5/uWKnyn81PulWx/xdFgy6gg92mwtBArNb8OxlK9jmdQv0uckA/9RzAz+eZ5GmksJhepT+H57xSOIAWTUBfS8tD5Kcre8nIX5Vk4dAPp8PAiy0LPKYeYui2zVboq+tWMkz5DebQgIXG6+VEGnRqj77LRUypd28ZVSGZCeA5J4TkZPSJ/aJ5szXybpoNXw1QOUUXyd9Sb1/hCfiDwS+XmZNqEJPxekMwryz+nZy5Ph4O9E4Xo0VXfSndxKxCofVtu5s9ioT+2RNFlM49GSTWBHaPsU/gzyPQVTDUrwUhmzUTm6cWr/s96n6dXg8MxjX2WP0AdYMwvv8WZ++eNSEKsXpUTECYxHP6n7ENct5ZJnmVcXifukYBJM0xatVIzImT3NOzOLBCWsAqWtLA5+iD1Lgx9Yy0dOxvj+W1EPtMTgcyi08AZ3wsoM6Z2MClyaK0lDkr3VHdahjPqzsNA/PcuSg5JMuOd25nvZNlOZ0azWHyPV4xrnN5SVCEc2FhPpNOC/BuGmKpItcudVgONpo4T3jLCNp/R8RJWTTN0fShr8Wyi+/rEZVNXPhs9iYkfS1Tce9JdWFkq3n6TsKQ8tEBnMRqlrOfCQfmxAkHBmDiaVcibFzuUJsqAAVanXYaK4plrIF3eoY/oByrBzk+Dq7NzaGkYbvO3uSScE29qxGT81zhr84+yPkLlDbWTci2J1maPEDQn+9cibdTmQAW0ms3xzk/j6ZOdIPAEMceiZKJpJQN5Fdg2EnrQ9oY1GZBY4on7YlOzObAR8BTFsKGLkpdmO1h8snoQFD5R7wtk+qpaHSRwa7SdRaUMTzj3yPCCul0uDTsYK3KPrB50vvz3PiCat+IcCDEF+VCDr6Ogg4U blFjpkiI UOQEYL+QpKT3oV1X/HL4H8j3aqby9XavwrX8zOgOe6Heqa338eIROfo0bI7Mj+tOJJpc7dmxyWbZ7RN3BBGYeiDN/tssP/+AdJYhxGK2bnGzedsNUOQcwgudWR/zGQN9eKC8yChF3rrvlgtGCg3obxH18LUgMlm1/xIewxTZ1z+jOuxau7o7GSPsRQ/N+TqwqHH+r3HYA+jtzHsL6sQztrDhBvCOv/p1PpbMjLMK2wi8yyRk01sjB0rcx8vyuJQv75KZiY3niiRXVW2rTy7adDUUsKdNpm8wu369r 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: Extend the tests-writing-purpose DAMON sysfs control module to support the kdamonds start functionality. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 206 ++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py index 78101846ab66..6b99f87a5f1e 100644 --- a/tools/testing/selftests/damon/_damon_sysfs.py +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -1,5 +1,28 @@ # SPDX-License-Identifier: GPL-2.0 +import os + +sysfs_root = '/sys/kernel/mm/damon/admin' + +def write_file(path, string): + "Returns error string if failed, or None otherwise" + string = '%s' % string + try: + with open(path, 'w') as f: + f.write(string) + except Exception as e: + return '%s' % e + return None + +def read_file(path): + '''Returns the read content and error string. The read content is None if + the reading failed''' + try: + with open(path, 'r') as f: + return f.read(), None + except Exception as e: + return None, '%s' % e + class DamosAccessPattern: size = None nr_accesses = None @@ -18,6 +41,35 @@ class DamosAccessPattern: if self.age == None: self.age = [0, 2**64 - 1] + def sysfs_dir(self): + return os.path.join(self.scheme.sysfs_dir(), 'access_pattern') + + def stage(self): + err = write_file( + os.path.join(self.sysfs_dir(), 'sz', 'min'), self.size[0]) + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'sz', 'max'), self.size[1]) + if err != None: + return err + err = write_file(os.path.join(self.sysfs_dir(), 'nr_accesses', 'min'), + self.nr_accesses[0]) + if err != None: + return err + err = write_file(os.path.join(self.sysfs_dir(), 'nr_accesses', 'max'), + self.nr_accesses[1]) + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'age', 'min'), self.age[0]) + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'age', 'max'), self.age[1]) + if err != None: + return err + class Damos: action = None access_pattern = None @@ -30,6 +82,39 @@ class Damos: self.access_pattern = access_pattern self.access_pattern.scheme = self + def sysfs_dir(self): + return os.path.join( + self.context.sysfs_dir(), 'schemes', '%d' % self.idx) + + def stage(self): + err = write_file(os.path.join(self.sysfs_dir(), 'action'), self.action) + if err != None: + return err + err = self.access_pattern.stage() + if err != None: + return err + + # disable quotas + err = write_file(os.path.join(self.sysfs_dir(), 'quotas', 'ms'), '0') + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'quotas', 'bytes'), '0') + if err != None: + return err + + # disable watermarks + err = write_file( + os.path.join(self.sysfs_dir(), 'watermarks', 'metric'), 'none') + if err != None: + return err + + # disable filters + err = write_file( + os.path.join(self.sysfs_dir(), 'filters', 'nr_filters'), '0') + if err != None: + return err + class DamonTarget: pid = None # todo: Support target regions if test is made @@ -39,6 +124,18 @@ class DamonTarget: def __init__(self, pid): self.pid = pid + def sysfs_dir(self): + return os.path.join( + self.context.sysfs_dir(), 'targets', '%d' % self.idx) + + def stage(self): + err = write_file( + os.path.join(self.sysfs_dir(), 'regions', 'nr_regions'), '0') + if err != None: + return err + return write_file( + os.path.join(self.sysfs_dir(), 'pid_target'), self.pid) + class DamonAttrs: sample_us = None aggr_us = None @@ -55,6 +152,40 @@ class DamonAttrs: self.min_nr_regions = min_nr_regions self.max_nr_regions = max_nr_regions + def interval_sysfs_dir(self): + return os.path.join(self.context.sysfs_dir(), 'monitoring_attrs', + 'intervals') + + def nr_regions_range_sysfs_dir(self): + return os.path.join(self.context.sysfs_dir(), 'monitoring_attrs', + 'nr_regions') + + def stage(self): + err = write_file(os.path.join(self.interval_sysfs_dir(), 'sample_us'), + self.sample_us) + if err != None: + return err + err = write_file(os.path.join(self.interval_sysfs_dir(), 'aggr_us'), + self.aggr_us) + if err != None: + return err + err = write_file(os.path.join(self.interval_sysfs_dir(), 'update_us'), + self.update_us) + if err != None: + return err + + err = write_file( + os.path.join(self.nr_regions_range_sysfs_dir(), 'min'), + self.min_nr_regions) + if err != None: + return err + + err = write_file( + os.path.join(self.nr_regions_range_sysfs_dir(), 'max'), + self.max_nr_regions) + if err != None: + return err + class DamonCtx: ops = None monitoring_attrs = None @@ -79,6 +210,46 @@ class DamonCtx: scheme.idx = idx scheme.context = self + def sysfs_dir(self): + return os.path.join(self.kdamond.sysfs_dir(), 'contexts', + '%d' % self.idx) + + def stage(self): + err = write_file( + os.path.join(self.sysfs_dir(), 'operations'), self.ops) + if err != None: + return err + err = self.monitoring_attrs.stage() + if err != None: + return err + + nr_targets_file = os.path.join( + self.sysfs_dir(), 'targets', 'nr_targets') + content, err = read_file(nr_targets_file) + if err != None: + return err + if int(content) != len(self.targets): + err = write_file(nr_targets_file, '%d' % len(self.targets)) + if err != None: + return err + for target in self.targets: + err = target.stage() + if err != None: + return err + + nr_schemes_file = os.path.join( + self.sysfs_dir(), 'schemes', 'nr_schemes') + content, err = read_file(nr_schemes_file) + if int(content) != len(self.schemes): + err = write_file(nr_schemes_file, '%d' % len(self.schemes)) + if err != None: + return err + for scheme in self.schemes: + err = scheme.stage() + if err != None: + return err + return None + class Kdamond: state = None pid = None @@ -92,6 +263,27 @@ class Kdamond: context.idx = idx context.kdamond = self + def sysfs_dir(self): + return os.path.join(self.kdamonds.sysfs_dir(), '%d' % self.idx) + + def start(self): + nr_contexts_file = os.path.join(self.sysfs_dir(), + 'contexts', 'nr_contexts') + content, err = read_file(nr_contexts_file) + if err != None: + return err + if int(content) != len(self.contexts): + err = write_file(nr_contexts_file, '%d' % len(self.contexts)) + if err != None: + return err + + for context in self.contexts: + err = context.stage() + if err != None: + return err + err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on') + return err + class Kdamonds: kdamonds = [] @@ -100,3 +292,17 @@ class Kdamonds: for idx, kdamond in enumerate(self.kdamonds): kdamond.idx = idx kdamond.kdamonds = self + + def sysfs_dir(self): + return os.path.join(sysfs_root, 'kdamonds') + + def start(self): + err = write_file(os.path.join(self.sysfs_dir(), 'nr_kdamonds'), + '%s' % len(self.kdamonds)) + if err != None: + return err + for kdamond in self.kdamonds: + err = kdamond.start() + if err != None: + return err + return None