--- zzzz-none-000/linux-2.6.19.2/kernel/taskstats.c 2007-01-10 19:10:37.000000000 +0000 +++ davinci-8020-5505/linux-2.6.19.2/kernel/taskstats.c 2007-01-11 07:38:19.000000000 +0000 @@ -77,8 +77,7 @@ /* * If new attributes are added, please revisit this allocation */ - size = nlmsg_total_size(genlmsg_total_size(size)); - skb = nlmsg_new(size, GFP_KERNEL); + skb = nlmsg_new(genlmsg_total_size(size), GFP_KERNEL); if (!skb) return -ENOMEM; @@ -175,19 +174,21 @@ up_write(&listeners->sem); } -static int fill_pid(pid_t pid, struct task_struct *tsk, +static int fill_pid(pid_t pid, struct task_struct *pidtsk, struct taskstats *stats) { int rc = 0; + struct task_struct *tsk = pidtsk; - if (!tsk) { - rcu_read_lock(); + if (!pidtsk) { + read_lock(&tasklist_lock); tsk = find_task_by_pid(pid); - if (tsk) - get_task_struct(tsk); - rcu_read_unlock(); - if (!tsk) + if (!tsk) { + read_unlock(&tasklist_lock); return -ESRCH; + } + get_task_struct(tsk); + read_unlock(&tasklist_lock); } else get_task_struct(tsk); @@ -213,30 +214,39 @@ } -static int fill_tgid(pid_t tgid, struct task_struct *first, +static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, struct taskstats *stats) { - struct task_struct *tsk; + struct task_struct *tsk, *first; unsigned long flags; - int rc = -ESRCH; /* * Add additional stats from live tasks except zombie thread group * leaders who are already counted with the dead tasks */ - rcu_read_lock(); - if (!first) + first = tgidtsk; + if (!first) { + read_lock(&tasklist_lock); first = find_task_by_pid(tgid); + if (!first) { + read_unlock(&tasklist_lock); + return -ESRCH; + } + get_task_struct(first); + read_unlock(&tasklist_lock); + } else + get_task_struct(first); - if (!first || !lock_task_sighand(first, &flags)) - goto out; - + /* Start with stats from dead tasks */ + spin_lock_irqsave(&first->signal->stats_lock, flags); if (first->signal->stats) memcpy(stats, first->signal->stats, sizeof(*stats)); + spin_unlock_irqrestore(&first->signal->stats_lock, flags); tsk = first; + read_lock(&tasklist_lock); do { - if (tsk->exit_state) + if (tsk->exit_state == EXIT_ZOMBIE && thread_group_leader(tsk)) continue; /* * Accounting subsystem can call its functions here to @@ -247,18 +257,15 @@ delayacct_add_tsk(stats, tsk); } while_each_thread(first, tsk); - - unlock_task_sighand(first, &flags); - rc = 0; -out: - rcu_read_unlock(); - + read_unlock(&tasklist_lock); stats->version = TASKSTATS_VERSION; + /* * Accounting subsytems can also add calls here to modify * fields of taskstats. */ - return rc; + + return 0; } @@ -266,7 +273,7 @@ { unsigned long flags; - spin_lock_irqsave(&tsk->sighand->siglock, flags); + spin_lock_irqsave(&tsk->signal->stats_lock, flags); if (!tsk->signal->stats) goto ret; @@ -278,7 +285,7 @@ */ delayacct_add_tsk(tsk->signal->stats, tsk); ret: - spin_unlock_irqrestore(&tsk->sighand->siglock, flags); + spin_unlock_irqrestore(&tsk->signal->stats_lock, flags); return; } @@ -412,7 +419,7 @@ return send_reply(rep_skb, info->snd_pid); nla_put_failure: - rc = genlmsg_cancel(rep_skb, reply); + return genlmsg_cancel(rep_skb, reply); err: nlmsg_free(rep_skb); return rc; @@ -454,26 +461,24 @@ size_t size; int is_thread_group; struct nlattr *na; + unsigned long flags; - if (!family_registered) + if (!family_registered || !tidstats) return; + spin_lock_irqsave(&tsk->signal->stats_lock, flags); + is_thread_group = tsk->signal->stats ? 1 : 0; + spin_unlock_irqrestore(&tsk->signal->stats_lock, flags); + + rc = 0; /* * Size includes space for nested attributes */ size = nla_total_size(sizeof(u32)) + nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); - is_thread_group = (tsk->signal->stats != NULL); - if (is_thread_group) { - /* PID + STATS + TGID + STATS */ - size = 2 * size; - /* fill the tsk->signal->stats structure */ - fill_tgid_exit(tsk); - } - - if (!tidstats) - return; + if (is_thread_group) + size = 2 * size; /* PID + STATS + TGID + STATS */ rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size); if (rc < 0) @@ -493,8 +498,11 @@ goto send; /* + * tsk has/had a thread group so fill the tsk->signal->stats structure * Doesn't matter if tsk is the leader or the last group member leaving */ + + fill_tgid_exit(tsk); if (!group_dead) goto send; @@ -511,6 +519,7 @@ nla_put_failure: genlmsg_cancel(rep_skb, reply); + goto ret; err_skb: nlmsg_free(rep_skb); ret: