From patchwork Wed Nov 13 16:26:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13873998 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 45321D462D0 for ; Wed, 13 Nov 2024 16:26:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B53A6B009D; Wed, 13 Nov 2024 11:26:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 360F26B00A0; Wed, 13 Nov 2024 11:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2040C6B00AB; Wed, 13 Nov 2024 11:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 020CC6B009D for ; Wed, 13 Nov 2024 11:26:33 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ABEAD140BCC for ; Wed, 13 Nov 2024 16:26:33 +0000 (UTC) X-FDA: 82781599404.02.066A332 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 24FD0C0020 for ; Wed, 13 Nov 2024 16:25:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="o1/agY4m"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731515062; a=rsa-sha256; cv=none; b=2SroM9AjiTzskqP+ARRdYv/5Qt2YYvGkHFtcjonLDp6QxTCZfY0I2FhN17M91xzf/x62d+ i/74mWaiBcRI4eq5etC8BfIntFrRcPsT7298XPnd4Uz8cXQlesTw9NLG4QfxPBydbWYzsZ NctYgOcHGKQ90R8376p60TAp7hB5QUA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="o1/agY4m"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731515062; 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=HZwQtdqqdVsLGqaVZ9sRV3Acq7QAqpRdBrtcWh/BJJI=; b=DX66Tn619/UYzTHMW/hhsA2V4cvM9Dno7FnoBTF9RXO25WBuvEZ220l87KAZSab/8LBPM7 pygwVdM0+taRVv2h8tv/Zdy9aCE9irOopuKZv492B6kFfZDN1j+j4RZCLXMdgxkgp2ByLI Y1wStzRnnv4h+CpWS26FS0d4rDkFUhA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 022B15C58BD; Wed, 13 Nov 2024 16:25:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D835AC4CECF; Wed, 13 Nov 2024 16:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515191; bh=6Kv8j6GXmb5OgoQ5xsiPf6fy1wOOGSi9iB0lHZRsXOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1/agY4mtPOWPXWZBhVsqgjbwv8NMsbuCUP2I9qvZ5wF/90hlRy8DhVmtSg7OSDku pyz5low1w7vWU5yo3CU8zLSdJN1o8MSsS3I2p2hjntM+ji1MCf6jxv/FGD3c9WR45R nlkG1pMI5X2xqnwEOgSI4x4QVzEztAoLpK7iZ/PDyGTg4wx1D3TikN6WqGsS5c4IJm Hn9QIr+XYSv+fITSvjfkqh4pNORtFhSDmsXJ2zNlfaYhYlWX8EDv7UVUUKnCTkB6tK ghKzb432jDLcwBmImZJ48ywfO1qpdiQ6Q/rkxubKlBHBadv0EAxiruqVgFSCQzleZE Jrm7ClSIAvi4g== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 2/5] samples/damon/wsse: implement DAMON starting and stopping Date: Wed, 13 Nov 2024 08:26:21 -0800 Message-Id: <20241113162624.48973-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 24FD0C0020 X-Stat-Signature: s7j9imtyg6s57hye3mkwrbqda59ts9ku X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731515147-276868 X-HE-Meta: U2FsdGVkX18JAq8Lk3sqG8B5G4QScHVyWQoCsp0nYbTJ9Fz/q7Mqul89kgahM6+RPdOV4v/gbCBhi5AoG/6P5LQzoC6L/n2c/QTqQJ8MWOPPT5ckX7aniISkHhBQLRO9xGsvVtGecNLY3WIIFd2XcEe3S+ZpKKMNgqVE5o/qTKXGB/T+KVof9eQwJ3b3Y34PSy3vs0We6840wbhm9OMHymxuUmityIPFsrY2dTdP2K6EJ4OVorkbN1qLiXutPifagq6sLzcwWgWIbjpD7nfUPOn+tQiANvYo5ks6BcS0RxndNPcGa8rU1StiGZbdtOfkR+G9aj7kRYg0hgvqs3u04JnLHRdia4VGiVjqhqEufm9qre2PWgfyb92/M8DZOW+jQ9VIu29Vf7WENs+Buef346GPf8cjoKva5abFMyO7nIEVHrsyiBv7kfdkEX9qFX0GkLPcbk+uwg57GdmoOioSC+anc8/kWDiqOxibfEBtm+clZHGkYU8yFlhyfnWBAmhUIOyzOGXe34dsiXHPYpaK1JLkAYP8DsO9uxN5zHsGlxEeB6HGifpzKUsn2mIwXTJsYuFx4klnkQi5HOqo+z9QB/2Ut+SoDkOcM9/vjufzGHxKqasHmOV03a+EjrFTlsn6g2vUGpPNs8uANTk/YWwze2MztYhJy98rtvSKqiC/hH/ib+iwq3wxTIS+SoaGXj0qP4VhSspYPaFz1FeHsbH4UorVhtVIu3dyE3mRDE1jN1jJXVdpNED6uIfglNsiqyTBnbm/jgk18LTQbwLbwW5n0BXKS43nuBsoUdMihaILeH5QsxOG20/NQ8f+0K8eOVGlL6VKKcQH9O/At1yeCEPLmAmKYaBR35//YEkp8lNHTz0fBnIxikJrCtNC+nCg/Vz7NRnLv0xuYdvbxY1AOQ3ptYmbJ+gEQZ7hjRNJ33aqwDi4kTHHy3zGBgURAHXbHRTgkj9RnIH4Kpm2ms6AX8f 6xIsG3Ix h98EAMVSEFDMrme+7wcAiGY++3TYfoRNyUW3mBeZclSUbv3K9QbWGtXDrkY/BwwY6VUegZQW698VgMJl7bSjDxF7GOwdWBgdNp6EqUIfLsACPkO25BY2vhAxwr9z51nhZdlWMRF2+jiMgKQbZASajyBx/BjXavhYtdwvgWP7asWrv5V0BwUlzEfPbDE0Dg8dyoS+kdYpQcDns2n5CeBAx6WlH4a+Yogz1LkbeS9TKQSTBXaU= 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: Start running DAMON for the process that user requested to estimate the process via 'pid' parameter, when 'y' is passed to 'enable' parameter. If 'n' is passed, stop running DAMON. Iterating the DAMON monitoring results and estimating the working set side is not yet implemented. It will be implemented by the following commit. Signed-off-by: SeongJae Park --- samples/damon/wsse.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 5912f15181c8..119ac8a2c901 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -27,15 +27,48 @@ static bool enable __read_mostly; module_param_cb(enable, &enable_param_ops, &enable, 0600); MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE_WSSE"); +static struct damon_ctx *ctx; +static struct pid *target_pidp; + static int damon_sample_wsse_start(void) { + struct damon_target *target; + pr_info("start\n"); - return 0; + + ctx = damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target = damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp = find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid = target_pidp; + + return damon_start(&ctx, 1, true); } static void damon_sample_wsse_stop(void) { pr_info("stop\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + if (target_pidp) + put_pid(target_pidp); } static int damon_sample_wsse_enable_store(