diff options
Diffstat (limited to 'kernel')
75 files changed, 3201 insertions, 1756 deletions
diff --git a/kernel/Kconfig.hz b/kernel/Kconfig.hz index 382dd5a8b2d7..94fabd534b03 100644 --- a/kernel/Kconfig.hz +++ b/kernel/Kconfig.hz | |||
@@ -55,4 +55,4 @@ config HZ | |||
55 | default 1000 if HZ_1000 | 55 | default 1000 if HZ_1000 |
56 | 56 | ||
57 | config SCHED_HRTICK | 57 | config SCHED_HRTICK |
58 | def_bool HIGH_RES_TIMERS && USE_GENERIC_SMP_HELPERS | 58 | def_bool HIGH_RES_TIMERS && (!SMP || USE_GENERIC_SMP_HELPERS) |
diff --git a/kernel/Makefile b/kernel/Makefile index 54f69837d35a..4e1d7df7c3e2 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -84,6 +84,7 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o | |||
84 | obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o | 84 | obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o |
85 | obj-$(CONFIG_MARKERS) += marker.o | 85 | obj-$(CONFIG_MARKERS) += marker.o |
86 | obj-$(CONFIG_LATENCYTOP) += latencytop.o | 86 | obj-$(CONFIG_LATENCYTOP) += latencytop.o |
87 | obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o | ||
87 | obj-$(CONFIG_FTRACE) += trace/ | 88 | obj-$(CONFIG_FTRACE) += trace/ |
88 | obj-$(CONFIG_TRACING) += trace/ | 89 | obj-$(CONFIG_TRACING) += trace/ |
89 | obj-$(CONFIG_SMP) += sched_cpupri.o | 90 | obj-$(CONFIG_SMP) += sched_cpupri.o |
diff --git a/kernel/audit.c b/kernel/audit.c index e092f1c0ce30..4414e93d8750 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -707,12 +707,14 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
707 | if (status_get->mask & AUDIT_STATUS_ENABLED) { | 707 | if (status_get->mask & AUDIT_STATUS_ENABLED) { |
708 | err = audit_set_enabled(status_get->enabled, | 708 | err = audit_set_enabled(status_get->enabled, |
709 | loginuid, sessionid, sid); | 709 | loginuid, sessionid, sid); |
710 | if (err < 0) return err; | 710 | if (err < 0) |
711 | return err; | ||
711 | } | 712 | } |
712 | if (status_get->mask & AUDIT_STATUS_FAILURE) { | 713 | if (status_get->mask & AUDIT_STATUS_FAILURE) { |
713 | err = audit_set_failure(status_get->failure, | 714 | err = audit_set_failure(status_get->failure, |
714 | loginuid, sessionid, sid); | 715 | loginuid, sessionid, sid); |
715 | if (err < 0) return err; | 716 | if (err < 0) |
717 | return err; | ||
716 | } | 718 | } |
717 | if (status_get->mask & AUDIT_STATUS_PID) { | 719 | if (status_get->mask & AUDIT_STATUS_PID) { |
718 | int new_pid = status_get->pid; | 720 | int new_pid = status_get->pid; |
@@ -725,9 +727,12 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
725 | audit_pid = new_pid; | 727 | audit_pid = new_pid; |
726 | audit_nlk_pid = NETLINK_CB(skb).pid; | 728 | audit_nlk_pid = NETLINK_CB(skb).pid; |
727 | } | 729 | } |
728 | if (status_get->mask & AUDIT_STATUS_RATE_LIMIT) | 730 | if (status_get->mask & AUDIT_STATUS_RATE_LIMIT) { |
729 | err = audit_set_rate_limit(status_get->rate_limit, | 731 | err = audit_set_rate_limit(status_get->rate_limit, |
730 | loginuid, sessionid, sid); | 732 | loginuid, sessionid, sid); |
733 | if (err < 0) | ||
734 | return err; | ||
735 | } | ||
731 | if (status_get->mask & AUDIT_STATUS_BACKLOG_LIMIT) | 736 | if (status_get->mask & AUDIT_STATUS_BACKLOG_LIMIT) |
732 | err = audit_set_backlog_limit(status_get->backlog_limit, | 737 | err = audit_set_backlog_limit(status_get->backlog_limit, |
733 | loginuid, sessionid, sid); | 738 | loginuid, sessionid, sid); |
@@ -1366,7 +1371,7 @@ int audit_string_contains_control(const char *string, size_t len) | |||
1366 | { | 1371 | { |
1367 | const unsigned char *p; | 1372 | const unsigned char *p; |
1368 | for (p = string; p < (const unsigned char *)string + len && *p; p++) { | 1373 | for (p = string; p < (const unsigned char *)string + len && *p; p++) { |
1369 | if (*p == '"' || *p < 0x21 || *p > 0x7f) | 1374 | if (*p == '"' || *p < 0x21 || *p > 0x7e) |
1370 | return 1; | 1375 | return 1; |
1371 | } | 1376 | } |
1372 | return 0; | 1377 | return 0; |
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 98c50cc671bb..b7d354e2b0ef 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
@@ -1022,8 +1022,11 @@ static void audit_update_watch(struct audit_parent *parent, | |||
1022 | struct audit_buffer *ab; | 1022 | struct audit_buffer *ab; |
1023 | ab = audit_log_start(NULL, GFP_KERNEL, | 1023 | ab = audit_log_start(NULL, GFP_KERNEL, |
1024 | AUDIT_CONFIG_CHANGE); | 1024 | AUDIT_CONFIG_CHANGE); |
1025 | audit_log_format(ab, "auid=%u ses=%u", | ||
1026 | audit_get_loginuid(current), | ||
1027 | audit_get_sessionid(current)); | ||
1025 | audit_log_format(ab, | 1028 | audit_log_format(ab, |
1026 | "op=updated rules specifying path="); | 1029 | " op=updated rules specifying path="); |
1027 | audit_log_untrustedstring(ab, owatch->path); | 1030 | audit_log_untrustedstring(ab, owatch->path); |
1028 | audit_log_format(ab, " with dev=%u ino=%lu\n", | 1031 | audit_log_format(ab, " with dev=%u ino=%lu\n", |
1029 | dev, ino); | 1032 | dev, ino); |
@@ -1058,7 +1061,10 @@ static void audit_remove_parent_watches(struct audit_parent *parent) | |||
1058 | struct audit_buffer *ab; | 1061 | struct audit_buffer *ab; |
1059 | ab = audit_log_start(NULL, GFP_KERNEL, | 1062 | ab = audit_log_start(NULL, GFP_KERNEL, |
1060 | AUDIT_CONFIG_CHANGE); | 1063 | AUDIT_CONFIG_CHANGE); |
1061 | audit_log_format(ab, "op=remove rule path="); | 1064 | audit_log_format(ab, "auid=%u ses=%u", |
1065 | audit_get_loginuid(current), | ||
1066 | audit_get_sessionid(current)); | ||
1067 | audit_log_format(ab, " op=remove rule path="); | ||
1062 | audit_log_untrustedstring(ab, w->path); | 1068 | audit_log_untrustedstring(ab, w->path); |
1063 | if (r->filterkey) { | 1069 | if (r->filterkey) { |
1064 | audit_log_format(ab, " key="); | 1070 | audit_log_format(ab, " key="); |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 4699950e65bd..59cedfb040e7 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -243,7 +243,11 @@ static inline int open_arg(int flags, int mask) | |||
243 | 243 | ||
244 | static int audit_match_perm(struct audit_context *ctx, int mask) | 244 | static int audit_match_perm(struct audit_context *ctx, int mask) |
245 | { | 245 | { |
246 | unsigned n = ctx->major; | 246 | unsigned n; |
247 | if (unlikely(!ctx)) | ||
248 | return 0; | ||
249 | |||
250 | n = ctx->major; | ||
247 | switch (audit_classify_syscall(ctx->arch, n)) { | 251 | switch (audit_classify_syscall(ctx->arch, n)) { |
248 | case 0: /* native */ | 252 | case 0: /* native */ |
249 | if ((mask & AUDIT_PERM_WRITE) && | 253 | if ((mask & AUDIT_PERM_WRITE) && |
@@ -284,6 +288,10 @@ static int audit_match_filetype(struct audit_context *ctx, int which) | |||
284 | { | 288 | { |
285 | unsigned index = which & ~S_IFMT; | 289 | unsigned index = which & ~S_IFMT; |
286 | mode_t mode = which & S_IFMT; | 290 | mode_t mode = which & S_IFMT; |
291 | |||
292 | if (unlikely(!ctx)) | ||
293 | return 0; | ||
294 | |||
287 | if (index >= ctx->name_count) | 295 | if (index >= ctx->name_count) |
288 | return 0; | 296 | return 0; |
289 | if (ctx->names[index].ino == -1) | 297 | if (ctx->names[index].ino == -1) |
@@ -610,7 +618,7 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
610 | if (!result) | 618 | if (!result) |
611 | return 0; | 619 | return 0; |
612 | } | 620 | } |
613 | if (rule->filterkey) | 621 | if (rule->filterkey && ctx) |
614 | ctx->filterkey = kstrdup(rule->filterkey, GFP_ATOMIC); | 622 | ctx->filterkey = kstrdup(rule->filterkey, GFP_ATOMIC); |
615 | switch (rule->action) { | 623 | switch (rule->action) { |
616 | case AUDIT_NEVER: *state = AUDIT_DISABLED; break; | 624 | case AUDIT_NEVER: *state = AUDIT_DISABLED; break; |
@@ -2375,7 +2383,7 @@ int __audit_signal_info(int sig, struct task_struct *t) | |||
2375 | struct audit_context *ctx = tsk->audit_context; | 2383 | struct audit_context *ctx = tsk->audit_context; |
2376 | 2384 | ||
2377 | if (audit_pid && t->tgid == audit_pid) { | 2385 | if (audit_pid && t->tgid == audit_pid) { |
2378 | if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1) { | 2386 | if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1 || sig == SIGUSR2) { |
2379 | audit_sig_pid = tsk->pid; | 2387 | audit_sig_pid = tsk->pid; |
2380 | if (tsk->loginuid != -1) | 2388 | if (tsk->loginuid != -1) |
2381 | audit_sig_uid = tsk->loginuid; | 2389 | audit_sig_uid = tsk->loginuid; |
diff --git a/kernel/capability.c b/kernel/capability.c index 0101e847603e..33e51e78c2d8 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
@@ -486,17 +486,22 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | |||
486 | return ret; | 486 | return ret; |
487 | } | 487 | } |
488 | 488 | ||
489 | int __capable(struct task_struct *t, int cap) | 489 | /** |
490 | * capable - Determine if the current task has a superior capability in effect | ||
491 | * @cap: The capability to be tested for | ||
492 | * | ||
493 | * Return true if the current task has the given superior capability currently | ||
494 | * available for use, false if not. | ||
495 | * | ||
496 | * This sets PF_SUPERPRIV on the task if the capability is available on the | ||
497 | * assumption that it's about to be used. | ||
498 | */ | ||
499 | int capable(int cap) | ||
490 | { | 500 | { |
491 | if (security_capable(t, cap) == 0) { | 501 | if (has_capability(current, cap)) { |
492 | t->flags |= PF_SUPERPRIV; | 502 | current->flags |= PF_SUPERPRIV; |
493 | return 1; | 503 | return 1; |
494 | } | 504 | } |
495 | return 0; | 505 | return 0; |
496 | } | 506 | } |
497 | |||
498 | int capable(int cap) | ||
499 | { | ||
500 | return __capable(current, cap); | ||
501 | } | ||
502 | EXPORT_SYMBOL(capable); | 507 | EXPORT_SYMBOL(capable); |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 66ec9fd21e0c..a0123d75ec9a 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <linux/delayacct.h> | 45 | #include <linux/delayacct.h> |
46 | #include <linux/cgroupstats.h> | 46 | #include <linux/cgroupstats.h> |
47 | #include <linux/hash.h> | 47 | #include <linux/hash.h> |
48 | #include <linux/namei.h> | ||
48 | 49 | ||
49 | #include <asm/atomic.h> | 50 | #include <asm/atomic.h> |
50 | 51 | ||
@@ -354,6 +355,17 @@ static struct css_set *find_existing_css_set( | |||
354 | return NULL; | 355 | return NULL; |
355 | } | 356 | } |
356 | 357 | ||
358 | static void free_cg_links(struct list_head *tmp) | ||
359 | { | ||
360 | struct cg_cgroup_link *link; | ||
361 | struct cg_cgroup_link *saved_link; | ||
362 | |||
363 | list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) { | ||
364 | list_del(&link->cgrp_link_list); | ||
365 | kfree(link); | ||
366 | } | ||
367 | } | ||
368 | |||
357 | /* | 369 | /* |
358 | * allocate_cg_links() allocates "count" cg_cgroup_link structures | 370 | * allocate_cg_links() allocates "count" cg_cgroup_link structures |
359 | * and chains them on tmp through their cgrp_link_list fields. Returns 0 on | 371 | * and chains them on tmp through their cgrp_link_list fields. Returns 0 on |
@@ -362,17 +374,12 @@ static struct css_set *find_existing_css_set( | |||
362 | static int allocate_cg_links(int count, struct list_head *tmp) | 374 | static int allocate_cg_links(int count, struct list_head *tmp) |
363 | { | 375 | { |
364 | struct cg_cgroup_link *link; | 376 | struct cg_cgroup_link *link; |
365 | struct cg_cgroup_link *saved_link; | ||
366 | int i; | 377 | int i; |
367 | INIT_LIST_HEAD(tmp); | 378 | INIT_LIST_HEAD(tmp); |
368 | for (i = 0; i < count; i++) { | 379 | for (i = 0; i < count; i++) { |
369 | link = kmalloc(sizeof(*link), GFP_KERNEL); | 380 | link = kmalloc(sizeof(*link), GFP_KERNEL); |
370 | if (!link) { | 381 | if (!link) { |
371 | list_for_each_entry_safe(link, saved_link, tmp, | 382 | free_cg_links(tmp); |
372 | cgrp_link_list) { | ||
373 | list_del(&link->cgrp_link_list); | ||
374 | kfree(link); | ||
375 | } | ||
376 | return -ENOMEM; | 383 | return -ENOMEM; |
377 | } | 384 | } |
378 | list_add(&link->cgrp_link_list, tmp); | 385 | list_add(&link->cgrp_link_list, tmp); |
@@ -380,17 +387,6 @@ static int allocate_cg_links(int count, struct list_head *tmp) | |||
380 | return 0; | 387 | return 0; |
381 | } | 388 | } |
382 | 389 | ||
383 | static void free_cg_links(struct list_head *tmp) | ||
384 | { | ||
385 | struct cg_cgroup_link *link; | ||
386 | struct cg_cgroup_link *saved_link; | ||
387 | |||
388 | list_for_each_entry_safe(link, saved_link, tmp, cgrp_link_list) { | ||
389 | list_del(&link->cgrp_link_list); | ||
390 | kfree(link); | ||
391 | } | ||
392 | } | ||
393 | |||
394 | /* | 390 | /* |
395 | * find_css_set() takes an existing cgroup group and a | 391 | * find_css_set() takes an existing cgroup group and a |
396 | * cgroup object, and returns a css_set object that's | 392 | * cgroup object, and returns a css_set object that's |
@@ -955,7 +951,6 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
955 | struct super_block *sb; | 951 | struct super_block *sb; |
956 | struct cgroupfs_root *root; | 952 | struct cgroupfs_root *root; |
957 | struct list_head tmp_cg_links; | 953 | struct list_head tmp_cg_links; |
958 | INIT_LIST_HEAD(&tmp_cg_links); | ||
959 | 954 | ||
960 | /* First find the desired set of subsystems */ | 955 | /* First find the desired set of subsystems */ |
961 | ret = parse_cgroupfs_options(data, &opts); | 956 | ret = parse_cgroupfs_options(data, &opts); |
@@ -1423,14 +1418,17 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft, | |||
1423 | if (buffer == NULL) | 1418 | if (buffer == NULL) |
1424 | return -ENOMEM; | 1419 | return -ENOMEM; |
1425 | } | 1420 | } |
1426 | if (nbytes && copy_from_user(buffer, userbuf, nbytes)) | 1421 | if (nbytes && copy_from_user(buffer, userbuf, nbytes)) { |
1427 | return -EFAULT; | 1422 | retval = -EFAULT; |
1423 | goto out; | ||
1424 | } | ||
1428 | 1425 | ||
1429 | buffer[nbytes] = 0; /* nul-terminate */ | 1426 | buffer[nbytes] = 0; /* nul-terminate */ |
1430 | strstrip(buffer); | 1427 | strstrip(buffer); |
1431 | retval = cft->write_string(cgrp, cft, buffer); | 1428 | retval = cft->write_string(cgrp, cft, buffer); |
1432 | if (!retval) | 1429 | if (!retval) |
1433 | retval = nbytes; | 1430 | retval = nbytes; |
1431 | out: | ||
1434 | if (buffer != local_buffer) | 1432 | if (buffer != local_buffer) |
1435 | kfree(buffer); | 1433 | kfree(buffer); |
1436 | return retval; | 1434 | return retval; |
@@ -1529,7 +1527,7 @@ static int cgroup_seqfile_show(struct seq_file *m, void *arg) | |||
1529 | return cft->read_seq_string(state->cgroup, cft, m); | 1527 | return cft->read_seq_string(state->cgroup, cft, m); |
1530 | } | 1528 | } |
1531 | 1529 | ||
1532 | int cgroup_seqfile_release(struct inode *inode, struct file *file) | 1530 | static int cgroup_seqfile_release(struct inode *inode, struct file *file) |
1533 | { | 1531 | { |
1534 | struct seq_file *seq = file->private_data; | 1532 | struct seq_file *seq = file->private_data; |
1535 | kfree(seq->private); | 1533 | kfree(seq->private); |
@@ -2370,7 +2368,7 @@ static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
2370 | return cgroup_create(c_parent, dentry, mode | S_IFDIR); | 2368 | return cgroup_create(c_parent, dentry, mode | S_IFDIR); |
2371 | } | 2369 | } |
2372 | 2370 | ||
2373 | static inline int cgroup_has_css_refs(struct cgroup *cgrp) | 2371 | static int cgroup_has_css_refs(struct cgroup *cgrp) |
2374 | { | 2372 | { |
2375 | /* Check the reference count on each subsystem. Since we | 2373 | /* Check the reference count on each subsystem. Since we |
2376 | * already established that there are no tasks in the | 2374 | * already established that there are no tasks in the |
@@ -2740,14 +2738,15 @@ void cgroup_fork_callbacks(struct task_struct *child) | |||
2740 | */ | 2738 | */ |
2741 | void cgroup_mm_owner_callbacks(struct task_struct *old, struct task_struct *new) | 2739 | void cgroup_mm_owner_callbacks(struct task_struct *old, struct task_struct *new) |
2742 | { | 2740 | { |
2743 | struct cgroup *oldcgrp, *newcgrp; | 2741 | struct cgroup *oldcgrp, *newcgrp = NULL; |
2744 | 2742 | ||
2745 | if (need_mm_owner_callback) { | 2743 | if (need_mm_owner_callback) { |
2746 | int i; | 2744 | int i; |
2747 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 2745 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
2748 | struct cgroup_subsys *ss = subsys[i]; | 2746 | struct cgroup_subsys *ss = subsys[i]; |
2749 | oldcgrp = task_cgroup(old, ss->subsys_id); | 2747 | oldcgrp = task_cgroup(old, ss->subsys_id); |
2750 | newcgrp = task_cgroup(new, ss->subsys_id); | 2748 | if (new) |
2749 | newcgrp = task_cgroup(new, ss->subsys_id); | ||
2751 | if (oldcgrp == newcgrp) | 2750 | if (oldcgrp == newcgrp) |
2752 | continue; | 2751 | continue; |
2753 | if (ss->mm_owner_changed) | 2752 | if (ss->mm_owner_changed) |
diff --git a/kernel/cpu.c b/kernel/cpu.c index 10ba5f1004a5..86d49045daed 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -199,13 +199,14 @@ static int __ref take_cpu_down(void *_param) | |||
199 | struct take_cpu_down_param *param = _param; | 199 | struct take_cpu_down_param *param = _param; |
200 | int err; | 200 | int err; |
201 | 201 | ||
202 | raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod, | ||
203 | param->hcpu); | ||
204 | /* Ensure this CPU doesn't handle any more interrupts. */ | 202 | /* Ensure this CPU doesn't handle any more interrupts. */ |
205 | err = __cpu_disable(); | 203 | err = __cpu_disable(); |
206 | if (err < 0) | 204 | if (err < 0) |
207 | return err; | 205 | return err; |
208 | 206 | ||
207 | raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod, | ||
208 | param->hcpu); | ||
209 | |||
209 | /* Force idle task to run as soon as we yield: it should | 210 | /* Force idle task to run as soon as we yield: it should |
210 | immediately notice cpu is offline and die quickly. */ | 211 | immediately notice cpu is offline and die quickly. */ |
211 | sched_idle_next(); | 212 | sched_idle_next(); |
@@ -216,7 +217,6 @@ static int __ref take_cpu_down(void *_param) | |||
216 | static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | 217 | static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) |
217 | { | 218 | { |
218 | int err, nr_calls = 0; | 219 | int err, nr_calls = 0; |
219 | struct task_struct *p; | ||
220 | cpumask_t old_allowed, tmp; | 220 | cpumask_t old_allowed, tmp; |
221 | void *hcpu = (void *)(long)cpu; | 221 | void *hcpu = (void *)(long)cpu; |
222 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; | 222 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; |
@@ -249,21 +249,18 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
249 | cpus_setall(tmp); | 249 | cpus_setall(tmp); |
250 | cpu_clear(cpu, tmp); | 250 | cpu_clear(cpu, tmp); |
251 | set_cpus_allowed_ptr(current, &tmp); | 251 | set_cpus_allowed_ptr(current, &tmp); |
252 | tmp = cpumask_of_cpu(cpu); | ||
252 | 253 | ||
253 | p = __stop_machine_run(take_cpu_down, &tcd_param, cpu); | 254 | err = __stop_machine(take_cpu_down, &tcd_param, &tmp); |
254 | 255 | if (err) { | |
255 | if (IS_ERR(p) || cpu_online(cpu)) { | ||
256 | /* CPU didn't die: tell everyone. Can't complain. */ | 256 | /* CPU didn't die: tell everyone. Can't complain. */ |
257 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, | 257 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, |
258 | hcpu) == NOTIFY_BAD) | 258 | hcpu) == NOTIFY_BAD) |
259 | BUG(); | 259 | BUG(); |
260 | 260 | ||
261 | if (IS_ERR(p)) { | 261 | goto out_allowed; |
262 | err = PTR_ERR(p); | ||
263 | goto out_allowed; | ||
264 | } | ||
265 | goto out_thread; | ||
266 | } | 262 | } |
263 | BUG_ON(cpu_online(cpu)); | ||
267 | 264 | ||
268 | /* Wait for it to sleep (leaving idle task). */ | 265 | /* Wait for it to sleep (leaving idle task). */ |
269 | while (!idle_cpu(cpu)) | 266 | while (!idle_cpu(cpu)) |
@@ -279,8 +276,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
279 | 276 | ||
280 | check_for_tasks(cpu); | 277 | check_for_tasks(cpu); |
281 | 278 | ||
282 | out_thread: | ||
283 | err = kthread_stop(p); | ||
284 | out_allowed: | 279 | out_allowed: |
285 | set_cpus_allowed_ptr(current, &old_allowed); | 280 | set_cpus_allowed_ptr(current, &old_allowed); |
286 | out_release: | 281 | out_release: |
@@ -355,6 +350,8 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen) | |||
355 | goto out_notify; | 350 | goto out_notify; |
356 | BUG_ON(!cpu_online(cpu)); | 351 | BUG_ON(!cpu_online(cpu)); |
357 | 352 | ||
353 | cpu_set(cpu, cpu_active_map); | ||
354 | |||
358 | /* Now call notifier in preparation. */ | 355 | /* Now call notifier in preparation. */ |
359 | raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu); | 356 | raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu); |
360 | 357 | ||
@@ -373,7 +370,7 @@ int __cpuinit cpu_up(unsigned int cpu) | |||
373 | if (!cpu_isset(cpu, cpu_possible_map)) { | 370 | if (!cpu_isset(cpu, cpu_possible_map)) { |
374 | printk(KERN_ERR "can't online cpu %d because it is not " | 371 | printk(KERN_ERR "can't online cpu %d because it is not " |
375 | "configured as may-hotadd at boot time\n", cpu); | 372 | "configured as may-hotadd at boot time\n", cpu); |
376 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) || defined(CONFIG_S390) | 373 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) |
377 | printk(KERN_ERR "please check additional_cpus= boot " | 374 | printk(KERN_ERR "please check additional_cpus= boot " |
378 | "parameter\n"); | 375 | "parameter\n"); |
379 | #endif | 376 | #endif |
@@ -389,9 +386,6 @@ int __cpuinit cpu_up(unsigned int cpu) | |||
389 | 386 | ||
390 | err = _cpu_up(cpu, 0); | 387 | err = _cpu_up(cpu, 0); |
391 | 388 | ||
392 | if (cpu_online(cpu)) | ||
393 | cpu_set(cpu, cpu_active_map); | ||
394 | |||
395 | out: | 389 | out: |
396 | cpu_maps_update_done(); | 390 | cpu_maps_update_done(); |
397 | return err; | 391 | return err; |
@@ -460,4 +454,48 @@ out: | |||
460 | } | 454 | } |
461 | #endif /* CONFIG_PM_SLEEP_SMP */ | 455 | #endif /* CONFIG_PM_SLEEP_SMP */ |
462 | 456 | ||
457 | /** | ||
458 | * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers | ||
459 | * @cpu: cpu that just started | ||
460 | * | ||
461 | * This function calls the cpu_chain notifiers with CPU_STARTING. | ||
462 | * It must be called by the arch code on the new cpu, before the new cpu | ||
463 | * enables interrupts and before the "boot" cpu returns from __cpu_up(). | ||
464 | */ | ||
465 | void notify_cpu_starting(unsigned int cpu) | ||
466 | { | ||
467 | unsigned long val = CPU_STARTING; | ||
468 | |||
469 | #ifdef CONFIG_PM_SLEEP_SMP | ||
470 | if (cpu_isset(cpu, frozen_cpus)) | ||
471 | val = CPU_STARTING_FROZEN; | ||
472 | #endif /* CONFIG_PM_SLEEP_SMP */ | ||
473 | raw_notifier_call_chain(&cpu_chain, val, (void *)(long)cpu); | ||
474 | } | ||
475 | |||
463 | #endif /* CONFIG_SMP */ | 476 | #endif /* CONFIG_SMP */ |
477 | |||
478 | /* | ||
479 | * cpu_bit_bitmap[] is a special, "compressed" data structure that | ||
480 | * represents all NR_CPUS bits binary values of 1<<nr. | ||
481 | * | ||
482 | * It is used by cpumask_of_cpu() to get a constant address to a CPU | ||
483 | * mask value that has a single bit set only. | ||
484 | */ | ||
485 | |||
486 | /* cpu_bit_bitmap[0] is empty - so we can back into it */ | ||
487 | #define MASK_DECLARE_1(x) [x+1][0] = 1UL << (x) | ||
488 | #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1) | ||
489 | #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2) | ||
490 | #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4) | ||
491 | |||
492 | const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = { | ||
493 | |||
494 | MASK_DECLARE_8(0), MASK_DECLARE_8(8), | ||
495 | MASK_DECLARE_8(16), MASK_DECLARE_8(24), | ||
496 | #if BITS_PER_LONG > 32 | ||
497 | MASK_DECLARE_8(32), MASK_DECLARE_8(40), | ||
498 | MASK_DECLARE_8(48), MASK_DECLARE_8(56), | ||
499 | #endif | ||
500 | }; | ||
501 | EXPORT_SYMBOL_GPL(cpu_bit_bitmap); | ||
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 91cf85b36dd5..eab7bd6628e0 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -14,6 +14,8 @@ | |||
14 | * 2003-10-22 Updates by Stephen Hemminger. | 14 | * 2003-10-22 Updates by Stephen Hemminger. |
15 | * 2004 May-July Rework by Paul Jackson. | 15 | * 2004 May-July Rework by Paul Jackson. |
16 | * 2006 Rework by Paul Menage to use generic cgroups | 16 | * 2006 Rework by Paul Menage to use generic cgroups |
17 | * 2008 Rework of the scheduler domains and CPU hotplug handling | ||
18 | * by Max Krasnyansky | ||
17 | * | 19 | * |
18 | * This file is subject to the terms and conditions of the GNU General Public | 20 | * This file is subject to the terms and conditions of the GNU General Public |
19 | * License. See the file COPYING in the main directory of the Linux | 21 | * License. See the file COPYING in the main directory of the Linux |
@@ -54,7 +56,6 @@ | |||
54 | #include <asm/uaccess.h> | 56 | #include <asm/uaccess.h> |
55 | #include <asm/atomic.h> | 57 | #include <asm/atomic.h> |
56 | #include <linux/mutex.h> | 58 | #include <linux/mutex.h> |
57 | #include <linux/kfifo.h> | ||
58 | #include <linux/workqueue.h> | 59 | #include <linux/workqueue.h> |
59 | #include <linux/cgroup.h> | 60 | #include <linux/cgroup.h> |
60 | 61 | ||
@@ -237,9 +238,11 @@ static struct cpuset top_cpuset = { | |||
237 | 238 | ||
238 | static DEFINE_MUTEX(callback_mutex); | 239 | static DEFINE_MUTEX(callback_mutex); |
239 | 240 | ||
240 | /* This is ugly, but preserves the userspace API for existing cpuset | 241 | /* |
242 | * This is ugly, but preserves the userspace API for existing cpuset | ||
241 | * users. If someone tries to mount the "cpuset" filesystem, we | 243 | * users. If someone tries to mount the "cpuset" filesystem, we |
242 | * silently switch it to mount "cgroup" instead */ | 244 | * silently switch it to mount "cgroup" instead |
245 | */ | ||
243 | static int cpuset_get_sb(struct file_system_type *fs_type, | 246 | static int cpuset_get_sb(struct file_system_type *fs_type, |
244 | int flags, const char *unused_dev_name, | 247 | int flags, const char *unused_dev_name, |
245 | void *data, struct vfsmount *mnt) | 248 | void *data, struct vfsmount *mnt) |
@@ -474,10 +477,9 @@ static int validate_change(const struct cpuset *cur, const struct cpuset *trial) | |||
474 | } | 477 | } |
475 | 478 | ||
476 | /* | 479 | /* |
477 | * Helper routine for rebuild_sched_domains(). | 480 | * Helper routine for generate_sched_domains(). |
478 | * Do cpusets a, b have overlapping cpus_allowed masks? | 481 | * Do cpusets a, b have overlapping cpus_allowed masks? |
479 | */ | 482 | */ |
480 | |||
481 | static int cpusets_overlap(struct cpuset *a, struct cpuset *b) | 483 | static int cpusets_overlap(struct cpuset *a, struct cpuset *b) |
482 | { | 484 | { |
483 | return cpus_intersects(a->cpus_allowed, b->cpus_allowed); | 485 | return cpus_intersects(a->cpus_allowed, b->cpus_allowed); |
@@ -486,34 +488,48 @@ static int cpusets_overlap(struct cpuset *a, struct cpuset *b) | |||
486 | static void | 488 | static void |
487 | update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c) | 489 | update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c) |
488 | { | 490 | { |
489 | if (!dattr) | ||
490 | return; | ||
491 | if (dattr->relax_domain_level < c->relax_domain_level) | 491 | if (dattr->relax_domain_level < c->relax_domain_level) |
492 | dattr->relax_domain_level = c->relax_domain_level; | 492 | dattr->relax_domain_level = c->relax_domain_level; |
493 | return; | 493 | return; |
494 | } | 494 | } |
495 | 495 | ||
496 | static void | ||
497 | update_domain_attr_tree(struct sched_domain_attr *dattr, struct cpuset *c) | ||
498 | { | ||
499 | LIST_HEAD(q); | ||
500 | |||
501 | list_add(&c->stack_list, &q); | ||
502 | while (!list_empty(&q)) { | ||
503 | struct cpuset *cp; | ||
504 | struct cgroup *cont; | ||
505 | struct cpuset *child; | ||
506 | |||
507 | cp = list_first_entry(&q, struct cpuset, stack_list); | ||
508 | list_del(q.next); | ||
509 | |||
510 | if (cpus_empty(cp->cpus_allowed)) | ||
511 | continue; | ||
512 | |||
513 | if (is_sched_load_balance(cp)) | ||
514 | update_domain_attr(dattr, cp); | ||
515 | |||
516 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { | ||
517 | child = cgroup_cs(cont); | ||
518 | list_add_tail(&child->stack_list, &q); | ||
519 | } | ||
520 | } | ||
521 | } | ||
522 | |||
496 | /* | 523 | /* |
497 | * rebuild_sched_domains() | 524 | * generate_sched_domains() |
498 | * | 525 | * |
499 | * This routine will be called to rebuild the scheduler's dynamic | 526 | * This function builds a partial partition of the systems CPUs |
500 | * sched domains: | 527 | * A 'partial partition' is a set of non-overlapping subsets whose |
501 | * - if the flag 'sched_load_balance' of any cpuset with non-empty | 528 | * union is a subset of that set. |
502 | * 'cpus' changes, | 529 | * The output of this function needs to be passed to kernel/sched.c |
503 | * - or if the 'cpus' allowed changes in any cpuset which has that | 530 | * partition_sched_domains() routine, which will rebuild the scheduler's |
504 | * flag enabled, | 531 | * load balancing domains (sched domains) as specified by that partial |
505 | * - or if the 'sched_relax_domain_level' of any cpuset which has | 532 | * partition. |
506 | * that flag enabled and with non-empty 'cpus' changes, | ||
507 | * - or if any cpuset with non-empty 'cpus' is removed, | ||
508 | * - or if a cpu gets offlined. | ||
509 | * | ||
510 | * This routine builds a partial partition of the systems CPUs | ||
511 | * (the set of non-overlappping cpumask_t's in the array 'part' | ||
512 | * below), and passes that partial partition to the kernel/sched.c | ||
513 | * partition_sched_domains() routine, which will rebuild the | ||
514 | * schedulers load balancing domains (sched domains) as specified | ||
515 | * by that partial partition. A 'partial partition' is a set of | ||
516 | * non-overlapping subsets whose union is a subset of that set. | ||
517 | * | 533 | * |
518 | * See "What is sched_load_balance" in Documentation/cpusets.txt | 534 | * See "What is sched_load_balance" in Documentation/cpusets.txt |
519 | * for a background explanation of this. | 535 | * for a background explanation of this. |
@@ -523,16 +539,10 @@ update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c) | |||
523 | * domains when operating in the severe memory shortage situations | 539 | * domains when operating in the severe memory shortage situations |
524 | * that could cause allocation failures below. | 540 | * that could cause allocation failures below. |
525 | * | 541 | * |
526 | * Call with cgroup_mutex held. May take callback_mutex during | 542 | * Must be called with cgroup_lock held. |
527 | * call due to the kfifo_alloc() and kmalloc() calls. May nest | ||
528 | * a call to the get_online_cpus()/put_online_cpus() pair. | ||
529 | * Must not be called holding callback_mutex, because we must not | ||
530 | * call get_online_cpus() while holding callback_mutex. Elsewhere | ||
531 | * the kernel nests callback_mutex inside get_online_cpus() calls. | ||
532 | * So the reverse nesting would risk an ABBA deadlock. | ||
533 | * | 543 | * |
534 | * The three key local variables below are: | 544 | * The three key local variables below are: |
535 | * q - a kfifo queue of cpuset pointers, used to implement a | 545 | * q - a linked-list queue of cpuset pointers, used to implement a |
536 | * top-down scan of all cpusets. This scan loads a pointer | 546 | * top-down scan of all cpusets. This scan loads a pointer |
537 | * to each cpuset marked is_sched_load_balance into the | 547 | * to each cpuset marked is_sched_load_balance into the |
538 | * array 'csa'. For our purposes, rebuilding the schedulers | 548 | * array 'csa'. For our purposes, rebuilding the schedulers |
@@ -564,10 +574,10 @@ update_domain_attr(struct sched_domain_attr *dattr, struct cpuset *c) | |||
564 | * element of the partition (one sched domain) to be passed to | 574 | * element of the partition (one sched domain) to be passed to |
565 | * partition_sched_domains(). | 575 | * partition_sched_domains(). |
566 | */ | 576 | */ |
567 | 577 | static int generate_sched_domains(cpumask_t **domains, | |
568 | void rebuild_sched_domains(void) | 578 | struct sched_domain_attr **attributes) |
569 | { | 579 | { |
570 | struct kfifo *q; /* queue of cpusets to be scanned */ | 580 | LIST_HEAD(q); /* queue of cpusets to be scanned */ |
571 | struct cpuset *cp; /* scans q */ | 581 | struct cpuset *cp; /* scans q */ |
572 | struct cpuset **csa; /* array of all cpuset ptrs */ | 582 | struct cpuset **csa; /* array of all cpuset ptrs */ |
573 | int csn; /* how many cpuset ptrs in csa so far */ | 583 | int csn; /* how many cpuset ptrs in csa so far */ |
@@ -577,49 +587,58 @@ void rebuild_sched_domains(void) | |||
577 | int ndoms; /* number of sched domains in result */ | 587 | int ndoms; /* number of sched domains in result */ |
578 | int nslot; /* next empty doms[] cpumask_t slot */ | 588 | int nslot; /* next empty doms[] cpumask_t slot */ |
579 | 589 | ||
580 | q = NULL; | 590 | ndoms = 0; |
581 | csa = NULL; | ||
582 | doms = NULL; | 591 | doms = NULL; |
583 | dattr = NULL; | 592 | dattr = NULL; |
593 | csa = NULL; | ||
584 | 594 | ||
585 | /* Special case for the 99% of systems with one, full, sched domain */ | 595 | /* Special case for the 99% of systems with one, full, sched domain */ |
586 | if (is_sched_load_balance(&top_cpuset)) { | 596 | if (is_sched_load_balance(&top_cpuset)) { |
587 | ndoms = 1; | ||
588 | doms = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 597 | doms = kmalloc(sizeof(cpumask_t), GFP_KERNEL); |
589 | if (!doms) | 598 | if (!doms) |
590 | goto rebuild; | 599 | goto done; |
600 | |||
591 | dattr = kmalloc(sizeof(struct sched_domain_attr), GFP_KERNEL); | 601 | dattr = kmalloc(sizeof(struct sched_domain_attr), GFP_KERNEL); |
592 | if (dattr) { | 602 | if (dattr) { |
593 | *dattr = SD_ATTR_INIT; | 603 | *dattr = SD_ATTR_INIT; |
594 | update_domain_attr(dattr, &top_cpuset); | 604 | update_domain_attr_tree(dattr, &top_cpuset); |
595 | } | 605 | } |
596 | *doms = top_cpuset.cpus_allowed; | 606 | *doms = top_cpuset.cpus_allowed; |
597 | goto rebuild; | ||
598 | } | ||
599 | 607 | ||
600 | q = kfifo_alloc(number_of_cpusets * sizeof(cp), GFP_KERNEL, NULL); | 608 | ndoms = 1; |
601 | if (IS_ERR(q)) | ||
602 | goto done; | 609 | goto done; |
610 | } | ||
611 | |||
603 | csa = kmalloc(number_of_cpusets * sizeof(cp), GFP_KERNEL); | 612 | csa = kmalloc(number_of_cpusets * sizeof(cp), GFP_KERNEL); |
604 | if (!csa) | 613 | if (!csa) |
605 | goto done; | 614 | goto done; |
606 | csn = 0; | 615 | csn = 0; |
607 | 616 | ||
608 | cp = &top_cpuset; | 617 | list_add(&top_cpuset.stack_list, &q); |
609 | __kfifo_put(q, (void *)&cp, sizeof(cp)); | 618 | while (!list_empty(&q)) { |
610 | while (__kfifo_get(q, (void *)&cp, sizeof(cp))) { | ||
611 | struct cgroup *cont; | 619 | struct cgroup *cont; |
612 | struct cpuset *child; /* scans child cpusets of cp */ | 620 | struct cpuset *child; /* scans child cpusets of cp */ |
613 | 621 | ||
622 | cp = list_first_entry(&q, struct cpuset, stack_list); | ||
623 | list_del(q.next); | ||
624 | |||
614 | if (cpus_empty(cp->cpus_allowed)) | 625 | if (cpus_empty(cp->cpus_allowed)) |
615 | continue; | 626 | continue; |
616 | 627 | ||
617 | if (is_sched_load_balance(cp)) | 628 | /* |
629 | * All child cpusets contain a subset of the parent's cpus, so | ||
630 | * just skip them, and then we call update_domain_attr_tree() | ||
631 | * to calc relax_domain_level of the corresponding sched | ||
632 | * domain. | ||
633 | */ | ||
634 | if (is_sched_load_balance(cp)) { | ||
618 | csa[csn++] = cp; | 635 | csa[csn++] = cp; |
636 | continue; | ||
637 | } | ||
619 | 638 | ||
620 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { | 639 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { |
621 | child = cgroup_cs(cont); | 640 | child = cgroup_cs(cont); |
622 | __kfifo_put(q, (void *)&child, sizeof(cp)); | 641 | list_add_tail(&child->stack_list, &q); |
623 | } | 642 | } |
624 | } | 643 | } |
625 | 644 | ||
@@ -650,63 +669,141 @@ restart: | |||
650 | } | 669 | } |
651 | } | 670 | } |
652 | 671 | ||
653 | /* Convert <csn, csa> to <ndoms, doms> */ | 672 | /* |
673 | * Now we know how many domains to create. | ||
674 | * Convert <csn, csa> to <ndoms, doms> and populate cpu masks. | ||
675 | */ | ||
654 | doms = kmalloc(ndoms * sizeof(cpumask_t), GFP_KERNEL); | 676 | doms = kmalloc(ndoms * sizeof(cpumask_t), GFP_KERNEL); |
655 | if (!doms) | 677 | if (!doms) { |
656 | goto rebuild; | 678 | ndoms = 0; |
679 | goto done; | ||
680 | } | ||
681 | |||
682 | /* | ||
683 | * The rest of the code, including the scheduler, can deal with | ||
684 | * dattr==NULL case. No need to abort if alloc fails. | ||
685 | */ | ||
657 | dattr = kmalloc(ndoms * sizeof(struct sched_domain_attr), GFP_KERNEL); | 686 | dattr = kmalloc(ndoms * sizeof(struct sched_domain_attr), GFP_KERNEL); |
658 | 687 | ||
659 | for (nslot = 0, i = 0; i < csn; i++) { | 688 | for (nslot = 0, i = 0; i < csn; i++) { |
660 | struct cpuset *a = csa[i]; | 689 | struct cpuset *a = csa[i]; |
690 | cpumask_t *dp; | ||
661 | int apn = a->pn; | 691 | int apn = a->pn; |
662 | 692 | ||
663 | if (apn >= 0) { | 693 | if (apn < 0) { |
664 | cpumask_t *dp = doms + nslot; | 694 | /* Skip completed partitions */ |
665 | 695 | continue; | |
666 | if (nslot == ndoms) { | 696 | } |
667 | static int warnings = 10; | 697 | |
668 | if (warnings) { | 698 | dp = doms + nslot; |
669 | printk(KERN_WARNING | 699 | |
670 | "rebuild_sched_domains confused:" | 700 | if (nslot == ndoms) { |
671 | " nslot %d, ndoms %d, csn %d, i %d," | 701 | static int warnings = 10; |
672 | " apn %d\n", | 702 | if (warnings) { |
673 | nslot, ndoms, csn, i, apn); | 703 | printk(KERN_WARNING |
674 | warnings--; | 704 | "rebuild_sched_domains confused:" |
675 | } | 705 | " nslot %d, ndoms %d, csn %d, i %d," |
676 | continue; | 706 | " apn %d\n", |
707 | nslot, ndoms, csn, i, apn); | ||
708 | warnings--; | ||
677 | } | 709 | } |
710 | continue; | ||
711 | } | ||
678 | 712 | ||
679 | cpus_clear(*dp); | 713 | cpus_clear(*dp); |
680 | if (dattr) | 714 | if (dattr) |
681 | *(dattr + nslot) = SD_ATTR_INIT; | 715 | *(dattr + nslot) = SD_ATTR_INIT; |
682 | for (j = i; j < csn; j++) { | 716 | for (j = i; j < csn; j++) { |
683 | struct cpuset *b = csa[j]; | 717 | struct cpuset *b = csa[j]; |
684 | 718 | ||
685 | if (apn == b->pn) { | 719 | if (apn == b->pn) { |
686 | cpus_or(*dp, *dp, b->cpus_allowed); | 720 | cpus_or(*dp, *dp, b->cpus_allowed); |
687 | b->pn = -1; | 721 | if (dattr) |
688 | if (dattr) | 722 | update_domain_attr_tree(dattr + nslot, b); |
689 | update_domain_attr(dattr | 723 | |
690 | + nslot, b); | 724 | /* Done with this partition */ |
691 | } | 725 | b->pn = -1; |
692 | } | 726 | } |
693 | nslot++; | ||
694 | } | 727 | } |
728 | nslot++; | ||
695 | } | 729 | } |
696 | BUG_ON(nslot != ndoms); | 730 | BUG_ON(nslot != ndoms); |
697 | 731 | ||
698 | rebuild: | 732 | done: |
699 | /* Have scheduler rebuild sched domains */ | 733 | kfree(csa); |
734 | |||
735 | *domains = doms; | ||
736 | *attributes = dattr; | ||
737 | return ndoms; | ||
738 | } | ||
739 | |||
740 | /* | ||
741 | * Rebuild scheduler domains. | ||
742 | * | ||
743 | * Call with neither cgroup_mutex held nor within get_online_cpus(). | ||
744 | * Takes both cgroup_mutex and get_online_cpus(). | ||
745 | * | ||
746 | * Cannot be directly called from cpuset code handling changes | ||
747 | * to the cpuset pseudo-filesystem, because it cannot be called | ||
748 | * from code that already holds cgroup_mutex. | ||
749 | */ | ||
750 | static void do_rebuild_sched_domains(struct work_struct *unused) | ||
751 | { | ||
752 | struct sched_domain_attr *attr; | ||
753 | cpumask_t *doms; | ||
754 | int ndoms; | ||
755 | |||
700 | get_online_cpus(); | 756 | get_online_cpus(); |
701 | partition_sched_domains(ndoms, doms, dattr); | 757 | |
758 | /* Generate domain masks and attrs */ | ||
759 | cgroup_lock(); | ||
760 | ndoms = generate_sched_domains(&doms, &attr); | ||
761 | cgroup_unlock(); | ||
762 | |||
763 | /* Have scheduler rebuild the domains */ | ||
764 | partition_sched_domains(ndoms, doms, attr); | ||
765 | |||
702 | put_online_cpus(); | 766 | put_online_cpus(); |
767 | } | ||
703 | 768 | ||
704 | done: | 769 | static DECLARE_WORK(rebuild_sched_domains_work, do_rebuild_sched_domains); |
705 | if (q && !IS_ERR(q)) | 770 | |
706 | kfifo_free(q); | 771 | /* |
707 | kfree(csa); | 772 | * Rebuild scheduler domains, asynchronously via workqueue. |
708 | /* Don't kfree(doms) -- partition_sched_domains() does that. */ | 773 | * |
709 | /* Don't kfree(dattr) -- partition_sched_domains() does that. */ | 774 | * If the flag 'sched_load_balance' of any cpuset with non-empty |
775 | * 'cpus' changes, or if the 'cpus' allowed changes in any cpuset | ||
776 | * which has that flag enabled, or if any cpuset with a non-empty | ||
777 | * 'cpus' is removed, then call this routine to rebuild the | ||
778 | * scheduler's dynamic sched domains. | ||
779 | * | ||
780 | * The rebuild_sched_domains() and partition_sched_domains() | ||
781 | * routines must nest cgroup_lock() inside get_online_cpus(), | ||
782 | * but such cpuset changes as these must nest that locking the | ||
783 | * other way, holding cgroup_lock() for much of the code. | ||
784 | * | ||
785 | * So in order to avoid an ABBA deadlock, the cpuset code handling | ||
786 | * these user changes delegates the actual sched domain rebuilding | ||
787 | * to a separate workqueue thread, which ends up processing the | ||
788 | * above do_rebuild_sched_domains() function. | ||
789 | */ | ||
790 | static void async_rebuild_sched_domains(void) | ||
791 | { | ||
792 | schedule_work(&rebuild_sched_domains_work); | ||
793 | } | ||
794 | |||
795 | /* | ||
796 | * Accomplishes the same scheduler domain rebuild as the above | ||
797 | * async_rebuild_sched_domains(), however it directly calls the | ||
798 | * rebuild routine synchronously rather than calling it via an | ||
799 | * asynchronous work thread. | ||
800 | * | ||
801 | * This can only be called from code that is not holding | ||
802 | * cgroup_mutex (not nested in a cgroup_lock() call.) | ||
803 | */ | ||
804 | void rebuild_sched_domains(void) | ||
805 | { | ||
806 | do_rebuild_sched_domains(NULL); | ||
710 | } | 807 | } |
711 | 808 | ||
712 | /** | 809 | /** |
@@ -746,37 +843,25 @@ static void cpuset_change_cpumask(struct task_struct *tsk, | |||
746 | /** | 843 | /** |
747 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. | 844 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. |
748 | * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed | 845 | * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed |
846 | * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks() | ||
749 | * | 847 | * |
750 | * Called with cgroup_mutex held | 848 | * Called with cgroup_mutex held |
751 | * | 849 | * |
752 | * The cgroup_scan_tasks() function will scan all the tasks in a cgroup, | 850 | * The cgroup_scan_tasks() function will scan all the tasks in a cgroup, |
753 | * calling callback functions for each. | 851 | * calling callback functions for each. |
754 | * | 852 | * |
755 | * Return 0 if successful, -errno if not. | 853 | * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0 |
854 | * if @heap != NULL. | ||
756 | */ | 855 | */ |
757 | static int update_tasks_cpumask(struct cpuset *cs) | 856 | static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap) |
758 | { | 857 | { |
759 | struct cgroup_scanner scan; | 858 | struct cgroup_scanner scan; |
760 | struct ptr_heap heap; | ||
761 | int retval; | ||
762 | |||
763 | /* | ||
764 | * cgroup_scan_tasks() will initialize heap->gt for us. | ||
765 | * heap_init() is still needed here for we should not change | ||
766 | * cs->cpus_allowed when heap_init() fails. | ||
767 | */ | ||
768 | retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL); | ||
769 | if (retval) | ||
770 | return retval; | ||
771 | 859 | ||
772 | scan.cg = cs->css.cgroup; | 860 | scan.cg = cs->css.cgroup; |
773 | scan.test_task = cpuset_test_cpumask; | 861 | scan.test_task = cpuset_test_cpumask; |
774 | scan.process_task = cpuset_change_cpumask; | 862 | scan.process_task = cpuset_change_cpumask; |
775 | scan.heap = &heap; | 863 | scan.heap = heap; |
776 | retval = cgroup_scan_tasks(&scan); | 864 | cgroup_scan_tasks(&scan); |
777 | |||
778 | heap_free(&heap); | ||
779 | return retval; | ||
780 | } | 865 | } |
781 | 866 | ||
782 | /** | 867 | /** |
@@ -786,6 +871,7 @@ static int update_tasks_cpumask(struct cpuset *cs) | |||
786 | */ | 871 | */ |
787 | static int update_cpumask(struct cpuset *cs, const char *buf) | 872 | static int update_cpumask(struct cpuset *cs, const char *buf) |
788 | { | 873 | { |
874 | struct ptr_heap heap; | ||
789 | struct cpuset trialcs; | 875 | struct cpuset trialcs; |
790 | int retval; | 876 | int retval; |
791 | int is_load_balanced; | 877 | int is_load_balanced; |
@@ -820,6 +906,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf) | |||
820 | if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) | 906 | if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) |
821 | return 0; | 907 | return 0; |
822 | 908 | ||
909 | retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL); | ||
910 | if (retval) | ||
911 | return retval; | ||
912 | |||
823 | is_load_balanced = is_sched_load_balance(&trialcs); | 913 | is_load_balanced = is_sched_load_balance(&trialcs); |
824 | 914 | ||
825 | mutex_lock(&callback_mutex); | 915 | mutex_lock(&callback_mutex); |
@@ -830,12 +920,12 @@ static int update_cpumask(struct cpuset *cs, const char *buf) | |||
830 | * Scan tasks in the cpuset, and update the cpumasks of any | 920 | * Scan tasks in the cpuset, and update the cpumasks of any |
831 | * that need an update. | 921 | * that need an update. |
832 | */ | 922 | */ |
833 | retval = update_tasks_cpumask(cs); | 923 | update_tasks_cpumask(cs, &heap); |
834 | if (retval < 0) | 924 | |
835 | return retval; | 925 | heap_free(&heap); |
836 | 926 | ||
837 | if (is_load_balanced) | 927 | if (is_load_balanced) |
838 | rebuild_sched_domains(); | 928 | async_rebuild_sched_domains(); |
839 | return 0; | 929 | return 0; |
840 | } | 930 | } |
841 | 931 | ||
@@ -1062,7 +1152,7 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val) | |||
1062 | if (val != cs->relax_domain_level) { | 1152 | if (val != cs->relax_domain_level) { |
1063 | cs->relax_domain_level = val; | 1153 | cs->relax_domain_level = val; |
1064 | if (!cpus_empty(cs->cpus_allowed) && is_sched_load_balance(cs)) | 1154 | if (!cpus_empty(cs->cpus_allowed) && is_sched_load_balance(cs)) |
1065 | rebuild_sched_domains(); | 1155 | async_rebuild_sched_domains(); |
1066 | } | 1156 | } |
1067 | 1157 | ||
1068 | return 0; | 1158 | return 0; |
@@ -1103,7 +1193,7 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, | |||
1103 | mutex_unlock(&callback_mutex); | 1193 | mutex_unlock(&callback_mutex); |
1104 | 1194 | ||
1105 | if (cpus_nonempty && balance_flag_changed) | 1195 | if (cpus_nonempty && balance_flag_changed) |
1106 | rebuild_sched_domains(); | 1196 | async_rebuild_sched_domains(); |
1107 | 1197 | ||
1108 | return 0; | 1198 | return 0; |
1109 | } | 1199 | } |
@@ -1464,6 +1554,9 @@ static u64 cpuset_read_u64(struct cgroup *cont, struct cftype *cft) | |||
1464 | default: | 1554 | default: |
1465 | BUG(); | 1555 | BUG(); |
1466 | } | 1556 | } |
1557 | |||
1558 | /* Unreachable but makes gcc happy */ | ||
1559 | return 0; | ||
1467 | } | 1560 | } |
1468 | 1561 | ||
1469 | static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft) | 1562 | static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft) |
@@ -1476,6 +1569,9 @@ static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft) | |||
1476 | default: | 1569 | default: |
1477 | BUG(); | 1570 | BUG(); |
1478 | } | 1571 | } |
1572 | |||
1573 | /* Unrechable but makes gcc happy */ | ||
1574 | return 0; | ||
1479 | } | 1575 | } |
1480 | 1576 | ||
1481 | 1577 | ||
@@ -1664,15 +1760,9 @@ static struct cgroup_subsys_state *cpuset_create( | |||
1664 | } | 1760 | } |
1665 | 1761 | ||
1666 | /* | 1762 | /* |
1667 | * Locking note on the strange update_flag() call below: | ||
1668 | * | ||
1669 | * If the cpuset being removed has its flag 'sched_load_balance' | 1763 | * If the cpuset being removed has its flag 'sched_load_balance' |
1670 | * enabled, then simulate turning sched_load_balance off, which | 1764 | * enabled, then simulate turning sched_load_balance off, which |
1671 | * will call rebuild_sched_domains(). The get_online_cpus() | 1765 | * will call async_rebuild_sched_domains(). |
1672 | * call in rebuild_sched_domains() must not be made while holding | ||
1673 | * callback_mutex. Elsewhere the kernel nests callback_mutex inside | ||
1674 | * get_online_cpus() calls. So the reverse nesting would risk an | ||
1675 | * ABBA deadlock. | ||
1676 | */ | 1766 | */ |
1677 | 1767 | ||
1678 | static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont) | 1768 | static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont) |
@@ -1691,7 +1781,7 @@ static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont) | |||
1691 | struct cgroup_subsys cpuset_subsys = { | 1781 | struct cgroup_subsys cpuset_subsys = { |
1692 | .name = "cpuset", | 1782 | .name = "cpuset", |
1693 | .create = cpuset_create, | 1783 | .create = cpuset_create, |
1694 | .destroy = cpuset_destroy, | 1784 | .destroy = cpuset_destroy, |
1695 | .can_attach = cpuset_can_attach, | 1785 | .can_attach = cpuset_can_attach, |
1696 | .attach = cpuset_attach, | 1786 | .attach = cpuset_attach, |
1697 | .populate = cpuset_populate, | 1787 | .populate = cpuset_populate, |
@@ -1783,7 +1873,7 @@ static void move_member_tasks_to_cpuset(struct cpuset *from, struct cpuset *to) | |||
1783 | } | 1873 | } |
1784 | 1874 | ||
1785 | /* | 1875 | /* |
1786 | * If common_cpu_mem_hotplug_unplug(), below, unplugs any CPUs | 1876 | * If CPU and/or memory hotplug handlers, below, unplug any CPUs |
1787 | * or memory nodes, we need to walk over the cpuset hierarchy, | 1877 | * or memory nodes, we need to walk over the cpuset hierarchy, |
1788 | * removing that CPU or node from all cpusets. If this removes the | 1878 | * removing that CPU or node from all cpusets. If this removes the |
1789 | * last CPU or node from a cpuset, then move the tasks in the empty | 1879 | * last CPU or node from a cpuset, then move the tasks in the empty |
@@ -1831,26 +1921,23 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs) | |||
1831 | * that has tasks along with an empty 'mems'. But if we did see such | 1921 | * that has tasks along with an empty 'mems'. But if we did see such |
1832 | * a cpuset, we'd handle it just like we do if its 'cpus' was empty. | 1922 | * a cpuset, we'd handle it just like we do if its 'cpus' was empty. |
1833 | */ | 1923 | */ |
1834 | static void scan_for_empty_cpusets(const struct cpuset *root) | 1924 | static void scan_for_empty_cpusets(struct cpuset *root) |
1835 | { | 1925 | { |
1926 | LIST_HEAD(queue); | ||
1836 | struct cpuset *cp; /* scans cpusets being updated */ | 1927 | struct cpuset *cp; /* scans cpusets being updated */ |
1837 | struct cpuset *child; /* scans child cpusets of cp */ | 1928 | struct cpuset *child; /* scans child cpusets of cp */ |
1838 | struct list_head queue; | ||
1839 | struct cgroup *cont; | 1929 | struct cgroup *cont; |
1840 | nodemask_t oldmems; | 1930 | nodemask_t oldmems; |
1841 | 1931 | ||
1842 | INIT_LIST_HEAD(&queue); | ||
1843 | |||
1844 | list_add_tail((struct list_head *)&root->stack_list, &queue); | 1932 | list_add_tail((struct list_head *)&root->stack_list, &queue); |
1845 | 1933 | ||
1846 | while (!list_empty(&queue)) { | 1934 | while (!list_empty(&queue)) { |
1847 | cp = container_of(queue.next, struct cpuset, stack_list); | 1935 | cp = list_first_entry(&queue, struct cpuset, stack_list); |
1848 | list_del(queue.next); | 1936 | list_del(queue.next); |
1849 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { | 1937 | list_for_each_entry(cont, &cp->css.cgroup->children, sibling) { |
1850 | child = cgroup_cs(cont); | 1938 | child = cgroup_cs(cont); |
1851 | list_add_tail(&child->stack_list, &queue); | 1939 | list_add_tail(&child->stack_list, &queue); |
1852 | } | 1940 | } |
1853 | cont = cp->css.cgroup; | ||
1854 | 1941 | ||
1855 | /* Continue past cpusets with all cpus, mems online */ | 1942 | /* Continue past cpusets with all cpus, mems online */ |
1856 | if (cpus_subset(cp->cpus_allowed, cpu_online_map) && | 1943 | if (cpus_subset(cp->cpus_allowed, cpu_online_map) && |
@@ -1871,42 +1958,13 @@ static void scan_for_empty_cpusets(const struct cpuset *root) | |||
1871 | nodes_empty(cp->mems_allowed)) | 1958 | nodes_empty(cp->mems_allowed)) |
1872 | remove_tasks_in_empty_cpuset(cp); | 1959 | remove_tasks_in_empty_cpuset(cp); |
1873 | else { | 1960 | else { |
1874 | update_tasks_cpumask(cp); | 1961 | update_tasks_cpumask(cp, NULL); |
1875 | update_tasks_nodemask(cp, &oldmems); | 1962 | update_tasks_nodemask(cp, &oldmems); |
1876 | } | 1963 | } |
1877 | } | 1964 | } |
1878 | } | 1965 | } |
1879 | 1966 | ||
1880 | /* | 1967 | /* |
1881 | * The cpus_allowed and mems_allowed nodemasks in the top_cpuset track | ||
1882 | * cpu_online_map and node_states[N_HIGH_MEMORY]. Force the top cpuset to | ||
1883 | * track what's online after any CPU or memory node hotplug or unplug event. | ||
1884 | * | ||
1885 | * Since there are two callers of this routine, one for CPU hotplug | ||
1886 | * events and one for memory node hotplug events, we could have coded | ||
1887 | * two separate routines here. We code it as a single common routine | ||
1888 | * in order to minimize text size. | ||
1889 | */ | ||
1890 | |||
1891 | static void common_cpu_mem_hotplug_unplug(int rebuild_sd) | ||
1892 | { | ||
1893 | cgroup_lock(); | ||
1894 | |||
1895 | top_cpuset.cpus_allowed = cpu_online_map; | ||
1896 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; | ||
1897 | scan_for_empty_cpusets(&top_cpuset); | ||
1898 | |||
1899 | /* | ||
1900 | * Scheduler destroys domains on hotplug events. | ||
1901 | * Rebuild them based on the current settings. | ||
1902 | */ | ||
1903 | if (rebuild_sd) | ||
1904 | rebuild_sched_domains(); | ||
1905 | |||
1906 | cgroup_unlock(); | ||
1907 | } | ||
1908 | |||
1909 | /* | ||
1910 | * The top_cpuset tracks what CPUs and Memory Nodes are online, | 1968 | * The top_cpuset tracks what CPUs and Memory Nodes are online, |
1911 | * period. This is necessary in order to make cpusets transparent | 1969 | * period. This is necessary in order to make cpusets transparent |
1912 | * (of no affect) on systems that are actively using CPU hotplug | 1970 | * (of no affect) on systems that are actively using CPU hotplug |
@@ -1914,40 +1972,52 @@ static void common_cpu_mem_hotplug_unplug(int rebuild_sd) | |||
1914 | * | 1972 | * |
1915 | * This routine ensures that top_cpuset.cpus_allowed tracks | 1973 | * This routine ensures that top_cpuset.cpus_allowed tracks |
1916 | * cpu_online_map on each CPU hotplug (cpuhp) event. | 1974 | * cpu_online_map on each CPU hotplug (cpuhp) event. |
1975 | * | ||
1976 | * Called within get_online_cpus(). Needs to call cgroup_lock() | ||
1977 | * before calling generate_sched_domains(). | ||
1917 | */ | 1978 | */ |
1918 | 1979 | static int cpuset_track_online_cpus(struct notifier_block *unused_nb, | |
1919 | static int cpuset_handle_cpuhp(struct notifier_block *unused_nb, | ||
1920 | unsigned long phase, void *unused_cpu) | 1980 | unsigned long phase, void *unused_cpu) |
1921 | { | 1981 | { |
1982 | struct sched_domain_attr *attr; | ||
1983 | cpumask_t *doms; | ||
1984 | int ndoms; | ||
1985 | |||
1922 | switch (phase) { | 1986 | switch (phase) { |
1923 | case CPU_UP_CANCELED: | ||
1924 | case CPU_UP_CANCELED_FROZEN: | ||
1925 | case CPU_DOWN_FAILED: | ||
1926 | case CPU_DOWN_FAILED_FROZEN: | ||
1927 | case CPU_ONLINE: | 1987 | case CPU_ONLINE: |
1928 | case CPU_ONLINE_FROZEN: | 1988 | case CPU_ONLINE_FROZEN: |
1929 | case CPU_DEAD: | 1989 | case CPU_DEAD: |
1930 | case CPU_DEAD_FROZEN: | 1990 | case CPU_DEAD_FROZEN: |
1931 | common_cpu_mem_hotplug_unplug(1); | ||
1932 | break; | 1991 | break; |
1992 | |||
1933 | default: | 1993 | default: |
1934 | return NOTIFY_DONE; | 1994 | return NOTIFY_DONE; |
1935 | } | 1995 | } |
1936 | 1996 | ||
1997 | cgroup_lock(); | ||
1998 | top_cpuset.cpus_allowed = cpu_online_map; | ||
1999 | scan_for_empty_cpusets(&top_cpuset); | ||
2000 | ndoms = generate_sched_domains(&doms, &attr); | ||
2001 | cgroup_unlock(); | ||
2002 | |||
2003 | /* Have scheduler rebuild the domains */ | ||
2004 | partition_sched_domains(ndoms, doms, attr); | ||
2005 | |||
1937 | return NOTIFY_OK; | 2006 | return NOTIFY_OK; |
1938 | } | 2007 | } |
1939 | 2008 | ||
1940 | #ifdef CONFIG_MEMORY_HOTPLUG | 2009 | #ifdef CONFIG_MEMORY_HOTPLUG |
1941 | /* | 2010 | /* |
1942 | * Keep top_cpuset.mems_allowed tracking node_states[N_HIGH_MEMORY]. | 2011 | * Keep top_cpuset.mems_allowed tracking node_states[N_HIGH_MEMORY]. |
1943 | * Call this routine anytime after you change | 2012 | * Call this routine anytime after node_states[N_HIGH_MEMORY] changes. |
1944 | * node_states[N_HIGH_MEMORY]. | 2013 | * See also the previous routine cpuset_track_online_cpus(). |
1945 | * See also the previous routine cpuset_handle_cpuhp(). | ||
1946 | */ | 2014 | */ |
1947 | |||
1948 | void cpuset_track_online_nodes(void) | 2015 | void cpuset_track_online_nodes(void) |
1949 | { | 2016 | { |
1950 | common_cpu_mem_hotplug_unplug(0); | 2017 | cgroup_lock(); |
2018 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; | ||
2019 | scan_for_empty_cpusets(&top_cpuset); | ||
2020 | cgroup_unlock(); | ||
1951 | } | 2021 | } |
1952 | #endif | 2022 | #endif |
1953 | 2023 | ||
@@ -1962,7 +2032,7 @@ void __init cpuset_init_smp(void) | |||
1962 | top_cpuset.cpus_allowed = cpu_online_map; | 2032 | top_cpuset.cpus_allowed = cpu_online_map; |
1963 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; | 2033 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; |
1964 | 2034 | ||
1965 | hotcpu_notifier(cpuset_handle_cpuhp, 0); | 2035 | hotcpu_notifier(cpuset_track_online_cpus, 0); |
1966 | } | 2036 | } |
1967 | 2037 | ||
1968 | /** | 2038 | /** |
diff --git a/kernel/dma-coherent.c b/kernel/dma-coherent.c new file mode 100644 index 000000000000..f013a0c2e111 --- /dev/null +++ b/kernel/dma-coherent.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | * Coherent per-device memory handling. | ||
3 | * Borrowed from i386 | ||
4 | */ | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/dma-mapping.h> | ||
7 | |||
8 | struct dma_coherent_mem { | ||
9 | void *virt_base; | ||
10 | u32 device_base; | ||
11 | int size; | ||
12 | int flags; | ||
13 | unsigned long *bitmap; | ||
14 | }; | ||
15 | |||
16 | int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | ||
17 | dma_addr_t device_addr, size_t size, int flags) | ||
18 | { | ||
19 | void __iomem *mem_base = NULL; | ||
20 | int pages = size >> PAGE_SHIFT; | ||
21 | int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); | ||
22 | |||
23 | if ((flags & (DMA_MEMORY_MAP | DMA_MEMORY_IO)) == 0) | ||
24 | goto out; | ||
25 | if (!size) | ||
26 | goto out; | ||
27 | if (dev->dma_mem) | ||
28 | goto out; | ||
29 | |||
30 | /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */ | ||
31 | |||
32 | mem_base = ioremap(bus_addr, size); | ||
33 | if (!mem_base) | ||
34 | goto out; | ||
35 | |||
36 | dev->dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL); | ||
37 | if (!dev->dma_mem) | ||
38 | goto out; | ||
39 | dev->dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL); | ||
40 | if (!dev->dma_mem->bitmap) | ||
41 | goto free1_out; | ||
42 | |||
43 | dev->dma_mem->virt_base = mem_base; | ||
44 | dev->dma_mem->device_base = device_addr; | ||
45 | dev->dma_mem->size = pages; | ||
46 | dev->dma_mem->flags = flags; | ||
47 | |||
48 | if (flags & DMA_MEMORY_MAP) | ||
49 | return DMA_MEMORY_MAP; | ||
50 | |||
51 | return DMA_MEMORY_IO; | ||
52 | |||
53 | free1_out: | ||
54 | kfree(dev->dma_mem); | ||
55 | out: | ||
56 | if (mem_base) | ||
57 | iounmap(mem_base); | ||
58 | return 0; | ||
59 | } | ||
60 | EXPORT_SYMBOL(dma_declare_coherent_memory); | ||
61 | |||
62 | void dma_release_declared_memory(struct device *dev) | ||
63 | { | ||
64 | struct dma_coherent_mem *mem = dev->dma_mem; | ||
65 | |||
66 | if (!mem) | ||
67 | return; | ||
68 | dev->dma_mem = NULL; | ||
69 | iounmap(mem->virt_base); | ||
70 | kfree(mem->bitmap); | ||
71 | kfree(mem); | ||
72 | } | ||
73 | EXPORT_SYMBOL(dma_release_declared_memory); | ||
74 | |||
75 | void *dma_mark_declared_memory_occupied(struct device *dev, | ||
76 | dma_addr_t device_addr, size_t size) | ||
77 | { | ||
78 | struct dma_coherent_mem *mem = dev->dma_mem; | ||
79 | int pos, err; | ||
80 | |||
81 | size += device_addr & ~PAGE_MASK; | ||
82 | |||
83 | if (!mem) | ||
84 | return ERR_PTR(-EINVAL); | ||
85 | |||
86 | pos = (device_addr - mem->device_base) >> PAGE_SHIFT; | ||
87 | err = bitmap_allocate_region(mem->bitmap, pos, get_order(size)); | ||
88 | if (err != 0) | ||
89 | return ERR_PTR(err); | ||
90 | return mem->virt_base + (pos << PAGE_SHIFT); | ||
91 | } | ||
92 | EXPORT_SYMBOL(dma_mark_declared_memory_occupied); | ||
93 | |||
94 | /** | ||
95 | * dma_alloc_from_coherent() - try to allocate memory from the per-device coherent area | ||
96 | * | ||
97 | * @dev: device from which we allocate memory | ||
98 | * @size: size of requested memory area | ||
99 | * @dma_handle: This will be filled with the correct dma handle | ||
100 | * @ret: This pointer will be filled with the virtual address | ||
101 | * to allocated area. | ||
102 | * | ||
103 | * This function should be only called from per-arch dma_alloc_coherent() | ||
104 | * to support allocation from per-device coherent memory pools. | ||
105 | * | ||
106 | * Returns 0 if dma_alloc_coherent should continue with allocating from | ||
107 | * generic memory areas, or !0 if dma_alloc_coherent should return @ret. | ||
108 | */ | ||
109 | int dma_alloc_from_coherent(struct device *dev, ssize_t size, | ||
110 | dma_addr_t *dma_handle, void **ret) | ||
111 | { | ||
112 | struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; | ||
113 | int order = get_order(size); | ||
114 | |||
115 | if (mem) { | ||
116 | int page = bitmap_find_free_region(mem->bitmap, mem->size, | ||
117 | order); | ||
118 | if (page >= 0) { | ||
119 | *dma_handle = mem->device_base + (page << PAGE_SHIFT); | ||
120 | *ret = mem->virt_base + (page << PAGE_SHIFT); | ||
121 | memset(*ret, 0, size); | ||
122 | } else if (mem->flags & DMA_MEMORY_EXCLUSIVE) | ||
123 | *ret = NULL; | ||
124 | } | ||
125 | return (mem != NULL); | ||
126 | } | ||
127 | EXPORT_SYMBOL(dma_alloc_from_coherent); | ||
128 | |||
129 | /** | ||
130 | * dma_release_from_coherent() - try to free the memory allocated from per-device coherent memory pool | ||
131 | * @dev: device from which the memory was allocated | ||
132 | * @order: the order of pages allocated | ||
133 | * @vaddr: virtual address of allocated pages | ||
134 | * | ||
135 | * This checks whether the memory was allocated from the per-device | ||
136 | * coherent memory pool and if so, releases that memory. | ||
137 | * | ||
138 | * Returns 1 if we correctly released the memory, or 0 if | ||
139 | * dma_release_coherent() should proceed with releasing memory from | ||
140 | * generic pools. | ||
141 | */ | ||
142 | int dma_release_from_coherent(struct device *dev, int order, void *vaddr) | ||
143 | { | ||
144 | struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; | ||
145 | |||
146 | if (mem && vaddr >= mem->virt_base && vaddr < | ||
147 | (mem->virt_base + (mem->size << PAGE_SHIFT))) { | ||
148 | int page = (vaddr - mem->virt_base) >> PAGE_SHIFT; | ||
149 | |||
150 | bitmap_release_region(mem->bitmap, page, order); | ||
151 | return 1; | ||
152 | } | ||
153 | return 0; | ||
154 | } | ||
155 | EXPORT_SYMBOL(dma_release_from_coherent); | ||
diff --git a/kernel/exec_domain.c b/kernel/exec_domain.c index c1ef192aa655..0d407e886735 100644 --- a/kernel/exec_domain.c +++ b/kernel/exec_domain.c | |||
@@ -168,7 +168,6 @@ __set_personality(u_long personality) | |||
168 | current->personality = personality; | 168 | current->personality = personality; |
169 | oep = current_thread_info()->exec_domain; | 169 | oep = current_thread_info()->exec_domain; |
170 | current_thread_info()->exec_domain = ep; | 170 | current_thread_info()->exec_domain = ep; |
171 | set_fs_altroot(); | ||
172 | 171 | ||
173 | module_put(oep->module); | 172 | module_put(oep->module); |
174 | return 0; | 173 | return 0; |
diff --git a/kernel/exit.c b/kernel/exit.c index ad933bb29ec7..85a83c831856 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <linux/resource.h> | 46 | #include <linux/resource.h> |
47 | #include <linux/blkdev.h> | 47 | #include <linux/blkdev.h> |
48 | #include <linux/task_io_accounting_ops.h> | 48 | #include <linux/task_io_accounting_ops.h> |
49 | #include <linux/tracehook.h> | ||
49 | 50 | ||
50 | #include <asm/uaccess.h> | 51 | #include <asm/uaccess.h> |
51 | #include <asm/unistd.h> | 52 | #include <asm/unistd.h> |
@@ -111,27 +112,16 @@ static void __exit_signal(struct task_struct *tsk) | |||
111 | * We won't ever get here for the group leader, since it | 112 | * We won't ever get here for the group leader, since it |
112 | * will have been the last reference on the signal_struct. | 113 | * will have been the last reference on the signal_struct. |
113 | */ | 114 | */ |
114 | sig->utime = cputime_add(sig->utime, tsk->utime); | 115 | sig->utime = cputime_add(sig->utime, task_utime(tsk)); |
115 | sig->stime = cputime_add(sig->stime, tsk->stime); | 116 | sig->stime = cputime_add(sig->stime, task_stime(tsk)); |
116 | sig->gtime = cputime_add(sig->gtime, tsk->gtime); | 117 | sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); |
117 | sig->min_flt += tsk->min_flt; | 118 | sig->min_flt += tsk->min_flt; |
118 | sig->maj_flt += tsk->maj_flt; | 119 | sig->maj_flt += tsk->maj_flt; |
119 | sig->nvcsw += tsk->nvcsw; | 120 | sig->nvcsw += tsk->nvcsw; |
120 | sig->nivcsw += tsk->nivcsw; | 121 | sig->nivcsw += tsk->nivcsw; |
121 | sig->inblock += task_io_get_inblock(tsk); | 122 | sig->inblock += task_io_get_inblock(tsk); |
122 | sig->oublock += task_io_get_oublock(tsk); | 123 | sig->oublock += task_io_get_oublock(tsk); |
123 | #ifdef CONFIG_TASK_XACCT | 124 | task_io_accounting_add(&sig->ioac, &tsk->ioac); |
124 | sig->rchar += tsk->rchar; | ||
125 | sig->wchar += tsk->wchar; | ||
126 | sig->syscr += tsk->syscr; | ||
127 | sig->syscw += tsk->syscw; | ||
128 | #endif /* CONFIG_TASK_XACCT */ | ||
129 | #ifdef CONFIG_TASK_IO_ACCOUNTING | ||
130 | sig->ioac.read_bytes += tsk->ioac.read_bytes; | ||
131 | sig->ioac.write_bytes += tsk->ioac.write_bytes; | ||
132 | sig->ioac.cancelled_write_bytes += | ||
133 | tsk->ioac.cancelled_write_bytes; | ||
134 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ | ||
135 | sig->sum_sched_runtime += tsk->se.sum_exec_runtime; | 125 | sig->sum_sched_runtime += tsk->se.sum_exec_runtime; |
136 | sig = NULL; /* Marker for below. */ | 126 | sig = NULL; /* Marker for below. */ |
137 | } | 127 | } |
@@ -162,27 +152,17 @@ static void delayed_put_task_struct(struct rcu_head *rhp) | |||
162 | put_task_struct(container_of(rhp, struct task_struct, rcu)); | 152 | put_task_struct(container_of(rhp, struct task_struct, rcu)); |
163 | } | 153 | } |
164 | 154 | ||
165 | /* | ||
166 | * Do final ptrace-related cleanup of a zombie being reaped. | ||
167 | * | ||
168 | * Called with write_lock(&tasklist_lock) held. | ||
169 | */ | ||
170 | static void ptrace_release_task(struct task_struct *p) | ||
171 | { | ||
172 | BUG_ON(!list_empty(&p->ptraced)); | ||
173 | ptrace_unlink(p); | ||
174 | BUG_ON(!list_empty(&p->ptrace_entry)); | ||
175 | } | ||
176 | 155 | ||
177 | void release_task(struct task_struct * p) | 156 | void release_task(struct task_struct * p) |
178 | { | 157 | { |
179 | struct task_struct *leader; | 158 | struct task_struct *leader; |
180 | int zap_leader; | 159 | int zap_leader; |
181 | repeat: | 160 | repeat: |
161 | tracehook_prepare_release_task(p); | ||
182 | atomic_dec(&p->user->processes); | 162 | atomic_dec(&p->user->processes); |
183 | proc_flush_task(p); | 163 | proc_flush_task(p); |
184 | write_lock_irq(&tasklist_lock); | 164 | write_lock_irq(&tasklist_lock); |
185 | ptrace_release_task(p); | 165 | tracehook_finish_release_task(p); |
186 | __exit_signal(p); | 166 | __exit_signal(p); |
187 | 167 | ||
188 | /* | 168 | /* |
@@ -204,6 +184,13 @@ repeat: | |||
204 | * that case. | 184 | * that case. |
205 | */ | 185 | */ |
206 | zap_leader = task_detached(leader); | 186 | zap_leader = task_detached(leader); |
187 | |||
188 | /* | ||
189 | * This maintains the invariant that release_task() | ||
190 | * only runs on a task in EXIT_DEAD, just for sanity. | ||
191 | */ | ||
192 | if (zap_leader) | ||
193 | leader->exit_state = EXIT_DEAD; | ||
207 | } | 194 | } |
208 | 195 | ||
209 | write_unlock_irq(&tasklist_lock); | 196 | write_unlock_irq(&tasklist_lock); |
@@ -567,8 +554,6 @@ void put_fs_struct(struct fs_struct *fs) | |||
567 | if (atomic_dec_and_test(&fs->count)) { | 554 | if (atomic_dec_and_test(&fs->count)) { |
568 | path_put(&fs->root); | 555 | path_put(&fs->root); |
569 | path_put(&fs->pwd); | 556 | path_put(&fs->pwd); |
570 | if (fs->altroot.dentry) | ||
571 | path_put(&fs->altroot); | ||
572 | kmem_cache_free(fs_cachep, fs); | 557 | kmem_cache_free(fs_cachep, fs); |
573 | } | 558 | } |
574 | } | 559 | } |
@@ -598,8 +583,6 @@ mm_need_new_owner(struct mm_struct *mm, struct task_struct *p) | |||
598 | * If there are other users of the mm and the owner (us) is exiting | 583 | * If there are other users of the mm and the owner (us) is exiting |
599 | * we need to find a new owner to take on the responsibility. | 584 | * we need to find a new owner to take on the responsibility. |
600 | */ | 585 | */ |
601 | if (!mm) | ||
602 | return 0; | ||
603 | if (atomic_read(&mm->mm_users) <= 1) | 586 | if (atomic_read(&mm->mm_users) <= 1) |
604 | return 0; | 587 | return 0; |
605 | if (mm->owner != p) | 588 | if (mm->owner != p) |
@@ -642,6 +625,16 @@ retry: | |||
642 | } while_each_thread(g, c); | 625 | } while_each_thread(g, c); |
643 | 626 | ||
644 | read_unlock(&tasklist_lock); | 627 | read_unlock(&tasklist_lock); |
628 | /* | ||
629 | * We found no owner yet mm_users > 1: this implies that we are | ||
630 | * most likely racing with swapoff (try_to_unuse()) or /proc or | ||
631 | * ptrace or page migration (get_task_mm()). Mark owner as NULL, | ||
632 | * so that subsystems can understand the callback and take action. | ||
633 | */ | ||
634 | down_write(&mm->mmap_sem); | ||
635 | cgroup_mm_owner_callbacks(mm->owner, NULL); | ||
636 | mm->owner = NULL; | ||
637 | up_write(&mm->mmap_sem); | ||
645 | return; | 638 | return; |
646 | 639 | ||
647 | assign_new_owner: | 640 | assign_new_owner: |
@@ -846,26 +839,50 @@ static void reparent_thread(struct task_struct *p, struct task_struct *father) | |||
846 | * the child reaper process (ie "init") in our pid | 839 | * the child reaper process (ie "init") in our pid |
847 | * space. | 840 | * space. |
848 | */ | 841 | */ |
842 | static struct task_struct *find_new_reaper(struct task_struct *father) | ||
843 | { | ||
844 | struct pid_namespace *pid_ns = task_active_pid_ns(father); | ||
845 | struct task_struct *thread; | ||
846 | |||
847 | thread = father; | ||
848 | while_each_thread(father, thread) { | ||
849 | if (thread->flags & PF_EXITING) | ||
850 | continue; | ||
851 | if (unlikely(pid_ns->child_reaper == father)) | ||
852 | pid_ns->child_reaper = thread; | ||
853 | return thread; | ||
854 | } | ||
855 | |||
856 | if (unlikely(pid_ns->child_reaper == father)) { | ||
857 | write_unlock_irq(&tasklist_lock); | ||
858 | if (unlikely(pid_ns == &init_pid_ns)) | ||
859 | panic("Attempted to kill init!"); | ||
860 | |||
861 | zap_pid_ns_processes(pid_ns); | ||
862 | write_lock_irq(&tasklist_lock); | ||
863 | /* | ||
864 | * We can not clear ->child_reaper or leave it alone. | ||
865 | * There may by stealth EXIT_DEAD tasks on ->children, | ||
866 | * forget_original_parent() must move them somewhere. | ||
867 | */ | ||
868 | pid_ns->child_reaper = init_pid_ns.child_reaper; | ||
869 | } | ||
870 | |||
871 | return pid_ns->child_reaper; | ||
872 | } | ||
873 | |||
849 | static void forget_original_parent(struct task_struct *father) | 874 | static void forget_original_parent(struct task_struct *father) |
850 | { | 875 | { |
851 | struct task_struct *p, *n, *reaper = father; | 876 | struct task_struct *p, *n, *reaper; |
852 | LIST_HEAD(ptrace_dead); | 877 | LIST_HEAD(ptrace_dead); |
853 | 878 | ||
854 | write_lock_irq(&tasklist_lock); | 879 | write_lock_irq(&tasklist_lock); |
855 | 880 | reaper = find_new_reaper(father); | |
856 | /* | 881 | /* |
857 | * First clean up ptrace if we were using it. | 882 | * First clean up ptrace if we were using it. |
858 | */ | 883 | */ |
859 | ptrace_exit(father, &ptrace_dead); | 884 | ptrace_exit(father, &ptrace_dead); |
860 | 885 | ||
861 | do { | ||
862 | reaper = next_thread(reaper); | ||
863 | if (reaper == father) { | ||
864 | reaper = task_child_reaper(father); | ||
865 | break; | ||
866 | } | ||
867 | } while (reaper->flags & PF_EXITING); | ||
868 | |||
869 | list_for_each_entry_safe(p, n, &father->children, sibling) { | 886 | list_for_each_entry_safe(p, n, &father->children, sibling) { |
870 | p->real_parent = reaper; | 887 | p->real_parent = reaper; |
871 | if (p->parent == father) { | 888 | if (p->parent == father) { |
@@ -887,7 +904,8 @@ static void forget_original_parent(struct task_struct *father) | |||
887 | */ | 904 | */ |
888 | static void exit_notify(struct task_struct *tsk, int group_dead) | 905 | static void exit_notify(struct task_struct *tsk, int group_dead) |
889 | { | 906 | { |
890 | int state; | 907 | int signal; |
908 | void *cookie; | ||
891 | 909 | ||
892 | /* | 910 | /* |
893 | * This does two things: | 911 | * This does two things: |
@@ -924,33 +942,24 @@ static void exit_notify(struct task_struct *tsk, int group_dead) | |||
924 | !capable(CAP_KILL)) | 942 | !capable(CAP_KILL)) |
925 | tsk->exit_signal = SIGCHLD; | 943 | tsk->exit_signal = SIGCHLD; |
926 | 944 | ||
927 | /* If something other than our normal parent is ptracing us, then | 945 | signal = tracehook_notify_death(tsk, &cookie, group_dead); |
928 | * send it a SIGCHLD instead of honoring exit_signal. exit_signal | 946 | if (signal >= 0) |
929 | * only has special meaning to our real parent. | 947 | signal = do_notify_parent(tsk, signal); |
930 | */ | ||
931 | if (!task_detached(tsk) && thread_group_empty(tsk)) { | ||
932 | int signal = ptrace_reparented(tsk) ? | ||
933 | SIGCHLD : tsk->exit_signal; | ||
934 | do_notify_parent(tsk, signal); | ||
935 | } else if (tsk->ptrace) { | ||
936 | do_notify_parent(tsk, SIGCHLD); | ||
937 | } | ||
938 | 948 | ||
939 | state = EXIT_ZOMBIE; | 949 | tsk->exit_state = signal == DEATH_REAP ? EXIT_DEAD : EXIT_ZOMBIE; |
940 | if (task_detached(tsk) && likely(!tsk->ptrace)) | ||
941 | state = EXIT_DEAD; | ||
942 | tsk->exit_state = state; | ||
943 | 950 | ||
944 | /* mt-exec, de_thread() is waiting for us */ | 951 | /* mt-exec, de_thread() is waiting for us */ |
945 | if (thread_group_leader(tsk) && | 952 | if (thread_group_leader(tsk) && |
946 | tsk->signal->notify_count < 0 && | 953 | tsk->signal->group_exit_task && |
947 | tsk->signal->group_exit_task) | 954 | tsk->signal->notify_count < 0) |
948 | wake_up_process(tsk->signal->group_exit_task); | 955 | wake_up_process(tsk->signal->group_exit_task); |
949 | 956 | ||
950 | write_unlock_irq(&tasklist_lock); | 957 | write_unlock_irq(&tasklist_lock); |
951 | 958 | ||
959 | tracehook_report_death(tsk, signal, cookie, group_dead); | ||
960 | |||
952 | /* If the process is dead, release it - nobody will wait for it */ | 961 | /* If the process is dead, release it - nobody will wait for it */ |
953 | if (state == EXIT_DEAD) | 962 | if (signal == DEATH_REAP) |
954 | release_task(tsk); | 963 | release_task(tsk); |
955 | } | 964 | } |
956 | 965 | ||
@@ -982,39 +991,6 @@ static void check_stack_usage(void) | |||
982 | static inline void check_stack_usage(void) {} | 991 | static inline void check_stack_usage(void) {} |
983 | #endif | 992 | #endif |
984 | 993 | ||
985 | static inline void exit_child_reaper(struct task_struct *tsk) | ||
986 | { | ||
987 | if (likely(tsk->group_leader != task_child_reaper(tsk))) | ||
988 | return; | ||
989 | |||
990 | if (tsk->nsproxy->pid_ns == &init_pid_ns) | ||
991 | panic("Attempted to kill init!"); | ||
992 | |||
993 | /* | ||
994 | * @tsk is the last thread in the 'cgroup-init' and is exiting. | ||
995 | * Terminate all remaining processes in the namespace and reap them | ||
996 | * before exiting @tsk. | ||
997 | * | ||
998 | * Note that @tsk (last thread of cgroup-init) may not necessarily | ||
999 | * be the child-reaper (i.e main thread of cgroup-init) of the | ||
1000 | * namespace i.e the child_reaper may have already exited. | ||
1001 | * | ||
1002 | * Even after a child_reaper exits, we let it inherit orphaned children, | ||
1003 | * because, pid_ns->child_reaper remains valid as long as there is | ||
1004 | * at least one living sub-thread in the cgroup init. | ||
1005 | |||
1006 | * This living sub-thread of the cgroup-init will be notified when | ||
1007 | * a child inherited by the 'child-reaper' exits (do_notify_parent() | ||
1008 | * uses __group_send_sig_info()). Further, when reaping child processes, | ||
1009 | * do_wait() iterates over children of all living sub threads. | ||
1010 | |||
1011 | * i.e even though 'child_reaper' thread is listed as the parent of the | ||
1012 | * orphaned children, any living sub-thread in the cgroup-init can | ||
1013 | * perform the role of the child_reaper. | ||
1014 | */ | ||
1015 | zap_pid_ns_processes(tsk->nsproxy->pid_ns); | ||
1016 | } | ||
1017 | |||
1018 | NORET_TYPE void do_exit(long code) | 994 | NORET_TYPE void do_exit(long code) |
1019 | { | 995 | { |
1020 | struct task_struct *tsk = current; | 996 | struct task_struct *tsk = current; |
@@ -1029,10 +1005,7 @@ NORET_TYPE void do_exit(long code) | |||
1029 | if (unlikely(!tsk->pid)) | 1005 | if (unlikely(!tsk->pid)) |
1030 | panic("Attempted to kill the idle task!"); | 1006 | panic("Attempted to kill the idle task!"); |
1031 | 1007 | ||
1032 | if (unlikely(current->ptrace & PT_TRACE_EXIT)) { | 1008 | tracehook_report_exit(&code); |
1033 | current->ptrace_message = code; | ||
1034 | ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP); | ||
1035 | } | ||
1036 | 1009 | ||
1037 | /* | 1010 | /* |
1038 | * We're taking recursive faults here in do_exit. Safest is to just | 1011 | * We're taking recursive faults here in do_exit. Safest is to just |
@@ -1077,7 +1050,6 @@ NORET_TYPE void do_exit(long code) | |||
1077 | } | 1050 | } |
1078 | group_dead = atomic_dec_and_test(&tsk->signal->live); | 1051 | group_dead = atomic_dec_and_test(&tsk->signal->live); |
1079 | if (group_dead) { | 1052 | if (group_dead) { |
1080 | exit_child_reaper(tsk); | ||
1081 | hrtimer_cancel(&tsk->signal->real_timer); | 1053 | hrtimer_cancel(&tsk->signal->real_timer); |
1082 | exit_itimers(tsk->signal); | 1054 | exit_itimers(tsk->signal); |
1083 | } | 1055 | } |
@@ -1378,21 +1350,8 @@ static int wait_task_zombie(struct task_struct *p, int options, | |||
1378 | psig->coublock += | 1350 | psig->coublock += |
1379 | task_io_get_oublock(p) + | 1351 | task_io_get_oublock(p) + |
1380 | sig->oublock + sig->coublock; | 1352 | sig->oublock + sig->coublock; |
1381 | #ifdef CONFIG_TASK_XACCT | 1353 | task_io_accounting_add(&psig->ioac, &p->ioac); |
1382 | psig->rchar += p->rchar + sig->rchar; | 1354 | task_io_accounting_add(&psig->ioac, &sig->ioac); |
1383 | psig->wchar += p->wchar + sig->wchar; | ||
1384 | psig->syscr += p->syscr + sig->syscr; | ||
1385 | psig->syscw += p->syscw + sig->syscw; | ||
1386 | #endif /* CONFIG_TASK_XACCT */ | ||
1387 | #ifdef CONFIG_TASK_IO_ACCOUNTING | ||
1388 | psig->ioac.read_bytes += | ||
1389 | p->ioac.read_bytes + sig->ioac.read_bytes; | ||
1390 | psig->ioac.write_bytes += | ||
1391 | p->ioac.write_bytes + sig->ioac.write_bytes; | ||
1392 | psig->ioac.cancelled_write_bytes += | ||
1393 | p->ioac.cancelled_write_bytes + | ||
1394 | sig->ioac.cancelled_write_bytes; | ||
1395 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ | ||
1396 | spin_unlock_irq(&p->parent->sighand->siglock); | 1355 | spin_unlock_irq(&p->parent->sighand->siglock); |
1397 | } | 1356 | } |
1398 | 1357 | ||
diff --git a/kernel/fork.c b/kernel/fork.c index b99d73e971a4..7ce2ebe84796 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/key.h> | 27 | #include <linux/key.h> |
28 | #include <linux/binfmts.h> | 28 | #include <linux/binfmts.h> |
29 | #include <linux/mman.h> | 29 | #include <linux/mman.h> |
30 | #include <linux/mmu_notifier.h> | ||
30 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
31 | #include <linux/nsproxy.h> | 32 | #include <linux/nsproxy.h> |
32 | #include <linux/capability.h> | 33 | #include <linux/capability.h> |
@@ -37,6 +38,7 @@ | |||
37 | #include <linux/swap.h> | 38 | #include <linux/swap.h> |
38 | #include <linux/syscalls.h> | 39 | #include <linux/syscalls.h> |
39 | #include <linux/jiffies.h> | 40 | #include <linux/jiffies.h> |
41 | #include <linux/tracehook.h> | ||
40 | #include <linux/futex.h> | 42 | #include <linux/futex.h> |
41 | #include <linux/task_io_accounting_ops.h> | 43 | #include <linux/task_io_accounting_ops.h> |
42 | #include <linux/rcupdate.h> | 44 | #include <linux/rcupdate.h> |
@@ -413,6 +415,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) | |||
413 | 415 | ||
414 | if (likely(!mm_alloc_pgd(mm))) { | 416 | if (likely(!mm_alloc_pgd(mm))) { |
415 | mm->def_flags = 0; | 417 | mm->def_flags = 0; |
418 | mmu_notifier_mm_init(mm); | ||
416 | return mm; | 419 | return mm; |
417 | } | 420 | } |
418 | 421 | ||
@@ -445,6 +448,7 @@ void __mmdrop(struct mm_struct *mm) | |||
445 | BUG_ON(mm == &init_mm); | 448 | BUG_ON(mm == &init_mm); |
446 | mm_free_pgd(mm); | 449 | mm_free_pgd(mm); |
447 | destroy_context(mm); | 450 | destroy_context(mm); |
451 | mmu_notifier_mm_destroy(mm); | ||
448 | free_mm(mm); | 452 | free_mm(mm); |
449 | } | 453 | } |
450 | EXPORT_SYMBOL_GPL(__mmdrop); | 454 | EXPORT_SYMBOL_GPL(__mmdrop); |
@@ -656,13 +660,6 @@ static struct fs_struct *__copy_fs_struct(struct fs_struct *old) | |||
656 | path_get(&old->root); | 660 | path_get(&old->root); |
657 | fs->pwd = old->pwd; | 661 | fs->pwd = old->pwd; |
658 | path_get(&old->pwd); | 662 | path_get(&old->pwd); |
659 | if (old->altroot.dentry) { | ||
660 | fs->altroot = old->altroot; | ||
661 | path_get(&old->altroot); | ||
662 | } else { | ||
663 | fs->altroot.mnt = NULL; | ||
664 | fs->altroot.dentry = NULL; | ||
665 | } | ||
666 | read_unlock(&old->lock); | 663 | read_unlock(&old->lock); |
667 | } | 664 | } |
668 | return fs; | 665 | return fs; |
@@ -812,12 +809,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
812 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; | 809 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; |
813 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; | 810 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; |
814 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; | 811 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; |
815 | #ifdef CONFIG_TASK_XACCT | 812 | task_io_accounting_init(&sig->ioac); |
816 | sig->rchar = sig->wchar = sig->syscr = sig->syscw = 0; | ||
817 | #endif | ||
818 | #ifdef CONFIG_TASK_IO_ACCOUNTING | ||
819 | memset(&sig->ioac, 0, sizeof(sig->ioac)); | ||
820 | #endif | ||
821 | sig->sum_sched_runtime = 0; | 813 | sig->sum_sched_runtime = 0; |
822 | INIT_LIST_HEAD(&sig->cpu_timers[0]); | 814 | INIT_LIST_HEAD(&sig->cpu_timers[0]); |
823 | INIT_LIST_HEAD(&sig->cpu_timers[1]); | 815 | INIT_LIST_HEAD(&sig->cpu_timers[1]); |
@@ -865,8 +857,7 @@ static void copy_flags(unsigned long clone_flags, struct task_struct *p) | |||
865 | 857 | ||
866 | new_flags &= ~PF_SUPERPRIV; | 858 | new_flags &= ~PF_SUPERPRIV; |
867 | new_flags |= PF_FORKNOEXEC; | 859 | new_flags |= PF_FORKNOEXEC; |
868 | if (!(clone_flags & CLONE_PTRACE)) | 860 | new_flags |= PF_STARTING; |
869 | p->ptrace = 0; | ||
870 | p->flags = new_flags; | 861 | p->flags = new_flags; |
871 | clear_freeze_flag(p); | 862 | clear_freeze_flag(p); |
872 | } | 863 | } |
@@ -907,7 +898,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
907 | struct pt_regs *regs, | 898 | struct pt_regs *regs, |
908 | unsigned long stack_size, | 899 | unsigned long stack_size, |
909 | int __user *child_tidptr, | 900 | int __user *child_tidptr, |
910 | struct pid *pid) | 901 | struct pid *pid, |
902 | int trace) | ||
911 | { | 903 | { |
912 | int retval; | 904 | int retval; |
913 | struct task_struct *p; | 905 | struct task_struct *p; |
@@ -1000,13 +992,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1000 | p->last_switch_timestamp = 0; | 992 | p->last_switch_timestamp = 0; |
1001 | #endif | 993 | #endif |
1002 | 994 | ||
1003 | #ifdef CONFIG_TASK_XACCT | 995 | task_io_accounting_init(&p->ioac); |
1004 | p->rchar = 0; /* I/O counter: bytes read */ | ||
1005 | p->wchar = 0; /* I/O counter: bytes written */ | ||
1006 | p->syscr = 0; /* I/O counter: read syscalls */ | ||
1007 | p->syscw = 0; /* I/O counter: write syscalls */ | ||
1008 | #endif | ||
1009 | task_io_accounting_init(p); | ||
1010 | acct_clear_integrals(p); | 996 | acct_clear_integrals(p); |
1011 | 997 | ||
1012 | p->it_virt_expires = cputime_zero; | 998 | p->it_virt_expires = cputime_zero; |
@@ -1163,8 +1149,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1163 | */ | 1149 | */ |
1164 | p->group_leader = p; | 1150 | p->group_leader = p; |
1165 | INIT_LIST_HEAD(&p->thread_group); | 1151 | INIT_LIST_HEAD(&p->thread_group); |
1166 | INIT_LIST_HEAD(&p->ptrace_entry); | ||
1167 | INIT_LIST_HEAD(&p->ptraced); | ||
1168 | 1152 | ||
1169 | /* Now that the task is set up, run cgroup callbacks if | 1153 | /* Now that the task is set up, run cgroup callbacks if |
1170 | * necessary. We need to run them before the task is visible | 1154 | * necessary. We need to run them before the task is visible |
@@ -1195,7 +1179,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1195 | p->real_parent = current->real_parent; | 1179 | p->real_parent = current->real_parent; |
1196 | else | 1180 | else |
1197 | p->real_parent = current; | 1181 | p->real_parent = current; |
1198 | p->parent = p->real_parent; | ||
1199 | 1182 | ||
1200 | spin_lock(¤t->sighand->siglock); | 1183 | spin_lock(¤t->sighand->siglock); |
1201 | 1184 | ||
@@ -1237,8 +1220,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1237 | 1220 | ||
1238 | if (likely(p->pid)) { | 1221 | if (likely(p->pid)) { |
1239 | list_add_tail(&p->sibling, &p->real_parent->children); | 1222 | list_add_tail(&p->sibling, &p->real_parent->children); |
1240 | if (unlikely(p->ptrace & PT_PTRACED)) | 1223 | tracehook_finish_clone(p, clone_flags, trace); |
1241 | __ptrace_link(p, current->parent); | ||
1242 | 1224 | ||
1243 | if (thread_group_leader(p)) { | 1225 | if (thread_group_leader(p)) { |
1244 | if (clone_flags & CLONE_NEWPID) | 1226 | if (clone_flags & CLONE_NEWPID) |
@@ -1323,29 +1305,13 @@ struct task_struct * __cpuinit fork_idle(int cpu) | |||
1323 | struct pt_regs regs; | 1305 | struct pt_regs regs; |
1324 | 1306 | ||
1325 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, | 1307 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, |
1326 | &init_struct_pid); | 1308 | &init_struct_pid, 0); |
1327 | if (!IS_ERR(task)) | 1309 | if (!IS_ERR(task)) |
1328 | init_idle(task, cpu); | 1310 | init_idle(task, cpu); |
1329 | 1311 | ||
1330 | return task; | 1312 | return task; |
1331 | } | 1313 | } |
1332 | 1314 | ||
1333 | static int fork_traceflag(unsigned clone_flags) | ||
1334 | { | ||
1335 | if (clone_flags & CLONE_UNTRACED) | ||
1336 | return 0; | ||
1337 | else if (clone_flags & CLONE_VFORK) { | ||
1338 | if (current->ptrace & PT_TRACE_VFORK) | ||
1339 | return PTRACE_EVENT_VFORK; | ||
1340 | } else if ((clone_flags & CSIGNAL) != SIGCHLD) { | ||
1341 | if (current->ptrace & PT_TRACE_CLONE) | ||
1342 | return PTRACE_EVENT_CLONE; | ||
1343 | } else if (current->ptrace & PT_TRACE_FORK) | ||
1344 | return PTRACE_EVENT_FORK; | ||
1345 | |||
1346 | return 0; | ||
1347 | } | ||
1348 | |||
1349 | /* | 1315 | /* |
1350 | * Ok, this is the main fork-routine. | 1316 | * Ok, this is the main fork-routine. |
1351 | * | 1317 | * |
@@ -1380,14 +1346,14 @@ long do_fork(unsigned long clone_flags, | |||
1380 | } | 1346 | } |
1381 | } | 1347 | } |
1382 | 1348 | ||
1383 | if (unlikely(current->ptrace)) { | 1349 | /* |
1384 | trace = fork_traceflag (clone_flags); | 1350 | * When called from kernel_thread, don't do user tracing stuff. |
1385 | if (trace) | 1351 | */ |
1386 | clone_flags |= CLONE_PTRACE; | 1352 | if (likely(user_mode(regs))) |
1387 | } | 1353 | trace = tracehook_prepare_clone(clone_flags); |
1388 | 1354 | ||
1389 | p = copy_process(clone_flags, stack_start, regs, stack_size, | 1355 | p = copy_process(clone_flags, stack_start, regs, stack_size, |
1390 | child_tidptr, NULL); | 1356 | child_tidptr, NULL, trace); |
1391 | /* | 1357 | /* |
1392 | * Do this prior waking up the new thread - the thread pointer | 1358 | * Do this prior waking up the new thread - the thread pointer |
1393 | * might get invalid after that point, if the thread exits quickly. | 1359 | * might get invalid after that point, if the thread exits quickly. |
@@ -1405,32 +1371,35 @@ long do_fork(unsigned long clone_flags, | |||
1405 | init_completion(&vfork); | 1371 | init_completion(&vfork); |
1406 | } | 1372 | } |
1407 | 1373 | ||
1408 | if ((p->ptrace & PT_PTRACED) || (clone_flags & CLONE_STOPPED)) { | 1374 | tracehook_report_clone(trace, regs, clone_flags, nr, p); |
1375 | |||
1376 | /* | ||
1377 | * We set PF_STARTING at creation in case tracing wants to | ||
1378 | * use this to distinguish a fully live task from one that | ||
1379 | * hasn't gotten to tracehook_report_clone() yet. Now we | ||
1380 | * clear it and set the child going. | ||
1381 | */ | ||
1382 | p->flags &= ~PF_STARTING; | ||
1383 | |||
1384 | if (unlikely(clone_flags & CLONE_STOPPED)) { | ||
1409 | /* | 1385 | /* |
1410 | * We'll start up with an immediate SIGSTOP. | 1386 | * We'll start up with an immediate SIGSTOP. |
1411 | */ | 1387 | */ |
1412 | sigaddset(&p->pending.signal, SIGSTOP); | 1388 | sigaddset(&p->pending.signal, SIGSTOP); |
1413 | set_tsk_thread_flag(p, TIF_SIGPENDING); | 1389 | set_tsk_thread_flag(p, TIF_SIGPENDING); |
1414 | } | ||
1415 | |||
1416 | if (!(clone_flags & CLONE_STOPPED)) | ||
1417 | wake_up_new_task(p, clone_flags); | ||
1418 | else | ||
1419 | __set_task_state(p, TASK_STOPPED); | 1390 | __set_task_state(p, TASK_STOPPED); |
1420 | 1391 | } else { | |
1421 | if (unlikely (trace)) { | 1392 | wake_up_new_task(p, clone_flags); |
1422 | current->ptrace_message = nr; | ||
1423 | ptrace_notify ((trace << 8) | SIGTRAP); | ||
1424 | } | 1393 | } |
1425 | 1394 | ||
1395 | tracehook_report_clone_complete(trace, regs, | ||
1396 | clone_flags, nr, p); | ||
1397 | |||
1426 | if (clone_flags & CLONE_VFORK) { | 1398 | if (clone_flags & CLONE_VFORK) { |
1427 | freezer_do_not_count(); | 1399 | freezer_do_not_count(); |
1428 | wait_for_completion(&vfork); | 1400 | wait_for_completion(&vfork); |
1429 | freezer_count(); | 1401 | freezer_count(); |
1430 | if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE)) { | 1402 | tracehook_report_vfork_done(p, nr); |
1431 | current->ptrace_message = nr; | ||
1432 | ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP); | ||
1433 | } | ||
1434 | } | 1403 | } |
1435 | } else { | 1404 | } else { |
1436 | nr = PTR_ERR(p); | 1405 | nr = PTR_ERR(p); |
@@ -1442,7 +1411,7 @@ long do_fork(unsigned long clone_flags, | |||
1442 | #define ARCH_MIN_MMSTRUCT_ALIGN 0 | 1411 | #define ARCH_MIN_MMSTRUCT_ALIGN 0 |
1443 | #endif | 1412 | #endif |
1444 | 1413 | ||
1445 | static void sighand_ctor(struct kmem_cache *cachep, void *data) | 1414 | static void sighand_ctor(void *data) |
1446 | { | 1415 | { |
1447 | struct sighand_struct *sighand = data; | 1416 | struct sighand_struct *sighand = data; |
1448 | 1417 | ||
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index b8e4dce80a74..cdec83e722fa 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -672,13 +672,14 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
672 | */ | 672 | */ |
673 | BUG_ON(timer->function(timer) != HRTIMER_NORESTART); | 673 | BUG_ON(timer->function(timer) != HRTIMER_NORESTART); |
674 | return 1; | 674 | return 1; |
675 | case HRTIMER_CB_IRQSAFE_NO_SOFTIRQ: | 675 | case HRTIMER_CB_IRQSAFE_PERCPU: |
676 | case HRTIMER_CB_IRQSAFE_UNLOCKED: | ||
676 | /* | 677 | /* |
677 | * This is solely for the sched tick emulation with | 678 | * This is solely for the sched tick emulation with |
678 | * dynamic tick support to ensure that we do not | 679 | * dynamic tick support to ensure that we do not |
679 | * restart the tick right on the edge and end up with | 680 | * restart the tick right on the edge and end up with |
680 | * the tick timer in the softirq ! The calling site | 681 | * the tick timer in the softirq ! The calling site |
681 | * takes care of this. | 682 | * takes care of this. Also used for hrtimer sleeper ! |
682 | */ | 683 | */ |
683 | debug_hrtimer_deactivate(timer); | 684 | debug_hrtimer_deactivate(timer); |
684 | return 1; | 685 | return 1; |
@@ -1245,7 +1246,8 @@ static void __run_hrtimer(struct hrtimer *timer) | |||
1245 | timer_stats_account_hrtimer(timer); | 1246 | timer_stats_account_hrtimer(timer); |
1246 | 1247 | ||
1247 | fn = timer->function; | 1248 | fn = timer->function; |
1248 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_NO_SOFTIRQ) { | 1249 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU || |
1250 | timer->cb_mode == HRTIMER_CB_IRQSAFE_UNLOCKED) { | ||
1249 | /* | 1251 | /* |
1250 | * Used for scheduler timers, avoid lock inversion with | 1252 | * Used for scheduler timers, avoid lock inversion with |
1251 | * rq->lock and tasklist_lock. | 1253 | * rq->lock and tasklist_lock. |
@@ -1452,7 +1454,7 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) | |||
1452 | sl->timer.function = hrtimer_wakeup; | 1454 | sl->timer.function = hrtimer_wakeup; |
1453 | sl->task = task; | 1455 | sl->task = task; |
1454 | #ifdef CONFIG_HIGH_RES_TIMERS | 1456 | #ifdef CONFIG_HIGH_RES_TIMERS |
1455 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 1457 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED; |
1456 | #endif | 1458 | #endif |
1457 | } | 1459 | } |
1458 | 1460 | ||
@@ -1591,29 +1593,95 @@ static void __cpuinit init_hrtimers_cpu(int cpu) | |||
1591 | 1593 | ||
1592 | #ifdef CONFIG_HOTPLUG_CPU | 1594 | #ifdef CONFIG_HOTPLUG_CPU |
1593 | 1595 | ||
1594 | static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | 1596 | static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, |
1595 | struct hrtimer_clock_base *new_base) | 1597 | struct hrtimer_clock_base *new_base, int dcpu) |
1596 | { | 1598 | { |
1597 | struct hrtimer *timer; | 1599 | struct hrtimer *timer; |
1598 | struct rb_node *node; | 1600 | struct rb_node *node; |
1601 | int raise = 0; | ||
1599 | 1602 | ||
1600 | while ((node = rb_first(&old_base->active))) { | 1603 | while ((node = rb_first(&old_base->active))) { |
1601 | timer = rb_entry(node, struct hrtimer, node); | 1604 | timer = rb_entry(node, struct hrtimer, node); |
1602 | BUG_ON(hrtimer_callback_running(timer)); | 1605 | BUG_ON(hrtimer_callback_running(timer)); |
1603 | debug_hrtimer_deactivate(timer); | 1606 | debug_hrtimer_deactivate(timer); |
1604 | __remove_hrtimer(timer, old_base, HRTIMER_STATE_INACTIVE, 0); | 1607 | |
1608 | /* | ||
1609 | * Should not happen. Per CPU timers should be | ||
1610 | * canceled _before_ the migration code is called | ||
1611 | */ | ||
1612 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU) { | ||
1613 | __remove_hrtimer(timer, old_base, | ||
1614 | HRTIMER_STATE_INACTIVE, 0); | ||
1615 | WARN(1, "hrtimer (%p %p)active but cpu %d dead\n", | ||
1616 | timer, timer->function, dcpu); | ||
1617 | continue; | ||
1618 | } | ||
1619 | |||
1620 | /* | ||
1621 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the | ||
1622 | * timer could be seen as !active and just vanish away | ||
1623 | * under us on another CPU | ||
1624 | */ | ||
1625 | __remove_hrtimer(timer, old_base, HRTIMER_STATE_MIGRATE, 0); | ||
1605 | timer->base = new_base; | 1626 | timer->base = new_base; |
1606 | /* | 1627 | /* |
1607 | * Enqueue the timer. Allow reprogramming of the event device | 1628 | * Enqueue the timer. Allow reprogramming of the event device |
1608 | */ | 1629 | */ |
1609 | enqueue_hrtimer(timer, new_base, 1); | 1630 | enqueue_hrtimer(timer, new_base, 1); |
1631 | |||
1632 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1633 | /* | ||
1634 | * Happens with high res enabled when the timer was | ||
1635 | * already expired and the callback mode is | ||
1636 | * HRTIMER_CB_IRQSAFE_UNLOCKED (hrtimer_sleeper). The | ||
1637 | * enqueue code does not move them to the soft irq | ||
1638 | * pending list for performance/latency reasons, but | ||
1639 | * in the migration state, we need to do that | ||
1640 | * otherwise we end up with a stale timer. | ||
1641 | */ | ||
1642 | if (timer->state == HRTIMER_STATE_MIGRATE) { | ||
1643 | timer->state = HRTIMER_STATE_PENDING; | ||
1644 | list_add_tail(&timer->cb_entry, | ||
1645 | &new_base->cpu_base->cb_pending); | ||
1646 | raise = 1; | ||
1647 | } | ||
1648 | #endif | ||
1649 | /* Clear the migration state bit */ | ||
1650 | timer->state &= ~HRTIMER_STATE_MIGRATE; | ||
1651 | } | ||
1652 | return raise; | ||
1653 | } | ||
1654 | |||
1655 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1656 | static int migrate_hrtimer_pending(struct hrtimer_cpu_base *old_base, | ||
1657 | struct hrtimer_cpu_base *new_base) | ||
1658 | { | ||
1659 | struct hrtimer *timer; | ||
1660 | int raise = 0; | ||
1661 | |||
1662 | while (!list_empty(&old_base->cb_pending)) { | ||
1663 | timer = list_entry(old_base->cb_pending.next, | ||
1664 | struct hrtimer, cb_entry); | ||
1665 | |||
1666 | __remove_hrtimer(timer, timer->base, HRTIMER_STATE_PENDING, 0); | ||
1667 | timer->base = &new_base->clock_base[timer->base->index]; | ||
1668 | list_add_tail(&timer->cb_entry, &new_base->cb_pending); | ||
1669 | raise = 1; | ||
1610 | } | 1670 | } |
1671 | return raise; | ||
1672 | } | ||
1673 | #else | ||
1674 | static int migrate_hrtimer_pending(struct hrtimer_cpu_base *old_base, | ||
1675 | struct hrtimer_cpu_base *new_base) | ||
1676 | { | ||
1677 | return 0; | ||
1611 | } | 1678 | } |
1679 | #endif | ||
1612 | 1680 | ||
1613 | static void migrate_hrtimers(int cpu) | 1681 | static void migrate_hrtimers(int cpu) |
1614 | { | 1682 | { |
1615 | struct hrtimer_cpu_base *old_base, *new_base; | 1683 | struct hrtimer_cpu_base *old_base, *new_base; |
1616 | int i; | 1684 | int i, raise = 0; |
1617 | 1685 | ||
1618 | BUG_ON(cpu_online(cpu)); | 1686 | BUG_ON(cpu_online(cpu)); |
1619 | old_base = &per_cpu(hrtimer_bases, cpu); | 1687 | old_base = &per_cpu(hrtimer_bases, cpu); |
@@ -1626,14 +1694,21 @@ static void migrate_hrtimers(int cpu) | |||
1626 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); | 1694 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
1627 | 1695 | ||
1628 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { | 1696 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { |
1629 | migrate_hrtimer_list(&old_base->clock_base[i], | 1697 | if (migrate_hrtimer_list(&old_base->clock_base[i], |
1630 | &new_base->clock_base[i]); | 1698 | &new_base->clock_base[i], cpu)) |
1699 | raise = 1; | ||
1631 | } | 1700 | } |
1632 | 1701 | ||
1702 | if (migrate_hrtimer_pending(old_base, new_base)) | ||
1703 | raise = 1; | ||
1704 | |||
1633 | spin_unlock(&old_base->lock); | 1705 | spin_unlock(&old_base->lock); |
1634 | spin_unlock(&new_base->lock); | 1706 | spin_unlock(&new_base->lock); |
1635 | local_irq_enable(); | 1707 | local_irq_enable(); |
1636 | put_cpu_var(hrtimer_bases); | 1708 | put_cpu_var(hrtimer_bases); |
1709 | |||
1710 | if (raise) | ||
1711 | hrtimer_raise_softirq(); | ||
1637 | } | 1712 | } |
1638 | #endif /* CONFIG_HOTPLUG_CPU */ | 1713 | #endif /* CONFIG_HOTPLUG_CPU */ |
1639 | 1714 | ||
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 964964baefa2..3cd441ebf5d2 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c | |||
@@ -28,8 +28,7 @@ void dynamic_irq_init(unsigned int irq) | |||
28 | unsigned long flags; | 28 | unsigned long flags; |
29 | 29 | ||
30 | if (irq >= NR_IRQS) { | 30 | if (irq >= NR_IRQS) { |
31 | printk(KERN_ERR "Trying to initialize invalid IRQ%d\n", irq); | 31 | WARN(1, KERN_ERR "Trying to initialize invalid IRQ%d\n", irq); |
32 | WARN_ON(1); | ||
33 | return; | 32 | return; |
34 | } | 33 | } |
35 | 34 | ||
@@ -62,8 +61,7 @@ void dynamic_irq_cleanup(unsigned int irq) | |||
62 | unsigned long flags; | 61 | unsigned long flags; |
63 | 62 | ||
64 | if (irq >= NR_IRQS) { | 63 | if (irq >= NR_IRQS) { |
65 | printk(KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq); | 64 | WARN(1, KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq); |
66 | WARN_ON(1); | ||
67 | return; | 65 | return; |
68 | } | 66 | } |
69 | 67 | ||
@@ -71,9 +69,8 @@ void dynamic_irq_cleanup(unsigned int irq) | |||
71 | spin_lock_irqsave(&desc->lock, flags); | 69 | spin_lock_irqsave(&desc->lock, flags); |
72 | if (desc->action) { | 70 | if (desc->action) { |
73 | spin_unlock_irqrestore(&desc->lock, flags); | 71 | spin_unlock_irqrestore(&desc->lock, flags); |
74 | printk(KERN_ERR "Destroying IRQ%d without calling free_irq\n", | 72 | WARN(1, KERN_ERR "Destroying IRQ%d without calling free_irq\n", |
75 | irq); | 73 | irq); |
76 | WARN_ON(1); | ||
77 | return; | 74 | return; |
78 | } | 75 | } |
79 | desc->msi_desc = NULL; | 76 | desc->msi_desc = NULL; |
@@ -96,8 +93,7 @@ int set_irq_chip(unsigned int irq, struct irq_chip *chip) | |||
96 | unsigned long flags; | 93 | unsigned long flags; |
97 | 94 | ||
98 | if (irq >= NR_IRQS) { | 95 | if (irq >= NR_IRQS) { |
99 | printk(KERN_ERR "Trying to install chip for IRQ%d\n", irq); | 96 | WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq); |
100 | WARN_ON(1); | ||
101 | return -EINVAL; | 97 | return -EINVAL; |
102 | } | 98 | } |
103 | 99 | ||
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index f8914b92b664..60c49e324390 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
@@ -89,7 +89,14 @@ int irq_set_affinity(unsigned int irq, cpumask_t cpumask) | |||
89 | set_balance_irq_affinity(irq, cpumask); | 89 | set_balance_irq_affinity(irq, cpumask); |
90 | 90 | ||
91 | #ifdef CONFIG_GENERIC_PENDING_IRQ | 91 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
92 | set_pending_irq(irq, cpumask); | 92 | if (desc->status & IRQ_MOVE_PCNTXT) { |
93 | unsigned long flags; | ||
94 | |||
95 | spin_lock_irqsave(&desc->lock, flags); | ||
96 | desc->chip->set_affinity(irq, cpumask); | ||
97 | spin_unlock_irqrestore(&desc->lock, flags); | ||
98 | } else | ||
99 | set_pending_irq(irq, cpumask); | ||
93 | #else | 100 | #else |
94 | desc->affinity = cpumask; | 101 | desc->affinity = cpumask; |
95 | desc->chip->set_affinity(irq, cpumask); | 102 | desc->chip->set_affinity(irq, cpumask); |
@@ -177,8 +184,7 @@ static void __enable_irq(struct irq_desc *desc, unsigned int irq) | |||
177 | { | 184 | { |
178 | switch (desc->depth) { | 185 | switch (desc->depth) { |
179 | case 0: | 186 | case 0: |
180 | printk(KERN_WARNING "Unbalanced enable for IRQ %d\n", irq); | 187 | WARN(1, KERN_WARNING "Unbalanced enable for IRQ %d\n", irq); |
181 | WARN_ON(1); | ||
182 | break; | 188 | break; |
183 | case 1: { | 189 | case 1: { |
184 | unsigned int status = desc->status & ~IRQ_DISABLED; | 190 | unsigned int status = desc->status & ~IRQ_DISABLED; |
@@ -324,7 +330,8 @@ static int __irq_set_trigger(struct irq_chip *chip, unsigned int irq, | |||
324 | ret = chip->set_type(irq, flags & IRQF_TRIGGER_MASK); | 330 | ret = chip->set_type(irq, flags & IRQF_TRIGGER_MASK); |
325 | 331 | ||
326 | if (ret) | 332 | if (ret) |
327 | pr_err("setting flow type for irq %u failed (%pF)\n", | 333 | pr_err("setting trigger mode %d for irq %u failed (%pF)\n", |
334 | (int)(flags & IRQF_TRIGGER_MASK), | ||
328 | irq, chip->set_type); | 335 | irq, chip->set_type); |
329 | 336 | ||
330 | return ret; | 337 | return ret; |
diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 6c6d35d68ee9..a09dd29c2fd7 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include <linux/irq.h> | 9 | #include <linux/irq.h> |
10 | #include <linux/proc_fs.h> | 10 | #include <linux/proc_fs.h> |
11 | #include <linux/seq_file.h> | ||
11 | #include <linux/interrupt.h> | 12 | #include <linux/interrupt.h> |
12 | 13 | ||
13 | #include "internals.h" | 14 | #include "internals.h" |
@@ -16,23 +17,18 @@ static struct proc_dir_entry *root_irq_dir; | |||
16 | 17 | ||
17 | #ifdef CONFIG_SMP | 18 | #ifdef CONFIG_SMP |
18 | 19 | ||
19 | static int irq_affinity_read_proc(char *page, char **start, off_t off, | 20 | static int irq_affinity_proc_show(struct seq_file *m, void *v) |
20 | int count, int *eof, void *data) | ||
21 | { | 21 | { |
22 | struct irq_desc *desc = irq_desc + (long)data; | 22 | struct irq_desc *desc = irq_desc + (long)m->private; |
23 | cpumask_t *mask = &desc->affinity; | 23 | cpumask_t *mask = &desc->affinity; |
24 | int len; | ||
25 | 24 | ||
26 | #ifdef CONFIG_GENERIC_PENDING_IRQ | 25 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
27 | if (desc->status & IRQ_MOVE_PENDING) | 26 | if (desc->status & IRQ_MOVE_PENDING) |
28 | mask = &desc->pending_mask; | 27 | mask = &desc->pending_mask; |
29 | #endif | 28 | #endif |
30 | len = cpumask_scnprintf(page, count, *mask); | 29 | seq_cpumask(m, mask); |
31 | 30 | seq_putc(m, '\n'); | |
32 | if (count - len < 2) | 31 | return 0; |
33 | return -EINVAL; | ||
34 | len += sprintf(page + len, "\n"); | ||
35 | return len; | ||
36 | } | 32 | } |
37 | 33 | ||
38 | #ifndef is_affinity_mask_valid | 34 | #ifndef is_affinity_mask_valid |
@@ -40,11 +36,12 @@ static int irq_affinity_read_proc(char *page, char **start, off_t off, | |||
40 | #endif | 36 | #endif |
41 | 37 | ||
42 | int no_irq_affinity; | 38 | int no_irq_affinity; |
43 | static int irq_affinity_write_proc(struct file *file, const char __user *buffer, | 39 | static ssize_t irq_affinity_proc_write(struct file *file, |
44 | unsigned long count, void *data) | 40 | const char __user *buffer, size_t count, loff_t *pos) |
45 | { | 41 | { |
46 | unsigned int irq = (int)(long)data, full_count = count, err; | 42 | unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data; |
47 | cpumask_t new_value; | 43 | cpumask_t new_value; |
44 | int err; | ||
48 | 45 | ||
49 | if (!irq_desc[irq].chip->set_affinity || no_irq_affinity || | 46 | if (!irq_desc[irq].chip->set_affinity || no_irq_affinity || |
50 | irq_balancing_disabled(irq)) | 47 | irq_balancing_disabled(irq)) |
@@ -65,28 +62,38 @@ static int irq_affinity_write_proc(struct file *file, const char __user *buffer, | |||
65 | if (!cpus_intersects(new_value, cpu_online_map)) | 62 | if (!cpus_intersects(new_value, cpu_online_map)) |
66 | /* Special case for empty set - allow the architecture | 63 | /* Special case for empty set - allow the architecture |
67 | code to set default SMP affinity. */ | 64 | code to set default SMP affinity. */ |
68 | return irq_select_affinity(irq) ? -EINVAL : full_count; | 65 | return irq_select_affinity(irq) ? -EINVAL : count; |
69 | 66 | ||
70 | irq_set_affinity(irq, new_value); | 67 | irq_set_affinity(irq, new_value); |
71 | 68 | ||
72 | return full_count; | 69 | return count; |
73 | } | 70 | } |
74 | 71 | ||
75 | static int default_affinity_read(char *page, char **start, off_t off, | 72 | static int irq_affinity_proc_open(struct inode *inode, struct file *file) |
76 | int count, int *eof, void *data) | ||
77 | { | 73 | { |
78 | int len = cpumask_scnprintf(page, count, irq_default_affinity); | 74 | return single_open(file, irq_affinity_proc_show, PDE(inode)->data); |
79 | if (count - len < 2) | ||
80 | return -EINVAL; | ||
81 | len += sprintf(page + len, "\n"); | ||
82 | return len; | ||
83 | } | 75 | } |
84 | 76 | ||
85 | static int default_affinity_write(struct file *file, const char __user *buffer, | 77 | static const struct file_operations irq_affinity_proc_fops = { |
86 | unsigned long count, void *data) | 78 | .open = irq_affinity_proc_open, |
79 | .read = seq_read, | ||
80 | .llseek = seq_lseek, | ||
81 | .release = single_release, | ||
82 | .write = irq_affinity_proc_write, | ||
83 | }; | ||
84 | |||
85 | static int default_affinity_show(struct seq_file *m, void *v) | ||
86 | { | ||
87 | seq_cpumask(m, &irq_default_affinity); | ||
88 | seq_putc(m, '\n'); | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static ssize_t default_affinity_write(struct file *file, | ||
93 | const char __user *buffer, size_t count, loff_t *ppos) | ||
87 | { | 94 | { |
88 | unsigned int full_count = count, err; | ||
89 | cpumask_t new_value; | 95 | cpumask_t new_value; |
96 | int err; | ||
90 | 97 | ||
91 | err = cpumask_parse_user(buffer, count, new_value); | 98 | err = cpumask_parse_user(buffer, count, new_value); |
92 | if (err) | 99 | if (err) |
@@ -105,8 +112,21 @@ static int default_affinity_write(struct file *file, const char __user *buffer, | |||
105 | 112 | ||
106 | irq_default_affinity = new_value; | 113 | irq_default_affinity = new_value; |
107 | 114 | ||
108 | return full_count; | 115 | return count; |
109 | } | 116 | } |
117 | |||
118 | static int default_affinity_open(struct inode *inode, struct file *file) | ||
119 | { | ||
120 | return single_open(file, default_affinity_show, NULL); | ||
121 | } | ||
122 | |||
123 | static const struct file_operations default_affinity_proc_fops = { | ||
124 | .open = default_affinity_open, | ||
125 | .read = seq_read, | ||
126 | .llseek = seq_lseek, | ||
127 | .release = single_release, | ||
128 | .write = default_affinity_write, | ||
129 | }; | ||
110 | #endif | 130 | #endif |
111 | 131 | ||
112 | static int irq_spurious_read(char *page, char **start, off_t off, | 132 | static int irq_spurious_read(char *page, char **start, off_t off, |
@@ -178,16 +198,9 @@ void register_irq_proc(unsigned int irq) | |||
178 | irq_desc[irq].dir = proc_mkdir(name, root_irq_dir); | 198 | irq_desc[irq].dir = proc_mkdir(name, root_irq_dir); |
179 | 199 | ||
180 | #ifdef CONFIG_SMP | 200 | #ifdef CONFIG_SMP |
181 | { | 201 | /* create /proc/irq/<irq>/smp_affinity */ |
182 | /* create /proc/irq/<irq>/smp_affinity */ | 202 | proc_create_data("smp_affinity", 0600, irq_desc[irq].dir, |
183 | entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir); | 203 | &irq_affinity_proc_fops, (void *)(long)irq); |
184 | |||
185 | if (entry) { | ||
186 | entry->data = (void *)(long)irq; | ||
187 | entry->read_proc = irq_affinity_read_proc; | ||
188 | entry->write_proc = irq_affinity_write_proc; | ||
189 | } | ||
190 | } | ||
191 | #endif | 204 | #endif |
192 | 205 | ||
193 | entry = create_proc_entry("spurious", 0444, irq_desc[irq].dir); | 206 | entry = create_proc_entry("spurious", 0444, irq_desc[irq].dir); |
@@ -208,15 +221,8 @@ void unregister_handler_proc(unsigned int irq, struct irqaction *action) | |||
208 | void register_default_affinity_proc(void) | 221 | void register_default_affinity_proc(void) |
209 | { | 222 | { |
210 | #ifdef CONFIG_SMP | 223 | #ifdef CONFIG_SMP |
211 | struct proc_dir_entry *entry; | 224 | proc_create("irq/default_smp_affinity", 0600, NULL, |
212 | 225 | &default_affinity_proc_fops); | |
213 | /* create /proc/irq/default_smp_affinity */ | ||
214 | entry = create_proc_entry("default_smp_affinity", 0600, root_irq_dir); | ||
215 | if (entry) { | ||
216 | entry->data = NULL; | ||
217 | entry->read_proc = default_affinity_read; | ||
218 | entry->write_proc = default_affinity_write; | ||
219 | } | ||
220 | #endif | 226 | #endif |
221 | } | 227 | } |
222 | 228 | ||
diff --git a/kernel/kexec.c b/kernel/kexec.c index 1c5fcacbcf33..aef265325cd3 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c | |||
@@ -12,7 +12,7 @@ | |||
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/fs.h> | 13 | #include <linux/fs.h> |
14 | #include <linux/kexec.h> | 14 | #include <linux/kexec.h> |
15 | #include <linux/spinlock.h> | 15 | #include <linux/mutex.h> |
16 | #include <linux/list.h> | 16 | #include <linux/list.h> |
17 | #include <linux/highmem.h> | 17 | #include <linux/highmem.h> |
18 | #include <linux/syscalls.h> | 18 | #include <linux/syscalls.h> |
@@ -24,6 +24,12 @@ | |||
24 | #include <linux/utsrelease.h> | 24 | #include <linux/utsrelease.h> |
25 | #include <linux/utsname.h> | 25 | #include <linux/utsname.h> |
26 | #include <linux/numa.h> | 26 | #include <linux/numa.h> |
27 | #include <linux/suspend.h> | ||
28 | #include <linux/device.h> | ||
29 | #include <linux/freezer.h> | ||
30 | #include <linux/pm.h> | ||
31 | #include <linux/cpu.h> | ||
32 | #include <linux/console.h> | ||
27 | 33 | ||
28 | #include <asm/page.h> | 34 | #include <asm/page.h> |
29 | #include <asm/uaccess.h> | 35 | #include <asm/uaccess.h> |
@@ -71,7 +77,7 @@ int kexec_should_crash(struct task_struct *p) | |||
71 | * | 77 | * |
72 | * The code for the transition from the current kernel to the | 78 | * The code for the transition from the current kernel to the |
73 | * the new kernel is placed in the control_code_buffer, whose size | 79 | * the new kernel is placed in the control_code_buffer, whose size |
74 | * is given by KEXEC_CONTROL_CODE_SIZE. In the best case only a single | 80 | * is given by KEXEC_CONTROL_PAGE_SIZE. In the best case only a single |
75 | * page of memory is necessary, but some architectures require more. | 81 | * page of memory is necessary, but some architectures require more. |
76 | * Because this memory must be identity mapped in the transition from | 82 | * Because this memory must be identity mapped in the transition from |
77 | * virtual to physical addresses it must live in the range | 83 | * virtual to physical addresses it must live in the range |
@@ -236,12 +242,18 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry, | |||
236 | */ | 242 | */ |
237 | result = -ENOMEM; | 243 | result = -ENOMEM; |
238 | image->control_code_page = kimage_alloc_control_pages(image, | 244 | image->control_code_page = kimage_alloc_control_pages(image, |
239 | get_order(KEXEC_CONTROL_CODE_SIZE)); | 245 | get_order(KEXEC_CONTROL_PAGE_SIZE)); |
240 | if (!image->control_code_page) { | 246 | if (!image->control_code_page) { |
241 | printk(KERN_ERR "Could not allocate control_code_buffer\n"); | 247 | printk(KERN_ERR "Could not allocate control_code_buffer\n"); |
242 | goto out; | 248 | goto out; |
243 | } | 249 | } |
244 | 250 | ||
251 | image->swap_page = kimage_alloc_control_pages(image, 0); | ||
252 | if (!image->swap_page) { | ||
253 | printk(KERN_ERR "Could not allocate swap buffer\n"); | ||
254 | goto out; | ||
255 | } | ||
256 | |||
245 | result = 0; | 257 | result = 0; |
246 | out: | 258 | out: |
247 | if (result == 0) | 259 | if (result == 0) |
@@ -305,7 +317,7 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry, | |||
305 | */ | 317 | */ |
306 | result = -ENOMEM; | 318 | result = -ENOMEM; |
307 | image->control_code_page = kimage_alloc_control_pages(image, | 319 | image->control_code_page = kimage_alloc_control_pages(image, |
308 | get_order(KEXEC_CONTROL_CODE_SIZE)); | 320 | get_order(KEXEC_CONTROL_PAGE_SIZE)); |
309 | if (!image->control_code_page) { | 321 | if (!image->control_code_page) { |
310 | printk(KERN_ERR "Could not allocate control_code_buffer\n"); | 322 | printk(KERN_ERR "Could not allocate control_code_buffer\n"); |
311 | goto out; | 323 | goto out; |
@@ -589,14 +601,12 @@ static void kimage_free_extra_pages(struct kimage *image) | |||
589 | kimage_free_page_list(&image->unuseable_pages); | 601 | kimage_free_page_list(&image->unuseable_pages); |
590 | 602 | ||
591 | } | 603 | } |
592 | static int kimage_terminate(struct kimage *image) | 604 | static void kimage_terminate(struct kimage *image) |
593 | { | 605 | { |
594 | if (*image->entry != 0) | 606 | if (*image->entry != 0) |
595 | image->entry++; | 607 | image->entry++; |
596 | 608 | ||
597 | *image->entry = IND_DONE; | 609 | *image->entry = IND_DONE; |
598 | |||
599 | return 0; | ||
600 | } | 610 | } |
601 | 611 | ||
602 | #define for_each_kimage_entry(image, ptr, entry) \ | 612 | #define for_each_kimage_entry(image, ptr, entry) \ |
@@ -743,8 +753,14 @@ static struct page *kimage_alloc_page(struct kimage *image, | |||
743 | *old = addr | (*old & ~PAGE_MASK); | 753 | *old = addr | (*old & ~PAGE_MASK); |
744 | 754 | ||
745 | /* The old page I have found cannot be a | 755 | /* The old page I have found cannot be a |
746 | * destination page, so return it. | 756 | * destination page, so return it if it's |
757 | * gfp_flags honor the ones passed in. | ||
747 | */ | 758 | */ |
759 | if (!(gfp_mask & __GFP_HIGHMEM) && | ||
760 | PageHighMem(old_page)) { | ||
761 | kimage_free_pages(old_page); | ||
762 | continue; | ||
763 | } | ||
748 | addr = old_addr; | 764 | addr = old_addr; |
749 | page = old_page; | 765 | page = old_page; |
750 | break; | 766 | break; |
@@ -914,19 +930,14 @@ static int kimage_load_segment(struct kimage *image, | |||
914 | */ | 930 | */ |
915 | struct kimage *kexec_image; | 931 | struct kimage *kexec_image; |
916 | struct kimage *kexec_crash_image; | 932 | struct kimage *kexec_crash_image; |
917 | /* | 933 | |
918 | * A home grown binary mutex. | 934 | static DEFINE_MUTEX(kexec_mutex); |
919 | * Nothing can wait so this mutex is safe to use | ||
920 | * in interrupt context :) | ||
921 | */ | ||
922 | static int kexec_lock; | ||
923 | 935 | ||
924 | asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, | 936 | asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, |
925 | struct kexec_segment __user *segments, | 937 | struct kexec_segment __user *segments, |
926 | unsigned long flags) | 938 | unsigned long flags) |
927 | { | 939 | { |
928 | struct kimage **dest_image, *image; | 940 | struct kimage **dest_image, *image; |
929 | int locked; | ||
930 | int result; | 941 | int result; |
931 | 942 | ||
932 | /* We only trust the superuser with rebooting the system. */ | 943 | /* We only trust the superuser with rebooting the system. */ |
@@ -962,8 +973,7 @@ asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, | |||
962 | * | 973 | * |
963 | * KISS: always take the mutex. | 974 | * KISS: always take the mutex. |
964 | */ | 975 | */ |
965 | locked = xchg(&kexec_lock, 1); | 976 | if (!mutex_trylock(&kexec_mutex)) |
966 | if (locked) | ||
967 | return -EBUSY; | 977 | return -EBUSY; |
968 | 978 | ||
969 | dest_image = &kexec_image; | 979 | dest_image = &kexec_image; |
@@ -988,6 +998,8 @@ asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, | |||
988 | if (result) | 998 | if (result) |
989 | goto out; | 999 | goto out; |
990 | 1000 | ||
1001 | if (flags & KEXEC_PRESERVE_CONTEXT) | ||
1002 | image->preserve_context = 1; | ||
991 | result = machine_kexec_prepare(image); | 1003 | result = machine_kexec_prepare(image); |
992 | if (result) | 1004 | if (result) |
993 | goto out; | 1005 | goto out; |
@@ -997,16 +1009,13 @@ asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, | |||
997 | if (result) | 1009 | if (result) |
998 | goto out; | 1010 | goto out; |
999 | } | 1011 | } |
1000 | result = kimage_terminate(image); | 1012 | kimage_terminate(image); |
1001 | if (result) | ||
1002 | goto out; | ||
1003 | } | 1013 | } |
1004 | /* Install the new kernel, and Uninstall the old */ | 1014 | /* Install the new kernel, and Uninstall the old */ |
1005 | image = xchg(dest_image, image); | 1015 | image = xchg(dest_image, image); |
1006 | 1016 | ||
1007 | out: | 1017 | out: |
1008 | locked = xchg(&kexec_lock, 0); /* Release the mutex */ | 1018 | mutex_unlock(&kexec_mutex); |
1009 | BUG_ON(!locked); | ||
1010 | kimage_free(image); | 1019 | kimage_free(image); |
1011 | 1020 | ||
1012 | return result; | 1021 | return result; |
@@ -1053,10 +1062,7 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry, | |||
1053 | 1062 | ||
1054 | void crash_kexec(struct pt_regs *regs) | 1063 | void crash_kexec(struct pt_regs *regs) |
1055 | { | 1064 | { |
1056 | int locked; | 1065 | /* Take the kexec_mutex here to prevent sys_kexec_load |
1057 | |||
1058 | |||
1059 | /* Take the kexec_lock here to prevent sys_kexec_load | ||
1060 | * running on one cpu from replacing the crash kernel | 1066 | * running on one cpu from replacing the crash kernel |
1061 | * we are using after a panic on a different cpu. | 1067 | * we are using after a panic on a different cpu. |
1062 | * | 1068 | * |
@@ -1064,8 +1070,7 @@ void crash_kexec(struct pt_regs *regs) | |||
1064 | * of memory the xchg(&kexec_crash_image) would be | 1070 | * of memory the xchg(&kexec_crash_image) would be |
1065 | * sufficient. But since I reuse the memory... | 1071 | * sufficient. But since I reuse the memory... |
1066 | */ | 1072 | */ |
1067 | locked = xchg(&kexec_lock, 1); | 1073 | if (mutex_trylock(&kexec_mutex)) { |
1068 | if (!locked) { | ||
1069 | if (kexec_crash_image) { | 1074 | if (kexec_crash_image) { |
1070 | struct pt_regs fixed_regs; | 1075 | struct pt_regs fixed_regs; |
1071 | crash_setup_regs(&fixed_regs, regs); | 1076 | crash_setup_regs(&fixed_regs, regs); |
@@ -1073,8 +1078,7 @@ void crash_kexec(struct pt_regs *regs) | |||
1073 | machine_crash_shutdown(&fixed_regs); | 1078 | machine_crash_shutdown(&fixed_regs); |
1074 | machine_kexec(kexec_crash_image); | 1079 | machine_kexec(kexec_crash_image); |
1075 | } | 1080 | } |
1076 | locked = xchg(&kexec_lock, 0); | 1081 | mutex_unlock(&kexec_mutex); |
1077 | BUG_ON(!locked); | ||
1078 | } | 1082 | } |
1079 | } | 1083 | } |
1080 | 1084 | ||
@@ -1415,3 +1419,79 @@ static int __init crash_save_vmcoreinfo_init(void) | |||
1415 | } | 1419 | } |
1416 | 1420 | ||
1417 | module_init(crash_save_vmcoreinfo_init) | 1421 | module_init(crash_save_vmcoreinfo_init) |
1422 | |||
1423 | /* | ||
1424 | * Move into place and start executing a preloaded standalone | ||
1425 | * executable. If nothing was preloaded return an error. | ||
1426 | */ | ||
1427 | int kernel_kexec(void) | ||
1428 | { | ||
1429 | int error = 0; | ||
1430 | |||
1431 | if (!mutex_trylock(&kexec_mutex)) | ||
1432 | return -EBUSY; | ||
1433 | if (!kexec_image) { | ||
1434 | error = -EINVAL; | ||
1435 | goto Unlock; | ||
1436 | } | ||
1437 | |||
1438 | #ifdef CONFIG_KEXEC_JUMP | ||
1439 | if (kexec_image->preserve_context) { | ||
1440 | mutex_lock(&pm_mutex); | ||
1441 | pm_prepare_console(); | ||
1442 | error = freeze_processes(); | ||
1443 | if (error) { | ||
1444 | error = -EBUSY; | ||
1445 | goto Restore_console; | ||
1446 | } | ||
1447 | suspend_console(); | ||
1448 | error = device_suspend(PMSG_FREEZE); | ||
1449 | if (error) | ||
1450 | goto Resume_console; | ||
1451 | error = disable_nonboot_cpus(); | ||
1452 | if (error) | ||
1453 | goto Resume_devices; | ||
1454 | device_pm_lock(); | ||
1455 | local_irq_disable(); | ||
1456 | /* At this point, device_suspend() has been called, | ||
1457 | * but *not* device_power_down(). We *must* | ||
1458 | * device_power_down() now. Otherwise, drivers for | ||
1459 | * some devices (e.g. interrupt controllers) become | ||
1460 | * desynchronized with the actual state of the | ||
1461 | * hardware at resume time, and evil weirdness ensues. | ||
1462 | */ | ||
1463 | error = device_power_down(PMSG_FREEZE); | ||
1464 | if (error) | ||
1465 | goto Enable_irqs; | ||
1466 | } else | ||
1467 | #endif | ||
1468 | { | ||
1469 | kernel_restart_prepare(NULL); | ||
1470 | printk(KERN_EMERG "Starting new kernel\n"); | ||
1471 | machine_shutdown(); | ||
1472 | } | ||
1473 | |||
1474 | machine_kexec(kexec_image); | ||
1475 | |||
1476 | #ifdef CONFIG_KEXEC_JUMP | ||
1477 | if (kexec_image->preserve_context) { | ||
1478 | device_power_up(PMSG_RESTORE); | ||
1479 | Enable_irqs: | ||
1480 | local_irq_enable(); | ||
1481 | device_pm_unlock(); | ||
1482 | enable_nonboot_cpus(); | ||
1483 | Resume_devices: | ||
1484 | device_resume(PMSG_RESTORE); | ||
1485 | Resume_console: | ||
1486 | resume_console(); | ||
1487 | thaw_processes(); | ||
1488 | Restore_console: | ||
1489 | pm_restore_console(); | ||
1490 | mutex_unlock(&pm_mutex); | ||
1491 | } | ||
1492 | #endif | ||
1493 | |||
1494 | Unlock: | ||
1495 | mutex_unlock(&kexec_mutex); | ||
1496 | return error; | ||
1497 | } | ||
diff --git a/kernel/kgdb.c b/kernel/kgdb.c index 3ec23c3ec97f..e4dcfb2272a4 100644 --- a/kernel/kgdb.c +++ b/kernel/kgdb.c | |||
@@ -56,12 +56,14 @@ | |||
56 | 56 | ||
57 | static int kgdb_break_asap; | 57 | static int kgdb_break_asap; |
58 | 58 | ||
59 | #define KGDB_MAX_THREAD_QUERY 17 | ||
59 | struct kgdb_state { | 60 | struct kgdb_state { |
60 | int ex_vector; | 61 | int ex_vector; |
61 | int signo; | 62 | int signo; |
62 | int err_code; | 63 | int err_code; |
63 | int cpu; | 64 | int cpu; |
64 | int pass_exception; | 65 | int pass_exception; |
66 | unsigned long thr_query; | ||
65 | unsigned long threadid; | 67 | unsigned long threadid; |
66 | long kgdb_usethreadid; | 68 | long kgdb_usethreadid; |
67 | struct pt_regs *linux_regs; | 69 | struct pt_regs *linux_regs; |
@@ -166,13 +168,6 @@ early_param("nokgdbroundup", opt_nokgdbroundup); | |||
166 | * Weak aliases for breakpoint management, | 168 | * Weak aliases for breakpoint management, |
167 | * can be overriden by architectures when needed: | 169 | * can be overriden by architectures when needed: |
168 | */ | 170 | */ |
169 | int __weak kgdb_validate_break_address(unsigned long addr) | ||
170 | { | ||
171 | char tmp_variable[BREAK_INSTR_SIZE]; | ||
172 | |||
173 | return probe_kernel_read(tmp_variable, (char *)addr, BREAK_INSTR_SIZE); | ||
174 | } | ||
175 | |||
176 | int __weak kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr) | 171 | int __weak kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr) |
177 | { | 172 | { |
178 | int err; | 173 | int err; |
@@ -191,6 +186,25 @@ int __weak kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle) | |||
191 | (char *)bundle, BREAK_INSTR_SIZE); | 186 | (char *)bundle, BREAK_INSTR_SIZE); |
192 | } | 187 | } |
193 | 188 | ||
189 | int __weak kgdb_validate_break_address(unsigned long addr) | ||
190 | { | ||
191 | char tmp_variable[BREAK_INSTR_SIZE]; | ||
192 | int err; | ||
193 | /* Validate setting the breakpoint and then removing it. In the | ||
194 | * remove fails, the kernel needs to emit a bad message because we | ||
195 | * are deep trouble not being able to put things back the way we | ||
196 | * found them. | ||
197 | */ | ||
198 | err = kgdb_arch_set_breakpoint(addr, tmp_variable); | ||
199 | if (err) | ||
200 | return err; | ||
201 | err = kgdb_arch_remove_breakpoint(addr, tmp_variable); | ||
202 | if (err) | ||
203 | printk(KERN_ERR "KGDB: Critical breakpoint error, kernel " | ||
204 | "memory destroyed at: %lx", addr); | ||
205 | return err; | ||
206 | } | ||
207 | |||
194 | unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs) | 208 | unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs) |
195 | { | 209 | { |
196 | return instruction_pointer(regs); | 210 | return instruction_pointer(regs); |
@@ -433,9 +447,14 @@ int kgdb_hex2long(char **ptr, unsigned long *long_val) | |||
433 | { | 447 | { |
434 | int hex_val; | 448 | int hex_val; |
435 | int num = 0; | 449 | int num = 0; |
450 | int negate = 0; | ||
436 | 451 | ||
437 | *long_val = 0; | 452 | *long_val = 0; |
438 | 453 | ||
454 | if (**ptr == '-') { | ||
455 | negate = 1; | ||
456 | (*ptr)++; | ||
457 | } | ||
439 | while (**ptr) { | 458 | while (**ptr) { |
440 | hex_val = hex(**ptr); | 459 | hex_val = hex(**ptr); |
441 | if (hex_val < 0) | 460 | if (hex_val < 0) |
@@ -446,6 +465,9 @@ int kgdb_hex2long(char **ptr, unsigned long *long_val) | |||
446 | (*ptr)++; | 465 | (*ptr)++; |
447 | } | 466 | } |
448 | 467 | ||
468 | if (negate) | ||
469 | *long_val = -*long_val; | ||
470 | |||
449 | return num; | 471 | return num; |
450 | } | 472 | } |
451 | 473 | ||
@@ -466,7 +488,7 @@ static int write_mem_msg(int binary) | |||
466 | if (err) | 488 | if (err) |
467 | return err; | 489 | return err; |
468 | if (CACHE_FLUSH_IS_SAFE) | 490 | if (CACHE_FLUSH_IS_SAFE) |
469 | flush_icache_range(addr, addr + length + 1); | 491 | flush_icache_range(addr, addr + length); |
470 | return 0; | 492 | return 0; |
471 | } | 493 | } |
472 | 494 | ||
@@ -515,10 +537,16 @@ static void int_to_threadref(unsigned char *id, int value) | |||
515 | static struct task_struct *getthread(struct pt_regs *regs, int tid) | 537 | static struct task_struct *getthread(struct pt_regs *regs, int tid) |
516 | { | 538 | { |
517 | /* | 539 | /* |
518 | * Non-positive TIDs are remapped idle tasks: | 540 | * Non-positive TIDs are remapped to the cpu shadow information |
519 | */ | 541 | */ |
520 | if (tid <= 0) | 542 | if (tid == 0 || tid == -1) |
521 | return idle_task(-tid); | 543 | tid = -atomic_read(&kgdb_active) - 2; |
544 | if (tid < 0) { | ||
545 | if (kgdb_info[-tid - 2].task) | ||
546 | return kgdb_info[-tid - 2].task; | ||
547 | else | ||
548 | return idle_task(-tid - 2); | ||
549 | } | ||
522 | 550 | ||
523 | /* | 551 | /* |
524 | * find_task_by_pid_ns() does not take the tasklist lock anymore | 552 | * find_task_by_pid_ns() does not take the tasklist lock anymore |
@@ -562,6 +590,7 @@ static void kgdb_wait(struct pt_regs *regs) | |||
562 | 590 | ||
563 | /* Signal the primary CPU that we are done: */ | 591 | /* Signal the primary CPU that we are done: */ |
564 | atomic_set(&cpu_in_kgdb[cpu], 0); | 592 | atomic_set(&cpu_in_kgdb[cpu], 0); |
593 | touch_softlockup_watchdog(); | ||
565 | clocksource_touch_watchdog(); | 594 | clocksource_touch_watchdog(); |
566 | local_irq_restore(flags); | 595 | local_irq_restore(flags); |
567 | } | 596 | } |
@@ -725,14 +754,15 @@ setundefined: | |||
725 | } | 754 | } |
726 | 755 | ||
727 | /* | 756 | /* |
728 | * Remap normal tasks to their real PID, idle tasks to -1 ... -NR_CPUs: | 757 | * Remap normal tasks to their real PID, |
758 | * CPU shadow threads are mapped to -CPU - 2 | ||
729 | */ | 759 | */ |
730 | static inline int shadow_pid(int realpid) | 760 | static inline int shadow_pid(int realpid) |
731 | { | 761 | { |
732 | if (realpid) | 762 | if (realpid) |
733 | return realpid; | 763 | return realpid; |
734 | 764 | ||
735 | return -1-raw_smp_processor_id(); | 765 | return -raw_smp_processor_id() - 2; |
736 | } | 766 | } |
737 | 767 | ||
738 | static char gdbmsgbuf[BUFMAX + 1]; | 768 | static char gdbmsgbuf[BUFMAX + 1]; |
@@ -826,7 +856,7 @@ static void gdb_cmd_getregs(struct kgdb_state *ks) | |||
826 | local_debuggerinfo = kgdb_info[ks->cpu].debuggerinfo; | 856 | local_debuggerinfo = kgdb_info[ks->cpu].debuggerinfo; |
827 | } else { | 857 | } else { |
828 | local_debuggerinfo = NULL; | 858 | local_debuggerinfo = NULL; |
829 | for (i = 0; i < NR_CPUS; i++) { | 859 | for_each_online_cpu(i) { |
830 | /* | 860 | /* |
831 | * Try to find the task on some other | 861 | * Try to find the task on some other |
832 | * or possibly this node if we do not | 862 | * or possibly this node if we do not |
@@ -960,10 +990,13 @@ static int gdb_cmd_reboot(struct kgdb_state *ks) | |||
960 | /* Handle the 'q' query packets */ | 990 | /* Handle the 'q' query packets */ |
961 | static void gdb_cmd_query(struct kgdb_state *ks) | 991 | static void gdb_cmd_query(struct kgdb_state *ks) |
962 | { | 992 | { |
963 | struct task_struct *thread; | 993 | struct task_struct *g; |
994 | struct task_struct *p; | ||
964 | unsigned char thref[8]; | 995 | unsigned char thref[8]; |
965 | char *ptr; | 996 | char *ptr; |
966 | int i; | 997 | int i; |
998 | int cpu; | ||
999 | int finished = 0; | ||
967 | 1000 | ||
968 | switch (remcom_in_buffer[1]) { | 1001 | switch (remcom_in_buffer[1]) { |
969 | case 's': | 1002 | case 's': |
@@ -973,22 +1006,34 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
973 | break; | 1006 | break; |
974 | } | 1007 | } |
975 | 1008 | ||
976 | if (remcom_in_buffer[1] == 'f') | 1009 | i = 0; |
977 | ks->threadid = 1; | ||
978 | |||
979 | remcom_out_buffer[0] = 'm'; | 1010 | remcom_out_buffer[0] = 'm'; |
980 | ptr = remcom_out_buffer + 1; | 1011 | ptr = remcom_out_buffer + 1; |
981 | 1012 | if (remcom_in_buffer[1] == 'f') { | |
982 | for (i = 0; i < 17; ks->threadid++) { | 1013 | /* Each cpu is a shadow thread */ |
983 | thread = getthread(ks->linux_regs, ks->threadid); | 1014 | for_each_online_cpu(cpu) { |
984 | if (thread) { | 1015 | ks->thr_query = 0; |
985 | int_to_threadref(thref, ks->threadid); | 1016 | int_to_threadref(thref, -cpu - 2); |
986 | pack_threadid(ptr, thref); | 1017 | pack_threadid(ptr, thref); |
987 | ptr += BUF_THREAD_ID_SIZE; | 1018 | ptr += BUF_THREAD_ID_SIZE; |
988 | *(ptr++) = ','; | 1019 | *(ptr++) = ','; |
989 | i++; | 1020 | i++; |
990 | } | 1021 | } |
991 | } | 1022 | } |
1023 | |||
1024 | do_each_thread(g, p) { | ||
1025 | if (i >= ks->thr_query && !finished) { | ||
1026 | int_to_threadref(thref, p->pid); | ||
1027 | pack_threadid(ptr, thref); | ||
1028 | ptr += BUF_THREAD_ID_SIZE; | ||
1029 | *(ptr++) = ','; | ||
1030 | ks->thr_query++; | ||
1031 | if (ks->thr_query % KGDB_MAX_THREAD_QUERY == 0) | ||
1032 | finished = 1; | ||
1033 | } | ||
1034 | i++; | ||
1035 | } while_each_thread(g, p); | ||
1036 | |||
992 | *(--ptr) = '\0'; | 1037 | *(--ptr) = '\0'; |
993 | break; | 1038 | break; |
994 | 1039 | ||
@@ -1011,15 +1056,15 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
1011 | error_packet(remcom_out_buffer, -EINVAL); | 1056 | error_packet(remcom_out_buffer, -EINVAL); |
1012 | break; | 1057 | break; |
1013 | } | 1058 | } |
1014 | if (ks->threadid > 0) { | 1059 | if ((int)ks->threadid > 0) { |
1015 | kgdb_mem2hex(getthread(ks->linux_regs, | 1060 | kgdb_mem2hex(getthread(ks->linux_regs, |
1016 | ks->threadid)->comm, | 1061 | ks->threadid)->comm, |
1017 | remcom_out_buffer, 16); | 1062 | remcom_out_buffer, 16); |
1018 | } else { | 1063 | } else { |
1019 | static char tmpstr[23 + BUF_THREAD_ID_SIZE]; | 1064 | static char tmpstr[23 + BUF_THREAD_ID_SIZE]; |
1020 | 1065 | ||
1021 | sprintf(tmpstr, "Shadow task %d for pid 0", | 1066 | sprintf(tmpstr, "shadowCPU%d", |
1022 | (int)(-ks->threadid-1)); | 1067 | (int)(-ks->threadid - 2)); |
1023 | kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr)); | 1068 | kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr)); |
1024 | } | 1069 | } |
1025 | break; | 1070 | break; |
@@ -1388,6 +1433,7 @@ acquirelock: | |||
1388 | atomic_read(&kgdb_cpu_doing_single_step) != cpu) { | 1433 | atomic_read(&kgdb_cpu_doing_single_step) != cpu) { |
1389 | 1434 | ||
1390 | atomic_set(&kgdb_active, -1); | 1435 | atomic_set(&kgdb_active, -1); |
1436 | touch_softlockup_watchdog(); | ||
1391 | clocksource_touch_watchdog(); | 1437 | clocksource_touch_watchdog(); |
1392 | local_irq_restore(flags); | 1438 | local_irq_restore(flags); |
1393 | 1439 | ||
@@ -1418,7 +1464,7 @@ acquirelock: | |||
1418 | * Get the passive CPU lock which will hold all the non-primary | 1464 | * Get the passive CPU lock which will hold all the non-primary |
1419 | * CPU in a spin state while the debugger is active | 1465 | * CPU in a spin state while the debugger is active |
1420 | */ | 1466 | */ |
1421 | if (!kgdb_single_step || !kgdb_contthread) { | 1467 | if (!kgdb_single_step) { |
1422 | for (i = 0; i < NR_CPUS; i++) | 1468 | for (i = 0; i < NR_CPUS; i++) |
1423 | atomic_set(&passive_cpu_wait[i], 1); | 1469 | atomic_set(&passive_cpu_wait[i], 1); |
1424 | } | 1470 | } |
@@ -1431,7 +1477,7 @@ acquirelock: | |||
1431 | 1477 | ||
1432 | #ifdef CONFIG_SMP | 1478 | #ifdef CONFIG_SMP |
1433 | /* Signal the other CPUs to enter kgdb_wait() */ | 1479 | /* Signal the other CPUs to enter kgdb_wait() */ |
1434 | if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup) | 1480 | if ((!kgdb_single_step) && kgdb_do_roundup) |
1435 | kgdb_roundup_cpus(flags); | 1481 | kgdb_roundup_cpus(flags); |
1436 | #endif | 1482 | #endif |
1437 | 1483 | ||
@@ -1450,7 +1496,7 @@ acquirelock: | |||
1450 | kgdb_post_primary_code(ks->linux_regs, ks->ex_vector, ks->err_code); | 1496 | kgdb_post_primary_code(ks->linux_regs, ks->ex_vector, ks->err_code); |
1451 | kgdb_deactivate_sw_breakpoints(); | 1497 | kgdb_deactivate_sw_breakpoints(); |
1452 | kgdb_single_step = 0; | 1498 | kgdb_single_step = 0; |
1453 | kgdb_contthread = NULL; | 1499 | kgdb_contthread = current; |
1454 | exception_level = 0; | 1500 | exception_level = 0; |
1455 | 1501 | ||
1456 | /* Talk to debugger with gdbserial protocol */ | 1502 | /* Talk to debugger with gdbserial protocol */ |
@@ -1464,7 +1510,7 @@ acquirelock: | |||
1464 | kgdb_info[ks->cpu].task = NULL; | 1510 | kgdb_info[ks->cpu].task = NULL; |
1465 | atomic_set(&cpu_in_kgdb[ks->cpu], 0); | 1511 | atomic_set(&cpu_in_kgdb[ks->cpu], 0); |
1466 | 1512 | ||
1467 | if (!kgdb_single_step || !kgdb_contthread) { | 1513 | if (!kgdb_single_step) { |
1468 | for (i = NR_CPUS-1; i >= 0; i--) | 1514 | for (i = NR_CPUS-1; i >= 0; i--) |
1469 | atomic_set(&passive_cpu_wait[i], 0); | 1515 | atomic_set(&passive_cpu_wait[i], 0); |
1470 | /* | 1516 | /* |
@@ -1480,6 +1526,7 @@ acquirelock: | |||
1480 | kgdb_restore: | 1526 | kgdb_restore: |
1481 | /* Free kgdb_active */ | 1527 | /* Free kgdb_active */ |
1482 | atomic_set(&kgdb_active, -1); | 1528 | atomic_set(&kgdb_active, -1); |
1529 | touch_softlockup_watchdog(); | ||
1483 | clocksource_touch_watchdog(); | 1530 | clocksource_touch_watchdog(); |
1484 | local_irq_restore(flags); | 1531 | local_irq_restore(flags); |
1485 | 1532 | ||
diff --git a/kernel/kthread.c b/kernel/kthread.c index 6111c27491b1..96cff2f8710b 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c | |||
@@ -176,7 +176,7 @@ void kthread_bind(struct task_struct *k, unsigned int cpu) | |||
176 | return; | 176 | return; |
177 | } | 177 | } |
178 | /* Must have done schedule() in kthread() before we set_task_cpu */ | 178 | /* Must have done schedule() in kthread() before we set_task_cpu */ |
179 | wait_task_inactive(k); | 179 | wait_task_inactive(k, 0); |
180 | set_task_cpu(k, cpu); | 180 | set_task_cpu(k, cpu); |
181 | k->cpus_allowed = cpumask_of_cpu(cpu); | 181 | k->cpus_allowed = cpumask_of_cpu(cpu); |
182 | k->rt.nr_cpus_allowed = 1; | 182 | k->rt.nr_cpus_allowed = 1; |
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index d38a64362973..dbda475b13bd 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -124,6 +124,15 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES]; | |||
124 | unsigned long nr_lock_classes; | 124 | unsigned long nr_lock_classes; |
125 | static struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; | 125 | static struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; |
126 | 126 | ||
127 | static inline struct lock_class *hlock_class(struct held_lock *hlock) | ||
128 | { | ||
129 | if (!hlock->class_idx) { | ||
130 | DEBUG_LOCKS_WARN_ON(1); | ||
131 | return NULL; | ||
132 | } | ||
133 | return lock_classes + hlock->class_idx - 1; | ||
134 | } | ||
135 | |||
127 | #ifdef CONFIG_LOCK_STAT | 136 | #ifdef CONFIG_LOCK_STAT |
128 | static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], lock_stats); | 137 | static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], lock_stats); |
129 | 138 | ||
@@ -222,7 +231,7 @@ static void lock_release_holdtime(struct held_lock *hlock) | |||
222 | 231 | ||
223 | holdtime = sched_clock() - hlock->holdtime_stamp; | 232 | holdtime = sched_clock() - hlock->holdtime_stamp; |
224 | 233 | ||
225 | stats = get_lock_stats(hlock->class); | 234 | stats = get_lock_stats(hlock_class(hlock)); |
226 | if (hlock->read) | 235 | if (hlock->read) |
227 | lock_time_inc(&stats->read_holdtime, holdtime); | 236 | lock_time_inc(&stats->read_holdtime, holdtime); |
228 | else | 237 | else |
@@ -372,6 +381,19 @@ unsigned int nr_process_chains; | |||
372 | unsigned int max_lockdep_depth; | 381 | unsigned int max_lockdep_depth; |
373 | unsigned int max_recursion_depth; | 382 | unsigned int max_recursion_depth; |
374 | 383 | ||
384 | static unsigned int lockdep_dependency_gen_id; | ||
385 | |||
386 | static bool lockdep_dependency_visit(struct lock_class *source, | ||
387 | unsigned int depth) | ||
388 | { | ||
389 | if (!depth) | ||
390 | lockdep_dependency_gen_id++; | ||
391 | if (source->dep_gen_id == lockdep_dependency_gen_id) | ||
392 | return true; | ||
393 | source->dep_gen_id = lockdep_dependency_gen_id; | ||
394 | return false; | ||
395 | } | ||
396 | |||
375 | #ifdef CONFIG_DEBUG_LOCKDEP | 397 | #ifdef CONFIG_DEBUG_LOCKDEP |
376 | /* | 398 | /* |
377 | * We cannot printk in early bootup code. Not even early_printk() | 399 | * We cannot printk in early bootup code. Not even early_printk() |
@@ -505,7 +527,7 @@ static void print_lockdep_cache(struct lockdep_map *lock) | |||
505 | 527 | ||
506 | static void print_lock(struct held_lock *hlock) | 528 | static void print_lock(struct held_lock *hlock) |
507 | { | 529 | { |
508 | print_lock_name(hlock->class); | 530 | print_lock_name(hlock_class(hlock)); |
509 | printk(", at: "); | 531 | printk(", at: "); |
510 | print_ip_sym(hlock->acquire_ip); | 532 | print_ip_sym(hlock->acquire_ip); |
511 | } | 533 | } |
@@ -558,6 +580,9 @@ static void print_lock_dependencies(struct lock_class *class, int depth) | |||
558 | { | 580 | { |
559 | struct lock_list *entry; | 581 | struct lock_list *entry; |
560 | 582 | ||
583 | if (lockdep_dependency_visit(class, depth)) | ||
584 | return; | ||
585 | |||
561 | if (DEBUG_LOCKS_WARN_ON(depth >= 20)) | 586 | if (DEBUG_LOCKS_WARN_ON(depth >= 20)) |
562 | return; | 587 | return; |
563 | 588 | ||
@@ -850,11 +875,11 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
850 | if (!entry) | 875 | if (!entry) |
851 | return 0; | 876 | return 0; |
852 | 877 | ||
853 | entry->class = this; | ||
854 | entry->distance = distance; | ||
855 | if (!save_trace(&entry->trace)) | 878 | if (!save_trace(&entry->trace)) |
856 | return 0; | 879 | return 0; |
857 | 880 | ||
881 | entry->class = this; | ||
882 | entry->distance = distance; | ||
858 | /* | 883 | /* |
859 | * Since we never remove from the dependency list, the list can | 884 | * Since we never remove from the dependency list, the list can |
860 | * be walked lockless by other CPUs, it's only allocation | 885 | * be walked lockless by other CPUs, it's only allocation |
@@ -932,7 +957,7 @@ static noinline int print_circular_bug_tail(void) | |||
932 | if (debug_locks_silent) | 957 | if (debug_locks_silent) |
933 | return 0; | 958 | return 0; |
934 | 959 | ||
935 | this.class = check_source->class; | 960 | this.class = hlock_class(check_source); |
936 | if (!save_trace(&this.trace)) | 961 | if (!save_trace(&this.trace)) |
937 | return 0; | 962 | return 0; |
938 | 963 | ||
@@ -959,6 +984,67 @@ static int noinline print_infinite_recursion_bug(void) | |||
959 | return 0; | 984 | return 0; |
960 | } | 985 | } |
961 | 986 | ||
987 | unsigned long __lockdep_count_forward_deps(struct lock_class *class, | ||
988 | unsigned int depth) | ||
989 | { | ||
990 | struct lock_list *entry; | ||
991 | unsigned long ret = 1; | ||
992 | |||
993 | if (lockdep_dependency_visit(class, depth)) | ||
994 | return 0; | ||
995 | |||
996 | /* | ||
997 | * Recurse this class's dependency list: | ||
998 | */ | ||
999 | list_for_each_entry(entry, &class->locks_after, entry) | ||
1000 | ret += __lockdep_count_forward_deps(entry->class, depth + 1); | ||
1001 | |||
1002 | return ret; | ||
1003 | } | ||
1004 | |||
1005 | unsigned long lockdep_count_forward_deps(struct lock_class *class) | ||
1006 | { | ||
1007 | unsigned long ret, flags; | ||
1008 | |||
1009 | local_irq_save(flags); | ||
1010 | __raw_spin_lock(&lockdep_lock); | ||
1011 | ret = __lockdep_count_forward_deps(class, 0); | ||
1012 | __raw_spin_unlock(&lockdep_lock); | ||
1013 | local_irq_restore(flags); | ||
1014 | |||
1015 | return ret; | ||
1016 | } | ||
1017 | |||
1018 | unsigned long __lockdep_count_backward_deps(struct lock_class *class, | ||
1019 | unsigned int depth) | ||
1020 | { | ||
1021 | struct lock_list *entry; | ||
1022 | unsigned long ret = 1; | ||
1023 | |||
1024 | if (lockdep_dependency_visit(class, depth)) | ||
1025 | return 0; | ||
1026 | /* | ||
1027 | * Recurse this class's dependency list: | ||
1028 | */ | ||
1029 | list_for_each_entry(entry, &class->locks_before, entry) | ||
1030 | ret += __lockdep_count_backward_deps(entry->class, depth + 1); | ||
1031 | |||
1032 | return ret; | ||
1033 | } | ||
1034 | |||
1035 | unsigned long lockdep_count_backward_deps(struct lock_class *class) | ||
1036 | { | ||
1037 | unsigned long ret, flags; | ||
1038 | |||
1039 | local_irq_save(flags); | ||
1040 | __raw_spin_lock(&lockdep_lock); | ||
1041 | ret = __lockdep_count_backward_deps(class, 0); | ||
1042 | __raw_spin_unlock(&lockdep_lock); | ||
1043 | local_irq_restore(flags); | ||
1044 | |||
1045 | return ret; | ||
1046 | } | ||
1047 | |||
962 | /* | 1048 | /* |
963 | * Prove that the dependency graph starting at <entry> can not | 1049 | * Prove that the dependency graph starting at <entry> can not |
964 | * lead to <target>. Print an error and return 0 if it does. | 1050 | * lead to <target>. Print an error and return 0 if it does. |
@@ -968,6 +1054,9 @@ check_noncircular(struct lock_class *source, unsigned int depth) | |||
968 | { | 1054 | { |
969 | struct lock_list *entry; | 1055 | struct lock_list *entry; |
970 | 1056 | ||
1057 | if (lockdep_dependency_visit(source, depth)) | ||
1058 | return 1; | ||
1059 | |||
971 | debug_atomic_inc(&nr_cyclic_check_recursions); | 1060 | debug_atomic_inc(&nr_cyclic_check_recursions); |
972 | if (depth > max_recursion_depth) | 1061 | if (depth > max_recursion_depth) |
973 | max_recursion_depth = depth; | 1062 | max_recursion_depth = depth; |
@@ -977,7 +1066,7 @@ check_noncircular(struct lock_class *source, unsigned int depth) | |||
977 | * Check this lock's dependency list: | 1066 | * Check this lock's dependency list: |
978 | */ | 1067 | */ |
979 | list_for_each_entry(entry, &source->locks_after, entry) { | 1068 | list_for_each_entry(entry, &source->locks_after, entry) { |
980 | if (entry->class == check_target->class) | 1069 | if (entry->class == hlock_class(check_target)) |
981 | return print_circular_bug_header(entry, depth+1); | 1070 | return print_circular_bug_header(entry, depth+1); |
982 | debug_atomic_inc(&nr_cyclic_checks); | 1071 | debug_atomic_inc(&nr_cyclic_checks); |
983 | if (!check_noncircular(entry->class, depth+1)) | 1072 | if (!check_noncircular(entry->class, depth+1)) |
@@ -1011,6 +1100,9 @@ find_usage_forwards(struct lock_class *source, unsigned int depth) | |||
1011 | struct lock_list *entry; | 1100 | struct lock_list *entry; |
1012 | int ret; | 1101 | int ret; |
1013 | 1102 | ||
1103 | if (lockdep_dependency_visit(source, depth)) | ||
1104 | return 1; | ||
1105 | |||
1014 | if (depth > max_recursion_depth) | 1106 | if (depth > max_recursion_depth) |
1015 | max_recursion_depth = depth; | 1107 | max_recursion_depth = depth; |
1016 | if (depth >= RECURSION_LIMIT) | 1108 | if (depth >= RECURSION_LIMIT) |
@@ -1050,6 +1142,9 @@ find_usage_backwards(struct lock_class *source, unsigned int depth) | |||
1050 | struct lock_list *entry; | 1142 | struct lock_list *entry; |
1051 | int ret; | 1143 | int ret; |
1052 | 1144 | ||
1145 | if (lockdep_dependency_visit(source, depth)) | ||
1146 | return 1; | ||
1147 | |||
1053 | if (!__raw_spin_is_locked(&lockdep_lock)) | 1148 | if (!__raw_spin_is_locked(&lockdep_lock)) |
1054 | return DEBUG_LOCKS_WARN_ON(1); | 1149 | return DEBUG_LOCKS_WARN_ON(1); |
1055 | 1150 | ||
@@ -1064,6 +1159,11 @@ find_usage_backwards(struct lock_class *source, unsigned int depth) | |||
1064 | return 2; | 1159 | return 2; |
1065 | } | 1160 | } |
1066 | 1161 | ||
1162 | if (!source && debug_locks_off_graph_unlock()) { | ||
1163 | WARN_ON(1); | ||
1164 | return 0; | ||
1165 | } | ||
1166 | |||
1067 | /* | 1167 | /* |
1068 | * Check this lock's dependency list: | 1168 | * Check this lock's dependency list: |
1069 | */ | 1169 | */ |
@@ -1103,9 +1203,9 @@ print_bad_irq_dependency(struct task_struct *curr, | |||
1103 | printk("\nand this task is already holding:\n"); | 1203 | printk("\nand this task is already holding:\n"); |
1104 | print_lock(prev); | 1204 | print_lock(prev); |
1105 | printk("which would create a new lock dependency:\n"); | 1205 | printk("which would create a new lock dependency:\n"); |
1106 | print_lock_name(prev->class); | 1206 | print_lock_name(hlock_class(prev)); |
1107 | printk(" ->"); | 1207 | printk(" ->"); |
1108 | print_lock_name(next->class); | 1208 | print_lock_name(hlock_class(next)); |
1109 | printk("\n"); | 1209 | printk("\n"); |
1110 | 1210 | ||
1111 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", | 1211 | printk("\nbut this new dependency connects a %s-irq-safe lock:\n", |
@@ -1146,12 +1246,12 @@ check_usage(struct task_struct *curr, struct held_lock *prev, | |||
1146 | 1246 | ||
1147 | find_usage_bit = bit_backwards; | 1247 | find_usage_bit = bit_backwards; |
1148 | /* fills in <backwards_match> */ | 1248 | /* fills in <backwards_match> */ |
1149 | ret = find_usage_backwards(prev->class, 0); | 1249 | ret = find_usage_backwards(hlock_class(prev), 0); |
1150 | if (!ret || ret == 1) | 1250 | if (!ret || ret == 1) |
1151 | return ret; | 1251 | return ret; |
1152 | 1252 | ||
1153 | find_usage_bit = bit_forwards; | 1253 | find_usage_bit = bit_forwards; |
1154 | ret = find_usage_forwards(next->class, 0); | 1254 | ret = find_usage_forwards(hlock_class(next), 0); |
1155 | if (!ret || ret == 1) | 1255 | if (!ret || ret == 1) |
1156 | return ret; | 1256 | return ret; |
1157 | /* ret == 2 */ | 1257 | /* ret == 2 */ |
@@ -1272,18 +1372,32 @@ check_deadlock(struct task_struct *curr, struct held_lock *next, | |||
1272 | struct lockdep_map *next_instance, int read) | 1372 | struct lockdep_map *next_instance, int read) |
1273 | { | 1373 | { |
1274 | struct held_lock *prev; | 1374 | struct held_lock *prev; |
1375 | struct held_lock *nest = NULL; | ||
1275 | int i; | 1376 | int i; |
1276 | 1377 | ||
1277 | for (i = 0; i < curr->lockdep_depth; i++) { | 1378 | for (i = 0; i < curr->lockdep_depth; i++) { |
1278 | prev = curr->held_locks + i; | 1379 | prev = curr->held_locks + i; |
1279 | if (prev->class != next->class) | 1380 | |
1381 | if (prev->instance == next->nest_lock) | ||
1382 | nest = prev; | ||
1383 | |||
1384 | if (hlock_class(prev) != hlock_class(next)) | ||
1280 | continue; | 1385 | continue; |
1386 | |||
1281 | /* | 1387 | /* |
1282 | * Allow read-after-read recursion of the same | 1388 | * Allow read-after-read recursion of the same |
1283 | * lock class (i.e. read_lock(lock)+read_lock(lock)): | 1389 | * lock class (i.e. read_lock(lock)+read_lock(lock)): |
1284 | */ | 1390 | */ |
1285 | if ((read == 2) && prev->read) | 1391 | if ((read == 2) && prev->read) |
1286 | return 2; | 1392 | return 2; |
1393 | |||
1394 | /* | ||
1395 | * We're holding the nest_lock, which serializes this lock's | ||
1396 | * nesting behaviour. | ||
1397 | */ | ||
1398 | if (nest) | ||
1399 | return 2; | ||
1400 | |||
1287 | return print_deadlock_bug(curr, prev, next); | 1401 | return print_deadlock_bug(curr, prev, next); |
1288 | } | 1402 | } |
1289 | return 1; | 1403 | return 1; |
@@ -1329,7 +1443,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1329 | */ | 1443 | */ |
1330 | check_source = next; | 1444 | check_source = next; |
1331 | check_target = prev; | 1445 | check_target = prev; |
1332 | if (!(check_noncircular(next->class, 0))) | 1446 | if (!(check_noncircular(hlock_class(next), 0))) |
1333 | return print_circular_bug_tail(); | 1447 | return print_circular_bug_tail(); |
1334 | 1448 | ||
1335 | if (!check_prev_add_irq(curr, prev, next)) | 1449 | if (!check_prev_add_irq(curr, prev, next)) |
@@ -1353,8 +1467,8 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1353 | * chains - the second one will be new, but L1 already has | 1467 | * chains - the second one will be new, but L1 already has |
1354 | * L2 added to its dependency list, due to the first chain.) | 1468 | * L2 added to its dependency list, due to the first chain.) |
1355 | */ | 1469 | */ |
1356 | list_for_each_entry(entry, &prev->class->locks_after, entry) { | 1470 | list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { |
1357 | if (entry->class == next->class) { | 1471 | if (entry->class == hlock_class(next)) { |
1358 | if (distance == 1) | 1472 | if (distance == 1) |
1359 | entry->distance = 1; | 1473 | entry->distance = 1; |
1360 | return 2; | 1474 | return 2; |
@@ -1365,26 +1479,28 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1365 | * Ok, all validations passed, add the new lock | 1479 | * Ok, all validations passed, add the new lock |
1366 | * to the previous lock's dependency list: | 1480 | * to the previous lock's dependency list: |
1367 | */ | 1481 | */ |
1368 | ret = add_lock_to_list(prev->class, next->class, | 1482 | ret = add_lock_to_list(hlock_class(prev), hlock_class(next), |
1369 | &prev->class->locks_after, next->acquire_ip, distance); | 1483 | &hlock_class(prev)->locks_after, |
1484 | next->acquire_ip, distance); | ||
1370 | 1485 | ||
1371 | if (!ret) | 1486 | if (!ret) |
1372 | return 0; | 1487 | return 0; |
1373 | 1488 | ||
1374 | ret = add_lock_to_list(next->class, prev->class, | 1489 | ret = add_lock_to_list(hlock_class(next), hlock_class(prev), |
1375 | &next->class->locks_before, next->acquire_ip, distance); | 1490 | &hlock_class(next)->locks_before, |
1491 | next->acquire_ip, distance); | ||
1376 | if (!ret) | 1492 | if (!ret) |
1377 | return 0; | 1493 | return 0; |
1378 | 1494 | ||
1379 | /* | 1495 | /* |
1380 | * Debugging printouts: | 1496 | * Debugging printouts: |
1381 | */ | 1497 | */ |
1382 | if (verbose(prev->class) || verbose(next->class)) { | 1498 | if (verbose(hlock_class(prev)) || verbose(hlock_class(next))) { |
1383 | graph_unlock(); | 1499 | graph_unlock(); |
1384 | printk("\n new dependency: "); | 1500 | printk("\n new dependency: "); |
1385 | print_lock_name(prev->class); | 1501 | print_lock_name(hlock_class(prev)); |
1386 | printk(" => "); | 1502 | printk(" => "); |
1387 | print_lock_name(next->class); | 1503 | print_lock_name(hlock_class(next)); |
1388 | printk("\n"); | 1504 | printk("\n"); |
1389 | dump_stack(); | 1505 | dump_stack(); |
1390 | return graph_lock(); | 1506 | return graph_lock(); |
@@ -1481,7 +1597,7 @@ static inline int lookup_chain_cache(struct task_struct *curr, | |||
1481 | struct held_lock *hlock, | 1597 | struct held_lock *hlock, |
1482 | u64 chain_key) | 1598 | u64 chain_key) |
1483 | { | 1599 | { |
1484 | struct lock_class *class = hlock->class; | 1600 | struct lock_class *class = hlock_class(hlock); |
1485 | struct list_head *hash_head = chainhashentry(chain_key); | 1601 | struct list_head *hash_head = chainhashentry(chain_key); |
1486 | struct lock_chain *chain; | 1602 | struct lock_chain *chain; |
1487 | struct held_lock *hlock_curr, *hlock_next; | 1603 | struct held_lock *hlock_curr, *hlock_next; |
@@ -1554,7 +1670,7 @@ cache_hit: | |||
1554 | if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) { | 1670 | if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) { |
1555 | chain->base = cn; | 1671 | chain->base = cn; |
1556 | for (j = 0; j < chain->depth - 1; j++, i++) { | 1672 | for (j = 0; j < chain->depth - 1; j++, i++) { |
1557 | int lock_id = curr->held_locks[i].class - lock_classes; | 1673 | int lock_id = curr->held_locks[i].class_idx - 1; |
1558 | chain_hlocks[chain->base + j] = lock_id; | 1674 | chain_hlocks[chain->base + j] = lock_id; |
1559 | } | 1675 | } |
1560 | chain_hlocks[chain->base + j] = class - lock_classes; | 1676 | chain_hlocks[chain->base + j] = class - lock_classes; |
@@ -1643,14 +1759,13 @@ static void check_chain_key(struct task_struct *curr) | |||
1643 | hlock = curr->held_locks + i; | 1759 | hlock = curr->held_locks + i; |
1644 | if (chain_key != hlock->prev_chain_key) { | 1760 | if (chain_key != hlock->prev_chain_key) { |
1645 | debug_locks_off(); | 1761 | debug_locks_off(); |
1646 | printk("hm#1, depth: %u [%u], %016Lx != %016Lx\n", | 1762 | WARN(1, "hm#1, depth: %u [%u], %016Lx != %016Lx\n", |
1647 | curr->lockdep_depth, i, | 1763 | curr->lockdep_depth, i, |
1648 | (unsigned long long)chain_key, | 1764 | (unsigned long long)chain_key, |
1649 | (unsigned long long)hlock->prev_chain_key); | 1765 | (unsigned long long)hlock->prev_chain_key); |
1650 | WARN_ON(1); | ||
1651 | return; | 1766 | return; |
1652 | } | 1767 | } |
1653 | id = hlock->class - lock_classes; | 1768 | id = hlock->class_idx - 1; |
1654 | if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) | 1769 | if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS)) |
1655 | return; | 1770 | return; |
1656 | 1771 | ||
@@ -1662,11 +1777,10 @@ static void check_chain_key(struct task_struct *curr) | |||
1662 | } | 1777 | } |
1663 | if (chain_key != curr->curr_chain_key) { | 1778 | if (chain_key != curr->curr_chain_key) { |
1664 | debug_locks_off(); | 1779 | debug_locks_off(); |
1665 | printk("hm#2, depth: %u [%u], %016Lx != %016Lx\n", | 1780 | WARN(1, "hm#2, depth: %u [%u], %016Lx != %016Lx\n", |
1666 | curr->lockdep_depth, i, | 1781 | curr->lockdep_depth, i, |
1667 | (unsigned long long)chain_key, | 1782 | (unsigned long long)chain_key, |
1668 | (unsigned long long)curr->curr_chain_key); | 1783 | (unsigned long long)curr->curr_chain_key); |
1669 | WARN_ON(1); | ||
1670 | } | 1784 | } |
1671 | #endif | 1785 | #endif |
1672 | } | 1786 | } |
@@ -1695,7 +1809,7 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, | |||
1695 | print_lock(this); | 1809 | print_lock(this); |
1696 | 1810 | ||
1697 | printk("{%s} state was registered at:\n", usage_str[prev_bit]); | 1811 | printk("{%s} state was registered at:\n", usage_str[prev_bit]); |
1698 | print_stack_trace(this->class->usage_traces + prev_bit, 1); | 1812 | print_stack_trace(hlock_class(this)->usage_traces + prev_bit, 1); |
1699 | 1813 | ||
1700 | print_irqtrace_events(curr); | 1814 | print_irqtrace_events(curr); |
1701 | printk("\nother info that might help us debug this:\n"); | 1815 | printk("\nother info that might help us debug this:\n"); |
@@ -1714,7 +1828,7 @@ static inline int | |||
1714 | valid_state(struct task_struct *curr, struct held_lock *this, | 1828 | valid_state(struct task_struct *curr, struct held_lock *this, |
1715 | enum lock_usage_bit new_bit, enum lock_usage_bit bad_bit) | 1829 | enum lock_usage_bit new_bit, enum lock_usage_bit bad_bit) |
1716 | { | 1830 | { |
1717 | if (unlikely(this->class->usage_mask & (1 << bad_bit))) | 1831 | if (unlikely(hlock_class(this)->usage_mask & (1 << bad_bit))) |
1718 | return print_usage_bug(curr, this, bad_bit, new_bit); | 1832 | return print_usage_bug(curr, this, bad_bit, new_bit); |
1719 | return 1; | 1833 | return 1; |
1720 | } | 1834 | } |
@@ -1753,7 +1867,7 @@ print_irq_inversion_bug(struct task_struct *curr, struct lock_class *other, | |||
1753 | lockdep_print_held_locks(curr); | 1867 | lockdep_print_held_locks(curr); |
1754 | 1868 | ||
1755 | printk("\nthe first lock's dependencies:\n"); | 1869 | printk("\nthe first lock's dependencies:\n"); |
1756 | print_lock_dependencies(this->class, 0); | 1870 | print_lock_dependencies(hlock_class(this), 0); |
1757 | 1871 | ||
1758 | printk("\nthe second lock's dependencies:\n"); | 1872 | printk("\nthe second lock's dependencies:\n"); |
1759 | print_lock_dependencies(other, 0); | 1873 | print_lock_dependencies(other, 0); |
@@ -1776,7 +1890,7 @@ check_usage_forwards(struct task_struct *curr, struct held_lock *this, | |||
1776 | 1890 | ||
1777 | find_usage_bit = bit; | 1891 | find_usage_bit = bit; |
1778 | /* fills in <forwards_match> */ | 1892 | /* fills in <forwards_match> */ |
1779 | ret = find_usage_forwards(this->class, 0); | 1893 | ret = find_usage_forwards(hlock_class(this), 0); |
1780 | if (!ret || ret == 1) | 1894 | if (!ret || ret == 1) |
1781 | return ret; | 1895 | return ret; |
1782 | 1896 | ||
@@ -1795,7 +1909,7 @@ check_usage_backwards(struct task_struct *curr, struct held_lock *this, | |||
1795 | 1909 | ||
1796 | find_usage_bit = bit; | 1910 | find_usage_bit = bit; |
1797 | /* fills in <backwards_match> */ | 1911 | /* fills in <backwards_match> */ |
1798 | ret = find_usage_backwards(this->class, 0); | 1912 | ret = find_usage_backwards(hlock_class(this), 0); |
1799 | if (!ret || ret == 1) | 1913 | if (!ret || ret == 1) |
1800 | return ret; | 1914 | return ret; |
1801 | 1915 | ||
@@ -1861,7 +1975,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1861 | LOCK_ENABLED_HARDIRQS_READ, "hard-read")) | 1975 | LOCK_ENABLED_HARDIRQS_READ, "hard-read")) |
1862 | return 0; | 1976 | return 0; |
1863 | #endif | 1977 | #endif |
1864 | if (hardirq_verbose(this->class)) | 1978 | if (hardirq_verbose(hlock_class(this))) |
1865 | ret = 2; | 1979 | ret = 2; |
1866 | break; | 1980 | break; |
1867 | case LOCK_USED_IN_SOFTIRQ: | 1981 | case LOCK_USED_IN_SOFTIRQ: |
@@ -1886,7 +2000,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1886 | LOCK_ENABLED_SOFTIRQS_READ, "soft-read")) | 2000 | LOCK_ENABLED_SOFTIRQS_READ, "soft-read")) |
1887 | return 0; | 2001 | return 0; |
1888 | #endif | 2002 | #endif |
1889 | if (softirq_verbose(this->class)) | 2003 | if (softirq_verbose(hlock_class(this))) |
1890 | ret = 2; | 2004 | ret = 2; |
1891 | break; | 2005 | break; |
1892 | case LOCK_USED_IN_HARDIRQ_READ: | 2006 | case LOCK_USED_IN_HARDIRQ_READ: |
@@ -1899,7 +2013,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1899 | if (!check_usage_forwards(curr, this, | 2013 | if (!check_usage_forwards(curr, this, |
1900 | LOCK_ENABLED_HARDIRQS, "hard")) | 2014 | LOCK_ENABLED_HARDIRQS, "hard")) |
1901 | return 0; | 2015 | return 0; |
1902 | if (hardirq_verbose(this->class)) | 2016 | if (hardirq_verbose(hlock_class(this))) |
1903 | ret = 2; | 2017 | ret = 2; |
1904 | break; | 2018 | break; |
1905 | case LOCK_USED_IN_SOFTIRQ_READ: | 2019 | case LOCK_USED_IN_SOFTIRQ_READ: |
@@ -1912,7 +2026,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1912 | if (!check_usage_forwards(curr, this, | 2026 | if (!check_usage_forwards(curr, this, |
1913 | LOCK_ENABLED_SOFTIRQS, "soft")) | 2027 | LOCK_ENABLED_SOFTIRQS, "soft")) |
1914 | return 0; | 2028 | return 0; |
1915 | if (softirq_verbose(this->class)) | 2029 | if (softirq_verbose(hlock_class(this))) |
1916 | ret = 2; | 2030 | ret = 2; |
1917 | break; | 2031 | break; |
1918 | case LOCK_ENABLED_HARDIRQS: | 2032 | case LOCK_ENABLED_HARDIRQS: |
@@ -1938,7 +2052,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1938 | LOCK_USED_IN_HARDIRQ_READ, "hard-read")) | 2052 | LOCK_USED_IN_HARDIRQ_READ, "hard-read")) |
1939 | return 0; | 2053 | return 0; |
1940 | #endif | 2054 | #endif |
1941 | if (hardirq_verbose(this->class)) | 2055 | if (hardirq_verbose(hlock_class(this))) |
1942 | ret = 2; | 2056 | ret = 2; |
1943 | break; | 2057 | break; |
1944 | case LOCK_ENABLED_SOFTIRQS: | 2058 | case LOCK_ENABLED_SOFTIRQS: |
@@ -1964,7 +2078,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1964 | LOCK_USED_IN_SOFTIRQ_READ, "soft-read")) | 2078 | LOCK_USED_IN_SOFTIRQ_READ, "soft-read")) |
1965 | return 0; | 2079 | return 0; |
1966 | #endif | 2080 | #endif |
1967 | if (softirq_verbose(this->class)) | 2081 | if (softirq_verbose(hlock_class(this))) |
1968 | ret = 2; | 2082 | ret = 2; |
1969 | break; | 2083 | break; |
1970 | case LOCK_ENABLED_HARDIRQS_READ: | 2084 | case LOCK_ENABLED_HARDIRQS_READ: |
@@ -1979,7 +2093,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1979 | LOCK_USED_IN_HARDIRQ, "hard")) | 2093 | LOCK_USED_IN_HARDIRQ, "hard")) |
1980 | return 0; | 2094 | return 0; |
1981 | #endif | 2095 | #endif |
1982 | if (hardirq_verbose(this->class)) | 2096 | if (hardirq_verbose(hlock_class(this))) |
1983 | ret = 2; | 2097 | ret = 2; |
1984 | break; | 2098 | break; |
1985 | case LOCK_ENABLED_SOFTIRQS_READ: | 2099 | case LOCK_ENABLED_SOFTIRQS_READ: |
@@ -1994,7 +2108,7 @@ static int mark_lock_irq(struct task_struct *curr, struct held_lock *this, | |||
1994 | LOCK_USED_IN_SOFTIRQ, "soft")) | 2108 | LOCK_USED_IN_SOFTIRQ, "soft")) |
1995 | return 0; | 2109 | return 0; |
1996 | #endif | 2110 | #endif |
1997 | if (softirq_verbose(this->class)) | 2111 | if (softirq_verbose(hlock_class(this))) |
1998 | ret = 2; | 2112 | ret = 2; |
1999 | break; | 2113 | break; |
2000 | default: | 2114 | default: |
@@ -2310,7 +2424,7 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, | |||
2310 | * If already set then do not dirty the cacheline, | 2424 | * If already set then do not dirty the cacheline, |
2311 | * nor do any checks: | 2425 | * nor do any checks: |
2312 | */ | 2426 | */ |
2313 | if (likely(this->class->usage_mask & new_mask)) | 2427 | if (likely(hlock_class(this)->usage_mask & new_mask)) |
2314 | return 1; | 2428 | return 1; |
2315 | 2429 | ||
2316 | if (!graph_lock()) | 2430 | if (!graph_lock()) |
@@ -2318,14 +2432,14 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, | |||
2318 | /* | 2432 | /* |
2319 | * Make sure we didnt race: | 2433 | * Make sure we didnt race: |
2320 | */ | 2434 | */ |
2321 | if (unlikely(this->class->usage_mask & new_mask)) { | 2435 | if (unlikely(hlock_class(this)->usage_mask & new_mask)) { |
2322 | graph_unlock(); | 2436 | graph_unlock(); |
2323 | return 1; | 2437 | return 1; |
2324 | } | 2438 | } |
2325 | 2439 | ||
2326 | this->class->usage_mask |= new_mask; | 2440 | hlock_class(this)->usage_mask |= new_mask; |
2327 | 2441 | ||
2328 | if (!save_trace(this->class->usage_traces + new_bit)) | 2442 | if (!save_trace(hlock_class(this)->usage_traces + new_bit)) |
2329 | return 0; | 2443 | return 0; |
2330 | 2444 | ||
2331 | switch (new_bit) { | 2445 | switch (new_bit) { |
@@ -2405,7 +2519,7 @@ EXPORT_SYMBOL_GPL(lockdep_init_map); | |||
2405 | */ | 2519 | */ |
2406 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | 2520 | static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, |
2407 | int trylock, int read, int check, int hardirqs_off, | 2521 | int trylock, int read, int check, int hardirqs_off, |
2408 | unsigned long ip) | 2522 | struct lockdep_map *nest_lock, unsigned long ip) |
2409 | { | 2523 | { |
2410 | struct task_struct *curr = current; | 2524 | struct task_struct *curr = current; |
2411 | struct lock_class *class = NULL; | 2525 | struct lock_class *class = NULL; |
@@ -2459,14 +2573,16 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
2459 | return 0; | 2573 | return 0; |
2460 | 2574 | ||
2461 | hlock = curr->held_locks + depth; | 2575 | hlock = curr->held_locks + depth; |
2462 | 2576 | if (DEBUG_LOCKS_WARN_ON(!class)) | |
2463 | hlock->class = class; | 2577 | return 0; |
2578 | hlock->class_idx = class - lock_classes + 1; | ||
2464 | hlock->acquire_ip = ip; | 2579 | hlock->acquire_ip = ip; |
2465 | hlock->instance = lock; | 2580 | hlock->instance = lock; |
2581 | hlock->nest_lock = nest_lock; | ||
2466 | hlock->trylock = trylock; | 2582 | hlock->trylock = trylock; |
2467 | hlock->read = read; | 2583 | hlock->read = read; |
2468 | hlock->check = check; | 2584 | hlock->check = check; |
2469 | hlock->hardirqs_off = hardirqs_off; | 2585 | hlock->hardirqs_off = !!hardirqs_off; |
2470 | #ifdef CONFIG_LOCK_STAT | 2586 | #ifdef CONFIG_LOCK_STAT |
2471 | hlock->waittime_stamp = 0; | 2587 | hlock->waittime_stamp = 0; |
2472 | hlock->holdtime_stamp = sched_clock(); | 2588 | hlock->holdtime_stamp = sched_clock(); |
@@ -2574,6 +2690,55 @@ static int check_unlock(struct task_struct *curr, struct lockdep_map *lock, | |||
2574 | return 1; | 2690 | return 1; |
2575 | } | 2691 | } |
2576 | 2692 | ||
2693 | static int | ||
2694 | __lock_set_subclass(struct lockdep_map *lock, | ||
2695 | unsigned int subclass, unsigned long ip) | ||
2696 | { | ||
2697 | struct task_struct *curr = current; | ||
2698 | struct held_lock *hlock, *prev_hlock; | ||
2699 | struct lock_class *class; | ||
2700 | unsigned int depth; | ||
2701 | int i; | ||
2702 | |||
2703 | depth = curr->lockdep_depth; | ||
2704 | if (DEBUG_LOCKS_WARN_ON(!depth)) | ||
2705 | return 0; | ||
2706 | |||
2707 | prev_hlock = NULL; | ||
2708 | for (i = depth-1; i >= 0; i--) { | ||
2709 | hlock = curr->held_locks + i; | ||
2710 | /* | ||
2711 | * We must not cross into another context: | ||
2712 | */ | ||
2713 | if (prev_hlock && prev_hlock->irq_context != hlock->irq_context) | ||
2714 | break; | ||
2715 | if (hlock->instance == lock) | ||
2716 | goto found_it; | ||
2717 | prev_hlock = hlock; | ||
2718 | } | ||
2719 | return print_unlock_inbalance_bug(curr, lock, ip); | ||
2720 | |||
2721 | found_it: | ||
2722 | class = register_lock_class(lock, subclass, 0); | ||
2723 | hlock->class_idx = class - lock_classes + 1; | ||
2724 | |||
2725 | curr->lockdep_depth = i; | ||
2726 | curr->curr_chain_key = hlock->prev_chain_key; | ||
2727 | |||
2728 | for (; i < depth; i++) { | ||
2729 | hlock = curr->held_locks + i; | ||
2730 | if (!__lock_acquire(hlock->instance, | ||
2731 | hlock_class(hlock)->subclass, hlock->trylock, | ||
2732 | hlock->read, hlock->check, hlock->hardirqs_off, | ||
2733 | hlock->nest_lock, hlock->acquire_ip)) | ||
2734 | return 0; | ||
2735 | } | ||
2736 | |||
2737 | if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth)) | ||
2738 | return 0; | ||
2739 | return 1; | ||
2740 | } | ||
2741 | |||
2577 | /* | 2742 | /* |
2578 | * Remove the lock to the list of currently held locks in a | 2743 | * Remove the lock to the list of currently held locks in a |
2579 | * potentially non-nested (out of order) manner. This is a | 2744 | * potentially non-nested (out of order) manner. This is a |
@@ -2624,9 +2789,9 @@ found_it: | |||
2624 | for (i++; i < depth; i++) { | 2789 | for (i++; i < depth; i++) { |
2625 | hlock = curr->held_locks + i; | 2790 | hlock = curr->held_locks + i; |
2626 | if (!__lock_acquire(hlock->instance, | 2791 | if (!__lock_acquire(hlock->instance, |
2627 | hlock->class->subclass, hlock->trylock, | 2792 | hlock_class(hlock)->subclass, hlock->trylock, |
2628 | hlock->read, hlock->check, hlock->hardirqs_off, | 2793 | hlock->read, hlock->check, hlock->hardirqs_off, |
2629 | hlock->acquire_ip)) | 2794 | hlock->nest_lock, hlock->acquire_ip)) |
2630 | return 0; | 2795 | return 0; |
2631 | } | 2796 | } |
2632 | 2797 | ||
@@ -2669,7 +2834,7 @@ static int lock_release_nested(struct task_struct *curr, | |||
2669 | 2834 | ||
2670 | #ifdef CONFIG_DEBUG_LOCKDEP | 2835 | #ifdef CONFIG_DEBUG_LOCKDEP |
2671 | hlock->prev_chain_key = 0; | 2836 | hlock->prev_chain_key = 0; |
2672 | hlock->class = NULL; | 2837 | hlock->class_idx = 0; |
2673 | hlock->acquire_ip = 0; | 2838 | hlock->acquire_ip = 0; |
2674 | hlock->irq_context = 0; | 2839 | hlock->irq_context = 0; |
2675 | #endif | 2840 | #endif |
@@ -2738,18 +2903,36 @@ static void check_flags(unsigned long flags) | |||
2738 | #endif | 2903 | #endif |
2739 | } | 2904 | } |
2740 | 2905 | ||
2906 | void | ||
2907 | lock_set_subclass(struct lockdep_map *lock, | ||
2908 | unsigned int subclass, unsigned long ip) | ||
2909 | { | ||
2910 | unsigned long flags; | ||
2911 | |||
2912 | if (unlikely(current->lockdep_recursion)) | ||
2913 | return; | ||
2914 | |||
2915 | raw_local_irq_save(flags); | ||
2916 | current->lockdep_recursion = 1; | ||
2917 | check_flags(flags); | ||
2918 | if (__lock_set_subclass(lock, subclass, ip)) | ||
2919 | check_chain_key(current); | ||
2920 | current->lockdep_recursion = 0; | ||
2921 | raw_local_irq_restore(flags); | ||
2922 | } | ||
2923 | |||
2924 | EXPORT_SYMBOL_GPL(lock_set_subclass); | ||
2925 | |||
2741 | /* | 2926 | /* |
2742 | * We are not always called with irqs disabled - do that here, | 2927 | * We are not always called with irqs disabled - do that here, |
2743 | * and also avoid lockdep recursion: | 2928 | * and also avoid lockdep recursion: |
2744 | */ | 2929 | */ |
2745 | void lock_acquire(struct lockdep_map *lock, unsigned int subclass, | 2930 | void lock_acquire(struct lockdep_map *lock, unsigned int subclass, |
2746 | int trylock, int read, int check, unsigned long ip) | 2931 | int trylock, int read, int check, |
2932 | struct lockdep_map *nest_lock, unsigned long ip) | ||
2747 | { | 2933 | { |
2748 | unsigned long flags; | 2934 | unsigned long flags; |
2749 | 2935 | ||
2750 | if (unlikely(!lock_stat && !prove_locking)) | ||
2751 | return; | ||
2752 | |||
2753 | if (unlikely(current->lockdep_recursion)) | 2936 | if (unlikely(current->lockdep_recursion)) |
2754 | return; | 2937 | return; |
2755 | 2938 | ||
@@ -2758,7 +2941,7 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
2758 | 2941 | ||
2759 | current->lockdep_recursion = 1; | 2942 | current->lockdep_recursion = 1; |
2760 | __lock_acquire(lock, subclass, trylock, read, check, | 2943 | __lock_acquire(lock, subclass, trylock, read, check, |
2761 | irqs_disabled_flags(flags), ip); | 2944 | irqs_disabled_flags(flags), nest_lock, ip); |
2762 | current->lockdep_recursion = 0; | 2945 | current->lockdep_recursion = 0; |
2763 | raw_local_irq_restore(flags); | 2946 | raw_local_irq_restore(flags); |
2764 | } | 2947 | } |
@@ -2770,9 +2953,6 @@ void lock_release(struct lockdep_map *lock, int nested, | |||
2770 | { | 2953 | { |
2771 | unsigned long flags; | 2954 | unsigned long flags; |
2772 | 2955 | ||
2773 | if (unlikely(!lock_stat && !prove_locking)) | ||
2774 | return; | ||
2775 | |||
2776 | if (unlikely(current->lockdep_recursion)) | 2956 | if (unlikely(current->lockdep_recursion)) |
2777 | return; | 2957 | return; |
2778 | 2958 | ||
@@ -2845,11 +3025,11 @@ __lock_contended(struct lockdep_map *lock, unsigned long ip) | |||
2845 | found_it: | 3025 | found_it: |
2846 | hlock->waittime_stamp = sched_clock(); | 3026 | hlock->waittime_stamp = sched_clock(); |
2847 | 3027 | ||
2848 | point = lock_contention_point(hlock->class, ip); | 3028 | point = lock_contention_point(hlock_class(hlock), ip); |
2849 | 3029 | ||
2850 | stats = get_lock_stats(hlock->class); | 3030 | stats = get_lock_stats(hlock_class(hlock)); |
2851 | if (point < ARRAY_SIZE(stats->contention_point)) | 3031 | if (point < ARRAY_SIZE(stats->contention_point)) |
2852 | stats->contention_point[i]++; | 3032 | stats->contention_point[point]++; |
2853 | if (lock->cpu != smp_processor_id()) | 3033 | if (lock->cpu != smp_processor_id()) |
2854 | stats->bounces[bounce_contended + !!hlock->read]++; | 3034 | stats->bounces[bounce_contended + !!hlock->read]++; |
2855 | put_lock_stats(stats); | 3035 | put_lock_stats(stats); |
@@ -2893,7 +3073,7 @@ found_it: | |||
2893 | hlock->holdtime_stamp = now; | 3073 | hlock->holdtime_stamp = now; |
2894 | } | 3074 | } |
2895 | 3075 | ||
2896 | stats = get_lock_stats(hlock->class); | 3076 | stats = get_lock_stats(hlock_class(hlock)); |
2897 | if (waittime) { | 3077 | if (waittime) { |
2898 | if (hlock->read) | 3078 | if (hlock->read) |
2899 | lock_time_inc(&stats->read_waittime, waittime); | 3079 | lock_time_inc(&stats->read_waittime, waittime); |
@@ -2988,6 +3168,7 @@ static void zap_class(struct lock_class *class) | |||
2988 | list_del_rcu(&class->hash_entry); | 3168 | list_del_rcu(&class->hash_entry); |
2989 | list_del_rcu(&class->lock_entry); | 3169 | list_del_rcu(&class->lock_entry); |
2990 | 3170 | ||
3171 | class->key = NULL; | ||
2991 | } | 3172 | } |
2992 | 3173 | ||
2993 | static inline int within(const void *addr, void *start, unsigned long size) | 3174 | static inline int within(const void *addr, void *start, unsigned long size) |
diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h index c3600a091a28..56b196932c08 100644 --- a/kernel/lockdep_internals.h +++ b/kernel/lockdep_internals.h | |||
@@ -17,9 +17,6 @@ | |||
17 | */ | 17 | */ |
18 | #define MAX_LOCKDEP_ENTRIES 8192UL | 18 | #define MAX_LOCKDEP_ENTRIES 8192UL |
19 | 19 | ||
20 | #define MAX_LOCKDEP_KEYS_BITS 11 | ||
21 | #define MAX_LOCKDEP_KEYS (1UL << MAX_LOCKDEP_KEYS_BITS) | ||
22 | |||
23 | #define MAX_LOCKDEP_CHAINS_BITS 14 | 20 | #define MAX_LOCKDEP_CHAINS_BITS 14 |
24 | #define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) | 21 | #define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS) |
25 | 22 | ||
@@ -53,6 +50,22 @@ extern unsigned int nr_process_chains; | |||
53 | extern unsigned int max_lockdep_depth; | 50 | extern unsigned int max_lockdep_depth; |
54 | extern unsigned int max_recursion_depth; | 51 | extern unsigned int max_recursion_depth; |
55 | 52 | ||
53 | #ifdef CONFIG_PROVE_LOCKING | ||
54 | extern unsigned long lockdep_count_forward_deps(struct lock_class *); | ||
55 | extern unsigned long lockdep_count_backward_deps(struct lock_class *); | ||
56 | #else | ||
57 | static inline unsigned long | ||
58 | lockdep_count_forward_deps(struct lock_class *class) | ||
59 | { | ||
60 | return 0; | ||
61 | } | ||
62 | static inline unsigned long | ||
63 | lockdep_count_backward_deps(struct lock_class *class) | ||
64 | { | ||
65 | return 0; | ||
66 | } | ||
67 | #endif | ||
68 | |||
56 | #ifdef CONFIG_DEBUG_LOCKDEP | 69 | #ifdef CONFIG_DEBUG_LOCKDEP |
57 | /* | 70 | /* |
58 | * Various lockdep statistics: | 71 | * Various lockdep statistics: |
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c index 9b0e940e2545..20dbcbf9c7dd 100644 --- a/kernel/lockdep_proc.c +++ b/kernel/lockdep_proc.c | |||
@@ -63,34 +63,6 @@ static void l_stop(struct seq_file *m, void *v) | |||
63 | { | 63 | { |
64 | } | 64 | } |
65 | 65 | ||
66 | static unsigned long count_forward_deps(struct lock_class *class) | ||
67 | { | ||
68 | struct lock_list *entry; | ||
69 | unsigned long ret = 1; | ||
70 | |||
71 | /* | ||
72 | * Recurse this class's dependency list: | ||
73 | */ | ||
74 | list_for_each_entry(entry, &class->locks_after, entry) | ||
75 | ret += count_forward_deps(entry->class); | ||
76 | |||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | static unsigned long count_backward_deps(struct lock_class *class) | ||
81 | { | ||
82 | struct lock_list *entry; | ||
83 | unsigned long ret = 1; | ||
84 | |||
85 | /* | ||
86 | * Recurse this class's dependency list: | ||
87 | */ | ||
88 | list_for_each_entry(entry, &class->locks_before, entry) | ||
89 | ret += count_backward_deps(entry->class); | ||
90 | |||
91 | return ret; | ||
92 | } | ||
93 | |||
94 | static void print_name(struct seq_file *m, struct lock_class *class) | 66 | static void print_name(struct seq_file *m, struct lock_class *class) |
95 | { | 67 | { |
96 | char str[128]; | 68 | char str[128]; |
@@ -110,7 +82,6 @@ static void print_name(struct seq_file *m, struct lock_class *class) | |||
110 | 82 | ||
111 | static int l_show(struct seq_file *m, void *v) | 83 | static int l_show(struct seq_file *m, void *v) |
112 | { | 84 | { |
113 | unsigned long nr_forward_deps, nr_backward_deps; | ||
114 | struct lock_class *class = v; | 85 | struct lock_class *class = v; |
115 | struct lock_list *entry; | 86 | struct lock_list *entry; |
116 | char c1, c2, c3, c4; | 87 | char c1, c2, c3, c4; |
@@ -124,11 +95,10 @@ static int l_show(struct seq_file *m, void *v) | |||
124 | #ifdef CONFIG_DEBUG_LOCKDEP | 95 | #ifdef CONFIG_DEBUG_LOCKDEP |
125 | seq_printf(m, " OPS:%8ld", class->ops); | 96 | seq_printf(m, " OPS:%8ld", class->ops); |
126 | #endif | 97 | #endif |
127 | nr_forward_deps = count_forward_deps(class); | 98 | #ifdef CONFIG_PROVE_LOCKING |
128 | seq_printf(m, " FD:%5ld", nr_forward_deps); | 99 | seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class)); |
129 | 100 | seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class)); | |
130 | nr_backward_deps = count_backward_deps(class); | 101 | #endif |
131 | seq_printf(m, " BD:%5ld", nr_backward_deps); | ||
132 | 102 | ||
133 | get_usage_chars(class, &c1, &c2, &c3, &c4); | 103 | get_usage_chars(class, &c1, &c2, &c3, &c4); |
134 | seq_printf(m, " %c%c%c%c", c1, c2, c3, c4); | 104 | seq_printf(m, " %c%c%c%c", c1, c2, c3, c4); |
@@ -229,6 +199,9 @@ static int lc_show(struct seq_file *m, void *v) | |||
229 | 199 | ||
230 | for (i = 0; i < chain->depth; i++) { | 200 | for (i = 0; i < chain->depth; i++) { |
231 | class = lock_chain_get_class(chain, i); | 201 | class = lock_chain_get_class(chain, i); |
202 | if (!class->key) | ||
203 | continue; | ||
204 | |||
232 | seq_printf(m, "[%p] ", class->key); | 205 | seq_printf(m, "[%p] ", class->key); |
233 | print_name(m, class); | 206 | print_name(m, class); |
234 | seq_puts(m, "\n"); | 207 | seq_puts(m, "\n"); |
@@ -350,7 +323,9 @@ static int lockdep_stats_show(struct seq_file *m, void *v) | |||
350 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQS_READ) | 323 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQS_READ) |
351 | nr_hardirq_read_unsafe++; | 324 | nr_hardirq_read_unsafe++; |
352 | 325 | ||
353 | sum_forward_deps += count_forward_deps(class); | 326 | #ifdef CONFIG_PROVE_LOCKING |
327 | sum_forward_deps += lockdep_count_forward_deps(class); | ||
328 | #endif | ||
354 | } | 329 | } |
355 | #ifdef CONFIG_DEBUG_LOCKDEP | 330 | #ifdef CONFIG_DEBUG_LOCKDEP |
356 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused); | 331 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused); |
@@ -497,8 +472,9 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr) | |||
497 | { | 472 | { |
498 | unsigned long rem; | 473 | unsigned long rem; |
499 | 474 | ||
475 | nr += 5; /* for display rounding */ | ||
500 | rem = do_div(nr, 1000); /* XXX: do_div_signed */ | 476 | rem = do_div(nr, 1000); /* XXX: do_div_signed */ |
501 | snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, ((int)rem+5)/10); | 477 | snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, (int)rem/10); |
502 | } | 478 | } |
503 | 479 | ||
504 | static void seq_time(struct seq_file *m, s64 time) | 480 | static void seq_time(struct seq_file *m, s64 time) |
diff --git a/kernel/marker.c b/kernel/marker.c index 971da5317903..7d1faecd7a51 100644 --- a/kernel/marker.c +++ b/kernel/marker.c | |||
@@ -126,6 +126,11 @@ void marker_probe_cb(const struct marker *mdata, void *call_private, ...) | |||
126 | struct marker_probe_closure *multi; | 126 | struct marker_probe_closure *multi; |
127 | int i; | 127 | int i; |
128 | /* | 128 | /* |
129 | * Read mdata->ptype before mdata->multi. | ||
130 | */ | ||
131 | smp_rmb(); | ||
132 | multi = mdata->multi; | ||
133 | /* | ||
129 | * multi points to an array, therefore accessing the array | 134 | * multi points to an array, therefore accessing the array |
130 | * depends on reading multi. However, even in this case, | 135 | * depends on reading multi. However, even in this case, |
131 | * we must insure that the pointer is read _before_ the array | 136 | * we must insure that the pointer is read _before_ the array |
@@ -133,7 +138,6 @@ void marker_probe_cb(const struct marker *mdata, void *call_private, ...) | |||
133 | * in the fast path, so put the explicit barrier here. | 138 | * in the fast path, so put the explicit barrier here. |
134 | */ | 139 | */ |
135 | smp_read_barrier_depends(); | 140 | smp_read_barrier_depends(); |
136 | multi = mdata->multi; | ||
137 | for (i = 0; multi[i].func; i++) { | 141 | for (i = 0; multi[i].func; i++) { |
138 | va_start(args, call_private); | 142 | va_start(args, call_private); |
139 | multi[i].func(multi[i].probe_private, call_private, | 143 | multi[i].func(multi[i].probe_private, call_private, |
@@ -175,6 +179,11 @@ void marker_probe_cb_noarg(const struct marker *mdata, void *call_private, ...) | |||
175 | struct marker_probe_closure *multi; | 179 | struct marker_probe_closure *multi; |
176 | int i; | 180 | int i; |
177 | /* | 181 | /* |
182 | * Read mdata->ptype before mdata->multi. | ||
183 | */ | ||
184 | smp_rmb(); | ||
185 | multi = mdata->multi; | ||
186 | /* | ||
178 | * multi points to an array, therefore accessing the array | 187 | * multi points to an array, therefore accessing the array |
179 | * depends on reading multi. However, even in this case, | 188 | * depends on reading multi. However, even in this case, |
180 | * we must insure that the pointer is read _before_ the array | 189 | * we must insure that the pointer is read _before_ the array |
@@ -182,7 +191,6 @@ void marker_probe_cb_noarg(const struct marker *mdata, void *call_private, ...) | |||
182 | * in the fast path, so put the explicit barrier here. | 191 | * in the fast path, so put the explicit barrier here. |
183 | */ | 192 | */ |
184 | smp_read_barrier_depends(); | 193 | smp_read_barrier_depends(); |
185 | multi = mdata->multi; | ||
186 | for (i = 0; multi[i].func; i++) | 194 | for (i = 0; multi[i].func; i++) |
187 | multi[i].func(multi[i].probe_private, call_private, | 195 | multi[i].func(multi[i].probe_private, call_private, |
188 | mdata->format, &args); | 196 | mdata->format, &args); |
diff --git a/kernel/module.c b/kernel/module.c index d8b5605132a0..9db11911e04b 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -325,18 +325,6 @@ static unsigned long find_symbol(const char *name, | |||
325 | return -ENOENT; | 325 | return -ENOENT; |
326 | } | 326 | } |
327 | 327 | ||
328 | /* lookup symbol in given range of kernel_symbols */ | ||
329 | static const struct kernel_symbol *lookup_symbol(const char *name, | ||
330 | const struct kernel_symbol *start, | ||
331 | const struct kernel_symbol *stop) | ||
332 | { | ||
333 | const struct kernel_symbol *ks = start; | ||
334 | for (; ks < stop; ks++) | ||
335 | if (strcmp(ks->name, name) == 0) | ||
336 | return ks; | ||
337 | return NULL; | ||
338 | } | ||
339 | |||
340 | /* Search for module by name: must hold module_mutex. */ | 328 | /* Search for module by name: must hold module_mutex. */ |
341 | static struct module *find_module(const char *name) | 329 | static struct module *find_module(const char *name) |
342 | { | 330 | { |
@@ -690,7 +678,7 @@ static int try_stop_module(struct module *mod, int flags, int *forced) | |||
690 | if (flags & O_NONBLOCK) { | 678 | if (flags & O_NONBLOCK) { |
691 | struct stopref sref = { mod, flags, forced }; | 679 | struct stopref sref = { mod, flags, forced }; |
692 | 680 | ||
693 | return stop_machine_run(__try_stop_module, &sref, NR_CPUS); | 681 | return stop_machine(__try_stop_module, &sref, NULL); |
694 | } else { | 682 | } else { |
695 | /* We don't need to stop the machine for this. */ | 683 | /* We don't need to stop the machine for this. */ |
696 | mod->state = MODULE_STATE_GOING; | 684 | mod->state = MODULE_STATE_GOING; |
@@ -1428,7 +1416,7 @@ static int __unlink_module(void *_mod) | |||
1428 | static void free_module(struct module *mod) | 1416 | static void free_module(struct module *mod) |
1429 | { | 1417 | { |
1430 | /* Delete from various lists */ | 1418 | /* Delete from various lists */ |
1431 | stop_machine_run(__unlink_module, mod, NR_CPUS); | 1419 | stop_machine(__unlink_module, mod, NULL); |
1432 | remove_notes_attrs(mod); | 1420 | remove_notes_attrs(mod); |
1433 | remove_sect_attrs(mod); | 1421 | remove_sect_attrs(mod); |
1434 | mod_kobject_remove(mod); | 1422 | mod_kobject_remove(mod); |
@@ -1703,6 +1691,19 @@ static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | |||
1703 | } | 1691 | } |
1704 | 1692 | ||
1705 | #ifdef CONFIG_KALLSYMS | 1693 | #ifdef CONFIG_KALLSYMS |
1694 | |||
1695 | /* lookup symbol in given range of kernel_symbols */ | ||
1696 | static const struct kernel_symbol *lookup_symbol(const char *name, | ||
1697 | const struct kernel_symbol *start, | ||
1698 | const struct kernel_symbol *stop) | ||
1699 | { | ||
1700 | const struct kernel_symbol *ks = start; | ||
1701 | for (; ks < stop; ks++) | ||
1702 | if (strcmp(ks->name, name) == 0) | ||
1703 | return ks; | ||
1704 | return NULL; | ||
1705 | } | ||
1706 | |||
1706 | static int is_exported(const char *name, const struct module *mod) | 1707 | static int is_exported(const char *name, const struct module *mod) |
1707 | { | 1708 | { |
1708 | if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab)) | 1709 | if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab)) |
@@ -1798,7 +1799,7 @@ static void *module_alloc_update_bounds(unsigned long size) | |||
1798 | 1799 | ||
1799 | /* Allocate and load the module: note that size of section 0 is always | 1800 | /* Allocate and load the module: note that size of section 0 is always |
1800 | zero, and we rely on this for optional sections. */ | 1801 | zero, and we rely on this for optional sections. */ |
1801 | static struct module *load_module(void __user *umod, | 1802 | static noinline struct module *load_module(void __user *umod, |
1802 | unsigned long len, | 1803 | unsigned long len, |
1803 | const char __user *uargs) | 1804 | const char __user *uargs) |
1804 | { | 1805 | { |
@@ -2196,7 +2197,7 @@ static struct module *load_module(void __user *umod, | |||
2196 | /* Now sew it into the lists so we can get lockdep and oops | 2197 | /* Now sew it into the lists so we can get lockdep and oops |
2197 | * info during argument parsing. Noone should access us, since | 2198 | * info during argument parsing. Noone should access us, since |
2198 | * strong_try_module_get() will fail. */ | 2199 | * strong_try_module_get() will fail. */ |
2199 | stop_machine_run(__link_module, mod, NR_CPUS); | 2200 | stop_machine(__link_module, mod, NULL); |
2200 | 2201 | ||
2201 | /* Size of section 0 is 0, so this works well if no params */ | 2202 | /* Size of section 0 is 0, so this works well if no params */ |
2202 | err = parse_args(mod->name, mod->args, | 2203 | err = parse_args(mod->name, mod->args, |
@@ -2230,7 +2231,7 @@ static struct module *load_module(void __user *umod, | |||
2230 | return mod; | 2231 | return mod; |
2231 | 2232 | ||
2232 | unlink: | 2233 | unlink: |
2233 | stop_machine_run(__unlink_module, mod, NR_CPUS); | 2234 | stop_machine(__unlink_module, mod, NULL); |
2234 | module_arch_cleanup(mod); | 2235 | module_arch_cleanup(mod); |
2235 | cleanup: | 2236 | cleanup: |
2236 | kobject_del(&mod->mkobj.kobj); | 2237 | kobject_del(&mod->mkobj.kobj); |
@@ -2287,7 +2288,7 @@ sys_init_module(void __user *umod, | |||
2287 | 2288 | ||
2288 | /* Start the module */ | 2289 | /* Start the module */ |
2289 | if (mod->init != NULL) | 2290 | if (mod->init != NULL) |
2290 | ret = mod->init(); | 2291 | ret = do_one_initcall(mod->init); |
2291 | if (ret < 0) { | 2292 | if (ret < 0) { |
2292 | /* Init routine failed: abort. Try to protect us from | 2293 | /* Init routine failed: abort. Try to protect us from |
2293 | buggy refcounters. */ | 2294 | buggy refcounters. */ |
diff --git a/kernel/mutex.c b/kernel/mutex.c index bcdc9ac8ef60..12c779dc65d4 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c | |||
@@ -34,6 +34,7 @@ | |||
34 | /*** | 34 | /*** |
35 | * mutex_init - initialize the mutex | 35 | * mutex_init - initialize the mutex |
36 | * @lock: the mutex to be initialized | 36 | * @lock: the mutex to be initialized |
37 | * @key: the lock_class_key for the class; used by mutex lock debugging | ||
37 | * | 38 | * |
38 | * Initialize the mutex to unlocked state. | 39 | * Initialize the mutex to unlocked state. |
39 | * | 40 | * |
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index 21575fc46d05..1d3ef29a2583 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c | |||
@@ -14,7 +14,6 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/version.h> | ||
18 | #include <linux/nsproxy.h> | 17 | #include <linux/nsproxy.h> |
19 | #include <linux/init_task.h> | 18 | #include <linux/init_task.h> |
20 | #include <linux/mnt_namespace.h> | 19 | #include <linux/mnt_namespace.h> |
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index ea567b78d1aa..fab8ea86fac3 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -179,9 +179,6 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
179 | rc = sys_wait4(-1, NULL, __WALL, NULL); | 179 | rc = sys_wait4(-1, NULL, __WALL, NULL); |
180 | } while (rc != -ECHILD); | 180 | } while (rc != -ECHILD); |
181 | 181 | ||
182 | |||
183 | /* Child reaper for the pid namespace is going away */ | ||
184 | pid_ns->child_reaper = NULL; | ||
185 | acct_exit_ns(pid_ns); | 182 | acct_exit_ns(pid_ns); |
186 | return; | 183 | return; |
187 | } | 184 | } |
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c index 8cb757026386..dfdec524d1b7 100644 --- a/kernel/pm_qos_params.c +++ b/kernel/pm_qos_params.c | |||
@@ -24,7 +24,7 @@ | |||
24 | * requirement that the application has is cleaned up when closes the file | 24 | * requirement that the application has is cleaned up when closes the file |
25 | * pointer or exits the pm_qos_object will get an opportunity to clean up. | 25 | * pointer or exits the pm_qos_object will get an opportunity to clean up. |
26 | * | 26 | * |
27 | * mark gross mgross@linux.intel.com | 27 | * Mark Gross <mgross@linux.intel.com> |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <linux/pm_qos_params.h> | 30 | #include <linux/pm_qos_params.h> |
@@ -43,7 +43,7 @@ | |||
43 | #include <linux/uaccess.h> | 43 | #include <linux/uaccess.h> |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * locking rule: all changes to target_value or requirements or notifiers lists | 46 | * locking rule: all changes to requirements or notifiers lists |
47 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock | 47 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock |
48 | * held, taken with _irqsave. One lock to rule them all | 48 | * held, taken with _irqsave. One lock to rule them all |
49 | */ | 49 | */ |
@@ -66,7 +66,7 @@ struct pm_qos_object { | |||
66 | struct miscdevice pm_qos_power_miscdev; | 66 | struct miscdevice pm_qos_power_miscdev; |
67 | char *name; | 67 | char *name; |
68 | s32 default_value; | 68 | s32 default_value; |
69 | s32 target_value; | 69 | atomic_t target_value; |
70 | s32 (*comparitor)(s32, s32); | 70 | s32 (*comparitor)(s32, s32); |
71 | }; | 71 | }; |
72 | 72 | ||
@@ -77,7 +77,7 @@ static struct pm_qos_object cpu_dma_pm_qos = { | |||
77 | .notifiers = &cpu_dma_lat_notifier, | 77 | .notifiers = &cpu_dma_lat_notifier, |
78 | .name = "cpu_dma_latency", | 78 | .name = "cpu_dma_latency", |
79 | .default_value = 2000 * USEC_PER_SEC, | 79 | .default_value = 2000 * USEC_PER_SEC, |
80 | .target_value = 2000 * USEC_PER_SEC, | 80 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), |
81 | .comparitor = min_compare | 81 | .comparitor = min_compare |
82 | }; | 82 | }; |
83 | 83 | ||
@@ -87,7 +87,7 @@ static struct pm_qos_object network_lat_pm_qos = { | |||
87 | .notifiers = &network_lat_notifier, | 87 | .notifiers = &network_lat_notifier, |
88 | .name = "network_latency", | 88 | .name = "network_latency", |
89 | .default_value = 2000 * USEC_PER_SEC, | 89 | .default_value = 2000 * USEC_PER_SEC, |
90 | .target_value = 2000 * USEC_PER_SEC, | 90 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), |
91 | .comparitor = min_compare | 91 | .comparitor = min_compare |
92 | }; | 92 | }; |
93 | 93 | ||
@@ -99,7 +99,7 @@ static struct pm_qos_object network_throughput_pm_qos = { | |||
99 | .notifiers = &network_throughput_notifier, | 99 | .notifiers = &network_throughput_notifier, |
100 | .name = "network_throughput", | 100 | .name = "network_throughput", |
101 | .default_value = 0, | 101 | .default_value = 0, |
102 | .target_value = 0, | 102 | .target_value = ATOMIC_INIT(0), |
103 | .comparitor = max_compare | 103 | .comparitor = max_compare |
104 | }; | 104 | }; |
105 | 105 | ||
@@ -150,11 +150,11 @@ static void update_target(int target) | |||
150 | extreme_value = pm_qos_array[target]->comparitor( | 150 | extreme_value = pm_qos_array[target]->comparitor( |
151 | extreme_value, node->value); | 151 | extreme_value, node->value); |
152 | } | 152 | } |
153 | if (pm_qos_array[target]->target_value != extreme_value) { | 153 | if (atomic_read(&pm_qos_array[target]->target_value) != extreme_value) { |
154 | call_notifier = 1; | 154 | call_notifier = 1; |
155 | pm_qos_array[target]->target_value = extreme_value; | 155 | atomic_set(&pm_qos_array[target]->target_value, extreme_value); |
156 | pr_debug(KERN_ERR "new target for qos %d is %d\n", target, | 156 | pr_debug(KERN_ERR "new target for qos %d is %d\n", target, |
157 | pm_qos_array[target]->target_value); | 157 | atomic_read(&pm_qos_array[target]->target_value)); |
158 | } | 158 | } |
159 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 159 | spin_unlock_irqrestore(&pm_qos_lock, flags); |
160 | 160 | ||
@@ -193,14 +193,7 @@ static int find_pm_qos_object_by_minor(int minor) | |||
193 | */ | 193 | */ |
194 | int pm_qos_requirement(int pm_qos_class) | 194 | int pm_qos_requirement(int pm_qos_class) |
195 | { | 195 | { |
196 | int ret_val; | 196 | return atomic_read(&pm_qos_array[pm_qos_class]->target_value); |
197 | unsigned long flags; | ||
198 | |||
199 | spin_lock_irqsave(&pm_qos_lock, flags); | ||
200 | ret_val = pm_qos_array[pm_qos_class]->target_value; | ||
201 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
202 | |||
203 | return ret_val; | ||
204 | } | 197 | } |
205 | EXPORT_SYMBOL_GPL(pm_qos_requirement); | 198 | EXPORT_SYMBOL_GPL(pm_qos_requirement); |
206 | 199 | ||
@@ -211,8 +204,8 @@ EXPORT_SYMBOL_GPL(pm_qos_requirement); | |||
211 | * @value: defines the qos request | 204 | * @value: defines the qos request |
212 | * | 205 | * |
213 | * This function inserts a new entry in the pm_qos_class list of requested qos | 206 | * This function inserts a new entry in the pm_qos_class list of requested qos |
214 | * performance charactoistics. It recomputes the agregate QoS expectations for | 207 | * performance characteristics. It recomputes the aggregate QoS expectations |
215 | * the pm_qos_class of parrameters. | 208 | * for the pm_qos_class of parameters. |
216 | */ | 209 | */ |
217 | int pm_qos_add_requirement(int pm_qos_class, char *name, s32 value) | 210 | int pm_qos_add_requirement(int pm_qos_class, char *name, s32 value) |
218 | { | 211 | { |
@@ -250,10 +243,10 @@ EXPORT_SYMBOL_GPL(pm_qos_add_requirement); | |||
250 | * @name: identifies the request | 243 | * @name: identifies the request |
251 | * @value: defines the qos request | 244 | * @value: defines the qos request |
252 | * | 245 | * |
253 | * Updates an existing qos requierement for the pm_qos_class of parameters along | 246 | * Updates an existing qos requirement for the pm_qos_class of parameters along |
254 | * with updating the target pm_qos_class value. | 247 | * with updating the target pm_qos_class value. |
255 | * | 248 | * |
256 | * If the named request isn't in the lest then no change is made. | 249 | * If the named request isn't in the list then no change is made. |
257 | */ | 250 | */ |
258 | int pm_qos_update_requirement(int pm_qos_class, char *name, s32 new_value) | 251 | int pm_qos_update_requirement(int pm_qos_class, char *name, s32 new_value) |
259 | { | 252 | { |
@@ -287,7 +280,7 @@ EXPORT_SYMBOL_GPL(pm_qos_update_requirement); | |||
287 | * @pm_qos_class: identifies which list of qos request to us | 280 | * @pm_qos_class: identifies which list of qos request to us |
288 | * @name: identifies the request | 281 | * @name: identifies the request |
289 | * | 282 | * |
290 | * Will remove named qos request from pm_qos_class list of parrameters and | 283 | * Will remove named qos request from pm_qos_class list of parameters and |
291 | * recompute the current target value for the pm_qos_class. | 284 | * recompute the current target value for the pm_qos_class. |
292 | */ | 285 | */ |
293 | void pm_qos_remove_requirement(int pm_qos_class, char *name) | 286 | void pm_qos_remove_requirement(int pm_qos_class, char *name) |
@@ -319,7 +312,7 @@ EXPORT_SYMBOL_GPL(pm_qos_remove_requirement); | |||
319 | * @notifier: notifier block managed by caller. | 312 | * @notifier: notifier block managed by caller. |
320 | * | 313 | * |
321 | * will register the notifier into a notification chain that gets called | 314 | * will register the notifier into a notification chain that gets called |
322 | * uppon changes to the pm_qos_class target value. | 315 | * upon changes to the pm_qos_class target value. |
323 | */ | 316 | */ |
324 | int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier) | 317 | int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier) |
325 | { | 318 | { |
@@ -338,7 +331,7 @@ EXPORT_SYMBOL_GPL(pm_qos_add_notifier); | |||
338 | * @notifier: notifier block to be removed. | 331 | * @notifier: notifier block to be removed. |
339 | * | 332 | * |
340 | * will remove the notifier from the notification chain that gets called | 333 | * will remove the notifier from the notification chain that gets called |
341 | * uppon changes to the pm_qos_class target value. | 334 | * upon changes to the pm_qos_class target value. |
342 | */ | 335 | */ |
343 | int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier) | 336 | int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier) |
344 | { | 337 | { |
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index 9a21681aa80f..5131e5471169 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c | |||
@@ -289,21 +289,29 @@ void do_schedule_next_timer(struct siginfo *info) | |||
289 | else | 289 | else |
290 | schedule_next_timer(timr); | 290 | schedule_next_timer(timr); |
291 | 291 | ||
292 | info->si_overrun = timr->it_overrun_last; | 292 | info->si_overrun += timr->it_overrun_last; |
293 | } | 293 | } |
294 | 294 | ||
295 | if (timr) | 295 | if (timr) |
296 | unlock_timer(timr, flags); | 296 | unlock_timer(timr, flags); |
297 | } | 297 | } |
298 | 298 | ||
299 | int posix_timer_event(struct k_itimer *timr,int si_private) | 299 | int posix_timer_event(struct k_itimer *timr, int si_private) |
300 | { | 300 | { |
301 | memset(&timr->sigq->info, 0, sizeof(siginfo_t)); | 301 | /* |
302 | * FIXME: if ->sigq is queued we can race with | ||
303 | * dequeue_signal()->do_schedule_next_timer(). | ||
304 | * | ||
305 | * If dequeue_signal() sees the "right" value of | ||
306 | * si_sys_private it calls do_schedule_next_timer(). | ||
307 | * We re-queue ->sigq and drop ->it_lock(). | ||
308 | * do_schedule_next_timer() locks the timer | ||
309 | * and re-schedules it while ->sigq is pending. | ||
310 | * Not really bad, but not that we want. | ||
311 | */ | ||
302 | timr->sigq->info.si_sys_private = si_private; | 312 | timr->sigq->info.si_sys_private = si_private; |
303 | /* Send signal to the process that owns this timer.*/ | ||
304 | 313 | ||
305 | timr->sigq->info.si_signo = timr->it_sigev_signo; | 314 | timr->sigq->info.si_signo = timr->it_sigev_signo; |
306 | timr->sigq->info.si_errno = 0; | ||
307 | timr->sigq->info.si_code = SI_TIMER; | 315 | timr->sigq->info.si_code = SI_TIMER; |
308 | timr->sigq->info.si_tid = timr->it_id; | 316 | timr->sigq->info.si_tid = timr->it_id; |
309 | timr->sigq->info.si_value = timr->it_sigev_value; | 317 | timr->sigq->info.si_value = timr->it_sigev_value; |
@@ -433,8 +441,9 @@ static struct k_itimer * alloc_posix_timer(void) | |||
433 | return tmr; | 441 | return tmr; |
434 | if (unlikely(!(tmr->sigq = sigqueue_alloc()))) { | 442 | if (unlikely(!(tmr->sigq = sigqueue_alloc()))) { |
435 | kmem_cache_free(posix_timers_cache, tmr); | 443 | kmem_cache_free(posix_timers_cache, tmr); |
436 | tmr = NULL; | 444 | return NULL; |
437 | } | 445 | } |
446 | memset(&tmr->sigq->info, 0, sizeof(siginfo_t)); | ||
438 | return tmr; | 447 | return tmr; |
439 | } | 448 | } |
440 | 449 | ||
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index f011e0870b52..bbd85c60f741 100644 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/console.h> | 21 | #include <linux/console.h> |
22 | #include <linux/cpu.h> | 22 | #include <linux/cpu.h> |
23 | #include <linux/freezer.h> | 23 | #include <linux/freezer.h> |
24 | #include <linux/ftrace.h> | ||
24 | 25 | ||
25 | #include "power.h" | 26 | #include "power.h" |
26 | 27 | ||
@@ -255,7 +256,7 @@ static int create_image(int platform_mode) | |||
255 | 256 | ||
256 | int hibernation_snapshot(int platform_mode) | 257 | int hibernation_snapshot(int platform_mode) |
257 | { | 258 | { |
258 | int error; | 259 | int error, ftrace_save; |
259 | 260 | ||
260 | /* Free memory before shutting down devices. */ | 261 | /* Free memory before shutting down devices. */ |
261 | error = swsusp_shrink_memory(); | 262 | error = swsusp_shrink_memory(); |
@@ -267,6 +268,7 @@ int hibernation_snapshot(int platform_mode) | |||
267 | goto Close; | 268 | goto Close; |
268 | 269 | ||
269 | suspend_console(); | 270 | suspend_console(); |
271 | ftrace_save = __ftrace_enabled_save(); | ||
270 | error = device_suspend(PMSG_FREEZE); | 272 | error = device_suspend(PMSG_FREEZE); |
271 | if (error) | 273 | if (error) |
272 | goto Recover_platform; | 274 | goto Recover_platform; |
@@ -296,6 +298,7 @@ int hibernation_snapshot(int platform_mode) | |||
296 | Resume_devices: | 298 | Resume_devices: |
297 | device_resume(in_suspend ? | 299 | device_resume(in_suspend ? |
298 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); | 300 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); |
301 | __ftrace_enabled_restore(ftrace_save); | ||
299 | resume_console(); | 302 | resume_console(); |
300 | Close: | 303 | Close: |
301 | platform_end(platform_mode); | 304 | platform_end(platform_mode); |
@@ -366,10 +369,11 @@ static int resume_target_kernel(void) | |||
366 | 369 | ||
367 | int hibernation_restore(int platform_mode) | 370 | int hibernation_restore(int platform_mode) |
368 | { | 371 | { |
369 | int error; | 372 | int error, ftrace_save; |
370 | 373 | ||
371 | pm_prepare_console(); | 374 | pm_prepare_console(); |
372 | suspend_console(); | 375 | suspend_console(); |
376 | ftrace_save = __ftrace_enabled_save(); | ||
373 | error = device_suspend(PMSG_QUIESCE); | 377 | error = device_suspend(PMSG_QUIESCE); |
374 | if (error) | 378 | if (error) |
375 | goto Finish; | 379 | goto Finish; |
@@ -384,6 +388,7 @@ int hibernation_restore(int platform_mode) | |||
384 | platform_restore_cleanup(platform_mode); | 388 | platform_restore_cleanup(platform_mode); |
385 | device_resume(PMSG_RECOVER); | 389 | device_resume(PMSG_RECOVER); |
386 | Finish: | 390 | Finish: |
391 | __ftrace_enabled_restore(ftrace_save); | ||
387 | resume_console(); | 392 | resume_console(); |
388 | pm_restore_console(); | 393 | pm_restore_console(); |
389 | return error; | 394 | return error; |
@@ -396,7 +401,7 @@ int hibernation_restore(int platform_mode) | |||
396 | 401 | ||
397 | int hibernation_platform_enter(void) | 402 | int hibernation_platform_enter(void) |
398 | { | 403 | { |
399 | int error; | 404 | int error, ftrace_save; |
400 | 405 | ||
401 | if (!hibernation_ops) | 406 | if (!hibernation_ops) |
402 | return -ENOSYS; | 407 | return -ENOSYS; |
@@ -411,6 +416,7 @@ int hibernation_platform_enter(void) | |||
411 | goto Close; | 416 | goto Close; |
412 | 417 | ||
413 | suspend_console(); | 418 | suspend_console(); |
419 | ftrace_save = __ftrace_enabled_save(); | ||
414 | error = device_suspend(PMSG_HIBERNATE); | 420 | error = device_suspend(PMSG_HIBERNATE); |
415 | if (error) { | 421 | if (error) { |
416 | if (hibernation_ops->recover) | 422 | if (hibernation_ops->recover) |
@@ -445,6 +451,7 @@ int hibernation_platform_enter(void) | |||
445 | hibernation_ops->finish(); | 451 | hibernation_ops->finish(); |
446 | Resume_devices: | 452 | Resume_devices: |
447 | device_resume(PMSG_RESTORE); | 453 | device_resume(PMSG_RESTORE); |
454 | __ftrace_enabled_restore(ftrace_save); | ||
448 | resume_console(); | 455 | resume_console(); |
449 | Close: | 456 | Close: |
450 | hibernation_ops->end(); | 457 | hibernation_ops->end(); |
diff --git a/kernel/power/main.c b/kernel/power/main.c index 95bff23ecdaa..540b16b68565 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/freezer.h> | 21 | #include <linux/freezer.h> |
22 | #include <linux/vmstat.h> | 22 | #include <linux/vmstat.h> |
23 | #include <linux/syscalls.h> | 23 | #include <linux/syscalls.h> |
24 | #include <linux/ftrace.h> | ||
24 | 25 | ||
25 | #include "power.h" | 26 | #include "power.h" |
26 | 27 | ||
@@ -310,7 +311,7 @@ static int suspend_enter(suspend_state_t state) | |||
310 | */ | 311 | */ |
311 | int suspend_devices_and_enter(suspend_state_t state) | 312 | int suspend_devices_and_enter(suspend_state_t state) |
312 | { | 313 | { |
313 | int error; | 314 | int error, ftrace_save; |
314 | 315 | ||
315 | if (!suspend_ops) | 316 | if (!suspend_ops) |
316 | return -ENOSYS; | 317 | return -ENOSYS; |
@@ -321,6 +322,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
321 | goto Close; | 322 | goto Close; |
322 | } | 323 | } |
323 | suspend_console(); | 324 | suspend_console(); |
325 | ftrace_save = __ftrace_enabled_save(); | ||
324 | suspend_test_start(); | 326 | suspend_test_start(); |
325 | error = device_suspend(PMSG_SUSPEND); | 327 | error = device_suspend(PMSG_SUSPEND); |
326 | if (error) { | 328 | if (error) { |
@@ -352,6 +354,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
352 | suspend_test_start(); | 354 | suspend_test_start(); |
353 | device_resume(PMSG_RESUME); | 355 | device_resume(PMSG_RESUME); |
354 | suspend_test_finish("resume devices"); | 356 | suspend_test_finish("resume devices"); |
357 | __ftrace_enabled_restore(ftrace_save); | ||
355 | resume_console(); | 358 | resume_console(); |
356 | Close: | 359 | Close: |
357 | if (suspend_ops->end) | 360 | if (suspend_ops->end) |
@@ -635,6 +638,13 @@ static void __init test_wakealarm(struct rtc_device *rtc, suspend_state_t state) | |||
635 | } | 638 | } |
636 | if (status < 0) | 639 | if (status < 0) |
637 | printk(err_suspend, status); | 640 | printk(err_suspend, status); |
641 | |||
642 | /* Some platforms can't detect that the alarm triggered the | ||
643 | * wakeup, or (accordingly) disable it after it afterwards. | ||
644 | * It's supposed to give oneshot behavior; cope. | ||
645 | */ | ||
646 | alm.enabled = false; | ||
647 | rtc_set_alarm(rtc, &alm); | ||
638 | } | 648 | } |
639 | 649 | ||
640 | static int __init has_wakealarm(struct device *dev, void *name_ptr) | 650 | static int __init has_wakealarm(struct device *dev, void *name_ptr) |
diff --git a/kernel/power/power.h b/kernel/power/power.h index 700f44ec8406..acc0c101dbd5 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h | |||
@@ -53,8 +53,6 @@ extern int hibernation_platform_enter(void); | |||
53 | 53 | ||
54 | extern int pfn_is_nosave(unsigned long); | 54 | extern int pfn_is_nosave(unsigned long); |
55 | 55 | ||
56 | extern struct mutex pm_mutex; | ||
57 | |||
58 | #define power_attr(_name) \ | 56 | #define power_attr(_name) \ |
59 | static struct kobj_attribute _name##_attr = { \ | 57 | static struct kobj_attribute _name##_attr = { \ |
60 | .attr = { \ | 58 | .attr = { \ |
diff --git a/kernel/power/swap.c b/kernel/power/swap.c index a0abf9a463f9..80ccac849e46 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/file.h> | 15 | #include <linux/file.h> |
16 | #include <linux/utsname.h> | 16 | #include <linux/utsname.h> |
17 | #include <linux/version.h> | ||
18 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
19 | #include <linux/bitops.h> | 18 | #include <linux/bitops.h> |
20 | #include <linux/genhd.h> | 19 | #include <linux/genhd.h> |
diff --git a/kernel/printk.c b/kernel/printk.c index a7f7559c5f6c..b51b1567bb55 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -1309,14 +1309,14 @@ void tty_write_message(struct tty_struct *tty, char *msg) | |||
1309 | 1309 | ||
1310 | #if defined CONFIG_PRINTK | 1310 | #if defined CONFIG_PRINTK |
1311 | 1311 | ||
1312 | DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10); | ||
1313 | /* | 1312 | /* |
1314 | * printk rate limiting, lifted from the networking subsystem. | 1313 | * printk rate limiting, lifted from the networking subsystem. |
1315 | * | 1314 | * |
1316 | * This enforces a rate limit: not more than one kernel message | 1315 | * This enforces a rate limit: not more than 10 kernel messages |
1317 | * every printk_ratelimit_jiffies to make a denial-of-service | 1316 | * every 5s to make a denial-of-service attack impossible. |
1318 | * attack impossible. | ||
1319 | */ | 1317 | */ |
1318 | DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10); | ||
1319 | |||
1320 | int printk_ratelimit(void) | 1320 | int printk_ratelimit(void) |
1321 | { | 1321 | { |
1322 | return __ratelimit(&printk_ratelimit_state); | 1322 | return __ratelimit(&printk_ratelimit_state); |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 8392a9da6450..356699a96d56 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -107,7 +107,7 @@ int ptrace_check_attach(struct task_struct *child, int kill) | |||
107 | read_unlock(&tasklist_lock); | 107 | read_unlock(&tasklist_lock); |
108 | 108 | ||
109 | if (!ret && !kill) | 109 | if (!ret && !kill) |
110 | wait_task_inactive(child); | 110 | ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH; |
111 | 111 | ||
112 | /* All systems go.. */ | 112 | /* All systems go.. */ |
113 | return ret; | 113 | return ret; |
@@ -140,7 +140,7 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode) | |||
140 | if (!dumpable && !capable(CAP_SYS_PTRACE)) | 140 | if (!dumpable && !capable(CAP_SYS_PTRACE)) |
141 | return -EPERM; | 141 | return -EPERM; |
142 | 142 | ||
143 | return security_ptrace(current, task, mode); | 143 | return security_ptrace_may_access(task, mode); |
144 | } | 144 | } |
145 | 145 | ||
146 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) | 146 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) |
@@ -499,8 +499,7 @@ repeat: | |||
499 | goto repeat; | 499 | goto repeat; |
500 | } | 500 | } |
501 | 501 | ||
502 | ret = security_ptrace(current->parent, current, | 502 | ret = security_ptrace_traceme(current->parent); |
503 | PTRACE_MODE_ATTACH); | ||
504 | 503 | ||
505 | /* | 504 | /* |
506 | * Set the ptrace bit in the process ptrace flags. | 505 | * Set the ptrace bit in the process ptrace flags. |
diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c index 6f8696c502f4..37f72e551542 100644 --- a/kernel/rcuclassic.c +++ b/kernel/rcuclassic.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/notifier.h> | 47 | #include <linux/notifier.h> |
48 | #include <linux/cpu.h> | 48 | #include <linux/cpu.h> |
49 | #include <linux/mutex.h> | 49 | #include <linux/mutex.h> |
50 | #include <linux/time.h> | ||
50 | 51 | ||
51 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 52 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
52 | static struct lock_class_key rcu_lock_key; | 53 | static struct lock_class_key rcu_lock_key; |
@@ -60,12 +61,14 @@ EXPORT_SYMBOL_GPL(rcu_lock_map); | |||
60 | static struct rcu_ctrlblk rcu_ctrlblk = { | 61 | static struct rcu_ctrlblk rcu_ctrlblk = { |
61 | .cur = -300, | 62 | .cur = -300, |
62 | .completed = -300, | 63 | .completed = -300, |
64 | .pending = -300, | ||
63 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock), | 65 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_ctrlblk.lock), |
64 | .cpumask = CPU_MASK_NONE, | 66 | .cpumask = CPU_MASK_NONE, |
65 | }; | 67 | }; |
66 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { | 68 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { |
67 | .cur = -300, | 69 | .cur = -300, |
68 | .completed = -300, | 70 | .completed = -300, |
71 | .pending = -300, | ||
69 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_bh_ctrlblk.lock), | 72 | .lock = __SPIN_LOCK_UNLOCKED(&rcu_bh_ctrlblk.lock), |
70 | .cpumask = CPU_MASK_NONE, | 73 | .cpumask = CPU_MASK_NONE, |
71 | }; | 74 | }; |
@@ -83,7 +86,10 @@ static void force_quiescent_state(struct rcu_data *rdp, | |||
83 | { | 86 | { |
84 | int cpu; | 87 | int cpu; |
85 | cpumask_t cpumask; | 88 | cpumask_t cpumask; |
89 | unsigned long flags; | ||
90 | |||
86 | set_need_resched(); | 91 | set_need_resched(); |
92 | spin_lock_irqsave(&rcp->lock, flags); | ||
87 | if (unlikely(!rcp->signaled)) { | 93 | if (unlikely(!rcp->signaled)) { |
88 | rcp->signaled = 1; | 94 | rcp->signaled = 1; |
89 | /* | 95 | /* |
@@ -91,8 +97,8 @@ static void force_quiescent_state(struct rcu_data *rdp, | |||
91 | * rdp->cpu is the current cpu. | 97 | * rdp->cpu is the current cpu. |
92 | * | 98 | * |
93 | * cpu_online_map is updated by the _cpu_down() | 99 | * cpu_online_map is updated by the _cpu_down() |
94 | * using stop_machine_run(). Since we're in irqs disabled | 100 | * using __stop_machine(). Since we're in irqs disabled |
95 | * section, stop_machine_run() is not exectuting, hence | 101 | * section, __stop_machine() is not exectuting, hence |
96 | * the cpu_online_map is stable. | 102 | * the cpu_online_map is stable. |
97 | * | 103 | * |
98 | * However, a cpu might have been offlined _just_ before | 104 | * However, a cpu might have been offlined _just_ before |
@@ -109,6 +115,7 @@ static void force_quiescent_state(struct rcu_data *rdp, | |||
109 | for_each_cpu_mask_nr(cpu, cpumask) | 115 | for_each_cpu_mask_nr(cpu, cpumask) |
110 | smp_send_reschedule(cpu); | 116 | smp_send_reschedule(cpu); |
111 | } | 117 | } |
118 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
112 | } | 119 | } |
113 | #else | 120 | #else |
114 | static inline void force_quiescent_state(struct rcu_data *rdp, | 121 | static inline void force_quiescent_state(struct rcu_data *rdp, |
@@ -118,6 +125,126 @@ static inline void force_quiescent_state(struct rcu_data *rdp, | |||
118 | } | 125 | } |
119 | #endif | 126 | #endif |
120 | 127 | ||
128 | static void __call_rcu(struct rcu_head *head, struct rcu_ctrlblk *rcp, | ||
129 | struct rcu_data *rdp) | ||
130 | { | ||
131 | long batch; | ||
132 | |||
133 | head->next = NULL; | ||
134 | smp_mb(); /* Read of rcu->cur must happen after any change by caller. */ | ||
135 | |||
136 | /* | ||
137 | * Determine the batch number of this callback. | ||
138 | * | ||
139 | * Using ACCESS_ONCE to avoid the following error when gcc eliminates | ||
140 | * local variable "batch" and emits codes like this: | ||
141 | * 1) rdp->batch = rcp->cur + 1 # gets old value | ||
142 | * ...... | ||
143 | * 2)rcu_batch_after(rcp->cur + 1, rdp->batch) # gets new value | ||
144 | * then [*nxttail[0], *nxttail[1]) may contain callbacks | ||
145 | * that batch# = rdp->batch, see the comment of struct rcu_data. | ||
146 | */ | ||
147 | batch = ACCESS_ONCE(rcp->cur) + 1; | ||
148 | |||
149 | if (rdp->nxtlist && rcu_batch_after(batch, rdp->batch)) { | ||
150 | /* process callbacks */ | ||
151 | rdp->nxttail[0] = rdp->nxttail[1]; | ||
152 | rdp->nxttail[1] = rdp->nxttail[2]; | ||
153 | if (rcu_batch_after(batch - 1, rdp->batch)) | ||
154 | rdp->nxttail[0] = rdp->nxttail[2]; | ||
155 | } | ||
156 | |||
157 | rdp->batch = batch; | ||
158 | *rdp->nxttail[2] = head; | ||
159 | rdp->nxttail[2] = &head->next; | ||
160 | |||
161 | if (unlikely(++rdp->qlen > qhimark)) { | ||
162 | rdp->blimit = INT_MAX; | ||
163 | force_quiescent_state(rdp, &rcu_ctrlblk); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
168 | |||
169 | static void record_gp_stall_check_time(struct rcu_ctrlblk *rcp) | ||
170 | { | ||
171 | rcp->gp_start = jiffies; | ||
172 | rcp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_CHECK; | ||
173 | } | ||
174 | |||
175 | static void print_other_cpu_stall(struct rcu_ctrlblk *rcp) | ||
176 | { | ||
177 | int cpu; | ||
178 | long delta; | ||
179 | unsigned long flags; | ||
180 | |||
181 | /* Only let one CPU complain about others per time interval. */ | ||
182 | |||
183 | spin_lock_irqsave(&rcp->lock, flags); | ||
184 | delta = jiffies - rcp->jiffies_stall; | ||
185 | if (delta < 2 || rcp->cur != rcp->completed) { | ||
186 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
187 | return; | ||
188 | } | ||
189 | rcp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | ||
190 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
191 | |||
192 | /* OK, time to rat on our buddy... */ | ||
193 | |||
194 | printk(KERN_ERR "RCU detected CPU stalls:"); | ||
195 | for_each_possible_cpu(cpu) { | ||
196 | if (cpu_isset(cpu, rcp->cpumask)) | ||
197 | printk(" %d", cpu); | ||
198 | } | ||
199 | printk(" (detected by %d, t=%ld jiffies)\n", | ||
200 | smp_processor_id(), (long)(jiffies - rcp->gp_start)); | ||
201 | } | ||
202 | |||
203 | static void print_cpu_stall(struct rcu_ctrlblk *rcp) | ||
204 | { | ||
205 | unsigned long flags; | ||
206 | |||
207 | printk(KERN_ERR "RCU detected CPU %d stall (t=%lu/%lu jiffies)\n", | ||
208 | smp_processor_id(), jiffies, | ||
209 | jiffies - rcp->gp_start); | ||
210 | dump_stack(); | ||
211 | spin_lock_irqsave(&rcp->lock, flags); | ||
212 | if ((long)(jiffies - rcp->jiffies_stall) >= 0) | ||
213 | rcp->jiffies_stall = | ||
214 | jiffies + RCU_SECONDS_TILL_STALL_RECHECK; | ||
215 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
216 | set_need_resched(); /* kick ourselves to get things going. */ | ||
217 | } | ||
218 | |||
219 | static void check_cpu_stall(struct rcu_ctrlblk *rcp) | ||
220 | { | ||
221 | long delta; | ||
222 | |||
223 | delta = jiffies - rcp->jiffies_stall; | ||
224 | if (cpu_isset(smp_processor_id(), rcp->cpumask) && delta >= 0) { | ||
225 | |||
226 | /* We haven't checked in, so go dump stack. */ | ||
227 | print_cpu_stall(rcp); | ||
228 | |||
229 | } else if (rcp->cur != rcp->completed && delta >= 2) { | ||
230 | |||
231 | /* They had two seconds to dump stack, so complain. */ | ||
232 | print_other_cpu_stall(rcp); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
237 | |||
238 | static void record_gp_stall_check_time(struct rcu_ctrlblk *rcp) | ||
239 | { | ||
240 | } | ||
241 | |||
242 | static inline void check_cpu_stall(struct rcu_ctrlblk *rcp) | ||
243 | { | ||
244 | } | ||
245 | |||
246 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
247 | |||
121 | /** | 248 | /** |
122 | * call_rcu - Queue an RCU callback for invocation after a grace period. | 249 | * call_rcu - Queue an RCU callback for invocation after a grace period. |
123 | * @head: structure to be used for queueing the RCU updates. | 250 | * @head: structure to be used for queueing the RCU updates. |
@@ -133,18 +260,10 @@ void call_rcu(struct rcu_head *head, | |||
133 | void (*func)(struct rcu_head *rcu)) | 260 | void (*func)(struct rcu_head *rcu)) |
134 | { | 261 | { |
135 | unsigned long flags; | 262 | unsigned long flags; |
136 | struct rcu_data *rdp; | ||
137 | 263 | ||
138 | head->func = func; | 264 | head->func = func; |
139 | head->next = NULL; | ||
140 | local_irq_save(flags); | 265 | local_irq_save(flags); |
141 | rdp = &__get_cpu_var(rcu_data); | 266 | __call_rcu(head, &rcu_ctrlblk, &__get_cpu_var(rcu_data)); |
142 | *rdp->nxttail = head; | ||
143 | rdp->nxttail = &head->next; | ||
144 | if (unlikely(++rdp->qlen > qhimark)) { | ||
145 | rdp->blimit = INT_MAX; | ||
146 | force_quiescent_state(rdp, &rcu_ctrlblk); | ||
147 | } | ||
148 | local_irq_restore(flags); | 267 | local_irq_restore(flags); |
149 | } | 268 | } |
150 | EXPORT_SYMBOL_GPL(call_rcu); | 269 | EXPORT_SYMBOL_GPL(call_rcu); |
@@ -169,20 +288,10 @@ void call_rcu_bh(struct rcu_head *head, | |||
169 | void (*func)(struct rcu_head *rcu)) | 288 | void (*func)(struct rcu_head *rcu)) |
170 | { | 289 | { |
171 | unsigned long flags; | 290 | unsigned long flags; |
172 | struct rcu_data *rdp; | ||
173 | 291 | ||
174 | head->func = func; | 292 | head->func = func; |
175 | head->next = NULL; | ||
176 | local_irq_save(flags); | 293 | local_irq_save(flags); |
177 | rdp = &__get_cpu_var(rcu_bh_data); | 294 | __call_rcu(head, &rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); |
178 | *rdp->nxttail = head; | ||
179 | rdp->nxttail = &head->next; | ||
180 | |||
181 | if (unlikely(++rdp->qlen > qhimark)) { | ||
182 | rdp->blimit = INT_MAX; | ||
183 | force_quiescent_state(rdp, &rcu_bh_ctrlblk); | ||
184 | } | ||
185 | |||
186 | local_irq_restore(flags); | 295 | local_irq_restore(flags); |
187 | } | 296 | } |
188 | EXPORT_SYMBOL_GPL(call_rcu_bh); | 297 | EXPORT_SYMBOL_GPL(call_rcu_bh); |
@@ -211,12 +320,6 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed_bh); | |||
211 | static inline void raise_rcu_softirq(void) | 320 | static inline void raise_rcu_softirq(void) |
212 | { | 321 | { |
213 | raise_softirq(RCU_SOFTIRQ); | 322 | raise_softirq(RCU_SOFTIRQ); |
214 | /* | ||
215 | * The smp_mb() here is required to ensure that this cpu's | ||
216 | * __rcu_process_callbacks() reads the most recently updated | ||
217 | * value of rcu->cur. | ||
218 | */ | ||
219 | smp_mb(); | ||
220 | } | 323 | } |
221 | 324 | ||
222 | /* | 325 | /* |
@@ -225,6 +328,7 @@ static inline void raise_rcu_softirq(void) | |||
225 | */ | 328 | */ |
226 | static void rcu_do_batch(struct rcu_data *rdp) | 329 | static void rcu_do_batch(struct rcu_data *rdp) |
227 | { | 330 | { |
331 | unsigned long flags; | ||
228 | struct rcu_head *next, *list; | 332 | struct rcu_head *next, *list; |
229 | int count = 0; | 333 | int count = 0; |
230 | 334 | ||
@@ -239,9 +343,9 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
239 | } | 343 | } |
240 | rdp->donelist = list; | 344 | rdp->donelist = list; |
241 | 345 | ||
242 | local_irq_disable(); | 346 | local_irq_save(flags); |
243 | rdp->qlen -= count; | 347 | rdp->qlen -= count; |
244 | local_irq_enable(); | 348 | local_irq_restore(flags); |
245 | if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark) | 349 | if (rdp->blimit == INT_MAX && rdp->qlen <= qlowmark) |
246 | rdp->blimit = blimit; | 350 | rdp->blimit = blimit; |
247 | 351 | ||
@@ -269,6 +373,7 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
269 | * rcu_check_quiescent_state calls rcu_start_batch(0) to start the next grace | 373 | * rcu_check_quiescent_state calls rcu_start_batch(0) to start the next grace |
270 | * period (if necessary). | 374 | * period (if necessary). |
271 | */ | 375 | */ |
376 | |||
272 | /* | 377 | /* |
273 | * Register a new batch of callbacks, and start it up if there is currently no | 378 | * Register a new batch of callbacks, and start it up if there is currently no |
274 | * active batch and the batch to be registered has not already occurred. | 379 | * active batch and the batch to be registered has not already occurred. |
@@ -276,15 +381,10 @@ static void rcu_do_batch(struct rcu_data *rdp) | |||
276 | */ | 381 | */ |
277 | static void rcu_start_batch(struct rcu_ctrlblk *rcp) | 382 | static void rcu_start_batch(struct rcu_ctrlblk *rcp) |
278 | { | 383 | { |
279 | if (rcp->next_pending && | 384 | if (rcp->cur != rcp->pending && |
280 | rcp->completed == rcp->cur) { | 385 | rcp->completed == rcp->cur) { |
281 | rcp->next_pending = 0; | ||
282 | /* | ||
283 | * next_pending == 0 must be visible in | ||
284 | * __rcu_process_callbacks() before it can see new value of cur. | ||
285 | */ | ||
286 | smp_wmb(); | ||
287 | rcp->cur++; | 386 | rcp->cur++; |
387 | record_gp_stall_check_time(rcp); | ||
288 | 388 | ||
289 | /* | 389 | /* |
290 | * Accessing nohz_cpu_mask before incrementing rcp->cur needs a | 390 | * Accessing nohz_cpu_mask before incrementing rcp->cur needs a |
@@ -322,6 +422,8 @@ static void cpu_quiet(int cpu, struct rcu_ctrlblk *rcp) | |||
322 | static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, | 422 | static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, |
323 | struct rcu_data *rdp) | 423 | struct rcu_data *rdp) |
324 | { | 424 | { |
425 | unsigned long flags; | ||
426 | |||
325 | if (rdp->quiescbatch != rcp->cur) { | 427 | if (rdp->quiescbatch != rcp->cur) { |
326 | /* start new grace period: */ | 428 | /* start new grace period: */ |
327 | rdp->qs_pending = 1; | 429 | rdp->qs_pending = 1; |
@@ -345,7 +447,7 @@ static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, | |||
345 | return; | 447 | return; |
346 | rdp->qs_pending = 0; | 448 | rdp->qs_pending = 0; |
347 | 449 | ||
348 | spin_lock(&rcp->lock); | 450 | spin_lock_irqsave(&rcp->lock, flags); |
349 | /* | 451 | /* |
350 | * rdp->quiescbatch/rcp->cur and the cpu bitmap can come out of sync | 452 | * rdp->quiescbatch/rcp->cur and the cpu bitmap can come out of sync |
351 | * during cpu startup. Ignore the quiescent state. | 453 | * during cpu startup. Ignore the quiescent state. |
@@ -353,7 +455,7 @@ static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, | |||
353 | if (likely(rdp->quiescbatch == rcp->cur)) | 455 | if (likely(rdp->quiescbatch == rcp->cur)) |
354 | cpu_quiet(rdp->cpu, rcp); | 456 | cpu_quiet(rdp->cpu, rcp); |
355 | 457 | ||
356 | spin_unlock(&rcp->lock); | 458 | spin_unlock_irqrestore(&rcp->lock, flags); |
357 | } | 459 | } |
358 | 460 | ||
359 | 461 | ||
@@ -364,33 +466,38 @@ static void rcu_check_quiescent_state(struct rcu_ctrlblk *rcp, | |||
364 | * which is dead and hence not processing interrupts. | 466 | * which is dead and hence not processing interrupts. |
365 | */ | 467 | */ |
366 | static void rcu_move_batch(struct rcu_data *this_rdp, struct rcu_head *list, | 468 | static void rcu_move_batch(struct rcu_data *this_rdp, struct rcu_head *list, |
367 | struct rcu_head **tail) | 469 | struct rcu_head **tail, long batch) |
368 | { | 470 | { |
369 | local_irq_disable(); | 471 | unsigned long flags; |
370 | *this_rdp->nxttail = list; | 472 | |
371 | if (list) | 473 | if (list) { |
372 | this_rdp->nxttail = tail; | 474 | local_irq_save(flags); |
373 | local_irq_enable(); | 475 | this_rdp->batch = batch; |
476 | *this_rdp->nxttail[2] = list; | ||
477 | this_rdp->nxttail[2] = tail; | ||
478 | local_irq_restore(flags); | ||
479 | } | ||
374 | } | 480 | } |
375 | 481 | ||
376 | static void __rcu_offline_cpu(struct rcu_data *this_rdp, | 482 | static void __rcu_offline_cpu(struct rcu_data *this_rdp, |
377 | struct rcu_ctrlblk *rcp, struct rcu_data *rdp) | 483 | struct rcu_ctrlblk *rcp, struct rcu_data *rdp) |
378 | { | 484 | { |
379 | /* if the cpu going offline owns the grace period | 485 | unsigned long flags; |
486 | |||
487 | /* | ||
488 | * if the cpu going offline owns the grace period | ||
380 | * we can block indefinitely waiting for it, so flush | 489 | * we can block indefinitely waiting for it, so flush |
381 | * it here | 490 | * it here |
382 | */ | 491 | */ |
383 | spin_lock_bh(&rcp->lock); | 492 | spin_lock_irqsave(&rcp->lock, flags); |
384 | if (rcp->cur != rcp->completed) | 493 | if (rcp->cur != rcp->completed) |
385 | cpu_quiet(rdp->cpu, rcp); | 494 | cpu_quiet(rdp->cpu, rcp); |
386 | spin_unlock_bh(&rcp->lock); | 495 | rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail, rcp->cur + 1); |
387 | rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail); | 496 | rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail[2], rcp->cur + 1); |
388 | rcu_move_batch(this_rdp, rdp->curlist, rdp->curtail); | 497 | spin_unlock(&rcp->lock); |
389 | rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail); | ||
390 | 498 | ||
391 | local_irq_disable(); | ||
392 | this_rdp->qlen += rdp->qlen; | 499 | this_rdp->qlen += rdp->qlen; |
393 | local_irq_enable(); | 500 | local_irq_restore(flags); |
394 | } | 501 | } |
395 | 502 | ||
396 | static void rcu_offline_cpu(int cpu) | 503 | static void rcu_offline_cpu(int cpu) |
@@ -420,38 +527,52 @@ static void rcu_offline_cpu(int cpu) | |||
420 | static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp, | 527 | static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp, |
421 | struct rcu_data *rdp) | 528 | struct rcu_data *rdp) |
422 | { | 529 | { |
423 | if (rdp->curlist && !rcu_batch_before(rcp->completed, rdp->batch)) { | 530 | unsigned long flags; |
424 | *rdp->donetail = rdp->curlist; | 531 | long completed_snap; |
425 | rdp->donetail = rdp->curtail; | ||
426 | rdp->curlist = NULL; | ||
427 | rdp->curtail = &rdp->curlist; | ||
428 | } | ||
429 | 532 | ||
430 | if (rdp->nxtlist && !rdp->curlist) { | 533 | if (rdp->nxtlist) { |
431 | local_irq_disable(); | 534 | local_irq_save(flags); |
432 | rdp->curlist = rdp->nxtlist; | 535 | completed_snap = ACCESS_ONCE(rcp->completed); |
433 | rdp->curtail = rdp->nxttail; | ||
434 | rdp->nxtlist = NULL; | ||
435 | rdp->nxttail = &rdp->nxtlist; | ||
436 | local_irq_enable(); | ||
437 | 536 | ||
438 | /* | 537 | /* |
439 | * start the next batch of callbacks | 538 | * move the other grace-period-completed entries to |
539 | * [rdp->nxtlist, *rdp->nxttail[0]) temporarily | ||
440 | */ | 540 | */ |
541 | if (!rcu_batch_before(completed_snap, rdp->batch)) | ||
542 | rdp->nxttail[0] = rdp->nxttail[1] = rdp->nxttail[2]; | ||
543 | else if (!rcu_batch_before(completed_snap, rdp->batch - 1)) | ||
544 | rdp->nxttail[0] = rdp->nxttail[1]; | ||
441 | 545 | ||
442 | /* determine batch number */ | 546 | /* |
443 | rdp->batch = rcp->cur + 1; | 547 | * the grace period for entries in |
444 | /* see the comment and corresponding wmb() in | 548 | * [rdp->nxtlist, *rdp->nxttail[0]) has completed and |
445 | * the rcu_start_batch() | 549 | * move these entries to donelist |
446 | */ | 550 | */ |
447 | smp_rmb(); | 551 | if (rdp->nxttail[0] != &rdp->nxtlist) { |
552 | *rdp->donetail = rdp->nxtlist; | ||
553 | rdp->donetail = rdp->nxttail[0]; | ||
554 | rdp->nxtlist = *rdp->nxttail[0]; | ||
555 | *rdp->donetail = NULL; | ||
556 | |||
557 | if (rdp->nxttail[1] == rdp->nxttail[0]) | ||
558 | rdp->nxttail[1] = &rdp->nxtlist; | ||
559 | if (rdp->nxttail[2] == rdp->nxttail[0]) | ||
560 | rdp->nxttail[2] = &rdp->nxtlist; | ||
561 | rdp->nxttail[0] = &rdp->nxtlist; | ||
562 | } | ||
563 | |||
564 | local_irq_restore(flags); | ||
565 | |||
566 | if (rcu_batch_after(rdp->batch, rcp->pending)) { | ||
567 | unsigned long flags2; | ||
448 | 568 | ||
449 | if (!rcp->next_pending) { | ||
450 | /* and start it/schedule start if it's a new batch */ | 569 | /* and start it/schedule start if it's a new batch */ |
451 | spin_lock(&rcp->lock); | 570 | spin_lock_irqsave(&rcp->lock, flags2); |
452 | rcp->next_pending = 1; | 571 | if (rcu_batch_after(rdp->batch, rcp->pending)) { |
453 | rcu_start_batch(rcp); | 572 | rcp->pending = rdp->batch; |
454 | spin_unlock(&rcp->lock); | 573 | rcu_start_batch(rcp); |
574 | } | ||
575 | spin_unlock_irqrestore(&rcp->lock, flags2); | ||
455 | } | 576 | } |
456 | } | 577 | } |
457 | 578 | ||
@@ -462,21 +583,53 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp, | |||
462 | 583 | ||
463 | static void rcu_process_callbacks(struct softirq_action *unused) | 584 | static void rcu_process_callbacks(struct softirq_action *unused) |
464 | { | 585 | { |
586 | /* | ||
587 | * Memory references from any prior RCU read-side critical sections | ||
588 | * executed by the interrupted code must be see before any RCU | ||
589 | * grace-period manupulations below. | ||
590 | */ | ||
591 | |||
592 | smp_mb(); /* See above block comment. */ | ||
593 | |||
465 | __rcu_process_callbacks(&rcu_ctrlblk, &__get_cpu_var(rcu_data)); | 594 | __rcu_process_callbacks(&rcu_ctrlblk, &__get_cpu_var(rcu_data)); |
466 | __rcu_process_callbacks(&rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); | 595 | __rcu_process_callbacks(&rcu_bh_ctrlblk, &__get_cpu_var(rcu_bh_data)); |
596 | |||
597 | /* | ||
598 | * Memory references from any later RCU read-side critical sections | ||
599 | * executed by the interrupted code must be see after any RCU | ||
600 | * grace-period manupulations above. | ||
601 | */ | ||
602 | |||
603 | smp_mb(); /* See above block comment. */ | ||
467 | } | 604 | } |
468 | 605 | ||
469 | static int __rcu_pending(struct rcu_ctrlblk *rcp, struct rcu_data *rdp) | 606 | static int __rcu_pending(struct rcu_ctrlblk *rcp, struct rcu_data *rdp) |
470 | { | 607 | { |
471 | /* This cpu has pending rcu entries and the grace period | 608 | /* Check for CPU stalls, if enabled. */ |
472 | * for them has completed. | 609 | check_cpu_stall(rcp); |
473 | */ | ||
474 | if (rdp->curlist && !rcu_batch_before(rcp->completed, rdp->batch)) | ||
475 | return 1; | ||
476 | 610 | ||
477 | /* This cpu has no pending entries, but there are new entries */ | 611 | if (rdp->nxtlist) { |
478 | if (!rdp->curlist && rdp->nxtlist) | 612 | long completed_snap = ACCESS_ONCE(rcp->completed); |
479 | return 1; | 613 | |
614 | /* | ||
615 | * This cpu has pending rcu entries and the grace period | ||
616 | * for them has completed. | ||
617 | */ | ||
618 | if (!rcu_batch_before(completed_snap, rdp->batch)) | ||
619 | return 1; | ||
620 | if (!rcu_batch_before(completed_snap, rdp->batch - 1) && | ||
621 | rdp->nxttail[0] != rdp->nxttail[1]) | ||
622 | return 1; | ||
623 | if (rdp->nxttail[0] != &rdp->nxtlist) | ||
624 | return 1; | ||
625 | |||
626 | /* | ||
627 | * This cpu has pending rcu entries and the new batch | ||
628 | * for then hasn't been started nor scheduled start | ||
629 | */ | ||
630 | if (rcu_batch_after(rdp->batch, rcp->pending)) | ||
631 | return 1; | ||
632 | } | ||
480 | 633 | ||
481 | /* This cpu has finished callbacks to invoke */ | 634 | /* This cpu has finished callbacks to invoke */ |
482 | if (rdp->donelist) | 635 | if (rdp->donelist) |
@@ -512,9 +665,15 @@ int rcu_needs_cpu(int cpu) | |||
512 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); | 665 | struct rcu_data *rdp = &per_cpu(rcu_data, cpu); |
513 | struct rcu_data *rdp_bh = &per_cpu(rcu_bh_data, cpu); | 666 | struct rcu_data *rdp_bh = &per_cpu(rcu_bh_data, cpu); |
514 | 667 | ||
515 | return (!!rdp->curlist || !!rdp_bh->curlist || rcu_pending(cpu)); | 668 | return !!rdp->nxtlist || !!rdp_bh->nxtlist || rcu_pending(cpu); |
516 | } | 669 | } |
517 | 670 | ||
671 | /* | ||
672 | * Top-level function driving RCU grace-period detection, normally | ||
673 | * invoked from the scheduler-clock interrupt. This function simply | ||
674 | * increments counters that are read only from softirq by this same | ||
675 | * CPU, so there are no memory barriers required. | ||
676 | */ | ||
518 | void rcu_check_callbacks(int cpu, int user) | 677 | void rcu_check_callbacks(int cpu, int user) |
519 | { | 678 | { |
520 | if (user || | 679 | if (user || |
@@ -558,14 +717,17 @@ void rcu_check_callbacks(int cpu, int user) | |||
558 | static void rcu_init_percpu_data(int cpu, struct rcu_ctrlblk *rcp, | 717 | static void rcu_init_percpu_data(int cpu, struct rcu_ctrlblk *rcp, |
559 | struct rcu_data *rdp) | 718 | struct rcu_data *rdp) |
560 | { | 719 | { |
720 | unsigned long flags; | ||
721 | |||
722 | spin_lock_irqsave(&rcp->lock, flags); | ||
561 | memset(rdp, 0, sizeof(*rdp)); | 723 | memset(rdp, 0, sizeof(*rdp)); |
562 | rdp->curtail = &rdp->curlist; | 724 | rdp->nxttail[0] = rdp->nxttail[1] = rdp->nxttail[2] = &rdp->nxtlist; |
563 | rdp->nxttail = &rdp->nxtlist; | ||
564 | rdp->donetail = &rdp->donelist; | 725 | rdp->donetail = &rdp->donelist; |
565 | rdp->quiescbatch = rcp->completed; | 726 | rdp->quiescbatch = rcp->completed; |
566 | rdp->qs_pending = 0; | 727 | rdp->qs_pending = 0; |
567 | rdp->cpu = cpu; | 728 | rdp->cpu = cpu; |
568 | rdp->blimit = blimit; | 729 | rdp->blimit = blimit; |
730 | spin_unlock_irqrestore(&rcp->lock, flags); | ||
569 | } | 731 | } |
570 | 732 | ||
571 | static void __cpuinit rcu_online_cpu(int cpu) | 733 | static void __cpuinit rcu_online_cpu(int cpu) |
@@ -610,6 +772,9 @@ static struct notifier_block __cpuinitdata rcu_nb = { | |||
610 | */ | 772 | */ |
611 | void __init __rcu_init(void) | 773 | void __init __rcu_init(void) |
612 | { | 774 | { |
775 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
776 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | ||
777 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
613 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, | 778 | rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, |
614 | (void *)(long)smp_processor_id()); | 779 | (void *)(long)smp_processor_id()); |
615 | /* Register notifier for non-boot CPUs */ | 780 | /* Register notifier for non-boot CPUs */ |
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index f14f372cf6f5..467d5940f624 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
@@ -77,6 +77,7 @@ void wakeme_after_rcu(struct rcu_head *head) | |||
77 | * sections are delimited by rcu_read_lock() and rcu_read_unlock(), | 77 | * sections are delimited by rcu_read_lock() and rcu_read_unlock(), |
78 | * and may be nested. | 78 | * and may be nested. |
79 | */ | 79 | */ |
80 | void synchronize_rcu(void); /* Makes kernel-doc tools happy */ | ||
80 | synchronize_rcu_xxx(synchronize_rcu, call_rcu) | 81 | synchronize_rcu_xxx(synchronize_rcu, call_rcu) |
81 | EXPORT_SYMBOL_GPL(synchronize_rcu); | 82 | EXPORT_SYMBOL_GPL(synchronize_rcu); |
82 | 83 | ||
diff --git a/kernel/rcupreempt.c b/kernel/rcupreempt.c index 27827931ca0d..ca4bbbe04aa4 100644 --- a/kernel/rcupreempt.c +++ b/kernel/rcupreempt.c | |||
@@ -59,14 +59,6 @@ | |||
59 | #include <linux/rcupreempt_trace.h> | 59 | #include <linux/rcupreempt_trace.h> |
60 | 60 | ||
61 | /* | 61 | /* |
62 | * Macro that prevents the compiler from reordering accesses, but does | ||
63 | * absolutely -nothing- to prevent CPUs from reordering. This is used | ||
64 | * only to mediate communication between mainline code and hardware | ||
65 | * interrupt and NMI handlers. | ||
66 | */ | ||
67 | #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) | ||
68 | |||
69 | /* | ||
70 | * PREEMPT_RCU data structures. | 62 | * PREEMPT_RCU data structures. |
71 | */ | 63 | */ |
72 | 64 | ||
diff --git a/kernel/rcupreempt_trace.c b/kernel/rcupreempt_trace.c index 5edf82c34bbc..35c2d3360ecf 100644 --- a/kernel/rcupreempt_trace.c +++ b/kernel/rcupreempt_trace.c | |||
@@ -308,11 +308,16 @@ out: | |||
308 | 308 | ||
309 | static int __init rcupreempt_trace_init(void) | 309 | static int __init rcupreempt_trace_init(void) |
310 | { | 310 | { |
311 | int ret; | ||
312 | |||
311 | mutex_init(&rcupreempt_trace_mutex); | 313 | mutex_init(&rcupreempt_trace_mutex); |
312 | rcupreempt_trace_buf = kmalloc(RCUPREEMPT_TRACE_BUF_SIZE, GFP_KERNEL); | 314 | rcupreempt_trace_buf = kmalloc(RCUPREEMPT_TRACE_BUF_SIZE, GFP_KERNEL); |
313 | if (!rcupreempt_trace_buf) | 315 | if (!rcupreempt_trace_buf) |
314 | return 1; | 316 | return 1; |
315 | return rcupreempt_debugfs_init(); | 317 | ret = rcupreempt_debugfs_init(); |
318 | if (ret) | ||
319 | kfree(rcupreempt_trace_buf); | ||
320 | return ret; | ||
316 | } | 321 | } |
317 | 322 | ||
318 | static void __exit rcupreempt_trace_cleanup(void) | 323 | static void __exit rcupreempt_trace_cleanup(void) |
diff --git a/kernel/relay.c b/kernel/relay.c index 7de644cdec43..8d13a7855c08 100644 --- a/kernel/relay.c +++ b/kernel/relay.c | |||
@@ -407,6 +407,35 @@ void relay_reset(struct rchan *chan) | |||
407 | } | 407 | } |
408 | EXPORT_SYMBOL_GPL(relay_reset); | 408 | EXPORT_SYMBOL_GPL(relay_reset); |
409 | 409 | ||
410 | static inline void relay_set_buf_dentry(struct rchan_buf *buf, | ||
411 | struct dentry *dentry) | ||
412 | { | ||
413 | buf->dentry = dentry; | ||
414 | buf->dentry->d_inode->i_size = buf->early_bytes; | ||
415 | } | ||
416 | |||
417 | static struct dentry *relay_create_buf_file(struct rchan *chan, | ||
418 | struct rchan_buf *buf, | ||
419 | unsigned int cpu) | ||
420 | { | ||
421 | struct dentry *dentry; | ||
422 | char *tmpname; | ||
423 | |||
424 | tmpname = kzalloc(NAME_MAX + 1, GFP_KERNEL); | ||
425 | if (!tmpname) | ||
426 | return NULL; | ||
427 | snprintf(tmpname, NAME_MAX, "%s%d", chan->base_filename, cpu); | ||
428 | |||
429 | /* Create file in fs */ | ||
430 | dentry = chan->cb->create_buf_file(tmpname, chan->parent, | ||
431 | S_IRUSR, buf, | ||
432 | &chan->is_global); | ||
433 | |||
434 | kfree(tmpname); | ||
435 | |||
436 | return dentry; | ||
437 | } | ||
438 | |||
410 | /* | 439 | /* |
411 | * relay_open_buf - create a new relay channel buffer | 440 | * relay_open_buf - create a new relay channel buffer |
412 | * | 441 | * |
@@ -416,45 +445,34 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu) | |||
416 | { | 445 | { |
417 | struct rchan_buf *buf = NULL; | 446 | struct rchan_buf *buf = NULL; |
418 | struct dentry *dentry; | 447 | struct dentry *dentry; |
419 | char *tmpname; | ||
420 | 448 | ||
421 | if (chan->is_global) | 449 | if (chan->is_global) |
422 | return chan->buf[0]; | 450 | return chan->buf[0]; |
423 | 451 | ||
424 | tmpname = kzalloc(NAME_MAX + 1, GFP_KERNEL); | ||
425 | if (!tmpname) | ||
426 | goto end; | ||
427 | snprintf(tmpname, NAME_MAX, "%s%d", chan->base_filename, cpu); | ||
428 | |||
429 | buf = relay_create_buf(chan); | 452 | buf = relay_create_buf(chan); |
430 | if (!buf) | 453 | if (!buf) |
431 | goto free_name; | 454 | return NULL; |
455 | |||
456 | if (chan->has_base_filename) { | ||
457 | dentry = relay_create_buf_file(chan, buf, cpu); | ||
458 | if (!dentry) | ||
459 | goto free_buf; | ||
460 | relay_set_buf_dentry(buf, dentry); | ||
461 | } | ||
432 | 462 | ||
433 | buf->cpu = cpu; | 463 | buf->cpu = cpu; |
434 | __relay_reset(buf, 1); | 464 | __relay_reset(buf, 1); |
435 | 465 | ||
436 | /* Create file in fs */ | ||
437 | dentry = chan->cb->create_buf_file(tmpname, chan->parent, S_IRUSR, | ||
438 | buf, &chan->is_global); | ||
439 | if (!dentry) | ||
440 | goto free_buf; | ||
441 | |||
442 | buf->dentry = dentry; | ||
443 | |||
444 | if(chan->is_global) { | 466 | if(chan->is_global) { |
445 | chan->buf[0] = buf; | 467 | chan->buf[0] = buf; |
446 | buf->cpu = 0; | 468 | buf->cpu = 0; |
447 | } | 469 | } |
448 | 470 | ||
449 | goto free_name; | 471 | return buf; |
450 | 472 | ||
451 | free_buf: | 473 | free_buf: |
452 | relay_destroy_buf(buf); | 474 | relay_destroy_buf(buf); |
453 | buf = NULL; | 475 | return NULL; |
454 | free_name: | ||
455 | kfree(tmpname); | ||
456 | end: | ||
457 | return buf; | ||
458 | } | 476 | } |
459 | 477 | ||
460 | /** | 478 | /** |
@@ -537,8 +555,8 @@ static int __cpuinit relay_hotcpu_callback(struct notifier_block *nb, | |||
537 | 555 | ||
538 | /** | 556 | /** |
539 | * relay_open - create a new relay channel | 557 | * relay_open - create a new relay channel |
540 | * @base_filename: base name of files to create | 558 | * @base_filename: base name of files to create, %NULL for buffering only |
541 | * @parent: dentry of parent directory, %NULL for root directory | 559 | * @parent: dentry of parent directory, %NULL for root directory or buffer |
542 | * @subbuf_size: size of sub-buffers | 560 | * @subbuf_size: size of sub-buffers |
543 | * @n_subbufs: number of sub-buffers | 561 | * @n_subbufs: number of sub-buffers |
544 | * @cb: client callback functions | 562 | * @cb: client callback functions |
@@ -560,8 +578,6 @@ struct rchan *relay_open(const char *base_filename, | |||
560 | { | 578 | { |
561 | unsigned int i; | 579 | unsigned int i; |
562 | struct rchan *chan; | 580 | struct rchan *chan; |
563 | if (!base_filename) | ||
564 | return NULL; | ||
565 | 581 | ||
566 | if (!(subbuf_size && n_subbufs)) | 582 | if (!(subbuf_size && n_subbufs)) |
567 | return NULL; | 583 | return NULL; |
@@ -576,7 +592,10 @@ struct rchan *relay_open(const char *base_filename, | |||
576 | chan->alloc_size = FIX_SIZE(subbuf_size * n_subbufs); | 592 | chan->alloc_size = FIX_SIZE(subbuf_size * n_subbufs); |
577 | chan->parent = parent; | 593 | chan->parent = parent; |
578 | chan->private_data = private_data; | 594 | chan->private_data = private_data; |
579 | strlcpy(chan->base_filename, base_filename, NAME_MAX); | 595 | if (base_filename) { |
596 | chan->has_base_filename = 1; | ||
597 | strlcpy(chan->base_filename, base_filename, NAME_MAX); | ||
598 | } | ||
580 | setup_callbacks(chan, cb); | 599 | setup_callbacks(chan, cb); |
581 | kref_init(&chan->kref); | 600 | kref_init(&chan->kref); |
582 | 601 | ||
@@ -604,6 +623,94 @@ free_bufs: | |||
604 | } | 623 | } |
605 | EXPORT_SYMBOL_GPL(relay_open); | 624 | EXPORT_SYMBOL_GPL(relay_open); |
606 | 625 | ||
626 | struct rchan_percpu_buf_dispatcher { | ||
627 | struct rchan_buf *buf; | ||
628 | struct dentry *dentry; | ||
629 | }; | ||
630 | |||
631 | /* Called in atomic context. */ | ||
632 | static void __relay_set_buf_dentry(void *info) | ||
633 | { | ||
634 | struct rchan_percpu_buf_dispatcher *p = info; | ||
635 | |||
636 | relay_set_buf_dentry(p->buf, p->dentry); | ||
637 | } | ||
638 | |||
639 | /** | ||
640 | * relay_late_setup_files - triggers file creation | ||
641 | * @chan: channel to operate on | ||
642 | * @base_filename: base name of files to create | ||
643 | * @parent: dentry of parent directory, %NULL for root directory | ||
644 | * | ||
645 | * Returns 0 if successful, non-zero otherwise. | ||
646 | * | ||
647 | * Use to setup files for a previously buffer-only channel. | ||
648 | * Useful to do early tracing in kernel, before VFS is up, for example. | ||
649 | */ | ||
650 | int relay_late_setup_files(struct rchan *chan, | ||
651 | const char *base_filename, | ||
652 | struct dentry *parent) | ||
653 | { | ||
654 | int err = 0; | ||
655 | unsigned int i, curr_cpu; | ||
656 | unsigned long flags; | ||
657 | struct dentry *dentry; | ||
658 | struct rchan_percpu_buf_dispatcher disp; | ||
659 | |||
660 | if (!chan || !base_filename) | ||
661 | return -EINVAL; | ||
662 | |||
663 | strlcpy(chan->base_filename, base_filename, NAME_MAX); | ||
664 | |||
665 | mutex_lock(&relay_channels_mutex); | ||
666 | /* Is chan already set up? */ | ||
667 | if (unlikely(chan->has_base_filename)) | ||
668 | return -EEXIST; | ||
669 | chan->has_base_filename = 1; | ||
670 | chan->parent = parent; | ||
671 | curr_cpu = get_cpu(); | ||
672 | /* | ||
673 | * The CPU hotplug notifier ran before us and created buffers with | ||
674 | * no files associated. So it's safe to call relay_setup_buf_file() | ||
675 | * on all currently online CPUs. | ||
676 | */ | ||
677 | for_each_online_cpu(i) { | ||
678 | if (unlikely(!chan->buf[i])) { | ||
679 | printk(KERN_ERR "relay_late_setup_files: CPU %u " | ||
680 | "has no buffer, it must have!\n", i); | ||
681 | BUG(); | ||
682 | err = -EINVAL; | ||
683 | break; | ||
684 | } | ||
685 | |||
686 | dentry = relay_create_buf_file(chan, chan->buf[i], i); | ||
687 | if (unlikely(!dentry)) { | ||
688 | err = -EINVAL; | ||
689 | break; | ||
690 | } | ||
691 | |||
692 | if (curr_cpu == i) { | ||
693 | local_irq_save(flags); | ||
694 | relay_set_buf_dentry(chan->buf[i], dentry); | ||
695 | local_irq_restore(flags); | ||
696 | } else { | ||
697 | disp.buf = chan->buf[i]; | ||
698 | disp.dentry = dentry; | ||
699 | smp_mb(); | ||
700 | /* relay_channels_mutex must be held, so wait. */ | ||
701 | err = smp_call_function_single(i, | ||
702 | __relay_set_buf_dentry, | ||
703 | &disp, 1); | ||
704 | } | ||
705 | if (unlikely(err)) | ||
706 | break; | ||
707 | } | ||
708 | put_cpu(); | ||
709 | mutex_unlock(&relay_channels_mutex); | ||
710 | |||
711 | return err; | ||
712 | } | ||
713 | |||
607 | /** | 714 | /** |
608 | * relay_switch_subbuf - switch to a new sub-buffer | 715 | * relay_switch_subbuf - switch to a new sub-buffer |
609 | * @buf: channel buffer | 716 | * @buf: channel buffer |
@@ -627,8 +734,13 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length) | |||
627 | old_subbuf = buf->subbufs_produced % buf->chan->n_subbufs; | 734 | old_subbuf = buf->subbufs_produced % buf->chan->n_subbufs; |
628 | buf->padding[old_subbuf] = buf->prev_padding; | 735 | buf->padding[old_subbuf] = buf->prev_padding; |
629 | buf->subbufs_produced++; | 736 | buf->subbufs_produced++; |
630 | buf->dentry->d_inode->i_size += buf->chan->subbuf_size - | 737 | if (buf->dentry) |
631 | buf->padding[old_subbuf]; | 738 | buf->dentry->d_inode->i_size += |
739 | buf->chan->subbuf_size - | ||
740 | buf->padding[old_subbuf]; | ||
741 | else | ||
742 | buf->early_bytes += buf->chan->subbuf_size - | ||
743 | buf->padding[old_subbuf]; | ||
632 | smp_mb(); | 744 | smp_mb(); |
633 | if (waitqueue_active(&buf->read_wait)) | 745 | if (waitqueue_active(&buf->read_wait)) |
634 | /* | 746 | /* |
@@ -832,6 +944,10 @@ static void relay_file_read_consume(struct rchan_buf *buf, | |||
832 | size_t n_subbufs = buf->chan->n_subbufs; | 944 | size_t n_subbufs = buf->chan->n_subbufs; |
833 | size_t read_subbuf; | 945 | size_t read_subbuf; |
834 | 946 | ||
947 | if (buf->subbufs_produced == buf->subbufs_consumed && | ||
948 | buf->offset == buf->bytes_consumed) | ||
949 | return; | ||
950 | |||
835 | if (buf->bytes_consumed + bytes_consumed > subbuf_size) { | 951 | if (buf->bytes_consumed + bytes_consumed > subbuf_size) { |
836 | relay_subbufs_consumed(buf->chan, buf->cpu, 1); | 952 | relay_subbufs_consumed(buf->chan, buf->cpu, 1); |
837 | buf->bytes_consumed = 0; | 953 | buf->bytes_consumed = 0; |
@@ -863,6 +979,8 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos) | |||
863 | 979 | ||
864 | relay_file_read_consume(buf, read_pos, 0); | 980 | relay_file_read_consume(buf, read_pos, 0); |
865 | 981 | ||
982 | consumed = buf->subbufs_consumed; | ||
983 | |||
866 | if (unlikely(buf->offset > subbuf_size)) { | 984 | if (unlikely(buf->offset > subbuf_size)) { |
867 | if (produced == consumed) | 985 | if (produced == consumed) |
868 | return 0; | 986 | return 0; |
@@ -881,8 +999,12 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos) | |||
881 | if (consumed > produced) | 999 | if (consumed > produced) |
882 | produced += n_subbufs * subbuf_size; | 1000 | produced += n_subbufs * subbuf_size; |
883 | 1001 | ||
884 | if (consumed == produced) | 1002 | if (consumed == produced) { |
1003 | if (buf->offset == subbuf_size && | ||
1004 | buf->subbufs_produced > buf->subbufs_consumed) | ||
1005 | return 1; | ||
885 | return 0; | 1006 | return 0; |
1007 | } | ||
886 | 1008 | ||
887 | return 1; | 1009 | return 1; |
888 | } | 1010 | } |
@@ -1237,4 +1359,4 @@ static __init int relay_init(void) | |||
1237 | return 0; | 1359 | return 0; |
1238 | } | 1360 | } |
1239 | 1361 | ||
1240 | module_init(relay_init); | 1362 | early_initcall(relay_init); |
diff --git a/kernel/resource.c b/kernel/resource.c index 74af2d7cb5a1..414d6fc9131e 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
@@ -362,35 +362,21 @@ int allocate_resource(struct resource *root, struct resource *new, | |||
362 | 362 | ||
363 | EXPORT_SYMBOL(allocate_resource); | 363 | EXPORT_SYMBOL(allocate_resource); |
364 | 364 | ||
365 | /** | 365 | /* |
366 | * insert_resource - Inserts a resource in the resource tree | 366 | * Insert a resource into the resource tree. If successful, return NULL, |
367 | * @parent: parent of the new resource | 367 | * otherwise return the conflicting resource (compare to __request_resource()) |
368 | * @new: new resource to insert | ||
369 | * | ||
370 | * Returns 0 on success, -EBUSY if the resource can't be inserted. | ||
371 | * | ||
372 | * This function is equivalent to request_resource when no conflict | ||
373 | * happens. If a conflict happens, and the conflicting resources | ||
374 | * entirely fit within the range of the new resource, then the new | ||
375 | * resource is inserted and the conflicting resources become children of | ||
376 | * the new resource. | ||
377 | */ | 368 | */ |
378 | int insert_resource(struct resource *parent, struct resource *new) | 369 | static struct resource * __insert_resource(struct resource *parent, struct resource *new) |
379 | { | 370 | { |
380 | int result; | ||
381 | struct resource *first, *next; | 371 | struct resource *first, *next; |
382 | 372 | ||
383 | write_lock(&resource_lock); | ||
384 | |||
385 | for (;; parent = first) { | 373 | for (;; parent = first) { |
386 | result = 0; | ||
387 | first = __request_resource(parent, new); | 374 | first = __request_resource(parent, new); |
388 | if (!first) | 375 | if (!first) |
389 | goto out; | 376 | return first; |
390 | 377 | ||
391 | result = -EBUSY; | ||
392 | if (first == parent) | 378 | if (first == parent) |
393 | goto out; | 379 | return first; |
394 | 380 | ||
395 | if ((first->start > new->start) || (first->end < new->end)) | 381 | if ((first->start > new->start) || (first->end < new->end)) |
396 | break; | 382 | break; |
@@ -401,15 +387,13 @@ int insert_resource(struct resource *parent, struct resource *new) | |||
401 | for (next = first; ; next = next->sibling) { | 387 | for (next = first; ; next = next->sibling) { |
402 | /* Partial overlap? Bad, and unfixable */ | 388 | /* Partial overlap? Bad, and unfixable */ |
403 | if (next->start < new->start || next->end > new->end) | 389 | if (next->start < new->start || next->end > new->end) |
404 | goto out; | 390 | return next; |
405 | if (!next->sibling) | 391 | if (!next->sibling) |
406 | break; | 392 | break; |
407 | if (next->sibling->start > new->end) | 393 | if (next->sibling->start > new->end) |
408 | break; | 394 | break; |
409 | } | 395 | } |
410 | 396 | ||
411 | result = 0; | ||
412 | |||
413 | new->parent = parent; | 397 | new->parent = parent; |
414 | new->sibling = next->sibling; | 398 | new->sibling = next->sibling; |
415 | new->child = first; | 399 | new->child = first; |
@@ -426,10 +410,64 @@ int insert_resource(struct resource *parent, struct resource *new) | |||
426 | next = next->sibling; | 410 | next = next->sibling; |
427 | next->sibling = new; | 411 | next->sibling = new; |
428 | } | 412 | } |
413 | return NULL; | ||
414 | } | ||
429 | 415 | ||
430 | out: | 416 | /** |
417 | * insert_resource - Inserts a resource in the resource tree | ||
418 | * @parent: parent of the new resource | ||
419 | * @new: new resource to insert | ||
420 | * | ||
421 | * Returns 0 on success, -EBUSY if the resource can't be inserted. | ||
422 | * | ||
423 | * This function is equivalent to request_resource when no conflict | ||
424 | * happens. If a conflict happens, and the conflicting resources | ||
425 | * entirely fit within the range of the new resource, then the new | ||
426 | * resource is inserted and the conflicting resources become children of | ||
427 | * the new resource. | ||
428 | */ | ||
429 | int insert_resource(struct resource *parent, struct resource *new) | ||
430 | { | ||
431 | struct resource *conflict; | ||
432 | |||
433 | write_lock(&resource_lock); | ||
434 | conflict = __insert_resource(parent, new); | ||
435 | write_unlock(&resource_lock); | ||
436 | return conflict ? -EBUSY : 0; | ||
437 | } | ||
438 | |||
439 | /** | ||
440 | * insert_resource_expand_to_fit - Insert a resource into the resource tree | ||
441 | * @root: root resource descriptor | ||
442 | * @new: new resource to insert | ||
443 | * | ||
444 | * Insert a resource into the resource tree, possibly expanding it in order | ||
445 | * to make it encompass any conflicting resources. | ||
446 | */ | ||
447 | void insert_resource_expand_to_fit(struct resource *root, struct resource *new) | ||
448 | { | ||
449 | if (new->parent) | ||
450 | return; | ||
451 | |||
452 | write_lock(&resource_lock); | ||
453 | for (;;) { | ||
454 | struct resource *conflict; | ||
455 | |||
456 | conflict = __insert_resource(root, new); | ||
457 | if (!conflict) | ||
458 | break; | ||
459 | if (conflict == root) | ||
460 | break; | ||
461 | |||
462 | /* Ok, expand resource to cover the conflict, then try again .. */ | ||
463 | if (conflict->start < new->start) | ||
464 | new->start = conflict->start; | ||
465 | if (conflict->end > new->end) | ||
466 | new->end = conflict->end; | ||
467 | |||
468 | printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); | ||
469 | } | ||
431 | write_unlock(&resource_lock); | 470 | write_unlock(&resource_lock); |
432 | return result; | ||
433 | } | 471 | } |
434 | 472 | ||
435 | /** | 473 | /** |
@@ -478,6 +516,74 @@ int adjust_resource(struct resource *res, resource_size_t start, resource_size_t | |||
478 | return result; | 516 | return result; |
479 | } | 517 | } |
480 | 518 | ||
519 | static void __init __reserve_region_with_split(struct resource *root, | ||
520 | resource_size_t start, resource_size_t end, | ||
521 | const char *name) | ||
522 | { | ||
523 | struct resource *parent = root; | ||
524 | struct resource *conflict; | ||
525 | struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL); | ||
526 | |||
527 | if (!res) | ||
528 | return; | ||
529 | |||
530 | res->name = name; | ||
531 | res->start = start; | ||
532 | res->end = end; | ||
533 | res->flags = IORESOURCE_BUSY; | ||
534 | |||
535 | for (;;) { | ||
536 | conflict = __request_resource(parent, res); | ||
537 | if (!conflict) | ||
538 | break; | ||
539 | if (conflict != parent) { | ||
540 | parent = conflict; | ||
541 | if (!(conflict->flags & IORESOURCE_BUSY)) | ||
542 | continue; | ||
543 | } | ||
544 | |||
545 | /* Uhhuh, that didn't work out.. */ | ||
546 | kfree(res); | ||
547 | res = NULL; | ||
548 | break; | ||
549 | } | ||
550 | |||
551 | if (!res) { | ||
552 | printk(KERN_DEBUG " __reserve_region_with_split: (%s) [%llx, %llx], res: (%s) [%llx, %llx]\n", | ||
553 | conflict->name, conflict->start, conflict->end, | ||
554 | name, start, end); | ||
555 | |||
556 | /* failed, split and try again */ | ||
557 | |||
558 | /* conflict coverred whole area */ | ||
559 | if (conflict->start <= start && conflict->end >= end) | ||
560 | return; | ||
561 | |||
562 | if (conflict->start > start) | ||
563 | __reserve_region_with_split(root, start, conflict->start-1, name); | ||
564 | if (!(conflict->flags & IORESOURCE_BUSY)) { | ||
565 | resource_size_t common_start, common_end; | ||
566 | |||
567 | common_start = max(conflict->start, start); | ||
568 | common_end = min(conflict->end, end); | ||
569 | if (common_start < common_end) | ||
570 | __reserve_region_with_split(root, common_start, common_end, name); | ||
571 | } | ||
572 | if (conflict->end < end) | ||
573 | __reserve_region_with_split(root, conflict->end+1, end, name); | ||
574 | } | ||
575 | |||
576 | } | ||
577 | |||
578 | void reserve_region_with_split(struct resource *root, | ||
579 | resource_size_t start, resource_size_t end, | ||
580 | const char *name) | ||
581 | { | ||
582 | write_lock(&resource_lock); | ||
583 | __reserve_region_with_split(root, start, end, name); | ||
584 | write_unlock(&resource_lock); | ||
585 | } | ||
586 | |||
481 | EXPORT_SYMBOL(adjust_resource); | 587 | EXPORT_SYMBOL(adjust_resource); |
482 | 588 | ||
483 | /** | 589 | /** |
@@ -490,7 +596,7 @@ resource_size_t resource_alignment(struct resource *res) | |||
490 | { | 596 | { |
491 | switch (res->flags & (IORESOURCE_SIZEALIGN | IORESOURCE_STARTALIGN)) { | 597 | switch (res->flags & (IORESOURCE_SIZEALIGN | IORESOURCE_STARTALIGN)) { |
492 | case IORESOURCE_SIZEALIGN: | 598 | case IORESOURCE_SIZEALIGN: |
493 | return res->end - res->start + 1; | 599 | return resource_size(res); |
494 | case IORESOURCE_STARTALIGN: | 600 | case IORESOURCE_STARTALIGN: |
495 | return res->start; | 601 | return res->start; |
496 | default: | 602 | default: |
diff --git a/kernel/sched.c b/kernel/sched.c index 0047bd9b96aa..6f230596bd0c 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -201,14 +201,19 @@ void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime) | |||
201 | hrtimer_init(&rt_b->rt_period_timer, | 201 | hrtimer_init(&rt_b->rt_period_timer, |
202 | CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 202 | CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
203 | rt_b->rt_period_timer.function = sched_rt_period_timer; | 203 | rt_b->rt_period_timer.function = sched_rt_period_timer; |
204 | rt_b->rt_period_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 204 | rt_b->rt_period_timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED; |
205 | } | ||
206 | |||
207 | static inline int rt_bandwidth_enabled(void) | ||
208 | { | ||
209 | return sysctl_sched_rt_runtime >= 0; | ||
205 | } | 210 | } |
206 | 211 | ||
207 | static void start_rt_bandwidth(struct rt_bandwidth *rt_b) | 212 | static void start_rt_bandwidth(struct rt_bandwidth *rt_b) |
208 | { | 213 | { |
209 | ktime_t now; | 214 | ktime_t now; |
210 | 215 | ||
211 | if (rt_b->rt_runtime == RUNTIME_INF) | 216 | if (rt_bandwidth_enabled() && rt_b->rt_runtime == RUNTIME_INF) |
212 | return; | 217 | return; |
213 | 218 | ||
214 | if (hrtimer_active(&rt_b->rt_period_timer)) | 219 | if (hrtimer_active(&rt_b->rt_period_timer)) |
@@ -298,9 +303,9 @@ static DEFINE_PER_CPU(struct cfs_rq, init_cfs_rq) ____cacheline_aligned_in_smp; | |||
298 | static DEFINE_PER_CPU(struct sched_rt_entity, init_sched_rt_entity); | 303 | static DEFINE_PER_CPU(struct sched_rt_entity, init_sched_rt_entity); |
299 | static DEFINE_PER_CPU(struct rt_rq, init_rt_rq) ____cacheline_aligned_in_smp; | 304 | static DEFINE_PER_CPU(struct rt_rq, init_rt_rq) ____cacheline_aligned_in_smp; |
300 | #endif /* CONFIG_RT_GROUP_SCHED */ | 305 | #endif /* CONFIG_RT_GROUP_SCHED */ |
301 | #else /* !CONFIG_FAIR_GROUP_SCHED */ | 306 | #else /* !CONFIG_USER_SCHED */ |
302 | #define root_task_group init_task_group | 307 | #define root_task_group init_task_group |
303 | #endif /* CONFIG_FAIR_GROUP_SCHED */ | 308 | #endif /* CONFIG_USER_SCHED */ |
304 | 309 | ||
305 | /* task_group_lock serializes add/remove of task groups and also changes to | 310 | /* task_group_lock serializes add/remove of task groups and also changes to |
306 | * a task group's cpu shares. | 311 | * a task group's cpu shares. |
@@ -600,14 +605,13 @@ struct rq { | |||
600 | /* BKL stats */ | 605 | /* BKL stats */ |
601 | unsigned int bkl_count; | 606 | unsigned int bkl_count; |
602 | #endif | 607 | #endif |
603 | struct lock_class_key rq_lock_key; | ||
604 | }; | 608 | }; |
605 | 609 | ||
606 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); | 610 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); |
607 | 611 | ||
608 | static inline void check_preempt_curr(struct rq *rq, struct task_struct *p) | 612 | static inline void check_preempt_curr(struct rq *rq, struct task_struct *p, int sync) |
609 | { | 613 | { |
610 | rq->curr->sched_class->check_preempt_curr(rq, p); | 614 | rq->curr->sched_class->check_preempt_curr(rq, p, sync); |
611 | } | 615 | } |
612 | 616 | ||
613 | static inline int cpu_of(struct rq *rq) | 617 | static inline int cpu_of(struct rq *rq) |
@@ -809,9 +813,9 @@ const_debug unsigned int sysctl_sched_nr_migrate = 32; | |||
809 | 813 | ||
810 | /* | 814 | /* |
811 | * ratelimit for updating the group shares. | 815 | * ratelimit for updating the group shares. |
812 | * default: 0.5ms | 816 | * default: 0.25ms |
813 | */ | 817 | */ |
814 | const_debug unsigned int sysctl_sched_shares_ratelimit = 500000; | 818 | unsigned int sysctl_sched_shares_ratelimit = 250000; |
815 | 819 | ||
816 | /* | 820 | /* |
817 | * period over which we measure -rt task cpu usage in us. | 821 | * period over which we measure -rt task cpu usage in us. |
@@ -834,7 +838,7 @@ static inline u64 global_rt_period(void) | |||
834 | 838 | ||
835 | static inline u64 global_rt_runtime(void) | 839 | static inline u64 global_rt_runtime(void) |
836 | { | 840 | { |
837 | if (sysctl_sched_rt_period < 0) | 841 | if (sysctl_sched_rt_runtime < 0) |
838 | return RUNTIME_INF; | 842 | return RUNTIME_INF; |
839 | 843 | ||
840 | return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC; | 844 | return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC; |
@@ -1088,7 +1092,7 @@ hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
1088 | return NOTIFY_DONE; | 1092 | return NOTIFY_DONE; |
1089 | } | 1093 | } |
1090 | 1094 | ||
1091 | static void init_hrtick(void) | 1095 | static __init void init_hrtick(void) |
1092 | { | 1096 | { |
1093 | hotcpu_notifier(hotplug_hrtick, 0); | 1097 | hotcpu_notifier(hotplug_hrtick, 0); |
1094 | } | 1098 | } |
@@ -1103,7 +1107,7 @@ static void hrtick_start(struct rq *rq, u64 delay) | |||
1103 | hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay), HRTIMER_MODE_REL); | 1107 | hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay), HRTIMER_MODE_REL); |
1104 | } | 1108 | } |
1105 | 1109 | ||
1106 | static void init_hrtick(void) | 1110 | static inline void init_hrtick(void) |
1107 | { | 1111 | { |
1108 | } | 1112 | } |
1109 | #endif /* CONFIG_SMP */ | 1113 | #endif /* CONFIG_SMP */ |
@@ -1120,9 +1124,9 @@ static void init_rq_hrtick(struct rq *rq) | |||
1120 | 1124 | ||
1121 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 1125 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
1122 | rq->hrtick_timer.function = hrtick; | 1126 | rq->hrtick_timer.function = hrtick; |
1123 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 1127 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_PERCPU; |
1124 | } | 1128 | } |
1125 | #else | 1129 | #else /* CONFIG_SCHED_HRTICK */ |
1126 | static inline void hrtick_clear(struct rq *rq) | 1130 | static inline void hrtick_clear(struct rq *rq) |
1127 | { | 1131 | { |
1128 | } | 1132 | } |
@@ -1134,7 +1138,7 @@ static inline void init_rq_hrtick(struct rq *rq) | |||
1134 | static inline void init_hrtick(void) | 1138 | static inline void init_hrtick(void) |
1135 | { | 1139 | { |
1136 | } | 1140 | } |
1137 | #endif | 1141 | #endif /* CONFIG_SCHED_HRTICK */ |
1138 | 1142 | ||
1139 | /* | 1143 | /* |
1140 | * resched_task - mark a task 'to be rescheduled now'. | 1144 | * resched_task - mark a task 'to be rescheduled now'. |
@@ -1381,38 +1385,24 @@ static inline void dec_cpu_load(struct rq *rq, unsigned long load) | |||
1381 | update_load_sub(&rq->load, load); | 1385 | update_load_sub(&rq->load, load); |
1382 | } | 1386 | } |
1383 | 1387 | ||
1384 | #ifdef CONFIG_SMP | 1388 | #if (defined(CONFIG_SMP) && defined(CONFIG_FAIR_GROUP_SCHED)) || defined(CONFIG_RT_GROUP_SCHED) |
1385 | static unsigned long source_load(int cpu, int type); | 1389 | typedef int (*tg_visitor)(struct task_group *, void *); |
1386 | static unsigned long target_load(int cpu, int type); | ||
1387 | static int task_hot(struct task_struct *p, u64 now, struct sched_domain *sd); | ||
1388 | |||
1389 | static unsigned long cpu_avg_load_per_task(int cpu) | ||
1390 | { | ||
1391 | struct rq *rq = cpu_rq(cpu); | ||
1392 | |||
1393 | if (rq->nr_running) | ||
1394 | rq->avg_load_per_task = rq->load.weight / rq->nr_running; | ||
1395 | |||
1396 | return rq->avg_load_per_task; | ||
1397 | } | ||
1398 | |||
1399 | #ifdef CONFIG_FAIR_GROUP_SCHED | ||
1400 | |||
1401 | typedef void (*tg_visitor)(struct task_group *, int, struct sched_domain *); | ||
1402 | 1390 | ||
1403 | /* | 1391 | /* |
1404 | * Iterate the full tree, calling @down when first entering a node and @up when | 1392 | * Iterate the full tree, calling @down when first entering a node and @up when |
1405 | * leaving it for the final time. | 1393 | * leaving it for the final time. |
1406 | */ | 1394 | */ |
1407 | static void | 1395 | static int walk_tg_tree(tg_visitor down, tg_visitor up, void *data) |
1408 | walk_tg_tree(tg_visitor down, tg_visitor up, int cpu, struct sched_domain *sd) | ||
1409 | { | 1396 | { |
1410 | struct task_group *parent, *child; | 1397 | struct task_group *parent, *child; |
1398 | int ret; | ||
1411 | 1399 | ||
1412 | rcu_read_lock(); | 1400 | rcu_read_lock(); |
1413 | parent = &root_task_group; | 1401 | parent = &root_task_group; |
1414 | down: | 1402 | down: |
1415 | (*down)(parent, cpu, sd); | 1403 | ret = (*down)(parent, data); |
1404 | if (ret) | ||
1405 | goto out_unlock; | ||
1416 | list_for_each_entry_rcu(child, &parent->children, siblings) { | 1406 | list_for_each_entry_rcu(child, &parent->children, siblings) { |
1417 | parent = child; | 1407 | parent = child; |
1418 | goto down; | 1408 | goto down; |
@@ -1420,15 +1410,43 @@ down: | |||
1420 | up: | 1410 | up: |
1421 | continue; | 1411 | continue; |
1422 | } | 1412 | } |
1423 | (*up)(parent, cpu, sd); | 1413 | ret = (*up)(parent, data); |
1414 | if (ret) | ||
1415 | goto out_unlock; | ||
1424 | 1416 | ||
1425 | child = parent; | 1417 | child = parent; |
1426 | parent = parent->parent; | 1418 | parent = parent->parent; |
1427 | if (parent) | 1419 | if (parent) |
1428 | goto up; | 1420 | goto up; |
1421 | out_unlock: | ||
1429 | rcu_read_unlock(); | 1422 | rcu_read_unlock(); |
1423 | |||
1424 | return ret; | ||
1430 | } | 1425 | } |
1431 | 1426 | ||
1427 | static int tg_nop(struct task_group *tg, void *data) | ||
1428 | { | ||
1429 | return 0; | ||
1430 | } | ||
1431 | #endif | ||
1432 | |||
1433 | #ifdef CONFIG_SMP | ||
1434 | static unsigned long source_load(int cpu, int type); | ||
1435 | static unsigned long target_load(int cpu, int type); | ||
1436 | static int task_hot(struct task_struct *p, u64 now, struct sched_domain *sd); | ||
1437 | |||
1438 | static unsigned long cpu_avg_load_per_task(int cpu) | ||
1439 | { | ||
1440 | struct rq *rq = cpu_rq(cpu); | ||
1441 | |||
1442 | if (rq->nr_running) | ||
1443 | rq->avg_load_per_task = rq->load.weight / rq->nr_running; | ||
1444 | |||
1445 | return rq->avg_load_per_task; | ||
1446 | } | ||
1447 | |||
1448 | #ifdef CONFIG_FAIR_GROUP_SCHED | ||
1449 | |||
1432 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); | 1450 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); |
1433 | 1451 | ||
1434 | /* | 1452 | /* |
@@ -1487,11 +1505,11 @@ __update_group_shares_cpu(struct task_group *tg, int cpu, | |||
1487 | * This needs to be done in a bottom-up fashion because the rq weight of a | 1505 | * This needs to be done in a bottom-up fashion because the rq weight of a |
1488 | * parent group depends on the shares of its child groups. | 1506 | * parent group depends on the shares of its child groups. |
1489 | */ | 1507 | */ |
1490 | static void | 1508 | static int tg_shares_up(struct task_group *tg, void *data) |
1491 | tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd) | ||
1492 | { | 1509 | { |
1493 | unsigned long rq_weight = 0; | 1510 | unsigned long rq_weight = 0; |
1494 | unsigned long shares = 0; | 1511 | unsigned long shares = 0; |
1512 | struct sched_domain *sd = data; | ||
1495 | int i; | 1513 | int i; |
1496 | 1514 | ||
1497 | for_each_cpu_mask(i, sd->span) { | 1515 | for_each_cpu_mask(i, sd->span) { |
@@ -1516,6 +1534,8 @@ tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd) | |||
1516 | __update_group_shares_cpu(tg, i, shares, rq_weight); | 1534 | __update_group_shares_cpu(tg, i, shares, rq_weight); |
1517 | spin_unlock_irqrestore(&rq->lock, flags); | 1535 | spin_unlock_irqrestore(&rq->lock, flags); |
1518 | } | 1536 | } |
1537 | |||
1538 | return 0; | ||
1519 | } | 1539 | } |
1520 | 1540 | ||
1521 | /* | 1541 | /* |
@@ -1523,10 +1543,10 @@ tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd) | |||
1523 | * This needs to be done in a top-down fashion because the load of a child | 1543 | * This needs to be done in a top-down fashion because the load of a child |
1524 | * group is a fraction of its parents load. | 1544 | * group is a fraction of its parents load. |
1525 | */ | 1545 | */ |
1526 | static void | 1546 | static int tg_load_down(struct task_group *tg, void *data) |
1527 | tg_load_down(struct task_group *tg, int cpu, struct sched_domain *sd) | ||
1528 | { | 1547 | { |
1529 | unsigned long load; | 1548 | unsigned long load; |
1549 | long cpu = (long)data; | ||
1530 | 1550 | ||
1531 | if (!tg->parent) { | 1551 | if (!tg->parent) { |
1532 | load = cpu_rq(cpu)->load.weight; | 1552 | load = cpu_rq(cpu)->load.weight; |
@@ -1537,11 +1557,8 @@ tg_load_down(struct task_group *tg, int cpu, struct sched_domain *sd) | |||
1537 | } | 1557 | } |
1538 | 1558 | ||
1539 | tg->cfs_rq[cpu]->h_load = load; | 1559 | tg->cfs_rq[cpu]->h_load = load; |
1540 | } | ||
1541 | 1560 | ||
1542 | static void | 1561 | return 0; |
1543 | tg_nop(struct task_group *tg, int cpu, struct sched_domain *sd) | ||
1544 | { | ||
1545 | } | 1562 | } |
1546 | 1563 | ||
1547 | static void update_shares(struct sched_domain *sd) | 1564 | static void update_shares(struct sched_domain *sd) |
@@ -1551,7 +1568,7 @@ static void update_shares(struct sched_domain *sd) | |||
1551 | 1568 | ||
1552 | if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) { | 1569 | if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) { |
1553 | sd->last_update = now; | 1570 | sd->last_update = now; |
1554 | walk_tg_tree(tg_nop, tg_shares_up, 0, sd); | 1571 | walk_tg_tree(tg_nop, tg_shares_up, sd); |
1555 | } | 1572 | } |
1556 | } | 1573 | } |
1557 | 1574 | ||
@@ -1562,9 +1579,9 @@ static void update_shares_locked(struct rq *rq, struct sched_domain *sd) | |||
1562 | spin_lock(&rq->lock); | 1579 | spin_lock(&rq->lock); |
1563 | } | 1580 | } |
1564 | 1581 | ||
1565 | static void update_h_load(int cpu) | 1582 | static void update_h_load(long cpu) |
1566 | { | 1583 | { |
1567 | walk_tg_tree(tg_load_down, tg_nop, cpu, NULL); | 1584 | walk_tg_tree(tg_load_down, tg_nop, (void *)cpu); |
1568 | } | 1585 | } |
1569 | 1586 | ||
1570 | #else | 1587 | #else |
@@ -1867,16 +1884,24 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | |||
1867 | /* | 1884 | /* |
1868 | * wait_task_inactive - wait for a thread to unschedule. | 1885 | * wait_task_inactive - wait for a thread to unschedule. |
1869 | * | 1886 | * |
1887 | * If @match_state is nonzero, it's the @p->state value just checked and | ||
1888 | * not expected to change. If it changes, i.e. @p might have woken up, | ||
1889 | * then return zero. When we succeed in waiting for @p to be off its CPU, | ||
1890 | * we return a positive number (its total switch count). If a second call | ||
1891 | * a short while later returns the same number, the caller can be sure that | ||
1892 | * @p has remained unscheduled the whole time. | ||
1893 | * | ||
1870 | * The caller must ensure that the task *will* unschedule sometime soon, | 1894 | * The caller must ensure that the task *will* unschedule sometime soon, |
1871 | * else this function might spin for a *long* time. This function can't | 1895 | * else this function might spin for a *long* time. This function can't |
1872 | * be called with interrupts off, or it may introduce deadlock with | 1896 | * be called with interrupts off, or it may introduce deadlock with |
1873 | * smp_call_function() if an IPI is sent by the same process we are | 1897 | * smp_call_function() if an IPI is sent by the same process we are |
1874 | * waiting to become inactive. | 1898 | * waiting to become inactive. |
1875 | */ | 1899 | */ |
1876 | void wait_task_inactive(struct task_struct *p) | 1900 | unsigned long wait_task_inactive(struct task_struct *p, long match_state) |
1877 | { | 1901 | { |
1878 | unsigned long flags; | 1902 | unsigned long flags; |
1879 | int running, on_rq; | 1903 | int running, on_rq; |
1904 | unsigned long ncsw; | ||
1880 | struct rq *rq; | 1905 | struct rq *rq; |
1881 | 1906 | ||
1882 | for (;;) { | 1907 | for (;;) { |
@@ -1899,8 +1924,11 @@ void wait_task_inactive(struct task_struct *p) | |||
1899 | * return false if the runqueue has changed and p | 1924 | * return false if the runqueue has changed and p |
1900 | * is actually now running somewhere else! | 1925 | * is actually now running somewhere else! |
1901 | */ | 1926 | */ |
1902 | while (task_running(rq, p)) | 1927 | while (task_running(rq, p)) { |
1928 | if (match_state && unlikely(p->state != match_state)) | ||
1929 | return 0; | ||
1903 | cpu_relax(); | 1930 | cpu_relax(); |
1931 | } | ||
1904 | 1932 | ||
1905 | /* | 1933 | /* |
1906 | * Ok, time to look more closely! We need the rq | 1934 | * Ok, time to look more closely! We need the rq |
@@ -1910,9 +1938,18 @@ void wait_task_inactive(struct task_struct *p) | |||
1910 | rq = task_rq_lock(p, &flags); | 1938 | rq = task_rq_lock(p, &flags); |
1911 | running = task_running(rq, p); | 1939 | running = task_running(rq, p); |
1912 | on_rq = p->se.on_rq; | 1940 | on_rq = p->se.on_rq; |
1941 | ncsw = 0; | ||
1942 | if (!match_state || p->state == match_state) | ||
1943 | ncsw = p->nvcsw | LONG_MIN; /* sets MSB */ | ||
1913 | task_rq_unlock(rq, &flags); | 1944 | task_rq_unlock(rq, &flags); |
1914 | 1945 | ||
1915 | /* | 1946 | /* |
1947 | * If it changed from the expected state, bail out now. | ||
1948 | */ | ||
1949 | if (unlikely(!ncsw)) | ||
1950 | break; | ||
1951 | |||
1952 | /* | ||
1916 | * Was it really running after all now that we | 1953 | * Was it really running after all now that we |
1917 | * checked with the proper locks actually held? | 1954 | * checked with the proper locks actually held? |
1918 | * | 1955 | * |
@@ -1944,6 +1981,8 @@ void wait_task_inactive(struct task_struct *p) | |||
1944 | */ | 1981 | */ |
1945 | break; | 1982 | break; |
1946 | } | 1983 | } |
1984 | |||
1985 | return ncsw; | ||
1947 | } | 1986 | } |
1948 | 1987 | ||
1949 | /*** | 1988 | /*** |
@@ -2261,7 +2300,7 @@ out_running: | |||
2261 | trace_mark(kernel_sched_wakeup, | 2300 | trace_mark(kernel_sched_wakeup, |
2262 | "pid %d state %ld ## rq %p task %p rq->curr %p", | 2301 | "pid %d state %ld ## rq %p task %p rq->curr %p", |
2263 | p->pid, p->state, rq, p, rq->curr); | 2302 | p->pid, p->state, rq, p, rq->curr); |
2264 | check_preempt_curr(rq, p); | 2303 | check_preempt_curr(rq, p, sync); |
2265 | 2304 | ||
2266 | p->state = TASK_RUNNING; | 2305 | p->state = TASK_RUNNING; |
2267 | #ifdef CONFIG_SMP | 2306 | #ifdef CONFIG_SMP |
@@ -2396,7 +2435,7 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags) | |||
2396 | trace_mark(kernel_sched_wakeup_new, | 2435 | trace_mark(kernel_sched_wakeup_new, |
2397 | "pid %d state %ld ## rq %p task %p rq->curr %p", | 2436 | "pid %d state %ld ## rq %p task %p rq->curr %p", |
2398 | p->pid, p->state, rq, p, rq->curr); | 2437 | p->pid, p->state, rq, p, rq->curr); |
2399 | check_preempt_curr(rq, p); | 2438 | check_preempt_curr(rq, p, 0); |
2400 | #ifdef CONFIG_SMP | 2439 | #ifdef CONFIG_SMP |
2401 | if (p->sched_class->task_wake_up) | 2440 | if (p->sched_class->task_wake_up) |
2402 | p->sched_class->task_wake_up(rq, p); | 2441 | p->sched_class->task_wake_up(rq, p); |
@@ -2734,10 +2773,10 @@ static void double_rq_lock(struct rq *rq1, struct rq *rq2) | |||
2734 | } else { | 2773 | } else { |
2735 | if (rq1 < rq2) { | 2774 | if (rq1 < rq2) { |
2736 | spin_lock(&rq1->lock); | 2775 | spin_lock(&rq1->lock); |
2737 | spin_lock(&rq2->lock); | 2776 | spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING); |
2738 | } else { | 2777 | } else { |
2739 | spin_lock(&rq2->lock); | 2778 | spin_lock(&rq2->lock); |
2740 | spin_lock(&rq1->lock); | 2779 | spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); |
2741 | } | 2780 | } |
2742 | } | 2781 | } |
2743 | update_rq_clock(rq1); | 2782 | update_rq_clock(rq1); |
@@ -2780,14 +2819,21 @@ static int double_lock_balance(struct rq *this_rq, struct rq *busiest) | |||
2780 | if (busiest < this_rq) { | 2819 | if (busiest < this_rq) { |
2781 | spin_unlock(&this_rq->lock); | 2820 | spin_unlock(&this_rq->lock); |
2782 | spin_lock(&busiest->lock); | 2821 | spin_lock(&busiest->lock); |
2783 | spin_lock(&this_rq->lock); | 2822 | spin_lock_nested(&this_rq->lock, SINGLE_DEPTH_NESTING); |
2784 | ret = 1; | 2823 | ret = 1; |
2785 | } else | 2824 | } else |
2786 | spin_lock(&busiest->lock); | 2825 | spin_lock_nested(&busiest->lock, SINGLE_DEPTH_NESTING); |
2787 | } | 2826 | } |
2788 | return ret; | 2827 | return ret; |
2789 | } | 2828 | } |
2790 | 2829 | ||
2830 | static void double_unlock_balance(struct rq *this_rq, struct rq *busiest) | ||
2831 | __releases(busiest->lock) | ||
2832 | { | ||
2833 | spin_unlock(&busiest->lock); | ||
2834 | lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_); | ||
2835 | } | ||
2836 | |||
2791 | /* | 2837 | /* |
2792 | * If dest_cpu is allowed for this process, migrate the task to it. | 2838 | * If dest_cpu is allowed for this process, migrate the task to it. |
2793 | * This is accomplished by forcing the cpu_allowed mask to only | 2839 | * This is accomplished by forcing the cpu_allowed mask to only |
@@ -2849,7 +2895,7 @@ static void pull_task(struct rq *src_rq, struct task_struct *p, | |||
2849 | * Note that idle threads have a prio of MAX_PRIO, for this test | 2895 | * Note that idle threads have a prio of MAX_PRIO, for this test |
2850 | * to be always true for them. | 2896 | * to be always true for them. |
2851 | */ | 2897 | */ |
2852 | check_preempt_curr(this_rq, p); | 2898 | check_preempt_curr(this_rq, p, 0); |
2853 | } | 2899 | } |
2854 | 2900 | ||
2855 | /* | 2901 | /* |
@@ -3612,7 +3658,7 @@ redo: | |||
3612 | ld_moved = move_tasks(this_rq, this_cpu, busiest, | 3658 | ld_moved = move_tasks(this_rq, this_cpu, busiest, |
3613 | imbalance, sd, CPU_NEWLY_IDLE, | 3659 | imbalance, sd, CPU_NEWLY_IDLE, |
3614 | &all_pinned); | 3660 | &all_pinned); |
3615 | spin_unlock(&busiest->lock); | 3661 | double_unlock_balance(this_rq, busiest); |
3616 | 3662 | ||
3617 | if (unlikely(all_pinned)) { | 3663 | if (unlikely(all_pinned)) { |
3618 | cpu_clear(cpu_of(busiest), *cpus); | 3664 | cpu_clear(cpu_of(busiest), *cpus); |
@@ -3727,7 +3773,7 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3727 | else | 3773 | else |
3728 | schedstat_inc(sd, alb_failed); | 3774 | schedstat_inc(sd, alb_failed); |
3729 | } | 3775 | } |
3730 | spin_unlock(&target_rq->lock); | 3776 | double_unlock_balance(busiest_rq, target_rq); |
3731 | } | 3777 | } |
3732 | 3778 | ||
3733 | #ifdef CONFIG_NO_HZ | 3779 | #ifdef CONFIG_NO_HZ |
@@ -4148,6 +4194,65 @@ void account_steal_time(struct task_struct *p, cputime_t steal) | |||
4148 | } | 4194 | } |
4149 | 4195 | ||
4150 | /* | 4196 | /* |
4197 | * Use precise platform statistics if available: | ||
4198 | */ | ||
4199 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | ||
4200 | cputime_t task_utime(struct task_struct *p) | ||
4201 | { | ||
4202 | return p->utime; | ||
4203 | } | ||
4204 | |||
4205 | cputime_t task_stime(struct task_struct *p) | ||
4206 | { | ||
4207 | return p->stime; | ||
4208 | } | ||
4209 | #else | ||
4210 | cputime_t task_utime(struct task_struct *p) | ||
4211 | { | ||
4212 | clock_t utime = cputime_to_clock_t(p->utime), | ||
4213 | total = utime + cputime_to_clock_t(p->stime); | ||
4214 | u64 temp; | ||
4215 | |||
4216 | /* | ||
4217 | * Use CFS's precise accounting: | ||
4218 | */ | ||
4219 | temp = (u64)nsec_to_clock_t(p->se.sum_exec_runtime); | ||
4220 | |||
4221 | if (total) { | ||
4222 | temp *= utime; | ||
4223 | do_div(temp, total); | ||
4224 | } | ||
4225 | utime = (clock_t)temp; | ||
4226 | |||
4227 | p->prev_utime = max(p->prev_utime, clock_t_to_cputime(utime)); | ||
4228 | return p->prev_utime; | ||
4229 | } | ||
4230 | |||
4231 | cputime_t task_stime(struct task_struct *p) | ||
4232 | { | ||
4233 | clock_t stime; | ||
4234 | |||
4235 | /* | ||
4236 | * Use CFS's precise accounting. (we subtract utime from | ||
4237 | * the total, to make sure the total observed by userspace | ||
4238 | * grows monotonically - apps rely on that): | ||
4239 | */ | ||
4240 | stime = nsec_to_clock_t(p->se.sum_exec_runtime) - | ||
4241 | cputime_to_clock_t(task_utime(p)); | ||
4242 | |||
4243 | if (stime >= 0) | ||
4244 | p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime)); | ||
4245 | |||
4246 | return p->prev_stime; | ||
4247 | } | ||
4248 | #endif | ||
4249 | |||
4250 | inline cputime_t task_gtime(struct task_struct *p) | ||
4251 | { | ||
4252 | return p->gtime; | ||
4253 | } | ||
4254 | |||
4255 | /* | ||
4151 | * This function gets called by the timer code, with HZ frequency. | 4256 | * This function gets called by the timer code, with HZ frequency. |
4152 | * We call it with interrupts disabled. | 4257 | * We call it with interrupts disabled. |
4153 | * | 4258 | * |
@@ -4537,6 +4642,15 @@ __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive) | |||
4537 | } | 4642 | } |
4538 | EXPORT_SYMBOL_GPL(__wake_up_sync); /* For internal use only */ | 4643 | EXPORT_SYMBOL_GPL(__wake_up_sync); /* For internal use only */ |
4539 | 4644 | ||
4645 | /** | ||
4646 | * complete: - signals a single thread waiting on this completion | ||
4647 | * @x: holds the state of this particular completion | ||
4648 | * | ||
4649 | * This will wake up a single thread waiting on this completion. Threads will be | ||
4650 | * awakened in the same order in which they were queued. | ||
4651 | * | ||
4652 | * See also complete_all(), wait_for_completion() and related routines. | ||
4653 | */ | ||
4540 | void complete(struct completion *x) | 4654 | void complete(struct completion *x) |
4541 | { | 4655 | { |
4542 | unsigned long flags; | 4656 | unsigned long flags; |
@@ -4548,6 +4662,12 @@ void complete(struct completion *x) | |||
4548 | } | 4662 | } |
4549 | EXPORT_SYMBOL(complete); | 4663 | EXPORT_SYMBOL(complete); |
4550 | 4664 | ||
4665 | /** | ||
4666 | * complete_all: - signals all threads waiting on this completion | ||
4667 | * @x: holds the state of this particular completion | ||
4668 | * | ||
4669 | * This will wake up all threads waiting on this particular completion event. | ||
4670 | */ | ||
4551 | void complete_all(struct completion *x) | 4671 | void complete_all(struct completion *x) |
4552 | { | 4672 | { |
4553 | unsigned long flags; | 4673 | unsigned long flags; |
@@ -4568,10 +4688,7 @@ do_wait_for_common(struct completion *x, long timeout, int state) | |||
4568 | wait.flags |= WQ_FLAG_EXCLUSIVE; | 4688 | wait.flags |= WQ_FLAG_EXCLUSIVE; |
4569 | __add_wait_queue_tail(&x->wait, &wait); | 4689 | __add_wait_queue_tail(&x->wait, &wait); |
4570 | do { | 4690 | do { |
4571 | if ((state == TASK_INTERRUPTIBLE && | 4691 | if (signal_pending_state(state, current)) { |
4572 | signal_pending(current)) || | ||
4573 | (state == TASK_KILLABLE && | ||
4574 | fatal_signal_pending(current))) { | ||
4575 | timeout = -ERESTARTSYS; | 4692 | timeout = -ERESTARTSYS; |
4576 | break; | 4693 | break; |
4577 | } | 4694 | } |
@@ -4599,12 +4716,31 @@ wait_for_common(struct completion *x, long timeout, int state) | |||
4599 | return timeout; | 4716 | return timeout; |
4600 | } | 4717 | } |
4601 | 4718 | ||
4719 | /** | ||
4720 | * wait_for_completion: - waits for completion of a task | ||
4721 | * @x: holds the state of this particular completion | ||
4722 | * | ||
4723 | * This waits to be signaled for completion of a specific task. It is NOT | ||
4724 | * interruptible and there is no timeout. | ||
4725 | * | ||
4726 | * See also similar routines (i.e. wait_for_completion_timeout()) with timeout | ||
4727 | * and interrupt capability. Also see complete(). | ||
4728 | */ | ||
4602 | void __sched wait_for_completion(struct completion *x) | 4729 | void __sched wait_for_completion(struct completion *x) |
4603 | { | 4730 | { |
4604 | wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); | 4731 | wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); |
4605 | } | 4732 | } |
4606 | EXPORT_SYMBOL(wait_for_completion); | 4733 | EXPORT_SYMBOL(wait_for_completion); |
4607 | 4734 | ||
4735 | /** | ||
4736 | * wait_for_completion_timeout: - waits for completion of a task (w/timeout) | ||
4737 | * @x: holds the state of this particular completion | ||
4738 | * @timeout: timeout value in jiffies | ||
4739 | * | ||
4740 | * This waits for either a completion of a specific task to be signaled or for a | ||
4741 | * specified timeout to expire. The timeout is in jiffies. It is not | ||
4742 | * interruptible. | ||
4743 | */ | ||
4608 | unsigned long __sched | 4744 | unsigned long __sched |
4609 | wait_for_completion_timeout(struct completion *x, unsigned long timeout) | 4745 | wait_for_completion_timeout(struct completion *x, unsigned long timeout) |
4610 | { | 4746 | { |
@@ -4612,6 +4748,13 @@ wait_for_completion_timeout(struct completion *x, unsigned long timeout) | |||
4612 | } | 4748 | } |
4613 | EXPORT_SYMBOL(wait_for_completion_timeout); | 4749 | EXPORT_SYMBOL(wait_for_completion_timeout); |
4614 | 4750 | ||
4751 | /** | ||
4752 | * wait_for_completion_interruptible: - waits for completion of a task (w/intr) | ||
4753 | * @x: holds the state of this particular completion | ||
4754 | * | ||
4755 | * This waits for completion of a specific task to be signaled. It is | ||
4756 | * interruptible. | ||
4757 | */ | ||
4615 | int __sched wait_for_completion_interruptible(struct completion *x) | 4758 | int __sched wait_for_completion_interruptible(struct completion *x) |
4616 | { | 4759 | { |
4617 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); | 4760 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); |
@@ -4621,6 +4764,14 @@ int __sched wait_for_completion_interruptible(struct completion *x) | |||
4621 | } | 4764 | } |
4622 | EXPORT_SYMBOL(wait_for_completion_interruptible); | 4765 | EXPORT_SYMBOL(wait_for_completion_interruptible); |
4623 | 4766 | ||
4767 | /** | ||
4768 | * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr)) | ||
4769 | * @x: holds the state of this particular completion | ||
4770 | * @timeout: timeout value in jiffies | ||
4771 | * | ||
4772 | * This waits for either a completion of a specific task to be signaled or for a | ||
4773 | * specified timeout to expire. It is interruptible. The timeout is in jiffies. | ||
4774 | */ | ||
4624 | unsigned long __sched | 4775 | unsigned long __sched |
4625 | wait_for_completion_interruptible_timeout(struct completion *x, | 4776 | wait_for_completion_interruptible_timeout(struct completion *x, |
4626 | unsigned long timeout) | 4777 | unsigned long timeout) |
@@ -4629,6 +4780,13 @@ wait_for_completion_interruptible_timeout(struct completion *x, | |||
4629 | } | 4780 | } |
4630 | EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); | 4781 | EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); |
4631 | 4782 | ||
4783 | /** | ||
4784 | * wait_for_completion_killable: - waits for completion of a task (killable) | ||
4785 | * @x: holds the state of this particular completion | ||
4786 | * | ||
4787 | * This waits to be signaled for completion of a specific task. It can be | ||
4788 | * interrupted by a kill signal. | ||
4789 | */ | ||
4632 | int __sched wait_for_completion_killable(struct completion *x) | 4790 | int __sched wait_for_completion_killable(struct completion *x) |
4633 | { | 4791 | { |
4634 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); | 4792 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); |
@@ -4638,6 +4796,52 @@ int __sched wait_for_completion_killable(struct completion *x) | |||
4638 | } | 4796 | } |
4639 | EXPORT_SYMBOL(wait_for_completion_killable); | 4797 | EXPORT_SYMBOL(wait_for_completion_killable); |
4640 | 4798 | ||
4799 | /** | ||
4800 | * try_wait_for_completion - try to decrement a completion without blocking | ||
4801 | * @x: completion structure | ||
4802 | * | ||
4803 | * Returns: 0 if a decrement cannot be done without blocking | ||
4804 | * 1 if a decrement succeeded. | ||
4805 | * | ||
4806 | * If a completion is being used as a counting completion, | ||
4807 | * attempt to decrement the counter without blocking. This | ||
4808 | * enables us to avoid waiting if the resource the completion | ||
4809 | * is protecting is not available. | ||
4810 | */ | ||
4811 | bool try_wait_for_completion(struct completion *x) | ||
4812 | { | ||
4813 | int ret = 1; | ||
4814 | |||
4815 | spin_lock_irq(&x->wait.lock); | ||
4816 | if (!x->done) | ||
4817 | ret = 0; | ||
4818 | else | ||
4819 | x->done--; | ||
4820 | spin_unlock_irq(&x->wait.lock); | ||
4821 | return ret; | ||
4822 | } | ||
4823 | EXPORT_SYMBOL(try_wait_for_completion); | ||
4824 | |||
4825 | /** | ||
4826 | * completion_done - Test to see if a completion has any waiters | ||
4827 | * @x: completion structure | ||
4828 | * | ||
4829 | * Returns: 0 if there are waiters (wait_for_completion() in progress) | ||
4830 | * 1 if there are no waiters. | ||
4831 | * | ||
4832 | */ | ||
4833 | bool completion_done(struct completion *x) | ||
4834 | { | ||
4835 | int ret = 1; | ||
4836 | |||
4837 | spin_lock_irq(&x->wait.lock); | ||
4838 | if (!x->done) | ||
4839 | ret = 0; | ||
4840 | spin_unlock_irq(&x->wait.lock); | ||
4841 | return ret; | ||
4842 | } | ||
4843 | EXPORT_SYMBOL(completion_done); | ||
4844 | |||
4641 | static long __sched | 4845 | static long __sched |
4642 | sleep_on_common(wait_queue_head_t *q, int state, long timeout) | 4846 | sleep_on_common(wait_queue_head_t *q, int state, long timeout) |
4643 | { | 4847 | { |
@@ -4979,19 +5183,22 @@ recheck: | |||
4979 | return -EPERM; | 5183 | return -EPERM; |
4980 | } | 5184 | } |
4981 | 5185 | ||
5186 | if (user) { | ||
4982 | #ifdef CONFIG_RT_GROUP_SCHED | 5187 | #ifdef CONFIG_RT_GROUP_SCHED |
4983 | /* | 5188 | /* |
4984 | * Do not allow realtime tasks into groups that have no runtime | 5189 | * Do not allow realtime tasks into groups that have no runtime |
4985 | * assigned. | 5190 | * assigned. |
4986 | */ | 5191 | */ |
4987 | if (user | 5192 | if (rt_bandwidth_enabled() && rt_policy(policy) && |
4988 | && rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0) | 5193 | task_group(p)->rt_bandwidth.rt_runtime == 0) |
4989 | return -EPERM; | 5194 | return -EPERM; |
4990 | #endif | 5195 | #endif |
4991 | 5196 | ||
4992 | retval = security_task_setscheduler(p, policy, param); | 5197 | retval = security_task_setscheduler(p, policy, param); |
4993 | if (retval) | 5198 | if (retval) |
4994 | return retval; | 5199 | return retval; |
5200 | } | ||
5201 | |||
4995 | /* | 5202 | /* |
4996 | * make sure no PI-waiters arrive (or leave) while we are | 5203 | * make sure no PI-waiters arrive (or leave) while we are |
4997 | * changing the priority of the task: | 5204 | * changing the priority of the task: |
@@ -5707,6 +5914,8 @@ static inline void sched_init_granularity(void) | |||
5707 | sysctl_sched_latency = limit; | 5914 | sysctl_sched_latency = limit; |
5708 | 5915 | ||
5709 | sysctl_sched_wakeup_granularity *= factor; | 5916 | sysctl_sched_wakeup_granularity *= factor; |
5917 | |||
5918 | sysctl_sched_shares_ratelimit *= factor; | ||
5710 | } | 5919 | } |
5711 | 5920 | ||
5712 | #ifdef CONFIG_SMP | 5921 | #ifdef CONFIG_SMP |
@@ -5817,7 +6026,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
5817 | set_task_cpu(p, dest_cpu); | 6026 | set_task_cpu(p, dest_cpu); |
5818 | if (on_rq) { | 6027 | if (on_rq) { |
5819 | activate_task(rq_dest, p, 0); | 6028 | activate_task(rq_dest, p, 0); |
5820 | check_preempt_curr(rq_dest, p); | 6029 | check_preempt_curr(rq_dest, p, 0); |
5821 | } | 6030 | } |
5822 | done: | 6031 | done: |
5823 | ret = 1; | 6032 | ret = 1; |
@@ -6142,7 +6351,7 @@ set_table_entry(struct ctl_table *entry, | |||
6142 | static struct ctl_table * | 6351 | static struct ctl_table * |
6143 | sd_alloc_ctl_domain_table(struct sched_domain *sd) | 6352 | sd_alloc_ctl_domain_table(struct sched_domain *sd) |
6144 | { | 6353 | { |
6145 | struct ctl_table *table = sd_alloc_ctl_entry(12); | 6354 | struct ctl_table *table = sd_alloc_ctl_entry(13); |
6146 | 6355 | ||
6147 | if (table == NULL) | 6356 | if (table == NULL) |
6148 | return NULL; | 6357 | return NULL; |
@@ -6170,7 +6379,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd) | |||
6170 | sizeof(int), 0644, proc_dointvec_minmax); | 6379 | sizeof(int), 0644, proc_dointvec_minmax); |
6171 | set_table_entry(&table[10], "flags", &sd->flags, | 6380 | set_table_entry(&table[10], "flags", &sd->flags, |
6172 | sizeof(int), 0644, proc_dointvec_minmax); | 6381 | sizeof(int), 0644, proc_dointvec_minmax); |
6173 | /* &table[11] is terminator */ | 6382 | set_table_entry(&table[11], "name", sd->name, |
6383 | CORENAME_MAX_SIZE, 0444, proc_dostring); | ||
6384 | /* &table[12] is terminator */ | ||
6174 | 6385 | ||
6175 | return table; | 6386 | return table; |
6176 | } | 6387 | } |
@@ -6389,7 +6600,7 @@ static struct notifier_block __cpuinitdata migration_notifier = { | |||
6389 | .priority = 10 | 6600 | .priority = 10 |
6390 | }; | 6601 | }; |
6391 | 6602 | ||
6392 | void __init migration_init(void) | 6603 | static int __init migration_init(void) |
6393 | { | 6604 | { |
6394 | void *cpu = (void *)(long)smp_processor_id(); | 6605 | void *cpu = (void *)(long)smp_processor_id(); |
6395 | int err; | 6606 | int err; |
@@ -6399,7 +6610,10 @@ void __init migration_init(void) | |||
6399 | BUG_ON(err == NOTIFY_BAD); | 6610 | BUG_ON(err == NOTIFY_BAD); |
6400 | migration_call(&migration_notifier, CPU_ONLINE, cpu); | 6611 | migration_call(&migration_notifier, CPU_ONLINE, cpu); |
6401 | register_cpu_notifier(&migration_notifier); | 6612 | register_cpu_notifier(&migration_notifier); |
6613 | |||
6614 | return err; | ||
6402 | } | 6615 | } |
6616 | early_initcall(migration_init); | ||
6403 | #endif | 6617 | #endif |
6404 | 6618 | ||
6405 | #ifdef CONFIG_SMP | 6619 | #ifdef CONFIG_SMP |
@@ -7051,13 +7265,21 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) | |||
7051 | * Non-inlined to reduce accumulated stack pressure in build_sched_domains() | 7265 | * Non-inlined to reduce accumulated stack pressure in build_sched_domains() |
7052 | */ | 7266 | */ |
7053 | 7267 | ||
7268 | #ifdef CONFIG_SCHED_DEBUG | ||
7269 | # define SD_INIT_NAME(sd, type) sd->name = #type | ||
7270 | #else | ||
7271 | # define SD_INIT_NAME(sd, type) do { } while (0) | ||
7272 | #endif | ||
7273 | |||
7054 | #define SD_INIT(sd, type) sd_init_##type(sd) | 7274 | #define SD_INIT(sd, type) sd_init_##type(sd) |
7275 | |||
7055 | #define SD_INIT_FUNC(type) \ | 7276 | #define SD_INIT_FUNC(type) \ |
7056 | static noinline void sd_init_##type(struct sched_domain *sd) \ | 7277 | static noinline void sd_init_##type(struct sched_domain *sd) \ |
7057 | { \ | 7278 | { \ |
7058 | memset(sd, 0, sizeof(*sd)); \ | 7279 | memset(sd, 0, sizeof(*sd)); \ |
7059 | *sd = SD_##type##_INIT; \ | 7280 | *sd = SD_##type##_INIT; \ |
7060 | sd->level = SD_LV_##type; \ | 7281 | sd->level = SD_LV_##type; \ |
7282 | SD_INIT_NAME(sd, type); \ | ||
7061 | } | 7283 | } |
7062 | 7284 | ||
7063 | SD_INIT_FUNC(CPU) | 7285 | SD_INIT_FUNC(CPU) |
@@ -7553,24 +7775,27 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7553 | * and partition_sched_domains() will fallback to the single partition | 7775 | * and partition_sched_domains() will fallback to the single partition |
7554 | * 'fallback_doms', it also forces the domains to be rebuilt. | 7776 | * 'fallback_doms', it also forces the domains to be rebuilt. |
7555 | * | 7777 | * |
7778 | * If doms_new==NULL it will be replaced with cpu_online_map. | ||
7779 | * ndoms_new==0 is a special case for destroying existing domains. | ||
7780 | * It will not create the default domain. | ||
7781 | * | ||
7556 | * Call with hotplug lock held | 7782 | * Call with hotplug lock held |
7557 | */ | 7783 | */ |
7558 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | 7784 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, |
7559 | struct sched_domain_attr *dattr_new) | 7785 | struct sched_domain_attr *dattr_new) |
7560 | { | 7786 | { |
7561 | int i, j; | 7787 | int i, j, n; |
7562 | 7788 | ||
7563 | mutex_lock(&sched_domains_mutex); | 7789 | mutex_lock(&sched_domains_mutex); |
7564 | 7790 | ||
7565 | /* always unregister in case we don't destroy any domains */ | 7791 | /* always unregister in case we don't destroy any domains */ |
7566 | unregister_sched_domain_sysctl(); | 7792 | unregister_sched_domain_sysctl(); |
7567 | 7793 | ||
7568 | if (doms_new == NULL) | 7794 | n = doms_new ? ndoms_new : 0; |
7569 | ndoms_new = 0; | ||
7570 | 7795 | ||
7571 | /* Destroy deleted domains */ | 7796 | /* Destroy deleted domains */ |
7572 | for (i = 0; i < ndoms_cur; i++) { | 7797 | for (i = 0; i < ndoms_cur; i++) { |
7573 | for (j = 0; j < ndoms_new; j++) { | 7798 | for (j = 0; j < n; j++) { |
7574 | if (cpus_equal(doms_cur[i], doms_new[j]) | 7799 | if (cpus_equal(doms_cur[i], doms_new[j]) |
7575 | && dattrs_equal(dattr_cur, i, dattr_new, j)) | 7800 | && dattrs_equal(dattr_cur, i, dattr_new, j)) |
7576 | goto match1; | 7801 | goto match1; |
@@ -7583,7 +7808,6 @@ match1: | |||
7583 | 7808 | ||
7584 | if (doms_new == NULL) { | 7809 | if (doms_new == NULL) { |
7585 | ndoms_cur = 0; | 7810 | ndoms_cur = 0; |
7586 | ndoms_new = 1; | ||
7587 | doms_new = &fallback_doms; | 7811 | doms_new = &fallback_doms; |
7588 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | 7812 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); |
7589 | dattr_new = NULL; | 7813 | dattr_new = NULL; |
@@ -7620,8 +7844,13 @@ match2: | |||
7620 | int arch_reinit_sched_domains(void) | 7844 | int arch_reinit_sched_domains(void) |
7621 | { | 7845 | { |
7622 | get_online_cpus(); | 7846 | get_online_cpus(); |
7847 | |||
7848 | /* Destroy domains first to force the rebuild */ | ||
7849 | partition_sched_domains(0, NULL, NULL); | ||
7850 | |||
7623 | rebuild_sched_domains(); | 7851 | rebuild_sched_domains(); |
7624 | put_online_cpus(); | 7852 | put_online_cpus(); |
7853 | |||
7625 | return 0; | 7854 | return 0; |
7626 | } | 7855 | } |
7627 | 7856 | ||
@@ -7643,34 +7872,34 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | |||
7643 | } | 7872 | } |
7644 | 7873 | ||
7645 | #ifdef CONFIG_SCHED_MC | 7874 | #ifdef CONFIG_SCHED_MC |
7646 | static ssize_t sched_mc_power_savings_show(struct sys_device *dev, | 7875 | static ssize_t sched_mc_power_savings_show(struct sysdev_class *class, |
7647 | struct sysdev_attribute *attr, char *page) | 7876 | char *page) |
7648 | { | 7877 | { |
7649 | return sprintf(page, "%u\n", sched_mc_power_savings); | 7878 | return sprintf(page, "%u\n", sched_mc_power_savings); |
7650 | } | 7879 | } |
7651 | static ssize_t sched_mc_power_savings_store(struct sys_device *dev, | 7880 | static ssize_t sched_mc_power_savings_store(struct sysdev_class *class, |
7652 | struct sysdev_attribute *attr, | ||
7653 | const char *buf, size_t count) | 7881 | const char *buf, size_t count) |
7654 | { | 7882 | { |
7655 | return sched_power_savings_store(buf, count, 0); | 7883 | return sched_power_savings_store(buf, count, 0); |
7656 | } | 7884 | } |
7657 | static SYSDEV_ATTR(sched_mc_power_savings, 0644, sched_mc_power_savings_show, | 7885 | static SYSDEV_CLASS_ATTR(sched_mc_power_savings, 0644, |
7658 | sched_mc_power_savings_store); | 7886 | sched_mc_power_savings_show, |
7887 | sched_mc_power_savings_store); | ||
7659 | #endif | 7888 | #endif |
7660 | 7889 | ||
7661 | #ifdef CONFIG_SCHED_SMT | 7890 | #ifdef CONFIG_SCHED_SMT |
7662 | static ssize_t sched_smt_power_savings_show(struct sys_device *dev, | 7891 | static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev, |
7663 | struct sysdev_attribute *attr, char *page) | 7892 | char *page) |
7664 | { | 7893 | { |
7665 | return sprintf(page, "%u\n", sched_smt_power_savings); | 7894 | return sprintf(page, "%u\n", sched_smt_power_savings); |
7666 | } | 7895 | } |
7667 | static ssize_t sched_smt_power_savings_store(struct sys_device *dev, | 7896 | static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev, |
7668 | struct sysdev_attribute *attr, | ||
7669 | const char *buf, size_t count) | 7897 | const char *buf, size_t count) |
7670 | { | 7898 | { |
7671 | return sched_power_savings_store(buf, count, 1); | 7899 | return sched_power_savings_store(buf, count, 1); |
7672 | } | 7900 | } |
7673 | static SYSDEV_ATTR(sched_smt_power_savings, 0644, sched_smt_power_savings_show, | 7901 | static SYSDEV_CLASS_ATTR(sched_smt_power_savings, 0644, |
7902 | sched_smt_power_savings_show, | ||
7674 | sched_smt_power_savings_store); | 7903 | sched_smt_power_savings_store); |
7675 | #endif | 7904 | #endif |
7676 | 7905 | ||
@@ -7705,7 +7934,7 @@ static int update_sched_domains(struct notifier_block *nfb, | |||
7705 | case CPU_ONLINE_FROZEN: | 7934 | case CPU_ONLINE_FROZEN: |
7706 | case CPU_DEAD: | 7935 | case CPU_DEAD: |
7707 | case CPU_DEAD_FROZEN: | 7936 | case CPU_DEAD_FROZEN: |
7708 | partition_sched_domains(0, NULL, NULL); | 7937 | partition_sched_domains(1, NULL, NULL); |
7709 | return NOTIFY_OK; | 7938 | return NOTIFY_OK; |
7710 | 7939 | ||
7711 | default: | 7940 | default: |
@@ -7970,7 +8199,6 @@ void __init sched_init(void) | |||
7970 | 8199 | ||
7971 | rq = cpu_rq(i); | 8200 | rq = cpu_rq(i); |
7972 | spin_lock_init(&rq->lock); | 8201 | spin_lock_init(&rq->lock); |
7973 | lockdep_set_class(&rq->lock, &rq->rq_lock_key); | ||
7974 | rq->nr_running = 0; | 8202 | rq->nr_running = 0; |
7975 | init_cfs_rq(&rq->cfs, rq); | 8203 | init_cfs_rq(&rq->cfs, rq); |
7976 | init_rt_rq(&rq->rt, rq); | 8204 | init_rt_rq(&rq->rt, rq); |
@@ -8093,20 +8321,25 @@ void __might_sleep(char *file, int line) | |||
8093 | #ifdef in_atomic | 8321 | #ifdef in_atomic |
8094 | static unsigned long prev_jiffy; /* ratelimiting */ | 8322 | static unsigned long prev_jiffy; /* ratelimiting */ |
8095 | 8323 | ||
8096 | if ((in_atomic() || irqs_disabled()) && | 8324 | if ((!in_atomic() && !irqs_disabled()) || |
8097 | system_state == SYSTEM_RUNNING && !oops_in_progress) { | 8325 | system_state != SYSTEM_RUNNING || oops_in_progress) |
8098 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) | 8326 | return; |
8099 | return; | 8327 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) |
8100 | prev_jiffy = jiffies; | 8328 | return; |
8101 | printk(KERN_ERR "BUG: sleeping function called from invalid" | 8329 | prev_jiffy = jiffies; |
8102 | " context at %s:%d\n", file, line); | 8330 | |
8103 | printk("in_atomic():%d, irqs_disabled():%d\n", | 8331 | printk(KERN_ERR |
8104 | in_atomic(), irqs_disabled()); | 8332 | "BUG: sleeping function called from invalid context at %s:%d\n", |
8105 | debug_show_held_locks(current); | 8333 | file, line); |
8106 | if (irqs_disabled()) | 8334 | printk(KERN_ERR |
8107 | print_irqtrace_events(current); | 8335 | "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", |
8108 | dump_stack(); | 8336 | in_atomic(), irqs_disabled(), |
8109 | } | 8337 | current->pid, current->comm); |
8338 | |||
8339 | debug_show_held_locks(current); | ||
8340 | if (irqs_disabled()) | ||
8341 | print_irqtrace_events(current); | ||
8342 | dump_stack(); | ||
8110 | #endif | 8343 | #endif |
8111 | } | 8344 | } |
8112 | EXPORT_SYMBOL(__might_sleep); | 8345 | EXPORT_SYMBOL(__might_sleep); |
@@ -8427,8 +8660,8 @@ struct task_group *sched_create_group(struct task_group *parent) | |||
8427 | WARN_ON(!parent); /* root should already exist */ | 8660 | WARN_ON(!parent); /* root should already exist */ |
8428 | 8661 | ||
8429 | tg->parent = parent; | 8662 | tg->parent = parent; |
8430 | list_add_rcu(&tg->siblings, &parent->children); | ||
8431 | INIT_LIST_HEAD(&tg->children); | 8663 | INIT_LIST_HEAD(&tg->children); |
8664 | list_add_rcu(&tg->siblings, &parent->children); | ||
8432 | spin_unlock_irqrestore(&task_group_lock, flags); | 8665 | spin_unlock_irqrestore(&task_group_lock, flags); |
8433 | 8666 | ||
8434 | return tg; | 8667 | return tg; |
@@ -8604,73 +8837,95 @@ static DEFINE_MUTEX(rt_constraints_mutex); | |||
8604 | static unsigned long to_ratio(u64 period, u64 runtime) | 8837 | static unsigned long to_ratio(u64 period, u64 runtime) |
8605 | { | 8838 | { |
8606 | if (runtime == RUNTIME_INF) | 8839 | if (runtime == RUNTIME_INF) |
8607 | return 1ULL << 16; | 8840 | return 1ULL << 20; |
8608 | 8841 | ||
8609 | return div64_u64(runtime << 16, period); | 8842 | return div64_u64(runtime << 20, period); |
8610 | } | 8843 | } |
8611 | 8844 | ||
8612 | #ifdef CONFIG_CGROUP_SCHED | 8845 | /* Must be called with tasklist_lock held */ |
8613 | static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) | 8846 | static inline int tg_has_rt_tasks(struct task_group *tg) |
8614 | { | 8847 | { |
8615 | struct task_group *tgi, *parent = tg->parent; | 8848 | struct task_struct *g, *p; |
8616 | unsigned long total = 0; | ||
8617 | 8849 | ||
8618 | if (!parent) { | 8850 | do_each_thread(g, p) { |
8619 | if (global_rt_period() < period) | 8851 | if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg) |
8620 | return 0; | 8852 | return 1; |
8853 | } while_each_thread(g, p); | ||
8621 | 8854 | ||
8622 | return to_ratio(period, runtime) < | 8855 | return 0; |
8623 | to_ratio(global_rt_period(), global_rt_runtime()); | 8856 | } |
8624 | } | ||
8625 | 8857 | ||
8626 | if (ktime_to_ns(parent->rt_bandwidth.rt_period) < period) | 8858 | struct rt_schedulable_data { |
8627 | return 0; | 8859 | struct task_group *tg; |
8860 | u64 rt_period; | ||
8861 | u64 rt_runtime; | ||
8862 | }; | ||
8628 | 8863 | ||
8629 | rcu_read_lock(); | 8864 | static int tg_schedulable(struct task_group *tg, void *data) |
8630 | list_for_each_entry_rcu(tgi, &parent->children, siblings) { | 8865 | { |
8631 | if (tgi == tg) | 8866 | struct rt_schedulable_data *d = data; |
8632 | continue; | 8867 | struct task_group *child; |
8868 | unsigned long total, sum = 0; | ||
8869 | u64 period, runtime; | ||
8870 | |||
8871 | period = ktime_to_ns(tg->rt_bandwidth.rt_period); | ||
8872 | runtime = tg->rt_bandwidth.rt_runtime; | ||
8633 | 8873 | ||
8634 | total += to_ratio(ktime_to_ns(tgi->rt_bandwidth.rt_period), | 8874 | if (tg == d->tg) { |
8635 | tgi->rt_bandwidth.rt_runtime); | 8875 | period = d->rt_period; |
8876 | runtime = d->rt_runtime; | ||
8636 | } | 8877 | } |
8637 | rcu_read_unlock(); | ||
8638 | 8878 | ||
8639 | return total + to_ratio(period, runtime) <= | 8879 | /* |
8640 | to_ratio(ktime_to_ns(parent->rt_bandwidth.rt_period), | 8880 | * Cannot have more runtime than the period. |
8641 | parent->rt_bandwidth.rt_runtime); | 8881 | */ |
8642 | } | 8882 | if (runtime > period && runtime != RUNTIME_INF) |
8643 | #elif defined CONFIG_USER_SCHED | 8883 | return -EINVAL; |
8644 | static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) | ||
8645 | { | ||
8646 | struct task_group *tgi; | ||
8647 | unsigned long total = 0; | ||
8648 | unsigned long global_ratio = | ||
8649 | to_ratio(global_rt_period(), global_rt_runtime()); | ||
8650 | 8884 | ||
8651 | rcu_read_lock(); | 8885 | /* |
8652 | list_for_each_entry_rcu(tgi, &task_groups, list) { | 8886 | * Ensure we don't starve existing RT tasks. |
8653 | if (tgi == tg) | 8887 | */ |
8654 | continue; | 8888 | if (rt_bandwidth_enabled() && !runtime && tg_has_rt_tasks(tg)) |
8889 | return -EBUSY; | ||
8890 | |||
8891 | total = to_ratio(period, runtime); | ||
8892 | |||
8893 | /* | ||
8894 | * Nobody can have more than the global setting allows. | ||
8895 | */ | ||
8896 | if (total > to_ratio(global_rt_period(), global_rt_runtime())) | ||
8897 | return -EINVAL; | ||
8898 | |||
8899 | /* | ||
8900 | * The sum of our children's runtime should not exceed our own. | ||
8901 | */ | ||
8902 | list_for_each_entry_rcu(child, &tg->children, siblings) { | ||
8903 | period = ktime_to_ns(child->rt_bandwidth.rt_period); | ||
8904 | runtime = child->rt_bandwidth.rt_runtime; | ||
8655 | 8905 | ||
8656 | total += to_ratio(ktime_to_ns(tgi->rt_bandwidth.rt_period), | 8906 | if (child == d->tg) { |
8657 | tgi->rt_bandwidth.rt_runtime); | 8907 | period = d->rt_period; |
8908 | runtime = d->rt_runtime; | ||
8909 | } | ||
8910 | |||
8911 | sum += to_ratio(period, runtime); | ||
8658 | } | 8912 | } |
8659 | rcu_read_unlock(); | ||
8660 | 8913 | ||
8661 | return total + to_ratio(period, runtime) < global_ratio; | 8914 | if (sum > total) |
8915 | return -EINVAL; | ||
8916 | |||
8917 | return 0; | ||
8662 | } | 8918 | } |
8663 | #endif | ||
8664 | 8919 | ||
8665 | /* Must be called with tasklist_lock held */ | 8920 | static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) |
8666 | static inline int tg_has_rt_tasks(struct task_group *tg) | ||
8667 | { | 8921 | { |
8668 | struct task_struct *g, *p; | 8922 | struct rt_schedulable_data data = { |
8669 | do_each_thread(g, p) { | 8923 | .tg = tg, |
8670 | if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg) | 8924 | .rt_period = period, |
8671 | return 1; | 8925 | .rt_runtime = runtime, |
8672 | } while_each_thread(g, p); | 8926 | }; |
8673 | return 0; | 8927 | |
8928 | return walk_tg_tree(tg_schedulable, tg_nop, &data); | ||
8674 | } | 8929 | } |
8675 | 8930 | ||
8676 | static int tg_set_bandwidth(struct task_group *tg, | 8931 | static int tg_set_bandwidth(struct task_group *tg, |
@@ -8680,14 +8935,9 @@ static int tg_set_bandwidth(struct task_group *tg, | |||
8680 | 8935 | ||
8681 | mutex_lock(&rt_constraints_mutex); | 8936 | mutex_lock(&rt_constraints_mutex); |
8682 | read_lock(&tasklist_lock); | 8937 | read_lock(&tasklist_lock); |
8683 | if (rt_runtime == 0 && tg_has_rt_tasks(tg)) { | 8938 | err = __rt_schedulable(tg, rt_period, rt_runtime); |
8684 | err = -EBUSY; | 8939 | if (err) |
8685 | goto unlock; | ||
8686 | } | ||
8687 | if (!__rt_schedulable(tg, rt_period, rt_runtime)) { | ||
8688 | err = -EINVAL; | ||
8689 | goto unlock; | 8940 | goto unlock; |
8690 | } | ||
8691 | 8941 | ||
8692 | spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); | 8942 | spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); |
8693 | tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); | 8943 | tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); |
@@ -8756,16 +9006,25 @@ long sched_group_rt_period(struct task_group *tg) | |||
8756 | 9006 | ||
8757 | static int sched_rt_global_constraints(void) | 9007 | static int sched_rt_global_constraints(void) |
8758 | { | 9008 | { |
8759 | struct task_group *tg = &root_task_group; | 9009 | u64 runtime, period; |
8760 | u64 rt_runtime, rt_period; | ||
8761 | int ret = 0; | 9010 | int ret = 0; |
8762 | 9011 | ||
8763 | rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period); | 9012 | if (sysctl_sched_rt_period <= 0) |
8764 | rt_runtime = tg->rt_bandwidth.rt_runtime; | 9013 | return -EINVAL; |
9014 | |||
9015 | runtime = global_rt_runtime(); | ||
9016 | period = global_rt_period(); | ||
9017 | |||
9018 | /* | ||
9019 | * Sanity check on the sysctl variables. | ||
9020 | */ | ||
9021 | if (runtime > period && runtime != RUNTIME_INF) | ||
9022 | return -EINVAL; | ||
8765 | 9023 | ||
8766 | mutex_lock(&rt_constraints_mutex); | 9024 | mutex_lock(&rt_constraints_mutex); |
8767 | if (!__rt_schedulable(tg, rt_period, rt_runtime)) | 9025 | read_lock(&tasklist_lock); |
8768 | ret = -EINVAL; | 9026 | ret = __rt_schedulable(NULL, 0, 0); |
9027 | read_unlock(&tasklist_lock); | ||
8769 | mutex_unlock(&rt_constraints_mutex); | 9028 | mutex_unlock(&rt_constraints_mutex); |
8770 | 9029 | ||
8771 | return ret; | 9030 | return ret; |
@@ -8776,6 +9035,9 @@ static int sched_rt_global_constraints(void) | |||
8776 | unsigned long flags; | 9035 | unsigned long flags; |
8777 | int i; | 9036 | int i; |
8778 | 9037 | ||
9038 | if (sysctl_sched_rt_period <= 0) | ||
9039 | return -EINVAL; | ||
9040 | |||
8779 | spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags); | 9041 | spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags); |
8780 | for_each_possible_cpu(i) { | 9042 | for_each_possible_cpu(i) { |
8781 | struct rt_rq *rt_rq = &cpu_rq(i)->rt; | 9043 | struct rt_rq *rt_rq = &cpu_rq(i)->rt; |
@@ -8836,7 +9098,6 @@ cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
8836 | 9098 | ||
8837 | if (!cgrp->parent) { | 9099 | if (!cgrp->parent) { |
8838 | /* This is early initialization for the top cgroup */ | 9100 | /* This is early initialization for the top cgroup */ |
8839 | init_task_group.css.cgroup = cgrp; | ||
8840 | return &init_task_group.css; | 9101 | return &init_task_group.css; |
8841 | } | 9102 | } |
8842 | 9103 | ||
@@ -8845,9 +9106,6 @@ cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
8845 | if (IS_ERR(tg)) | 9106 | if (IS_ERR(tg)) |
8846 | return ERR_PTR(-ENOMEM); | 9107 | return ERR_PTR(-ENOMEM); |
8847 | 9108 | ||
8848 | /* Bind the cgroup to task_group object we just created */ | ||
8849 | tg->css.cgroup = cgrp; | ||
8850 | |||
8851 | return &tg->css; | 9109 | return &tg->css; |
8852 | } | 9110 | } |
8853 | 9111 | ||
diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c index 22ed55d1167f..e8ab096ddfe3 100644 --- a/kernel/sched_clock.c +++ b/kernel/sched_clock.c | |||
@@ -12,19 +12,17 @@ | |||
12 | * | 12 | * |
13 | * Create a semi stable clock from a mixture of other events, including: | 13 | * Create a semi stable clock from a mixture of other events, including: |
14 | * - gtod | 14 | * - gtod |
15 | * - jiffies | ||
16 | * - sched_clock() | 15 | * - sched_clock() |
17 | * - explicit idle events | 16 | * - explicit idle events |
18 | * | 17 | * |
19 | * We use gtod as base and the unstable clock deltas. The deltas are filtered, | 18 | * We use gtod as base and the unstable clock deltas. The deltas are filtered, |
20 | * making it monotonic and keeping it within an expected window. This window | 19 | * making it monotonic and keeping it within an expected window. |
21 | * is set up using jiffies. | ||
22 | * | 20 | * |
23 | * Furthermore, explicit sleep and wakeup hooks allow us to account for time | 21 | * Furthermore, explicit sleep and wakeup hooks allow us to account for time |
24 | * that is otherwise invisible (TSC gets stopped). | 22 | * that is otherwise invisible (TSC gets stopped). |
25 | * | 23 | * |
26 | * The clock: sched_clock_cpu() is monotonic per cpu, and should be somewhat | 24 | * The clock: sched_clock_cpu() is monotonic per cpu, and should be somewhat |
27 | * consistent between cpus (never more than 1 jiffies difference). | 25 | * consistent between cpus (never more than 2 jiffies difference). |
28 | */ | 26 | */ |
29 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
30 | #include <linux/percpu.h> | 28 | #include <linux/percpu.h> |
@@ -32,13 +30,19 @@ | |||
32 | #include <linux/ktime.h> | 30 | #include <linux/ktime.h> |
33 | #include <linux/module.h> | 31 | #include <linux/module.h> |
34 | 32 | ||
33 | /* | ||
34 | * Scheduler clock - returns current time in nanosec units. | ||
35 | * This is default implementation. | ||
36 | * Architectures and sub-architectures can override this. | ||
37 | */ | ||
38 | unsigned long long __attribute__((weak)) sched_clock(void) | ||
39 | { | ||
40 | return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ); | ||
41 | } | ||
35 | 42 | ||
36 | #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK | 43 | static __read_mostly int sched_clock_running; |
37 | 44 | ||
38 | #define MULTI_SHIFT 15 | 45 | #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK |
39 | /* Max is double, Min is 1/2 */ | ||
40 | #define MAX_MULTI (2LL << MULTI_SHIFT) | ||
41 | #define MIN_MULTI (1LL << (MULTI_SHIFT-1)) | ||
42 | 46 | ||
43 | struct sched_clock_data { | 47 | struct sched_clock_data { |
44 | /* | 48 | /* |
@@ -48,15 +52,9 @@ struct sched_clock_data { | |||
48 | */ | 52 | */ |
49 | raw_spinlock_t lock; | 53 | raw_spinlock_t lock; |
50 | 54 | ||
51 | unsigned long tick_jiffies; | ||
52 | u64 prev_raw; | ||
53 | u64 tick_raw; | 55 | u64 tick_raw; |
54 | u64 tick_gtod; | 56 | u64 tick_gtod; |
55 | u64 clock; | 57 | u64 clock; |
56 | s64 multi; | ||
57 | #ifdef CONFIG_NO_HZ | ||
58 | int check_max; | ||
59 | #endif | ||
60 | }; | 58 | }; |
61 | 59 | ||
62 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct sched_clock_data, sched_clock_data); | 60 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct sched_clock_data, sched_clock_data); |
@@ -71,121 +69,69 @@ static inline struct sched_clock_data *cpu_sdc(int cpu) | |||
71 | return &per_cpu(sched_clock_data, cpu); | 69 | return &per_cpu(sched_clock_data, cpu); |
72 | } | 70 | } |
73 | 71 | ||
74 | static __read_mostly int sched_clock_running; | ||
75 | |||
76 | void sched_clock_init(void) | 72 | void sched_clock_init(void) |
77 | { | 73 | { |
78 | u64 ktime_now = ktime_to_ns(ktime_get()); | 74 | u64 ktime_now = ktime_to_ns(ktime_get()); |
79 | unsigned long now_jiffies = jiffies; | ||
80 | int cpu; | 75 | int cpu; |
81 | 76 | ||
82 | for_each_possible_cpu(cpu) { | 77 | for_each_possible_cpu(cpu) { |
83 | struct sched_clock_data *scd = cpu_sdc(cpu); | 78 | struct sched_clock_data *scd = cpu_sdc(cpu); |
84 | 79 | ||
85 | scd->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | 80 | scd->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
86 | scd->tick_jiffies = now_jiffies; | ||
87 | scd->prev_raw = 0; | ||
88 | scd->tick_raw = 0; | 81 | scd->tick_raw = 0; |
89 | scd->tick_gtod = ktime_now; | 82 | scd->tick_gtod = ktime_now; |
90 | scd->clock = ktime_now; | 83 | scd->clock = ktime_now; |
91 | scd->multi = 1 << MULTI_SHIFT; | ||
92 | #ifdef CONFIG_NO_HZ | ||
93 | scd->check_max = 1; | ||
94 | #endif | ||
95 | } | 84 | } |
96 | 85 | ||
97 | sched_clock_running = 1; | 86 | sched_clock_running = 1; |
98 | } | 87 | } |
99 | 88 | ||
100 | #ifdef CONFIG_NO_HZ | ||
101 | /* | 89 | /* |
102 | * The dynamic ticks makes the delta jiffies inaccurate. This | 90 | * min,max except they take wrapping into account |
103 | * prevents us from checking the maximum time update. | ||
104 | * Disable the maximum check during stopped ticks. | ||
105 | */ | 91 | */ |
106 | void sched_clock_tick_stop(int cpu) | ||
107 | { | ||
108 | struct sched_clock_data *scd = cpu_sdc(cpu); | ||
109 | |||
110 | scd->check_max = 0; | ||
111 | } | ||
112 | 92 | ||
113 | void sched_clock_tick_start(int cpu) | 93 | static inline u64 wrap_min(u64 x, u64 y) |
114 | { | 94 | { |
115 | struct sched_clock_data *scd = cpu_sdc(cpu); | 95 | return (s64)(x - y) < 0 ? x : y; |
116 | |||
117 | scd->check_max = 1; | ||
118 | } | 96 | } |
119 | 97 | ||
120 | static int check_max(struct sched_clock_data *scd) | 98 | static inline u64 wrap_max(u64 x, u64 y) |
121 | { | 99 | { |
122 | return scd->check_max; | 100 | return (s64)(x - y) > 0 ? x : y; |
123 | } | 101 | } |
124 | #else | ||
125 | static int check_max(struct sched_clock_data *scd) | ||
126 | { | ||
127 | return 1; | ||
128 | } | ||
129 | #endif /* CONFIG_NO_HZ */ | ||
130 | 102 | ||
131 | /* | 103 | /* |
132 | * update the percpu scd from the raw @now value | 104 | * update the percpu scd from the raw @now value |
133 | * | 105 | * |
134 | * - filter out backward motion | 106 | * - filter out backward motion |
135 | * - use jiffies to generate a min,max window to clip the raw values | 107 | * - use the GTOD tick value to create a window to filter crazy TSC values |
136 | */ | 108 | */ |
137 | static void __update_sched_clock(struct sched_clock_data *scd, u64 now, u64 *time) | 109 | static u64 __update_sched_clock(struct sched_clock_data *scd, u64 now) |
138 | { | 110 | { |
139 | unsigned long now_jiffies = jiffies; | 111 | s64 delta = now - scd->tick_raw; |
140 | long delta_jiffies = now_jiffies - scd->tick_jiffies; | 112 | u64 clock, min_clock, max_clock; |
141 | u64 clock = scd->clock; | ||
142 | u64 min_clock, max_clock; | ||
143 | s64 delta = now - scd->prev_raw; | ||
144 | 113 | ||
145 | WARN_ON_ONCE(!irqs_disabled()); | 114 | WARN_ON_ONCE(!irqs_disabled()); |
146 | 115 | ||
147 | /* | 116 | if (unlikely(delta < 0)) |
148 | * At schedule tick the clock can be just under the gtod. We don't | 117 | delta = 0; |
149 | * want to push it too prematurely. | ||
150 | */ | ||
151 | min_clock = scd->tick_gtod + (delta_jiffies * TICK_NSEC); | ||
152 | if (min_clock > TICK_NSEC) | ||
153 | min_clock -= TICK_NSEC / 2; | ||
154 | |||
155 | if (unlikely(delta < 0)) { | ||
156 | clock++; | ||
157 | goto out; | ||
158 | } | ||
159 | 118 | ||
160 | /* | 119 | /* |
161 | * The clock must stay within a jiffie of the gtod. | 120 | * scd->clock = clamp(scd->tick_gtod + delta, |
162 | * But since we may be at the start of a jiffy or the end of one | 121 | * max(scd->tick_gtod, scd->clock), |
163 | * we add another jiffy buffer. | 122 | * scd->tick_gtod + TICK_NSEC); |
164 | */ | 123 | */ |
165 | max_clock = scd->tick_gtod + (2 + delta_jiffies) * TICK_NSEC; | ||
166 | 124 | ||
167 | delta *= scd->multi; | 125 | clock = scd->tick_gtod + delta; |
168 | delta >>= MULTI_SHIFT; | 126 | min_clock = wrap_max(scd->tick_gtod, scd->clock); |
127 | max_clock = scd->tick_gtod + TICK_NSEC; | ||
169 | 128 | ||
170 | if (unlikely(clock + delta > max_clock) && check_max(scd)) { | 129 | clock = wrap_max(clock, min_clock); |
171 | if (clock < max_clock) | 130 | clock = wrap_min(clock, max_clock); |
172 | clock = max_clock; | ||
173 | else | ||
174 | clock++; | ||
175 | } else { | ||
176 | clock += delta; | ||
177 | } | ||
178 | 131 | ||
179 | out: | 132 | scd->clock = clock; |
180 | if (unlikely(clock < min_clock)) | ||
181 | clock = min_clock; | ||
182 | 133 | ||
183 | if (time) | 134 | return scd->clock; |
184 | *time = clock; | ||
185 | else { | ||
186 | scd->prev_raw = now; | ||
187 | scd->clock = clock; | ||
188 | } | ||
189 | } | 135 | } |
190 | 136 | ||
191 | static void lock_double_clock(struct sched_clock_data *data1, | 137 | static void lock_double_clock(struct sched_clock_data *data1, |
@@ -203,7 +149,7 @@ static void lock_double_clock(struct sched_clock_data *data1, | |||
203 | u64 sched_clock_cpu(int cpu) | 149 | u64 sched_clock_cpu(int cpu) |
204 | { | 150 | { |
205 | struct sched_clock_data *scd = cpu_sdc(cpu); | 151 | struct sched_clock_data *scd = cpu_sdc(cpu); |
206 | u64 now, clock; | 152 | u64 now, clock, this_clock, remote_clock; |
207 | 153 | ||
208 | if (unlikely(!sched_clock_running)) | 154 | if (unlikely(!sched_clock_running)) |
209 | return 0ull; | 155 | return 0ull; |
@@ -212,43 +158,44 @@ u64 sched_clock_cpu(int cpu) | |||
212 | now = sched_clock(); | 158 | now = sched_clock(); |
213 | 159 | ||
214 | if (cpu != raw_smp_processor_id()) { | 160 | if (cpu != raw_smp_processor_id()) { |
215 | /* | ||
216 | * in order to update a remote cpu's clock based on our | ||
217 | * unstable raw time rebase it against: | ||
218 | * tick_raw (offset between raw counters) | ||
219 | * tick_gotd (tick offset between cpus) | ||
220 | */ | ||
221 | struct sched_clock_data *my_scd = this_scd(); | 161 | struct sched_clock_data *my_scd = this_scd(); |
222 | 162 | ||
223 | lock_double_clock(scd, my_scd); | 163 | lock_double_clock(scd, my_scd); |
224 | 164 | ||
225 | now -= my_scd->tick_raw; | 165 | this_clock = __update_sched_clock(my_scd, now); |
226 | now += scd->tick_raw; | 166 | remote_clock = scd->clock; |
227 | 167 | ||
228 | now += my_scd->tick_gtod; | 168 | /* |
229 | now -= scd->tick_gtod; | 169 | * Use the opportunity that we have both locks |
170 | * taken to couple the two clocks: we take the | ||
171 | * larger time as the latest time for both | ||
172 | * runqueues. (this creates monotonic movement) | ||
173 | */ | ||
174 | if (likely((s64)(remote_clock - this_clock) < 0)) { | ||
175 | clock = this_clock; | ||
176 | scd->clock = clock; | ||
177 | } else { | ||
178 | /* | ||
179 | * Should be rare, but possible: | ||
180 | */ | ||
181 | clock = remote_clock; | ||
182 | my_scd->clock = remote_clock; | ||
183 | } | ||
230 | 184 | ||
231 | __raw_spin_unlock(&my_scd->lock); | 185 | __raw_spin_unlock(&my_scd->lock); |
232 | |||
233 | __update_sched_clock(scd, now, &clock); | ||
234 | |||
235 | __raw_spin_unlock(&scd->lock); | ||
236 | |||
237 | } else { | 186 | } else { |
238 | __raw_spin_lock(&scd->lock); | 187 | __raw_spin_lock(&scd->lock); |
239 | __update_sched_clock(scd, now, NULL); | 188 | clock = __update_sched_clock(scd, now); |
240 | clock = scd->clock; | ||
241 | __raw_spin_unlock(&scd->lock); | ||
242 | } | 189 | } |
243 | 190 | ||
191 | __raw_spin_unlock(&scd->lock); | ||
192 | |||
244 | return clock; | 193 | return clock; |
245 | } | 194 | } |
246 | 195 | ||
247 | void sched_clock_tick(void) | 196 | void sched_clock_tick(void) |
248 | { | 197 | { |
249 | struct sched_clock_data *scd = this_scd(); | 198 | struct sched_clock_data *scd = this_scd(); |
250 | unsigned long now_jiffies = jiffies; | ||
251 | s64 mult, delta_gtod, delta_raw; | ||
252 | u64 now, now_gtod; | 199 | u64 now, now_gtod; |
253 | 200 | ||
254 | if (unlikely(!sched_clock_running)) | 201 | if (unlikely(!sched_clock_running)) |
@@ -260,29 +207,9 @@ void sched_clock_tick(void) | |||
260 | now = sched_clock(); | 207 | now = sched_clock(); |
261 | 208 | ||
262 | __raw_spin_lock(&scd->lock); | 209 | __raw_spin_lock(&scd->lock); |
263 | __update_sched_clock(scd, now, NULL); | ||
264 | /* | ||
265 | * update tick_gtod after __update_sched_clock() because that will | ||
266 | * already observe 1 new jiffy; adding a new tick_gtod to that would | ||
267 | * increase the clock 2 jiffies. | ||
268 | */ | ||
269 | delta_gtod = now_gtod - scd->tick_gtod; | ||
270 | delta_raw = now - scd->tick_raw; | ||
271 | |||
272 | if ((long)delta_raw > 0) { | ||
273 | mult = delta_gtod << MULTI_SHIFT; | ||
274 | do_div(mult, delta_raw); | ||
275 | scd->multi = mult; | ||
276 | if (scd->multi > MAX_MULTI) | ||
277 | scd->multi = MAX_MULTI; | ||
278 | else if (scd->multi < MIN_MULTI) | ||
279 | scd->multi = MIN_MULTI; | ||
280 | } else | ||
281 | scd->multi = 1 << MULTI_SHIFT; | ||
282 | |||
283 | scd->tick_raw = now; | 210 | scd->tick_raw = now; |
284 | scd->tick_gtod = now_gtod; | 211 | scd->tick_gtod = now_gtod; |
285 | scd->tick_jiffies = now_jiffies; | 212 | __update_sched_clock(scd, now); |
286 | __raw_spin_unlock(&scd->lock); | 213 | __raw_spin_unlock(&scd->lock); |
287 | } | 214 | } |
288 | 215 | ||
@@ -300,37 +227,28 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_sleep_event); | |||
300 | */ | 227 | */ |
301 | void sched_clock_idle_wakeup_event(u64 delta_ns) | 228 | void sched_clock_idle_wakeup_event(u64 delta_ns) |
302 | { | 229 | { |
303 | struct sched_clock_data *scd = this_scd(); | 230 | sched_clock_tick(); |
304 | u64 now = sched_clock(); | ||
305 | |||
306 | /* | ||
307 | * Override the previous timestamp and ignore all | ||
308 | * sched_clock() deltas that occured while we idled, | ||
309 | * and use the PM-provided delta_ns to advance the | ||
310 | * rq clock: | ||
311 | */ | ||
312 | __raw_spin_lock(&scd->lock); | ||
313 | scd->prev_raw = now; | ||
314 | scd->clock += delta_ns; | ||
315 | scd->multi = 1 << MULTI_SHIFT; | ||
316 | __raw_spin_unlock(&scd->lock); | ||
317 | |||
318 | touch_softlockup_watchdog(); | 231 | touch_softlockup_watchdog(); |
319 | } | 232 | } |
320 | EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); | 233 | EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); |
321 | 234 | ||
322 | #endif | 235 | #else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */ |
323 | 236 | ||
324 | /* | 237 | void sched_clock_init(void) |
325 | * Scheduler clock - returns current time in nanosec units. | ||
326 | * This is default implementation. | ||
327 | * Architectures and sub-architectures can override this. | ||
328 | */ | ||
329 | unsigned long long __attribute__((weak)) sched_clock(void) | ||
330 | { | 238 | { |
331 | return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ); | 239 | sched_clock_running = 1; |
332 | } | 240 | } |
333 | 241 | ||
242 | u64 sched_clock_cpu(int cpu) | ||
243 | { | ||
244 | if (unlikely(!sched_clock_running)) | ||
245 | return 0; | ||
246 | |||
247 | return sched_clock(); | ||
248 | } | ||
249 | |||
250 | #endif | ||
251 | |||
334 | unsigned long long cpu_clock(int cpu) | 252 | unsigned long long cpu_clock(int cpu) |
335 | { | 253 | { |
336 | unsigned long long clock; | 254 | unsigned long long clock; |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index cf2cd6ce4cb2..18fd17172eb6 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -409,64 +409,6 @@ static u64 sched_vslice_add(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
409 | } | 409 | } |
410 | 410 | ||
411 | /* | 411 | /* |
412 | * The goal of calc_delta_asym() is to be asymmetrically around NICE_0_LOAD, in | ||
413 | * that it favours >=0 over <0. | ||
414 | * | ||
415 | * -20 | | ||
416 | * | | ||
417 | * 0 --------+------- | ||
418 | * .' | ||
419 | * 19 .' | ||
420 | * | ||
421 | */ | ||
422 | static unsigned long | ||
423 | calc_delta_asym(unsigned long delta, struct sched_entity *se) | ||
424 | { | ||
425 | struct load_weight lw = { | ||
426 | .weight = NICE_0_LOAD, | ||
427 | .inv_weight = 1UL << (WMULT_SHIFT-NICE_0_SHIFT) | ||
428 | }; | ||
429 | |||
430 | for_each_sched_entity(se) { | ||
431 | struct load_weight *se_lw = &se->load; | ||
432 | unsigned long rw = cfs_rq_of(se)->load.weight; | ||
433 | |||
434 | #ifdef CONFIG_FAIR_SCHED_GROUP | ||
435 | struct cfs_rq *cfs_rq = se->my_q; | ||
436 | struct task_group *tg = NULL | ||
437 | |||
438 | if (cfs_rq) | ||
439 | tg = cfs_rq->tg; | ||
440 | |||
441 | if (tg && tg->shares < NICE_0_LOAD) { | ||
442 | /* | ||
443 | * scale shares to what it would have been had | ||
444 | * tg->weight been NICE_0_LOAD: | ||
445 | * | ||
446 | * weight = 1024 * shares / tg->weight | ||
447 | */ | ||
448 | lw.weight *= se->load.weight; | ||
449 | lw.weight /= tg->shares; | ||
450 | |||
451 | lw.inv_weight = 0; | ||
452 | |||
453 | se_lw = &lw; | ||
454 | rw += lw.weight - se->load.weight; | ||
455 | } else | ||
456 | #endif | ||
457 | |||
458 | if (se->load.weight < NICE_0_LOAD) { | ||
459 | se_lw = &lw; | ||
460 | rw += NICE_0_LOAD - se->load.weight; | ||
461 | } | ||
462 | |||
463 | delta = calc_delta_mine(delta, rw, se_lw); | ||
464 | } | ||
465 | |||
466 | return delta; | ||
467 | } | ||
468 | |||
469 | /* | ||
470 | * Update the current task's runtime statistics. Skip current tasks that | 412 | * Update the current task's runtime statistics. Skip current tasks that |
471 | * are not in our scheduling class. | 413 | * are not in our scheduling class. |
472 | */ | 414 | */ |
@@ -586,11 +528,12 @@ account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
586 | update_load_add(&cfs_rq->load, se->load.weight); | 528 | update_load_add(&cfs_rq->load, se->load.weight); |
587 | if (!parent_entity(se)) | 529 | if (!parent_entity(se)) |
588 | inc_cpu_load(rq_of(cfs_rq), se->load.weight); | 530 | inc_cpu_load(rq_of(cfs_rq), se->load.weight); |
589 | if (entity_is_task(se)) | 531 | if (entity_is_task(se)) { |
590 | add_cfs_task_weight(cfs_rq, se->load.weight); | 532 | add_cfs_task_weight(cfs_rq, se->load.weight); |
533 | list_add(&se->group_node, &cfs_rq->tasks); | ||
534 | } | ||
591 | cfs_rq->nr_running++; | 535 | cfs_rq->nr_running++; |
592 | se->on_rq = 1; | 536 | se->on_rq = 1; |
593 | list_add(&se->group_node, &cfs_rq->tasks); | ||
594 | } | 537 | } |
595 | 538 | ||
596 | static void | 539 | static void |
@@ -599,11 +542,12 @@ account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
599 | update_load_sub(&cfs_rq->load, se->load.weight); | 542 | update_load_sub(&cfs_rq->load, se->load.weight); |
600 | if (!parent_entity(se)) | 543 | if (!parent_entity(se)) |
601 | dec_cpu_load(rq_of(cfs_rq), se->load.weight); | 544 | dec_cpu_load(rq_of(cfs_rq), se->load.weight); |
602 | if (entity_is_task(se)) | 545 | if (entity_is_task(se)) { |
603 | add_cfs_task_weight(cfs_rq, -se->load.weight); | 546 | add_cfs_task_weight(cfs_rq, -se->load.weight); |
547 | list_del_init(&se->group_node); | ||
548 | } | ||
604 | cfs_rq->nr_running--; | 549 | cfs_rq->nr_running--; |
605 | se->on_rq = 0; | 550 | se->on_rq = 0; |
606 | list_del_init(&se->group_node); | ||
607 | } | 551 | } |
608 | 552 | ||
609 | static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) | 553 | static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) |
@@ -899,7 +843,7 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p) | |||
899 | * doesn't make sense. Rely on vruntime for fairness. | 843 | * doesn't make sense. Rely on vruntime for fairness. |
900 | */ | 844 | */ |
901 | if (rq->curr != p) | 845 | if (rq->curr != p) |
902 | delta = max(10000LL, delta); | 846 | delta = max_t(s64, 10000LL, delta); |
903 | 847 | ||
904 | hrtick_start(rq, delta); | 848 | hrtick_start(rq, delta); |
905 | } | 849 | } |
@@ -1085,7 +1029,6 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1085 | long wl, long wg) | 1029 | long wl, long wg) |
1086 | { | 1030 | { |
1087 | struct sched_entity *se = tg->se[cpu]; | 1031 | struct sched_entity *se = tg->se[cpu]; |
1088 | long more_w; | ||
1089 | 1032 | ||
1090 | if (!tg->parent) | 1033 | if (!tg->parent) |
1091 | return wl; | 1034 | return wl; |
@@ -1097,18 +1040,17 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1097 | if (!wl && sched_feat(ASYM_EFF_LOAD)) | 1040 | if (!wl && sched_feat(ASYM_EFF_LOAD)) |
1098 | return wl; | 1041 | return wl; |
1099 | 1042 | ||
1100 | /* | ||
1101 | * Instead of using this increment, also add the difference | ||
1102 | * between when the shares were last updated and now. | ||
1103 | */ | ||
1104 | more_w = se->my_q->load.weight - se->my_q->rq_weight; | ||
1105 | wl += more_w; | ||
1106 | wg += more_w; | ||
1107 | |||
1108 | for_each_sched_entity(se) { | 1043 | for_each_sched_entity(se) { |
1109 | #define D(n) (likely(n) ? (n) : 1) | ||
1110 | |||
1111 | long S, rw, s, a, b; | 1044 | long S, rw, s, a, b; |
1045 | long more_w; | ||
1046 | |||
1047 | /* | ||
1048 | * Instead of using this increment, also add the difference | ||
1049 | * between when the shares were last updated and now. | ||
1050 | */ | ||
1051 | more_w = se->my_q->load.weight - se->my_q->rq_weight; | ||
1052 | wl += more_w; | ||
1053 | wg += more_w; | ||
1112 | 1054 | ||
1113 | S = se->my_q->tg->shares; | 1055 | S = se->my_q->tg->shares; |
1114 | s = se->my_q->shares; | 1056 | s = se->my_q->shares; |
@@ -1117,7 +1059,11 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1117 | a = S*(rw + wl); | 1059 | a = S*(rw + wl); |
1118 | b = S*rw + s*wg; | 1060 | b = S*rw + s*wg; |
1119 | 1061 | ||
1120 | wl = s*(a-b)/D(b); | 1062 | wl = s*(a-b); |
1063 | |||
1064 | if (likely(b)) | ||
1065 | wl /= b; | ||
1066 | |||
1121 | /* | 1067 | /* |
1122 | * Assume the group is already running and will | 1068 | * Assume the group is already running and will |
1123 | * thus already be accounted for in the weight. | 1069 | * thus already be accounted for in the weight. |
@@ -1126,7 +1072,6 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1126 | * alter the group weight. | 1072 | * alter the group weight. |
1127 | */ | 1073 | */ |
1128 | wg = 0; | 1074 | wg = 0; |
1129 | #undef D | ||
1130 | } | 1075 | } |
1131 | 1076 | ||
1132 | return wl; | 1077 | return wl; |
@@ -1143,7 +1088,7 @@ static inline unsigned long effective_load(struct task_group *tg, int cpu, | |||
1143 | #endif | 1088 | #endif |
1144 | 1089 | ||
1145 | static int | 1090 | static int |
1146 | wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq, | 1091 | wake_affine(struct sched_domain *this_sd, struct rq *this_rq, |
1147 | struct task_struct *p, int prev_cpu, int this_cpu, int sync, | 1092 | struct task_struct *p, int prev_cpu, int this_cpu, int sync, |
1148 | int idx, unsigned long load, unsigned long this_load, | 1093 | int idx, unsigned long load, unsigned long this_load, |
1149 | unsigned int imbalance) | 1094 | unsigned int imbalance) |
@@ -1158,6 +1103,11 @@ wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq, | |||
1158 | if (!(this_sd->flags & SD_WAKE_AFFINE) || !sched_feat(AFFINE_WAKEUPS)) | 1103 | if (!(this_sd->flags & SD_WAKE_AFFINE) || !sched_feat(AFFINE_WAKEUPS)) |
1159 | return 0; | 1104 | return 0; |
1160 | 1105 | ||
1106 | if (!sync && sched_feat(SYNC_WAKEUPS) && | ||
1107 | curr->se.avg_overlap < sysctl_sched_migration_cost && | ||
1108 | p->se.avg_overlap < sysctl_sched_migration_cost) | ||
1109 | sync = 1; | ||
1110 | |||
1161 | /* | 1111 | /* |
1162 | * If sync wakeup then subtract the (maximum possible) | 1112 | * If sync wakeup then subtract the (maximum possible) |
1163 | * effect of the currently running task from the load | 1113 | * effect of the currently running task from the load |
@@ -1182,17 +1132,14 @@ wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq, | |||
1182 | * a reasonable amount of time then attract this newly | 1132 | * a reasonable amount of time then attract this newly |
1183 | * woken task: | 1133 | * woken task: |
1184 | */ | 1134 | */ |
1185 | if (sync && balanced) { | 1135 | if (sync && balanced) |
1186 | if (curr->se.avg_overlap < sysctl_sched_migration_cost && | 1136 | return 1; |
1187 | p->se.avg_overlap < sysctl_sched_migration_cost) | ||
1188 | return 1; | ||
1189 | } | ||
1190 | 1137 | ||
1191 | schedstat_inc(p, se.nr_wakeups_affine_attempts); | 1138 | schedstat_inc(p, se.nr_wakeups_affine_attempts); |
1192 | tl_per_task = cpu_avg_load_per_task(this_cpu); | 1139 | tl_per_task = cpu_avg_load_per_task(this_cpu); |
1193 | 1140 | ||
1194 | if ((tl <= load && tl + target_load(prev_cpu, idx) <= tl_per_task) || | 1141 | if (balanced || (tl <= load && tl + target_load(prev_cpu, idx) <= |
1195 | balanced) { | 1142 | tl_per_task)) { |
1196 | /* | 1143 | /* |
1197 | * This domain has SD_WAKE_AFFINE and | 1144 | * This domain has SD_WAKE_AFFINE and |
1198 | * p is cache cold in this domain, and | 1145 | * p is cache cold in this domain, and |
@@ -1211,16 +1158,17 @@ static int select_task_rq_fair(struct task_struct *p, int sync) | |||
1211 | struct sched_domain *sd, *this_sd = NULL; | 1158 | struct sched_domain *sd, *this_sd = NULL; |
1212 | int prev_cpu, this_cpu, new_cpu; | 1159 | int prev_cpu, this_cpu, new_cpu; |
1213 | unsigned long load, this_load; | 1160 | unsigned long load, this_load; |
1214 | struct rq *rq, *this_rq; | 1161 | struct rq *this_rq; |
1215 | unsigned int imbalance; | 1162 | unsigned int imbalance; |
1216 | int idx; | 1163 | int idx; |
1217 | 1164 | ||
1218 | prev_cpu = task_cpu(p); | 1165 | prev_cpu = task_cpu(p); |
1219 | rq = task_rq(p); | ||
1220 | this_cpu = smp_processor_id(); | 1166 | this_cpu = smp_processor_id(); |
1221 | this_rq = cpu_rq(this_cpu); | 1167 | this_rq = cpu_rq(this_cpu); |
1222 | new_cpu = prev_cpu; | 1168 | new_cpu = prev_cpu; |
1223 | 1169 | ||
1170 | if (prev_cpu == this_cpu) | ||
1171 | goto out; | ||
1224 | /* | 1172 | /* |
1225 | * 'this_sd' is the first domain that both | 1173 | * 'this_sd' is the first domain that both |
1226 | * this_cpu and prev_cpu are present in: | 1174 | * this_cpu and prev_cpu are present in: |
@@ -1248,13 +1196,10 @@ static int select_task_rq_fair(struct task_struct *p, int sync) | |||
1248 | load = source_load(prev_cpu, idx); | 1196 | load = source_load(prev_cpu, idx); |
1249 | this_load = target_load(this_cpu, idx); | 1197 | this_load = target_load(this_cpu, idx); |
1250 | 1198 | ||
1251 | if (wake_affine(rq, this_sd, this_rq, p, prev_cpu, this_cpu, sync, idx, | 1199 | if (wake_affine(this_sd, this_rq, p, prev_cpu, this_cpu, sync, idx, |
1252 | load, this_load, imbalance)) | 1200 | load, this_load, imbalance)) |
1253 | return this_cpu; | 1201 | return this_cpu; |
1254 | 1202 | ||
1255 | if (prev_cpu == this_cpu) | ||
1256 | goto out; | ||
1257 | |||
1258 | /* | 1203 | /* |
1259 | * Start passive balancing when half the imbalance_pct | 1204 | * Start passive balancing when half the imbalance_pct |
1260 | * limit is reached. | 1205 | * limit is reached. |
@@ -1281,62 +1226,20 @@ static unsigned long wakeup_gran(struct sched_entity *se) | |||
1281 | * + nice tasks. | 1226 | * + nice tasks. |
1282 | */ | 1227 | */ |
1283 | if (sched_feat(ASYM_GRAN)) | 1228 | if (sched_feat(ASYM_GRAN)) |
1284 | gran = calc_delta_asym(sysctl_sched_wakeup_granularity, se); | 1229 | gran = calc_delta_mine(gran, NICE_0_LOAD, &se->load); |
1285 | else | ||
1286 | gran = calc_delta_fair(sysctl_sched_wakeup_granularity, se); | ||
1287 | 1230 | ||
1288 | return gran; | 1231 | return gran; |
1289 | } | 1232 | } |
1290 | 1233 | ||
1291 | /* | 1234 | /* |
1292 | * Should 'se' preempt 'curr'. | ||
1293 | * | ||
1294 | * |s1 | ||
1295 | * |s2 | ||
1296 | * |s3 | ||
1297 | * g | ||
1298 | * |<--->|c | ||
1299 | * | ||
1300 | * w(c, s1) = -1 | ||
1301 | * w(c, s2) = 0 | ||
1302 | * w(c, s3) = 1 | ||
1303 | * | ||
1304 | */ | ||
1305 | static int | ||
1306 | wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se) | ||
1307 | { | ||
1308 | s64 gran, vdiff = curr->vruntime - se->vruntime; | ||
1309 | |||
1310 | if (vdiff < 0) | ||
1311 | return -1; | ||
1312 | |||
1313 | gran = wakeup_gran(curr); | ||
1314 | if (vdiff > gran) | ||
1315 | return 1; | ||
1316 | |||
1317 | return 0; | ||
1318 | } | ||
1319 | |||
1320 | /* return depth at which a sched entity is present in the hierarchy */ | ||
1321 | static inline int depth_se(struct sched_entity *se) | ||
1322 | { | ||
1323 | int depth = 0; | ||
1324 | |||
1325 | for_each_sched_entity(se) | ||
1326 | depth++; | ||
1327 | |||
1328 | return depth; | ||
1329 | } | ||
1330 | |||
1331 | /* | ||
1332 | * Preempt the current task with a newly woken task if needed: | 1235 | * Preempt the current task with a newly woken task if needed: |
1333 | */ | 1236 | */ |
1334 | static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) | 1237 | static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int sync) |
1335 | { | 1238 | { |
1336 | struct task_struct *curr = rq->curr; | 1239 | struct task_struct *curr = rq->curr; |
1337 | struct cfs_rq *cfs_rq = task_cfs_rq(curr); | 1240 | struct cfs_rq *cfs_rq = task_cfs_rq(curr); |
1338 | struct sched_entity *se = &curr->se, *pse = &p->se; | 1241 | struct sched_entity *se = &curr->se, *pse = &p->se; |
1339 | int se_depth, pse_depth; | 1242 | s64 delta_exec; |
1340 | 1243 | ||
1341 | if (unlikely(rt_prio(p->prio))) { | 1244 | if (unlikely(rt_prio(p->prio))) { |
1342 | update_rq_clock(rq); | 1245 | update_rq_clock(rq); |
@@ -1351,6 +1254,13 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) | |||
1351 | cfs_rq_of(pse)->next = pse; | 1254 | cfs_rq_of(pse)->next = pse; |
1352 | 1255 | ||
1353 | /* | 1256 | /* |
1257 | * We can come here with TIF_NEED_RESCHED already set from new task | ||
1258 | * wake up path. | ||
1259 | */ | ||
1260 | if (test_tsk_need_resched(curr)) | ||
1261 | return; | ||
1262 | |||
1263 | /* | ||
1354 | * Batch tasks do not preempt (their preemption is driven by | 1264 | * Batch tasks do not preempt (their preemption is driven by |
1355 | * the tick): | 1265 | * the tick): |
1356 | */ | 1266 | */ |
@@ -1360,33 +1270,15 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) | |||
1360 | if (!sched_feat(WAKEUP_PREEMPT)) | 1270 | if (!sched_feat(WAKEUP_PREEMPT)) |
1361 | return; | 1271 | return; |
1362 | 1272 | ||
1363 | /* | 1273 | if (sched_feat(WAKEUP_OVERLAP) && (sync || |
1364 | * preemption test can be made between sibling entities who are in the | 1274 | (se->avg_overlap < sysctl_sched_migration_cost && |
1365 | * same cfs_rq i.e who have a common parent. Walk up the hierarchy of | 1275 | pse->avg_overlap < sysctl_sched_migration_cost))) { |
1366 | * both tasks until we find their ancestors who are siblings of common | 1276 | resched_task(curr); |
1367 | * parent. | 1277 | return; |
1368 | */ | ||
1369 | |||
1370 | /* First walk up until both entities are at same depth */ | ||
1371 | se_depth = depth_se(se); | ||
1372 | pse_depth = depth_se(pse); | ||
1373 | |||
1374 | while (se_depth > pse_depth) { | ||
1375 | se_depth--; | ||
1376 | se = parent_entity(se); | ||
1377 | } | ||
1378 | |||
1379 | while (pse_depth > se_depth) { | ||
1380 | pse_depth--; | ||
1381 | pse = parent_entity(pse); | ||
1382 | } | ||
1383 | |||
1384 | while (!is_same_group(se, pse)) { | ||
1385 | se = parent_entity(se); | ||
1386 | pse = parent_entity(pse); | ||
1387 | } | 1278 | } |
1388 | 1279 | ||
1389 | if (wakeup_preempt_entity(se, pse) == 1) | 1280 | delta_exec = se->sum_exec_runtime - se->prev_sum_exec_runtime; |
1281 | if (delta_exec > wakeup_gran(pse)) | ||
1390 | resched_task(curr); | 1282 | resched_task(curr); |
1391 | } | 1283 | } |
1392 | 1284 | ||
@@ -1442,18 +1334,13 @@ __load_balance_iterator(struct cfs_rq *cfs_rq, struct list_head *next) | |||
1442 | struct task_struct *p = NULL; | 1334 | struct task_struct *p = NULL; |
1443 | struct sched_entity *se; | 1335 | struct sched_entity *se; |
1444 | 1336 | ||
1445 | while (next != &cfs_rq->tasks) { | 1337 | if (next == &cfs_rq->tasks) |
1446 | se = list_entry(next, struct sched_entity, group_node); | 1338 | return NULL; |
1447 | next = next->next; | ||
1448 | 1339 | ||
1449 | /* Skip over entities that are not tasks */ | 1340 | se = list_entry(next, struct sched_entity, group_node); |
1450 | if (entity_is_task(se)) { | 1341 | p = task_of(se); |
1451 | p = task_of(se); | 1342 | cfs_rq->balance_iterator = next->next; |
1452 | break; | ||
1453 | } | ||
1454 | } | ||
1455 | 1343 | ||
1456 | cfs_rq->balance_iterator = next; | ||
1457 | return p; | 1344 | return p; |
1458 | } | 1345 | } |
1459 | 1346 | ||
@@ -1502,7 +1389,7 @@ load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest, | |||
1502 | rcu_read_lock(); | 1389 | rcu_read_lock(); |
1503 | update_h_load(busiest_cpu); | 1390 | update_h_load(busiest_cpu); |
1504 | 1391 | ||
1505 | list_for_each_entry(tg, &task_groups, list) { | 1392 | list_for_each_entry_rcu(tg, &task_groups, list) { |
1506 | struct cfs_rq *busiest_cfs_rq = tg->cfs_rq[busiest_cpu]; | 1393 | struct cfs_rq *busiest_cfs_rq = tg->cfs_rq[busiest_cpu]; |
1507 | unsigned long busiest_h_load = busiest_cfs_rq->h_load; | 1394 | unsigned long busiest_h_load = busiest_cfs_rq->h_load; |
1508 | unsigned long busiest_weight = busiest_cfs_rq->load.weight; | 1395 | unsigned long busiest_weight = busiest_cfs_rq->load.weight; |
@@ -1615,10 +1502,10 @@ static void task_new_fair(struct rq *rq, struct task_struct *p) | |||
1615 | * 'current' within the tree based on its new key value. | 1502 | * 'current' within the tree based on its new key value. |
1616 | */ | 1503 | */ |
1617 | swap(curr->vruntime, se->vruntime); | 1504 | swap(curr->vruntime, se->vruntime); |
1505 | resched_task(rq->curr); | ||
1618 | } | 1506 | } |
1619 | 1507 | ||
1620 | enqueue_task_fair(rq, p, 0); | 1508 | enqueue_task_fair(rq, p, 0); |
1621 | resched_task(rq->curr); | ||
1622 | } | 1509 | } |
1623 | 1510 | ||
1624 | /* | 1511 | /* |
@@ -1637,7 +1524,7 @@ static void prio_changed_fair(struct rq *rq, struct task_struct *p, | |||
1637 | if (p->prio > oldprio) | 1524 | if (p->prio > oldprio) |
1638 | resched_task(rq->curr); | 1525 | resched_task(rq->curr); |
1639 | } else | 1526 | } else |
1640 | check_preempt_curr(rq, p); | 1527 | check_preempt_curr(rq, p, 0); |
1641 | } | 1528 | } |
1642 | 1529 | ||
1643 | /* | 1530 | /* |
@@ -1654,7 +1541,7 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p, | |||
1654 | if (running) | 1541 | if (running) |
1655 | resched_task(rq->curr); | 1542 | resched_task(rq->curr); |
1656 | else | 1543 | else |
1657 | check_preempt_curr(rq, p); | 1544 | check_preempt_curr(rq, p, 0); |
1658 | } | 1545 | } |
1659 | 1546 | ||
1660 | /* Account for a task changing its policy or group. | 1547 | /* Account for a task changing its policy or group. |
diff --git a/kernel/sched_features.h b/kernel/sched_features.h index 862b06bd560a..7c9e8f4a049f 100644 --- a/kernel/sched_features.h +++ b/kernel/sched_features.h | |||
@@ -8,6 +8,7 @@ SCHED_FEAT(SYNC_WAKEUPS, 1) | |||
8 | SCHED_FEAT(HRTICK, 1) | 8 | SCHED_FEAT(HRTICK, 1) |
9 | SCHED_FEAT(DOUBLE_TICK, 0) | 9 | SCHED_FEAT(DOUBLE_TICK, 0) |
10 | SCHED_FEAT(ASYM_GRAN, 1) | 10 | SCHED_FEAT(ASYM_GRAN, 1) |
11 | SCHED_FEAT(LB_BIAS, 0) | 11 | SCHED_FEAT(LB_BIAS, 1) |
12 | SCHED_FEAT(LB_WAKEUP_UPDATE, 1) | 12 | SCHED_FEAT(LB_WAKEUP_UPDATE, 1) |
13 | SCHED_FEAT(ASYM_EFF_LOAD, 1) | 13 | SCHED_FEAT(ASYM_EFF_LOAD, 1) |
14 | SCHED_FEAT(WAKEUP_OVERLAP, 0) | ||
diff --git a/kernel/sched_idletask.c b/kernel/sched_idletask.c index 3a4f92dbbe66..dec4ccabe2f5 100644 --- a/kernel/sched_idletask.c +++ b/kernel/sched_idletask.c | |||
@@ -14,7 +14,7 @@ static int select_task_rq_idle(struct task_struct *p, int sync) | |||
14 | /* | 14 | /* |
15 | * Idle tasks are unconditionally rescheduled: | 15 | * Idle tasks are unconditionally rescheduled: |
16 | */ | 16 | */ |
17 | static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p) | 17 | static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int sync) |
18 | { | 18 | { |
19 | resched_task(rq->idle); | 19 | resched_task(rq->idle); |
20 | } | 20 | } |
@@ -76,7 +76,7 @@ static void switched_to_idle(struct rq *rq, struct task_struct *p, | |||
76 | if (running) | 76 | if (running) |
77 | resched_task(rq->curr); | 77 | resched_task(rq->curr); |
78 | else | 78 | else |
79 | check_preempt_curr(rq, p); | 79 | check_preempt_curr(rq, p, 0); |
80 | } | 80 | } |
81 | 81 | ||
82 | static void prio_changed_idle(struct rq *rq, struct task_struct *p, | 82 | static void prio_changed_idle(struct rq *rq, struct task_struct *p, |
@@ -93,7 +93,7 @@ static void prio_changed_idle(struct rq *rq, struct task_struct *p, | |||
93 | if (p->prio > oldprio) | 93 | if (p->prio > oldprio) |
94 | resched_task(rq->curr); | 94 | resched_task(rq->curr); |
95 | } else | 95 | } else |
96 | check_preempt_curr(rq, p); | 96 | check_preempt_curr(rq, p, 0); |
97 | } | 97 | } |
98 | 98 | ||
99 | /* | 99 | /* |
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index 908c04f9dad0..cdf5740ab03e 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
@@ -102,12 +102,12 @@ static void dequeue_rt_entity(struct sched_rt_entity *rt_se); | |||
102 | 102 | ||
103 | static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) | 103 | static void sched_rt_rq_enqueue(struct rt_rq *rt_rq) |
104 | { | 104 | { |
105 | struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; | ||
105 | struct sched_rt_entity *rt_se = rt_rq->rt_se; | 106 | struct sched_rt_entity *rt_se = rt_rq->rt_se; |
106 | 107 | ||
107 | if (rt_se && !on_rt_rq(rt_se) && rt_rq->rt_nr_running) { | 108 | if (rt_rq->rt_nr_running) { |
108 | struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; | 109 | if (rt_se && !on_rt_rq(rt_se)) |
109 | 110 | enqueue_rt_entity(rt_se); | |
110 | enqueue_rt_entity(rt_se); | ||
111 | if (rt_rq->highest_prio < curr->prio) | 111 | if (rt_rq->highest_prio < curr->prio) |
112 | resched_task(curr); | 112 | resched_task(curr); |
113 | } | 113 | } |
@@ -199,6 +199,8 @@ static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se) | |||
199 | 199 | ||
200 | static inline void sched_rt_rq_enqueue(struct rt_rq *rt_rq) | 200 | static inline void sched_rt_rq_enqueue(struct rt_rq *rt_rq) |
201 | { | 201 | { |
202 | if (rt_rq->rt_nr_running) | ||
203 | resched_task(rq_of_rt_rq(rt_rq)->curr); | ||
202 | } | 204 | } |
203 | 205 | ||
204 | static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq) | 206 | static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq) |
@@ -229,6 +231,9 @@ static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq) | |||
229 | #endif /* CONFIG_RT_GROUP_SCHED */ | 231 | #endif /* CONFIG_RT_GROUP_SCHED */ |
230 | 232 | ||
231 | #ifdef CONFIG_SMP | 233 | #ifdef CONFIG_SMP |
234 | /* | ||
235 | * We ran out of runtime, see if we can borrow some from our neighbours. | ||
236 | */ | ||
232 | static int do_balance_runtime(struct rt_rq *rt_rq) | 237 | static int do_balance_runtime(struct rt_rq *rt_rq) |
233 | { | 238 | { |
234 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); | 239 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
@@ -248,9 +253,18 @@ static int do_balance_runtime(struct rt_rq *rt_rq) | |||
248 | continue; | 253 | continue; |
249 | 254 | ||
250 | spin_lock(&iter->rt_runtime_lock); | 255 | spin_lock(&iter->rt_runtime_lock); |
256 | /* | ||
257 | * Either all rqs have inf runtime and there's nothing to steal | ||
258 | * or __disable_runtime() below sets a specific rq to inf to | ||
259 | * indicate its been disabled and disalow stealing. | ||
260 | */ | ||
251 | if (iter->rt_runtime == RUNTIME_INF) | 261 | if (iter->rt_runtime == RUNTIME_INF) |
252 | goto next; | 262 | goto next; |
253 | 263 | ||
264 | /* | ||
265 | * From runqueues with spare time, take 1/n part of their | ||
266 | * spare time, but no more than our period. | ||
267 | */ | ||
254 | diff = iter->rt_runtime - iter->rt_time; | 268 | diff = iter->rt_runtime - iter->rt_time; |
255 | if (diff > 0) { | 269 | if (diff > 0) { |
256 | diff = div_u64((u64)diff, weight); | 270 | diff = div_u64((u64)diff, weight); |
@@ -272,6 +286,9 @@ next: | |||
272 | return more; | 286 | return more; |
273 | } | 287 | } |
274 | 288 | ||
289 | /* | ||
290 | * Ensure this RQ takes back all the runtime it lend to its neighbours. | ||
291 | */ | ||
275 | static void __disable_runtime(struct rq *rq) | 292 | static void __disable_runtime(struct rq *rq) |
276 | { | 293 | { |
277 | struct root_domain *rd = rq->rd; | 294 | struct root_domain *rd = rq->rd; |
@@ -287,18 +304,34 @@ static void __disable_runtime(struct rq *rq) | |||
287 | 304 | ||
288 | spin_lock(&rt_b->rt_runtime_lock); | 305 | spin_lock(&rt_b->rt_runtime_lock); |
289 | spin_lock(&rt_rq->rt_runtime_lock); | 306 | spin_lock(&rt_rq->rt_runtime_lock); |
307 | /* | ||
308 | * Either we're all inf and nobody needs to borrow, or we're | ||
309 | * already disabled and thus have nothing to do, or we have | ||
310 | * exactly the right amount of runtime to take out. | ||
311 | */ | ||
290 | if (rt_rq->rt_runtime == RUNTIME_INF || | 312 | if (rt_rq->rt_runtime == RUNTIME_INF || |
291 | rt_rq->rt_runtime == rt_b->rt_runtime) | 313 | rt_rq->rt_runtime == rt_b->rt_runtime) |
292 | goto balanced; | 314 | goto balanced; |
293 | spin_unlock(&rt_rq->rt_runtime_lock); | 315 | spin_unlock(&rt_rq->rt_runtime_lock); |
294 | 316 | ||
317 | /* | ||
318 | * Calculate the difference between what we started out with | ||
319 | * and what we current have, that's the amount of runtime | ||
320 | * we lend and now have to reclaim. | ||
321 | */ | ||
295 | want = rt_b->rt_runtime - rt_rq->rt_runtime; | 322 | want = rt_b->rt_runtime - rt_rq->rt_runtime; |
296 | 323 | ||
324 | /* | ||
325 | * Greedy reclaim, take back as much as we can. | ||
326 | */ | ||
297 | for_each_cpu_mask(i, rd->span) { | 327 | for_each_cpu_mask(i, rd->span) { |
298 | struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i); | 328 | struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i); |
299 | s64 diff; | 329 | s64 diff; |
300 | 330 | ||
301 | if (iter == rt_rq) | 331 | /* |
332 | * Can't reclaim from ourselves or disabled runqueues. | ||
333 | */ | ||
334 | if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) | ||
302 | continue; | 335 | continue; |
303 | 336 | ||
304 | spin_lock(&iter->rt_runtime_lock); | 337 | spin_lock(&iter->rt_runtime_lock); |
@@ -317,8 +350,16 @@ static void __disable_runtime(struct rq *rq) | |||
317 | } | 350 | } |
318 | 351 | ||
319 | spin_lock(&rt_rq->rt_runtime_lock); | 352 | spin_lock(&rt_rq->rt_runtime_lock); |
353 | /* | ||
354 | * We cannot be left wanting - that would mean some runtime | ||
355 | * leaked out of the system. | ||
356 | */ | ||
320 | BUG_ON(want); | 357 | BUG_ON(want); |
321 | balanced: | 358 | balanced: |
359 | /* | ||
360 | * Disable all the borrow logic by pretending we have inf | ||
361 | * runtime - in which case borrowing doesn't make sense. | ||
362 | */ | ||
322 | rt_rq->rt_runtime = RUNTIME_INF; | 363 | rt_rq->rt_runtime = RUNTIME_INF; |
323 | spin_unlock(&rt_rq->rt_runtime_lock); | 364 | spin_unlock(&rt_rq->rt_runtime_lock); |
324 | spin_unlock(&rt_b->rt_runtime_lock); | 365 | spin_unlock(&rt_b->rt_runtime_lock); |
@@ -341,6 +382,9 @@ static void __enable_runtime(struct rq *rq) | |||
341 | if (unlikely(!scheduler_running)) | 382 | if (unlikely(!scheduler_running)) |
342 | return; | 383 | return; |
343 | 384 | ||
385 | /* | ||
386 | * Reset each runqueue's bandwidth settings | ||
387 | */ | ||
344 | for_each_leaf_rt_rq(rt_rq, rq) { | 388 | for_each_leaf_rt_rq(rt_rq, rq) { |
345 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); | 389 | struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq); |
346 | 390 | ||
@@ -348,6 +392,7 @@ static void __enable_runtime(struct rq *rq) | |||
348 | spin_lock(&rt_rq->rt_runtime_lock); | 392 | spin_lock(&rt_rq->rt_runtime_lock); |
349 | rt_rq->rt_runtime = rt_b->rt_runtime; | 393 | rt_rq->rt_runtime = rt_b->rt_runtime; |
350 | rt_rq->rt_time = 0; | 394 | rt_rq->rt_time = 0; |
395 | rt_rq->rt_throttled = 0; | ||
351 | spin_unlock(&rt_rq->rt_runtime_lock); | 396 | spin_unlock(&rt_rq->rt_runtime_lock); |
352 | spin_unlock(&rt_b->rt_runtime_lock); | 397 | spin_unlock(&rt_b->rt_runtime_lock); |
353 | } | 398 | } |
@@ -386,7 +431,7 @@ static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun) | |||
386 | int i, idle = 1; | 431 | int i, idle = 1; |
387 | cpumask_t span; | 432 | cpumask_t span; |
388 | 433 | ||
389 | if (rt_b->rt_runtime == RUNTIME_INF) | 434 | if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) |
390 | return 1; | 435 | return 1; |
391 | 436 | ||
392 | span = sched_rt_period_mask(); | 437 | span = sched_rt_period_mask(); |
@@ -438,9 +483,6 @@ static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq) | |||
438 | { | 483 | { |
439 | u64 runtime = sched_rt_runtime(rt_rq); | 484 | u64 runtime = sched_rt_runtime(rt_rq); |
440 | 485 | ||
441 | if (runtime == RUNTIME_INF) | ||
442 | return 0; | ||
443 | |||
444 | if (rt_rq->rt_throttled) | 486 | if (rt_rq->rt_throttled) |
445 | return rt_rq_throttled(rt_rq); | 487 | return rt_rq_throttled(rt_rq); |
446 | 488 | ||
@@ -487,13 +529,18 @@ static void update_curr_rt(struct rq *rq) | |||
487 | curr->se.exec_start = rq->clock; | 529 | curr->se.exec_start = rq->clock; |
488 | cpuacct_charge(curr, delta_exec); | 530 | cpuacct_charge(curr, delta_exec); |
489 | 531 | ||
532 | if (!rt_bandwidth_enabled()) | ||
533 | return; | ||
534 | |||
490 | for_each_sched_rt_entity(rt_se) { | 535 | for_each_sched_rt_entity(rt_se) { |
491 | rt_rq = rt_rq_of_se(rt_se); | 536 | rt_rq = rt_rq_of_se(rt_se); |
492 | 537 | ||
493 | spin_lock(&rt_rq->rt_runtime_lock); | 538 | spin_lock(&rt_rq->rt_runtime_lock); |
494 | rt_rq->rt_time += delta_exec; | 539 | if (sched_rt_runtime(rt_rq) != RUNTIME_INF) { |
495 | if (sched_rt_runtime_exceeded(rt_rq)) | 540 | rt_rq->rt_time += delta_exec; |
496 | resched_task(curr); | 541 | if (sched_rt_runtime_exceeded(rt_rq)) |
542 | resched_task(curr); | ||
543 | } | ||
497 | spin_unlock(&rt_rq->rt_runtime_lock); | 544 | spin_unlock(&rt_rq->rt_runtime_lock); |
498 | } | 545 | } |
499 | } | 546 | } |
@@ -782,7 +829,7 @@ static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) | |||
782 | /* | 829 | /* |
783 | * Preempt the current task with a newly woken task if needed: | 830 | * Preempt the current task with a newly woken task if needed: |
784 | */ | 831 | */ |
785 | static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p) | 832 | static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int sync) |
786 | { | 833 | { |
787 | if (p->prio < rq->curr->prio) { | 834 | if (p->prio < rq->curr->prio) { |
788 | resched_task(rq->curr); | 835 | resched_task(rq->curr); |
@@ -861,6 +908,8 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) | |||
861 | #define RT_MAX_TRIES 3 | 908 | #define RT_MAX_TRIES 3 |
862 | 909 | ||
863 | static int double_lock_balance(struct rq *this_rq, struct rq *busiest); | 910 | static int double_lock_balance(struct rq *this_rq, struct rq *busiest); |
911 | static void double_unlock_balance(struct rq *this_rq, struct rq *busiest); | ||
912 | |||
864 | static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep); | 913 | static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep); |
865 | 914 | ||
866 | static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu) | 915 | static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu) |
@@ -1022,7 +1071,7 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq) | |||
1022 | break; | 1071 | break; |
1023 | 1072 | ||
1024 | /* try again */ | 1073 | /* try again */ |
1025 | spin_unlock(&lowest_rq->lock); | 1074 | double_unlock_balance(rq, lowest_rq); |
1026 | lowest_rq = NULL; | 1075 | lowest_rq = NULL; |
1027 | } | 1076 | } |
1028 | 1077 | ||
@@ -1091,7 +1140,7 @@ static int push_rt_task(struct rq *rq) | |||
1091 | 1140 | ||
1092 | resched_task(lowest_rq->curr); | 1141 | resched_task(lowest_rq->curr); |
1093 | 1142 | ||
1094 | spin_unlock(&lowest_rq->lock); | 1143 | double_unlock_balance(rq, lowest_rq); |
1095 | 1144 | ||
1096 | ret = 1; | 1145 | ret = 1; |
1097 | out: | 1146 | out: |
@@ -1197,7 +1246,7 @@ static int pull_rt_task(struct rq *this_rq) | |||
1197 | 1246 | ||
1198 | } | 1247 | } |
1199 | skip: | 1248 | skip: |
1200 | spin_unlock(&src_rq->lock); | 1249 | double_unlock_balance(this_rq, src_rq); |
1201 | } | 1250 | } |
1202 | 1251 | ||
1203 | return ret; | 1252 | return ret; |
diff --git a/kernel/semaphore.c b/kernel/semaphore.c index aaaeae8244e7..94a62c0d4ade 100644 --- a/kernel/semaphore.c +++ b/kernel/semaphore.c | |||
@@ -212,9 +212,7 @@ static inline int __sched __down_common(struct semaphore *sem, long state, | |||
212 | waiter.up = 0; | 212 | waiter.up = 0; |
213 | 213 | ||
214 | for (;;) { | 214 | for (;;) { |
215 | if (state == TASK_INTERRUPTIBLE && signal_pending(task)) | 215 | if (signal_pending_state(state, task)) |
216 | goto interrupted; | ||
217 | if (state == TASK_KILLABLE && fatal_signal_pending(task)) | ||
218 | goto interrupted; | 216 | goto interrupted; |
219 | if (timeout <= 0) | 217 | if (timeout <= 0) |
220 | goto timed_out; | 218 | goto timed_out; |
diff --git a/kernel/signal.c b/kernel/signal.c index 82c3545596c5..e661b01d340f 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/ptrace.h> | 22 | #include <linux/ptrace.h> |
23 | #include <linux/signal.h> | 23 | #include <linux/signal.h> |
24 | #include <linux/signalfd.h> | 24 | #include <linux/signalfd.h> |
25 | #include <linux/tracehook.h> | ||
25 | #include <linux/capability.h> | 26 | #include <linux/capability.h> |
26 | #include <linux/freezer.h> | 27 | #include <linux/freezer.h> |
27 | #include <linux/pid_namespace.h> | 28 | #include <linux/pid_namespace.h> |
@@ -39,24 +40,21 @@ | |||
39 | 40 | ||
40 | static struct kmem_cache *sigqueue_cachep; | 41 | static struct kmem_cache *sigqueue_cachep; |
41 | 42 | ||
42 | static int __sig_ignored(struct task_struct *t, int sig) | 43 | static void __user *sig_handler(struct task_struct *t, int sig) |
43 | { | 44 | { |
44 | void __user *handler; | 45 | return t->sighand->action[sig - 1].sa.sa_handler; |
46 | } | ||
45 | 47 | ||
48 | static int sig_handler_ignored(void __user *handler, int sig) | ||
49 | { | ||
46 | /* Is it explicitly or implicitly ignored? */ | 50 | /* Is it explicitly or implicitly ignored? */ |
47 | |||
48 | handler = t->sighand->action[sig - 1].sa.sa_handler; | ||
49 | return handler == SIG_IGN || | 51 | return handler == SIG_IGN || |
50 | (handler == SIG_DFL && sig_kernel_ignore(sig)); | 52 | (handler == SIG_DFL && sig_kernel_ignore(sig)); |
51 | } | 53 | } |
52 | 54 | ||
53 | static int sig_ignored(struct task_struct *t, int sig) | 55 | static int sig_ignored(struct task_struct *t, int sig) |
54 | { | 56 | { |
55 | /* | 57 | void __user *handler; |
56 | * Tracers always want to know about signals.. | ||
57 | */ | ||
58 | if (t->ptrace & PT_PTRACED) | ||
59 | return 0; | ||
60 | 58 | ||
61 | /* | 59 | /* |
62 | * Blocked signals are never ignored, since the | 60 | * Blocked signals are never ignored, since the |
@@ -66,7 +64,14 @@ static int sig_ignored(struct task_struct *t, int sig) | |||
66 | if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig)) | 64 | if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig)) |
67 | return 0; | 65 | return 0; |
68 | 66 | ||
69 | return __sig_ignored(t, sig); | 67 | handler = sig_handler(t, sig); |
68 | if (!sig_handler_ignored(handler, sig)) | ||
69 | return 0; | ||
70 | |||
71 | /* | ||
72 | * Tracers may want to know about even ignored signals. | ||
73 | */ | ||
74 | return !tracehook_consider_ignored_signal(t, sig, handler); | ||
70 | } | 75 | } |
71 | 76 | ||
72 | /* | 77 | /* |
@@ -129,7 +134,9 @@ void recalc_sigpending_and_wake(struct task_struct *t) | |||
129 | 134 | ||
130 | void recalc_sigpending(void) | 135 | void recalc_sigpending(void) |
131 | { | 136 | { |
132 | if (!recalc_sigpending_tsk(current) && !freezing(current)) | 137 | if (unlikely(tracehook_force_sigpending())) |
138 | set_thread_flag(TIF_SIGPENDING); | ||
139 | else if (!recalc_sigpending_tsk(current) && !freezing(current)) | ||
133 | clear_thread_flag(TIF_SIGPENDING); | 140 | clear_thread_flag(TIF_SIGPENDING); |
134 | 141 | ||
135 | } | 142 | } |
@@ -295,12 +302,12 @@ flush_signal_handlers(struct task_struct *t, int force_default) | |||
295 | 302 | ||
296 | int unhandled_signal(struct task_struct *tsk, int sig) | 303 | int unhandled_signal(struct task_struct *tsk, int sig) |
297 | { | 304 | { |
305 | void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler; | ||
298 | if (is_global_init(tsk)) | 306 | if (is_global_init(tsk)) |
299 | return 1; | 307 | return 1; |
300 | if (tsk->ptrace & PT_PTRACED) | 308 | if (handler != SIG_IGN && handler != SIG_DFL) |
301 | return 0; | 309 | return 0; |
302 | return (tsk->sighand->action[sig-1].sa.sa_handler == SIG_IGN) || | 310 | return !tracehook_consider_fatal_signal(tsk, sig, handler); |
303 | (tsk->sighand->action[sig-1].sa.sa_handler == SIG_DFL); | ||
304 | } | 311 | } |
305 | 312 | ||
306 | 313 | ||
@@ -591,9 +598,6 @@ static int check_kill_permission(int sig, struct siginfo *info, | |||
591 | return security_task_kill(t, info, sig, 0); | 598 | return security_task_kill(t, info, sig, 0); |
592 | } | 599 | } |
593 | 600 | ||
594 | /* forward decl */ | ||
595 | static void do_notify_parent_cldstop(struct task_struct *tsk, int why); | ||
596 | |||
597 | /* | 601 | /* |
598 | * Handle magic process-wide effects of stop/continue signals. Unlike | 602 | * Handle magic process-wide effects of stop/continue signals. Unlike |
599 | * the signal actions, these happen immediately at signal-generation | 603 | * the signal actions, these happen immediately at signal-generation |
@@ -756,7 +760,8 @@ static void complete_signal(int sig, struct task_struct *p, int group) | |||
756 | if (sig_fatal(p, sig) && | 760 | if (sig_fatal(p, sig) && |
757 | !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) && | 761 | !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) && |
758 | !sigismember(&t->real_blocked, sig) && | 762 | !sigismember(&t->real_blocked, sig) && |
759 | (sig == SIGKILL || !(t->ptrace & PT_PTRACED))) { | 763 | (sig == SIGKILL || |
764 | !tracehook_consider_fatal_signal(t, sig, SIG_DFL))) { | ||
760 | /* | 765 | /* |
761 | * This signal will be fatal to the whole group. | 766 | * This signal will be fatal to the whole group. |
762 | */ | 767 | */ |
@@ -1299,6 +1304,7 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group) | |||
1299 | q->info.si_overrun++; | 1304 | q->info.si_overrun++; |
1300 | goto out; | 1305 | goto out; |
1301 | } | 1306 | } |
1307 | q->info.si_overrun = 0; | ||
1302 | 1308 | ||
1303 | signalfd_notify(t, sig); | 1309 | signalfd_notify(t, sig); |
1304 | pending = group ? &t->signal->shared_pending : &t->pending; | 1310 | pending = group ? &t->signal->shared_pending : &t->pending; |
@@ -1323,13 +1329,16 @@ static inline void __wake_up_parent(struct task_struct *p, | |||
1323 | /* | 1329 | /* |
1324 | * Let a parent know about the death of a child. | 1330 | * Let a parent know about the death of a child. |
1325 | * For a stopped/continued status change, use do_notify_parent_cldstop instead. | 1331 | * For a stopped/continued status change, use do_notify_parent_cldstop instead. |
1332 | * | ||
1333 | * Returns -1 if our parent ignored us and so we've switched to | ||
1334 | * self-reaping, or else @sig. | ||
1326 | */ | 1335 | */ |
1327 | 1336 | int do_notify_parent(struct task_struct *tsk, int sig) | |
1328 | void do_notify_parent(struct task_struct *tsk, int sig) | ||
1329 | { | 1337 | { |
1330 | struct siginfo info; | 1338 | struct siginfo info; |
1331 | unsigned long flags; | 1339 | unsigned long flags; |
1332 | struct sighand_struct *psig; | 1340 | struct sighand_struct *psig; |
1341 | int ret = sig; | ||
1333 | 1342 | ||
1334 | BUG_ON(sig == -1); | 1343 | BUG_ON(sig == -1); |
1335 | 1344 | ||
@@ -1394,14 +1403,16 @@ void do_notify_parent(struct task_struct *tsk, int sig) | |||
1394 | * is implementation-defined: we do (if you don't want | 1403 | * is implementation-defined: we do (if you don't want |
1395 | * it, just use SIG_IGN instead). | 1404 | * it, just use SIG_IGN instead). |
1396 | */ | 1405 | */ |
1397 | tsk->exit_signal = -1; | 1406 | ret = tsk->exit_signal = -1; |
1398 | if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) | 1407 | if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) |
1399 | sig = 0; | 1408 | sig = -1; |
1400 | } | 1409 | } |
1401 | if (valid_signal(sig) && sig > 0) | 1410 | if (valid_signal(sig) && sig > 0) |
1402 | __group_send_sig_info(sig, &info, tsk->parent); | 1411 | __group_send_sig_info(sig, &info, tsk->parent); |
1403 | __wake_up_parent(tsk, tsk->parent); | 1412 | __wake_up_parent(tsk, tsk->parent); |
1404 | spin_unlock_irqrestore(&psig->siglock, flags); | 1413 | spin_unlock_irqrestore(&psig->siglock, flags); |
1414 | |||
1415 | return ret; | ||
1405 | } | 1416 | } |
1406 | 1417 | ||
1407 | static void do_notify_parent_cldstop(struct task_struct *tsk, int why) | 1418 | static void do_notify_parent_cldstop(struct task_struct *tsk, int why) |
@@ -1599,7 +1610,7 @@ finish_stop(int stop_count) | |||
1599 | * a group stop in progress and we are the last to stop, | 1610 | * a group stop in progress and we are the last to stop, |
1600 | * report to the parent. When ptraced, every thread reports itself. | 1611 | * report to the parent. When ptraced, every thread reports itself. |
1601 | */ | 1612 | */ |
1602 | if (stop_count == 0 || (current->ptrace & PT_PTRACED)) { | 1613 | if (tracehook_notify_jctl(stop_count == 0, CLD_STOPPED)) { |
1603 | read_lock(&tasklist_lock); | 1614 | read_lock(&tasklist_lock); |
1604 | do_notify_parent_cldstop(current, CLD_STOPPED); | 1615 | do_notify_parent_cldstop(current, CLD_STOPPED); |
1605 | read_unlock(&tasklist_lock); | 1616 | read_unlock(&tasklist_lock); |
@@ -1735,6 +1746,9 @@ relock: | |||
1735 | signal->flags &= ~SIGNAL_CLD_MASK; | 1746 | signal->flags &= ~SIGNAL_CLD_MASK; |
1736 | spin_unlock_irq(&sighand->siglock); | 1747 | spin_unlock_irq(&sighand->siglock); |
1737 | 1748 | ||
1749 | if (unlikely(!tracehook_notify_jctl(1, why))) | ||
1750 | goto relock; | ||
1751 | |||
1738 | read_lock(&tasklist_lock); | 1752 | read_lock(&tasklist_lock); |
1739 | do_notify_parent_cldstop(current->group_leader, why); | 1753 | do_notify_parent_cldstop(current->group_leader, why); |
1740 | read_unlock(&tasklist_lock); | 1754 | read_unlock(&tasklist_lock); |
@@ -1748,17 +1762,33 @@ relock: | |||
1748 | do_signal_stop(0)) | 1762 | do_signal_stop(0)) |
1749 | goto relock; | 1763 | goto relock; |
1750 | 1764 | ||
1751 | signr = dequeue_signal(current, ¤t->blocked, info); | 1765 | /* |
1752 | if (!signr) | 1766 | * Tracing can induce an artifical signal and choose sigaction. |
1753 | break; /* will return 0 */ | 1767 | * The return value in @signr determines the default action, |
1768 | * but @info->si_signo is the signal number we will report. | ||
1769 | */ | ||
1770 | signr = tracehook_get_signal(current, regs, info, return_ka); | ||
1771 | if (unlikely(signr < 0)) | ||
1772 | goto relock; | ||
1773 | if (unlikely(signr != 0)) | ||
1774 | ka = return_ka; | ||
1775 | else { | ||
1776 | signr = dequeue_signal(current, ¤t->blocked, | ||
1777 | info); | ||
1754 | 1778 | ||
1755 | if (signr != SIGKILL) { | ||
1756 | signr = ptrace_signal(signr, info, regs, cookie); | ||
1757 | if (!signr) | 1779 | if (!signr) |
1758 | continue; | 1780 | break; /* will return 0 */ |
1781 | |||
1782 | if (signr != SIGKILL) { | ||
1783 | signr = ptrace_signal(signr, info, | ||
1784 | regs, cookie); | ||
1785 | if (!signr) | ||
1786 | continue; | ||
1787 | } | ||
1788 | |||
1789 | ka = &sighand->action[signr-1]; | ||
1759 | } | 1790 | } |
1760 | 1791 | ||
1761 | ka = &sighand->action[signr-1]; | ||
1762 | if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ | 1792 | if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ |
1763 | continue; | 1793 | continue; |
1764 | if (ka->sa.sa_handler != SIG_DFL) { | 1794 | if (ka->sa.sa_handler != SIG_DFL) { |
@@ -1806,7 +1836,7 @@ relock: | |||
1806 | spin_lock_irq(&sighand->siglock); | 1836 | spin_lock_irq(&sighand->siglock); |
1807 | } | 1837 | } |
1808 | 1838 | ||
1809 | if (likely(do_signal_stop(signr))) { | 1839 | if (likely(do_signal_stop(info->si_signo))) { |
1810 | /* It released the siglock. */ | 1840 | /* It released the siglock. */ |
1811 | goto relock; | 1841 | goto relock; |
1812 | } | 1842 | } |
@@ -1827,7 +1857,7 @@ relock: | |||
1827 | 1857 | ||
1828 | if (sig_kernel_coredump(signr)) { | 1858 | if (sig_kernel_coredump(signr)) { |
1829 | if (print_fatal_signals) | 1859 | if (print_fatal_signals) |
1830 | print_fatal_signal(regs, signr); | 1860 | print_fatal_signal(regs, info->si_signo); |
1831 | /* | 1861 | /* |
1832 | * If it was able to dump core, this kills all | 1862 | * If it was able to dump core, this kills all |
1833 | * other threads in the group and synchronizes with | 1863 | * other threads in the group and synchronizes with |
@@ -1836,13 +1866,13 @@ relock: | |||
1836 | * first and our do_group_exit call below will use | 1866 | * first and our do_group_exit call below will use |
1837 | * that value and ignore the one we pass it. | 1867 | * that value and ignore the one we pass it. |
1838 | */ | 1868 | */ |
1839 | do_coredump((long)signr, signr, regs); | 1869 | do_coredump(info->si_signo, info->si_signo, regs); |
1840 | } | 1870 | } |
1841 | 1871 | ||
1842 | /* | 1872 | /* |
1843 | * Death signals, no core dump. | 1873 | * Death signals, no core dump. |
1844 | */ | 1874 | */ |
1845 | do_group_exit(signr); | 1875 | do_group_exit(info->si_signo); |
1846 | /* NOTREACHED */ | 1876 | /* NOTREACHED */ |
1847 | } | 1877 | } |
1848 | spin_unlock_irq(&sighand->siglock); | 1878 | spin_unlock_irq(&sighand->siglock); |
@@ -1884,7 +1914,7 @@ void exit_signals(struct task_struct *tsk) | |||
1884 | out: | 1914 | out: |
1885 | spin_unlock_irq(&tsk->sighand->siglock); | 1915 | spin_unlock_irq(&tsk->sighand->siglock); |
1886 | 1916 | ||
1887 | if (unlikely(group_stop)) { | 1917 | if (unlikely(group_stop) && tracehook_notify_jctl(1, CLD_STOPPED)) { |
1888 | read_lock(&tasklist_lock); | 1918 | read_lock(&tasklist_lock); |
1889 | do_notify_parent_cldstop(tsk, CLD_STOPPED); | 1919 | do_notify_parent_cldstop(tsk, CLD_STOPPED); |
1890 | read_unlock(&tasklist_lock); | 1920 | read_unlock(&tasklist_lock); |
@@ -1895,7 +1925,6 @@ EXPORT_SYMBOL(recalc_sigpending); | |||
1895 | EXPORT_SYMBOL_GPL(dequeue_signal); | 1925 | EXPORT_SYMBOL_GPL(dequeue_signal); |
1896 | EXPORT_SYMBOL(flush_signals); | 1926 | EXPORT_SYMBOL(flush_signals); |
1897 | EXPORT_SYMBOL(force_sig); | 1927 | EXPORT_SYMBOL(force_sig); |
1898 | EXPORT_SYMBOL(ptrace_notify); | ||
1899 | EXPORT_SYMBOL(send_sig); | 1928 | EXPORT_SYMBOL(send_sig); |
1900 | EXPORT_SYMBOL(send_sig_info); | 1929 | EXPORT_SYMBOL(send_sig_info); |
1901 | EXPORT_SYMBOL(sigprocmask); | 1930 | EXPORT_SYMBOL(sigprocmask); |
@@ -2299,7 +2328,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) | |||
2299 | * (for example, SIGCHLD), shall cause the pending signal to | 2328 | * (for example, SIGCHLD), shall cause the pending signal to |
2300 | * be discarded, whether or not it is blocked" | 2329 | * be discarded, whether or not it is blocked" |
2301 | */ | 2330 | */ |
2302 | if (__sig_ignored(t, sig)) { | 2331 | if (sig_handler_ignored(sig_handler(t, sig), sig)) { |
2303 | sigemptyset(&mask); | 2332 | sigemptyset(&mask); |
2304 | sigaddset(&mask, sig); | 2333 | sigaddset(&mask, sig); |
2305 | rm_from_queue_full(&mask, &t->signal->shared_pending); | 2334 | rm_from_queue_full(&mask, &t->signal->shared_pending); |
diff --git a/kernel/smp.c b/kernel/smp.c index 462c785ca1ee..f362a8553777 100644 --- a/kernel/smp.c +++ b/kernel/smp.c | |||
@@ -33,7 +33,7 @@ struct call_single_queue { | |||
33 | spinlock_t lock; | 33 | spinlock_t lock; |
34 | }; | 34 | }; |
35 | 35 | ||
36 | void __cpuinit init_call_single_data(void) | 36 | static int __cpuinit init_call_single_data(void) |
37 | { | 37 | { |
38 | int i; | 38 | int i; |
39 | 39 | ||
@@ -43,7 +43,9 @@ void __cpuinit init_call_single_data(void) | |||
43 | spin_lock_init(&q->lock); | 43 | spin_lock_init(&q->lock); |
44 | INIT_LIST_HEAD(&q->list); | 44 | INIT_LIST_HEAD(&q->list); |
45 | } | 45 | } |
46 | return 0; | ||
46 | } | 47 | } |
48 | early_initcall(init_call_single_data); | ||
47 | 49 | ||
48 | static void csd_flag_wait(struct call_single_data *data) | 50 | static void csd_flag_wait(struct call_single_data *data) |
49 | { | 51 | { |
@@ -133,7 +135,8 @@ void generic_smp_call_function_interrupt(void) | |||
133 | */ | 135 | */ |
134 | smp_wmb(); | 136 | smp_wmb(); |
135 | data->csd.flags &= ~CSD_FLAG_WAIT; | 137 | data->csd.flags &= ~CSD_FLAG_WAIT; |
136 | } else | 138 | } |
139 | if (data->csd.flags & CSD_FLAG_ALLOC) | ||
137 | call_rcu(&data->rcu_head, rcu_free_call_data); | 140 | call_rcu(&data->rcu_head, rcu_free_call_data); |
138 | } | 141 | } |
139 | rcu_read_unlock(); | 142 | rcu_read_unlock(); |
@@ -207,8 +210,10 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
207 | { | 210 | { |
208 | struct call_single_data d; | 211 | struct call_single_data d; |
209 | unsigned long flags; | 212 | unsigned long flags; |
210 | /* prevent preemption and reschedule on another processor */ | 213 | /* prevent preemption and reschedule on another processor, |
214 | as well as CPU removal */ | ||
211 | int me = get_cpu(); | 215 | int me = get_cpu(); |
216 | int err = 0; | ||
212 | 217 | ||
213 | /* Can deadlock when called with interrupts disabled */ | 218 | /* Can deadlock when called with interrupts disabled */ |
214 | WARN_ON(irqs_disabled()); | 219 | WARN_ON(irqs_disabled()); |
@@ -217,7 +222,7 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
217 | local_irq_save(flags); | 222 | local_irq_save(flags); |
218 | func(info); | 223 | func(info); |
219 | local_irq_restore(flags); | 224 | local_irq_restore(flags); |
220 | } else { | 225 | } else if ((unsigned)cpu < NR_CPUS && cpu_online(cpu)) { |
221 | struct call_single_data *data = NULL; | 226 | struct call_single_data *data = NULL; |
222 | 227 | ||
223 | if (!wait) { | 228 | if (!wait) { |
@@ -233,10 +238,12 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
233 | data->func = func; | 238 | data->func = func; |
234 | data->info = info; | 239 | data->info = info; |
235 | generic_exec_single(cpu, data); | 240 | generic_exec_single(cpu, data); |
241 | } else { | ||
242 | err = -ENXIO; /* CPU not online */ | ||
236 | } | 243 | } |
237 | 244 | ||
238 | put_cpu(); | 245 | put_cpu(); |
239 | return 0; | 246 | return err; |
240 | } | 247 | } |
241 | EXPORT_SYMBOL(smp_call_function_single); | 248 | EXPORT_SYMBOL(smp_call_function_single); |
242 | 249 | ||
@@ -258,6 +265,42 @@ void __smp_call_function_single(int cpu, struct call_single_data *data) | |||
258 | generic_exec_single(cpu, data); | 265 | generic_exec_single(cpu, data); |
259 | } | 266 | } |
260 | 267 | ||
268 | /* Dummy function */ | ||
269 | static void quiesce_dummy(void *unused) | ||
270 | { | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | * Ensure stack based data used in call function mask is safe to free. | ||
275 | * | ||
276 | * This is needed by smp_call_function_mask when using on-stack data, because | ||
277 | * a single call function queue is shared by all CPUs, and any CPU may pick up | ||
278 | * the data item on the queue at any time before it is deleted. So we need to | ||
279 | * ensure that all CPUs have transitioned through a quiescent state after | ||
280 | * this call. | ||
281 | * | ||
282 | * This is a very slow function, implemented by sending synchronous IPIs to | ||
283 | * all possible CPUs. For this reason, we have to alloc data rather than use | ||
284 | * stack based data even in the case of synchronous calls. The stack based | ||
285 | * data is then just used for deadlock/oom fallback which will be very rare. | ||
286 | * | ||
287 | * If a faster scheme can be made, we could go back to preferring stack based | ||
288 | * data -- the data allocation/free is non-zero cost. | ||
289 | */ | ||
290 | static void smp_call_function_mask_quiesce_stack(cpumask_t mask) | ||
291 | { | ||
292 | struct call_single_data data; | ||
293 | int cpu; | ||
294 | |||
295 | data.func = quiesce_dummy; | ||
296 | data.info = NULL; | ||
297 | |||
298 | for_each_cpu_mask(cpu, mask) { | ||
299 | data.flags = CSD_FLAG_WAIT; | ||
300 | generic_exec_single(cpu, &data); | ||
301 | } | ||
302 | } | ||
303 | |||
261 | /** | 304 | /** |
262 | * smp_call_function_mask(): Run a function on a set of other CPUs. | 305 | * smp_call_function_mask(): Run a function on a set of other CPUs. |
263 | * @mask: The set of cpus to run on. | 306 | * @mask: The set of cpus to run on. |
@@ -283,6 +326,7 @@ int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info, | |||
283 | cpumask_t allbutself; | 326 | cpumask_t allbutself; |
284 | unsigned long flags; | 327 | unsigned long flags; |
285 | int cpu, num_cpus; | 328 | int cpu, num_cpus; |
329 | int slowpath = 0; | ||
286 | 330 | ||
287 | /* Can deadlock when called with interrupts disabled */ | 331 | /* Can deadlock when called with interrupts disabled */ |
288 | WARN_ON(irqs_disabled()); | 332 | WARN_ON(irqs_disabled()); |
@@ -304,15 +348,16 @@ int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info, | |||
304 | return smp_call_function_single(cpu, func, info, wait); | 348 | return smp_call_function_single(cpu, func, info, wait); |
305 | } | 349 | } |
306 | 350 | ||
307 | if (!wait) { | 351 | data = kmalloc(sizeof(*data), GFP_ATOMIC); |
308 | data = kmalloc(sizeof(*data), GFP_ATOMIC); | 352 | if (data) { |
309 | if (data) | 353 | data->csd.flags = CSD_FLAG_ALLOC; |
310 | data->csd.flags = CSD_FLAG_ALLOC; | 354 | if (wait) |
311 | } | 355 | data->csd.flags |= CSD_FLAG_WAIT; |
312 | if (!data) { | 356 | } else { |
313 | data = &d; | 357 | data = &d; |
314 | data->csd.flags = CSD_FLAG_WAIT; | 358 | data->csd.flags = CSD_FLAG_WAIT; |
315 | wait = 1; | 359 | wait = 1; |
360 | slowpath = 1; | ||
316 | } | 361 | } |
317 | 362 | ||
318 | spin_lock_init(&data->lock); | 363 | spin_lock_init(&data->lock); |
@@ -329,8 +374,11 @@ int smp_call_function_mask(cpumask_t mask, void (*func)(void *), void *info, | |||
329 | arch_send_call_function_ipi(mask); | 374 | arch_send_call_function_ipi(mask); |
330 | 375 | ||
331 | /* optionally wait for the CPUs to complete */ | 376 | /* optionally wait for the CPUs to complete */ |
332 | if (wait) | 377 | if (wait) { |
333 | csd_flag_wait(&data->csd); | 378 | csd_flag_wait(&data->csd); |
379 | if (unlikely(slowpath)) | ||
380 | smp_call_function_mask_quiesce_stack(mask); | ||
381 | } | ||
334 | 382 | ||
335 | return 0; | 383 | return 0; |
336 | } | 384 | } |
diff --git a/kernel/softirq.c b/kernel/softirq.c index f6b03d56c2bf..c506f266a6b9 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
@@ -630,7 +630,7 @@ static struct notifier_block __cpuinitdata cpu_nfb = { | |||
630 | .notifier_call = cpu_callback | 630 | .notifier_call = cpu_callback |
631 | }; | 631 | }; |
632 | 632 | ||
633 | __init int spawn_ksoftirqd(void) | 633 | static __init int spawn_ksoftirqd(void) |
634 | { | 634 | { |
635 | void *cpu = (void *)(long)smp_processor_id(); | 635 | void *cpu = (void *)(long)smp_processor_id(); |
636 | int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu); | 636 | int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu); |
@@ -640,6 +640,7 @@ __init int spawn_ksoftirqd(void) | |||
640 | register_cpu_notifier(&cpu_nfb); | 640 | register_cpu_notifier(&cpu_nfb); |
641 | return 0; | 641 | return 0; |
642 | } | 642 | } |
643 | early_initcall(spawn_ksoftirqd); | ||
643 | 644 | ||
644 | #ifdef CONFIG_SMP | 645 | #ifdef CONFIG_SMP |
645 | /* | 646 | /* |
diff --git a/kernel/softlockup.c b/kernel/softlockup.c index 7bd8d1aadd5d..cb838ee93a82 100644 --- a/kernel/softlockup.c +++ b/kernel/softlockup.c | |||
@@ -233,7 +233,8 @@ static void check_hung_uninterruptible_tasks(int this_cpu) | |||
233 | do_each_thread(g, t) { | 233 | do_each_thread(g, t) { |
234 | if (!--max_count) | 234 | if (!--max_count) |
235 | goto unlock; | 235 | goto unlock; |
236 | if (t->state & TASK_UNINTERRUPTIBLE) | 236 | /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ |
237 | if (t->state == TASK_UNINTERRUPTIBLE) | ||
237 | check_hung_task(t, now); | 238 | check_hung_task(t, now); |
238 | } while_each_thread(g, t); | 239 | } while_each_thread(g, t); |
239 | unlock: | 240 | unlock: |
@@ -338,14 +339,33 @@ static struct notifier_block __cpuinitdata cpu_nfb = { | |||
338 | .notifier_call = cpu_callback | 339 | .notifier_call = cpu_callback |
339 | }; | 340 | }; |
340 | 341 | ||
341 | __init void spawn_softlockup_task(void) | 342 | static int __initdata nosoftlockup; |
343 | |||
344 | static int __init nosoftlockup_setup(char *str) | ||
345 | { | ||
346 | nosoftlockup = 1; | ||
347 | return 1; | ||
348 | } | ||
349 | __setup("nosoftlockup", nosoftlockup_setup); | ||
350 | |||
351 | static int __init spawn_softlockup_task(void) | ||
342 | { | 352 | { |
343 | void *cpu = (void *)(long)smp_processor_id(); | 353 | void *cpu = (void *)(long)smp_processor_id(); |
344 | int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu); | 354 | int err; |
345 | 355 | ||
346 | BUG_ON(err == NOTIFY_BAD); | 356 | if (nosoftlockup) |
357 | return 0; | ||
358 | |||
359 | err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu); | ||
360 | if (err == NOTIFY_BAD) { | ||
361 | BUG(); | ||
362 | return 1; | ||
363 | } | ||
347 | cpu_callback(&cpu_nfb, CPU_ONLINE, cpu); | 364 | cpu_callback(&cpu_nfb, CPU_ONLINE, cpu); |
348 | register_cpu_notifier(&cpu_nfb); | 365 | register_cpu_notifier(&cpu_nfb); |
349 | 366 | ||
350 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); | 367 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); |
368 | |||
369 | return 0; | ||
351 | } | 370 | } |
371 | early_initcall(spawn_softlockup_task); | ||
diff --git a/kernel/spinlock.c b/kernel/spinlock.c index a1fb54c93cdd..29ab20749dd3 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c | |||
@@ -290,8 +290,8 @@ void __lockfunc _spin_lock_nested(spinlock_t *lock, int subclass) | |||
290 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); | 290 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
291 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | 291 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); |
292 | } | 292 | } |
293 | |||
294 | EXPORT_SYMBOL(_spin_lock_nested); | 293 | EXPORT_SYMBOL(_spin_lock_nested); |
294 | |||
295 | unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclass) | 295 | unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclass) |
296 | { | 296 | { |
297 | unsigned long flags; | 297 | unsigned long flags; |
@@ -311,9 +311,17 @@ unsigned long __lockfunc _spin_lock_irqsave_nested(spinlock_t *lock, int subclas | |||
311 | #endif | 311 | #endif |
312 | return flags; | 312 | return flags; |
313 | } | 313 | } |
314 | |||
315 | EXPORT_SYMBOL(_spin_lock_irqsave_nested); | 314 | EXPORT_SYMBOL(_spin_lock_irqsave_nested); |
316 | 315 | ||
316 | void __lockfunc _spin_lock_nest_lock(spinlock_t *lock, | ||
317 | struct lockdep_map *nest_lock) | ||
318 | { | ||
319 | preempt_disable(); | ||
320 | spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_); | ||
321 | LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock); | ||
322 | } | ||
323 | EXPORT_SYMBOL(_spin_lock_nest_lock); | ||
324 | |||
317 | #endif | 325 | #endif |
318 | 326 | ||
319 | void __lockfunc _spin_unlock(spinlock_t *lock) | 327 | void __lockfunc _spin_unlock(spinlock_t *lock) |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 738b411ff2d3..af3c7cea258b 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* Copyright 2005 Rusty Russell rusty@rustcorp.com.au IBM Corporation. | 1 | /* Copyright 2008, 2005 Rusty Russell rusty@rustcorp.com.au IBM Corporation. |
2 | * GPL v2 and any later version. | 2 | * GPL v2 and any later version. |
3 | */ | 3 | */ |
4 | #include <linux/cpu.h> | 4 | #include <linux/cpu.h> |
@@ -13,204 +13,177 @@ | |||
13 | #include <asm/atomic.h> | 13 | #include <asm/atomic.h> |
14 | #include <asm/uaccess.h> | 14 | #include <asm/uaccess.h> |
15 | 15 | ||
16 | /* Since we effect priority and affinity (both of which are visible | 16 | /* This controls the threads on each CPU. */ |
17 | * to, and settable by outside processes) we do indirection via a | ||
18 | * kthread. */ | ||
19 | |||
20 | /* Thread to stop each CPU in user context. */ | ||
21 | enum stopmachine_state { | 17 | enum stopmachine_state { |
22 | STOPMACHINE_WAIT, | 18 | /* Dummy starting state for thread. */ |
19 | STOPMACHINE_NONE, | ||
20 | /* Awaiting everyone to be scheduled. */ | ||
23 | STOPMACHINE_PREPARE, | 21 | STOPMACHINE_PREPARE, |
22 | /* Disable interrupts. */ | ||
24 | STOPMACHINE_DISABLE_IRQ, | 23 | STOPMACHINE_DISABLE_IRQ, |
24 | /* Run the function */ | ||
25 | STOPMACHINE_RUN, | ||
26 | /* Exit */ | ||
25 | STOPMACHINE_EXIT, | 27 | STOPMACHINE_EXIT, |
26 | }; | 28 | }; |
29 | static enum stopmachine_state state; | ||
27 | 30 | ||
28 | static enum stopmachine_state stopmachine_state; | 31 | struct stop_machine_data { |
29 | static unsigned int stopmachine_num_threads; | 32 | int (*fn)(void *); |
30 | static atomic_t stopmachine_thread_ack; | 33 | void *data; |
31 | 34 | int fnret; | |
32 | static int stopmachine(void *cpu) | 35 | }; |
33 | { | ||
34 | int irqs_disabled = 0; | ||
35 | int prepared = 0; | ||
36 | cpumask_of_cpu_ptr(cpumask, (int)(long)cpu); | ||
37 | |||
38 | set_cpus_allowed_ptr(current, cpumask); | ||
39 | |||
40 | /* Ack: we are alive */ | ||
41 | smp_mb(); /* Theoretically the ack = 0 might not be on this CPU yet. */ | ||
42 | atomic_inc(&stopmachine_thread_ack); | ||
43 | |||
44 | /* Simple state machine */ | ||
45 | while (stopmachine_state != STOPMACHINE_EXIT) { | ||
46 | if (stopmachine_state == STOPMACHINE_DISABLE_IRQ | ||
47 | && !irqs_disabled) { | ||
48 | local_irq_disable(); | ||
49 | hard_irq_disable(); | ||
50 | irqs_disabled = 1; | ||
51 | /* Ack: irqs disabled. */ | ||
52 | smp_mb(); /* Must read state first. */ | ||
53 | atomic_inc(&stopmachine_thread_ack); | ||
54 | } else if (stopmachine_state == STOPMACHINE_PREPARE | ||
55 | && !prepared) { | ||
56 | /* Everyone is in place, hold CPU. */ | ||
57 | preempt_disable(); | ||
58 | prepared = 1; | ||
59 | smp_mb(); /* Must read state first. */ | ||
60 | atomic_inc(&stopmachine_thread_ack); | ||
61 | } | ||
62 | /* Yield in first stage: migration threads need to | ||
63 | * help our sisters onto their CPUs. */ | ||
64 | if (!prepared && !irqs_disabled) | ||
65 | yield(); | ||
66 | cpu_relax(); | ||
67 | } | ||
68 | |||
69 | /* Ack: we are exiting. */ | ||
70 | smp_mb(); /* Must read state first. */ | ||
71 | atomic_inc(&stopmachine_thread_ack); | ||
72 | |||
73 | if (irqs_disabled) | ||
74 | local_irq_enable(); | ||
75 | if (prepared) | ||
76 | preempt_enable(); | ||
77 | 36 | ||
78 | return 0; | 37 | /* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */ |
79 | } | 38 | static unsigned int num_threads; |
39 | static atomic_t thread_ack; | ||
40 | static struct completion finished; | ||
41 | static DEFINE_MUTEX(lock); | ||
80 | 42 | ||
81 | /* Change the thread state */ | 43 | static void set_state(enum stopmachine_state newstate) |
82 | static void stopmachine_set_state(enum stopmachine_state state) | ||
83 | { | 44 | { |
84 | atomic_set(&stopmachine_thread_ack, 0); | 45 | /* Reset ack counter. */ |
46 | atomic_set(&thread_ack, num_threads); | ||
85 | smp_wmb(); | 47 | smp_wmb(); |
86 | stopmachine_state = state; | 48 | state = newstate; |
87 | while (atomic_read(&stopmachine_thread_ack) != stopmachine_num_threads) | ||
88 | cpu_relax(); | ||
89 | } | 49 | } |
90 | 50 | ||
91 | static int stop_machine(void) | 51 | /* Last one to ack a state moves to the next state. */ |
52 | static void ack_state(void) | ||
92 | { | 53 | { |
93 | int i, ret = 0; | 54 | if (atomic_dec_and_test(&thread_ack)) { |
94 | 55 | /* If we're the last one to ack the EXIT, we're finished. */ | |
95 | atomic_set(&stopmachine_thread_ack, 0); | 56 | if (state == STOPMACHINE_EXIT) |
96 | stopmachine_num_threads = 0; | 57 | complete(&finished); |
97 | stopmachine_state = STOPMACHINE_WAIT; | 58 | else |
98 | 59 | set_state(state + 1); | |
99 | for_each_online_cpu(i) { | ||
100 | if (i == raw_smp_processor_id()) | ||
101 | continue; | ||
102 | ret = kernel_thread(stopmachine, (void *)(long)i,CLONE_KERNEL); | ||
103 | if (ret < 0) | ||
104 | break; | ||
105 | stopmachine_num_threads++; | ||
106 | } | ||
107 | |||
108 | /* Wait for them all to come to life. */ | ||
109 | while (atomic_read(&stopmachine_thread_ack) != stopmachine_num_threads) { | ||
110 | yield(); | ||
111 | cpu_relax(); | ||
112 | } | 60 | } |
61 | } | ||
113 | 62 | ||
114 | /* If some failed, kill them all. */ | 63 | /* This is the actual thread which stops the CPU. It exits by itself rather |
115 | if (ret < 0) { | 64 | * than waiting for kthread_stop(), because it's easier for hotplug CPU. */ |
116 | stopmachine_set_state(STOPMACHINE_EXIT); | 65 | static int stop_cpu(struct stop_machine_data *smdata) |
117 | return ret; | 66 | { |
118 | } | 67 | enum stopmachine_state curstate = STOPMACHINE_NONE; |
119 | 68 | ||
120 | /* Now they are all started, make them hold the CPUs, ready. */ | 69 | /* Simple state machine */ |
121 | preempt_disable(); | 70 | do { |
122 | stopmachine_set_state(STOPMACHINE_PREPARE); | 71 | /* Chill out and ensure we re-read stopmachine_state. */ |
72 | cpu_relax(); | ||
73 | if (state != curstate) { | ||
74 | curstate = state; | ||
75 | switch (curstate) { | ||
76 | case STOPMACHINE_DISABLE_IRQ: | ||
77 | local_irq_disable(); | ||
78 | hard_irq_disable(); | ||
79 | break; | ||
80 | case STOPMACHINE_RUN: | ||
81 | /* |= allows error detection if functions on | ||
82 | * multiple CPUs. */ | ||
83 | smdata->fnret |= smdata->fn(smdata->data); | ||
84 | break; | ||
85 | default: | ||
86 | break; | ||
87 | } | ||
88 | ack_state(); | ||
89 | } | ||
90 | } while (curstate != STOPMACHINE_EXIT); | ||
123 | 91 | ||
124 | /* Make them disable irqs. */ | 92 | local_irq_enable(); |
125 | local_irq_disable(); | 93 | do_exit(0); |
126 | hard_irq_disable(); | 94 | } |
127 | stopmachine_set_state(STOPMACHINE_DISABLE_IRQ); | ||
128 | 95 | ||
96 | /* Callback for CPUs which aren't supposed to do anything. */ | ||
97 | static int chill(void *unused) | ||
98 | { | ||
129 | return 0; | 99 | return 0; |
130 | } | 100 | } |
131 | 101 | ||
132 | static void restart_machine(void) | 102 | int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus) |
133 | { | 103 | { |
134 | stopmachine_set_state(STOPMACHINE_EXIT); | 104 | int i, err; |
135 | local_irq_enable(); | 105 | struct stop_machine_data active, idle; |
136 | preempt_enable_no_resched(); | 106 | struct task_struct **threads; |
137 | } | 107 | |
108 | active.fn = fn; | ||
109 | active.data = data; | ||
110 | active.fnret = 0; | ||
111 | idle.fn = chill; | ||
112 | idle.data = NULL; | ||
113 | |||
114 | /* This could be too big for stack on large machines. */ | ||
115 | threads = kcalloc(NR_CPUS, sizeof(threads[0]), GFP_KERNEL); | ||
116 | if (!threads) | ||
117 | return -ENOMEM; | ||
118 | |||
119 | /* Set up initial state. */ | ||
120 | mutex_lock(&lock); | ||
121 | init_completion(&finished); | ||
122 | num_threads = num_online_cpus(); | ||
123 | set_state(STOPMACHINE_PREPARE); | ||
138 | 124 | ||
139 | struct stop_machine_data { | 125 | for_each_online_cpu(i) { |
140 | int (*fn)(void *); | 126 | struct stop_machine_data *smdata = &idle; |
141 | void *data; | 127 | struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; |
142 | struct completion done; | ||
143 | }; | ||
144 | 128 | ||
145 | static int do_stop(void *_smdata) | 129 | if (!cpus) { |
146 | { | 130 | if (i == first_cpu(cpu_online_map)) |
147 | struct stop_machine_data *smdata = _smdata; | 131 | smdata = &active; |
148 | int ret; | 132 | } else { |
133 | if (cpu_isset(i, *cpus)) | ||
134 | smdata = &active; | ||
135 | } | ||
149 | 136 | ||
150 | ret = stop_machine(); | 137 | threads[i] = kthread_create((void *)stop_cpu, smdata, "kstop%u", |
151 | if (ret == 0) { | 138 | i); |
152 | ret = smdata->fn(smdata->data); | 139 | if (IS_ERR(threads[i])) { |
153 | restart_machine(); | 140 | err = PTR_ERR(threads[i]); |
154 | } | 141 | threads[i] = NULL; |
142 | goto kill_threads; | ||
143 | } | ||
155 | 144 | ||
156 | /* We're done: you can kthread_stop us now */ | 145 | /* Place it onto correct cpu. */ |
157 | complete(&smdata->done); | 146 | kthread_bind(threads[i], i); |
158 | 147 | ||
159 | /* Wait for kthread_stop */ | 148 | /* Make it highest prio. */ |
160 | set_current_state(TASK_INTERRUPTIBLE); | 149 | if (sched_setscheduler_nocheck(threads[i], SCHED_FIFO, ¶m)) |
161 | while (!kthread_should_stop()) { | 150 | BUG(); |
162 | schedule(); | ||
163 | set_current_state(TASK_INTERRUPTIBLE); | ||
164 | } | 151 | } |
165 | __set_current_state(TASK_RUNNING); | ||
166 | return ret; | ||
167 | } | ||
168 | 152 | ||
169 | struct task_struct *__stop_machine_run(int (*fn)(void *), void *data, | 153 | /* We've created all the threads. Wake them all: hold this CPU so one |
170 | unsigned int cpu) | 154 | * doesn't hit this CPU until we're ready. */ |
171 | { | 155 | get_cpu(); |
172 | static DEFINE_MUTEX(stopmachine_mutex); | 156 | for_each_online_cpu(i) |
173 | struct stop_machine_data smdata; | 157 | wake_up_process(threads[i]); |
174 | struct task_struct *p; | ||
175 | 158 | ||
176 | smdata.fn = fn; | 159 | /* This will release the thread on our CPU. */ |
177 | smdata.data = data; | 160 | put_cpu(); |
178 | init_completion(&smdata.done); | 161 | wait_for_completion(&finished); |
162 | mutex_unlock(&lock); | ||
179 | 163 | ||
180 | mutex_lock(&stopmachine_mutex); | 164 | kfree(threads); |
181 | 165 | ||
182 | /* If they don't care which CPU fn runs on, bind to any online one. */ | 166 | return active.fnret; |
183 | if (cpu == NR_CPUS) | ||
184 | cpu = raw_smp_processor_id(); | ||
185 | 167 | ||
186 | p = kthread_create(do_stop, &smdata, "kstopmachine"); | 168 | kill_threads: |
187 | if (!IS_ERR(p)) { | 169 | for_each_online_cpu(i) |
188 | struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; | 170 | if (threads[i]) |
171 | kthread_stop(threads[i]); | ||
172 | mutex_unlock(&lock); | ||
189 | 173 | ||
190 | /* One high-prio thread per cpu. We'll do this one. */ | 174 | kfree(threads); |
191 | sched_setscheduler_nocheck(p, SCHED_FIFO, ¶m); | 175 | return err; |
192 | kthread_bind(p, cpu); | ||
193 | wake_up_process(p); | ||
194 | wait_for_completion(&smdata.done); | ||
195 | } | ||
196 | mutex_unlock(&stopmachine_mutex); | ||
197 | return p; | ||
198 | } | 176 | } |
199 | 177 | ||
200 | int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) | 178 | int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus) |
201 | { | 179 | { |
202 | struct task_struct *p; | ||
203 | int ret; | 180 | int ret; |
204 | 181 | ||
205 | /* No CPUs can come up or down during this. */ | 182 | /* No CPUs can come up or down during this. */ |
206 | get_online_cpus(); | 183 | get_online_cpus(); |
207 | p = __stop_machine_run(fn, data, cpu); | 184 | ret = __stop_machine(fn, data, cpus); |
208 | if (!IS_ERR(p)) | ||
209 | ret = kthread_stop(p); | ||
210 | else | ||
211 | ret = PTR_ERR(p); | ||
212 | put_online_cpus(); | 185 | put_online_cpus(); |
213 | 186 | ||
214 | return ret; | 187 | return ret; |
215 | } | 188 | } |
216 | EXPORT_SYMBOL_GPL(stop_machine_run); | 189 | EXPORT_SYMBOL_GPL(stop_machine); |
diff --git a/kernel/sys.c b/kernel/sys.c index 0c9d3fa1f5ff..038a7bc0901d 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -169,9 +169,9 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) | |||
169 | pgrp = find_vpid(who); | 169 | pgrp = find_vpid(who); |
170 | else | 170 | else |
171 | pgrp = task_pgrp(current); | 171 | pgrp = task_pgrp(current); |
172 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { | 172 | do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { |
173 | error = set_one_prio(p, niceval, error); | 173 | error = set_one_prio(p, niceval, error); |
174 | } while_each_pid_task(pgrp, PIDTYPE_PGID, p); | 174 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); |
175 | break; | 175 | break; |
176 | case PRIO_USER: | 176 | case PRIO_USER: |
177 | user = current->user; | 177 | user = current->user; |
@@ -229,11 +229,11 @@ asmlinkage long sys_getpriority(int which, int who) | |||
229 | pgrp = find_vpid(who); | 229 | pgrp = find_vpid(who); |
230 | else | 230 | else |
231 | pgrp = task_pgrp(current); | 231 | pgrp = task_pgrp(current); |
232 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { | 232 | do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { |
233 | niceval = 20 - task_nice(p); | 233 | niceval = 20 - task_nice(p); |
234 | if (niceval > retval) | 234 | if (niceval > retval) |
235 | retval = niceval; | 235 | retval = niceval; |
236 | } while_each_pid_task(pgrp, PIDTYPE_PGID, p); | 236 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); |
237 | break; | 237 | break; |
238 | case PRIO_USER: | 238 | case PRIO_USER: |
239 | user = current->user; | 239 | user = current->user; |
@@ -274,7 +274,7 @@ void emergency_restart(void) | |||
274 | } | 274 | } |
275 | EXPORT_SYMBOL_GPL(emergency_restart); | 275 | EXPORT_SYMBOL_GPL(emergency_restart); |
276 | 276 | ||
277 | static void kernel_restart_prepare(char *cmd) | 277 | void kernel_restart_prepare(char *cmd) |
278 | { | 278 | { |
279 | blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd); | 279 | blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd); |
280 | system_state = SYSTEM_RESTART; | 280 | system_state = SYSTEM_RESTART; |
@@ -301,26 +301,6 @@ void kernel_restart(char *cmd) | |||
301 | } | 301 | } |
302 | EXPORT_SYMBOL_GPL(kernel_restart); | 302 | EXPORT_SYMBOL_GPL(kernel_restart); |
303 | 303 | ||
304 | /** | ||
305 | * kernel_kexec - reboot the system | ||
306 | * | ||
307 | * Move into place and start executing a preloaded standalone | ||
308 | * executable. If nothing was preloaded return an error. | ||
309 | */ | ||
310 | static void kernel_kexec(void) | ||
311 | { | ||
312 | #ifdef CONFIG_KEXEC | ||
313 | struct kimage *image; | ||
314 | image = xchg(&kexec_image, NULL); | ||
315 | if (!image) | ||
316 | return; | ||
317 | kernel_restart_prepare(NULL); | ||
318 | printk(KERN_EMERG "Starting new kernel\n"); | ||
319 | machine_shutdown(); | ||
320 | machine_kexec(image); | ||
321 | #endif | ||
322 | } | ||
323 | |||
324 | static void kernel_shutdown_prepare(enum system_states state) | 304 | static void kernel_shutdown_prepare(enum system_states state) |
325 | { | 305 | { |
326 | blocking_notifier_call_chain(&reboot_notifier_list, | 306 | blocking_notifier_call_chain(&reboot_notifier_list, |
@@ -425,10 +405,15 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user | |||
425 | kernel_restart(buffer); | 405 | kernel_restart(buffer); |
426 | break; | 406 | break; |
427 | 407 | ||
408 | #ifdef CONFIG_KEXEC | ||
428 | case LINUX_REBOOT_CMD_KEXEC: | 409 | case LINUX_REBOOT_CMD_KEXEC: |
429 | kernel_kexec(); | 410 | { |
430 | unlock_kernel(); | 411 | int ret; |
431 | return -EINVAL; | 412 | ret = kernel_kexec(); |
413 | unlock_kernel(); | ||
414 | return ret; | ||
415 | } | ||
416 | #endif | ||
432 | 417 | ||
433 | #ifdef CONFIG_HIBERNATION | 418 | #ifdef CONFIG_HIBERNATION |
434 | case LINUX_REBOOT_CMD_SW_SUSPEND: | 419 | case LINUX_REBOOT_CMD_SW_SUSPEND: |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 35a50db9b6ce..1bf369bd4423 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -118,10 +118,8 @@ extern char modprobe_path[]; | |||
118 | extern int sg_big_buff; | 118 | extern int sg_big_buff; |
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | #ifdef __sparc__ | 121 | #ifdef CONFIG_SPARC |
122 | extern char reboot_command []; | 122 | #include <asm/system.h> |
123 | extern int stop_a_enabled; | ||
124 | extern int scons_pwroff; | ||
125 | #endif | 123 | #endif |
126 | 124 | ||
127 | #ifdef __hppa__ | 125 | #ifdef __hppa__ |
@@ -159,13 +157,15 @@ static int proc_dointvec_taint(struct ctl_table *table, int write, struct file * | |||
159 | static struct ctl_table root_table[]; | 157 | static struct ctl_table root_table[]; |
160 | static struct ctl_table_root sysctl_table_root; | 158 | static struct ctl_table_root sysctl_table_root; |
161 | static struct ctl_table_header root_table_header = { | 159 | static struct ctl_table_header root_table_header = { |
160 | .count = 1, | ||
162 | .ctl_table = root_table, | 161 | .ctl_table = root_table, |
163 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list), | 162 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), |
164 | .root = &sysctl_table_root, | 163 | .root = &sysctl_table_root, |
164 | .set = &sysctl_table_root.default_set, | ||
165 | }; | 165 | }; |
166 | static struct ctl_table_root sysctl_table_root = { | 166 | static struct ctl_table_root sysctl_table_root = { |
167 | .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), | 167 | .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), |
168 | .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry), | 168 | .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), |
169 | }; | 169 | }; |
170 | 170 | ||
171 | static struct ctl_table kern_table[]; | 171 | static struct ctl_table kern_table[]; |
@@ -413,7 +413,7 @@ static struct ctl_table kern_table[] = { | |||
413 | .mode = 0644, | 413 | .mode = 0644, |
414 | .proc_handler = &proc_dointvec, | 414 | .proc_handler = &proc_dointvec, |
415 | }, | 415 | }, |
416 | #ifdef __sparc__ | 416 | #ifdef CONFIG_SPARC |
417 | { | 417 | { |
418 | .ctl_name = KERN_SPARC_REBOOT, | 418 | .ctl_name = KERN_SPARC_REBOOT, |
419 | .procname = "reboot-cmd", | 419 | .procname = "reboot-cmd", |
@@ -1386,6 +1386,9 @@ static void start_unregistering(struct ctl_table_header *p) | |||
1386 | spin_unlock(&sysctl_lock); | 1386 | spin_unlock(&sysctl_lock); |
1387 | wait_for_completion(&wait); | 1387 | wait_for_completion(&wait); |
1388 | spin_lock(&sysctl_lock); | 1388 | spin_lock(&sysctl_lock); |
1389 | } else { | ||
1390 | /* anything non-NULL; we'll never dereference it */ | ||
1391 | p->unregistering = ERR_PTR(-EINVAL); | ||
1389 | } | 1392 | } |
1390 | /* | 1393 | /* |
1391 | * do not remove from the list until nobody holds it; walking the | 1394 | * do not remove from the list until nobody holds it; walking the |
@@ -1394,6 +1397,32 @@ static void start_unregistering(struct ctl_table_header *p) | |||
1394 | list_del_init(&p->ctl_entry); | 1397 | list_del_init(&p->ctl_entry); |
1395 | } | 1398 | } |
1396 | 1399 | ||
1400 | void sysctl_head_get(struct ctl_table_header *head) | ||
1401 | { | ||
1402 | spin_lock(&sysctl_lock); | ||
1403 | head->count++; | ||
1404 | spin_unlock(&sysctl_lock); | ||
1405 | } | ||
1406 | |||
1407 | void sysctl_head_put(struct ctl_table_header *head) | ||
1408 | { | ||
1409 | spin_lock(&sysctl_lock); | ||
1410 | if (!--head->count) | ||
1411 | kfree(head); | ||
1412 | spin_unlock(&sysctl_lock); | ||
1413 | } | ||
1414 | |||
1415 | struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) | ||
1416 | { | ||
1417 | if (!head) | ||
1418 | BUG(); | ||
1419 | spin_lock(&sysctl_lock); | ||
1420 | if (!use_table(head)) | ||
1421 | head = ERR_PTR(-ENOENT); | ||
1422 | spin_unlock(&sysctl_lock); | ||
1423 | return head; | ||
1424 | } | ||
1425 | |||
1397 | void sysctl_head_finish(struct ctl_table_header *head) | 1426 | void sysctl_head_finish(struct ctl_table_header *head) |
1398 | { | 1427 | { |
1399 | if (!head) | 1428 | if (!head) |
@@ -1403,14 +1432,20 @@ void sysctl_head_finish(struct ctl_table_header *head) | |||
1403 | spin_unlock(&sysctl_lock); | 1432 | spin_unlock(&sysctl_lock); |
1404 | } | 1433 | } |
1405 | 1434 | ||
1435 | static struct ctl_table_set * | ||
1436 | lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) | ||
1437 | { | ||
1438 | struct ctl_table_set *set = &root->default_set; | ||
1439 | if (root->lookup) | ||
1440 | set = root->lookup(root, namespaces); | ||
1441 | return set; | ||
1442 | } | ||
1443 | |||
1406 | static struct list_head * | 1444 | static struct list_head * |
1407 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) | 1445 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) |
1408 | { | 1446 | { |
1409 | struct list_head *header_list; | 1447 | struct ctl_table_set *set = lookup_header_set(root, namespaces); |
1410 | header_list = &root->header_list; | 1448 | return &set->list; |
1411 | if (root->lookup) | ||
1412 | header_list = root->lookup(root, namespaces); | ||
1413 | return header_list; | ||
1414 | } | 1449 | } |
1415 | 1450 | ||
1416 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, | 1451 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, |
@@ -1480,9 +1515,9 @@ static int do_sysctl_strategy(struct ctl_table_root *root, | |||
1480 | int op = 0, rc; | 1515 | int op = 0, rc; |
1481 | 1516 | ||
1482 | if (oldval) | 1517 | if (oldval) |
1483 | op |= 004; | 1518 | op |= MAY_READ; |
1484 | if (newval) | 1519 | if (newval) |
1485 | op |= 002; | 1520 | op |= MAY_WRITE; |
1486 | if (sysctl_perm(root, table, op)) | 1521 | if (sysctl_perm(root, table, op)) |
1487 | return -EPERM; | 1522 | return -EPERM; |
1488 | 1523 | ||
@@ -1524,7 +1559,7 @@ repeat: | |||
1524 | if (n == table->ctl_name) { | 1559 | if (n == table->ctl_name) { |
1525 | int error; | 1560 | int error; |
1526 | if (table->child) { | 1561 | if (table->child) { |
1527 | if (sysctl_perm(root, table, 001)) | 1562 | if (sysctl_perm(root, table, MAY_EXEC)) |
1528 | return -EPERM; | 1563 | return -EPERM; |
1529 | name++; | 1564 | name++; |
1530 | nlen--; | 1565 | nlen--; |
@@ -1599,7 +1634,7 @@ static int test_perm(int mode, int op) | |||
1599 | mode >>= 6; | 1634 | mode >>= 6; |
1600 | else if (in_egroup_p(0)) | 1635 | else if (in_egroup_p(0)) |
1601 | mode >>= 3; | 1636 | mode >>= 3; |
1602 | if ((mode & op & 0007) == op) | 1637 | if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) |
1603 | return 0; | 1638 | return 0; |
1604 | return -EACCES; | 1639 | return -EACCES; |
1605 | } | 1640 | } |
@@ -1609,7 +1644,7 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) | |||
1609 | int error; | 1644 | int error; |
1610 | int mode; | 1645 | int mode; |
1611 | 1646 | ||
1612 | error = security_sysctl(table, op); | 1647 | error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); |
1613 | if (error) | 1648 | if (error) |
1614 | return error; | 1649 | return error; |
1615 | 1650 | ||
@@ -1644,6 +1679,54 @@ static __init int sysctl_init(void) | |||
1644 | 1679 | ||
1645 | core_initcall(sysctl_init); | 1680 | core_initcall(sysctl_init); |
1646 | 1681 | ||
1682 | static struct ctl_table *is_branch_in(struct ctl_table *branch, | ||
1683 | struct ctl_table *table) | ||
1684 | { | ||
1685 | struct ctl_table *p; | ||
1686 | const char *s = branch->procname; | ||
1687 | |||
1688 | /* branch should have named subdirectory as its first element */ | ||
1689 | if (!s || !branch->child) | ||
1690 | return NULL; | ||
1691 | |||
1692 | /* ... and nothing else */ | ||
1693 | if (branch[1].procname || branch[1].ctl_name) | ||
1694 | return NULL; | ||
1695 | |||
1696 | /* table should contain subdirectory with the same name */ | ||
1697 | for (p = table; p->procname || p->ctl_name; p++) { | ||
1698 | if (!p->child) | ||
1699 | continue; | ||
1700 | if (p->procname && strcmp(p->procname, s) == 0) | ||
1701 | return p; | ||
1702 | } | ||
1703 | return NULL; | ||
1704 | } | ||
1705 | |||
1706 | /* see if attaching q to p would be an improvement */ | ||
1707 | static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) | ||
1708 | { | ||
1709 | struct ctl_table *to = p->ctl_table, *by = q->ctl_table; | ||
1710 | struct ctl_table *next; | ||
1711 | int is_better = 0; | ||
1712 | int not_in_parent = !p->attached_by; | ||
1713 | |||
1714 | while ((next = is_branch_in(by, to)) != NULL) { | ||
1715 | if (by == q->attached_by) | ||
1716 | is_better = 1; | ||
1717 | if (to == p->attached_by) | ||
1718 | not_in_parent = 1; | ||
1719 | by = by->child; | ||
1720 | to = next->child; | ||
1721 | } | ||
1722 | |||
1723 | if (is_better && not_in_parent) { | ||
1724 | q->attached_by = by; | ||
1725 | q->attached_to = to; | ||
1726 | q->parent = p; | ||
1727 | } | ||
1728 | } | ||
1729 | |||
1647 | /** | 1730 | /** |
1648 | * __register_sysctl_paths - register a sysctl hierarchy | 1731 | * __register_sysctl_paths - register a sysctl hierarchy |
1649 | * @root: List of sysctl headers to register on | 1732 | * @root: List of sysctl headers to register on |
@@ -1720,10 +1803,10 @@ struct ctl_table_header *__register_sysctl_paths( | |||
1720 | struct nsproxy *namespaces, | 1803 | struct nsproxy *namespaces, |
1721 | const struct ctl_path *path, struct ctl_table *table) | 1804 | const struct ctl_path *path, struct ctl_table *table) |
1722 | { | 1805 | { |
1723 | struct list_head *header_list; | ||
1724 | struct ctl_table_header *header; | 1806 | struct ctl_table_header *header; |
1725 | struct ctl_table *new, **prevp; | 1807 | struct ctl_table *new, **prevp; |
1726 | unsigned int n, npath; | 1808 | unsigned int n, npath; |
1809 | struct ctl_table_set *set; | ||
1727 | 1810 | ||
1728 | /* Count the path components */ | 1811 | /* Count the path components */ |
1729 | for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) | 1812 | for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) |
@@ -1765,6 +1848,7 @@ struct ctl_table_header *__register_sysctl_paths( | |||
1765 | header->unregistering = NULL; | 1848 | header->unregistering = NULL; |
1766 | header->root = root; | 1849 | header->root = root; |
1767 | sysctl_set_parent(NULL, header->ctl_table); | 1850 | sysctl_set_parent(NULL, header->ctl_table); |
1851 | header->count = 1; | ||
1768 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK | 1852 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
1769 | if (sysctl_check_table(namespaces, header->ctl_table)) { | 1853 | if (sysctl_check_table(namespaces, header->ctl_table)) { |
1770 | kfree(header); | 1854 | kfree(header); |
@@ -1772,8 +1856,20 @@ struct ctl_table_header *__register_sysctl_paths( | |||
1772 | } | 1856 | } |
1773 | #endif | 1857 | #endif |
1774 | spin_lock(&sysctl_lock); | 1858 | spin_lock(&sysctl_lock); |
1775 | header_list = lookup_header_list(root, namespaces); | 1859 | header->set = lookup_header_set(root, namespaces); |
1776 | list_add_tail(&header->ctl_entry, header_list); | 1860 | header->attached_by = header->ctl_table; |
1861 | header->attached_to = root_table; | ||
1862 | header->parent = &root_table_header; | ||
1863 | for (set = header->set; set; set = set->parent) { | ||
1864 | struct ctl_table_header *p; | ||
1865 | list_for_each_entry(p, &set->list, ctl_entry) { | ||
1866 | if (p->unregistering) | ||
1867 | continue; | ||
1868 | try_attach(p, header); | ||
1869 | } | ||
1870 | } | ||
1871 | header->parent->count++; | ||
1872 | list_add_tail(&header->ctl_entry, &header->set->list); | ||
1777 | spin_unlock(&sysctl_lock); | 1873 | spin_unlock(&sysctl_lock); |
1778 | 1874 | ||
1779 | return header; | 1875 | return header; |
@@ -1828,8 +1924,37 @@ void unregister_sysctl_table(struct ctl_table_header * header) | |||
1828 | 1924 | ||
1829 | spin_lock(&sysctl_lock); | 1925 | spin_lock(&sysctl_lock); |
1830 | start_unregistering(header); | 1926 | start_unregistering(header); |
1927 | if (!--header->parent->count) { | ||
1928 | WARN_ON(1); | ||
1929 | kfree(header->parent); | ||
1930 | } | ||
1931 | if (!--header->count) | ||
1932 | kfree(header); | ||
1831 | spin_unlock(&sysctl_lock); | 1933 | spin_unlock(&sysctl_lock); |
1832 | kfree(header); | 1934 | } |
1935 | |||
1936 | int sysctl_is_seen(struct ctl_table_header *p) | ||
1937 | { | ||
1938 | struct ctl_table_set *set = p->set; | ||
1939 | int res; | ||
1940 | spin_lock(&sysctl_lock); | ||
1941 | if (p->unregistering) | ||
1942 | res = 0; | ||
1943 | else if (!set->is_seen) | ||
1944 | res = 1; | ||
1945 | else | ||
1946 | res = set->is_seen(set); | ||
1947 | spin_unlock(&sysctl_lock); | ||
1948 | return res; | ||
1949 | } | ||
1950 | |||
1951 | void setup_sysctl_set(struct ctl_table_set *p, | ||
1952 | struct ctl_table_set *parent, | ||
1953 | int (*is_seen)(struct ctl_table_set *)) | ||
1954 | { | ||
1955 | INIT_LIST_HEAD(&p->list); | ||
1956 | p->parent = parent ? parent : &sysctl_table_root.default_set; | ||
1957 | p->is_seen = is_seen; | ||
1833 | } | 1958 | } |
1834 | 1959 | ||
1835 | #else /* !CONFIG_SYSCTL */ | 1960 | #else /* !CONFIG_SYSCTL */ |
@@ -1848,6 +1973,16 @@ void unregister_sysctl_table(struct ctl_table_header * table) | |||
1848 | { | 1973 | { |
1849 | } | 1974 | } |
1850 | 1975 | ||
1976 | void setup_sysctl_set(struct ctl_table_set *p, | ||
1977 | struct ctl_table_set *parent, | ||
1978 | int (*is_seen)(struct ctl_table_set *)) | ||
1979 | { | ||
1980 | } | ||
1981 | |||
1982 | void sysctl_head_put(struct ctl_table_header *head) | ||
1983 | { | ||
1984 | } | ||
1985 | |||
1851 | #endif /* CONFIG_SYSCTL */ | 1986 | #endif /* CONFIG_SYSCTL */ |
1852 | 1987 | ||
1853 | /* | 1988 | /* |
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index 3d1e3e1a1971..f8d968063cea 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c | |||
@@ -72,6 +72,16 @@ void clockevents_set_mode(struct clock_event_device *dev, | |||
72 | } | 72 | } |
73 | 73 | ||
74 | /** | 74 | /** |
75 | * clockevents_shutdown - shutdown the device and clear next_event | ||
76 | * @dev: device to shutdown | ||
77 | */ | ||
78 | void clockevents_shutdown(struct clock_event_device *dev) | ||
79 | { | ||
80 | clockevents_set_mode(dev, CLOCK_EVT_MODE_SHUTDOWN); | ||
81 | dev->next_event.tv64 = KTIME_MAX; | ||
82 | } | ||
83 | |||
84 | /** | ||
75 | * clockevents_program_event - Reprogram the clock event device. | 85 | * clockevents_program_event - Reprogram the clock event device. |
76 | * @expires: absolute expiry time (monotonic clock) | 86 | * @expires: absolute expiry time (monotonic clock) |
77 | * | 87 | * |
@@ -177,7 +187,7 @@ void clockevents_register_device(struct clock_event_device *dev) | |||
177 | /* | 187 | /* |
178 | * Noop handler when we shut down an event device | 188 | * Noop handler when we shut down an event device |
179 | */ | 189 | */ |
180 | static void clockevents_handle_noop(struct clock_event_device *dev) | 190 | void clockevents_handle_noop(struct clock_event_device *dev) |
181 | { | 191 | { |
182 | } | 192 | } |
183 | 193 | ||
@@ -199,7 +209,6 @@ void clockevents_exchange_device(struct clock_event_device *old, | |||
199 | * released list and do a notify add later. | 209 | * released list and do a notify add later. |
200 | */ | 210 | */ |
201 | if (old) { | 211 | if (old) { |
202 | old->event_handler = clockevents_handle_noop; | ||
203 | clockevents_set_mode(old, CLOCK_EVT_MODE_UNUSED); | 212 | clockevents_set_mode(old, CLOCK_EVT_MODE_UNUSED); |
204 | list_del(&old->list); | 213 | list_del(&old->list); |
205 | list_add(&old->list, &clockevents_released); | 214 | list_add(&old->list, &clockevents_released); |
@@ -207,7 +216,7 @@ void clockevents_exchange_device(struct clock_event_device *old, | |||
207 | 216 | ||
208 | if (new) { | 217 | if (new) { |
209 | BUG_ON(new->mode != CLOCK_EVT_MODE_UNUSED); | 218 | BUG_ON(new->mode != CLOCK_EVT_MODE_UNUSED); |
210 | clockevents_set_mode(new, CLOCK_EVT_MODE_SHUTDOWN); | 219 | clockevents_shutdown(new); |
211 | } | 220 | } |
212 | local_irq_restore(flags); | 221 | local_irq_restore(flags); |
213 | } | 222 | } |
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 5125ddd8196b..1ad46f3df6e7 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c | |||
@@ -245,7 +245,7 @@ static void sync_cmos_clock(unsigned long dummy) | |||
245 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) | 245 | if (abs(now.tv_nsec - (NSEC_PER_SEC / 2)) <= tick_nsec / 2) |
246 | fail = update_persistent_clock(now); | 246 | fail = update_persistent_clock(now); |
247 | 247 | ||
248 | next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec; | 248 | next.tv_nsec = (NSEC_PER_SEC / 2) - now.tv_nsec - (TICK_NSEC / 2); |
249 | if (next.tv_nsec <= 0) | 249 | if (next.tv_nsec <= 0) |
250 | next.tv_nsec += NSEC_PER_SEC; | 250 | next.tv_nsec += NSEC_PER_SEC; |
251 | 251 | ||
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index 31463d370b94..cb01cd8f919b 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
@@ -175,6 +175,8 @@ static void tick_do_periodic_broadcast(void) | |||
175 | */ | 175 | */ |
176 | static void tick_handle_periodic_broadcast(struct clock_event_device *dev) | 176 | static void tick_handle_periodic_broadcast(struct clock_event_device *dev) |
177 | { | 177 | { |
178 | ktime_t next; | ||
179 | |||
178 | tick_do_periodic_broadcast(); | 180 | tick_do_periodic_broadcast(); |
179 | 181 | ||
180 | /* | 182 | /* |
@@ -185,10 +187,13 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev) | |||
185 | 187 | ||
186 | /* | 188 | /* |
187 | * Setup the next period for devices, which do not have | 189 | * Setup the next period for devices, which do not have |
188 | * periodic mode: | 190 | * periodic mode. We read dev->next_event first and add to it |
191 | * when the event alrady expired. clockevents_program_event() | ||
192 | * sets dev->next_event only when the event is really | ||
193 | * programmed to the device. | ||
189 | */ | 194 | */ |
190 | for (;;) { | 195 | for (next = dev->next_event; ;) { |
191 | ktime_t next = ktime_add(dev->next_event, tick_period); | 196 | next = ktime_add(next, tick_period); |
192 | 197 | ||
193 | if (!clockevents_program_event(dev, next, ktime_get())) | 198 | if (!clockevents_program_event(dev, next, ktime_get())) |
194 | return; | 199 | return; |
@@ -205,7 +210,7 @@ static void tick_do_broadcast_on_off(void *why) | |||
205 | struct clock_event_device *bc, *dev; | 210 | struct clock_event_device *bc, *dev; |
206 | struct tick_device *td; | 211 | struct tick_device *td; |
207 | unsigned long flags, *reason = why; | 212 | unsigned long flags, *reason = why; |
208 | int cpu; | 213 | int cpu, bc_stopped; |
209 | 214 | ||
210 | spin_lock_irqsave(&tick_broadcast_lock, flags); | 215 | spin_lock_irqsave(&tick_broadcast_lock, flags); |
211 | 216 | ||
@@ -223,14 +228,16 @@ static void tick_do_broadcast_on_off(void *why) | |||
223 | if (!tick_device_is_functional(dev)) | 228 | if (!tick_device_is_functional(dev)) |
224 | goto out; | 229 | goto out; |
225 | 230 | ||
231 | bc_stopped = cpus_empty(tick_broadcast_mask); | ||
232 | |||
226 | switch (*reason) { | 233 | switch (*reason) { |
227 | case CLOCK_EVT_NOTIFY_BROADCAST_ON: | 234 | case CLOCK_EVT_NOTIFY_BROADCAST_ON: |
228 | case CLOCK_EVT_NOTIFY_BROADCAST_FORCE: | 235 | case CLOCK_EVT_NOTIFY_BROADCAST_FORCE: |
229 | if (!cpu_isset(cpu, tick_broadcast_mask)) { | 236 | if (!cpu_isset(cpu, tick_broadcast_mask)) { |
230 | cpu_set(cpu, tick_broadcast_mask); | 237 | cpu_set(cpu, tick_broadcast_mask); |
231 | if (td->mode == TICKDEV_MODE_PERIODIC) | 238 | if (tick_broadcast_device.mode == |
232 | clockevents_set_mode(dev, | 239 | TICKDEV_MODE_PERIODIC) |
233 | CLOCK_EVT_MODE_SHUTDOWN); | 240 | clockevents_shutdown(dev); |
234 | } | 241 | } |
235 | if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE) | 242 | if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE) |
236 | tick_broadcast_force = 1; | 243 | tick_broadcast_force = 1; |
@@ -239,15 +246,17 @@ static void tick_do_broadcast_on_off(void *why) | |||
239 | if (!tick_broadcast_force && | 246 | if (!tick_broadcast_force && |
240 | cpu_isset(cpu, tick_broadcast_mask)) { | 247 | cpu_isset(cpu, tick_broadcast_mask)) { |
241 | cpu_clear(cpu, tick_broadcast_mask); | 248 | cpu_clear(cpu, tick_broadcast_mask); |
242 | if (td->mode == TICKDEV_MODE_PERIODIC) | 249 | if (tick_broadcast_device.mode == |
250 | TICKDEV_MODE_PERIODIC) | ||
243 | tick_setup_periodic(dev, 0); | 251 | tick_setup_periodic(dev, 0); |
244 | } | 252 | } |
245 | break; | 253 | break; |
246 | } | 254 | } |
247 | 255 | ||
248 | if (cpus_empty(tick_broadcast_mask)) | 256 | if (cpus_empty(tick_broadcast_mask)) { |
249 | clockevents_set_mode(bc, CLOCK_EVT_MODE_SHUTDOWN); | 257 | if (!bc_stopped) |
250 | else { | 258 | clockevents_shutdown(bc); |
259 | } else if (bc_stopped) { | ||
251 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) | 260 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) |
252 | tick_broadcast_start_periodic(bc); | 261 | tick_broadcast_start_periodic(bc); |
253 | else | 262 | else |
@@ -298,7 +307,7 @@ void tick_shutdown_broadcast(unsigned int *cpup) | |||
298 | 307 | ||
299 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) { | 308 | if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) { |
300 | if (bc && cpus_empty(tick_broadcast_mask)) | 309 | if (bc && cpus_empty(tick_broadcast_mask)) |
301 | clockevents_set_mode(bc, CLOCK_EVT_MODE_SHUTDOWN); | 310 | clockevents_shutdown(bc); |
302 | } | 311 | } |
303 | 312 | ||
304 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); | 313 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
@@ -313,7 +322,7 @@ void tick_suspend_broadcast(void) | |||
313 | 322 | ||
314 | bc = tick_broadcast_device.evtdev; | 323 | bc = tick_broadcast_device.evtdev; |
315 | if (bc) | 324 | if (bc) |
316 | clockevents_set_mode(bc, CLOCK_EVT_MODE_SHUTDOWN); | 325 | clockevents_shutdown(bc); |
317 | 326 | ||
318 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); | 327 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
319 | } | 328 | } |
@@ -364,16 +373,8 @@ cpumask_t *tick_get_broadcast_oneshot_mask(void) | |||
364 | static int tick_broadcast_set_event(ktime_t expires, int force) | 373 | static int tick_broadcast_set_event(ktime_t expires, int force) |
365 | { | 374 | { |
366 | struct clock_event_device *bc = tick_broadcast_device.evtdev; | 375 | struct clock_event_device *bc = tick_broadcast_device.evtdev; |
367 | ktime_t now = ktime_get(); | 376 | |
368 | int res; | 377 | return tick_dev_program_event(bc, expires, force); |
369 | |||
370 | for(;;) { | ||
371 | res = clockevents_program_event(bc, expires, now); | ||
372 | if (!res || !force) | ||
373 | return res; | ||
374 | now = ktime_get(); | ||
375 | expires = ktime_add(now, ktime_set(0, bc->min_delta_ns)); | ||
376 | } | ||
377 | } | 378 | } |
378 | 379 | ||
379 | int tick_resume_broadcast_oneshot(struct clock_event_device *bc) | 380 | int tick_resume_broadcast_oneshot(struct clock_event_device *bc) |
@@ -491,14 +492,52 @@ static void tick_broadcast_clear_oneshot(int cpu) | |||
491 | cpu_clear(cpu, tick_broadcast_oneshot_mask); | 492 | cpu_clear(cpu, tick_broadcast_oneshot_mask); |
492 | } | 493 | } |
493 | 494 | ||
495 | static void tick_broadcast_init_next_event(cpumask_t *mask, ktime_t expires) | ||
496 | { | ||
497 | struct tick_device *td; | ||
498 | int cpu; | ||
499 | |||
500 | for_each_cpu_mask_nr(cpu, *mask) { | ||
501 | td = &per_cpu(tick_cpu_device, cpu); | ||
502 | if (td->evtdev) | ||
503 | td->evtdev->next_event = expires; | ||
504 | } | ||
505 | } | ||
506 | |||
494 | /** | 507 | /** |
495 | * tick_broadcast_setup_oneshot - setup the broadcast device | 508 | * tick_broadcast_setup_oneshot - setup the broadcast device |
496 | */ | 509 | */ |
497 | void tick_broadcast_setup_oneshot(struct clock_event_device *bc) | 510 | void tick_broadcast_setup_oneshot(struct clock_event_device *bc) |
498 | { | 511 | { |
499 | bc->event_handler = tick_handle_oneshot_broadcast; | 512 | /* Set it up only once ! */ |
500 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); | 513 | if (bc->event_handler != tick_handle_oneshot_broadcast) { |
501 | bc->next_event.tv64 = KTIME_MAX; | 514 | int was_periodic = bc->mode == CLOCK_EVT_MODE_PERIODIC; |
515 | int cpu = smp_processor_id(); | ||
516 | cpumask_t mask; | ||
517 | |||
518 | bc->event_handler = tick_handle_oneshot_broadcast; | ||
519 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); | ||
520 | |||
521 | /* Take the do_timer update */ | ||
522 | tick_do_timer_cpu = cpu; | ||
523 | |||
524 | /* | ||
525 | * We must be careful here. There might be other CPUs | ||
526 | * waiting for periodic broadcast. We need to set the | ||
527 | * oneshot_mask bits for those and program the | ||
528 | * broadcast device to fire. | ||
529 | */ | ||
530 | mask = tick_broadcast_mask; | ||
531 | cpu_clear(cpu, mask); | ||
532 | cpus_or(tick_broadcast_oneshot_mask, | ||
533 | tick_broadcast_oneshot_mask, mask); | ||
534 | |||
535 | if (was_periodic && !cpus_empty(mask)) { | ||
536 | tick_broadcast_init_next_event(&mask, tick_next_period); | ||
537 | tick_broadcast_set_event(tick_next_period, 1); | ||
538 | } else | ||
539 | bc->next_event.tv64 = KTIME_MAX; | ||
540 | } | ||
502 | } | 541 | } |
503 | 542 | ||
504 | /* | 543 | /* |
@@ -538,4 +577,12 @@ void tick_shutdown_broadcast_oneshot(unsigned int *cpup) | |||
538 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); | 577 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
539 | } | 578 | } |
540 | 579 | ||
580 | /* | ||
581 | * Check, whether the broadcast device is in one shot mode | ||
582 | */ | ||
583 | int tick_broadcast_oneshot_active(void) | ||
584 | { | ||
585 | return tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT; | ||
586 | } | ||
587 | |||
541 | #endif | 588 | #endif |
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index bf43284d6855..df12434b43ca 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c | |||
@@ -33,7 +33,7 @@ DEFINE_PER_CPU(struct tick_device, tick_cpu_device); | |||
33 | */ | 33 | */ |
34 | ktime_t tick_next_period; | 34 | ktime_t tick_next_period; |
35 | ktime_t tick_period; | 35 | ktime_t tick_period; |
36 | int tick_do_timer_cpu __read_mostly = -1; | 36 | int tick_do_timer_cpu __read_mostly = TICK_DO_TIMER_BOOT; |
37 | DEFINE_SPINLOCK(tick_device_lock); | 37 | DEFINE_SPINLOCK(tick_device_lock); |
38 | 38 | ||
39 | /* | 39 | /* |
@@ -109,7 +109,8 @@ void tick_setup_periodic(struct clock_event_device *dev, int broadcast) | |||
109 | if (!tick_device_is_functional(dev)) | 109 | if (!tick_device_is_functional(dev)) |
110 | return; | 110 | return; |
111 | 111 | ||
112 | if (dev->features & CLOCK_EVT_FEAT_PERIODIC) { | 112 | if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) && |
113 | !tick_broadcast_oneshot_active()) { | ||
113 | clockevents_set_mode(dev, CLOCK_EVT_MODE_PERIODIC); | 114 | clockevents_set_mode(dev, CLOCK_EVT_MODE_PERIODIC); |
114 | } else { | 115 | } else { |
115 | unsigned long seq; | 116 | unsigned long seq; |
@@ -148,7 +149,7 @@ static void tick_setup_device(struct tick_device *td, | |||
148 | * If no cpu took the do_timer update, assign it to | 149 | * If no cpu took the do_timer update, assign it to |
149 | * this cpu: | 150 | * this cpu: |
150 | */ | 151 | */ |
151 | if (tick_do_timer_cpu == -1) { | 152 | if (tick_do_timer_cpu == TICK_DO_TIMER_BOOT) { |
152 | tick_do_timer_cpu = cpu; | 153 | tick_do_timer_cpu = cpu; |
153 | tick_next_period = ktime_get(); | 154 | tick_next_period = ktime_get(); |
154 | tick_period = ktime_set(0, NSEC_PER_SEC / HZ); | 155 | tick_period = ktime_set(0, NSEC_PER_SEC / HZ); |
@@ -161,6 +162,7 @@ static void tick_setup_device(struct tick_device *td, | |||
161 | } else { | 162 | } else { |
162 | handler = td->evtdev->event_handler; | 163 | handler = td->evtdev->event_handler; |
163 | next_event = td->evtdev->next_event; | 164 | next_event = td->evtdev->next_event; |
165 | td->evtdev->event_handler = clockevents_handle_noop; | ||
164 | } | 166 | } |
165 | 167 | ||
166 | td->evtdev = newdev; | 168 | td->evtdev = newdev; |
@@ -196,12 +198,10 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
196 | struct tick_device *td; | 198 | struct tick_device *td; |
197 | int cpu, ret = NOTIFY_OK; | 199 | int cpu, ret = NOTIFY_OK; |
198 | unsigned long flags; | 200 | unsigned long flags; |
199 | cpumask_of_cpu_ptr_declare(cpumask); | ||
200 | 201 | ||
201 | spin_lock_irqsave(&tick_device_lock, flags); | 202 | spin_lock_irqsave(&tick_device_lock, flags); |
202 | 203 | ||
203 | cpu = smp_processor_id(); | 204 | cpu = smp_processor_id(); |
204 | cpumask_of_cpu_ptr_next(cpumask, cpu); | ||
205 | if (!cpu_isset(cpu, newdev->cpumask)) | 205 | if (!cpu_isset(cpu, newdev->cpumask)) |
206 | goto out_bc; | 206 | goto out_bc; |
207 | 207 | ||
@@ -209,7 +209,7 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
209 | curdev = td->evtdev; | 209 | curdev = td->evtdev; |
210 | 210 | ||
211 | /* cpu local device ? */ | 211 | /* cpu local device ? */ |
212 | if (!cpus_equal(newdev->cpumask, *cpumask)) { | 212 | if (!cpus_equal(newdev->cpumask, cpumask_of_cpu(cpu))) { |
213 | 213 | ||
214 | /* | 214 | /* |
215 | * If the cpu affinity of the device interrupt can not | 215 | * If the cpu affinity of the device interrupt can not |
@@ -222,7 +222,7 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
222 | * If we have a cpu local device already, do not replace it | 222 | * If we have a cpu local device already, do not replace it |
223 | * by a non cpu local device | 223 | * by a non cpu local device |
224 | */ | 224 | */ |
225 | if (curdev && cpus_equal(curdev->cpumask, *cpumask)) | 225 | if (curdev && cpus_equal(curdev->cpumask, cpumask_of_cpu(cpu))) |
226 | goto out_bc; | 226 | goto out_bc; |
227 | } | 227 | } |
228 | 228 | ||
@@ -250,11 +250,11 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
250 | * not give it back to the clockevents layer ! | 250 | * not give it back to the clockevents layer ! |
251 | */ | 251 | */ |
252 | if (tick_is_broadcast_device(curdev)) { | 252 | if (tick_is_broadcast_device(curdev)) { |
253 | clockevents_set_mode(curdev, CLOCK_EVT_MODE_SHUTDOWN); | 253 | clockevents_shutdown(curdev); |
254 | curdev = NULL; | 254 | curdev = NULL; |
255 | } | 255 | } |
256 | clockevents_exchange_device(curdev, newdev); | 256 | clockevents_exchange_device(curdev, newdev); |
257 | tick_setup_device(td, newdev, cpu, cpumask); | 257 | tick_setup_device(td, newdev, cpu, &cpumask_of_cpu(cpu)); |
258 | if (newdev->features & CLOCK_EVT_FEAT_ONESHOT) | 258 | if (newdev->features & CLOCK_EVT_FEAT_ONESHOT) |
259 | tick_oneshot_notify(); | 259 | tick_oneshot_notify(); |
260 | 260 | ||
@@ -301,7 +301,8 @@ static void tick_shutdown(unsigned int *cpup) | |||
301 | if (*cpup == tick_do_timer_cpu) { | 301 | if (*cpup == tick_do_timer_cpu) { |
302 | int cpu = first_cpu(cpu_online_map); | 302 | int cpu = first_cpu(cpu_online_map); |
303 | 303 | ||
304 | tick_do_timer_cpu = (cpu != NR_CPUS) ? cpu : -1; | 304 | tick_do_timer_cpu = (cpu != NR_CPUS) ? cpu : |
305 | TICK_DO_TIMER_NONE; | ||
305 | } | 306 | } |
306 | spin_unlock_irqrestore(&tick_device_lock, flags); | 307 | spin_unlock_irqrestore(&tick_device_lock, flags); |
307 | } | 308 | } |
@@ -312,7 +313,7 @@ static void tick_suspend(void) | |||
312 | unsigned long flags; | 313 | unsigned long flags; |
313 | 314 | ||
314 | spin_lock_irqsave(&tick_device_lock, flags); | 315 | spin_lock_irqsave(&tick_device_lock, flags); |
315 | clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_SHUTDOWN); | 316 | clockevents_shutdown(td->evtdev); |
316 | spin_unlock_irqrestore(&tick_device_lock, flags); | 317 | spin_unlock_irqrestore(&tick_device_lock, flags); |
317 | } | 318 | } |
318 | 319 | ||
diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h index f13f2b7f4fd4..469248782c23 100644 --- a/kernel/time/tick-internal.h +++ b/kernel/time/tick-internal.h | |||
@@ -1,6 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * tick internal variable and functions used by low/high res code | 2 | * tick internal variable and functions used by low/high res code |
3 | */ | 3 | */ |
4 | |||
5 | #define TICK_DO_TIMER_NONE -1 | ||
6 | #define TICK_DO_TIMER_BOOT -2 | ||
7 | |||
4 | DECLARE_PER_CPU(struct tick_device, tick_cpu_device); | 8 | DECLARE_PER_CPU(struct tick_device, tick_cpu_device); |
5 | extern spinlock_t tick_device_lock; | 9 | extern spinlock_t tick_device_lock; |
6 | extern ktime_t tick_next_period; | 10 | extern ktime_t tick_next_period; |
@@ -10,6 +14,8 @@ extern int tick_do_timer_cpu __read_mostly; | |||
10 | extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast); | 14 | extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast); |
11 | extern void tick_handle_periodic(struct clock_event_device *dev); | 15 | extern void tick_handle_periodic(struct clock_event_device *dev); |
12 | 16 | ||
17 | extern void clockevents_shutdown(struct clock_event_device *dev); | ||
18 | |||
13 | /* | 19 | /* |
14 | * NO_HZ / high resolution timer shared code | 20 | * NO_HZ / high resolution timer shared code |
15 | */ | 21 | */ |
@@ -17,6 +23,8 @@ extern void tick_handle_periodic(struct clock_event_device *dev); | |||
17 | extern void tick_setup_oneshot(struct clock_event_device *newdev, | 23 | extern void tick_setup_oneshot(struct clock_event_device *newdev, |
18 | void (*handler)(struct clock_event_device *), | 24 | void (*handler)(struct clock_event_device *), |
19 | ktime_t nextevt); | 25 | ktime_t nextevt); |
26 | extern int tick_dev_program_event(struct clock_event_device *dev, | ||
27 | ktime_t expires, int force); | ||
20 | extern int tick_program_event(ktime_t expires, int force); | 28 | extern int tick_program_event(ktime_t expires, int force); |
21 | extern void tick_oneshot_notify(void); | 29 | extern void tick_oneshot_notify(void); |
22 | extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)); | 30 | extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)); |
@@ -27,6 +35,7 @@ extern void tick_broadcast_oneshot_control(unsigned long reason); | |||
27 | extern void tick_broadcast_switch_to_oneshot(void); | 35 | extern void tick_broadcast_switch_to_oneshot(void); |
28 | extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup); | 36 | extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup); |
29 | extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc); | 37 | extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc); |
38 | extern int tick_broadcast_oneshot_active(void); | ||
30 | # else /* BROADCAST */ | 39 | # else /* BROADCAST */ |
31 | static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) | 40 | static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) |
32 | { | 41 | { |
@@ -35,6 +44,7 @@ static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) | |||
35 | static inline void tick_broadcast_oneshot_control(unsigned long reason) { } | 44 | static inline void tick_broadcast_oneshot_control(unsigned long reason) { } |
36 | static inline void tick_broadcast_switch_to_oneshot(void) { } | 45 | static inline void tick_broadcast_switch_to_oneshot(void) { } |
37 | static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } | 46 | static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } |
47 | static inline int tick_broadcast_oneshot_active(void) { return 0; } | ||
38 | # endif /* !BROADCAST */ | 48 | # endif /* !BROADCAST */ |
39 | 49 | ||
40 | #else /* !ONESHOT */ | 50 | #else /* !ONESHOT */ |
@@ -64,6 +74,7 @@ static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc) | |||
64 | { | 74 | { |
65 | return 0; | 75 | return 0; |
66 | } | 76 | } |
77 | static inline int tick_broadcast_oneshot_active(void) { return 0; } | ||
67 | #endif /* !TICK_ONESHOT */ | 78 | #endif /* !TICK_ONESHOT */ |
68 | 79 | ||
69 | /* | 80 | /* |
diff --git a/kernel/time/tick-oneshot.c b/kernel/time/tick-oneshot.c index 450c04935b66..2e8de678e767 100644 --- a/kernel/time/tick-oneshot.c +++ b/kernel/time/tick-oneshot.c | |||
@@ -23,24 +23,56 @@ | |||
23 | #include "tick-internal.h" | 23 | #include "tick-internal.h" |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * tick_program_event | 26 | * tick_program_event internal worker function |
27 | */ | 27 | */ |
28 | int tick_program_event(ktime_t expires, int force) | 28 | int tick_dev_program_event(struct clock_event_device *dev, ktime_t expires, |
29 | int force) | ||
29 | { | 30 | { |
30 | struct clock_event_device *dev = __get_cpu_var(tick_cpu_device).evtdev; | ||
31 | ktime_t now = ktime_get(); | 31 | ktime_t now = ktime_get(); |
32 | int i; | ||
32 | 33 | ||
33 | while (1) { | 34 | for (i = 0;;) { |
34 | int ret = clockevents_program_event(dev, expires, now); | 35 | int ret = clockevents_program_event(dev, expires, now); |
35 | 36 | ||
36 | if (!ret || !force) | 37 | if (!ret || !force) |
37 | return ret; | 38 | return ret; |
39 | |||
40 | /* | ||
41 | * We tried 2 times to program the device with the given | ||
42 | * min_delta_ns. If that's not working then we double it | ||
43 | * and emit a warning. | ||
44 | */ | ||
45 | if (++i > 2) { | ||
46 | /* Increase the min. delta and try again */ | ||
47 | if (!dev->min_delta_ns) | ||
48 | dev->min_delta_ns = 5000; | ||
49 | else | ||
50 | dev->min_delta_ns += dev->min_delta_ns >> 1; | ||
51 | |||
52 | printk(KERN_WARNING | ||
53 | "CE: %s increasing min_delta_ns to %lu nsec\n", | ||
54 | dev->name ? dev->name : "?", | ||
55 | dev->min_delta_ns << 1); | ||
56 | |||
57 | i = 0; | ||
58 | } | ||
59 | |||
38 | now = ktime_get(); | 60 | now = ktime_get(); |
39 | expires = ktime_add(now, ktime_set(0, dev->min_delta_ns)); | 61 | expires = ktime_add_ns(now, dev->min_delta_ns); |
40 | } | 62 | } |
41 | } | 63 | } |
42 | 64 | ||
43 | /** | 65 | /** |
66 | * tick_program_event | ||
67 | */ | ||
68 | int tick_program_event(ktime_t expires, int force) | ||
69 | { | ||
70 | struct clock_event_device *dev = __get_cpu_var(tick_cpu_device).evtdev; | ||
71 | |||
72 | return tick_dev_program_event(dev, expires, force); | ||
73 | } | ||
74 | |||
75 | /** | ||
44 | * tick_resume_onshot - resume oneshot mode | 76 | * tick_resume_onshot - resume oneshot mode |
45 | */ | 77 | */ |
46 | void tick_resume_oneshot(void) | 78 | void tick_resume_oneshot(void) |
@@ -61,7 +93,7 @@ void tick_setup_oneshot(struct clock_event_device *newdev, | |||
61 | { | 93 | { |
62 | newdev->event_handler = handler; | 94 | newdev->event_handler = handler; |
63 | clockevents_set_mode(newdev, CLOCK_EVT_MODE_ONESHOT); | 95 | clockevents_set_mode(newdev, CLOCK_EVT_MODE_ONESHOT); |
64 | clockevents_program_event(newdev, next_event, ktime_get()); | 96 | tick_dev_program_event(newdev, next_event, 1); |
65 | } | 97 | } |
66 | 98 | ||
67 | /** | 99 | /** |
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 825b4c00fe44..a4d219398167 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/profile.h> | 20 | #include <linux/profile.h> |
21 | #include <linux/sched.h> | 21 | #include <linux/sched.h> |
22 | #include <linux/tick.h> | 22 | #include <linux/tick.h> |
23 | #include <linux/module.h> | ||
23 | 24 | ||
24 | #include <asm/irq_regs.h> | 25 | #include <asm/irq_regs.h> |
25 | 26 | ||
@@ -75,6 +76,9 @@ static void tick_do_update_jiffies64(ktime_t now) | |||
75 | incr * ticks); | 76 | incr * ticks); |
76 | } | 77 | } |
77 | do_timer(++ticks); | 78 | do_timer(++ticks); |
79 | |||
80 | /* Keep the tick_next_period variable up to date */ | ||
81 | tick_next_period = ktime_add(last_jiffies_update, tick_period); | ||
78 | } | 82 | } |
79 | write_sequnlock(&xtime_lock); | 83 | write_sequnlock(&xtime_lock); |
80 | } | 84 | } |
@@ -162,6 +166,8 @@ void tick_nohz_stop_idle(int cpu) | |||
162 | ts->idle_lastupdate = now; | 166 | ts->idle_lastupdate = now; |
163 | ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); | 167 | ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); |
164 | ts->idle_active = 0; | 168 | ts->idle_active = 0; |
169 | |||
170 | sched_clock_idle_wakeup_event(0); | ||
165 | } | 171 | } |
166 | } | 172 | } |
167 | 173 | ||
@@ -177,6 +183,7 @@ static ktime_t tick_nohz_start_idle(struct tick_sched *ts) | |||
177 | } | 183 | } |
178 | ts->idle_entrytime = now; | 184 | ts->idle_entrytime = now; |
179 | ts->idle_active = 1; | 185 | ts->idle_active = 1; |
186 | sched_clock_idle_sleep_event(); | ||
180 | return now; | 187 | return now; |
181 | } | 188 | } |
182 | 189 | ||
@@ -184,9 +191,17 @@ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) | |||
184 | { | 191 | { |
185 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | 192 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); |
186 | 193 | ||
187 | *last_update_time = ktime_to_us(ts->idle_lastupdate); | 194 | if (!tick_nohz_enabled) |
195 | return -1; | ||
196 | |||
197 | if (ts->idle_active) | ||
198 | *last_update_time = ktime_to_us(ts->idle_lastupdate); | ||
199 | else | ||
200 | *last_update_time = ktime_to_us(ktime_get()); | ||
201 | |||
188 | return ktime_to_us(ts->idle_sleeptime); | 202 | return ktime_to_us(ts->idle_sleeptime); |
189 | } | 203 | } |
204 | EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); | ||
190 | 205 | ||
191 | /** | 206 | /** |
192 | * tick_nohz_stop_sched_tick - stop the idle tick from the idle task | 207 | * tick_nohz_stop_sched_tick - stop the idle tick from the idle task |
@@ -218,7 +233,7 @@ void tick_nohz_stop_sched_tick(int inidle) | |||
218 | */ | 233 | */ |
219 | if (unlikely(!cpu_online(cpu))) { | 234 | if (unlikely(!cpu_online(cpu))) { |
220 | if (cpu == tick_do_timer_cpu) | 235 | if (cpu == tick_do_timer_cpu) |
221 | tick_do_timer_cpu = -1; | 236 | tick_do_timer_cpu = TICK_DO_TIMER_NONE; |
222 | } | 237 | } |
223 | 238 | ||
224 | if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) | 239 | if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE)) |
@@ -289,7 +304,6 @@ void tick_nohz_stop_sched_tick(int inidle) | |||
289 | ts->tick_stopped = 1; | 304 | ts->tick_stopped = 1; |
290 | ts->idle_jiffies = last_jiffies; | 305 | ts->idle_jiffies = last_jiffies; |
291 | rcu_enter_nohz(); | 306 | rcu_enter_nohz(); |
292 | sched_clock_tick_stop(cpu); | ||
293 | } | 307 | } |
294 | 308 | ||
295 | /* | 309 | /* |
@@ -301,7 +315,7 @@ void tick_nohz_stop_sched_tick(int inidle) | |||
301 | * invoked. | 315 | * invoked. |
302 | */ | 316 | */ |
303 | if (cpu == tick_do_timer_cpu) | 317 | if (cpu == tick_do_timer_cpu) |
304 | tick_do_timer_cpu = -1; | 318 | tick_do_timer_cpu = TICK_DO_TIMER_NONE; |
305 | 319 | ||
306 | ts->idle_sleeps++; | 320 | ts->idle_sleeps++; |
307 | 321 | ||
@@ -392,7 +406,6 @@ void tick_nohz_restart_sched_tick(void) | |||
392 | select_nohz_load_balancer(0); | 406 | select_nohz_load_balancer(0); |
393 | now = ktime_get(); | 407 | now = ktime_get(); |
394 | tick_do_update_jiffies64(now); | 408 | tick_do_update_jiffies64(now); |
395 | sched_clock_tick_start(cpu); | ||
396 | cpu_clear(cpu, nohz_cpu_mask); | 409 | cpu_clear(cpu, nohz_cpu_mask); |
397 | 410 | ||
398 | /* | 411 | /* |
@@ -467,7 +480,7 @@ static void tick_nohz_handler(struct clock_event_device *dev) | |||
467 | * this duty, then the jiffies update is still serialized by | 480 | * this duty, then the jiffies update is still serialized by |
468 | * xtime_lock. | 481 | * xtime_lock. |
469 | */ | 482 | */ |
470 | if (unlikely(tick_do_timer_cpu == -1)) | 483 | if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) |
471 | tick_do_timer_cpu = cpu; | 484 | tick_do_timer_cpu = cpu; |
472 | 485 | ||
473 | /* Check, if the jiffies need an update */ | 486 | /* Check, if the jiffies need an update */ |
@@ -569,7 +582,7 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer) | |||
569 | * this duty, then the jiffies update is still serialized by | 582 | * this duty, then the jiffies update is still serialized by |
570 | * xtime_lock. | 583 | * xtime_lock. |
571 | */ | 584 | */ |
572 | if (unlikely(tick_do_timer_cpu == -1)) | 585 | if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) |
573 | tick_do_timer_cpu = cpu; | 586 | tick_do_timer_cpu = cpu; |
574 | #endif | 587 | #endif |
575 | 588 | ||
@@ -621,7 +634,7 @@ void tick_setup_sched_timer(void) | |||
621 | */ | 634 | */ |
622 | hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); | 635 | hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
623 | ts->sched_timer.function = tick_sched_timer; | 636 | ts->sched_timer.function = tick_sched_timer; |
624 | ts->sched_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 637 | ts->sched_timer.cb_mode = HRTIMER_CB_IRQSAFE_PERCPU; |
625 | 638 | ||
626 | /* Get the next period (per cpu) */ | 639 | /* Get the next period (per cpu) */ |
627 | ts->sched_timer.expires = tick_init_jiffy_update(); | 640 | ts->sched_timer.expires = tick_init_jiffy_update(); |
@@ -645,17 +658,21 @@ void tick_setup_sched_timer(void) | |||
645 | ts->nohz_mode = NOHZ_MODE_HIGHRES; | 658 | ts->nohz_mode = NOHZ_MODE_HIGHRES; |
646 | #endif | 659 | #endif |
647 | } | 660 | } |
661 | #endif /* HIGH_RES_TIMERS */ | ||
648 | 662 | ||
663 | #if defined CONFIG_NO_HZ || defined CONFIG_HIGH_RES_TIMERS | ||
649 | void tick_cancel_sched_timer(int cpu) | 664 | void tick_cancel_sched_timer(int cpu) |
650 | { | 665 | { |
651 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | 666 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); |
652 | 667 | ||
668 | # ifdef CONFIG_HIGH_RES_TIMERS | ||
653 | if (ts->sched_timer.base) | 669 | if (ts->sched_timer.base) |
654 | hrtimer_cancel(&ts->sched_timer); | 670 | hrtimer_cancel(&ts->sched_timer); |
671 | # endif | ||
655 | 672 | ||
656 | ts->nohz_mode = NOHZ_MODE_INACTIVE; | 673 | ts->nohz_mode = NOHZ_MODE_INACTIVE; |
657 | } | 674 | } |
658 | #endif /* HIGH_RES_TIMERS */ | 675 | #endif |
659 | 676 | ||
660 | /** | 677 | /** |
661 | * Async notification about clocksource changes | 678 | * Async notification about clocksource changes |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 4231a3dc224a..f6e3af31b403 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -587,7 +587,7 @@ static int __ftrace_modify_code(void *data) | |||
587 | 587 | ||
588 | static void ftrace_run_update_code(int command) | 588 | static void ftrace_run_update_code(int command) |
589 | { | 589 | { |
590 | stop_machine_run(__ftrace_modify_code, &command, NR_CPUS); | 590 | stop_machine(__ftrace_modify_code, &command, NULL); |
591 | } | 591 | } |
592 | 592 | ||
593 | void ftrace_disable_daemon(void) | 593 | void ftrace_disable_daemon(void) |
@@ -787,7 +787,7 @@ static int ftrace_update_code(void) | |||
787 | !ftrace_enabled || !ftraced_trigger) | 787 | !ftrace_enabled || !ftraced_trigger) |
788 | return 0; | 788 | return 0; |
789 | 789 | ||
790 | stop_machine_run(__ftrace_update_code, NULL, NR_CPUS); | 790 | stop_machine(__ftrace_update_code, NULL, NULL); |
791 | 791 | ||
792 | return 1; | 792 | return 1; |
793 | } | 793 | } |
@@ -1564,7 +1564,7 @@ static int __init ftrace_dynamic_init(void) | |||
1564 | 1564 | ||
1565 | addr = (unsigned long)ftrace_record_ip; | 1565 | addr = (unsigned long)ftrace_record_ip; |
1566 | 1566 | ||
1567 | stop_machine_run(ftrace_dyn_arch_init, &addr, NR_CPUS); | 1567 | stop_machine(ftrace_dyn_arch_init, &addr, NULL); |
1568 | 1568 | ||
1569 | /* ftrace_dyn_arch_init places the return code in addr */ | 1569 | /* ftrace_dyn_arch_init places the return code in addr */ |
1570 | if (addr) { | 1570 | if (addr) { |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 868e121c8e38..8f3fb3db61c3 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -1183,7 +1183,6 @@ static void *find_next_entry_inc(struct trace_iterator *iter) | |||
1183 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) | 1183 | static void *s_next(struct seq_file *m, void *v, loff_t *pos) |
1184 | { | 1184 | { |
1185 | struct trace_iterator *iter = m->private; | 1185 | struct trace_iterator *iter = m->private; |
1186 | void *last_ent = iter->ent; | ||
1187 | int i = (int)*pos; | 1186 | int i = (int)*pos; |
1188 | void *ent; | 1187 | void *ent; |
1189 | 1188 | ||
@@ -1203,9 +1202,6 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos) | |||
1203 | 1202 | ||
1204 | iter->pos = *pos; | 1203 | iter->pos = *pos; |
1205 | 1204 | ||
1206 | if (last_ent && !ent) | ||
1207 | seq_puts(m, "\n\nvim:ft=help\n"); | ||
1208 | |||
1209 | return ent; | 1205 | return ent; |
1210 | } | 1206 | } |
1211 | 1207 | ||
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 421d6fe3650e..ece6cfb649fa 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c | |||
@@ -253,12 +253,14 @@ void start_critical_timings(void) | |||
253 | if (preempt_trace() || irq_trace()) | 253 | if (preempt_trace() || irq_trace()) |
254 | start_critical_timing(CALLER_ADDR0, CALLER_ADDR1); | 254 | start_critical_timing(CALLER_ADDR0, CALLER_ADDR1); |
255 | } | 255 | } |
256 | EXPORT_SYMBOL_GPL(start_critical_timings); | ||
256 | 257 | ||
257 | void stop_critical_timings(void) | 258 | void stop_critical_timings(void) |
258 | { | 259 | { |
259 | if (preempt_trace() || irq_trace()) | 260 | if (preempt_trace() || irq_trace()) |
260 | stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1); | 261 | stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1); |
261 | } | 262 | } |
263 | EXPORT_SYMBOL_GPL(stop_critical_timings); | ||
262 | 264 | ||
263 | #ifdef CONFIG_IRQSOFF_TRACER | 265 | #ifdef CONFIG_IRQSOFF_TRACER |
264 | #ifdef CONFIG_PROVE_LOCKING | 266 | #ifdef CONFIG_PROVE_LOCKING |
@@ -337,12 +339,14 @@ EXPORT_SYMBOL(trace_hardirqs_off_caller); | |||
337 | #ifdef CONFIG_PREEMPT_TRACER | 339 | #ifdef CONFIG_PREEMPT_TRACER |
338 | void trace_preempt_on(unsigned long a0, unsigned long a1) | 340 | void trace_preempt_on(unsigned long a0, unsigned long a1) |
339 | { | 341 | { |
340 | stop_critical_timing(a0, a1); | 342 | if (preempt_trace()) |
343 | stop_critical_timing(a0, a1); | ||
341 | } | 344 | } |
342 | 345 | ||
343 | void trace_preempt_off(unsigned long a0, unsigned long a1) | 346 | void trace_preempt_off(unsigned long a0, unsigned long a1) |
344 | { | 347 | { |
345 | start_critical_timing(a0, a1); | 348 | if (preempt_trace()) |
349 | start_critical_timing(a0, a1); | ||
346 | } | 350 | } |
347 | #endif /* CONFIG_PREEMPT_TRACER */ | 351 | #endif /* CONFIG_PREEMPT_TRACER */ |
348 | 352 | ||
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c index 3c8d61df4474..e303ccb62cdf 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c | |||
@@ -26,7 +26,8 @@ static struct task_struct *wakeup_task; | |||
26 | static int wakeup_cpu; | 26 | static int wakeup_cpu; |
27 | static unsigned wakeup_prio = -1; | 27 | static unsigned wakeup_prio = -1; |
28 | 28 | ||
29 | static DEFINE_SPINLOCK(wakeup_lock); | 29 | static raw_spinlock_t wakeup_lock = |
30 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | ||
30 | 31 | ||
31 | static void __wakeup_reset(struct trace_array *tr); | 32 | static void __wakeup_reset(struct trace_array *tr); |
32 | 33 | ||
@@ -56,7 +57,8 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip) | |||
56 | if (unlikely(disabled != 1)) | 57 | if (unlikely(disabled != 1)) |
57 | goto out; | 58 | goto out; |
58 | 59 | ||
59 | spin_lock_irqsave(&wakeup_lock, flags); | 60 | local_irq_save(flags); |
61 | __raw_spin_lock(&wakeup_lock); | ||
60 | 62 | ||
61 | if (unlikely(!wakeup_task)) | 63 | if (unlikely(!wakeup_task)) |
62 | goto unlock; | 64 | goto unlock; |
@@ -71,7 +73,8 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip) | |||
71 | trace_function(tr, data, ip, parent_ip, flags); | 73 | trace_function(tr, data, ip, parent_ip, flags); |
72 | 74 | ||
73 | unlock: | 75 | unlock: |
74 | spin_unlock_irqrestore(&wakeup_lock, flags); | 76 | __raw_spin_unlock(&wakeup_lock); |
77 | local_irq_restore(flags); | ||
75 | 78 | ||
76 | out: | 79 | out: |
77 | atomic_dec(&data->disabled); | 80 | atomic_dec(&data->disabled); |
@@ -145,7 +148,8 @@ wakeup_sched_switch(void *private, void *rq, struct task_struct *prev, | |||
145 | if (likely(disabled != 1)) | 148 | if (likely(disabled != 1)) |
146 | goto out; | 149 | goto out; |
147 | 150 | ||
148 | spin_lock_irqsave(&wakeup_lock, flags); | 151 | local_irq_save(flags); |
152 | __raw_spin_lock(&wakeup_lock); | ||
149 | 153 | ||
150 | /* We could race with grabbing wakeup_lock */ | 154 | /* We could race with grabbing wakeup_lock */ |
151 | if (unlikely(!tracer_enabled || next != wakeup_task)) | 155 | if (unlikely(!tracer_enabled || next != wakeup_task)) |
@@ -174,7 +178,8 @@ wakeup_sched_switch(void *private, void *rq, struct task_struct *prev, | |||
174 | 178 | ||
175 | out_unlock: | 179 | out_unlock: |
176 | __wakeup_reset(tr); | 180 | __wakeup_reset(tr); |
177 | spin_unlock_irqrestore(&wakeup_lock, flags); | 181 | __raw_spin_unlock(&wakeup_lock); |
182 | local_irq_restore(flags); | ||
178 | out: | 183 | out: |
179 | atomic_dec(&tr->data[cpu]->disabled); | 184 | atomic_dec(&tr->data[cpu]->disabled); |
180 | } | 185 | } |
@@ -209,8 +214,6 @@ static void __wakeup_reset(struct trace_array *tr) | |||
209 | struct trace_array_cpu *data; | 214 | struct trace_array_cpu *data; |
210 | int cpu; | 215 | int cpu; |
211 | 216 | ||
212 | assert_spin_locked(&wakeup_lock); | ||
213 | |||
214 | for_each_possible_cpu(cpu) { | 217 | for_each_possible_cpu(cpu) { |
215 | data = tr->data[cpu]; | 218 | data = tr->data[cpu]; |
216 | tracing_reset(data); | 219 | tracing_reset(data); |
@@ -229,9 +232,11 @@ static void wakeup_reset(struct trace_array *tr) | |||
229 | { | 232 | { |
230 | unsigned long flags; | 233 | unsigned long flags; |
231 | 234 | ||
232 | spin_lock_irqsave(&wakeup_lock, flags); | 235 | local_irq_save(flags); |
236 | __raw_spin_lock(&wakeup_lock); | ||
233 | __wakeup_reset(tr); | 237 | __wakeup_reset(tr); |
234 | spin_unlock_irqrestore(&wakeup_lock, flags); | 238 | __raw_spin_unlock(&wakeup_lock); |
239 | local_irq_restore(flags); | ||
235 | } | 240 | } |
236 | 241 | ||
237 | static void | 242 | static void |
@@ -252,7 +257,7 @@ wakeup_check_start(struct trace_array *tr, struct task_struct *p, | |||
252 | goto out; | 257 | goto out; |
253 | 258 | ||
254 | /* interrupts should be off from try_to_wake_up */ | 259 | /* interrupts should be off from try_to_wake_up */ |
255 | spin_lock(&wakeup_lock); | 260 | __raw_spin_lock(&wakeup_lock); |
256 | 261 | ||
257 | /* check for races. */ | 262 | /* check for races. */ |
258 | if (!tracer_enabled || p->prio >= wakeup_prio) | 263 | if (!tracer_enabled || p->prio >= wakeup_prio) |
@@ -274,7 +279,7 @@ wakeup_check_start(struct trace_array *tr, struct task_struct *p, | |||
274 | CALLER_ADDR1, CALLER_ADDR2, flags); | 279 | CALLER_ADDR1, CALLER_ADDR2, flags); |
275 | 280 | ||
276 | out_locked: | 281 | out_locked: |
277 | spin_unlock(&wakeup_lock); | 282 | __raw_spin_unlock(&wakeup_lock); |
278 | out: | 283 | out: |
279 | atomic_dec(&tr->data[cpu]->disabled); | 284 | atomic_dec(&tr->data[cpu]->disabled); |
280 | } | 285 | } |
diff --git a/kernel/trace/trace_sysprof.c b/kernel/trace/trace_sysprof.c index ce2d723c10e1..db58fb66a135 100644 --- a/kernel/trace/trace_sysprof.c +++ b/kernel/trace/trace_sysprof.c | |||
@@ -202,7 +202,7 @@ static void start_stack_timer(int cpu) | |||
202 | 202 | ||
203 | hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 203 | hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
204 | hrtimer->function = stack_trace_timer_fn; | 204 | hrtimer->function = stack_trace_timer_fn; |
205 | hrtimer->cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 205 | hrtimer->cb_mode = HRTIMER_CB_IRQSAFE_PERCPU; |
206 | 206 | ||
207 | hrtimer_start(hrtimer, ns_to_ktime(sample_period), HRTIMER_MODE_REL); | 207 | hrtimer_start(hrtimer, ns_to_ktime(sample_period), HRTIMER_MODE_REL); |
208 | } | 208 | } |
@@ -213,9 +213,7 @@ static void start_stack_timers(void) | |||
213 | int cpu; | 213 | int cpu; |
214 | 214 | ||
215 | for_each_online_cpu(cpu) { | 215 | for_each_online_cpu(cpu) { |
216 | cpumask_of_cpu_ptr(new_mask, cpu); | 216 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); |
217 | |||
218 | set_cpus_allowed_ptr(current, new_mask); | ||
219 | start_stack_timer(cpu); | 217 | start_stack_timer(cpu); |
220 | } | 218 | } |
221 | set_cpus_allowed_ptr(current, &saved_mask); | 219 | set_cpus_allowed_ptr(current, &saved_mask); |
diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 3da47ccdc5e5..8ebcd8532dfb 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c | |||
@@ -94,10 +94,10 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p) | |||
94 | stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB; | 94 | stats->hiwater_vm = mm->hiwater_vm * PAGE_SIZE / KB; |
95 | mmput(mm); | 95 | mmput(mm); |
96 | } | 96 | } |
97 | stats->read_char = p->rchar; | 97 | stats->read_char = p->ioac.rchar; |
98 | stats->write_char = p->wchar; | 98 | stats->write_char = p->ioac.wchar; |
99 | stats->read_syscalls = p->syscr; | 99 | stats->read_syscalls = p->ioac.syscr; |
100 | stats->write_syscalls = p->syscw; | 100 | stats->write_syscalls = p->ioac.syscw; |
101 | #ifdef CONFIG_TASK_IO_ACCOUNTING | 101 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
102 | stats->read_bytes = p->ioac.read_bytes; | 102 | stats->read_bytes = p->ioac.read_bytes; |
103 | stats->write_bytes = p->ioac.write_bytes; | 103 | stats->write_bytes = p->ioac.write_bytes; |
diff --git a/kernel/user.c b/kernel/user.c index 865ecf57a096..39d6159fae43 100644 --- a/kernel/user.c +++ b/kernel/user.c | |||
@@ -169,7 +169,7 @@ static ssize_t cpu_rt_runtime_show(struct kobject *kobj, | |||
169 | { | 169 | { |
170 | struct user_struct *up = container_of(kobj, struct user_struct, kobj); | 170 | struct user_struct *up = container_of(kobj, struct user_struct, kobj); |
171 | 171 | ||
172 | return sprintf(buf, "%lu\n", sched_group_rt_runtime(up->tg)); | 172 | return sprintf(buf, "%ld\n", sched_group_rt_runtime(up->tg)); |
173 | } | 173 | } |
174 | 174 | ||
175 | static ssize_t cpu_rt_runtime_store(struct kobject *kobj, | 175 | static ssize_t cpu_rt_runtime_store(struct kobject *kobj, |
@@ -180,7 +180,7 @@ static ssize_t cpu_rt_runtime_store(struct kobject *kobj, | |||
180 | unsigned long rt_runtime; | 180 | unsigned long rt_runtime; |
181 | int rc; | 181 | int rc; |
182 | 182 | ||
183 | sscanf(buf, "%lu", &rt_runtime); | 183 | sscanf(buf, "%ld", &rt_runtime); |
184 | 184 | ||
185 | rc = sched_group_set_rt_runtime(up->tg, rt_runtime); | 185 | rc = sched_group_set_rt_runtime(up->tg, rt_runtime); |
186 | 186 | ||
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index a9ab0596de44..532858fa5b88 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
@@ -6,7 +6,6 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/version.h> | ||
10 | #include <linux/nsproxy.h> | 9 | #include <linux/nsproxy.h> |
11 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
12 | #include <linux/user_namespace.h> | 11 | #include <linux/user_namespace.h> |
diff --git a/kernel/utsname.c b/kernel/utsname.c index 64d398f12444..815237a55af8 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/uts.h> | 13 | #include <linux/uts.h> |
14 | #include <linux/utsname.h> | 14 | #include <linux/utsname.h> |
15 | #include <linux/version.h> | ||
16 | #include <linux/err.h> | 15 | #include <linux/err.h> |
17 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
18 | 17 | ||
diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c index fe3a56c2256d..4ab9659d269e 100644 --- a/kernel/utsname_sysctl.c +++ b/kernel/utsname_sysctl.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/uts.h> | 13 | #include <linux/uts.h> |
14 | #include <linux/utsname.h> | 14 | #include <linux/utsname.h> |
15 | #include <linux/version.h> | ||
16 | #include <linux/sysctl.h> | 15 | #include <linux/sysctl.h> |
17 | 16 | ||
18 | static void *get_uts(ctl_table *table, int write) | 17 | static void *get_uts(ctl_table *table, int write) |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ec7e4f62aaff..4048e92aa04f 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -290,11 +290,11 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq) | |||
290 | 290 | ||
291 | BUG_ON(get_wq_data(work) != cwq); | 291 | BUG_ON(get_wq_data(work) != cwq); |
292 | work_clear_pending(work); | 292 | work_clear_pending(work); |
293 | lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 293 | lock_map_acquire(&cwq->wq->lockdep_map); |
294 | lock_acquire(&lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 294 | lock_map_acquire(&lockdep_map); |
295 | f(work); | 295 | f(work); |
296 | lock_release(&lockdep_map, 1, _THIS_IP_); | 296 | lock_map_release(&lockdep_map); |
297 | lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); | 297 | lock_map_release(&cwq->wq->lockdep_map); |
298 | 298 | ||
299 | if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { | 299 | if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { |
300 | printk(KERN_ERR "BUG: workqueue leaked lock or atomic: " | 300 | printk(KERN_ERR "BUG: workqueue leaked lock or atomic: " |
@@ -413,8 +413,8 @@ void flush_workqueue(struct workqueue_struct *wq) | |||
413 | int cpu; | 413 | int cpu; |
414 | 414 | ||
415 | might_sleep(); | 415 | might_sleep(); |
416 | lock_acquire(&wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 416 | lock_map_acquire(&wq->lockdep_map); |
417 | lock_release(&wq->lockdep_map, 1, _THIS_IP_); | 417 | lock_map_release(&wq->lockdep_map); |
418 | for_each_cpu_mask_nr(cpu, *cpu_map) | 418 | for_each_cpu_mask_nr(cpu, *cpu_map) |
419 | flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); | 419 | flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu)); |
420 | } | 420 | } |
@@ -441,8 +441,8 @@ int flush_work(struct work_struct *work) | |||
441 | if (!cwq) | 441 | if (!cwq) |
442 | return 0; | 442 | return 0; |
443 | 443 | ||
444 | lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 444 | lock_map_acquire(&cwq->wq->lockdep_map); |
445 | lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); | 445 | lock_map_release(&cwq->wq->lockdep_map); |
446 | 446 | ||
447 | prev = NULL; | 447 | prev = NULL; |
448 | spin_lock_irq(&cwq->lock); | 448 | spin_lock_irq(&cwq->lock); |
@@ -536,8 +536,8 @@ static void wait_on_work(struct work_struct *work) | |||
536 | 536 | ||
537 | might_sleep(); | 537 | might_sleep(); |
538 | 538 | ||
539 | lock_acquire(&work->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 539 | lock_map_acquire(&work->lockdep_map); |
540 | lock_release(&work->lockdep_map, 1, _THIS_IP_); | 540 | lock_map_release(&work->lockdep_map); |
541 | 541 | ||
542 | cwq = get_wq_data(work); | 542 | cwq = get_wq_data(work); |
543 | if (!cwq) | 543 | if (!cwq) |
@@ -830,10 +830,21 @@ struct workqueue_struct *__create_workqueue_key(const char *name, | |||
830 | start_workqueue_thread(cwq, -1); | 830 | start_workqueue_thread(cwq, -1); |
831 | } else { | 831 | } else { |
832 | cpu_maps_update_begin(); | 832 | cpu_maps_update_begin(); |
833 | /* | ||
834 | * We must place this wq on list even if the code below fails. | ||
835 | * cpu_down(cpu) can remove cpu from cpu_populated_map before | ||
836 | * destroy_workqueue() takes the lock, in that case we leak | ||
837 | * cwq[cpu]->thread. | ||
838 | */ | ||
833 | spin_lock(&workqueue_lock); | 839 | spin_lock(&workqueue_lock); |
834 | list_add(&wq->list, &workqueues); | 840 | list_add(&wq->list, &workqueues); |
835 | spin_unlock(&workqueue_lock); | 841 | spin_unlock(&workqueue_lock); |
836 | 842 | /* | |
843 | * We must initialize cwqs for each possible cpu even if we | ||
844 | * are going to call destroy_workqueue() finally. Otherwise | ||
845 | * cpu_up() can hit the uninitialized cwq once we drop the | ||
846 | * lock. | ||
847 | */ | ||
837 | for_each_possible_cpu(cpu) { | 848 | for_each_possible_cpu(cpu) { |
838 | cwq = init_cpu_workqueue(wq, cpu); | 849 | cwq = init_cpu_workqueue(wq, cpu); |
839 | if (err || !cpu_online(cpu)) | 850 | if (err || !cpu_online(cpu)) |
@@ -861,8 +872,8 @@ static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq) | |||
861 | if (cwq->thread == NULL) | 872 | if (cwq->thread == NULL) |
862 | return; | 873 | return; |
863 | 874 | ||
864 | lock_acquire(&cwq->wq->lockdep_map, 0, 0, 0, 2, _THIS_IP_); | 875 | lock_map_acquire(&cwq->wq->lockdep_map); |
865 | lock_release(&cwq->wq->lockdep_map, 1, _THIS_IP_); | 876 | lock_map_release(&cwq->wq->lockdep_map); |
866 | 877 | ||
867 | flush_cpu_workqueue(cwq); | 878 | flush_cpu_workqueue(cwq); |
868 | /* | 879 | /* |