From patchwork Tue Apr 26 20:38:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12827955 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 C3891C433FE for ; Tue, 26 Apr 2022 20:38:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B79C6B0074; Tue, 26 Apr 2022 16:38:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5666C6B0075; Tue, 26 Apr 2022 16:38:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BAD76B0078; Tue, 26 Apr 2022 16:38:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 287426B0074 for ; Tue, 26 Apr 2022 16:38:54 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 031B61106 for ; Tue, 26 Apr 2022 20:38:53 +0000 (UTC) X-FDA: 79400194188.03.0478B7E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 5488414003E for ; Tue, 26 Apr 2022 20:38:50 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 641E261331; Tue, 26 Apr 2022 20:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E726FC385AF; Tue, 26 Apr 2022 20:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651005531; bh=HHKeB02EgCdGBUKl47/DzUNIx/8bb6mqSCa+8N53rZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qk42HV6BFB3rbtCUB0gZoaOgEHm2n/PzxA7mbTRQdb+6IXCrRCSIU8hs23vE3A0Eh 8hLcjBP4FM4RstTEKPg+EX64pqapRr1LRpRt4x5QrWboE46evIra21scwK3jlSAeeV af6ur9taHVDHjUlk4kol/MjKP01cl8GvcwNmhvQdY1agWS5hYKr/bpWkQLtnpxNem2 D81bb7JC8sc+pvEhmX+ocrHA+iBIODe2P/GszZPjc7JMR7mHBfvDJ2LO8INUUGf0gL Uyc3+jl8Fay45kn08CSiuVOenaOszzpi64Ps0x7igL2YY9FAawqc6Nu3qouAm+QV7g vXk1L8doaCtBw== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 1/4] mm/damon/core: add a function for damon_operations registration checks Date: Tue, 26 Apr 2022 20:38:40 +0000 Message-Id: <20220426203843.45238-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426203843.45238-1-sj@kernel.org> References: <20220426203843.45238-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5488414003E X-Stat-Signature: ocp9hpsqkbq4uiyfdadkncnbxf5q9iyb Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Qk42HV6B; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspam-User: X-HE-Tag: 1651005530-715023 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: From: SeongJae Park To know if a specific 'damon_operations' is registered, users need to check the kernel config or try 'damon_select_ops()' with the ops of the question, and then see if it successes. In the latter case, the user should also revert the change. To make the process simple and convenient, this commit adds a function for checking if a specific 'damon_operations' is registered or not. Signed-off-by: SeongJae Park --- include/linux/damon.h | 1 + mm/damon/core.c | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index f23cbfa4248d..73ff0e2d2a4d 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -509,6 +509,7 @@ int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int, int damon_set_schemes(struct damon_ctx *ctx, struct damos **schemes, ssize_t nr_schemes); int damon_nr_running_ctxs(void); +bool damon_is_registered_ops(enum damon_ops_id id); int damon_register_ops(struct damon_operations *ops); int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id); diff --git a/mm/damon/core.c b/mm/damon/core.c index ca6124eb6516..5c1331f93c2e 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -30,7 +30,7 @@ static DEFINE_MUTEX(damon_ops_lock); static struct damon_operations damon_registered_ops[NR_DAMON_OPS]; /* Should be called under damon_ops_lock with id smaller than NR_DAMON_OPS */ -static bool damon_registered_ops_id(enum damon_ops_id id) +static bool __damon_is_registered_ops(enum damon_ops_id id) { struct damon_operations empty_ops = {}; @@ -39,6 +39,24 @@ static bool damon_registered_ops_id(enum damon_ops_id id) return true; } +/** + * damon_is_registered_ops() - Check if a given damon_operations is registered. + * @id: Id of the damon_operations to check if registered. + * + * Return: true if the ops is set, false otherwise. + */ +bool damon_is_registered_ops(enum damon_ops_id id) +{ + bool registered; + + if (id >= NR_DAMON_OPS) + return false; + mutex_lock(&damon_ops_lock); + registered = __damon_is_registered_ops(id); + mutex_unlock(&damon_ops_lock); + return registered; +} + /** * damon_register_ops() - Register a monitoring operations set to DAMON. * @ops: monitoring operations set to register. @@ -56,7 +74,7 @@ int damon_register_ops(struct damon_operations *ops) return -EINVAL; mutex_lock(&damon_ops_lock); /* Fail for already registered ops */ - if (damon_registered_ops_id(ops->id)) { + if (__damon_is_registered_ops(ops->id)) { err = -EINVAL; goto out; } @@ -84,7 +102,7 @@ int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id) return -EINVAL; mutex_lock(&damon_ops_lock); - if (!damon_registered_ops_id(id)) + if (!__damon_is_registered_ops(id)) err = -EINVAL; else ctx->ops = damon_registered_ops[id];