All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shailabh Nagar <nagar@watson.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	elsa-devel <elsa-devel@lists.sourceforge.net>,
	LSE <lse-tech@lists.sourceforge.net>,
	ckrm-tech <ckrm-tech@lists.sourceforge.net>
Subject: [Patch 5/6] Delay accounting: /proc interface
Date: Tue, 03 Jan 2006 23:31:40 +0000	[thread overview]
Message-ID: <43BB095C.5000809@watson.ibm.com> (raw)
In-Reply-To: <43BB05D8.6070101@watson.ibm.com>

Changes since 12/7/05
- Return per-tgid stats as sum of constituent tid data
- for cpu running time, use tsk->sched_info.cpu_time (collected by schedstats)

12/07/05: First post

delayacct-procfs.patch

Creates /proc/<pid>/delay interface for getting delay and cpu statistics
for tasks. The cpu stats are available (non-zero) only if CONFIG_SCHEDSTATS
is enabled.

Signed-off-by: Shailabh Nagar <nagar@watson.ibm.com>

 fs/proc/array.c    |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/proc/base.c     |   21 +++++++++++++++-
 fs/proc/internal.h |    2 +
 3 files changed, 90 insertions(+), 1 deletion(-)

Index: linux-2.6.15-rc7/fs/proc/array.c
===================================================================
--- linux-2.6.15-rc7.orig/fs/proc/array.c
+++ linux-2.6.15-rc7/fs/proc/array.c
@@ -488,3 +488,71 @@ int proc_pid_statm(struct task_struct *t
 	return sprintf(buffer,"%d %d %d %d %d %d %d\n",
 		       size, resident, shared, text, lib, data, 0);
 }
+
+#ifdef CONFIG_TASK_DELAY_ACCT
+int proc_pid_delay(struct task_struct *task, char * buffer)
+{
+	unsigned long long run_delay, run_time;
+	unsigned long run_count;
+
+#ifdef CONFIG_SCHEDSTATS
+	run_count = task->sched_info.pcnt ;
+	run_time = jiffies_to_usecs(task->sched_info.cpu_time)*1000;
+	run_delay = jiffies_to_usecs(task->sched_info.run_delay)*1000;
+#else
+	/* Non-zero values, zero count indicates data not collected */
+	run_count = 0;
+	run_time = run_delay = 1;
+#endif
+	return sprintf(buffer,"%lu %llu %llu %u %llu %u %llu\n",
+		       run_count, (uint64_t) run_time, (uint64_t) run_delay,
+		       (unsigned int) task->delays.blkio_count,
+		       (uint64_t) task->delays.blkio_delay,
+		       (unsigned int) task->delays.swapin_count,
+		       (uint64_t) task->delays.swapin_delay);
+}
+
+/*
+ * Sum up delay stats for tid's of the tgid
+ * For any delay stat, a zero delay and non-zero count indicates overflow
+ *
+ */
+int proc_tgid_delay(struct task_struct *task, char * buffer)
+{
+	uint64_t run_time = 0, run_delay = 0, run_count = 0;
+	uint64_t blkio_delay = 0, blkio_count = 0;
+	uint64_t swapin_delay = 0, swapin_count = 0, tmp;
+	struct task_struct *t = task;
+
+	read_lock(&tasklist_lock);
+	do {
+#ifdef CONFIG_SCHEDSTATS
+		run_count += t->sched_info.pcnt;
+		tmp = run_time + jiffies_to_usecs(t->sched_info.cpu_time)*1000;
+		run_time = (tmp < run_time)? 0:tmp ;
+		tmp = run_delay + jiffies_to_usecs(t->sched_info.run_delay)*1000;
+		run_delay = (tmp < run_delay)? 0:tmp;
+#else
+		/* Non-zero values, zero count indicates data not collected */
+		run_count = 0;
+		run_time = run_delay = 1;
+#endif
+		spin_lock(&t->delays.lock);
+		tmp = blkio_delay + t->delays.blkio_delay;
+		blkio_delay = (tmp < blkio_delay)? 0:tmp ;
+		tmp = swapin_delay + t->delays.swapin_delay;
+		swapin_delay = (tmp < swapin_delay)? 0:tmp ;
+		blkio_count += t->delays.blkio_count;
+		swapin_count += t->delays.swapin_count;
+		spin_unlock(&t->delays.lock);
+
+	} while_each_thread(task, t);
+	read_unlock(&tasklist_lock);
+
+	return sprintf(buffer,"%llu %llu %llu %llu %llu %llu %llu\n",
+		       run_count, run_time, run_delay,
+		       blkio_count, blkio_delay,
+		       swapin_count, swapin_delay);
+}
+
+#endif
Index: linux-2.6.15-rc7/fs/proc/base.c
===================================================================
--- linux-2.6.15-rc7.orig/fs/proc/base.c
+++ linux-2.6.15-rc7/fs/proc/base.c
@@ -165,7 +165,10 @@ enum pid_directory_inos {
 #endif
 	PROC_TID_OOM_SCORE,
 	PROC_TID_OOM_ADJUST,
-
+#ifdef CONFIG_TASK_DELAY_ACCT
+        PROC_TID_DELAY_ACCT,
+        PROC_TGID_DELAY_ACCT,
+#endif
 	/* Add new entries before this */
 	PROC_TID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
 };
