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

[PATCH] number of threads in /proc

Having the number-of-threads value easily available turns out to be very
important for procps performance.

The /proc/*/stat thing getting reused has been zero since the 2.2.xx
days, and was the seldom-used timeout value before that.
parent 15902084
...@@ -226,6 +226,7 @@ static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign, ...@@ -226,6 +226,7 @@ static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
static inline char * task_sig(struct task_struct *p, char *buffer) static inline char * task_sig(struct task_struct *p, char *buffer)
{ {
sigset_t pending, shpending, blocked, ignored, caught; sigset_t pending, shpending, blocked, ignored, caught;
int num_threads = 0;
sigemptyset(&pending); sigemptyset(&pending);
sigemptyset(&shpending); sigemptyset(&shpending);
...@@ -241,10 +242,13 @@ static inline char * task_sig(struct task_struct *p, char *buffer) ...@@ -241,10 +242,13 @@ static inline char * task_sig(struct task_struct *p, char *buffer)
shpending = p->signal->shared_pending.signal; shpending = p->signal->shared_pending.signal;
blocked = p->blocked; blocked = p->blocked;
collect_sigign_sigcatch(p, &ignored, &caught); collect_sigign_sigcatch(p, &ignored, &caught);
num_threads = atomic_read(&p->signal->count);
spin_unlock_irq(&p->sighand->siglock); spin_unlock_irq(&p->sighand->siglock);
} }
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
buffer += sprintf(buffer, "Threads:\t%d\n", num_threads);
/* render them all */ /* render them all */
buffer = render_sigset_t("SigPnd:\t", &pending, buffer); buffer = render_sigset_t("SigPnd:\t", &pending, buffer);
buffer = render_sigset_t("ShdPnd:\t", &shpending, buffer); buffer = render_sigset_t("ShdPnd:\t", &shpending, buffer);
...@@ -296,6 +300,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -296,6 +300,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
char state; char state;
int res; int res;
pid_t ppid; pid_t ppid;
int num_threads = 0;
struct mm_struct *mm; struct mm_struct *mm;
state = *get_task_state(task); state = *get_task_state(task);
...@@ -324,6 +329,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -324,6 +329,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
if (task->sighand) { if (task->sighand) {
spin_lock_irq(&task->sighand->siglock); spin_lock_irq(&task->sighand->siglock);
num_threads = atomic_read(&task->signal->count);
collect_sigign_sigcatch(task, &sigign, &sigcatch); collect_sigign_sigcatch(task, &sigign, &sigcatch);
spin_unlock_irq(&task->sighand->siglock); spin_unlock_irq(&task->sighand->siglock);
} }
...@@ -338,7 +344,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -338,7 +344,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
ppid = task->pid ? task->real_parent->pid : 0; ppid = task->pid ? task->real_parent->pid : 0;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld %lu %lu %lu %lu %lu \ %lu %lu %lu %lu %lu %ld %ld %ld %ld %d %ld %llu %lu %ld %lu %lu %lu %lu %lu \
%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu\n", %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu\n",
task->pid, task->pid,
task->comm, task->comm,
...@@ -359,7 +365,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer) ...@@ -359,7 +365,7 @@ int proc_pid_stat(struct task_struct *task, char * buffer)
jiffies_to_clock_t(task->cstime), jiffies_to_clock_t(task->cstime),
priority, priority,
nice, nice,
0UL /* removed */, num_threads,
jiffies_to_clock_t(task->it_real_value), jiffies_to_clock_t(task->it_real_value),
(unsigned long long) (unsigned long long)
jiffies_64_to_clock_t(task->start_time - INITIAL_JIFFIES), jiffies_64_to_clock_t(task->start_time - INITIAL_JIFFIES),
......
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