History

[PATCH] taskstats: kill ->taskstats_lock in favor of ->siglock

signal_struct is (mostly) protected by ->sighand->siglock, I think we don't need ->taskstats_lock to protect ->stats. This also allows us to simplify the locking in fill_tgid().

Oleg Nesterov committed 20 years ago

Commit b8534d71 parent 17b02694 files · +13 −21Browse files

Unified · Split

4 files
  1. include/linux/sched.h +0 −1
  2. include/linux/taskstats_kern.h +6 −9
  3. kernel/fork.c +1 −1
  4. kernel/taskstats.c +6 −10
include/linux/sched.h+0−1
@@ -466,7 +466,6 @@ struct signal_struct { · 465 unmodified lines
466466 struct pacct_struct pacct; /* per-process accounting information */
467467 #endif
468468 #ifdef CONFIG_TASKSTATS
469− spinlock_t stats_lock;
470469 struct taskstats *stats;
471470 #endif
472471 };
include/linux/taskstats_kern.h+6−9
@@ -23,28 +23,26 @@ static inline void taskstats_exit_free(struct taskstats *tidstats) · 22 unmodified lines
2323
2424 static inline void taskstats_tgid_init(struct signal_struct *sig)
2525 {
26− spin_lock_init(&sig->stats_lock);
2726 sig->stats = NULL;
2827 }
2928
30−static inline void taskstats_tgid_alloc(struct signal_struct *sig)
29+static inline void taskstats_tgid_alloc(struct task_struct *tsk)
3130 {
31+ struct signal_struct *sig = tsk->signal;
3232 struct taskstats *stats;
33− unsigned long flags;
3433
3534 if (sig->stats != NULL)
3635 return;
3736
37+ /* No problem if kmem_cache_zalloc() fails */
3838 stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
39− if (!stats)
40− return;
4139
42− spin_lock_irqsave(&sig->stats_lock, flags);
40+ spin_lock_irq(&tsk->sighand->siglock);
4341 if (!sig->stats) {
4442 sig->stats = stats;
4543 stats = NULL;
4644 }
47− spin_unlock_irqrestore(&sig->stats_lock, flags);
45+ spin_unlock_irq(&tsk->sighand->siglock);
4846
4947 if (stats)
5048 kmem_cache_free(taskstats_cache, stats);
@@ -59,7 +57,6 @@ static inline void taskstats_tgid_free(struct signal_struct *sig) · 8 unmodified lines
5957 extern void taskstats_exit_alloc(struct taskstats **, unsigned int *);
6058 extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int);
6159 extern void taskstats_init_early(void);
62−extern void taskstats_tgid_alloc(struct signal_struct *);
6360 #else
6461 static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu)
6562 {}
@@ -71,7 +68,7 @@ static inline void taskstats_exit_send(struct task_struct *tsk, · 5 unmodified lines
7168 {}
7269 static inline void taskstats_tgid_init(struct signal_struct *sig)
7370 {}
74−static inline void taskstats_tgid_alloc(struct signal_struct *sig)
71+static inline void taskstats_tgid_alloc(struct task_struct *tsk)
7572 {}
7673 static inline void taskstats_tgid_free(struct signal_struct *sig)
7774 {}
kernel/fork.c+1−1
@@ -830,7 +830,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts · 829 unmodified lines
830830 if (clone_flags & CLONE_THREAD) {
831831 atomic_inc(&current->signal->count);
832832 atomic_inc(&current->signal->live);
833− taskstats_tgid_alloc(current->signal);
833+ taskstats_tgid_alloc(current);
834834 return 0;
835835 }
836836 sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
kernel/taskstats.c+6−10
@@ -241,11 +241,11 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, · 240 unmodified lines
241241 tsk = first;
242242 read_lock(&tasklist_lock);
243243 /* Start with stats from dead tasks */
244− if (first->signal) {
245− spin_lock_irqsave(&first->signal->stats_lock, flags);
244+ if (first->sighand) {
245+ spin_lock_irqsave(&first->sighand->siglock, flags);
246246 if (first->signal->stats)
247247 memcpy(stats, first->signal->stats, sizeof(*stats));
248− spin_unlock_irqrestore(&first->signal->stats_lock, flags);
248+ spin_unlock_irqrestore(&first->sighand->siglock, flags);
249249 }
250250
251251 do {
@@ -276,7 +276,7 @@ static void fill_tgid_exit(struct task_struct *tsk) · 24 unmodified lines
276276 {
277277 unsigned long flags;
278278
279− spin_lock_irqsave(&tsk->signal->stats_lock, flags);
279+ spin_lock_irqsave(&tsk->sighand->siglock, flags);
280280 if (!tsk->signal->stats)
281281 goto ret;
282282
@@ -288,7 +288,7 @@ static void fill_tgid_exit(struct task_struct *tsk) · 5 unmodified lines
288288 */
289289 delayacct_add_tsk(tsk->signal->stats, tsk);
290290 ret:
291− spin_unlock_irqrestore(&tsk->signal->stats_lock, flags);
291+ spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
292292 return;
293293 }
294294
@@ -464,15 +464,10 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, · 169 unmodified lines
464464 size_t size;
465465 int is_thread_group;
466466 struct nlattr *na;
467− unsigned long flags;
468467
469468 if (!family_registered || !tidstats)
470469 return;
471470
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−
476471 rc = 0;
477472 /*
478473 * Size includes space for nested attributes
@@ -480,6 +475,7 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, · 1 unmodified line
480475 size = nla_total_size(sizeof(u32)) +
481476 nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
482477
478+ is_thread_group = (tsk->signal->stats != NULL);
483479 if (is_thread_group)
484480 size = 2 * size; /* PID + STATS + TGID + STATS */
485481