diff options
author | Mandeep Singh Baines <msb@google.com> | 2009-02-06 18:37:47 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-02-09 05:03:49 -0500 |
commit | 17406b82d621930cca8ccc1272cdac9a7dae8e40 (patch) | |
tree | 224c8b0b7c78a5467175fe10e116bdc6b73495ea | |
parent | 94be52dc075a32af4aa73d7e10f68734d62d6af2 (diff) |
softlockup: remove timestamp checking from hung_task
Impact: saves sizeof(long) bytes per task_struct
By guaranteeing that sysctl_hung_task_timeout_secs have elapsed between
tasklist scans we can avoid using timestamps.
Signed-off-by: Mandeep Singh Baines <msb@google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | include/linux/sched.h | 1 | ||||
-rw-r--r-- | kernel/fork.c | 8 | ||||
-rw-r--r-- | kernel/hung_task.c | 48 |
3 files changed, 12 insertions, 45 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 2a2811c6239d..e0d723fea9f5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1241,7 +1241,6 @@ struct task_struct { | |||
1241 | #endif | 1241 | #endif |
1242 | #ifdef CONFIG_DETECT_HUNG_TASK | 1242 | #ifdef CONFIG_DETECT_HUNG_TASK |
1243 | /* hung task detection */ | 1243 | /* hung task detection */ |
1244 | unsigned long last_switch_timestamp; | ||
1245 | unsigned long last_switch_count; | 1244 | unsigned long last_switch_count; |
1246 | #endif | 1245 | #endif |
1247 | /* CPU-specific state of this task */ | 1246 | /* CPU-specific state of this task */ |
diff --git a/kernel/fork.c b/kernel/fork.c index fb9444282836..bf582f75014b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -639,6 +639,9 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk) | |||
639 | 639 | ||
640 | tsk->min_flt = tsk->maj_flt = 0; | 640 | tsk->min_flt = tsk->maj_flt = 0; |
641 | tsk->nvcsw = tsk->nivcsw = 0; | 641 | tsk->nvcsw = tsk->nivcsw = 0; |
642 | #ifdef CONFIG_DETECT_HUNG_TASK | ||
643 | tsk->last_switch_count = tsk->nvcsw + tsk->nivcsw; | ||
644 | #endif | ||
642 | 645 | ||
643 | tsk->mm = NULL; | 646 | tsk->mm = NULL; |
644 | tsk->active_mm = NULL; | 647 | tsk->active_mm = NULL; |
@@ -1041,11 +1044,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1041 | 1044 | ||
1042 | p->default_timer_slack_ns = current->timer_slack_ns; | 1045 | p->default_timer_slack_ns = current->timer_slack_ns; |
1043 | 1046 | ||
1044 | #ifdef CONFIG_DETECT_HUNG_TASK | ||
1045 | p->last_switch_count = 0; | ||
1046 | p->last_switch_timestamp = 0; | ||
1047 | #endif | ||
1048 | |||
1049 | task_io_accounting_init(&p->ioac); | 1047 | task_io_accounting_init(&p->ioac); |
1050 | acct_clear_integrals(p); | 1048 | acct_clear_integrals(p); |
1051 | 1049 | ||
diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 3951a80e7cbe..0c924de58cb2 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c | |||
@@ -34,7 +34,6 @@ unsigned long __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; | |||
34 | * Zero means infinite timeout - no checking done: | 34 | * Zero means infinite timeout - no checking done: |
35 | */ | 35 | */ |
36 | unsigned long __read_mostly sysctl_hung_task_timeout_secs = 120; | 36 | unsigned long __read_mostly sysctl_hung_task_timeout_secs = 120; |
37 | static unsigned long __read_mostly hung_task_poll_jiffies; | ||
38 | 37 | ||
39 | unsigned long __read_mostly sysctl_hung_task_warnings = 10; | 38 | unsigned long __read_mostly sysctl_hung_task_warnings = 10; |
40 | 39 | ||
@@ -69,33 +68,17 @@ static struct notifier_block panic_block = { | |||
69 | .notifier_call = hung_task_panic, | 68 | .notifier_call = hung_task_panic, |
70 | }; | 69 | }; |
71 | 70 | ||
72 | /* | 71 | static void check_hung_task(struct task_struct *t, unsigned long timeout) |
73 | * Returns seconds, approximately. We don't need nanosecond | ||
74 | * resolution, and we don't need to waste time with a big divide when | ||
75 | * 2^30ns == 1.074s. | ||
76 | */ | ||
77 | static unsigned long get_timestamp(void) | ||
78 | { | ||
79 | int this_cpu = raw_smp_processor_id(); | ||
80 | |||
81 | return cpu_clock(this_cpu) >> 30LL; /* 2^30 ~= 10^9 */ | ||
82 | } | ||
83 | |||
84 | static void check_hung_task(struct task_struct *t, unsigned long now, | ||
85 | unsigned long timeout) | ||
86 | { | 72 | { |
87 | unsigned long switch_count = t->nvcsw + t->nivcsw; | 73 | unsigned long switch_count = t->nvcsw + t->nivcsw; |
88 | 74 | ||
89 | if (t->flags & PF_FROZEN) | 75 | if (t->flags & PF_FROZEN) |
90 | return; | 76 | return; |
91 | 77 | ||
92 | if (switch_count != t->last_switch_count || !t->last_switch_timestamp) { | 78 | if (switch_count != t->last_switch_count) { |
93 | t->last_switch_count = switch_count; | 79 | t->last_switch_count = switch_count; |
94 | t->last_switch_timestamp = now; | ||
95 | return; | 80 | return; |
96 | } | 81 | } |
97 | if ((long)(now - t->last_switch_timestamp) < timeout) | ||
98 | return; | ||
99 | if (!sysctl_hung_task_warnings) | 82 | if (!sysctl_hung_task_warnings) |
100 | return; | 83 | return; |
101 | sysctl_hung_task_warnings--; | 84 | sysctl_hung_task_warnings--; |
@@ -111,7 +94,6 @@ static void check_hung_task(struct task_struct *t, unsigned long now, | |||
111 | sched_show_task(t); | 94 | sched_show_task(t); |
112 | __debug_show_held_locks(t); | 95 | __debug_show_held_locks(t); |
113 | 96 | ||
114 | t->last_switch_timestamp = now; | ||
115 | touch_nmi_watchdog(); | 97 | touch_nmi_watchdog(); |
116 | 98 | ||
117 | if (sysctl_hung_task_panic) | 99 | if (sysctl_hung_task_panic) |
@@ -145,7 +127,6 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) | |||
145 | { | 127 | { |
146 | int max_count = sysctl_hung_task_check_count; | 128 | int max_count = sysctl_hung_task_check_count; |
147 | int batch_count = HUNG_TASK_BATCHING; | 129 | int batch_count = HUNG_TASK_BATCHING; |
148 | unsigned long now = get_timestamp(); | ||
149 | struct task_struct *g, *t; | 130 | struct task_struct *g, *t; |
150 | 131 | ||
151 | /* | 132 | /* |
@@ -168,19 +149,16 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) | |||
168 | } | 149 | } |
169 | /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ | 150 | /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ |
170 | if (t->state == TASK_UNINTERRUPTIBLE) | 151 | if (t->state == TASK_UNINTERRUPTIBLE) |
171 | check_hung_task(t, now, timeout); | 152 | check_hung_task(t, timeout); |
172 | } while_each_thread(g, t); | 153 | } while_each_thread(g, t); |
173 | unlock: | 154 | unlock: |
174 | rcu_read_unlock(); | 155 | rcu_read_unlock(); |
175 | } | 156 | } |
176 | 157 | ||
177 | static void update_poll_jiffies(void) | 158 | static unsigned long timeout_jiffies(unsigned long timeout) |
178 | { | 159 | { |
179 | /* timeout of 0 will disable the watchdog */ | 160 | /* timeout of 0 will disable the watchdog */ |
180 | if (sysctl_hung_task_timeout_secs == 0) | 161 | return timeout ? timeout * HZ : MAX_SCHEDULE_TIMEOUT; |
181 | hung_task_poll_jiffies = MAX_SCHEDULE_TIMEOUT; | ||
182 | else | ||
183 | hung_task_poll_jiffies = sysctl_hung_task_timeout_secs * HZ / 2; | ||
184 | } | 162 | } |
185 | 163 | ||
186 | /* | 164 | /* |
@@ -197,8 +175,6 @@ int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, | |||
197 | if (ret || !write) | 175 | if (ret || !write) |
198 | goto out; | 176 | goto out; |
199 | 177 | ||
200 | update_poll_jiffies(); | ||
201 | |||
202 | wake_up_process(watchdog_task); | 178 | wake_up_process(watchdog_task); |
203 | 179 | ||
204 | out: | 180 | out: |
@@ -211,20 +187,14 @@ int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, | |||
211 | static int watchdog(void *dummy) | 187 | static int watchdog(void *dummy) |
212 | { | 188 | { |
213 | set_user_nice(current, 0); | 189 | set_user_nice(current, 0); |
214 | update_poll_jiffies(); | ||
215 | 190 | ||
216 | for ( ; ; ) { | 191 | for ( ; ; ) { |
217 | unsigned long timeout; | 192 | unsigned long timeout = sysctl_hung_task_timeout_secs; |
218 | 193 | ||
219 | while (schedule_timeout_interruptible(hung_task_poll_jiffies)); | 194 | while (schedule_timeout_interruptible(timeout_jiffies(timeout))) |
195 | timeout = sysctl_hung_task_timeout_secs; | ||
220 | 196 | ||
221 | /* | 197 | check_hung_uninterruptible_tasks(timeout); |
222 | * Need to cache timeout here to avoid timeout being set | ||
223 | * to 0 via sysctl while inside check_hung_*_tasks(). | ||
224 | */ | ||
225 | timeout = sysctl_hung_task_timeout_secs; | ||
226 | if (timeout) | ||
227 | check_hung_uninterruptible_tasks(timeout); | ||
228 | } | 198 | } |
229 | 199 | ||
230 | return 0; | 200 | return 0; |