diff options
-rw-r--r-- | include/linux/sched.h | 1 | ||||
-rw-r--r-- | include/linux/taskstats_kern.h | 15 | ||||
-rw-r--r-- | kernel/fork.c | 2 | ||||
-rw-r--r-- | kernel/taskstats.c | 16 |
4 files changed, 13 insertions, 21 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 6735c1cf334c..eafe4a7b8237 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -466,7 +466,6 @@ struct signal_struct { | |||
466 | struct pacct_struct pacct; /* per-process accounting information */ | 466 | struct pacct_struct pacct; /* per-process accounting information */ |
467 | #endif | 467 | #endif |
468 | #ifdef CONFIG_TASKSTATS | 468 | #ifdef CONFIG_TASKSTATS |
469 | spinlock_t stats_lock; | ||
470 | struct taskstats *stats; | 469 | struct taskstats *stats; |
471 | #endif | 470 | #endif |
472 | }; | 471 | }; |
diff --git a/include/linux/taskstats_kern.h b/include/linux/taskstats_kern.h index 664224008fb2..6562a2050a25 100644 --- a/include/linux/taskstats_kern.h +++ b/include/linux/taskstats_kern.h | |||
@@ -23,28 +23,26 @@ static inline void taskstats_exit_free(struct taskstats *tidstats) | |||
23 | 23 | ||
24 | static inline void taskstats_tgid_init(struct signal_struct *sig) | 24 | static inline void taskstats_tgid_init(struct signal_struct *sig) |
25 | { | 25 | { |
26 | spin_lock_init(&sig->stats_lock); | ||
27 | sig->stats = NULL; | 26 | sig->stats = NULL; |
28 | } | 27 | } |
29 | 28 | ||
30 | static inline void taskstats_tgid_alloc(struct signal_struct *sig) | 29 | static inline void taskstats_tgid_alloc(struct task_struct *tsk) |
31 | { | 30 | { |
31 | struct signal_struct *sig = tsk->signal; | ||
32 | struct taskstats *stats; | 32 | struct taskstats *stats; |
33 | unsigned long flags; | ||
34 | 33 | ||
35 | if (sig->stats != NULL) | 34 | if (sig->stats != NULL) |
36 | return; | 35 | return; |
37 | 36 | ||
37 | /* No problem if kmem_cache_zalloc() fails */ | ||
38 | stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); | 38 | stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); |
39 | if (!stats) | ||
40 | return; | ||
41 | 39 | ||
42 | spin_lock_irqsave(&sig->stats_lock, flags); | 40 | spin_lock_irq(&tsk->sighand->siglock); |
43 | if (!sig->stats) { | 41 | if (!sig->stats) { |
44 | sig->stats = stats; | 42 | sig->stats = stats; |
45 | stats = NULL; | 43 | stats = NULL; |
46 | } | 44 | } |
47 | spin_unlock_irqrestore(&sig->stats_lock, flags); | 45 | spin_unlock_irq(&tsk->sighand->siglock); |
48 | 46 | ||
49 | if (stats) | 47 | if (stats) |
50 | kmem_cache_free(taskstats_cache, stats); | 48 | kmem_cache_free(taskstats_cache, stats); |
@@ -59,7 +57,6 @@ static inline void taskstats_tgid_free(struct signal_struct *sig) | |||
59 | extern void taskstats_exit_alloc(struct taskstats **, unsigned int *); | 57 | extern void taskstats_exit_alloc(struct taskstats **, unsigned int *); |
60 | extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int); | 58 | extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int); |
61 | extern void taskstats_init_early(void); | 59 | extern void taskstats_init_early(void); |
62 | extern void taskstats_tgid_alloc(struct signal_struct *); | ||
63 | #else | 60 | #else |
64 | static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) | 61 | static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) |
65 | {} | 62 | {} |
@@ -71,7 +68,7 @@ static inline void taskstats_exit_send(struct task_struct *tsk, | |||
71 | {} | 68 | {} |
72 | static inline void taskstats_tgid_init(struct signal_struct *sig) | 69 | static inline void taskstats_tgid_init(struct signal_struct *sig) |
73 | {} | 70 | {} |
74 | static inline void taskstats_tgid_alloc(struct signal_struct *sig) | 71 | static inline void taskstats_tgid_alloc(struct task_struct *tsk) |
75 | {} | 72 | {} |
76 | static inline void taskstats_tgid_free(struct signal_struct *sig) | 73 | static inline void taskstats_tgid_free(struct signal_struct *sig) |
77 | {} | 74 | {} |
diff --git a/kernel/fork.c b/kernel/fork.c index 213326609bac..3da978eec791 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -830,7 +830,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts | |||
830 | if (clone_flags & CLONE_THREAD) { | 830 | if (clone_flags & CLONE_THREAD) { |
831 | atomic_inc(¤t->signal->count); | 831 | atomic_inc(¤t->signal->count); |
832 | atomic_inc(¤t->signal->live); | 832 | atomic_inc(¤t->signal->live); |
833 | taskstats_tgid_alloc(current->signal); | 833 | taskstats_tgid_alloc(current); |
834 | return 0; | 834 | return 0; |
835 | } | 835 | } |
836 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); | 836 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); |
diff --git a/kernel/taskstats.c b/kernel/taskstats.c index 9aeee511a463..b2efda94615a 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c | |||
@@ -241,11 +241,11 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, | |||
241 | tsk = first; | 241 | tsk = first; |
242 | read_lock(&tasklist_lock); | 242 | read_lock(&tasklist_lock); |
243 | /* Start with stats from dead tasks */ | 243 | /* Start with stats from dead tasks */ |
244 | if (first->signal) { | 244 | if (first->sighand) { |
245 | spin_lock_irqsave(&first->signal->stats_lock, flags); | 245 | spin_lock_irqsave(&first->sighand->siglock, flags); |
246 | if (first->signal->stats) | 246 | if (first->signal->stats) |
247 | memcpy(stats, first->signal->stats, sizeof(*stats)); | 247 | memcpy(stats, first->signal->stats, sizeof(*stats)); |
248 | spin_unlock_irqrestore(&first->signal->stats_lock, flags); | 248 | spin_unlock_irqrestore(&first->sighand->siglock, flags); |
249 | } | 249 | } |
250 | 250 | ||
251 | do { | 251 | do { |
@@ -276,7 +276,7 @@ static void fill_tgid_exit(struct task_struct *tsk) | |||
276 | { | 276 | { |
277 | unsigned long flags; | 277 | unsigned long flags; |
278 | 278 | ||
279 | spin_lock_irqsave(&tsk->signal->stats_lock, flags); | 279 | spin_lock_irqsave(&tsk->sighand->siglock, flags); |
280 | if (!tsk->signal->stats) | 280 | if (!tsk->signal->stats) |
281 | goto ret; | 281 | goto ret; |
282 | 282 | ||
@@ -288,7 +288,7 @@ static void fill_tgid_exit(struct task_struct *tsk) | |||
288 | */ | 288 | */ |
289 | delayacct_add_tsk(tsk->signal->stats, tsk); | 289 | delayacct_add_tsk(tsk->signal->stats, tsk); |
290 | ret: | 290 | ret: |
291 | spin_unlock_irqrestore(&tsk->signal->stats_lock, flags); | 291 | spin_unlock_irqrestore(&tsk->sighand->siglock, flags); |
292 | return; | 292 | return; |
293 | } | 293 | } |
294 | 294 | ||
@@ -464,15 +464,10 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, | |||
464 | size_t size; | 464 | size_t size; |
465 | int is_thread_group; | 465 | int is_thread_group; |
466 | struct nlattr *na; | 466 | struct nlattr *na; |
467 | unsigned long flags; | ||
468 | 467 | ||
469 | if (!family_registered || !tidstats) | 468 | if (!family_registered || !tidstats) |
470 | return; | 469 | return; |
471 | 470 | ||
472 | spin_lock_irqsave(&tsk->signal->stats_lock, flags); | ||
473 | is_thread_group = tsk->signal->stats ? 1 : 0; | ||
474 | spin_unlock_irqrestore(&tsk->signal->stats_lock, flags); | ||
475 | |||
476 | rc = 0; | 471 | rc = 0; |
477 | /* | 472 | /* |
478 | * Size includes space for nested attributes | 473 | * Size includes space for nested attributes |
@@ -480,6 +475,7 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, | |||
480 | size = nla_total_size(sizeof(u32)) + | 475 | size = nla_total_size(sizeof(u32)) + |
481 | nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); | 476 | nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); |
482 | 477 | ||
478 | is_thread_group = (tsk->signal->stats != NULL); | ||
483 | if (is_thread_group) | 479 | if (is_thread_group) |
484 | size = 2 * size; /* PID + STATS + TGID + STATS */ | 480 | size = 2 * size; /* PID + STATS + TGID + STATS */ |
485 | 481 | ||