@@ -220,6 +223,9 @@ static struct pid_entry tgid_base_stuff[
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+#ifdef CONFIG_TASK_DELAY_ACCT
+	E(PROC_TGID_DELAY_ACCT,"delay",   S_IFREG|S_IRUGO),
+#endif
 	{0,0,NULL,0}
 };
 static struct pid_entry tid_base_stuff[] = {
@@ -262,6 +268,9 @@ static struct pid_entry tid_base_stuff[]
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
+#ifdef CONFIG_TASK_DELAY_ACCT
+	E(PROC_TID_DELAY_ACCT,"delay",   S_IFREG|S_IRUGO),
+#endif
 	{0,0,NULL,0}
 };

@@ -1786,6 +1795,16 @@ static struct dentry *proc_pident_lookup
 			inode->i_fop = &proc_loginuid_operations;
 			break;
 #endif
+#ifdef CONFIG_TASK_DELAY_ACCT
+		case PROC_TID_DELAY_ACCT:
+			inode->i_fop = &proc_info_file_operations;
+			ei->op.proc_read = proc_pid_delay;
+			break;
+		case PROC_TGID_DELAY_ACCT:
+			inode->i_fop = &proc_info_file_operations;
+			ei->op.proc_read = proc_tgid_delay;
+			break;
+#endif
 		default:
 			printk("procfs: impossible type (%d)",p->type);
 			iput(inode);
Index: linux-2.6.15-rc7/fs/proc/internal.h
===================================================================
--- linux-2.6.15-rc7.orig/fs/proc/internal.h
+++ linux-2.6.15-rc7/fs/proc/internal.h
@@ -36,6 +36,8 @@ extern int proc_tid_stat(struct task_str
 extern int proc_tgid_stat(struct task_struct *, char *);
 extern int proc_pid_status(struct task_struct *, char *);
 extern int proc_pid_statm(struct task_struct *, char *);
+extern int proc_pid_delay(struct task_struct *, char*);
+extern int proc_tgid_delay(struct task_struct *, char*);

 static inline struct task_struct *proc_task(struct inode *inode)
 {

  parent reply	other threads:[~2006-01-03 23:32 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-03 23:16 [Patch 0/6] Per-task delay accounting Shailabh Nagar
2006-01-03 23:23 ` [Patch 1/6] Delay accounting: timespec diff Shailabh Nagar
2006-01-03 23:26 ` [Patch 2/6] Delay accounting: Initialization, kernel boot option Shailabh Nagar
2006-01-03 23:28 ` [Patch 3/6] Delay accounting: Sync block I/O delays Shailabh Nagar
2006-01-03 23:30 ` [Patch 4/6] Delay accounting: Swap in delays Shailabh Nagar
2006-01-03 23:31 ` Shailabh Nagar [this message]
2006-01-03 23:33 ` [Patch 6/6] Delay accounting: Connector interface Shailabh Nagar
2006-01-04  0:21   ` Greg KH
2006-01-04  0:42     ` Shailabh Nagar
2006-01-04  0:51       ` Greg KH
2006-01-04  7:49         ` [Lse-tech] " Shailabh Nagar
2006-01-04 19:04   ` Jay Lan
2006-01-04 21:31     ` Shailabh Nagar
2006-01-04 22:40     ` [ckrm-tech] " Matt Helsley
2006-01-04 23:17       ` Andrew Morton
2006-01-05 18:42         ` [PATCH 00/01] Move Exit Connectors Matt Helsley
2006-01-05 19:17           ` [PATCH 01/01][RFC] " Matt Helsley
2006-01-05 19:20           ` [PATCH 00/01] " Matt Helsley
2006-01-05 23:10             ` Andrew Morton
2006-01-06  0:06               ` [ckrm-tech] " Matt Helsley
2006-01-06  8:57                 ` [Lse-tech] " Jes Sorensen
2006-01-06 16:45                   ` Shailabh Nagar
2006-01-11 10:36                     ` Jes Sorensen
2006-01-11 12:56                       ` John Hesterberg
2006-01-11 13:50                         ` Jes Sorensen
2006-01-11 21:02                       ` Matt Helsley
2006-01-11 21:39                         ` John Hesterberg
2006-01-11 22:42                           ` Matt Helsley
2006-01-12 10:01                             ` Jes Sorensen
2006-01-12 23:20                               ` Matt Helsley
2006-01-13  9:35                                 ` Jes Sorensen
2006-01-14  7:23                                   ` Matt Helsley
2006-01-12  3:29                           ` Keith Owens
2006-01-12  5:04                             ` Paul E. McKenney
2006-01-12  5:38                               ` Keith Owens
2006-01-12  6:19                               ` Keith Owens
2006-01-12  6:51                                 ` Paul E. McKenney
2006-01-12  7:50                                   ` Keith Owens
2006-01-12 15:17                                     ` Paul E. McKenney
2006-01-17 17:26                                       ` Paul E. McKenney
2006-01-17 23:57                                         ` Keith Owens
2006-01-18  2:49                                           ` Paul E. McKenney
2006-01-18  2:55                                             ` Lee Revell
2006-01-18  6:29                                               ` Paul E. McKenney
2006-01-12  5:26                             ` Matt Helsley
2006-01-12  5:45                               ` Keith Owens
2006-01-12  9:51                         ` Jes Sorensen
2006-01-12 23:01                           ` Matt Helsley
2006-01-13  9:59                             ` Jes Sorensen
2006-01-13 10:38                             ` Jes Sorensen
2006-01-13 23:22                               ` Matt Helsley
2006-01-12 23:49                       ` Matt Helsley
2006-01-05  0:01       ` [ckrm-tech] Re: [Patch 6/6] Delay accounting: Connector interface Shailabh Nagar

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=43BB095C.5000809@watson.ibm.com \
    --to=nagar@watson.ibm.com \
    --cc=akpm@osdl.org \
    --cc=ckrm-tech@lists.sourceforge.net \
    --cc=elsa-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lse-tech@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.