Commit bf719d26 authored by Albert Cahalan's avatar Albert Cahalan Committed by Linus Torvalds

[PATCH] distinct tgid/tid CPU usage

This patch adjusts /proc/*/stat to have distinct per-process and per-thread
CPU usage, faults, and wchan.
Signed-off-by: default avatarAlbert Cahalan <albert@users.sf.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 09b9135c
...@@ -300,9 +300,9 @@ int proc_pid_status(struct task_struct *task, char * buffer) ...@@ -300,9 +300,9 @@ int proc_pid_status(struct task_struct *task, char * buffer)
return buffer - orig; return buffer - orig;
} }
int proc_pid_stat(struct task_struct *task, char * buffer) static int do_task_stat(struct task_struct *task, char * buffer, int whole)
{ {
unsigned long vsize, eip, esp, wchan; unsigned long vsize, eip, esp, wchan = ~0UL;
long priority, nice; long priority, nice;
int tty_pgrp = -1, tty_nr = 0; int tty_pgrp = -1, tty_nr = 0;
sigset_t sigign, sigcatch; sigset_t sigign, sigcatch;
...@@ -313,6 +313,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -313,6 +313,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
struct mm_struct *mm; struct mm_struct *mm;
unsigned long long start_time; unsigned long long start_time;
unsigned long cmin_flt = 0, cmaj_flt = 0, cutime = 0, cstime = 0; unsigned long cmin_flt = 0, cmaj_flt = 0, cutime = 0, cstime = 0;
unsigned long min_flt = 0, maj_flt = 0, utime = 0, stime = 0;
unsigned long rsslim = 0; unsigned long rsslim = 0;
char tcomm[sizeof(task->comm)]; char tcomm[sizeof(task->comm)];
...@@ -326,7 +327,6 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -326,7 +327,6 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
} }
get_task_comm(tcomm, task); get_task_comm(tcomm, task);
wchan = get_wchan(task);
sigemptyset(&sigign); sigemptyset(&sigign);
sigemptyset(&sigcatch); sigemptyset(&sigcatch);
...@@ -349,18 +349,30 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -349,18 +349,30 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
cutime = task->signal->cutime; cutime = task->signal->cutime;
cstime = task->signal->cstime; cstime = task->signal->cstime;
rsslim = task->signal->rlim[RLIMIT_RSS].rlim_cur; rsslim = task->signal->rlim[RLIMIT_RSS].rlim_cur;
if (whole) {
min_flt = task->signal->min_flt;
maj_flt = task->signal->maj_flt;
utime = task->signal->utime;
stime = task->signal->stime;
}
} }
ppid = task->pid ? task->real_parent->pid : 0;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
if (!whole || num_threads<2)
wchan = get_wchan(task);
if (!whole) {
min_flt = task->min_flt;
maj_flt = task->maj_flt;
utime = task->utime;
stime = task->stime;
}
/* scale priority and nice values from timeslices to -20..20 */ /* scale priority and nice values from timeslices to -20..20 */
/* to make it look like a "normal" Unix priority/nice value */ /* to make it look like a "normal" Unix priority/nice value */
priority = task_prio(task); priority = task_prio(task);
nice = task_nice(task); nice = task_nice(task);
read_lock(&tasklist_lock);
ppid = task->pid ? task->real_parent->pid : 0;
read_unlock(&tasklist_lock);
/* Temporary variable needed for gcc-2.96 */ /* Temporary variable needed for gcc-2.96 */
/* convert timespec -> nsec*/ /* convert timespec -> nsec*/
start_time = (unsigned long long)task->start_time.tv_sec * NSEC_PER_SEC start_time = (unsigned long long)task->start_time.tv_sec * NSEC_PER_SEC
...@@ -380,12 +392,12 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -380,12 +392,12 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
tty_nr, tty_nr,
tty_pgrp, tty_pgrp,
task->flags, task->flags,
task->min_flt, min_flt,
cmin_flt, cmin_flt,
task->maj_flt, maj_flt,
cmaj_flt, cmaj_flt,
jiffies_to_clock_t(task->utime), jiffies_to_clock_t(utime),
jiffies_to_clock_t(task->stime), jiffies_to_clock_t(stime),
jiffies_to_clock_t(cutime), jiffies_to_clock_t(cutime),
jiffies_to_clock_t(cstime), jiffies_to_clock_t(cstime),
priority, priority,
...@@ -421,6 +433,16 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -421,6 +433,16 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
return res; return res;
} }
int proc_tid_stat(struct task_struct *task, char * buffer)
{
return do_task_stat(task, buffer, 0);
}
int proc_tgid_stat(struct task_struct *task, char * buffer)
{
return do_task_stat(task, buffer, 1);
}
int proc_pid_statm(struct task_struct *task, char *buffer) int proc_pid_statm(struct task_struct *task, char *buffer)
{ {
int size = 0, resident = 0, shared = 0, text = 0, lib = 0, data = 0; int size = 0, resident = 0, shared = 0, text = 0, lib = 0, data = 0;
......
...@@ -189,7 +189,8 @@ static inline int proc_type(struct inode *inode) ...@@ -189,7 +189,8 @@ static inline int proc_type(struct inode *inode)
return PROC_I(inode)->type; return PROC_I(inode)->type;
} }
int proc_pid_stat(struct task_struct*,char*); int proc_tid_stat(struct task_struct*,char*);
int proc_tgid_stat(struct task_struct*,char*);
int proc_pid_status(struct task_struct*,char*); int proc_pid_status(struct task_struct*,char*);
int proc_pid_statm(struct task_struct*,char*); int proc_pid_statm(struct task_struct*,char*);
...@@ -1315,9 +1316,12 @@ static struct dentry *proc_pident_lookup(struct inode *dir, ...@@ -1315,9 +1316,12 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
ei->op.proc_read = proc_pid_status; ei->op.proc_read = proc_pid_status;
break; break;
case PROC_TID_STAT: case PROC_TID_STAT:
inode->i_fop = &proc_info_file_operations;
ei->op.proc_read = proc_tid_stat;
break;
case PROC_TGID_STAT: case PROC_TGID_STAT:
inode->i_fop = &proc_info_file_operations; inode->i_fop = &proc_info_file_operations;
ei->op.proc_read = proc_pid_stat; ei->op.proc_read = proc_tgid_stat;
break; break;
case PROC_TID_CMDLINE: case PROC_TID_CMDLINE:
case PROC_TGID_CMDLINE: case PROC_TGID_CMDLINE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment