From: Divyesh Shah <dpshah@google.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, a.p.zijlstra@chello.nl, kenchen@google.com
Subject: [PATCH][RESEND] Export per-tid and per-tgid cputime in nanoseconds.
Date: Fri, 26 Feb 2010 18:03:48 -0800 [thread overview]
Message-ID: <20100227020242.1384.9945.stgit@austin.mtv.corp.google.com> (raw)
This can be used by applications to get finer granularity cputime usage on
platforms that use timestamp counters or HPET.
Signed-off-by: Divyesh Shah<dpshah@google.com>
---
fs/proc/array.c | 40 ++++++++++++++++++++++++++++++++++++++++
fs/proc/base.c | 2 ++
fs/proc/internal.h | 2 ++
3 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 13b5d07..54604b8 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -547,3 +547,43 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
return 0;
}
+
+static int do_task_cputime(struct task_struct *task, char * buffer, int whole)
+{
+ int res;
+ unsigned long flags;
+ unsigned long long sum_exec_runtime = 0;
+ struct task_struct *t;
+
+ if (lock_task_sighand(task, &flags)) {
+ if (whole) {
+ t = task;
+ /*
+ * Add up live thread sum_exec_runtime at the group
+ * level.
+ */
+ do {
+ sum_exec_runtime += t->se.sum_exec_runtime;
+ t = next_thread(t);
+ } while (t != task);
+ sum_exec_runtime += task->signal->sum_sched_runtime;
+ }
+ unlock_task_sighand(task, &flags);
+ }
+
+ if (!whole)
+ sum_exec_runtime = task->se.sum_exec_runtime;
+
+ res = sprintf(buffer,"%llu\n", sum_exec_runtime);
+ return res;
+}
+
+int proc_tid_cputime(struct task_struct *task, char * buffer)
+{
+ return do_task_cputime(task, buffer, 0);
+}
+
+int proc_tgid_cputime(struct task_struct *task, char * buffer)
+{
+ return do_task_cputime(task, buffer, 1);
+}
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 58324c2..8fbc785 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2595,6 +2595,7 @@ static const struct pid_entry tgid_base_stuff[] = {
REG("numa_maps", S_IRUGO, proc_numa_maps_operations),
#endif
REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations),
+ INF("cputime_ns", S_IRUGO, proc_tgid_cputime),
LNK("cwd", proc_cwd_link),
LNK("root", proc_root_link),
LNK("exe", proc_exe_link),
@@ -2930,6 +2931,7 @@ static const struct pid_entry tid_base_stuff[] = {
REG("numa_maps", S_IRUGO, proc_numa_maps_operations),
#endif
REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations),
+ INF("cputime_ns", S_IRUGO, proc_tid_cputime),
LNK("cwd", proc_cwd_link),
LNK("root", proc_root_link),
LNK("exe", proc_exe_link),
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 1f24a3e..f9e9799 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -51,6 +51,8 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task);
extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task);
+extern int proc_tid_cputime(struct task_struct *, char *);
+extern int proc_tgid_cputime(struct task_struct *, char *);
extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
extern const struct file_operations proc_maps_operations;
next reply other threads:[~2010-02-27 2:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-27 2:03 Divyesh Shah [this message]
2010-02-27 11:43 ` Peter Zijlstra
2010-03-01 15:44 ` Divyesh Shah
2010-03-01 18:05 ` Peter Zijlstra
2010-03-22 18:57 ` Divyesh Shah
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=20100227020242.1384.9945.stgit@austin.mtv.corp.google.com \
--to=dpshah@google.com \
--cc=a.p.zijlstra@chello.nl \
--cc=kenchen@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®