From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
To: Shailabh Nagar <nagar1234@in.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Venkatesh Pallipadi <venki@google.com>,
Suresh Siddha <suresh.b.siddha@intel.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@elte.hu>, Oleg Nesterov <oleg@redhat.com>,
John stultz <johnstul@us.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Roland McGrath <roland@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [RFC][PATCH v2 2/7] taskstats: Add "/proc/taskstats"
Date: Thu, 11 Nov 2010 18:03:54 +0100 [thread overview]
Message-ID: <20101111170814.229165018@linux.vnet.ibm.com> (raw)
In-Reply-To: 20101111170352.732381138@linux.vnet.ibm.com
[-- Attachment #1: 02-taskstats-top-proc.patch --]
[-- Type: text/plain, Size: 5790 bytes --]
From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
CHANGE HISTORY OF THIS PATCH
----------------------------
Version 2
---------
Replace ioctl interface with write interface (requested by Andrew Morton)
The taskstats command is now set by one sys_write() with a buffer that
contains first the taskstats command number (32 bit) and directly after that
number the command payload.
DESCRIPTION
-----------
Add procfs interface for the TASKSTATS_CMD_ATTR_PIDS taskstats command. A new
procfs file "/proc/taskstats" is introduced. With sys_write() the taskstats
command is defined. With a subsequent read system call the defined command
is executed and the result of the command is transferred into the read buffer.
This allows to get a complete and consistent snapshot with all tasks via two
system calls (write + read), when a sufficiently large buffer is provided.
This is not possible with the existing netlink interface, because there we
have the socket buffer size as restricting factor.
GOALS OF THIS PATCH
-------------------
* Allow transfer of a complete and consistent taskstats snapshot to user space.
* Reduce CPU time for data transmission compared to netlink mechanism,
because the proc solution is much more lightweight.
* User space code is much easier to write compared to netlink mechanism.
OPEN ISSUES
-----------
Currently only the TASKSTATS_CMD_ATTR_PIDS command is implemented. Implement
the following missing taskstasts commands:
* TASKSTATS_CMD_ATTR_PID
* TASKSTATS_CMD_ATTR_TGID
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
include/linux/taskstats_kern.h | 3 +
kernel/Makefile | 3 -
kernel/taskstats.c | 1
kernel/taskstats_proc.c | 107 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 113 insertions(+), 1 deletion(-)
--- a/include/linux/taskstats_kern.h
+++ b/include/linux/taskstats_kern.h
@@ -32,6 +32,7 @@ extern void taskstats_fill_atomic(struct
struct taskstats *stats);
extern void taskstats_fill_sleep(struct task_struct *tsk,
struct taskstats *stats);
+extern void taskstats_proc_init(void);
#else
static inline void taskstats_exit(struct task_struct *tsk, int group_dead)
{}
@@ -39,6 +40,8 @@ static inline void taskstats_tgid_free(s
{}
static inline void taskstats_init_early(void)
{}
+static inline void taskstats_proc_init(void)
+{}
#endif /* CONFIG_TASKSTATS */
#endif
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -90,7 +90,8 @@ obj-$(CONFIG_TINY_PREEMPT_RCU) += rcutin
obj-$(CONFIG_RELAY) += relay.o
obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
-obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o taskstats_snap.o
+obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o taskstats_snap.o \
+ taskstats_proc.o
obj-$(CONFIG_TRACEPOINTS) += tracepoint.o
obj-$(CONFIG_LATENCYTOP) += latencytop.o
obj-$(CONFIG_BINFMT_ELF) += elfcore.o
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -733,6 +733,7 @@ static int __init taskstats_init(void)
rc = genl_register_ops(&family, &cgroupstats_ops);
if (rc < 0)
goto err_cgroup_ops;
+ taskstats_proc_init();
family_registered = 1;
printk("registered taskstats version %d\n", TASKSTATS_GENL_VERSION);
return 0;
--- /dev/null
+++ b/kernel/taskstats_proc.c
@@ -0,0 +1,107 @@
+/*
+ * taskstats_proc.c - Export per-task statistics to userland using procfs
+ *
+ * Copyright IBM Corp. 2010
+ * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
+ */
+
+#include <linux/taskstats_kern.h>
+#include <linux/proc_fs.h>
+#include <linux/kernel.h>
+#include <linux/file.h>
+#include <asm/uaccess.h>
+
+struct proc_cmd {
+ u32 no;
+ union {
+ struct taskstats_cmd_pids cmd_pids;
+ u32 pid;
+ } d;
+};
+
+static ssize_t cmd_attr_pids_proc(struct taskstats *stats_vec,
+ struct taskstats_cmd_pids *cmd_pids)
+{
+ int rc;
+
+ rc = taskstats_snap_user(cmd_pids->pid, cmd_pids->cnt,
+ cmd_pids->time_ns, stats_vec);
+ if (rc < 0)
+ return rc;
+ else
+ return rc * sizeof(struct taskstats);
+}
+
+static int proc_taskstats_open(struct inode *inode, struct file *file)
+{
+ struct proc_cmd *proc_cmd;
+
+ proc_cmd = kmalloc(sizeof(*proc_cmd), GFP_KERNEL);
+ if (!proc_cmd)
+ return -ENOMEM;
+ proc_cmd->no = -1;
+ file->private_data = proc_cmd;
+ return 0;
+}
+
+static int proc_taskstats_close(struct inode *inode, struct file *file)
+{
+ kfree(file->private_data);
+ return 0;
+}
+
+static ssize_t proc_taskstats_write(struct file *file,
+ const char __user *buf, size_t count,
+ loff_t *ppos)
+{
+ struct proc_cmd *proc_cmd = file->private_data;
+ u32 no;
+
+ if (*ppos != 0)
+ return -EINVAL;
+ if (count < sizeof(no))
+ return -EINVAL;
+ if (copy_from_user(&no, buf, sizeof(no)))
+ return -EFAULT;
+ switch (no) {
+ case TASKSTATS_CMD_ATTR_PIDS:
+ if (count - sizeof(no) < sizeof(proc_cmd->d.cmd_pids))
+ return -EINVAL;
+ if (copy_from_user(&proc_cmd->d.cmd_pids, buf + sizeof(no),
+ sizeof(proc_cmd->d.cmd_pids)))
+ return -EFAULT;
+ break;
+ default:
+ return -EINVAL;
+ }
+ proc_cmd->no = no;
+ return count;
+}
+
+static ssize_t proc_taskstats_read(struct file *file, char __user *buf,
+ size_t size, loff_t *ppos)
+{
+ struct proc_cmd *proc_cmd = file->private_data;
+
+ if (*ppos != 0)
+ return -EINVAL;
+ switch (proc_cmd->no) {
+ case TASKSTATS_CMD_ATTR_PIDS:
+ return cmd_attr_pids_proc((struct taskstats *) buf,
+ &proc_cmd->d.cmd_pids);
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct file_operations proc_taskstats_ops = {
+ .open = proc_taskstats_open,
+ .release = proc_taskstats_close,
+ .read = proc_taskstats_read,
+ .write = proc_taskstats_write,
+};
+
+void __init taskstats_proc_init(void)
+{
+ proc_create("taskstats", 0666, NULL, &proc_taskstats_ops);
+}
next prev parent reply other threads:[~2010-11-11 17:03 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-11 17:03 [RFC][PATCH v2 0/7] taskstats: Enhancements for precise process accounting (version 2) Michael Holzheu
2010-11-11 17:03 ` [RFC][PATCH v2 1/7] taskstats: Add new taskstats command TASKSTATS_CMD_ATTR_PIDS Michael Holzheu
2010-11-13 19:20 ` Peter Zijlstra
2010-11-15 15:53 ` Michael Holzheu
2010-11-15 16:06 ` Peter Zijlstra
2010-11-15 17:09 ` Michael Holzheu
2010-11-15 17:21 ` Peter Zijlstra
2010-11-16 12:16 ` Michael Holzheu
2010-11-16 12:36 ` Peter Zijlstra
2010-11-13 19:39 ` Peter Zijlstra
2010-11-13 20:00 ` Balbir Singh
2010-11-15 14:50 ` Michael Holzheu
2010-11-11 17:03 ` Michael Holzheu [this message]
2010-11-11 17:03 ` [RFC][PATCH v2 3/7] taskstats: Add thread group ID to taskstats structure Michael Holzheu
2010-11-11 17:03 ` [RFC][PATCH v2 4/7] taskstats: Add per task steal time accounting Michael Holzheu
2010-11-13 19:38 ` Peter Zijlstra
2010-11-15 14:50 ` Martin Schwidefsky
2010-11-15 15:11 ` Peter Zijlstra
2010-11-15 17:42 ` Martin Schwidefsky
2010-11-15 17:45 ` Peter Zijlstra
2010-11-15 17:47 ` Peter Zijlstra
2010-11-15 17:48 ` Peter Zijlstra
2010-11-15 17:50 ` Peter Zijlstra
2010-11-15 17:59 ` Martin Schwidefsky
2010-11-15 18:08 ` Peter Zijlstra
2010-11-16 8:51 ` Martin Schwidefsky
2010-11-16 12:16 ` Peter Zijlstra
2010-11-16 15:33 ` Martin Schwidefsky
2010-11-16 15:45 ` Peter Zijlstra
2010-11-16 16:05 ` Martin Schwidefsky
2010-11-16 18:39 ` Jeremy Fitzhardinge
2010-11-16 16:38 ` Avi Kivity
2010-11-16 16:43 ` Peter Zijlstra
2010-11-16 16:56 ` Avi Kivity
2010-11-16 17:06 ` Avi Kivity
2010-11-11 17:03 ` [RFC][PATCH v2 5/7] taskstats: Improve cumulative CPU " Michael Holzheu
2010-11-13 18:38 ` Oleg Nesterov
2010-11-15 15:55 ` Martin Schwidefsky
2010-11-15 16:03 ` Peter Zijlstra
2010-11-15 17:49 ` Martin Schwidefsky
2010-11-15 17:51 ` Peter Zijlstra
2010-11-15 18:00 ` Martin Schwidefsky
2010-11-15 18:10 ` Peter Zijlstra
2010-11-16 8:54 ` Martin Schwidefsky
2010-11-16 16:57 ` Michael Holzheu
2010-11-18 17:10 ` Oleg Nesterov
2010-11-19 19:46 ` Michael Holzheu
2010-11-16 17:34 ` Michael Holzheu
2010-11-16 17:50 ` Oleg Nesterov
2010-11-18 16:34 ` Oleg Nesterov
2010-11-11 17:03 ` [RFC][PATCH v2 6/7] taskstats: Fix accounting for non-leader thread exec Michael Holzheu
2010-11-11 17:11 ` [RFC][PATCH v2 7/7] taskstats: Precise process accounting user space Michael Holzheu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101111170814.229165018@linux.vnet.ibm.com \
--to=holzheu@linux.vnet.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nagar1234@in.ibm.com \
--cc=oleg@redhat.com \
--cc=roland@redhat.com \
--cc=schwidefsky@de.ibm.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
--cc=venki@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).