diff options
Diffstat (limited to 'kernel/exit.c')
| -rw-r--r-- | kernel/exit.c | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index f7864ac2ecc1..546774a31a66 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -49,6 +49,7 @@ | |||
| 49 | #include <linux/init_task.h> | 49 | #include <linux/init_task.h> |
| 50 | #include <linux/perf_event.h> | 50 | #include <linux/perf_event.h> |
| 51 | #include <trace/events/sched.h> | 51 | #include <trace/events/sched.h> |
| 52 | #include <linux/hw_breakpoint.h> | ||
| 52 | 53 | ||
| 53 | #include <asm/uaccess.h> | 54 | #include <asm/uaccess.h> |
| 54 | #include <asm/unistd.h> | 55 | #include <asm/unistd.h> |
| @@ -67,10 +68,10 @@ static void __unhash_process(struct task_struct *p) | |||
| 67 | detach_pid(p, PIDTYPE_SID); | 68 | detach_pid(p, PIDTYPE_SID); |
| 68 | 69 | ||
| 69 | list_del_rcu(&p->tasks); | 70 | list_del_rcu(&p->tasks); |
| 71 | list_del_init(&p->sibling); | ||
| 70 | __get_cpu_var(process_counts)--; | 72 | __get_cpu_var(process_counts)--; |
| 71 | } | 73 | } |
| 72 | list_del_rcu(&p->thread_group); | 74 | list_del_rcu(&p->thread_group); |
| 73 | list_del_init(&p->sibling); | ||
| 74 | } | 75 | } |
| 75 | 76 | ||
| 76 | /* | 77 | /* |
| @@ -110,9 +111,9 @@ static void __exit_signal(struct task_struct *tsk) | |||
| 110 | * We won't ever get here for the group leader, since it | 111 | * We won't ever get here for the group leader, since it |
| 111 | * will have been the last reference on the signal_struct. | 112 | * will have been the last reference on the signal_struct. |
| 112 | */ | 113 | */ |
| 113 | sig->utime = cputime_add(sig->utime, task_utime(tsk)); | 114 | sig->utime = cputime_add(sig->utime, tsk->utime); |
| 114 | sig->stime = cputime_add(sig->stime, task_stime(tsk)); | 115 | sig->stime = cputime_add(sig->stime, tsk->stime); |
| 115 | sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); | 116 | sig->gtime = cputime_add(sig->gtime, tsk->gtime); |
| 116 | sig->min_flt += tsk->min_flt; | 117 | sig->min_flt += tsk->min_flt; |
| 117 | sig->maj_flt += tsk->maj_flt; | 118 | sig->maj_flt += tsk->maj_flt; |
| 118 | sig->nvcsw += tsk->nvcsw; | 119 | sig->nvcsw += tsk->nvcsw; |
| @@ -735,12 +736,9 @@ static struct task_struct *find_new_reaper(struct task_struct *father) | |||
| 735 | /* | 736 | /* |
| 736 | * Any that need to be release_task'd are put on the @dead list. | 737 | * Any that need to be release_task'd are put on the @dead list. |
| 737 | */ | 738 | */ |
| 738 | static void reparent_thread(struct task_struct *father, struct task_struct *p, | 739 | static void reparent_leader(struct task_struct *father, struct task_struct *p, |
| 739 | struct list_head *dead) | 740 | struct list_head *dead) |
| 740 | { | 741 | { |
| 741 | if (p->pdeath_signal) | ||
| 742 | group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p); | ||
| 743 | |||
| 744 | list_move_tail(&p->sibling, &p->real_parent->children); | 742 | list_move_tail(&p->sibling, &p->real_parent->children); |
| 745 | 743 | ||
| 746 | if (task_detached(p)) | 744 | if (task_detached(p)) |
| @@ -779,12 +777,18 @@ static void forget_original_parent(struct task_struct *father) | |||
| 779 | reaper = find_new_reaper(father); | 777 | reaper = find_new_reaper(father); |
| 780 | 778 | ||
| 781 | list_for_each_entry_safe(p, n, &father->children, sibling) { | 779 | list_for_each_entry_safe(p, n, &father->children, sibling) { |
| 782 | p->real_parent = reaper; | 780 | struct task_struct *t = p; |
| 783 | if (p->parent == father) { | 781 | do { |
| 784 | BUG_ON(task_ptrace(p)); | 782 | t->real_parent = reaper; |
| 785 | p->parent = p->real_parent; | 783 | if (t->parent == father) { |
| 786 | } | 784 | BUG_ON(task_ptrace(t)); |
| 787 | reparent_thread(father, p, &dead_children); | 785 | t->parent = t->real_parent; |
| 786 | } | ||
| 787 | if (t->pdeath_signal) | ||
| 788 | group_send_sig_info(t->pdeath_signal, | ||
| 789 | SEND_SIG_NOINFO, t); | ||
| 790 | } while_each_thread(p, t); | ||
| 791 | reparent_leader(father, p, &dead_children); | ||
| 788 | } | 792 | } |
| 789 | write_unlock_irq(&tasklist_lock); | 793 | write_unlock_irq(&tasklist_lock); |
| 790 | 794 | ||
| @@ -932,7 +936,7 @@ NORET_TYPE void do_exit(long code) | |||
| 932 | * an exiting task cleaning up the robust pi futexes. | 936 | * an exiting task cleaning up the robust pi futexes. |
| 933 | */ | 937 | */ |
| 934 | smp_mb(); | 938 | smp_mb(); |
| 935 | spin_unlock_wait(&tsk->pi_lock); | 939 | raw_spin_unlock_wait(&tsk->pi_lock); |
| 936 | 940 | ||
| 937 | if (unlikely(in_atomic())) | 941 | if (unlikely(in_atomic())) |
| 938 | printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", | 942 | printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", |
| @@ -970,7 +974,7 @@ NORET_TYPE void do_exit(long code) | |||
| 970 | exit_thread(); | 974 | exit_thread(); |
| 971 | cgroup_exit(tsk, 1); | 975 | cgroup_exit(tsk, 1); |
| 972 | 976 | ||
| 973 | if (group_dead && tsk->signal->leader) | 977 | if (group_dead) |
| 974 | disassociate_ctty(1); | 978 | disassociate_ctty(1); |
| 975 | 979 | ||
| 976 | module_put(task_thread_info(tsk)->exec_domain->module); | 980 | module_put(task_thread_info(tsk)->exec_domain->module); |
| @@ -978,6 +982,10 @@ NORET_TYPE void do_exit(long code) | |||
| 978 | proc_exit_connector(tsk); | 982 | proc_exit_connector(tsk); |
| 979 | 983 | ||
| 980 | /* | 984 | /* |
| 985 | * FIXME: do that only when needed, using sched_exit tracepoint | ||
| 986 | */ | ||
| 987 | flush_ptrace_hw_breakpoint(tsk); | ||
| 988 | /* | ||
| 981 | * Flush inherited counters to the parent - before the parent | 989 | * Flush inherited counters to the parent - before the parent |
| 982 | * gets woken up by child-exit notifications. | 990 | * gets woken up by child-exit notifications. |
| 983 | */ | 991 | */ |
| @@ -1004,7 +1012,7 @@ NORET_TYPE void do_exit(long code) | |||
| 1004 | tsk->flags |= PF_EXITPIDONE; | 1012 | tsk->flags |= PF_EXITPIDONE; |
| 1005 | 1013 | ||
| 1006 | if (tsk->io_context) | 1014 | if (tsk->io_context) |
| 1007 | exit_io_context(); | 1015 | exit_io_context(tsk); |
| 1008 | 1016 | ||
| 1009 | if (tsk->splice_pipe) | 1017 | if (tsk->splice_pipe) |
| 1010 | __free_pipe_info(tsk->splice_pipe); | 1018 | __free_pipe_info(tsk->splice_pipe); |
| @@ -1205,6 +1213,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) | |||
| 1205 | struct signal_struct *psig; | 1213 | struct signal_struct *psig; |
| 1206 | struct signal_struct *sig; | 1214 | struct signal_struct *sig; |
| 1207 | unsigned long maxrss; | 1215 | unsigned long maxrss; |
| 1216 | cputime_t tgutime, tgstime; | ||
| 1208 | 1217 | ||
| 1209 | /* | 1218 | /* |
| 1210 | * The resource counters for the group leader are in its | 1219 | * The resource counters for the group leader are in its |
| @@ -1220,20 +1229,23 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) | |||
| 1220 | * need to protect the access to parent->signal fields, | 1229 | * need to protect the access to parent->signal fields, |
| 1221 | * as other threads in the parent group can be right | 1230 | * as other threads in the parent group can be right |
| 1222 | * here reaping other children at the same time. | 1231 | * here reaping other children at the same time. |
| 1232 | * | ||
| 1233 | * We use thread_group_times() to get times for the thread | ||
| 1234 | * group, which consolidates times for all threads in the | ||
| 1235 | * group including the group leader. | ||
| 1223 | */ | 1236 | */ |
| 1237 | thread_group_times(p, &tgutime, &tgstime); | ||
| 1224 | spin_lock_irq(&p->real_parent->sighand->siglock); | 1238 | spin_lock_irq(&p->real_parent->sighand->siglock); |
| 1225 | psig = p->real_parent->signal; | 1239 | psig = p->real_parent->signal; |
| 1226 | sig = p->signal; | 1240 | sig = p->signal; |
| 1227 | psig->cutime = | 1241 | psig->cutime = |
| 1228 | cputime_add(psig->cutime, | 1242 | cputime_add(psig->cutime, |
| 1229 | cputime_add(p->utime, | 1243 | cputime_add(tgutime, |
| 1230 | cputime_add(sig->utime, | 1244 | sig->cutime)); |
| 1231 | sig->cutime))); | ||
| 1232 | psig->cstime = | 1245 | psig->cstime = |
| 1233 | cputime_add(psig->cstime, | 1246 | cputime_add(psig->cstime, |
| 1234 | cputime_add(p->stime, | 1247 | cputime_add(tgstime, |
| 1235 | cputime_add(sig->stime, | 1248 | sig->cstime)); |
| 1236 | sig->cstime))); | ||
| 1237 | psig->cgtime = | 1249 | psig->cgtime = |
| 1238 | cputime_add(psig->cgtime, | 1250 | cputime_add(psig->cgtime, |
| 1239 | cputime_add(p->gtime, | 1251 | cputime_add(p->gtime, |
| @@ -1542,14 +1554,9 @@ static int do_wait_thread(struct wait_opts *wo, struct task_struct *tsk) | |||
| 1542 | struct task_struct *p; | 1554 | struct task_struct *p; |
| 1543 | 1555 | ||
| 1544 | list_for_each_entry(p, &tsk->children, sibling) { | 1556 | list_for_each_entry(p, &tsk->children, sibling) { |
| 1545 | /* | 1557 | int ret = wait_consider_task(wo, 0, p); |
| 1546 | * Do not consider detached threads. | 1558 | if (ret) |
| 1547 | */ | 1559 | return ret; |
| 1548 | if (!task_detached(p)) { | ||
| 1549 | int ret = wait_consider_task(wo, 0, p); | ||
| 1550 | if (ret) | ||
| 1551 | return ret; | ||
| 1552 | } | ||
| 1553 | } | 1560 | } |
| 1554 | 1561 | ||
| 1555 | return 0; | 1562 | return 0; |
