Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3310412pxu; Tue, 15 Dec 2020 04:05:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/1b5X7t45AqKg1xGyh2HzMANoDjIowDh7xhz9hnUBUdRRSoK3R+BGyzQtyY7aDSu9q78F X-Received: by 2002:a17:906:5386:: with SMTP id g6mr21637551ejo.137.1608033956691; Tue, 15 Dec 2020 04:05:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608033956; cv=none; d=google.com; s=arc-20160816; b=09k1NbTEfOsjeM3cHh2ywGJcZfxoAp9DhuYxyqqsnHdswpM7yONl36uPZ/4WXp0QqB i3j+mXerWgHpJ2zIzXd+1Joe1xWze4L7NNHhDReNCrwXpZJJQFRsh7sYQNwEzUnUpSCB wtj8fiMALXHl0f570V7EdKSpdLTGE7EMdWP03oh/r1aR0NJgUpichCYlBZqY4sosMdHl 8qXousygxvnD9xouN1U404+Vqe6Y0wQstKAfp5h7QTpeh5IMXtf7EPyd8a/ZYedUgN6H qs8TVY6BcYMEuxkmBf1XF9n4narCoERlYF9Np4dcvjz+VgePwqKUnXMFkHsmtGQ17+9W E79g== 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=tYuImZATeZ5BU9vyZ/5gMK7OI/H0skCjpeJLNRGvwog=; b=KRnKsXAIzYcVv6cBnWO8K7ryoWXu7yHZRZqtMyfQBEBpgWAZt2XqP94DPyV9EqcWHz yumt+MZjzsDrVDnvqqo+LG8SSwejxoKRx66q1zSkd0CKKMOU+KiYousKjZH1JWp5ILGX qUwYyVSPC/box73x5IZkOnGjKioiC9w2LOOehsFiEipPP0AhjqOOUijFt59+xVO7j7rt 1ZodOjzAo0c61TKlXekBTOXA3NgYMM8bDCqvOkSRqxfXDqAdK54eDF55gbP/Mco7zHh2 NpPls6dE2NsOSBxN8S0rsbHOUcsGayoJ2B4X7tvDn7psVGlDyAMecYJQgiYulnLKpTd/ 18OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=KGYpDQmf; 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 b26si726699ejz.630.2020.12.15.04.05.32; Tue, 15 Dec 2020 04:05:56 -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=KGYpDQmf; 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 S1728494AbgLOMBS (ORCPT + 99 others); Tue, 15 Dec 2020 07:01:18 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:16725 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbgLOMAq (ORCPT ); Tue, 15 Dec 2020 07:00:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608033646; x=1639569646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=tYuImZATeZ5BU9vyZ/5gMK7OI/H0skCjpeJLNRGvwog=; b=KGYpDQmf8/P9SvuCdXMrcr8bFsooj/pHLJe7SoxItkOxxOt/os0d6yw/ FDTZJQ/Heccf1J+TC152SGuFMdJrJyCEXi4HLmHQqgLGxiRSbomH9ykXC 0IB18xFiO8z+qFXNZqRapL7JRiDtWcZQnnZGeJ/l+iot3octfOpbqGMnq A=; X-IronPort-AV: E=Sophos;i="5.78,420,1599523200"; d="scan'208";a="72726859" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-16425a8d.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 15 Dec 2020 12:00:06 +0000 Received: from EX13D31EUA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-1d-16425a8d.us-east-1.amazon.com (Postfix) with ESMTPS id 79167101104; Tue, 15 Dec 2020 11:59:53 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.252) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 15 Dec 2020 11:59:36 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v23 09/15] mm/damon/dbgfs: Export kdamond pid to the user space Date: Tue, 15 Dec 2020 12:54:42 +0100 Message-ID: <20201215115448.25633-10-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201215115448.25633-1-sjpark@amazon.com> References: <20201215115448.25633-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.252] X-ClientProxiedBy: EX13D33UWC002.ant.amazon.com (10.43.162.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 733d2f3e646e..a1512d3e5afe 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -337,6 +337,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; @@ -365,11 +391,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