Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3912157pxu; Tue, 20 Oct 2020 03:59:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylZwfsiOGEHoz2yS0r+q5LxIavjXjSqEQzvzUivyz9LyIJ9gkqm7ZpNeQQqZ0d7is5sngj X-Received: by 2002:a17:906:4b0f:: with SMTP id y15mr2444746eju.198.1603191574542; Tue, 20 Oct 2020 03:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603191574; cv=none; d=google.com; s=arc-20160816; b=Jcc1UkYb/CySKZ4r1EyJhhS0MF40OGZ1nGbB9AI5WW+xND2zrFuk11JvBUEO0uSVy3 apmtDOSpm9lPP0NSVKMd7mUFYyFRLczH91/M0PJZPFWnJa9DbM+X7+Up3OtkyjvIOIXz +WwCyNCAIerFzSzxwIKby3JTRgEHxvkHAXEh7ffXfFfd12WPLTM9Zh08sIJXMZJwltN+ s5d/NxfNcY1dJDFhIJDJmuDOIhBJhvRXL/NU+6xbbeEBxRcSLSCYl4tXWKpQE7daH2st 0UeFgKqcqW/daIQyWiqc+9xBw366mHM+8SmA5gK3z+GFMup6tqifcBhb3y+MTSQSEm7l 8ThA== 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=JsfFNZwGqOpvXiFV1LBG6WzEtB5PCi7m9BtzNbnD0XM=; b=DUPx6FGYhDbgHArbgxZUkn928wBnl4NR7OJnIEk7gpDfYKPSb31pd7O+P8HDwslNqy wG1czgy63yzxIVDVgV30OcRUvbaQEhip30LuAtrDafoypdlpe0e1K05pbZC4OUMAptbV IxnOSM8ZM1tnlL/ZB3NIkDdnU8VF4sxE7pG7RxprgNCyrrbU4cz6rbxS2xpdskkAhXiI K8AtOcDXt6xBUTNu1pVnN2+u2HhttbaGKPiBtuIp+/38tLJIkwU4XSqP1xS+rq9pgCpS wEDsgiMVRUYiLDvs7ipqtYnarStDIA5/JJnj6XUxUW0ZHd+j3IWrsHVYGNQ19y5zzqRk Zf4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ss+KC4X0; 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 x28si897900edi.543.2020.10.20.03.59.12; Tue, 20 Oct 2020 03:59:34 -0700 (PDT) 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=ss+KC4X0; 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 S2392289AbgJTJFz (ORCPT + 99 others); Tue, 20 Oct 2020 05:05:55 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:60251 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390557AbgJTJFy (ORCPT ); Tue, 20 Oct 2020 05:05:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1603184754; x=1634720754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=JsfFNZwGqOpvXiFV1LBG6WzEtB5PCi7m9BtzNbnD0XM=; b=ss+KC4X0pecLuf2IUj3Ap9zq4uOpj0EruDEes0bMMVhecgqzW1RA73Tj XfnXvZzg0DNU5M/3DfEUgS7iB4V7e+SXu7PC8Saw2CMVR4XgXdDKoj8Lw 7cn19kfvfnPQPVzVHqMfMvkwBMgR9o452lvf/rO6vc4CtgqqcgoFjPimL c=; X-IronPort-AV: E=Sophos;i="5.77,396,1596499200"; d="scan'208";a="78103905" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 20 Oct 2020 09:05:54 +0000 Received: from EX13D31EUB001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id C054CA1C53; Tue, 20 Oct 2020 09:05:50 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.237) by EX13D31EUB001.ant.amazon.com (10.43.166.210) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 20 Oct 2020 09:05:30 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v22 12/18] mm/damon/dbgfs: Export kdamond pid to the user space Date: Tue, 20 Oct 2020 10:59:34 +0200 Message-ID: <20201020085940.13875-13-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201020085940.13875-1-sjpark@amazon.com> References: <20201020085940.13875-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.237] X-ClientProxiedBy: EX13D41UWC001.ant.amazon.com (10.43.162.107) To EX13D31EUB001.ant.amazon.com (10.43.166.210) 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 5aac85de23d2..94ed2eca2510 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -369,6 +369,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; @@ -397,11 +423,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