Skip to content

Commit 3d9e0cf

Browse files
Michael Holzheutorvalds
authored andcommitted
taskstats: split fill_pid function
Separate the finding of a task_struct by pid or tgid from filling the taskstats data. This makes the code more readable. Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9323312 commit 3d9e0cf

1 file changed

Lines changed: 21 additions & 29 deletions

File tree

‎kernel/taskstats.c‎

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,8 @@ static void send_cpu_listeners(struct sk_buff *skb,
175175
up_write(&listeners->sem);
176176
}
177177

178-
static int fill_pid(pid_t pid, struct task_struct *tsk,
179-
struct taskstats *stats)
178+
static void fill_stats(struct task_struct *tsk, struct taskstats *stats)
180179
{
181-
int rc = 0;
182-
183-
if (!tsk) {
184-
rcu_read_lock();
185-
tsk = find_task_by_vpid(pid);
186-
if (tsk)
187-
get_task_struct(tsk);
188-
rcu_read_unlock();
189-
if (!tsk)
190-
return -ESRCH;
191-
} else
192-
get_task_struct(tsk);
193-
194180
memset(stats, 0, sizeof(*stats));
195181
/*
196182
* Each accounting subsystem adds calls to its functions to
@@ -209,17 +195,27 @@ static int fill_pid(pid_t pid, struct task_struct *tsk,
209195

210196
/* fill in extended acct fields */
211197
xacct_add_tsk(stats, tsk);
198+
}
212199

213-
/* Define err: label here if needed */
214-
put_task_struct(tsk);
215-
return rc;
200+
static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
201+
{
202+
struct task_struct *tsk;
216203

204+
rcu_read_lock();
205+
tsk = find_task_by_vpid(pid);
206+
if (tsk)
207+
get_task_struct(tsk);
208+
rcu_read_unlock();
209+
if (!tsk)
210+
return -ESRCH;
211+
fill_stats(tsk, stats);
212+
put_task_struct(tsk);
213+
return 0;
217214
}
218215

219-
static int fill_tgid(pid_t tgid, struct task_struct *first,
220-
struct taskstats *stats)
216+
static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
221217
{
222-
struct task_struct *tsk;
218+
struct task_struct *tsk, *first;
223219
unsigned long flags;
224220
int rc = -ESRCH;
225221

@@ -228,8 +224,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
228224
* leaders who are already counted with the dead tasks
229225
*/
230226
rcu_read_lock();
231-
if (!first)
232-
first = find_task_by_vpid(tgid);
227+
first = find_task_by_vpid(tgid);
233228

234229
if (!first || !lock_task_sighand(first, &flags))
235230
goto out;
@@ -268,7 +263,6 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
268263
return rc;
269264
}
270265

271-
272266
static void fill_tgid_exit(struct task_struct *tsk)
273267
{
274268
unsigned long flags;
@@ -483,7 +477,7 @@ static int cmd_attr_pid(struct genl_info *info)
483477
if (!stats)
484478
goto err;
485479

486-
rc = fill_pid(pid, NULL, stats);
480+
rc = fill_stats_for_pid(pid, stats);
487481
if (rc < 0)
488482
goto err;
489483
return send_reply(rep_skb, info);
@@ -513,7 +507,7 @@ static int cmd_attr_tgid(struct genl_info *info)
513507
if (!stats)
514508
goto err;
515509

516-
rc = fill_tgid(tgid, NULL, stats);
510+
rc = fill_stats_for_tgid(tgid, stats);
517511
if (rc < 0)
518512
goto err;
519513
return send_reply(rep_skb, info);
@@ -599,9 +593,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
599593
if (!stats)
600594
goto err;
601595

602-
rc = fill_pid(-1, tsk, stats);
603-
if (rc < 0)
604-
goto err;
596+
fill_stats(tsk, stats);
605597

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

0 commit comments

Comments
 (0)