Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1217628pxb; Thu, 4 Feb 2021 07:41:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJygE4J6D1FMXTMa0O38gA71741xaplI4PrC60Ckjy74V/1Vu/vPKHraJQ2913vqk/c1/mOL X-Received: by 2002:a17:906:2a42:: with SMTP id k2mr8396512eje.118.1612453307212; Thu, 04 Feb 2021 07:41:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612453307; cv=none; d=google.com; s=arc-20160816; b=iPjw8f+pxJZj/3X2wCycVrT/iMuSzSMo2PJErnaIQ/6soNmP9qLjNXDL0dKmWCE3xM MAF45pQTCf39sivG1CVhXKxMB96T9rqYSEIdbrsTeYNKwOV8vBeKDnCLVwAahvKRNC2L /8b4pJmkw8b9ltIVB4b/X2ZhA5HOn4TzbUwzDaQ9FfxOoRHoNa5J6ueg3+7cybv6c577 h8Ij760ODi2JNE/XO5m9pnIflT4F4SDhsP4IwJBSnX2fDC5jm8qmujAd/mhwWHuZuFKD pU+vfzL6Fl57va3eiEC2MmRm+AYcSM7Z9pjgmTo7aYh7MjJSyUEcU8HXRCxU8g9EG0vv loWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GvQHGg8Fg9cuT3SeiFVEkCtDNQ9QA2fEAQ+quD3Tkys=; b=tXGIaK22S1gUXCrYnvubiJIUzuuL1HDXHZohZKvwz5boI5o5TKvq+fL3AV0ig2BzFN h/7AojEBjOcapqEjS6wzooOTo4C7qlmYt0Ff3N1dNhKuV3f3PW5d1pTW2PaXOD1mtsat A3WQNjdBYNzxEh/DNgfoPeTOtdKo64Fmxny8yPhWUwPGco5YFyUQpD/To4Vkouis7Wcz 0VAtgpddZjhpOfvaZduZSChYEEMGYg77GaVx380c8nJILY9kzGI7SDQal/dl7sA5x99X OfF0Knt3GsUQgwSM31j94bnY25EIBBS+i8BI0LZQ371rzxhDhxwMyPpLxP2NCyP2vqCA CVzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=SIQ+wTw5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si3528805edp.207.2021.02.04.07.41.20; Thu, 04 Feb 2021 07:41:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=SIQ+wTw5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237401AbhBDPjY (ORCPT + 99 others); Thu, 4 Feb 2021 10:39:24 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:59028 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237381AbhBDPgA (ORCPT ); Thu, 4 Feb 2021 10:36:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1612452959; x=1643988959; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=GvQHGg8Fg9cuT3SeiFVEkCtDNQ9QA2fEAQ+quD3Tkys=; b=SIQ+wTw5Lw5kofb4e6qhXLnDA7IE3S/ERP3ldjbqdRQwHHxsIERxmelD bmN7G5HFdN6EOEmA9XJzNf93c3VsKeqnkEN3eFHZmbK9v7wpfFzbQviR6 sHkUWm5Au/csq5a1jjT+A+dNyvVUlz2xyrejum+i6IWoPlm5zPS7CiU1n w=; X-IronPort-AV: E=Sophos;i="5.79,401,1602547200"; d="scan'208";a="115853146" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-af6a10df.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 04 Feb 2021 15:35:16 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1a-af6a10df.us-east-1.amazon.com (Postfix) with ESMTPS id 03125A1E24; Thu, 4 Feb 2021 15:35:03 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.146) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Feb 2021 15:34:47 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v24 09/14] mm/damon/dbgfs: Export kdamond pid to the user space Date: Thu, 4 Feb 2021 16:31:45 +0100 Message-ID: <20210204153150.15948-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210204153150.15948-1-sjpark@amazon.com> References: <20210204153150.15948-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.146] X-ClientProxiedBy: EX13D18UWA001.ant.amazon.com (10.43.160.11) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park For CPU usage accounting, knowing pid of the monitoring thread could be helpful. For example, users could use cpuaccount cgroups with the pid. This commit therefore exports the pid of currently running monitoring thread to the user space via 'kdamond_pid' file in the debugfs directory. Signed-off-by: SeongJae Park --- mm/damon/dbgfs.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index dce4409e5887..4b9ac2043e99 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -358,6 +358,32 @@ static ssize_t dbgfs_target_ids_write(struct file *file, return ret; } +static ssize_t dbgfs_kdamond_pid_read(struct file *file, + char __user *buf, size_t count, loff_t *ppos) +{ + struct damon_ctx *ctx = file->private_data; + char *kbuf; + ssize_t len; + + kbuf = kmalloc(count, GFP_KERNEL); + if (!kbuf) + return -ENOMEM; + + mutex_lock(&ctx->kdamond_lock); + if (ctx->kdamond) + len = scnprintf(kbuf, count, "%d\n", ctx->kdamond->pid); + else + len = scnprintf(kbuf, count, "none\n"); + mutex_unlock(&ctx->kdamond_lock); + if (!len) + goto out; + len = simple_read_from_buffer(buf, count, ppos, kbuf, len); + +out: + kfree(kbuf); + return len; +} + static int damon_dbgfs_open(struct inode *inode, struct file *file) { file->private_data = inode->i_private; @@ -386,11 +412,18 @@ static const struct file_operations target_ids_fops = { .write = dbgfs_target_ids_write, }; +static const struct file_operations kdamond_pid_fops = { + .owner = THIS_MODULE, + .open = damon_dbgfs_open, + .read = dbgfs_kdamond_pid_read, +}; + static int dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx) { - const char * const file_names[] = {"attrs", "record", "target_ids"}; + const char * const file_names[] = {"attrs", "record", "target_ids", + "kdamond_pid"}; const struct file_operations *fops[] = {&attrs_fops, &record_fops, - &target_ids_fops}; + &target_ids_fops, &kdamond_pid_fops}; int i; for (i = 0; i < ARRAY_SIZE(file_names); i++) { -- 2.17.1