Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 218612
b: refs/heads/master
c: 3d9e0cf
h: refs/heads/master
v: v3
  • Loading branch information
Michael Holzheu authored and Linus Torvalds committed Oct 28, 2010
1 parent 9e13c29 commit a3bc6a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9323312592cca636d7c2580dc85fa4846efa86a2
refs/heads/master: 3d9e0cf1fe007b88db55d43dfdb6839e1a029ca5
50 changes: 21 additions & 29 deletions trunk/kernel/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,8 @@ static void send_cpu_listeners(struct sk_buff *skb,
up_write(&listeners->sem);
}

static int fill_pid(pid_t pid, struct task_struct *tsk,
struct taskstats *stats)
static void fill_stats(struct task_struct *tsk, struct taskstats *stats)
{
int rc = 0;

if (!tsk) {
rcu_read_lock();
tsk = find_task_by_vpid(pid);
if (tsk)
get_task_struct(tsk);
rcu_read_unlock();
if (!tsk)
return -ESRCH;
} else
get_task_struct(tsk);

memset(stats, 0, sizeof(*stats));
/*
* Each accounting subsystem adds calls to its functions to
Expand All @@ -209,17 +195,27 @@ static int fill_pid(pid_t pid, struct task_struct *tsk,

/* fill in extended acct fields */
xacct_add_tsk(stats, tsk);
}

/* Define err: label here if needed */
put_task_struct(tsk);
return rc;
static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
{
struct task_struct *tsk;

rcu_read_lock();
tsk = find_task_by_vpid(pid);
if (tsk)
get_task_struct(tsk);
rcu_read_unlock();
if (!tsk)
return -ESRCH;
fill_stats(tsk, stats);
put_task_struct(tsk);
return 0;
}

static int fill_tgid(pid_t tgid, struct task_struct *first,
struct taskstats *stats)
static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
{
struct task_struct *tsk;
struct task_struct *tsk, *first;
unsigned long flags;
int rc = -ESRCH;

Expand All @@ -228,8 +224,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
* leaders who are already counted with the dead tasks
*/
rcu_read_lock();
if (!first)
first = find_task_by_vpid(tgid);
first = find_task_by_vpid(tgid);

if (!first || !lock_task_sighand(first, &flags))
goto out;
Expand Down Expand Up @@ -268,7 +263,6 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
return rc;
}


static void fill_tgid_exit(struct task_struct *tsk)
{
unsigned long flags;
Expand Down Expand Up @@ -483,7 +477,7 @@ static int cmd_attr_pid(struct genl_info *info)
if (!stats)
goto err;

rc = fill_pid(pid, NULL, stats);
rc = fill_stats_for_pid(pid, stats);
if (rc < 0)
goto err;
return send_reply(rep_skb, info);
Expand Down Expand Up @@ -513,7 +507,7 @@ static int cmd_attr_tgid(struct genl_info *info)
if (!stats)
goto err;

rc = fill_tgid(tgid, NULL, stats);
rc = fill_stats_for_tgid(tgid, stats);
if (rc < 0)
goto err;
return send_reply(rep_skb, info);
Expand Down Expand Up @@ -599,9 +593,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
if (!stats)
goto err;

rc = fill_pid(-1, tsk, stats);
if (rc < 0)
goto err;
fill_stats(tsk, stats);

/*
* Doesn't matter if tsk is the leader or the last group member leaving
Expand Down

0 comments on commit a3bc6a7

Please sign in to comment.