diff options
Diffstat (limited to 'kernel')
74 files changed, 2830 insertions, 1711 deletions
diff --git a/kernel/acct.c b/kernel/acct.c index dd68b9059418..f6006a60df5d 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
@@ -548,7 +548,7 @@ static void do_acct_process(struct bsd_acct_struct *acct, | |||
548 | #endif | 548 | #endif |
549 | 549 | ||
550 | spin_lock_irq(¤t->sighand->siglock); | 550 | spin_lock_irq(¤t->sighand->siglock); |
551 | tty = current->signal->tty; | 551 | tty = current->signal->tty; /* Safe as we hold the siglock */ |
552 | ac.ac_tty = tty ? old_encode_dev(tty_devnum(tty)) : 0; | 552 | ac.ac_tty = tty ? old_encode_dev(tty_devnum(tty)) : 0; |
553 | ac.ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime))); | 553 | ac.ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime))); |
554 | ac.ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime))); | 554 | ac.ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime))); |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 972f8e61d36a..cf5bc2f5f9c3 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -243,10 +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; | ||
246 | if (unlikely(!ctx)) | 247 | if (unlikely(!ctx)) |
247 | return 0; | 248 | return 0; |
249 | n = ctx->major; | ||
248 | 250 | ||
249 | unsigned n = ctx->major; | ||
250 | switch (audit_classify_syscall(ctx->arch, n)) { | 251 | switch (audit_classify_syscall(ctx->arch, n)) { |
251 | case 0: /* native */ | 252 | case 0: /* native */ |
252 | if ((mask & AUDIT_PERM_WRITE) && | 253 | if ((mask & AUDIT_PERM_WRITE) && |
@@ -1203,13 +1204,13 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1203 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", | 1204 | (context->return_valid==AUDITSC_SUCCESS)?"yes":"no", |
1204 | context->return_code); | 1205 | context->return_code); |
1205 | 1206 | ||
1206 | mutex_lock(&tty_mutex); | 1207 | spin_lock_irq(&tsk->sighand->siglock); |
1207 | read_lock(&tasklist_lock); | ||
1208 | if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name) | 1208 | if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name) |
1209 | tty = tsk->signal->tty->name; | 1209 | tty = tsk->signal->tty->name; |
1210 | else | 1210 | else |
1211 | tty = "(none)"; | 1211 | tty = "(none)"; |
1212 | read_unlock(&tasklist_lock); | 1212 | spin_unlock_irq(&tsk->sighand->siglock); |
1213 | |||
1213 | audit_log_format(ab, | 1214 | audit_log_format(ab, |
1214 | " a0=%lx a1=%lx a2=%lx a3=%lx items=%d" | 1215 | " a0=%lx a1=%lx a2=%lx a3=%lx items=%d" |
1215 | " ppid=%d pid=%d auid=%u uid=%u gid=%u" | 1216 | " ppid=%d pid=%d auid=%u uid=%u gid=%u" |
@@ -1229,7 +1230,6 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1229 | context->egid, context->sgid, context->fsgid, tty, | 1230 | context->egid, context->sgid, context->fsgid, tty, |
1230 | tsk->sessionid); | 1231 | tsk->sessionid); |
1231 | 1232 | ||
1232 | mutex_unlock(&tty_mutex); | ||
1233 | 1233 | ||
1234 | audit_log_task_info(ab, tsk); | 1234 | audit_log_task_info(ab, tsk); |
1235 | if (context->filterkey) { | 1235 | if (context->filterkey) { |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 13932abde159..8c6e1c17e6d3 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -2735,21 +2735,24 @@ void cgroup_fork_callbacks(struct task_struct *child) | |||
2735 | * Called on every change to mm->owner. mm_init_owner() does not | 2735 | * Called on every change to mm->owner. mm_init_owner() does not |
2736 | * invoke this routine, since it assigns the mm->owner the first time | 2736 | * invoke this routine, since it assigns the mm->owner the first time |
2737 | * and does not change it. | 2737 | * and does not change it. |
2738 | * | ||
2739 | * The callbacks are invoked with mmap_sem held in read mode. | ||
2738 | */ | 2740 | */ |
2739 | void cgroup_mm_owner_callbacks(struct task_struct *old, struct task_struct *new) | 2741 | void cgroup_mm_owner_callbacks(struct task_struct *old, struct task_struct *new) |
2740 | { | 2742 | { |
2741 | struct cgroup *oldcgrp, *newcgrp; | 2743 | struct cgroup *oldcgrp, *newcgrp = NULL; |
2742 | 2744 | ||
2743 | if (need_mm_owner_callback) { | 2745 | if (need_mm_owner_callback) { |
2744 | int i; | 2746 | int i; |
2745 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 2747 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
2746 | struct cgroup_subsys *ss = subsys[i]; | 2748 | struct cgroup_subsys *ss = subsys[i]; |
2747 | oldcgrp = task_cgroup(old, ss->subsys_id); | 2749 | oldcgrp = task_cgroup(old, ss->subsys_id); |
2748 | newcgrp = task_cgroup(new, ss->subsys_id); | 2750 | if (new) |
2751 | newcgrp = task_cgroup(new, ss->subsys_id); | ||
2749 | if (oldcgrp == newcgrp) | 2752 | if (oldcgrp == newcgrp) |
2750 | continue; | 2753 | continue; |
2751 | if (ss->mm_owner_changed) | 2754 | if (ss->mm_owner_changed) |
2752 | ss->mm_owner_changed(ss, oldcgrp, newcgrp); | 2755 | ss->mm_owner_changed(ss, oldcgrp, newcgrp, new); |
2753 | } | 2756 | } |
2754 | } | 2757 | } |
2755 | } | 2758 | } |
diff --git a/kernel/compat.c b/kernel/compat.c index 32c254a8ab9a..8eafe3eb50d9 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
@@ -23,9 +23,68 @@ | |||
23 | #include <linux/timex.h> | 23 | #include <linux/timex.h> |
24 | #include <linux/migrate.h> | 24 | #include <linux/migrate.h> |
25 | #include <linux/posix-timers.h> | 25 | #include <linux/posix-timers.h> |
26 | #include <linux/times.h> | ||
26 | 27 | ||
27 | #include <asm/uaccess.h> | 28 | #include <asm/uaccess.h> |
28 | 29 | ||
30 | /* | ||
31 | * Note that the native side is already converted to a timespec, because | ||
32 | * that's what we want anyway. | ||
33 | */ | ||
34 | static int compat_get_timeval(struct timespec *o, | ||
35 | struct compat_timeval __user *i) | ||
36 | { | ||
37 | long usec; | ||
38 | |||
39 | if (get_user(o->tv_sec, &i->tv_sec) || | ||
40 | get_user(usec, &i->tv_usec)) | ||
41 | return -EFAULT; | ||
42 | o->tv_nsec = usec * 1000; | ||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static int compat_put_timeval(struct compat_timeval __user *o, | ||
47 | struct timeval *i) | ||
48 | { | ||
49 | return (put_user(i->tv_sec, &o->tv_sec) || | ||
50 | put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0; | ||
51 | } | ||
52 | |||
53 | asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, | ||
54 | struct timezone __user *tz) | ||
55 | { | ||
56 | if (tv) { | ||
57 | struct timeval ktv; | ||
58 | do_gettimeofday(&ktv); | ||
59 | if (compat_put_timeval(tv, &ktv)) | ||
60 | return -EFAULT; | ||
61 | } | ||
62 | if (tz) { | ||
63 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | ||
64 | return -EFAULT; | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, | ||
71 | struct timezone __user *tz) | ||
72 | { | ||
73 | struct timespec kts; | ||
74 | struct timezone ktz; | ||
75 | |||
76 | if (tv) { | ||
77 | if (compat_get_timeval(&kts, tv)) | ||
78 | return -EFAULT; | ||
79 | } | ||
80 | if (tz) { | ||
81 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | ||
82 | return -EFAULT; | ||
83 | } | ||
84 | |||
85 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | ||
86 | } | ||
87 | |||
29 | int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) | 88 | int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
30 | { | 89 | { |
31 | return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) || | 90 | return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) || |
@@ -150,49 +209,23 @@ asmlinkage long compat_sys_setitimer(int which, | |||
150 | return 0; | 209 | return 0; |
151 | } | 210 | } |
152 | 211 | ||
212 | static compat_clock_t clock_t_to_compat_clock_t(clock_t x) | ||
213 | { | ||
214 | return compat_jiffies_to_clock_t(clock_t_to_jiffies(x)); | ||
215 | } | ||
216 | |||
153 | asmlinkage long compat_sys_times(struct compat_tms __user *tbuf) | 217 | asmlinkage long compat_sys_times(struct compat_tms __user *tbuf) |
154 | { | 218 | { |
155 | /* | ||
156 | * In the SMP world we might just be unlucky and have one of | ||
157 | * the times increment as we use it. Since the value is an | ||
158 | * atomically safe type this is just fine. Conceptually its | ||
159 | * as if the syscall took an instant longer to occur. | ||
160 | */ | ||
161 | if (tbuf) { | 219 | if (tbuf) { |
220 | struct tms tms; | ||
162 | struct compat_tms tmp; | 221 | struct compat_tms tmp; |
163 | struct task_struct *tsk = current; | 222 | |
164 | struct task_struct *t; | 223 | do_sys_times(&tms); |
165 | cputime_t utime, stime, cutime, cstime; | 224 | /* Convert our struct tms to the compat version. */ |
166 | 225 | tmp.tms_utime = clock_t_to_compat_clock_t(tms.tms_utime); | |
167 | read_lock(&tasklist_lock); | 226 | tmp.tms_stime = clock_t_to_compat_clock_t(tms.tms_stime); |
168 | utime = tsk->signal->utime; | 227 | tmp.tms_cutime = clock_t_to_compat_clock_t(tms.tms_cutime); |
169 | stime = tsk->signal->stime; | 228 | tmp.tms_cstime = clock_t_to_compat_clock_t(tms.tms_cstime); |
170 | t = tsk; | ||
171 | do { | ||
172 | utime = cputime_add(utime, t->utime); | ||
173 | stime = cputime_add(stime, t->stime); | ||
174 | t = next_thread(t); | ||
175 | } while (t != tsk); | ||
176 | |||
177 | /* | ||
178 | * While we have tasklist_lock read-locked, no dying thread | ||
179 | * can be updating current->signal->[us]time. Instead, | ||
180 | * we got their counts included in the live thread loop. | ||
181 | * However, another thread can come in right now and | ||
182 | * do a wait call that updates current->signal->c[us]time. | ||
183 | * To make sure we always see that pair updated atomically, | ||
184 | * we take the siglock around fetching them. | ||
185 | */ | ||
186 | spin_lock_irq(&tsk->sighand->siglock); | ||
187 | cutime = tsk->signal->cutime; | ||
188 | cstime = tsk->signal->cstime; | ||
189 | spin_unlock_irq(&tsk->sighand->siglock); | ||
190 | read_unlock(&tasklist_lock); | ||
191 | |||
192 | tmp.tms_utime = compat_jiffies_to_clock_t(cputime_to_jiffies(utime)); | ||
193 | tmp.tms_stime = compat_jiffies_to_clock_t(cputime_to_jiffies(stime)); | ||
194 | tmp.tms_cutime = compat_jiffies_to_clock_t(cputime_to_jiffies(cutime)); | ||
195 | tmp.tms_cstime = compat_jiffies_to_clock_t(cputime_to_jiffies(cstime)); | ||
196 | if (copy_to_user(tbuf, &tmp, sizeof(tmp))) | 229 | if (copy_to_user(tbuf, &tmp, sizeof(tmp))) |
197 | return -EFAULT; | 230 | return -EFAULT; |
198 | } | 231 | } |
diff --git a/kernel/cpu.c b/kernel/cpu.c index f17e9854c246..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(); |
@@ -453,6 +454,25 @@ out: | |||
453 | } | 454 | } |
454 | #endif /* CONFIG_PM_SLEEP_SMP */ | 455 | #endif /* CONFIG_PM_SLEEP_SMP */ |
455 | 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 | |||
456 | #endif /* CONFIG_SMP */ | 476 | #endif /* CONFIG_SMP */ |
457 | 477 | ||
458 | /* | 478 | /* |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index d5ab79cf516d..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 |
@@ -236,9 +238,11 @@ static struct cpuset top_cpuset = { | |||
236 | 238 | ||
237 | static DEFINE_MUTEX(callback_mutex); | 239 | static DEFINE_MUTEX(callback_mutex); |
238 | 240 | ||
239 | /* This is ugly, but preserves the userspace API for existing cpuset | 241 | /* |
242 | * This is ugly, but preserves the userspace API for existing cpuset | ||
240 | * users. If someone tries to mount the "cpuset" filesystem, we | 243 | * users. If someone tries to mount the "cpuset" filesystem, we |
241 | * silently switch it to mount "cgroup" instead */ | 244 | * silently switch it to mount "cgroup" instead |
245 | */ | ||
242 | static int cpuset_get_sb(struct file_system_type *fs_type, | 246 | static int cpuset_get_sb(struct file_system_type *fs_type, |
243 | int flags, const char *unused_dev_name, | 247 | int flags, const char *unused_dev_name, |
244 | void *data, struct vfsmount *mnt) | 248 | void *data, struct vfsmount *mnt) |
@@ -473,10 +477,9 @@ static int validate_change(const struct cpuset *cur, const struct cpuset *trial) | |||
473 | } | 477 | } |
474 | 478 | ||
475 | /* | 479 | /* |
476 | * Helper routine for rebuild_sched_domains(). | 480 | * Helper routine for generate_sched_domains(). |
477 | * Do cpusets a, b have overlapping cpus_allowed masks? | 481 | * Do cpusets a, b have overlapping cpus_allowed masks? |
478 | */ | 482 | */ |
479 | |||
480 | static int cpusets_overlap(struct cpuset *a, struct cpuset *b) | 483 | static int cpusets_overlap(struct cpuset *a, struct cpuset *b) |
481 | { | 484 | { |
482 | return cpus_intersects(a->cpus_allowed, b->cpus_allowed); | 485 | return cpus_intersects(a->cpus_allowed, b->cpus_allowed); |
@@ -518,26 +521,15 @@ update_domain_attr_tree(struct sched_domain_attr *dattr, struct cpuset *c) | |||
518 | } | 521 | } |
519 | 522 | ||
520 | /* | 523 | /* |
521 | * rebuild_sched_domains() | 524 | * generate_sched_domains() |
522 | * | 525 | * |
523 | * This routine will be called to rebuild the scheduler's dynamic | 526 | * This function builds a partial partition of the systems CPUs |
524 | * sched domains: | 527 | * A 'partial partition' is a set of non-overlapping subsets whose |
525 | * - if the flag 'sched_load_balance' of any cpuset with non-empty | 528 | * union is a subset of that set. |
526 | * 'cpus' changes, | 529 | * The output of this function needs to be passed to kernel/sched.c |
527 | * - or if the 'cpus' allowed changes in any cpuset which has that | 530 | * partition_sched_domains() routine, which will rebuild the scheduler's |
528 | * flag enabled, | 531 | * load balancing domains (sched domains) as specified by that partial |
529 | * - or if the 'sched_relax_domain_level' of any cpuset which has | 532 | * partition. |
530 | * that flag enabled and with non-empty 'cpus' changes, | ||
531 | * - or if any cpuset with non-empty 'cpus' is removed, | ||
532 | * - or if a cpu gets offlined. | ||
533 | * | ||
534 | * This routine builds a partial partition of the systems CPUs | ||
535 | * (the set of non-overlappping cpumask_t's in the array 'part' | ||
536 | * below), and passes that partial partition to the kernel/sched.c | ||
537 | * partition_sched_domains() routine, which will rebuild the | ||
538 | * schedulers load balancing domains (sched domains) as specified | ||
539 | * by that partial partition. A 'partial partition' is a set of | ||
540 | * non-overlapping subsets whose union is a subset of that set. | ||
541 | * | 533 | * |
542 | * See "What is sched_load_balance" in Documentation/cpusets.txt | 534 | * See "What is sched_load_balance" in Documentation/cpusets.txt |
543 | * for a background explanation of this. | 535 | * for a background explanation of this. |
@@ -547,13 +539,7 @@ update_domain_attr_tree(struct sched_domain_attr *dattr, struct cpuset *c) | |||
547 | * domains when operating in the severe memory shortage situations | 539 | * domains when operating in the severe memory shortage situations |
548 | * that could cause allocation failures below. | 540 | * that could cause allocation failures below. |
549 | * | 541 | * |
550 | * Call with cgroup_mutex held. May take callback_mutex during | 542 | * Must be called with cgroup_lock held. |
551 | * call due to the kfifo_alloc() and kmalloc() calls. May nest | ||
552 | * a call to the get_online_cpus()/put_online_cpus() pair. | ||
553 | * Must not be called holding callback_mutex, because we must not | ||
554 | * call get_online_cpus() while holding callback_mutex. Elsewhere | ||
555 | * the kernel nests callback_mutex inside get_online_cpus() calls. | ||
556 | * So the reverse nesting would risk an ABBA deadlock. | ||
557 | * | 543 | * |
558 | * The three key local variables below are: | 544 | * The three key local variables below are: |
559 | * q - a linked-list queue of cpuset pointers, used to implement a | 545 | * q - a linked-list queue of cpuset pointers, used to implement a |
@@ -588,10 +574,10 @@ update_domain_attr_tree(struct sched_domain_attr *dattr, struct cpuset *c) | |||
588 | * element of the partition (one sched domain) to be passed to | 574 | * element of the partition (one sched domain) to be passed to |
589 | * partition_sched_domains(). | 575 | * partition_sched_domains(). |
590 | */ | 576 | */ |
591 | 577 | static int generate_sched_domains(cpumask_t **domains, | |
592 | void rebuild_sched_domains(void) | 578 | struct sched_domain_attr **attributes) |
593 | { | 579 | { |
594 | LIST_HEAD(q); /* queue of cpusets to be scanned*/ | 580 | LIST_HEAD(q); /* queue of cpusets to be scanned */ |
595 | struct cpuset *cp; /* scans q */ | 581 | struct cpuset *cp; /* scans q */ |
596 | struct cpuset **csa; /* array of all cpuset ptrs */ | 582 | struct cpuset **csa; /* array of all cpuset ptrs */ |
597 | int csn; /* how many cpuset ptrs in csa so far */ | 583 | int csn; /* how many cpuset ptrs in csa so far */ |
@@ -601,23 +587,26 @@ void rebuild_sched_domains(void) | |||
601 | int ndoms; /* number of sched domains in result */ | 587 | int ndoms; /* number of sched domains in result */ |
602 | int nslot; /* next empty doms[] cpumask_t slot */ | 588 | int nslot; /* next empty doms[] cpumask_t slot */ |
603 | 589 | ||
604 | csa = NULL; | 590 | ndoms = 0; |
605 | doms = NULL; | 591 | doms = NULL; |
606 | dattr = NULL; | 592 | dattr = NULL; |
593 | csa = NULL; | ||
607 | 594 | ||
608 | /* 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 */ |
609 | if (is_sched_load_balance(&top_cpuset)) { | 596 | if (is_sched_load_balance(&top_cpuset)) { |
610 | ndoms = 1; | ||
611 | doms = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 597 | doms = kmalloc(sizeof(cpumask_t), GFP_KERNEL); |
612 | if (!doms) | 598 | if (!doms) |
613 | goto rebuild; | 599 | goto done; |
600 | |||
614 | dattr = kmalloc(sizeof(struct sched_domain_attr), GFP_KERNEL); | 601 | dattr = kmalloc(sizeof(struct sched_domain_attr), GFP_KERNEL); |
615 | if (dattr) { | 602 | if (dattr) { |
616 | *dattr = SD_ATTR_INIT; | 603 | *dattr = SD_ATTR_INIT; |
617 | update_domain_attr_tree(dattr, &top_cpuset); | 604 | update_domain_attr_tree(dattr, &top_cpuset); |
618 | } | 605 | } |
619 | *doms = top_cpuset.cpus_allowed; | 606 | *doms = top_cpuset.cpus_allowed; |
620 | goto rebuild; | 607 | |
608 | ndoms = 1; | ||
609 | goto done; | ||
621 | } | 610 | } |
622 | 611 | ||
623 | csa = kmalloc(number_of_cpusets * sizeof(cp), GFP_KERNEL); | 612 | csa = kmalloc(number_of_cpusets * sizeof(cp), GFP_KERNEL); |
@@ -680,61 +669,141 @@ restart: | |||
680 | } | 669 | } |
681 | } | 670 | } |
682 | 671 | ||
683 | /* 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 | */ | ||
684 | doms = kmalloc(ndoms * sizeof(cpumask_t), GFP_KERNEL); | 676 | doms = kmalloc(ndoms * sizeof(cpumask_t), GFP_KERNEL); |
685 | if (!doms) | 677 | if (!doms) { |
686 | 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 | */ | ||
687 | dattr = kmalloc(ndoms * sizeof(struct sched_domain_attr), GFP_KERNEL); | 686 | dattr = kmalloc(ndoms * sizeof(struct sched_domain_attr), GFP_KERNEL); |
688 | 687 | ||
689 | for (nslot = 0, i = 0; i < csn; i++) { | 688 | for (nslot = 0, i = 0; i < csn; i++) { |
690 | struct cpuset *a = csa[i]; | 689 | struct cpuset *a = csa[i]; |
690 | cpumask_t *dp; | ||
691 | int apn = a->pn; | 691 | int apn = a->pn; |
692 | 692 | ||
693 | if (apn >= 0) { | 693 | if (apn < 0) { |
694 | cpumask_t *dp = doms + nslot; | 694 | /* Skip completed partitions */ |
695 | 695 | continue; | |
696 | if (nslot == ndoms) { | 696 | } |
697 | static int warnings = 10; | 697 | |
698 | if (warnings) { | 698 | dp = doms + nslot; |
699 | printk(KERN_WARNING | 699 | |
700 | "rebuild_sched_domains confused:" | 700 | if (nslot == ndoms) { |
701 | " nslot %d, ndoms %d, csn %d, i %d," | 701 | static int warnings = 10; |
702 | " apn %d\n", | 702 | if (warnings) { |
703 | nslot, ndoms, csn, i, apn); | 703 | printk(KERN_WARNING |
704 | warnings--; | 704 | "rebuild_sched_domains confused:" |
705 | } | 705 | " nslot %d, ndoms %d, csn %d, i %d," |
706 | continue; | 706 | " apn %d\n", |
707 | nslot, ndoms, csn, i, apn); | ||
708 | warnings--; | ||
707 | } | 709 | } |
710 | continue; | ||
711 | } | ||
708 | 712 | ||
709 | cpus_clear(*dp); | 713 | cpus_clear(*dp); |
710 | if (dattr) | 714 | if (dattr) |
711 | *(dattr + nslot) = SD_ATTR_INIT; | 715 | *(dattr + nslot) = SD_ATTR_INIT; |
712 | for (j = i; j < csn; j++) { | 716 | for (j = i; j < csn; j++) { |
713 | struct cpuset *b = csa[j]; | 717 | struct cpuset *b = csa[j]; |
714 | 718 | ||
715 | if (apn == b->pn) { | 719 | if (apn == b->pn) { |
716 | cpus_or(*dp, *dp, b->cpus_allowed); | 720 | cpus_or(*dp, *dp, b->cpus_allowed); |
717 | b->pn = -1; | 721 | if (dattr) |
718 | if (dattr) | 722 | update_domain_attr_tree(dattr + nslot, b); |
719 | update_domain_attr_tree(dattr | 723 | |
720 | + nslot, b); | 724 | /* Done with this partition */ |
721 | } | 725 | b->pn = -1; |
722 | } | 726 | } |
723 | nslot++; | ||
724 | } | 727 | } |
728 | nslot++; | ||
725 | } | 729 | } |
726 | BUG_ON(nslot != ndoms); | 730 | BUG_ON(nslot != ndoms); |
727 | 731 | ||
728 | rebuild: | 732 | done: |
729 | /* 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 | |||
730 | get_online_cpus(); | 756 | get_online_cpus(); |
731 | 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 | |||
732 | put_online_cpus(); | 766 | put_online_cpus(); |
767 | } | ||
733 | 768 | ||
734 | done: | 769 | static DECLARE_WORK(rebuild_sched_domains_work, do_rebuild_sched_domains); |
735 | kfree(csa); | 770 | |
736 | /* Don't kfree(doms) -- partition_sched_domains() does that. */ | 771 | /* |
737 | /* Don't kfree(dattr) -- partition_sched_domains() does that. */ | 772 | * Rebuild scheduler domains, asynchronously via workqueue. |
773 | * | ||
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); | ||
738 | } | 807 | } |
739 | 808 | ||
740 | /** | 809 | /** |
@@ -774,37 +843,25 @@ static void cpuset_change_cpumask(struct task_struct *tsk, | |||
774 | /** | 843 | /** |
775 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. | 844 | * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. |
776 | * @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() | ||
777 | * | 847 | * |
778 | * Called with cgroup_mutex held | 848 | * Called with cgroup_mutex held |
779 | * | 849 | * |
780 | * 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, |
781 | * calling callback functions for each. | 851 | * calling callback functions for each. |
782 | * | 852 | * |
783 | * 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. | ||
784 | */ | 855 | */ |
785 | static int update_tasks_cpumask(struct cpuset *cs) | 856 | static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap) |
786 | { | 857 | { |
787 | struct cgroup_scanner scan; | 858 | struct cgroup_scanner scan; |
788 | struct ptr_heap heap; | ||
789 | int retval; | ||
790 | |||
791 | /* | ||
792 | * cgroup_scan_tasks() will initialize heap->gt for us. | ||
793 | * heap_init() is still needed here for we should not change | ||
794 | * cs->cpus_allowed when heap_init() fails. | ||
795 | */ | ||
796 | retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL); | ||
797 | if (retval) | ||
798 | return retval; | ||
799 | 859 | ||
800 | scan.cg = cs->css.cgroup; | 860 | scan.cg = cs->css.cgroup; |
801 | scan.test_task = cpuset_test_cpumask; | 861 | scan.test_task = cpuset_test_cpumask; |
802 | scan.process_task = cpuset_change_cpumask; | 862 | scan.process_task = cpuset_change_cpumask; |
803 | scan.heap = &heap; | 863 | scan.heap = heap; |
804 | retval = cgroup_scan_tasks(&scan); | 864 | cgroup_scan_tasks(&scan); |
805 | |||
806 | heap_free(&heap); | ||
807 | return retval; | ||
808 | } | 865 | } |
809 | 866 | ||
810 | /** | 867 | /** |
@@ -814,6 +871,7 @@ static int update_tasks_cpumask(struct cpuset *cs) | |||
814 | */ | 871 | */ |
815 | static int update_cpumask(struct cpuset *cs, const char *buf) | 872 | static int update_cpumask(struct cpuset *cs, const char *buf) |
816 | { | 873 | { |
874 | struct ptr_heap heap; | ||
817 | struct cpuset trialcs; | 875 | struct cpuset trialcs; |
818 | int retval; | 876 | int retval; |
819 | int is_load_balanced; | 877 | int is_load_balanced; |
@@ -848,6 +906,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf) | |||
848 | if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) | 906 | if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed)) |
849 | return 0; | 907 | return 0; |
850 | 908 | ||
909 | retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL); | ||
910 | if (retval) | ||
911 | return retval; | ||
912 | |||
851 | is_load_balanced = is_sched_load_balance(&trialcs); | 913 | is_load_balanced = is_sched_load_balance(&trialcs); |
852 | 914 | ||
853 | mutex_lock(&callback_mutex); | 915 | mutex_lock(&callback_mutex); |
@@ -858,12 +920,12 @@ static int update_cpumask(struct cpuset *cs, const char *buf) | |||
858 | * Scan tasks in the cpuset, and update the cpumasks of any | 920 | * Scan tasks in the cpuset, and update the cpumasks of any |
859 | * that need an update. | 921 | * that need an update. |
860 | */ | 922 | */ |
861 | retval = update_tasks_cpumask(cs); | 923 | update_tasks_cpumask(cs, &heap); |
862 | if (retval < 0) | 924 | |
863 | return retval; | 925 | heap_free(&heap); |
864 | 926 | ||
865 | if (is_load_balanced) | 927 | if (is_load_balanced) |
866 | rebuild_sched_domains(); | 928 | async_rebuild_sched_domains(); |
867 | return 0; | 929 | return 0; |
868 | } | 930 | } |
869 | 931 | ||
@@ -1090,7 +1152,7 @@ static int update_relax_domain_level(struct cpuset *cs, s64 val) | |||
1090 | if (val != cs->relax_domain_level) { | 1152 | if (val != cs->relax_domain_level) { |
1091 | cs->relax_domain_level = val; | 1153 | cs->relax_domain_level = val; |
1092 | if (!cpus_empty(cs->cpus_allowed) && is_sched_load_balance(cs)) | 1154 | if (!cpus_empty(cs->cpus_allowed) && is_sched_load_balance(cs)) |
1093 | rebuild_sched_domains(); | 1155 | async_rebuild_sched_domains(); |
1094 | } | 1156 | } |
1095 | 1157 | ||
1096 | return 0; | 1158 | return 0; |
@@ -1131,7 +1193,7 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, | |||
1131 | mutex_unlock(&callback_mutex); | 1193 | mutex_unlock(&callback_mutex); |
1132 | 1194 | ||
1133 | if (cpus_nonempty && balance_flag_changed) | 1195 | if (cpus_nonempty && balance_flag_changed) |
1134 | rebuild_sched_domains(); | 1196 | async_rebuild_sched_domains(); |
1135 | 1197 | ||
1136 | return 0; | 1198 | return 0; |
1137 | } | 1199 | } |
@@ -1492,6 +1554,9 @@ static u64 cpuset_read_u64(struct cgroup *cont, struct cftype *cft) | |||
1492 | default: | 1554 | default: |
1493 | BUG(); | 1555 | BUG(); |
1494 | } | 1556 | } |
1557 | |||
1558 | /* Unreachable but makes gcc happy */ | ||
1559 | return 0; | ||
1495 | } | 1560 | } |
1496 | 1561 | ||
1497 | static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft) | 1562 | static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft) |
@@ -1504,6 +1569,9 @@ static s64 cpuset_read_s64(struct cgroup *cont, struct cftype *cft) | |||
1504 | default: | 1569 | default: |
1505 | BUG(); | 1570 | BUG(); |
1506 | } | 1571 | } |
1572 | |||
1573 | /* Unrechable but makes gcc happy */ | ||
1574 | return 0; | ||
1507 | } | 1575 | } |
1508 | 1576 | ||
1509 | 1577 | ||
@@ -1692,15 +1760,9 @@ static struct cgroup_subsys_state *cpuset_create( | |||
1692 | } | 1760 | } |
1693 | 1761 | ||
1694 | /* | 1762 | /* |
1695 | * Locking note on the strange update_flag() call below: | ||
1696 | * | ||
1697 | * If the cpuset being removed has its flag 'sched_load_balance' | 1763 | * If the cpuset being removed has its flag 'sched_load_balance' |
1698 | * enabled, then simulate turning sched_load_balance off, which | 1764 | * enabled, then simulate turning sched_load_balance off, which |
1699 | * will call rebuild_sched_domains(). The get_online_cpus() | 1765 | * will call async_rebuild_sched_domains(). |
1700 | * call in rebuild_sched_domains() must not be made while holding | ||
1701 | * callback_mutex. Elsewhere the kernel nests callback_mutex inside | ||
1702 | * get_online_cpus() calls. So the reverse nesting would risk an | ||
1703 | * ABBA deadlock. | ||
1704 | */ | 1766 | */ |
1705 | 1767 | ||
1706 | static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont) | 1768 | static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont) |
@@ -1719,7 +1781,7 @@ static void cpuset_destroy(struct cgroup_subsys *ss, struct cgroup *cont) | |||
1719 | struct cgroup_subsys cpuset_subsys = { | 1781 | struct cgroup_subsys cpuset_subsys = { |
1720 | .name = "cpuset", | 1782 | .name = "cpuset", |
1721 | .create = cpuset_create, | 1783 | .create = cpuset_create, |
1722 | .destroy = cpuset_destroy, | 1784 | .destroy = cpuset_destroy, |
1723 | .can_attach = cpuset_can_attach, | 1785 | .can_attach = cpuset_can_attach, |
1724 | .attach = cpuset_attach, | 1786 | .attach = cpuset_attach, |
1725 | .populate = cpuset_populate, | 1787 | .populate = cpuset_populate, |
@@ -1811,7 +1873,7 @@ static void move_member_tasks_to_cpuset(struct cpuset *from, struct cpuset *to) | |||
1811 | } | 1873 | } |
1812 | 1874 | ||
1813 | /* | 1875 | /* |
1814 | * If common_cpu_mem_hotplug_unplug(), below, unplugs any CPUs | 1876 | * If CPU and/or memory hotplug handlers, below, unplug any CPUs |
1815 | * or memory nodes, we need to walk over the cpuset hierarchy, | 1877 | * or memory nodes, we need to walk over the cpuset hierarchy, |
1816 | * 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 |
1817 | * 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 |
@@ -1859,7 +1921,7 @@ static void remove_tasks_in_empty_cpuset(struct cpuset *cs) | |||
1859 | * 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 |
1860 | * 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. |
1861 | */ | 1923 | */ |
1862 | static void scan_for_empty_cpusets(const struct cpuset *root) | 1924 | static void scan_for_empty_cpusets(struct cpuset *root) |
1863 | { | 1925 | { |
1864 | LIST_HEAD(queue); | 1926 | LIST_HEAD(queue); |
1865 | struct cpuset *cp; /* scans cpusets being updated */ | 1927 | struct cpuset *cp; /* scans cpusets being updated */ |
@@ -1896,42 +1958,13 @@ static void scan_for_empty_cpusets(const struct cpuset *root) | |||
1896 | nodes_empty(cp->mems_allowed)) | 1958 | nodes_empty(cp->mems_allowed)) |
1897 | remove_tasks_in_empty_cpuset(cp); | 1959 | remove_tasks_in_empty_cpuset(cp); |
1898 | else { | 1960 | else { |
1899 | update_tasks_cpumask(cp); | 1961 | update_tasks_cpumask(cp, NULL); |
1900 | update_tasks_nodemask(cp, &oldmems); | 1962 | update_tasks_nodemask(cp, &oldmems); |
1901 | } | 1963 | } |
1902 | } | 1964 | } |
1903 | } | 1965 | } |
1904 | 1966 | ||
1905 | /* | 1967 | /* |
1906 | * The cpus_allowed and mems_allowed nodemasks in the top_cpuset track | ||
1907 | * cpu_online_map and node_states[N_HIGH_MEMORY]. Force the top cpuset to | ||
1908 | * track what's online after any CPU or memory node hotplug or unplug event. | ||
1909 | * | ||
1910 | * Since there are two callers of this routine, one for CPU hotplug | ||
1911 | * events and one for memory node hotplug events, we could have coded | ||
1912 | * two separate routines here. We code it as a single common routine | ||
1913 | * in order to minimize text size. | ||
1914 | */ | ||
1915 | |||
1916 | static void common_cpu_mem_hotplug_unplug(int rebuild_sd) | ||
1917 | { | ||
1918 | cgroup_lock(); | ||
1919 | |||
1920 | top_cpuset.cpus_allowed = cpu_online_map; | ||
1921 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; | ||
1922 | scan_for_empty_cpusets(&top_cpuset); | ||
1923 | |||
1924 | /* | ||
1925 | * Scheduler destroys domains on hotplug events. | ||
1926 | * Rebuild them based on the current settings. | ||
1927 | */ | ||
1928 | if (rebuild_sd) | ||
1929 | rebuild_sched_domains(); | ||
1930 | |||
1931 | cgroup_unlock(); | ||
1932 | } | ||
1933 | |||
1934 | /* | ||
1935 | * The top_cpuset tracks what CPUs and Memory Nodes are online, | 1968 | * The top_cpuset tracks what CPUs and Memory Nodes are online, |
1936 | * period. This is necessary in order to make cpusets transparent | 1969 | * period. This is necessary in order to make cpusets transparent |
1937 | * (of no affect) on systems that are actively using CPU hotplug | 1970 | * (of no affect) on systems that are actively using CPU hotplug |
@@ -1939,40 +1972,52 @@ static void common_cpu_mem_hotplug_unplug(int rebuild_sd) | |||
1939 | * | 1972 | * |
1940 | * This routine ensures that top_cpuset.cpus_allowed tracks | 1973 | * This routine ensures that top_cpuset.cpus_allowed tracks |
1941 | * 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(). | ||
1942 | */ | 1978 | */ |
1943 | 1979 | static int cpuset_track_online_cpus(struct notifier_block *unused_nb, | |
1944 | static int cpuset_handle_cpuhp(struct notifier_block *unused_nb, | ||
1945 | unsigned long phase, void *unused_cpu) | 1980 | unsigned long phase, void *unused_cpu) |
1946 | { | 1981 | { |
1982 | struct sched_domain_attr *attr; | ||
1983 | cpumask_t *doms; | ||
1984 | int ndoms; | ||
1985 | |||
1947 | switch (phase) { | 1986 | switch (phase) { |
1948 | case CPU_UP_CANCELED: | ||
1949 | case CPU_UP_CANCELED_FROZEN: | ||
1950 | case CPU_DOWN_FAILED: | ||
1951 | case CPU_DOWN_FAILED_FROZEN: | ||
1952 | case CPU_ONLINE: | 1987 | case CPU_ONLINE: |
1953 | case CPU_ONLINE_FROZEN: | 1988 | case CPU_ONLINE_FROZEN: |
1954 | case CPU_DEAD: | 1989 | case CPU_DEAD: |
1955 | case CPU_DEAD_FROZEN: | 1990 | case CPU_DEAD_FROZEN: |
1956 | common_cpu_mem_hotplug_unplug(1); | ||
1957 | break; | 1991 | break; |
1992 | |||
1958 | default: | 1993 | default: |
1959 | return NOTIFY_DONE; | 1994 | return NOTIFY_DONE; |
1960 | } | 1995 | } |
1961 | 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 | |||
1962 | return NOTIFY_OK; | 2006 | return NOTIFY_OK; |
1963 | } | 2007 | } |
1964 | 2008 | ||
1965 | #ifdef CONFIG_MEMORY_HOTPLUG | 2009 | #ifdef CONFIG_MEMORY_HOTPLUG |
1966 | /* | 2010 | /* |
1967 | * Keep top_cpuset.mems_allowed tracking node_states[N_HIGH_MEMORY]. | 2011 | * Keep top_cpuset.mems_allowed tracking node_states[N_HIGH_MEMORY]. |
1968 | * Call this routine anytime after you change | 2012 | * Call this routine anytime after node_states[N_HIGH_MEMORY] changes. |
1969 | * node_states[N_HIGH_MEMORY]. | 2013 | * See also the previous routine cpuset_track_online_cpus(). |
1970 | * See also the previous routine cpuset_handle_cpuhp(). | ||
1971 | */ | 2014 | */ |
1972 | |||
1973 | void cpuset_track_online_nodes(void) | 2015 | void cpuset_track_online_nodes(void) |
1974 | { | 2016 | { |
1975 | 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(); | ||
1976 | } | 2021 | } |
1977 | #endif | 2022 | #endif |
1978 | 2023 | ||
@@ -1987,7 +2032,7 @@ void __init cpuset_init_smp(void) | |||
1987 | top_cpuset.cpus_allowed = cpu_online_map; | 2032 | top_cpuset.cpus_allowed = cpu_online_map; |
1988 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; | 2033 | top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY]; |
1989 | 2034 | ||
1990 | hotcpu_notifier(cpuset_handle_cpuhp, 0); | 2035 | hotcpu_notifier(cpuset_track_online_cpus, 0); |
1991 | } | 2036 | } |
1992 | 2037 | ||
1993 | /** | 2038 | /** |
diff --git a/kernel/dma-coherent.c b/kernel/dma-coherent.c index c1d4d5b4c61c..f013a0c2e111 100644 --- a/kernel/dma-coherent.c +++ b/kernel/dma-coherent.c | |||
@@ -124,6 +124,7 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t size, | |||
124 | } | 124 | } |
125 | return (mem != NULL); | 125 | return (mem != NULL); |
126 | } | 126 | } |
127 | EXPORT_SYMBOL(dma_alloc_from_coherent); | ||
127 | 128 | ||
128 | /** | 129 | /** |
129 | * dma_release_from_coherent() - try to free the memory allocated from per-device coherent memory pool | 130 | * dma_release_from_coherent() - try to free the memory allocated from per-device coherent memory pool |
@@ -151,3 +152,4 @@ int dma_release_from_coherent(struct device *dev, int order, void *vaddr) | |||
151 | } | 152 | } |
152 | return 0; | 153 | return 0; |
153 | } | 154 | } |
155 | EXPORT_SYMBOL(dma_release_from_coherent); | ||
diff --git a/kernel/dma.c b/kernel/dma.c index d2c60a822790..f903189c5304 100644 --- a/kernel/dma.c +++ b/kernel/dma.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: dma.c,v 1.7 1994/12/28 03:35:33 root Exp root $ | 1 | /* |
2 | * linux/kernel/dma.c: A DMA channel allocator. Inspired by linux/kernel/irq.c. | 2 | * linux/kernel/dma.c: A DMA channel allocator. Inspired by linux/kernel/irq.c. |
3 | * | 3 | * |
4 | * Written by Hennus Bergman, 1992. | 4 | * Written by Hennus Bergman, 1992. |
diff --git a/kernel/exit.c b/kernel/exit.c index 38ec40630149..059b38cae384 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -112,9 +112,7 @@ static void __exit_signal(struct task_struct *tsk) | |||
112 | * 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 |
113 | * will have been the last reference on the signal_struct. | 113 | * will have been the last reference on the signal_struct. |
114 | */ | 114 | */ |
115 | sig->utime = cputime_add(sig->utime, tsk->utime); | 115 | sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); |
116 | sig->stime = cputime_add(sig->stime, tsk->stime); | ||
117 | sig->gtime = cputime_add(sig->gtime, tsk->gtime); | ||
118 | sig->min_flt += tsk->min_flt; | 116 | sig->min_flt += tsk->min_flt; |
119 | sig->maj_flt += tsk->maj_flt; | 117 | sig->maj_flt += tsk->maj_flt; |
120 | sig->nvcsw += tsk->nvcsw; | 118 | sig->nvcsw += tsk->nvcsw; |
@@ -122,7 +120,6 @@ static void __exit_signal(struct task_struct *tsk) | |||
122 | sig->inblock += task_io_get_inblock(tsk); | 120 | sig->inblock += task_io_get_inblock(tsk); |
123 | sig->oublock += task_io_get_oublock(tsk); | 121 | sig->oublock += task_io_get_oublock(tsk); |
124 | task_io_accounting_add(&sig->ioac, &tsk->ioac); | 122 | task_io_accounting_add(&sig->ioac, &tsk->ioac); |
125 | sig->sum_sched_runtime += tsk->se.sum_exec_runtime; | ||
126 | sig = NULL; /* Marker for below. */ | 123 | sig = NULL; /* Marker for below. */ |
127 | } | 124 | } |
128 | 125 | ||
@@ -583,8 +580,6 @@ mm_need_new_owner(struct mm_struct *mm, struct task_struct *p) | |||
583 | * If there are other users of the mm and the owner (us) is exiting | 580 | * If there are other users of the mm and the owner (us) is exiting |
584 | * we need to find a new owner to take on the responsibility. | 581 | * we need to find a new owner to take on the responsibility. |
585 | */ | 582 | */ |
586 | if (!mm) | ||
587 | return 0; | ||
588 | if (atomic_read(&mm->mm_users) <= 1) | 583 | if (atomic_read(&mm->mm_users) <= 1) |
589 | return 0; | 584 | return 0; |
590 | if (mm->owner != p) | 585 | if (mm->owner != p) |
@@ -627,29 +622,38 @@ retry: | |||
627 | } while_each_thread(g, c); | 622 | } while_each_thread(g, c); |
628 | 623 | ||
629 | read_unlock(&tasklist_lock); | 624 | read_unlock(&tasklist_lock); |
625 | /* | ||
626 | * We found no owner yet mm_users > 1: this implies that we are | ||
627 | * most likely racing with swapoff (try_to_unuse()) or /proc or | ||
628 | * ptrace or page migration (get_task_mm()). Mark owner as NULL, | ||
629 | * so that subsystems can understand the callback and take action. | ||
630 | */ | ||
631 | down_write(&mm->mmap_sem); | ||
632 | cgroup_mm_owner_callbacks(mm->owner, NULL); | ||
633 | mm->owner = NULL; | ||
634 | up_write(&mm->mmap_sem); | ||
630 | return; | 635 | return; |
631 | 636 | ||
632 | assign_new_owner: | 637 | assign_new_owner: |
633 | BUG_ON(c == p); | 638 | BUG_ON(c == p); |
634 | get_task_struct(c); | 639 | get_task_struct(c); |
640 | read_unlock(&tasklist_lock); | ||
641 | down_write(&mm->mmap_sem); | ||
635 | /* | 642 | /* |
636 | * The task_lock protects c->mm from changing. | 643 | * The task_lock protects c->mm from changing. |
637 | * We always want mm->owner->mm == mm | 644 | * We always want mm->owner->mm == mm |
638 | */ | 645 | */ |
639 | task_lock(c); | 646 | task_lock(c); |
640 | /* | ||
641 | * Delay read_unlock() till we have the task_lock() | ||
642 | * to ensure that c does not slip away underneath us | ||
643 | */ | ||
644 | read_unlock(&tasklist_lock); | ||
645 | if (c->mm != mm) { | 647 | if (c->mm != mm) { |
646 | task_unlock(c); | 648 | task_unlock(c); |
649 | up_write(&mm->mmap_sem); | ||
647 | put_task_struct(c); | 650 | put_task_struct(c); |
648 | goto retry; | 651 | goto retry; |
649 | } | 652 | } |
650 | cgroup_mm_owner_callbacks(mm->owner, c); | 653 | cgroup_mm_owner_callbacks(mm->owner, c); |
651 | mm->owner = c; | 654 | mm->owner = c; |
652 | task_unlock(c); | 655 | task_unlock(c); |
656 | up_write(&mm->mmap_sem); | ||
653 | put_task_struct(c); | 657 | put_task_struct(c); |
654 | } | 658 | } |
655 | #endif /* CONFIG_MM_OWNER */ | 659 | #endif /* CONFIG_MM_OWNER */ |
@@ -831,26 +835,50 @@ static void reparent_thread(struct task_struct *p, struct task_struct *father) | |||
831 | * the child reaper process (ie "init") in our pid | 835 | * the child reaper process (ie "init") in our pid |
832 | * space. | 836 | * space. |
833 | */ | 837 | */ |
838 | static struct task_struct *find_new_reaper(struct task_struct *father) | ||
839 | { | ||
840 | struct pid_namespace *pid_ns = task_active_pid_ns(father); | ||
841 | struct task_struct *thread; | ||
842 | |||
843 | thread = father; | ||
844 | while_each_thread(father, thread) { | ||
845 | if (thread->flags & PF_EXITING) | ||
846 | continue; | ||
847 | if (unlikely(pid_ns->child_reaper == father)) | ||
848 | pid_ns->child_reaper = thread; | ||
849 | return thread; | ||
850 | } | ||
851 | |||
852 | if (unlikely(pid_ns->child_reaper == father)) { | ||
853 | write_unlock_irq(&tasklist_lock); | ||
854 | if (unlikely(pid_ns == &init_pid_ns)) | ||
855 | panic("Attempted to kill init!"); | ||
856 | |||
857 | zap_pid_ns_processes(pid_ns); | ||
858 | write_lock_irq(&tasklist_lock); | ||
859 | /* | ||
860 | * We can not clear ->child_reaper or leave it alone. | ||
861 | * There may by stealth EXIT_DEAD tasks on ->children, | ||
862 | * forget_original_parent() must move them somewhere. | ||
863 | */ | ||
864 | pid_ns->child_reaper = init_pid_ns.child_reaper; | ||
865 | } | ||
866 | |||
867 | return pid_ns->child_reaper; | ||
868 | } | ||
869 | |||
834 | static void forget_original_parent(struct task_struct *father) | 870 | static void forget_original_parent(struct task_struct *father) |
835 | { | 871 | { |
836 | struct task_struct *p, *n, *reaper = father; | 872 | struct task_struct *p, *n, *reaper; |
837 | LIST_HEAD(ptrace_dead); | 873 | LIST_HEAD(ptrace_dead); |
838 | 874 | ||
839 | write_lock_irq(&tasklist_lock); | 875 | write_lock_irq(&tasklist_lock); |
840 | 876 | reaper = find_new_reaper(father); | |
841 | /* | 877 | /* |
842 | * First clean up ptrace if we were using it. | 878 | * First clean up ptrace if we were using it. |
843 | */ | 879 | */ |
844 | ptrace_exit(father, &ptrace_dead); | 880 | ptrace_exit(father, &ptrace_dead); |
845 | 881 | ||
846 | do { | ||
847 | reaper = next_thread(reaper); | ||
848 | if (reaper == father) { | ||
849 | reaper = task_child_reaper(father); | ||
850 | break; | ||
851 | } | ||
852 | } while (reaper->flags & PF_EXITING); | ||
853 | |||
854 | list_for_each_entry_safe(p, n, &father->children, sibling) { | 882 | list_for_each_entry_safe(p, n, &father->children, sibling) { |
855 | p->real_parent = reaper; | 883 | p->real_parent = reaper; |
856 | if (p->parent == father) { | 884 | if (p->parent == father) { |
@@ -918,8 +946,8 @@ static void exit_notify(struct task_struct *tsk, int group_dead) | |||
918 | 946 | ||
919 | /* mt-exec, de_thread() is waiting for us */ | 947 | /* mt-exec, de_thread() is waiting for us */ |
920 | if (thread_group_leader(tsk) && | 948 | if (thread_group_leader(tsk) && |
921 | tsk->signal->notify_count < 0 && | 949 | tsk->signal->group_exit_task && |
922 | tsk->signal->group_exit_task) | 950 | tsk->signal->notify_count < 0) |
923 | wake_up_process(tsk->signal->group_exit_task); | 951 | wake_up_process(tsk->signal->group_exit_task); |
924 | 952 | ||
925 | write_unlock_irq(&tasklist_lock); | 953 | write_unlock_irq(&tasklist_lock); |
@@ -959,39 +987,6 @@ static void check_stack_usage(void) | |||
959 | static inline void check_stack_usage(void) {} | 987 | static inline void check_stack_usage(void) {} |
960 | #endif | 988 | #endif |
961 | 989 | ||
962 | static inline void exit_child_reaper(struct task_struct *tsk) | ||
963 | { | ||
964 | if (likely(tsk->group_leader != task_child_reaper(tsk))) | ||
965 | return; | ||
966 | |||
967 | if (tsk->nsproxy->pid_ns == &init_pid_ns) | ||
968 | panic("Attempted to kill init!"); | ||
969 | |||
970 | /* | ||
971 | * @tsk is the last thread in the 'cgroup-init' and is exiting. | ||
972 | * Terminate all remaining processes in the namespace and reap them | ||
973 | * before exiting @tsk. | ||
974 | * | ||
975 | * Note that @tsk (last thread of cgroup-init) may not necessarily | ||
976 | * be the child-reaper (i.e main thread of cgroup-init) of the | ||
977 | * namespace i.e the child_reaper may have already exited. | ||
978 | * | ||
979 | * Even after a child_reaper exits, we let it inherit orphaned children, | ||
980 | * because, pid_ns->child_reaper remains valid as long as there is | ||
981 | * at least one living sub-thread in the cgroup init. | ||
982 | |||
983 | * This living sub-thread of the cgroup-init will be notified when | ||
984 | * a child inherited by the 'child-reaper' exits (do_notify_parent() | ||
985 | * uses __group_send_sig_info()). Further, when reaping child processes, | ||
986 | * do_wait() iterates over children of all living sub threads. | ||
987 | |||
988 | * i.e even though 'child_reaper' thread is listed as the parent of the | ||
989 | * orphaned children, any living sub-thread in the cgroup-init can | ||
990 | * perform the role of the child_reaper. | ||
991 | */ | ||
992 | zap_pid_ns_processes(tsk->nsproxy->pid_ns); | ||
993 | } | ||
994 | |||
995 | NORET_TYPE void do_exit(long code) | 990 | NORET_TYPE void do_exit(long code) |
996 | { | 991 | { |
997 | struct task_struct *tsk = current; | 992 | struct task_struct *tsk = current; |
@@ -1051,7 +1046,6 @@ NORET_TYPE void do_exit(long code) | |||
1051 | } | 1046 | } |
1052 | group_dead = atomic_dec_and_test(&tsk->signal->live); | 1047 | group_dead = atomic_dec_and_test(&tsk->signal->live); |
1053 | if (group_dead) { | 1048 | if (group_dead) { |
1054 | exit_child_reaper(tsk); | ||
1055 | hrtimer_cancel(&tsk->signal->real_timer); | 1049 | hrtimer_cancel(&tsk->signal->real_timer); |
1056 | exit_itimers(tsk->signal); | 1050 | exit_itimers(tsk->signal); |
1057 | } | 1051 | } |
@@ -1304,6 +1298,7 @@ static int wait_task_zombie(struct task_struct *p, int options, | |||
1304 | if (likely(!traced)) { | 1298 | if (likely(!traced)) { |
1305 | struct signal_struct *psig; | 1299 | struct signal_struct *psig; |
1306 | struct signal_struct *sig; | 1300 | struct signal_struct *sig; |
1301 | struct task_cputime cputime; | ||
1307 | 1302 | ||
1308 | /* | 1303 | /* |
1309 | * The resource counters for the group leader are in its | 1304 | * The resource counters for the group leader are in its |
@@ -1319,20 +1314,23 @@ static int wait_task_zombie(struct task_struct *p, int options, | |||
1319 | * need to protect the access to p->parent->signal fields, | 1314 | * need to protect the access to p->parent->signal fields, |
1320 | * as other threads in the parent group can be right | 1315 | * as other threads in the parent group can be right |
1321 | * here reaping other children at the same time. | 1316 | * here reaping other children at the same time. |
1317 | * | ||
1318 | * We use thread_group_cputime() to get times for the thread | ||
1319 | * group, which consolidates times for all threads in the | ||
1320 | * group including the group leader. | ||
1322 | */ | 1321 | */ |
1323 | spin_lock_irq(&p->parent->sighand->siglock); | 1322 | spin_lock_irq(&p->parent->sighand->siglock); |
1324 | psig = p->parent->signal; | 1323 | psig = p->parent->signal; |
1325 | sig = p->signal; | 1324 | sig = p->signal; |
1325 | thread_group_cputime(p, &cputime); | ||
1326 | psig->cutime = | 1326 | psig->cutime = |
1327 | cputime_add(psig->cutime, | 1327 | cputime_add(psig->cutime, |
1328 | cputime_add(p->utime, | 1328 | cputime_add(cputime.utime, |
1329 | cputime_add(sig->utime, | 1329 | sig->cutime)); |
1330 | sig->cutime))); | ||
1331 | psig->cstime = | 1330 | psig->cstime = |
1332 | cputime_add(psig->cstime, | 1331 | cputime_add(psig->cstime, |
1333 | cputime_add(p->stime, | 1332 | cputime_add(cputime.stime, |
1334 | cputime_add(sig->stime, | 1333 | sig->cstime)); |
1335 | sig->cstime))); | ||
1336 | psig->cgtime = | 1334 | psig->cgtime = |
1337 | cputime_add(psig->cgtime, | 1335 | cputime_add(psig->cgtime, |
1338 | cputime_add(p->gtime, | 1336 | cputime_add(p->gtime, |
diff --git a/kernel/fork.c b/kernel/fork.c index 7ce2ebe84796..44e64d7ba29b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -759,15 +759,44 @@ void __cleanup_sighand(struct sighand_struct *sighand) | |||
759 | kmem_cache_free(sighand_cachep, sighand); | 759 | kmem_cache_free(sighand_cachep, sighand); |
760 | } | 760 | } |
761 | 761 | ||
762 | |||
763 | /* | ||
764 | * Initialize POSIX timer handling for a thread group. | ||
765 | */ | ||
766 | static void posix_cpu_timers_init_group(struct signal_struct *sig) | ||
767 | { | ||
768 | /* Thread group counters. */ | ||
769 | thread_group_cputime_init(sig); | ||
770 | |||
771 | /* Expiration times and increments. */ | ||
772 | sig->it_virt_expires = cputime_zero; | ||
773 | sig->it_virt_incr = cputime_zero; | ||
774 | sig->it_prof_expires = cputime_zero; | ||
775 | sig->it_prof_incr = cputime_zero; | ||
776 | |||
777 | /* Cached expiration times. */ | ||
778 | sig->cputime_expires.prof_exp = cputime_zero; | ||
779 | sig->cputime_expires.virt_exp = cputime_zero; | ||
780 | sig->cputime_expires.sched_exp = 0; | ||
781 | |||
782 | /* The timer lists. */ | ||
783 | INIT_LIST_HEAD(&sig->cpu_timers[0]); | ||
784 | INIT_LIST_HEAD(&sig->cpu_timers[1]); | ||
785 | INIT_LIST_HEAD(&sig->cpu_timers[2]); | ||
786 | } | ||
787 | |||
762 | static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | 788 | static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) |
763 | { | 789 | { |
764 | struct signal_struct *sig; | 790 | struct signal_struct *sig; |
765 | int ret; | 791 | int ret; |
766 | 792 | ||
767 | if (clone_flags & CLONE_THREAD) { | 793 | if (clone_flags & CLONE_THREAD) { |
768 | atomic_inc(¤t->signal->count); | 794 | ret = thread_group_cputime_clone_thread(current); |
769 | atomic_inc(¤t->signal->live); | 795 | if (likely(!ret)) { |
770 | return 0; | 796 | atomic_inc(¤t->signal->count); |
797 | atomic_inc(¤t->signal->live); | ||
798 | } | ||
799 | return ret; | ||
771 | } | 800 | } |
772 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); | 801 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); |
773 | tsk->signal = sig; | 802 | tsk->signal = sig; |
@@ -795,39 +824,25 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
795 | sig->it_real_incr.tv64 = 0; | 824 | sig->it_real_incr.tv64 = 0; |
796 | sig->real_timer.function = it_real_fn; | 825 | sig->real_timer.function = it_real_fn; |
797 | 826 | ||
798 | sig->it_virt_expires = cputime_zero; | ||
799 | sig->it_virt_incr = cputime_zero; | ||
800 | sig->it_prof_expires = cputime_zero; | ||
801 | sig->it_prof_incr = cputime_zero; | ||
802 | |||
803 | sig->leader = 0; /* session leadership doesn't inherit */ | 827 | sig->leader = 0; /* session leadership doesn't inherit */ |
804 | sig->tty_old_pgrp = NULL; | 828 | sig->tty_old_pgrp = NULL; |
829 | sig->tty = NULL; | ||
805 | 830 | ||
806 | sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero; | 831 | sig->cutime = sig->cstime = cputime_zero; |
807 | sig->gtime = cputime_zero; | 832 | sig->gtime = cputime_zero; |
808 | sig->cgtime = cputime_zero; | 833 | sig->cgtime = cputime_zero; |
809 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; | 834 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; |
810 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; | 835 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; |
811 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; | 836 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; |
812 | task_io_accounting_init(&sig->ioac); | 837 | task_io_accounting_init(&sig->ioac); |
813 | sig->sum_sched_runtime = 0; | ||
814 | INIT_LIST_HEAD(&sig->cpu_timers[0]); | ||
815 | INIT_LIST_HEAD(&sig->cpu_timers[1]); | ||
816 | INIT_LIST_HEAD(&sig->cpu_timers[2]); | ||
817 | taskstats_tgid_init(sig); | 838 | taskstats_tgid_init(sig); |
818 | 839 | ||
819 | task_lock(current->group_leader); | 840 | task_lock(current->group_leader); |
820 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); | 841 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); |
821 | task_unlock(current->group_leader); | 842 | task_unlock(current->group_leader); |
822 | 843 | ||
823 | if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { | 844 | posix_cpu_timers_init_group(sig); |
824 | /* | 845 | |
825 | * New sole thread in the process gets an expiry time | ||
826 | * of the whole CPU time limit. | ||
827 | */ | ||
828 | tsk->it_prof_expires = | ||
829 | secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); | ||
830 | } | ||
831 | acct_init_pacct(&sig->pacct); | 846 | acct_init_pacct(&sig->pacct); |
832 | 847 | ||
833 | tty_audit_fork(sig); | 848 | tty_audit_fork(sig); |
@@ -837,7 +852,9 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
837 | 852 | ||
838 | void __cleanup_signal(struct signal_struct *sig) | 853 | void __cleanup_signal(struct signal_struct *sig) |
839 | { | 854 | { |
855 | thread_group_cputime_free(sig); | ||
840 | exit_thread_group_keys(sig); | 856 | exit_thread_group_keys(sig); |
857 | tty_kref_put(sig->tty); | ||
841 | kmem_cache_free(signal_cachep, sig); | 858 | kmem_cache_free(signal_cachep, sig); |
842 | } | 859 | } |
843 | 860 | ||
@@ -886,6 +903,19 @@ void mm_init_owner(struct mm_struct *mm, struct task_struct *p) | |||
886 | #endif /* CONFIG_MM_OWNER */ | 903 | #endif /* CONFIG_MM_OWNER */ |
887 | 904 | ||
888 | /* | 905 | /* |
906 | * Initialize POSIX timer handling for a single task. | ||
907 | */ | ||
908 | static void posix_cpu_timers_init(struct task_struct *tsk) | ||
909 | { | ||
910 | tsk->cputime_expires.prof_exp = cputime_zero; | ||
911 | tsk->cputime_expires.virt_exp = cputime_zero; | ||
912 | tsk->cputime_expires.sched_exp = 0; | ||
913 | INIT_LIST_HEAD(&tsk->cpu_timers[0]); | ||
914 | INIT_LIST_HEAD(&tsk->cpu_timers[1]); | ||
915 | INIT_LIST_HEAD(&tsk->cpu_timers[2]); | ||
916 | } | ||
917 | |||
918 | /* | ||
889 | * This creates a new process as a copy of the old one, | 919 | * This creates a new process as a copy of the old one, |
890 | * but does not actually start it yet. | 920 | * but does not actually start it yet. |
891 | * | 921 | * |
@@ -995,12 +1025,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
995 | task_io_accounting_init(&p->ioac); | 1025 | task_io_accounting_init(&p->ioac); |
996 | acct_clear_integrals(p); | 1026 | acct_clear_integrals(p); |
997 | 1027 | ||
998 | p->it_virt_expires = cputime_zero; | 1028 | posix_cpu_timers_init(p); |
999 | p->it_prof_expires = cputime_zero; | ||
1000 | p->it_sched_expires = 0; | ||
1001 | INIT_LIST_HEAD(&p->cpu_timers[0]); | ||
1002 | INIT_LIST_HEAD(&p->cpu_timers[1]); | ||
1003 | INIT_LIST_HEAD(&p->cpu_timers[2]); | ||
1004 | 1029 | ||
1005 | p->lock_depth = -1; /* -1 = no lock */ | 1030 | p->lock_depth = -1; /* -1 = no lock */ |
1006 | do_posix_clock_monotonic_gettime(&p->start_time); | 1031 | do_posix_clock_monotonic_gettime(&p->start_time); |
@@ -1201,21 +1226,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1201 | if (clone_flags & CLONE_THREAD) { | 1226 | if (clone_flags & CLONE_THREAD) { |
1202 | p->group_leader = current->group_leader; | 1227 | p->group_leader = current->group_leader; |
1203 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); | 1228 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); |
1204 | |||
1205 | if (!cputime_eq(current->signal->it_virt_expires, | ||
1206 | cputime_zero) || | ||
1207 | !cputime_eq(current->signal->it_prof_expires, | ||
1208 | cputime_zero) || | ||
1209 | current->signal->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY || | ||
1210 | !list_empty(¤t->signal->cpu_timers[0]) || | ||
1211 | !list_empty(¤t->signal->cpu_timers[1]) || | ||
1212 | !list_empty(¤t->signal->cpu_timers[2])) { | ||
1213 | /* | ||
1214 | * Have child wake up on its first tick to check | ||
1215 | * for process CPU timers. | ||
1216 | */ | ||
1217 | p->it_prof_expires = jiffies_to_cputime(1); | ||
1218 | } | ||
1219 | } | 1229 | } |
1220 | 1230 | ||
1221 | if (likely(p->pid)) { | 1231 | if (likely(p->pid)) { |
@@ -1227,7 +1237,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1227 | p->nsproxy->pid_ns->child_reaper = p; | 1237 | p->nsproxy->pid_ns->child_reaper = p; |
1228 | 1238 | ||
1229 | p->signal->leader_pid = pid; | 1239 | p->signal->leader_pid = pid; |
1230 | p->signal->tty = current->signal->tty; | 1240 | tty_kref_put(p->signal->tty); |
1241 | p->signal->tty = tty_kref_get(current->signal->tty); | ||
1231 | set_task_pgrp(p, task_pgrp_nr(current)); | 1242 | set_task_pgrp(p, task_pgrp_nr(current)); |
1232 | set_task_session(p, task_session_nr(current)); | 1243 | set_task_session(p, task_session_nr(current)); |
1233 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); | 1244 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); |
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 4d761d50c529..95978f48e039 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. |
@@ -1450,7 +1452,7 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) | |||
1450 | sl->timer.function = hrtimer_wakeup; | 1452 | sl->timer.function = hrtimer_wakeup; |
1451 | sl->task = task; | 1453 | sl->task = task; |
1452 | #ifdef CONFIG_HIGH_RES_TIMERS | 1454 | #ifdef CONFIG_HIGH_RES_TIMERS |
1453 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 1455 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED; |
1454 | #endif | 1456 | #endif |
1455 | } | 1457 | } |
1456 | 1458 | ||
@@ -1589,29 +1591,95 @@ static void __cpuinit init_hrtimers_cpu(int cpu) | |||
1589 | 1591 | ||
1590 | #ifdef CONFIG_HOTPLUG_CPU | 1592 | #ifdef CONFIG_HOTPLUG_CPU |
1591 | 1593 | ||
1592 | static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | 1594 | static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, |
1593 | struct hrtimer_clock_base *new_base) | 1595 | struct hrtimer_clock_base *new_base, int dcpu) |
1594 | { | 1596 | { |
1595 | struct hrtimer *timer; | 1597 | struct hrtimer *timer; |
1596 | struct rb_node *node; | 1598 | struct rb_node *node; |
1599 | int raise = 0; | ||
1597 | 1600 | ||
1598 | while ((node = rb_first(&old_base->active))) { | 1601 | while ((node = rb_first(&old_base->active))) { |
1599 | timer = rb_entry(node, struct hrtimer, node); | 1602 | timer = rb_entry(node, struct hrtimer, node); |
1600 | BUG_ON(hrtimer_callback_running(timer)); | 1603 | BUG_ON(hrtimer_callback_running(timer)); |
1601 | debug_hrtimer_deactivate(timer); | 1604 | debug_hrtimer_deactivate(timer); |
1602 | __remove_hrtimer(timer, old_base, HRTIMER_STATE_INACTIVE, 0); | 1605 | |
1606 | /* | ||
1607 | * Should not happen. Per CPU timers should be | ||
1608 | * canceled _before_ the migration code is called | ||
1609 | */ | ||
1610 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU) { | ||
1611 | __remove_hrtimer(timer, old_base, | ||
1612 | HRTIMER_STATE_INACTIVE, 0); | ||
1613 | WARN(1, "hrtimer (%p %p)active but cpu %d dead\n", | ||
1614 | timer, timer->function, dcpu); | ||
1615 | continue; | ||
1616 | } | ||
1617 | |||
1618 | /* | ||
1619 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the | ||
1620 | * timer could be seen as !active and just vanish away | ||
1621 | * under us on another CPU | ||
1622 | */ | ||
1623 | __remove_hrtimer(timer, old_base, HRTIMER_STATE_MIGRATE, 0); | ||
1603 | timer->base = new_base; | 1624 | timer->base = new_base; |
1604 | /* | 1625 | /* |
1605 | * Enqueue the timer. Allow reprogramming of the event device | 1626 | * Enqueue the timer. Allow reprogramming of the event device |
1606 | */ | 1627 | */ |
1607 | enqueue_hrtimer(timer, new_base, 1); | 1628 | enqueue_hrtimer(timer, new_base, 1); |
1629 | |||
1630 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1631 | /* | ||
1632 | * Happens with high res enabled when the timer was | ||
1633 | * already expired and the callback mode is | ||
1634 | * HRTIMER_CB_IRQSAFE_UNLOCKED (hrtimer_sleeper). The | ||
1635 | * enqueue code does not move them to the soft irq | ||
1636 | * pending list for performance/latency reasons, but | ||
1637 | * in the migration state, we need to do that | ||
1638 | * otherwise we end up with a stale timer. | ||
1639 | */ | ||
1640 | if (timer->state == HRTIMER_STATE_MIGRATE) { | ||
1641 | timer->state = HRTIMER_STATE_PENDING; | ||
1642 | list_add_tail(&timer->cb_entry, | ||
1643 | &new_base->cpu_base->cb_pending); | ||
1644 | raise = 1; | ||
1645 | } | ||
1646 | #endif | ||
1647 | /* Clear the migration state bit */ | ||
1648 | timer->state &= ~HRTIMER_STATE_MIGRATE; | ||
1649 | } | ||
1650 | return raise; | ||
1651 | } | ||
1652 | |||
1653 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1654 | static int migrate_hrtimer_pending(struct hrtimer_cpu_base *old_base, | ||
1655 | struct hrtimer_cpu_base *new_base) | ||
1656 | { | ||
1657 | struct hrtimer *timer; | ||
1658 | int raise = 0; | ||
1659 | |||
1660 | while (!list_empty(&old_base->cb_pending)) { | ||
1661 | timer = list_entry(old_base->cb_pending.next, | ||
1662 | struct hrtimer, cb_entry); | ||
1663 | |||
1664 | __remove_hrtimer(timer, timer->base, HRTIMER_STATE_PENDING, 0); | ||
1665 | timer->base = &new_base->clock_base[timer->base->index]; | ||
1666 | list_add_tail(&timer->cb_entry, &new_base->cb_pending); | ||
1667 | raise = 1; | ||
1608 | } | 1668 | } |
1669 | return raise; | ||
1670 | } | ||
1671 | #else | ||
1672 | static int migrate_hrtimer_pending(struct hrtimer_cpu_base *old_base, | ||
1673 | struct hrtimer_cpu_base *new_base) | ||
1674 | { | ||
1675 | return 0; | ||
1609 | } | 1676 | } |
1677 | #endif | ||
1610 | 1678 | ||
1611 | static void migrate_hrtimers(int cpu) | 1679 | static void migrate_hrtimers(int cpu) |
1612 | { | 1680 | { |
1613 | struct hrtimer_cpu_base *old_base, *new_base; | 1681 | struct hrtimer_cpu_base *old_base, *new_base; |
1614 | int i; | 1682 | int i, raise = 0; |
1615 | 1683 | ||
1616 | BUG_ON(cpu_online(cpu)); | 1684 | BUG_ON(cpu_online(cpu)); |
1617 | old_base = &per_cpu(hrtimer_bases, cpu); | 1685 | old_base = &per_cpu(hrtimer_bases, cpu); |
@@ -1626,13 +1694,20 @@ 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_irq(&new_base->lock); | 1706 | spin_unlock_irq(&new_base->lock); |
1635 | put_cpu_var(hrtimer_bases); | 1707 | put_cpu_var(hrtimer_bases); |
1708 | |||
1709 | if (raise) | ||
1710 | hrtimer_raise_softirq(); | ||
1636 | } | 1711 | } |
1637 | #endif /* CONFIG_HOTPLUG_CPU */ | 1712 | #endif /* CONFIG_HOTPLUG_CPU */ |
1638 | 1713 | ||
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 0314074fa232..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); |
diff --git a/kernel/itimer.c b/kernel/itimer.c index ab982747d9bd..db7c358b9a02 100644 --- a/kernel/itimer.c +++ b/kernel/itimer.c | |||
@@ -55,17 +55,15 @@ int do_getitimer(int which, struct itimerval *value) | |||
55 | spin_unlock_irq(&tsk->sighand->siglock); | 55 | spin_unlock_irq(&tsk->sighand->siglock); |
56 | break; | 56 | break; |
57 | case ITIMER_VIRTUAL: | 57 | case ITIMER_VIRTUAL: |
58 | read_lock(&tasklist_lock); | ||
59 | spin_lock_irq(&tsk->sighand->siglock); | 58 | spin_lock_irq(&tsk->sighand->siglock); |
60 | cval = tsk->signal->it_virt_expires; | 59 | cval = tsk->signal->it_virt_expires; |
61 | cinterval = tsk->signal->it_virt_incr; | 60 | cinterval = tsk->signal->it_virt_incr; |
62 | if (!cputime_eq(cval, cputime_zero)) { | 61 | if (!cputime_eq(cval, cputime_zero)) { |
63 | struct task_struct *t = tsk; | 62 | struct task_cputime cputime; |
64 | cputime_t utime = tsk->signal->utime; | 63 | cputime_t utime; |
65 | do { | 64 | |
66 | utime = cputime_add(utime, t->utime); | 65 | thread_group_cputime(tsk, &cputime); |
67 | t = next_thread(t); | 66 | utime = cputime.utime; |
68 | } while (t != tsk); | ||
69 | if (cputime_le(cval, utime)) { /* about to fire */ | 67 | if (cputime_le(cval, utime)) { /* about to fire */ |
70 | cval = jiffies_to_cputime(1); | 68 | cval = jiffies_to_cputime(1); |
71 | } else { | 69 | } else { |
@@ -73,25 +71,19 @@ int do_getitimer(int which, struct itimerval *value) | |||
73 | } | 71 | } |
74 | } | 72 | } |
75 | spin_unlock_irq(&tsk->sighand->siglock); | 73 | spin_unlock_irq(&tsk->sighand->siglock); |
76 | read_unlock(&tasklist_lock); | ||
77 | cputime_to_timeval(cval, &value->it_value); | 74 | cputime_to_timeval(cval, &value->it_value); |
78 | cputime_to_timeval(cinterval, &value->it_interval); | 75 | cputime_to_timeval(cinterval, &value->it_interval); |
79 | break; | 76 | break; |
80 | case ITIMER_PROF: | 77 | case ITIMER_PROF: |
81 | read_lock(&tasklist_lock); | ||
82 | spin_lock_irq(&tsk->sighand->siglock); | 78 | spin_lock_irq(&tsk->sighand->siglock); |
83 | cval = tsk->signal->it_prof_expires; | 79 | cval = tsk->signal->it_prof_expires; |
84 | cinterval = tsk->signal->it_prof_incr; | 80 | cinterval = tsk->signal->it_prof_incr; |
85 | if (!cputime_eq(cval, cputime_zero)) { | 81 | if (!cputime_eq(cval, cputime_zero)) { |
86 | struct task_struct *t = tsk; | 82 | struct task_cputime times; |
87 | cputime_t ptime = cputime_add(tsk->signal->utime, | 83 | cputime_t ptime; |
88 | tsk->signal->stime); | 84 | |
89 | do { | 85 | thread_group_cputime(tsk, ×); |
90 | ptime = cputime_add(ptime, | 86 | ptime = cputime_add(times.utime, times.stime); |
91 | cputime_add(t->utime, | ||
92 | t->stime)); | ||
93 | t = next_thread(t); | ||
94 | } while (t != tsk); | ||
95 | if (cputime_le(cval, ptime)) { /* about to fire */ | 87 | if (cputime_le(cval, ptime)) { /* about to fire */ |
96 | cval = jiffies_to_cputime(1); | 88 | cval = jiffies_to_cputime(1); |
97 | } else { | 89 | } else { |
@@ -99,7 +91,6 @@ int do_getitimer(int which, struct itimerval *value) | |||
99 | } | 91 | } |
100 | } | 92 | } |
101 | spin_unlock_irq(&tsk->sighand->siglock); | 93 | spin_unlock_irq(&tsk->sighand->siglock); |
102 | read_unlock(&tasklist_lock); | ||
103 | cputime_to_timeval(cval, &value->it_value); | 94 | cputime_to_timeval(cval, &value->it_value); |
104 | cputime_to_timeval(cinterval, &value->it_interval); | 95 | cputime_to_timeval(cinterval, &value->it_interval); |
105 | break; | 96 | break; |
@@ -185,7 +176,6 @@ again: | |||
185 | case ITIMER_VIRTUAL: | 176 | case ITIMER_VIRTUAL: |
186 | nval = timeval_to_cputime(&value->it_value); | 177 | nval = timeval_to_cputime(&value->it_value); |
187 | ninterval = timeval_to_cputime(&value->it_interval); | 178 | ninterval = timeval_to_cputime(&value->it_interval); |
188 | read_lock(&tasklist_lock); | ||
189 | spin_lock_irq(&tsk->sighand->siglock); | 179 | spin_lock_irq(&tsk->sighand->siglock); |
190 | cval = tsk->signal->it_virt_expires; | 180 | cval = tsk->signal->it_virt_expires; |
191 | cinterval = tsk->signal->it_virt_incr; | 181 | cinterval = tsk->signal->it_virt_incr; |
@@ -200,7 +190,6 @@ again: | |||
200 | tsk->signal->it_virt_expires = nval; | 190 | tsk->signal->it_virt_expires = nval; |
201 | tsk->signal->it_virt_incr = ninterval; | 191 | tsk->signal->it_virt_incr = ninterval; |
202 | spin_unlock_irq(&tsk->sighand->siglock); | 192 | spin_unlock_irq(&tsk->sighand->siglock); |
203 | read_unlock(&tasklist_lock); | ||
204 | if (ovalue) { | 193 | if (ovalue) { |
205 | cputime_to_timeval(cval, &ovalue->it_value); | 194 | cputime_to_timeval(cval, &ovalue->it_value); |
206 | cputime_to_timeval(cinterval, &ovalue->it_interval); | 195 | cputime_to_timeval(cinterval, &ovalue->it_interval); |
@@ -209,7 +198,6 @@ again: | |||
209 | case ITIMER_PROF: | 198 | case ITIMER_PROF: |
210 | nval = timeval_to_cputime(&value->it_value); | 199 | nval = timeval_to_cputime(&value->it_value); |
211 | ninterval = timeval_to_cputime(&value->it_interval); | 200 | ninterval = timeval_to_cputime(&value->it_interval); |
212 | read_lock(&tasklist_lock); | ||
213 | spin_lock_irq(&tsk->sighand->siglock); | 201 | spin_lock_irq(&tsk->sighand->siglock); |
214 | cval = tsk->signal->it_prof_expires; | 202 | cval = tsk->signal->it_prof_expires; |
215 | cinterval = tsk->signal->it_prof_incr; | 203 | cinterval = tsk->signal->it_prof_incr; |
@@ -224,7 +212,6 @@ again: | |||
224 | tsk->signal->it_prof_expires = nval; | 212 | tsk->signal->it_prof_expires = nval; |
225 | tsk->signal->it_prof_incr = ninterval; | 213 | tsk->signal->it_prof_incr = ninterval; |
226 | spin_unlock_irq(&tsk->sighand->siglock); | 214 | spin_unlock_irq(&tsk->sighand->siglock); |
227 | read_unlock(&tasklist_lock); | ||
228 | if (ovalue) { | 215 | if (ovalue) { |
229 | cputime_to_timeval(cval, &ovalue->it_value); | 216 | cputime_to_timeval(cval, &ovalue->it_value); |
230 | cputime_to_timeval(cinterval, &ovalue->it_interval); | 217 | cputime_to_timeval(cinterval, &ovalue->it_interval); |
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 38fc10ac7541..5072cf1685a2 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c | |||
@@ -260,7 +260,6 @@ const char *kallsyms_lookup(unsigned long addr, | |||
260 | /* see if it's in a module */ | 260 | /* see if it's in a module */ |
261 | return module_address_lookup(addr, symbolsize, offset, modname, | 261 | return module_address_lookup(addr, symbolsize, offset, modname, |
262 | namebuf); | 262 | namebuf); |
263 | return NULL; | ||
264 | } | 263 | } |
265 | 264 | ||
266 | int lookup_symbol_name(unsigned long addr, char *symname) | 265 | int lookup_symbol_name(unsigned long addr, char *symname) |
diff --git a/kernel/kexec.c b/kernel/kexec.c index 59f3f0df35d4..aef265325cd3 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c | |||
@@ -753,8 +753,14 @@ static struct page *kimage_alloc_page(struct kimage *image, | |||
753 | *old = addr | (*old & ~PAGE_MASK); | 753 | *old = addr | (*old & ~PAGE_MASK); |
754 | 754 | ||
755 | /* The old page I have found cannot be a | 755 | /* The old page I have found cannot be a |
756 | * destination page, so return it. | 756 | * destination page, so return it if it's |
757 | * gfp_flags honor the ones passed in. | ||
757 | */ | 758 | */ |
759 | if (!(gfp_mask & __GFP_HIGHMEM) && | ||
760 | PageHighMem(old_page)) { | ||
761 | kimage_free_pages(old_page); | ||
762 | continue; | ||
763 | } | ||
758 | addr = old_addr; | 764 | addr = old_addr; |
759 | page = old_page; | 765 | page = old_page; |
760 | break; | 766 | break; |
diff --git a/kernel/kgdb.c b/kernel/kgdb.c index eaa21fc9ad1d..e4dcfb2272a4 100644 --- a/kernel/kgdb.c +++ b/kernel/kgdb.c | |||
@@ -488,7 +488,7 @@ static int write_mem_msg(int binary) | |||
488 | if (err) | 488 | if (err) |
489 | return err; | 489 | return err; |
490 | if (CACHE_FLUSH_IS_SAFE) | 490 | if (CACHE_FLUSH_IS_SAFE) |
491 | flush_icache_range(addr, addr + length + 1); | 491 | flush_icache_range(addr, addr + length); |
492 | return 0; | 492 | return 0; |
493 | } | 493 | } |
494 | 494 | ||
@@ -590,6 +590,7 @@ static void kgdb_wait(struct pt_regs *regs) | |||
590 | 590 | ||
591 | /* Signal the primary CPU that we are done: */ | 591 | /* Signal the primary CPU that we are done: */ |
592 | atomic_set(&cpu_in_kgdb[cpu], 0); | 592 | atomic_set(&cpu_in_kgdb[cpu], 0); |
593 | touch_softlockup_watchdog(); | ||
593 | clocksource_touch_watchdog(); | 594 | clocksource_touch_watchdog(); |
594 | local_irq_restore(flags); | 595 | local_irq_restore(flags); |
595 | } | 596 | } |
@@ -1432,6 +1433,7 @@ acquirelock: | |||
1432 | atomic_read(&kgdb_cpu_doing_single_step) != cpu) { | 1433 | atomic_read(&kgdb_cpu_doing_single_step) != cpu) { |
1433 | 1434 | ||
1434 | atomic_set(&kgdb_active, -1); | 1435 | atomic_set(&kgdb_active, -1); |
1436 | touch_softlockup_watchdog(); | ||
1435 | clocksource_touch_watchdog(); | 1437 | clocksource_touch_watchdog(); |
1436 | local_irq_restore(flags); | 1438 | local_irq_restore(flags); |
1437 | 1439 | ||
@@ -1462,7 +1464,7 @@ acquirelock: | |||
1462 | * 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 |
1463 | * CPU in a spin state while the debugger is active | 1465 | * CPU in a spin state while the debugger is active |
1464 | */ | 1466 | */ |
1465 | if (!kgdb_single_step || !kgdb_contthread) { | 1467 | if (!kgdb_single_step) { |
1466 | for (i = 0; i < NR_CPUS; i++) | 1468 | for (i = 0; i < NR_CPUS; i++) |
1467 | atomic_set(&passive_cpu_wait[i], 1); | 1469 | atomic_set(&passive_cpu_wait[i], 1); |
1468 | } | 1470 | } |
@@ -1475,7 +1477,7 @@ acquirelock: | |||
1475 | 1477 | ||
1476 | #ifdef CONFIG_SMP | 1478 | #ifdef CONFIG_SMP |
1477 | /* Signal the other CPUs to enter kgdb_wait() */ | 1479 | /* Signal the other CPUs to enter kgdb_wait() */ |
1478 | if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup) | 1480 | if ((!kgdb_single_step) && kgdb_do_roundup) |
1479 | kgdb_roundup_cpus(flags); | 1481 | kgdb_roundup_cpus(flags); |
1480 | #endif | 1482 | #endif |
1481 | 1483 | ||
@@ -1494,7 +1496,7 @@ acquirelock: | |||
1494 | 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); |
1495 | kgdb_deactivate_sw_breakpoints(); | 1497 | kgdb_deactivate_sw_breakpoints(); |
1496 | kgdb_single_step = 0; | 1498 | kgdb_single_step = 0; |
1497 | kgdb_contthread = NULL; | 1499 | kgdb_contthread = current; |
1498 | exception_level = 0; | 1500 | exception_level = 0; |
1499 | 1501 | ||
1500 | /* Talk to debugger with gdbserial protocol */ | 1502 | /* Talk to debugger with gdbserial protocol */ |
@@ -1508,7 +1510,7 @@ acquirelock: | |||
1508 | kgdb_info[ks->cpu].task = NULL; | 1510 | kgdb_info[ks->cpu].task = NULL; |
1509 | atomic_set(&cpu_in_kgdb[ks->cpu], 0); | 1511 | atomic_set(&cpu_in_kgdb[ks->cpu], 0); |
1510 | 1512 | ||
1511 | if (!kgdb_single_step || !kgdb_contthread) { | 1513 | if (!kgdb_single_step) { |
1512 | for (i = NR_CPUS-1; i >= 0; i--) | 1514 | for (i = NR_CPUS-1; i >= 0; i--) |
1513 | atomic_set(&passive_cpu_wait[i], 0); | 1515 | atomic_set(&passive_cpu_wait[i], 0); |
1514 | /* | 1516 | /* |
@@ -1524,6 +1526,7 @@ acquirelock: | |||
1524 | kgdb_restore: | 1526 | kgdb_restore: |
1525 | /* Free kgdb_active */ | 1527 | /* Free kgdb_active */ |
1526 | atomic_set(&kgdb_active, -1); | 1528 | atomic_set(&kgdb_active, -1); |
1529 | touch_softlockup_watchdog(); | ||
1527 | clocksource_touch_watchdog(); | 1530 | clocksource_touch_watchdog(); |
1528 | local_irq_restore(flags); | 1531 | local_irq_restore(flags); |
1529 | 1532 | ||
diff --git a/kernel/kmod.c b/kernel/kmod.c index 2456d1a0befb..3d3c3ea3a023 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c | |||
@@ -113,7 +113,7 @@ int request_module(const char *fmt, ...) | |||
113 | return ret; | 113 | return ret; |
114 | } | 114 | } |
115 | EXPORT_SYMBOL(request_module); | 115 | EXPORT_SYMBOL(request_module); |
116 | #endif /* CONFIG_KMOD */ | 116 | #endif /* CONFIG_MODULES */ |
117 | 117 | ||
118 | struct subprocess_info { | 118 | struct subprocess_info { |
119 | struct work_struct work; | 119 | struct work_struct work; |
@@ -265,7 +265,7 @@ static void __call_usermodehelper(struct work_struct *work) | |||
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | #ifdef CONFIG_PM | 268 | #ifdef CONFIG_PM_SLEEP |
269 | /* | 269 | /* |
270 | * If set, call_usermodehelper_exec() will exit immediately returning -EBUSY | 270 | * If set, call_usermodehelper_exec() will exit immediately returning -EBUSY |
271 | * (used for preventing user land processes from being created after the user | 271 | * (used for preventing user land processes from being created after the user |
@@ -288,39 +288,37 @@ static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq); | |||
288 | */ | 288 | */ |
289 | #define RUNNING_HELPERS_TIMEOUT (5 * HZ) | 289 | #define RUNNING_HELPERS_TIMEOUT (5 * HZ) |
290 | 290 | ||
291 | static int usermodehelper_pm_callback(struct notifier_block *nfb, | 291 | /** |
292 | unsigned long action, | 292 | * usermodehelper_disable - prevent new helpers from being started |
293 | void *ignored) | 293 | */ |
294 | int usermodehelper_disable(void) | ||
294 | { | 295 | { |
295 | long retval; | 296 | long retval; |
296 | 297 | ||
297 | switch (action) { | 298 | usermodehelper_disabled = 1; |
298 | case PM_HIBERNATION_PREPARE: | 299 | smp_mb(); |
299 | case PM_SUSPEND_PREPARE: | 300 | /* |
300 | usermodehelper_disabled = 1; | 301 | * From now on call_usermodehelper_exec() won't start any new |
301 | smp_mb(); | 302 | * helpers, so it is sufficient if running_helpers turns out to |
302 | /* | 303 | * be zero at one point (it may be increased later, but that |
303 | * From now on call_usermodehelper_exec() won't start any new | 304 | * doesn't matter). |
304 | * helpers, so it is sufficient if running_helpers turns out to | 305 | */ |
305 | * be zero at one point (it may be increased later, but that | 306 | retval = wait_event_timeout(running_helpers_waitq, |
306 | * doesn't matter). | ||
307 | */ | ||
308 | retval = wait_event_timeout(running_helpers_waitq, | ||
309 | atomic_read(&running_helpers) == 0, | 307 | atomic_read(&running_helpers) == 0, |
310 | RUNNING_HELPERS_TIMEOUT); | 308 | RUNNING_HELPERS_TIMEOUT); |
311 | if (retval) { | 309 | if (retval) |
312 | return NOTIFY_OK; | 310 | return 0; |
313 | } else { | ||
314 | usermodehelper_disabled = 0; | ||
315 | return NOTIFY_BAD; | ||
316 | } | ||
317 | case PM_POST_HIBERNATION: | ||
318 | case PM_POST_SUSPEND: | ||
319 | usermodehelper_disabled = 0; | ||
320 | return NOTIFY_OK; | ||
321 | } | ||
322 | 311 | ||
323 | return NOTIFY_DONE; | 312 | usermodehelper_disabled = 0; |
313 | return -EAGAIN; | ||
314 | } | ||
315 | |||
316 | /** | ||
317 | * usermodehelper_enable - allow new helpers to be started again | ||
318 | */ | ||
319 | void usermodehelper_enable(void) | ||
320 | { | ||
321 | usermodehelper_disabled = 0; | ||
324 | } | 322 | } |
325 | 323 | ||
326 | static void helper_lock(void) | 324 | static void helper_lock(void) |
@@ -334,18 +332,12 @@ static void helper_unlock(void) | |||
334 | if (atomic_dec_and_test(&running_helpers)) | 332 | if (atomic_dec_and_test(&running_helpers)) |
335 | wake_up(&running_helpers_waitq); | 333 | wake_up(&running_helpers_waitq); |
336 | } | 334 | } |
337 | 335 | #else /* CONFIG_PM_SLEEP */ | |
338 | static void register_pm_notifier_callback(void) | ||
339 | { | ||
340 | pm_notifier(usermodehelper_pm_callback, 0); | ||
341 | } | ||
342 | #else /* CONFIG_PM */ | ||
343 | #define usermodehelper_disabled 0 | 336 | #define usermodehelper_disabled 0 |
344 | 337 | ||
345 | static inline void helper_lock(void) {} | 338 | static inline void helper_lock(void) {} |
346 | static inline void helper_unlock(void) {} | 339 | static inline void helper_unlock(void) {} |
347 | static inline void register_pm_notifier_callback(void) {} | 340 | #endif /* CONFIG_PM_SLEEP */ |
348 | #endif /* CONFIG_PM */ | ||
349 | 341 | ||
350 | /** | 342 | /** |
351 | * call_usermodehelper_setup - prepare to call a usermode helper | 343 | * call_usermodehelper_setup - prepare to call a usermode helper |
@@ -515,5 +507,4 @@ void __init usermodehelper_init(void) | |||
515 | { | 507 | { |
516 | khelper_wq = create_singlethread_workqueue("khelper"); | 508 | khelper_wq = create_singlethread_workqueue("khelper"); |
517 | BUG_ON(!khelper_wq); | 509 | BUG_ON(!khelper_wq); |
518 | register_pm_notifier_callback(); | ||
519 | } | 510 | } |
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 75bc2cd9ebc6..8b57a2597f21 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -404,7 +404,7 @@ void kretprobe_hash_lock(struct task_struct *tsk, | |||
404 | spin_lock_irqsave(hlist_lock, *flags); | 404 | spin_lock_irqsave(hlist_lock, *flags); |
405 | } | 405 | } |
406 | 406 | ||
407 | void kretprobe_table_lock(unsigned long hash, unsigned long *flags) | 407 | static void kretprobe_table_lock(unsigned long hash, unsigned long *flags) |
408 | { | 408 | { |
409 | spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); | 409 | spinlock_t *hlist_lock = kretprobe_table_lock_ptr(hash); |
410 | spin_lock_irqsave(hlist_lock, *flags); | 410 | spin_lock_irqsave(hlist_lock, *flags); |
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index e53bc30e9ba5..08dd8ed86c77 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/kexec.h> | 16 | #include <linux/kexec.h> |
17 | #include <linux/profile.h> | ||
17 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
18 | 19 | ||
19 | #define KERNEL_ATTR_RO(_name) \ | 20 | #define KERNEL_ATTR_RO(_name) \ |
@@ -53,6 +54,37 @@ static ssize_t uevent_helper_store(struct kobject *kobj, | |||
53 | KERNEL_ATTR_RW(uevent_helper); | 54 | KERNEL_ATTR_RW(uevent_helper); |
54 | #endif | 55 | #endif |
55 | 56 | ||
57 | #ifdef CONFIG_PROFILING | ||
58 | static ssize_t profiling_show(struct kobject *kobj, | ||
59 | struct kobj_attribute *attr, char *buf) | ||
60 | { | ||
61 | return sprintf(buf, "%d\n", prof_on); | ||
62 | } | ||
63 | static ssize_t profiling_store(struct kobject *kobj, | ||
64 | struct kobj_attribute *attr, | ||
65 | const char *buf, size_t count) | ||
66 | { | ||
67 | int ret; | ||
68 | |||
69 | if (prof_on) | ||
70 | return -EEXIST; | ||
71 | /* | ||
72 | * This eventually calls into get_option() which | ||
73 | * has a ton of callers and is not const. It is | ||
74 | * easiest to cast it away here. | ||
75 | */ | ||
76 | profile_setup((char *)buf); | ||
77 | ret = profile_init(); | ||
78 | if (ret) | ||
79 | return ret; | ||
80 | ret = create_proc_profile(); | ||
81 | if (ret) | ||
82 | return ret; | ||
83 | return count; | ||
84 | } | ||
85 | KERNEL_ATTR_RW(profiling); | ||
86 | #endif | ||
87 | |||
56 | #ifdef CONFIG_KEXEC | 88 | #ifdef CONFIG_KEXEC |
57 | static ssize_t kexec_loaded_show(struct kobject *kobj, | 89 | static ssize_t kexec_loaded_show(struct kobject *kobj, |
58 | struct kobj_attribute *attr, char *buf) | 90 | struct kobj_attribute *attr, char *buf) |
@@ -109,6 +141,9 @@ static struct attribute * kernel_attrs[] = { | |||
109 | &uevent_seqnum_attr.attr, | 141 | &uevent_seqnum_attr.attr, |
110 | &uevent_helper_attr.attr, | 142 | &uevent_helper_attr.attr, |
111 | #endif | 143 | #endif |
144 | #ifdef CONFIG_PROFILING | ||
145 | &profiling_attr.attr, | ||
146 | #endif | ||
112 | #ifdef CONFIG_KEXEC | 147 | #ifdef CONFIG_KEXEC |
113 | &kexec_loaded_attr.attr, | 148 | &kexec_loaded_attr.attr, |
114 | &kexec_crash_loaded_attr.attr, | 149 | &kexec_crash_loaded_attr.attr, |
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 3bfb1877a003..dbda475b13bd 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -875,11 +875,11 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
875 | if (!entry) | 875 | if (!entry) |
876 | return 0; | 876 | return 0; |
877 | 877 | ||
878 | entry->class = this; | ||
879 | entry->distance = distance; | ||
880 | if (!save_trace(&entry->trace)) | 878 | if (!save_trace(&entry->trace)) |
881 | return 0; | 879 | return 0; |
882 | 880 | ||
881 | entry->class = this; | ||
882 | entry->distance = distance; | ||
883 | /* | 883 | /* |
884 | * Since we never remove from the dependency list, the list can | 884 | * Since we never remove from the dependency list, the list can |
885 | * be walked lockless by other CPUs, it's only allocation | 885 | * be walked lockless by other CPUs, it's only allocation |
@@ -3029,7 +3029,7 @@ found_it: | |||
3029 | 3029 | ||
3030 | stats = get_lock_stats(hlock_class(hlock)); | 3030 | stats = get_lock_stats(hlock_class(hlock)); |
3031 | if (point < ARRAY_SIZE(stats->contention_point)) | 3031 | if (point < ARRAY_SIZE(stats->contention_point)) |
3032 | stats->contention_point[i]++; | 3032 | stats->contention_point[point]++; |
3033 | if (lock->cpu != smp_processor_id()) | 3033 | if (lock->cpu != smp_processor_id()) |
3034 | stats->bounces[bounce_contended + !!hlock->read]++; | 3034 | stats->bounces[bounce_contended + !!hlock->read]++; |
3035 | put_lock_stats(stats); | 3035 | put_lock_stats(stats); |
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c index 4b194d34d77f..20dbcbf9c7dd 100644 --- a/kernel/lockdep_proc.c +++ b/kernel/lockdep_proc.c | |||
@@ -472,8 +472,9 @@ static void snprint_time(char *buf, size_t bufsiz, s64 nr) | |||
472 | { | 472 | { |
473 | unsigned long rem; | 473 | unsigned long rem; |
474 | 474 | ||
475 | nr += 5; /* for display rounding */ | ||
475 | rem = do_div(nr, 1000); /* XXX: do_div_signed */ | 476 | rem = do_div(nr, 1000); /* XXX: do_div_signed */ |
476 | snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, ((int)rem+5)/10); | 477 | snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, (int)rem/10); |
477 | } | 478 | } |
478 | 479 | ||
479 | 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/module.c b/kernel/module.c index 08864d257eb0..25bc9ac9e226 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -100,7 +100,7 @@ static inline int strong_try_module_get(struct module *mod) | |||
100 | static inline void add_taint_module(struct module *mod, unsigned flag) | 100 | static inline void add_taint_module(struct module *mod, unsigned flag) |
101 | { | 101 | { |
102 | add_taint(flag); | 102 | add_taint(flag); |
103 | mod->taints |= flag; | 103 | mod->taints |= (1U << flag); |
104 | } | 104 | } |
105 | 105 | ||
106 | /* | 106 | /* |
@@ -784,6 +784,7 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
784 | mutex_lock(&module_mutex); | 784 | mutex_lock(&module_mutex); |
785 | /* Store the name of the last unloaded module for diagnostic purposes */ | 785 | /* Store the name of the last unloaded module for diagnostic purposes */ |
786 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); | 786 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); |
787 | unregister_dynamic_debug_module(mod->name); | ||
787 | free_module(mod); | 788 | free_module(mod); |
788 | 789 | ||
789 | out: | 790 | out: |
@@ -923,7 +924,7 @@ static const char vermagic[] = VERMAGIC_STRING; | |||
923 | static int try_to_force_load(struct module *mod, const char *symname) | 924 | static int try_to_force_load(struct module *mod, const char *symname) |
924 | { | 925 | { |
925 | #ifdef CONFIG_MODULE_FORCE_LOAD | 926 | #ifdef CONFIG_MODULE_FORCE_LOAD |
926 | if (!(tainted & TAINT_FORCED_MODULE)) | 927 | if (!test_taint(TAINT_FORCED_MODULE)) |
927 | printk("%s: no version for \"%s\" found: kernel tainted.\n", | 928 | printk("%s: no version for \"%s\" found: kernel tainted.\n", |
928 | mod->name, symname); | 929 | mod->name, symname); |
929 | add_taint_module(mod, TAINT_FORCED_MODULE); | 930 | add_taint_module(mod, TAINT_FORCED_MODULE); |
@@ -1033,7 +1034,7 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs, | |||
1033 | const unsigned long *crc; | 1034 | const unsigned long *crc; |
1034 | 1035 | ||
1035 | ret = find_symbol(name, &owner, &crc, | 1036 | ret = find_symbol(name, &owner, &crc, |
1036 | !(mod->taints & TAINT_PROPRIETARY_MODULE), true); | 1037 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); |
1037 | if (!IS_ERR_VALUE(ret)) { | 1038 | if (!IS_ERR_VALUE(ret)) { |
1038 | /* use_module can fail due to OOM, | 1039 | /* use_module can fail due to OOM, |
1039 | or module initialization or unloading */ | 1040 | or module initialization or unloading */ |
@@ -1173,7 +1174,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs, | |||
1173 | while (i-- > 0) | 1174 | while (i-- > 0) |
1174 | sysfs_remove_bin_file(notes_attrs->dir, | 1175 | sysfs_remove_bin_file(notes_attrs->dir, |
1175 | ¬es_attrs->attrs[i]); | 1176 | ¬es_attrs->attrs[i]); |
1176 | kobject_del(notes_attrs->dir); | 1177 | kobject_put(notes_attrs->dir); |
1177 | } | 1178 | } |
1178 | kfree(notes_attrs); | 1179 | kfree(notes_attrs); |
1179 | } | 1180 | } |
@@ -1634,7 +1635,7 @@ static void set_license(struct module *mod, const char *license) | |||
1634 | license = "unspecified"; | 1635 | license = "unspecified"; |
1635 | 1636 | ||
1636 | if (!license_is_gpl_compatible(license)) { | 1637 | if (!license_is_gpl_compatible(license)) { |
1637 | if (!(tainted & TAINT_PROPRIETARY_MODULE)) | 1638 | if (!test_taint(TAINT_PROPRIETARY_MODULE)) |
1638 | printk(KERN_WARNING "%s: module license '%s' taints " | 1639 | printk(KERN_WARNING "%s: module license '%s' taints " |
1639 | "kernel.\n", mod->name, license); | 1640 | "kernel.\n", mod->name, license); |
1640 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 1641 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
@@ -1783,6 +1784,33 @@ static inline void add_kallsyms(struct module *mod, | |||
1783 | } | 1784 | } |
1784 | #endif /* CONFIG_KALLSYMS */ | 1785 | #endif /* CONFIG_KALLSYMS */ |
1785 | 1786 | ||
1787 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG | ||
1788 | static void dynamic_printk_setup(Elf_Shdr *sechdrs, unsigned int verboseindex) | ||
1789 | { | ||
1790 | struct mod_debug *debug_info; | ||
1791 | unsigned long pos, end; | ||
1792 | unsigned int num_verbose; | ||
1793 | |||
1794 | pos = sechdrs[verboseindex].sh_addr; | ||
1795 | num_verbose = sechdrs[verboseindex].sh_size / | ||
1796 | sizeof(struct mod_debug); | ||
1797 | end = pos + (num_verbose * sizeof(struct mod_debug)); | ||
1798 | |||
1799 | for (; pos < end; pos += sizeof(struct mod_debug)) { | ||
1800 | debug_info = (struct mod_debug *)pos; | ||
1801 | register_dynamic_debug_module(debug_info->modname, | ||
1802 | debug_info->type, debug_info->logical_modname, | ||
1803 | debug_info->flag_names, debug_info->hash, | ||
1804 | debug_info->hash2); | ||
1805 | } | ||
1806 | } | ||
1807 | #else | ||
1808 | static inline void dynamic_printk_setup(Elf_Shdr *sechdrs, | ||
1809 | unsigned int verboseindex) | ||
1810 | { | ||
1811 | } | ||
1812 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ | ||
1813 | |||
1786 | static void *module_alloc_update_bounds(unsigned long size) | 1814 | static void *module_alloc_update_bounds(unsigned long size) |
1787 | { | 1815 | { |
1788 | void *ret = module_alloc(size); | 1816 | void *ret = module_alloc(size); |
@@ -1799,13 +1827,14 @@ static void *module_alloc_update_bounds(unsigned long size) | |||
1799 | 1827 | ||
1800 | /* Allocate and load the module: note that size of section 0 is always | 1828 | /* Allocate and load the module: note that size of section 0 is always |
1801 | zero, and we rely on this for optional sections. */ | 1829 | zero, and we rely on this for optional sections. */ |
1802 | static struct module *load_module(void __user *umod, | 1830 | static noinline struct module *load_module(void __user *umod, |
1803 | unsigned long len, | 1831 | unsigned long len, |
1804 | const char __user *uargs) | 1832 | const char __user *uargs) |
1805 | { | 1833 | { |
1806 | Elf_Ehdr *hdr; | 1834 | Elf_Ehdr *hdr; |
1807 | Elf_Shdr *sechdrs; | 1835 | Elf_Shdr *sechdrs; |
1808 | char *secstrings, *args, *modmagic, *strtab = NULL; | 1836 | char *secstrings, *args, *modmagic, *strtab = NULL; |
1837 | char *staging; | ||
1809 | unsigned int i; | 1838 | unsigned int i; |
1810 | unsigned int symindex = 0; | 1839 | unsigned int symindex = 0; |
1811 | unsigned int strindex = 0; | 1840 | unsigned int strindex = 0; |
@@ -1831,6 +1860,7 @@ static struct module *load_module(void __user *umod, | |||
1831 | #endif | 1860 | #endif |
1832 | unsigned int markersindex; | 1861 | unsigned int markersindex; |
1833 | unsigned int markersstringsindex; | 1862 | unsigned int markersstringsindex; |
1863 | unsigned int verboseindex; | ||
1834 | struct module *mod; | 1864 | struct module *mod; |
1835 | long err = 0; | 1865 | long err = 0; |
1836 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ | 1866 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
@@ -1960,6 +1990,14 @@ static struct module *load_module(void __user *umod, | |||
1960 | goto free_hdr; | 1990 | goto free_hdr; |
1961 | } | 1991 | } |
1962 | 1992 | ||
1993 | staging = get_modinfo(sechdrs, infoindex, "staging"); | ||
1994 | if (staging) { | ||
1995 | add_taint_module(mod, TAINT_CRAP); | ||
1996 | printk(KERN_WARNING "%s: module is from the staging directory," | ||
1997 | " the quality is unknown, you have been warned.\n", | ||
1998 | mod->name); | ||
1999 | } | ||
2000 | |||
1963 | /* Now copy in args */ | 2001 | /* Now copy in args */ |
1964 | args = strndup_user(uargs, ~0UL >> 1); | 2002 | args = strndup_user(uargs, ~0UL >> 1); |
1965 | if (IS_ERR(args)) { | 2003 | if (IS_ERR(args)) { |
@@ -2117,6 +2155,7 @@ static struct module *load_module(void __user *umod, | |||
2117 | markersindex = find_sec(hdr, sechdrs, secstrings, "__markers"); | 2155 | markersindex = find_sec(hdr, sechdrs, secstrings, "__markers"); |
2118 | markersstringsindex = find_sec(hdr, sechdrs, secstrings, | 2156 | markersstringsindex = find_sec(hdr, sechdrs, secstrings, |
2119 | "__markers_strings"); | 2157 | "__markers_strings"); |
2158 | verboseindex = find_sec(hdr, sechdrs, secstrings, "__verbose"); | ||
2120 | 2159 | ||
2121 | /* Now do relocations. */ | 2160 | /* Now do relocations. */ |
2122 | for (i = 1; i < hdr->e_shnum; i++) { | 2161 | for (i = 1; i < hdr->e_shnum; i++) { |
@@ -2167,6 +2206,7 @@ static struct module *load_module(void __user *umod, | |||
2167 | marker_update_probe_range(mod->markers, | 2206 | marker_update_probe_range(mod->markers, |
2168 | mod->markers + mod->num_markers); | 2207 | mod->markers + mod->num_markers); |
2169 | #endif | 2208 | #endif |
2209 | dynamic_printk_setup(sechdrs, verboseindex); | ||
2170 | err = module_finalize(hdr, sechdrs, mod); | 2210 | err = module_finalize(hdr, sechdrs, mod); |
2171 | if (err < 0) | 2211 | if (err < 0) |
2172 | goto cleanup; | 2212 | goto cleanup; |
@@ -2552,10 +2592,12 @@ static char *module_flags(struct module *mod, char *buf) | |||
2552 | mod->state == MODULE_STATE_GOING || | 2592 | mod->state == MODULE_STATE_GOING || |
2553 | mod->state == MODULE_STATE_COMING) { | 2593 | mod->state == MODULE_STATE_COMING) { |
2554 | buf[bx++] = '('; | 2594 | buf[bx++] = '('; |
2555 | if (mod->taints & TAINT_PROPRIETARY_MODULE) | 2595 | if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) |
2556 | buf[bx++] = 'P'; | 2596 | buf[bx++] = 'P'; |
2557 | if (mod->taints & TAINT_FORCED_MODULE) | 2597 | if (mod->taints & (1 << TAINT_FORCED_MODULE)) |
2558 | buf[bx++] = 'F'; | 2598 | buf[bx++] = 'F'; |
2599 | if (mod->taints & (1 << TAINT_CRAP)) | ||
2600 | buf[bx++] = 'C'; | ||
2559 | /* | 2601 | /* |
2560 | * TAINT_FORCED_RMMOD: could be added. | 2602 | * TAINT_FORCED_RMMOD: could be added. |
2561 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't | 2603 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't |
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/panic.c b/kernel/panic.c index 12c5a0a6c89b..bda561ef3cdf 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include <linux/kallsyms.h> | 23 | #include <linux/kallsyms.h> |
24 | 24 | ||
25 | int panic_on_oops; | 25 | int panic_on_oops; |
26 | int tainted; | 26 | static unsigned long tainted_mask; |
27 | static int pause_on_oops; | 27 | static int pause_on_oops; |
28 | static int pause_on_oops_flag; | 28 | static int pause_on_oops_flag; |
29 | static DEFINE_SPINLOCK(pause_on_oops_lock); | 29 | static DEFINE_SPINLOCK(pause_on_oops_lock); |
@@ -143,6 +143,27 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
143 | 143 | ||
144 | EXPORT_SYMBOL(panic); | 144 | EXPORT_SYMBOL(panic); |
145 | 145 | ||
146 | |||
147 | struct tnt { | ||
148 | u8 bit; | ||
149 | char true; | ||
150 | char false; | ||
151 | }; | ||
152 | |||
153 | static const struct tnt tnts[] = { | ||
154 | { TAINT_PROPRIETARY_MODULE, 'P', 'G' }, | ||
155 | { TAINT_FORCED_MODULE, 'F', ' ' }, | ||
156 | { TAINT_UNSAFE_SMP, 'S', ' ' }, | ||
157 | { TAINT_FORCED_RMMOD, 'R', ' ' }, | ||
158 | { TAINT_MACHINE_CHECK, 'M', ' ' }, | ||
159 | { TAINT_BAD_PAGE, 'B', ' ' }, | ||
160 | { TAINT_USER, 'U', ' ' }, | ||
161 | { TAINT_DIE, 'D', ' ' }, | ||
162 | { TAINT_OVERRIDDEN_ACPI_TABLE, 'A', ' ' }, | ||
163 | { TAINT_WARN, 'W', ' ' }, | ||
164 | { TAINT_CRAP, 'C', ' ' }, | ||
165 | }; | ||
166 | |||
146 | /** | 167 | /** |
147 | * print_tainted - return a string to represent the kernel taint state. | 168 | * print_tainted - return a string to represent the kernel taint state. |
148 | * | 169 | * |
@@ -155,35 +176,45 @@ EXPORT_SYMBOL(panic); | |||
155 | * 'U' - Userspace-defined naughtiness. | 176 | * 'U' - Userspace-defined naughtiness. |
156 | * 'A' - ACPI table overridden. | 177 | * 'A' - ACPI table overridden. |
157 | * 'W' - Taint on warning. | 178 | * 'W' - Taint on warning. |
179 | * 'C' - modules from drivers/staging are loaded. | ||
158 | * | 180 | * |
159 | * The string is overwritten by the next call to print_taint(). | 181 | * The string is overwritten by the next call to print_taint(). |
160 | */ | 182 | */ |
161 | |||
162 | const char *print_tainted(void) | 183 | const char *print_tainted(void) |
163 | { | 184 | { |
164 | static char buf[20]; | 185 | static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ") + 1]; |
165 | if (tainted) { | 186 | |
166 | snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c%c%c%c%c", | 187 | if (tainted_mask) { |
167 | tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G', | 188 | char *s; |
168 | tainted & TAINT_FORCED_MODULE ? 'F' : ' ', | 189 | int i; |
169 | tainted & TAINT_UNSAFE_SMP ? 'S' : ' ', | 190 | |
170 | tainted & TAINT_FORCED_RMMOD ? 'R' : ' ', | 191 | s = buf + sprintf(buf, "Tainted: "); |
171 | tainted & TAINT_MACHINE_CHECK ? 'M' : ' ', | 192 | for (i = 0; i < ARRAY_SIZE(tnts); i++) { |
172 | tainted & TAINT_BAD_PAGE ? 'B' : ' ', | 193 | const struct tnt *t = &tnts[i]; |
173 | tainted & TAINT_USER ? 'U' : ' ', | 194 | *s++ = test_bit(t->bit, &tainted_mask) ? |
174 | tainted & TAINT_DIE ? 'D' : ' ', | 195 | t->true : t->false; |
175 | tainted & TAINT_OVERRIDDEN_ACPI_TABLE ? 'A' : ' ', | 196 | } |
176 | tainted & TAINT_WARN ? 'W' : ' '); | 197 | *s = 0; |
177 | } | 198 | } else |
178 | else | ||
179 | snprintf(buf, sizeof(buf), "Not tainted"); | 199 | snprintf(buf, sizeof(buf), "Not tainted"); |
180 | return(buf); | 200 | return(buf); |
181 | } | 201 | } |
182 | 202 | ||
203 | int test_taint(unsigned flag) | ||
204 | { | ||
205 | return test_bit(flag, &tainted_mask); | ||
206 | } | ||
207 | EXPORT_SYMBOL(test_taint); | ||
208 | |||
209 | unsigned long get_taint(void) | ||
210 | { | ||
211 | return tainted_mask; | ||
212 | } | ||
213 | |||
183 | void add_taint(unsigned flag) | 214 | void add_taint(unsigned flag) |
184 | { | 215 | { |
185 | debug_locks = 0; /* can't trust the integrity of the kernel anymore */ | 216 | debug_locks = 0; /* can't trust the integrity of the kernel anymore */ |
186 | tainted |= flag; | 217 | set_bit(flag, &tainted_mask); |
187 | } | 218 | } |
188 | EXPORT_SYMBOL(add_taint); | 219 | EXPORT_SYMBOL(add_taint); |
189 | 220 | ||
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 da9c2dda6a4e..dfdec524d1b7 100644 --- a/kernel/pm_qos_params.c +++ b/kernel/pm_qos_params.c | |||
@@ -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 | ||
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index c42a03aef36f..153dcb2639c3 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
@@ -7,6 +7,93 @@ | |||
7 | #include <linux/errno.h> | 7 | #include <linux/errno.h> |
8 | #include <linux/math64.h> | 8 | #include <linux/math64.h> |
9 | #include <asm/uaccess.h> | 9 | #include <asm/uaccess.h> |
10 | #include <linux/kernel_stat.h> | ||
11 | |||
12 | /* | ||
13 | * Allocate the thread_group_cputime structure appropriately and fill in the | ||
14 | * current values of the fields. Called from copy_signal() via | ||
15 | * thread_group_cputime_clone_thread() when adding a second or subsequent | ||
16 | * thread to a thread group. Assumes interrupts are enabled when called. | ||
17 | */ | ||
18 | int thread_group_cputime_alloc(struct task_struct *tsk) | ||
19 | { | ||
20 | struct signal_struct *sig = tsk->signal; | ||
21 | struct task_cputime *cputime; | ||
22 | |||
23 | /* | ||
24 | * If we have multiple threads and we don't already have a | ||
25 | * per-CPU task_cputime struct (checked in the caller), allocate | ||
26 | * one and fill it in with the times accumulated so far. We may | ||
27 | * race with another thread so recheck after we pick up the sighand | ||
28 | * lock. | ||
29 | */ | ||
30 | cputime = alloc_percpu(struct task_cputime); | ||
31 | if (cputime == NULL) | ||
32 | return -ENOMEM; | ||
33 | spin_lock_irq(&tsk->sighand->siglock); | ||
34 | if (sig->cputime.totals) { | ||
35 | spin_unlock_irq(&tsk->sighand->siglock); | ||
36 | free_percpu(cputime); | ||
37 | return 0; | ||
38 | } | ||
39 | sig->cputime.totals = cputime; | ||
40 | cputime = per_cpu_ptr(sig->cputime.totals, smp_processor_id()); | ||
41 | cputime->utime = tsk->utime; | ||
42 | cputime->stime = tsk->stime; | ||
43 | cputime->sum_exec_runtime = tsk->se.sum_exec_runtime; | ||
44 | spin_unlock_irq(&tsk->sighand->siglock); | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * thread_group_cputime - Sum the thread group time fields across all CPUs. | ||
50 | * | ||
51 | * @tsk: The task we use to identify the thread group. | ||
52 | * @times: task_cputime structure in which we return the summed fields. | ||
53 | * | ||
54 | * Walk the list of CPUs to sum the per-CPU time fields in the thread group | ||
55 | * time structure. | ||
56 | */ | ||
57 | void thread_group_cputime( | ||
58 | struct task_struct *tsk, | ||
59 | struct task_cputime *times) | ||
60 | { | ||
61 | struct signal_struct *sig; | ||
62 | int i; | ||
63 | struct task_cputime *tot; | ||
64 | |||
65 | sig = tsk->signal; | ||
66 | if (unlikely(!sig) || !sig->cputime.totals) { | ||
67 | times->utime = tsk->utime; | ||
68 | times->stime = tsk->stime; | ||
69 | times->sum_exec_runtime = tsk->se.sum_exec_runtime; | ||
70 | return; | ||
71 | } | ||
72 | times->stime = times->utime = cputime_zero; | ||
73 | times->sum_exec_runtime = 0; | ||
74 | for_each_possible_cpu(i) { | ||
75 | tot = per_cpu_ptr(tsk->signal->cputime.totals, i); | ||
76 | times->utime = cputime_add(times->utime, tot->utime); | ||
77 | times->stime = cputime_add(times->stime, tot->stime); | ||
78 | times->sum_exec_runtime += tot->sum_exec_runtime; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * Called after updating RLIMIT_CPU to set timer expiration if necessary. | ||
84 | */ | ||
85 | void update_rlimit_cpu(unsigned long rlim_new) | ||
86 | { | ||
87 | cputime_t cputime; | ||
88 | |||
89 | cputime = secs_to_cputime(rlim_new); | ||
90 | if (cputime_eq(current->signal->it_prof_expires, cputime_zero) || | ||
91 | cputime_lt(current->signal->it_prof_expires, cputime)) { | ||
92 | spin_lock_irq(¤t->sighand->siglock); | ||
93 | set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL); | ||
94 | spin_unlock_irq(¤t->sighand->siglock); | ||
95 | } | ||
96 | } | ||
10 | 97 | ||
11 | static int check_clock(const clockid_t which_clock) | 98 | static int check_clock(const clockid_t which_clock) |
12 | { | 99 | { |
@@ -158,10 +245,6 @@ static inline cputime_t virt_ticks(struct task_struct *p) | |||
158 | { | 245 | { |
159 | return p->utime; | 246 | return p->utime; |
160 | } | 247 | } |
161 | static inline unsigned long long sched_ns(struct task_struct *p) | ||
162 | { | ||
163 | return task_sched_runtime(p); | ||
164 | } | ||
165 | 248 | ||
166 | int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp) | 249 | int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp) |
167 | { | 250 | { |
@@ -211,7 +294,7 @@ static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p, | |||
211 | cpu->cpu = virt_ticks(p); | 294 | cpu->cpu = virt_ticks(p); |
212 | break; | 295 | break; |
213 | case CPUCLOCK_SCHED: | 296 | case CPUCLOCK_SCHED: |
214 | cpu->sched = sched_ns(p); | 297 | cpu->sched = p->se.sum_exec_runtime + task_delta_exec(p); |
215 | break; | 298 | break; |
216 | } | 299 | } |
217 | return 0; | 300 | return 0; |
@@ -220,59 +303,30 @@ static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p, | |||
220 | /* | 303 | /* |
221 | * Sample a process (thread group) clock for the given group_leader task. | 304 | * Sample a process (thread group) clock for the given group_leader task. |
222 | * Must be called with tasklist_lock held for reading. | 305 | * Must be called with tasklist_lock held for reading. |
223 | * Must be called with tasklist_lock held for reading, and p->sighand->siglock. | ||
224 | */ | 306 | */ |
225 | static int cpu_clock_sample_group_locked(unsigned int clock_idx, | 307 | static int cpu_clock_sample_group(const clockid_t which_clock, |
226 | struct task_struct *p, | 308 | struct task_struct *p, |
227 | union cpu_time_count *cpu) | 309 | union cpu_time_count *cpu) |
228 | { | 310 | { |
229 | struct task_struct *t = p; | 311 | struct task_cputime cputime; |
230 | switch (clock_idx) { | 312 | |
313 | thread_group_cputime(p, &cputime); | ||
314 | switch (which_clock) { | ||
231 | default: | 315 | default: |
232 | return -EINVAL; | 316 | return -EINVAL; |
233 | case CPUCLOCK_PROF: | 317 | case CPUCLOCK_PROF: |
234 | cpu->cpu = cputime_add(p->signal->utime, p->signal->stime); | 318 | cpu->cpu = cputime_add(cputime.utime, cputime.stime); |
235 | do { | ||
236 | cpu->cpu = cputime_add(cpu->cpu, prof_ticks(t)); | ||
237 | t = next_thread(t); | ||
238 | } while (t != p); | ||
239 | break; | 319 | break; |
240 | case CPUCLOCK_VIRT: | 320 | case CPUCLOCK_VIRT: |
241 | cpu->cpu = p->signal->utime; | 321 | cpu->cpu = cputime.utime; |
242 | do { | ||
243 | cpu->cpu = cputime_add(cpu->cpu, virt_ticks(t)); | ||
244 | t = next_thread(t); | ||
245 | } while (t != p); | ||
246 | break; | 322 | break; |
247 | case CPUCLOCK_SCHED: | 323 | case CPUCLOCK_SCHED: |
248 | cpu->sched = p->signal->sum_sched_runtime; | 324 | cpu->sched = cputime.sum_exec_runtime + task_delta_exec(p); |
249 | /* Add in each other live thread. */ | ||
250 | while ((t = next_thread(t)) != p) { | ||
251 | cpu->sched += t->se.sum_exec_runtime; | ||
252 | } | ||
253 | cpu->sched += sched_ns(p); | ||
254 | break; | 325 | break; |
255 | } | 326 | } |
256 | return 0; | 327 | return 0; |
257 | } | 328 | } |
258 | 329 | ||
259 | /* | ||
260 | * Sample a process (thread group) clock for the given group_leader task. | ||
261 | * Must be called with tasklist_lock held for reading. | ||
262 | */ | ||
263 | static int cpu_clock_sample_group(const clockid_t which_clock, | ||
264 | struct task_struct *p, | ||
265 | union cpu_time_count *cpu) | ||
266 | { | ||
267 | int ret; | ||
268 | unsigned long flags; | ||
269 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
270 | ret = cpu_clock_sample_group_locked(CPUCLOCK_WHICH(which_clock), p, | ||
271 | cpu); | ||
272 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
273 | return ret; | ||
274 | } | ||
275 | |||
276 | 330 | ||
277 | int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp) | 331 | int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp) |
278 | { | 332 | { |
@@ -471,80 +525,11 @@ void posix_cpu_timers_exit(struct task_struct *tsk) | |||
471 | } | 525 | } |
472 | void posix_cpu_timers_exit_group(struct task_struct *tsk) | 526 | void posix_cpu_timers_exit_group(struct task_struct *tsk) |
473 | { | 527 | { |
474 | cleanup_timers(tsk->signal->cpu_timers, | 528 | struct task_cputime cputime; |
475 | cputime_add(tsk->utime, tsk->signal->utime), | ||
476 | cputime_add(tsk->stime, tsk->signal->stime), | ||
477 | tsk->se.sum_exec_runtime + tsk->signal->sum_sched_runtime); | ||
478 | } | ||
479 | 529 | ||
480 | 530 | thread_group_cputime(tsk, &cputime); | |
481 | /* | 531 | cleanup_timers(tsk->signal->cpu_timers, |
482 | * Set the expiry times of all the threads in the process so one of them | 532 | cputime.utime, cputime.stime, cputime.sum_exec_runtime); |
483 | * will go off before the process cumulative expiry total is reached. | ||
484 | */ | ||
485 | static void process_timer_rebalance(struct task_struct *p, | ||
486 | unsigned int clock_idx, | ||
487 | union cpu_time_count expires, | ||
488 | union cpu_time_count val) | ||
489 | { | ||
490 | cputime_t ticks, left; | ||
491 | unsigned long long ns, nsleft; | ||
492 | struct task_struct *t = p; | ||
493 | unsigned int nthreads = atomic_read(&p->signal->live); | ||
494 | |||
495 | if (!nthreads) | ||
496 | return; | ||
497 | |||
498 | switch (clock_idx) { | ||
499 | default: | ||
500 | BUG(); | ||
501 | break; | ||
502 | case CPUCLOCK_PROF: | ||
503 | left = cputime_div_non_zero(cputime_sub(expires.cpu, val.cpu), | ||
504 | nthreads); | ||
505 | do { | ||
506 | if (likely(!(t->flags & PF_EXITING))) { | ||
507 | ticks = cputime_add(prof_ticks(t), left); | ||
508 | if (cputime_eq(t->it_prof_expires, | ||
509 | cputime_zero) || | ||
510 | cputime_gt(t->it_prof_expires, ticks)) { | ||
511 | t->it_prof_expires = ticks; | ||
512 | } | ||
513 | } | ||
514 | t = next_thread(t); | ||
515 | } while (t != p); | ||
516 | break; | ||
517 | case CPUCLOCK_VIRT: | ||
518 | left = cputime_div_non_zero(cputime_sub(expires.cpu, val.cpu), | ||
519 | nthreads); | ||
520 | do { | ||
521 | if (likely(!(t->flags & PF_EXITING))) { | ||
522 | ticks = cputime_add(virt_ticks(t), left); | ||
523 | if (cputime_eq(t->it_virt_expires, | ||
524 | cputime_zero) || | ||
525 | cputime_gt(t->it_virt_expires, ticks)) { | ||
526 | t->it_virt_expires = ticks; | ||
527 | } | ||
528 | } | ||
529 | t = next_thread(t); | ||
530 | } while (t != p); | ||
531 | break; | ||
532 | case CPUCLOCK_SCHED: | ||
533 | nsleft = expires.sched - val.sched; | ||
534 | do_div(nsleft, nthreads); | ||
535 | nsleft = max_t(unsigned long long, nsleft, 1); | ||
536 | do { | ||
537 | if (likely(!(t->flags & PF_EXITING))) { | ||
538 | ns = t->se.sum_exec_runtime + nsleft; | ||
539 | if (t->it_sched_expires == 0 || | ||
540 | t->it_sched_expires > ns) { | ||
541 | t->it_sched_expires = ns; | ||
542 | } | ||
543 | } | ||
544 | t = next_thread(t); | ||
545 | } while (t != p); | ||
546 | break; | ||
547 | } | ||
548 | } | 533 | } |
549 | 534 | ||
550 | static void clear_dead_task(struct k_itimer *timer, union cpu_time_count now) | 535 | static void clear_dead_task(struct k_itimer *timer, union cpu_time_count now) |
@@ -608,29 +593,32 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now) | |||
608 | default: | 593 | default: |
609 | BUG(); | 594 | BUG(); |
610 | case CPUCLOCK_PROF: | 595 | case CPUCLOCK_PROF: |
611 | if (cputime_eq(p->it_prof_expires, | 596 | if (cputime_eq(p->cputime_expires.prof_exp, |
612 | cputime_zero) || | 597 | cputime_zero) || |
613 | cputime_gt(p->it_prof_expires, | 598 | cputime_gt(p->cputime_expires.prof_exp, |
614 | nt->expires.cpu)) | 599 | nt->expires.cpu)) |
615 | p->it_prof_expires = nt->expires.cpu; | 600 | p->cputime_expires.prof_exp = |
601 | nt->expires.cpu; | ||
616 | break; | 602 | break; |
617 | case CPUCLOCK_VIRT: | 603 | case CPUCLOCK_VIRT: |
618 | if (cputime_eq(p->it_virt_expires, | 604 | if (cputime_eq(p->cputime_expires.virt_exp, |
619 | cputime_zero) || | 605 | cputime_zero) || |
620 | cputime_gt(p->it_virt_expires, | 606 | cputime_gt(p->cputime_expires.virt_exp, |
621 | nt->expires.cpu)) | 607 | nt->expires.cpu)) |
622 | p->it_virt_expires = nt->expires.cpu; | 608 | p->cputime_expires.virt_exp = |
609 | nt->expires.cpu; | ||
623 | break; | 610 | break; |
624 | case CPUCLOCK_SCHED: | 611 | case CPUCLOCK_SCHED: |
625 | if (p->it_sched_expires == 0 || | 612 | if (p->cputime_expires.sched_exp == 0 || |
626 | p->it_sched_expires > nt->expires.sched) | 613 | p->cputime_expires.sched_exp > |
627 | p->it_sched_expires = nt->expires.sched; | 614 | nt->expires.sched) |
615 | p->cputime_expires.sched_exp = | ||
616 | nt->expires.sched; | ||
628 | break; | 617 | break; |
629 | } | 618 | } |
630 | } else { | 619 | } else { |
631 | /* | 620 | /* |
632 | * For a process timer, we must balance | 621 | * For a process timer, set the cached expiration time. |
633 | * all the live threads' expirations. | ||
634 | */ | 622 | */ |
635 | switch (CPUCLOCK_WHICH(timer->it_clock)) { | 623 | switch (CPUCLOCK_WHICH(timer->it_clock)) { |
636 | default: | 624 | default: |
@@ -641,7 +629,9 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now) | |||
641 | cputime_lt(p->signal->it_virt_expires, | 629 | cputime_lt(p->signal->it_virt_expires, |
642 | timer->it.cpu.expires.cpu)) | 630 | timer->it.cpu.expires.cpu)) |
643 | break; | 631 | break; |
644 | goto rebalance; | 632 | p->signal->cputime_expires.virt_exp = |
633 | timer->it.cpu.expires.cpu; | ||
634 | break; | ||
645 | case CPUCLOCK_PROF: | 635 | case CPUCLOCK_PROF: |
646 | if (!cputime_eq(p->signal->it_prof_expires, | 636 | if (!cputime_eq(p->signal->it_prof_expires, |
647 | cputime_zero) && | 637 | cputime_zero) && |
@@ -652,13 +642,12 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now) | |||
652 | if (i != RLIM_INFINITY && | 642 | if (i != RLIM_INFINITY && |
653 | i <= cputime_to_secs(timer->it.cpu.expires.cpu)) | 643 | i <= cputime_to_secs(timer->it.cpu.expires.cpu)) |
654 | break; | 644 | break; |
655 | goto rebalance; | 645 | p->signal->cputime_expires.prof_exp = |
646 | timer->it.cpu.expires.cpu; | ||
647 | break; | ||
656 | case CPUCLOCK_SCHED: | 648 | case CPUCLOCK_SCHED: |
657 | rebalance: | 649 | p->signal->cputime_expires.sched_exp = |
658 | process_timer_rebalance( | 650 | timer->it.cpu.expires.sched; |
659 | timer->it.cpu.task, | ||
660 | CPUCLOCK_WHICH(timer->it_clock), | ||
661 | timer->it.cpu.expires, now); | ||
662 | break; | 651 | break; |
663 | } | 652 | } |
664 | } | 653 | } |
@@ -969,13 +958,13 @@ static void check_thread_timers(struct task_struct *tsk, | |||
969 | struct signal_struct *const sig = tsk->signal; | 958 | struct signal_struct *const sig = tsk->signal; |
970 | 959 | ||
971 | maxfire = 20; | 960 | maxfire = 20; |
972 | tsk->it_prof_expires = cputime_zero; | 961 | tsk->cputime_expires.prof_exp = cputime_zero; |
973 | while (!list_empty(timers)) { | 962 | while (!list_empty(timers)) { |
974 | struct cpu_timer_list *t = list_first_entry(timers, | 963 | struct cpu_timer_list *t = list_first_entry(timers, |
975 | struct cpu_timer_list, | 964 | struct cpu_timer_list, |
976 | entry); | 965 | entry); |
977 | if (!--maxfire || cputime_lt(prof_ticks(tsk), t->expires.cpu)) { | 966 | if (!--maxfire || cputime_lt(prof_ticks(tsk), t->expires.cpu)) { |
978 | tsk->it_prof_expires = t->expires.cpu; | 967 | tsk->cputime_expires.prof_exp = t->expires.cpu; |
979 | break; | 968 | break; |
980 | } | 969 | } |
981 | t->firing = 1; | 970 | t->firing = 1; |
@@ -984,13 +973,13 @@ static void check_thread_timers(struct task_struct *tsk, | |||
984 | 973 | ||
985 | ++timers; | 974 | ++timers; |
986 | maxfire = 20; | 975 | maxfire = 20; |
987 | tsk->it_virt_expires = cputime_zero; | 976 | tsk->cputime_expires.virt_exp = cputime_zero; |
988 | while (!list_empty(timers)) { | 977 | while (!list_empty(timers)) { |
989 | struct cpu_timer_list *t = list_first_entry(timers, | 978 | struct cpu_timer_list *t = list_first_entry(timers, |
990 | struct cpu_timer_list, | 979 | struct cpu_timer_list, |
991 | entry); | 980 | entry); |
992 | if (!--maxfire || cputime_lt(virt_ticks(tsk), t->expires.cpu)) { | 981 | if (!--maxfire || cputime_lt(virt_ticks(tsk), t->expires.cpu)) { |
993 | tsk->it_virt_expires = t->expires.cpu; | 982 | tsk->cputime_expires.virt_exp = t->expires.cpu; |
994 | break; | 983 | break; |
995 | } | 984 | } |
996 | t->firing = 1; | 985 | t->firing = 1; |
@@ -999,13 +988,13 @@ static void check_thread_timers(struct task_struct *tsk, | |||
999 | 988 | ||
1000 | ++timers; | 989 | ++timers; |
1001 | maxfire = 20; | 990 | maxfire = 20; |
1002 | tsk->it_sched_expires = 0; | 991 | tsk->cputime_expires.sched_exp = 0; |
1003 | while (!list_empty(timers)) { | 992 | while (!list_empty(timers)) { |
1004 | struct cpu_timer_list *t = list_first_entry(timers, | 993 | struct cpu_timer_list *t = list_first_entry(timers, |
1005 | struct cpu_timer_list, | 994 | struct cpu_timer_list, |
1006 | entry); | 995 | entry); |
1007 | if (!--maxfire || tsk->se.sum_exec_runtime < t->expires.sched) { | 996 | if (!--maxfire || tsk->se.sum_exec_runtime < t->expires.sched) { |
1008 | tsk->it_sched_expires = t->expires.sched; | 997 | tsk->cputime_expires.sched_exp = t->expires.sched; |
1009 | break; | 998 | break; |
1010 | } | 999 | } |
1011 | t->firing = 1; | 1000 | t->firing = 1; |
@@ -1055,10 +1044,10 @@ static void check_process_timers(struct task_struct *tsk, | |||
1055 | { | 1044 | { |
1056 | int maxfire; | 1045 | int maxfire; |
1057 | struct signal_struct *const sig = tsk->signal; | 1046 | struct signal_struct *const sig = tsk->signal; |
1058 | cputime_t utime, stime, ptime, virt_expires, prof_expires; | 1047 | cputime_t utime, ptime, virt_expires, prof_expires; |
1059 | unsigned long long sum_sched_runtime, sched_expires; | 1048 | unsigned long long sum_sched_runtime, sched_expires; |
1060 | struct task_struct *t; | ||
1061 | struct list_head *timers = sig->cpu_timers; | 1049 | struct list_head *timers = sig->cpu_timers; |
1050 | struct task_cputime cputime; | ||
1062 | 1051 | ||
1063 | /* | 1052 | /* |
1064 | * Don't sample the current process CPU clocks if there are no timers. | 1053 | * Don't sample the current process CPU clocks if there are no timers. |
@@ -1074,18 +1063,10 @@ static void check_process_timers(struct task_struct *tsk, | |||
1074 | /* | 1063 | /* |
1075 | * Collect the current process totals. | 1064 | * Collect the current process totals. |
1076 | */ | 1065 | */ |
1077 | utime = sig->utime; | 1066 | thread_group_cputime(tsk, &cputime); |
1078 | stime = sig->stime; | 1067 | utime = cputime.utime; |
1079 | sum_sched_runtime = sig->sum_sched_runtime; | 1068 | ptime = cputime_add(utime, cputime.stime); |
1080 | t = tsk; | 1069 | sum_sched_runtime = cputime.sum_exec_runtime; |
1081 | do { | ||
1082 | utime = cputime_add(utime, t->utime); | ||
1083 | stime = cputime_add(stime, t->stime); | ||
1084 | sum_sched_runtime += t->se.sum_exec_runtime; | ||
1085 | t = next_thread(t); | ||
1086 | } while (t != tsk); | ||
1087 | ptime = cputime_add(utime, stime); | ||
1088 | |||
1089 | maxfire = 20; | 1070 | maxfire = 20; |
1090 | prof_expires = cputime_zero; | 1071 | prof_expires = cputime_zero; |
1091 | while (!list_empty(timers)) { | 1072 | while (!list_empty(timers)) { |
@@ -1193,60 +1174,18 @@ static void check_process_timers(struct task_struct *tsk, | |||
1193 | } | 1174 | } |
1194 | } | 1175 | } |
1195 | 1176 | ||
1196 | if (!cputime_eq(prof_expires, cputime_zero) || | 1177 | if (!cputime_eq(prof_expires, cputime_zero) && |
1197 | !cputime_eq(virt_expires, cputime_zero) || | 1178 | (cputime_eq(sig->cputime_expires.prof_exp, cputime_zero) || |
1198 | sched_expires != 0) { | 1179 | cputime_gt(sig->cputime_expires.prof_exp, prof_expires))) |
1199 | /* | 1180 | sig->cputime_expires.prof_exp = prof_expires; |
1200 | * Rebalance the threads' expiry times for the remaining | 1181 | if (!cputime_eq(virt_expires, cputime_zero) && |
1201 | * process CPU timers. | 1182 | (cputime_eq(sig->cputime_expires.virt_exp, cputime_zero) || |
1202 | */ | 1183 | cputime_gt(sig->cputime_expires.virt_exp, virt_expires))) |
1203 | 1184 | sig->cputime_expires.virt_exp = virt_expires; | |
1204 | cputime_t prof_left, virt_left, ticks; | 1185 | if (sched_expires != 0 && |
1205 | unsigned long long sched_left, sched; | 1186 | (sig->cputime_expires.sched_exp == 0 || |
1206 | const unsigned int nthreads = atomic_read(&sig->live); | 1187 | sig->cputime_expires.sched_exp > sched_expires)) |
1207 | 1188 | sig->cputime_expires.sched_exp = sched_expires; | |
1208 | if (!nthreads) | ||
1209 | return; | ||
1210 | |||
1211 | prof_left = cputime_sub(prof_expires, utime); | ||
1212 | prof_left = cputime_sub(prof_left, stime); | ||
1213 | prof_left = cputime_div_non_zero(prof_left, nthreads); | ||
1214 | virt_left = cputime_sub(virt_expires, utime); | ||
1215 | virt_left = cputime_div_non_zero(virt_left, nthreads); | ||
1216 | if (sched_expires) { | ||
1217 | sched_left = sched_expires - sum_sched_runtime; | ||
1218 | do_div(sched_left, nthreads); | ||
1219 | sched_left = max_t(unsigned long long, sched_left, 1); | ||
1220 | } else { | ||
1221 | sched_left = 0; | ||
1222 | } | ||
1223 | t = tsk; | ||
1224 | do { | ||
1225 | if (unlikely(t->flags & PF_EXITING)) | ||
1226 | continue; | ||
1227 | |||
1228 | ticks = cputime_add(cputime_add(t->utime, t->stime), | ||
1229 | prof_left); | ||
1230 | if (!cputime_eq(prof_expires, cputime_zero) && | ||
1231 | (cputime_eq(t->it_prof_expires, cputime_zero) || | ||
1232 | cputime_gt(t->it_prof_expires, ticks))) { | ||
1233 | t->it_prof_expires = ticks; | ||
1234 | } | ||
1235 | |||
1236 | ticks = cputime_add(t->utime, virt_left); | ||
1237 | if (!cputime_eq(virt_expires, cputime_zero) && | ||
1238 | (cputime_eq(t->it_virt_expires, cputime_zero) || | ||
1239 | cputime_gt(t->it_virt_expires, ticks))) { | ||
1240 | t->it_virt_expires = ticks; | ||
1241 | } | ||
1242 | |||
1243 | sched = t->se.sum_exec_runtime + sched_left; | ||
1244 | if (sched_expires && (t->it_sched_expires == 0 || | ||
1245 | t->it_sched_expires > sched)) { | ||
1246 | t->it_sched_expires = sched; | ||
1247 | } | ||
1248 | } while ((t = next_thread(t)) != tsk); | ||
1249 | } | ||
1250 | } | 1189 | } |
1251 | 1190 | ||
1252 | /* | 1191 | /* |
@@ -1314,6 +1253,86 @@ out: | |||
1314 | ++timer->it_requeue_pending; | 1253 | ++timer->it_requeue_pending; |
1315 | } | 1254 | } |
1316 | 1255 | ||
1256 | /** | ||
1257 | * task_cputime_zero - Check a task_cputime struct for all zero fields. | ||
1258 | * | ||
1259 | * @cputime: The struct to compare. | ||
1260 | * | ||
1261 | * Checks @cputime to see if all fields are zero. Returns true if all fields | ||
1262 | * are zero, false if any field is nonzero. | ||
1263 | */ | ||
1264 | static inline int task_cputime_zero(const struct task_cputime *cputime) | ||
1265 | { | ||
1266 | if (cputime_eq(cputime->utime, cputime_zero) && | ||
1267 | cputime_eq(cputime->stime, cputime_zero) && | ||
1268 | cputime->sum_exec_runtime == 0) | ||
1269 | return 1; | ||
1270 | return 0; | ||
1271 | } | ||
1272 | |||
1273 | /** | ||
1274 | * task_cputime_expired - Compare two task_cputime entities. | ||
1275 | * | ||
1276 | * @sample: The task_cputime structure to be checked for expiration. | ||
1277 | * @expires: Expiration times, against which @sample will be checked. | ||
1278 | * | ||
1279 | * Checks @sample against @expires to see if any field of @sample has expired. | ||
1280 | * Returns true if any field of the former is greater than the corresponding | ||
1281 | * field of the latter if the latter field is set. Otherwise returns false. | ||
1282 | */ | ||
1283 | static inline int task_cputime_expired(const struct task_cputime *sample, | ||
1284 | const struct task_cputime *expires) | ||
1285 | { | ||
1286 | if (!cputime_eq(expires->utime, cputime_zero) && | ||
1287 | cputime_ge(sample->utime, expires->utime)) | ||
1288 | return 1; | ||
1289 | if (!cputime_eq(expires->stime, cputime_zero) && | ||
1290 | cputime_ge(cputime_add(sample->utime, sample->stime), | ||
1291 | expires->stime)) | ||
1292 | return 1; | ||
1293 | if (expires->sum_exec_runtime != 0 && | ||
1294 | sample->sum_exec_runtime >= expires->sum_exec_runtime) | ||
1295 | return 1; | ||
1296 | return 0; | ||
1297 | } | ||
1298 | |||
1299 | /** | ||
1300 | * fastpath_timer_check - POSIX CPU timers fast path. | ||
1301 | * | ||
1302 | * @tsk: The task (thread) being checked. | ||
1303 | * | ||
1304 | * Check the task and thread group timers. If both are zero (there are no | ||
1305 | * timers set) return false. Otherwise snapshot the task and thread group | ||
1306 | * timers and compare them with the corresponding expiration times. Return | ||
1307 | * true if a timer has expired, else return false. | ||
1308 | */ | ||
1309 | static inline int fastpath_timer_check(struct task_struct *tsk) | ||
1310 | { | ||
1311 | struct signal_struct *sig = tsk->signal; | ||
1312 | |||
1313 | if (unlikely(!sig)) | ||
1314 | return 0; | ||
1315 | |||
1316 | if (!task_cputime_zero(&tsk->cputime_expires)) { | ||
1317 | struct task_cputime task_sample = { | ||
1318 | .utime = tsk->utime, | ||
1319 | .stime = tsk->stime, | ||
1320 | .sum_exec_runtime = tsk->se.sum_exec_runtime | ||
1321 | }; | ||
1322 | |||
1323 | if (task_cputime_expired(&task_sample, &tsk->cputime_expires)) | ||
1324 | return 1; | ||
1325 | } | ||
1326 | if (!task_cputime_zero(&sig->cputime_expires)) { | ||
1327 | struct task_cputime group_sample; | ||
1328 | |||
1329 | thread_group_cputime(tsk, &group_sample); | ||
1330 | if (task_cputime_expired(&group_sample, &sig->cputime_expires)) | ||
1331 | return 1; | ||
1332 | } | ||
1333 | return 0; | ||
1334 | } | ||
1335 | |||
1317 | /* | 1336 | /* |
1318 | * This is called from the timer interrupt handler. The irq handler has | 1337 | * This is called from the timer interrupt handler. The irq handler has |
1319 | * already updated our counts. We need to check if any timers fire now. | 1338 | * already updated our counts. We need to check if any timers fire now. |
@@ -1326,42 +1345,31 @@ void run_posix_cpu_timers(struct task_struct *tsk) | |||
1326 | 1345 | ||
1327 | BUG_ON(!irqs_disabled()); | 1346 | BUG_ON(!irqs_disabled()); |
1328 | 1347 | ||
1329 | #define UNEXPIRED(clock) \ | 1348 | /* |
1330 | (cputime_eq(tsk->it_##clock##_expires, cputime_zero) || \ | 1349 | * The fast path checks that there are no expired thread or thread |
1331 | cputime_lt(clock##_ticks(tsk), tsk->it_##clock##_expires)) | 1350 | * group timers. If that's so, just return. |
1332 | 1351 | */ | |
1333 | if (UNEXPIRED(prof) && UNEXPIRED(virt) && | 1352 | if (!fastpath_timer_check(tsk)) |
1334 | (tsk->it_sched_expires == 0 || | ||
1335 | tsk->se.sum_exec_runtime < tsk->it_sched_expires)) | ||
1336 | return; | 1353 | return; |
1337 | 1354 | ||
1338 | #undef UNEXPIRED | 1355 | spin_lock(&tsk->sighand->siglock); |
1339 | |||
1340 | /* | 1356 | /* |
1341 | * Double-check with locks held. | 1357 | * Here we take off tsk->signal->cpu_timers[N] and |
1358 | * tsk->cpu_timers[N] all the timers that are firing, and | ||
1359 | * put them on the firing list. | ||
1342 | */ | 1360 | */ |
1343 | read_lock(&tasklist_lock); | 1361 | check_thread_timers(tsk, &firing); |
1344 | if (likely(tsk->signal != NULL)) { | 1362 | check_process_timers(tsk, &firing); |
1345 | spin_lock(&tsk->sighand->siglock); | ||
1346 | 1363 | ||
1347 | /* | 1364 | /* |
1348 | * Here we take off tsk->cpu_timers[N] and tsk->signal->cpu_timers[N] | 1365 | * We must release these locks before taking any timer's lock. |
1349 | * all the timers that are firing, and put them on the firing list. | 1366 | * There is a potential race with timer deletion here, as the |
1350 | */ | 1367 | * siglock now protects our private firing list. We have set |
1351 | check_thread_timers(tsk, &firing); | 1368 | * the firing flag in each timer, so that a deletion attempt |
1352 | check_process_timers(tsk, &firing); | 1369 | * that gets the timer lock before we do will give it up and |
1353 | 1370 | * spin until we've taken care of that timer below. | |
1354 | /* | 1371 | */ |
1355 | * We must release these locks before taking any timer's lock. | 1372 | spin_unlock(&tsk->sighand->siglock); |
1356 | * There is a potential race with timer deletion here, as the | ||
1357 | * siglock now protects our private firing list. We have set | ||
1358 | * the firing flag in each timer, so that a deletion attempt | ||
1359 | * that gets the timer lock before we do will give it up and | ||
1360 | * spin until we've taken care of that timer below. | ||
1361 | */ | ||
1362 | spin_unlock(&tsk->sighand->siglock); | ||
1363 | } | ||
1364 | read_unlock(&tasklist_lock); | ||
1365 | 1373 | ||
1366 | /* | 1374 | /* |
1367 | * Now that all the timers on our list have the firing flag, | 1375 | * Now that all the timers on our list have the firing flag, |
@@ -1389,10 +1397,9 @@ void run_posix_cpu_timers(struct task_struct *tsk) | |||
1389 | 1397 | ||
1390 | /* | 1398 | /* |
1391 | * Set one of the process-wide special case CPU timers. | 1399 | * Set one of the process-wide special case CPU timers. |
1392 | * The tasklist_lock and tsk->sighand->siglock must be held by the caller. | 1400 | * The tsk->sighand->siglock must be held by the caller. |
1393 | * The oldval argument is null for the RLIMIT_CPU timer, where *newval is | 1401 | * The *newval argument is relative and we update it to be absolute, *oldval |
1394 | * absolute; non-null for ITIMER_*, where *newval is relative and we update | 1402 | * is absolute and we update it to be relative. |
1395 | * it to be absolute, *oldval is absolute and we update it to be relative. | ||
1396 | */ | 1403 | */ |
1397 | void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, | 1404 | void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, |
1398 | cputime_t *newval, cputime_t *oldval) | 1405 | cputime_t *newval, cputime_t *oldval) |
@@ -1401,7 +1408,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, | |||
1401 | struct list_head *head; | 1408 | struct list_head *head; |
1402 | 1409 | ||
1403 | BUG_ON(clock_idx == CPUCLOCK_SCHED); | 1410 | BUG_ON(clock_idx == CPUCLOCK_SCHED); |
1404 | cpu_clock_sample_group_locked(clock_idx, tsk, &now); | 1411 | cpu_clock_sample_group(clock_idx, tsk, &now); |
1405 | 1412 | ||
1406 | if (oldval) { | 1413 | if (oldval) { |
1407 | if (!cputime_eq(*oldval, cputime_zero)) { | 1414 | if (!cputime_eq(*oldval, cputime_zero)) { |
@@ -1435,13 +1442,14 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, | |||
1435 | cputime_ge(list_first_entry(head, | 1442 | cputime_ge(list_first_entry(head, |
1436 | struct cpu_timer_list, entry)->expires.cpu, | 1443 | struct cpu_timer_list, entry)->expires.cpu, |
1437 | *newval)) { | 1444 | *newval)) { |
1438 | /* | 1445 | switch (clock_idx) { |
1439 | * Rejigger each thread's expiry time so that one will | 1446 | case CPUCLOCK_PROF: |
1440 | * notice before we hit the process-cumulative expiry time. | 1447 | tsk->signal->cputime_expires.prof_exp = *newval; |
1441 | */ | 1448 | break; |
1442 | union cpu_time_count expires = { .sched = 0 }; | 1449 | case CPUCLOCK_VIRT: |
1443 | expires.cpu = *newval; | 1450 | tsk->signal->cputime_expires.virt_exp = *newval; |
1444 | process_timer_rebalance(tsk, clock_idx, expires, now); | 1451 | break; |
1452 | } | ||
1445 | } | 1453 | } |
1446 | } | 1454 | } |
1447 | 1455 | ||
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index e36d5798cbff..b931d7cedbfa 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c | |||
@@ -223,6 +223,15 @@ static int posix_ktime_get_ts(clockid_t which_clock, struct timespec *tp) | |||
223 | } | 223 | } |
224 | 224 | ||
225 | /* | 225 | /* |
226 | * Get monotonic time for posix timers | ||
227 | */ | ||
228 | static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec *tp) | ||
229 | { | ||
230 | getrawmonotonic(tp); | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | /* | ||
226 | * Initialize everything, well, just everything in Posix clocks/timers ;) | 235 | * Initialize everything, well, just everything in Posix clocks/timers ;) |
227 | */ | 236 | */ |
228 | static __init int init_posix_timers(void) | 237 | static __init int init_posix_timers(void) |
@@ -235,9 +244,15 @@ static __init int init_posix_timers(void) | |||
235 | .clock_get = posix_ktime_get_ts, | 244 | .clock_get = posix_ktime_get_ts, |
236 | .clock_set = do_posix_clock_nosettime, | 245 | .clock_set = do_posix_clock_nosettime, |
237 | }; | 246 | }; |
247 | struct k_clock clock_monotonic_raw = { | ||
248 | .clock_getres = hrtimer_get_res, | ||
249 | .clock_get = posix_get_monotonic_raw, | ||
250 | .clock_set = do_posix_clock_nosettime, | ||
251 | }; | ||
238 | 252 | ||
239 | register_posix_clock(CLOCK_REALTIME, &clock_realtime); | 253 | register_posix_clock(CLOCK_REALTIME, &clock_realtime); |
240 | register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); | 254 | register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); |
255 | register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw); | ||
241 | 256 | ||
242 | posix_timers_cache = kmem_cache_create("posix_timers_cache", | 257 | posix_timers_cache = kmem_cache_create("posix_timers_cache", |
243 | sizeof (struct k_itimer), 0, SLAB_PANIC, | 258 | sizeof (struct k_itimer), 0, SLAB_PANIC, |
@@ -298,6 +313,7 @@ void do_schedule_next_timer(struct siginfo *info) | |||
298 | 313 | ||
299 | int posix_timer_event(struct k_itimer *timr, int si_private) | 314 | int posix_timer_event(struct k_itimer *timr, int si_private) |
300 | { | 315 | { |
316 | int shared, ret; | ||
301 | /* | 317 | /* |
302 | * FIXME: if ->sigq is queued we can race with | 318 | * FIXME: if ->sigq is queued we can race with |
303 | * dequeue_signal()->do_schedule_next_timer(). | 319 | * dequeue_signal()->do_schedule_next_timer(). |
@@ -311,25 +327,10 @@ int posix_timer_event(struct k_itimer *timr, int si_private) | |||
311 | */ | 327 | */ |
312 | timr->sigq->info.si_sys_private = si_private; | 328 | timr->sigq->info.si_sys_private = si_private; |
313 | 329 | ||
314 | timr->sigq->info.si_signo = timr->it_sigev_signo; | 330 | shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID); |
315 | timr->sigq->info.si_code = SI_TIMER; | 331 | ret = send_sigqueue(timr->sigq, timr->it_process, shared); |
316 | timr->sigq->info.si_tid = timr->it_id; | 332 | /* If we failed to send the signal the timer stops. */ |
317 | timr->sigq->info.si_value = timr->it_sigev_value; | 333 | return ret > 0; |
318 | |||
319 | if (timr->it_sigev_notify & SIGEV_THREAD_ID) { | ||
320 | struct task_struct *leader; | ||
321 | int ret = send_sigqueue(timr->sigq, timr->it_process, 0); | ||
322 | |||
323 | if (likely(ret >= 0)) | ||
324 | return ret; | ||
325 | |||
326 | timr->it_sigev_notify = SIGEV_SIGNAL; | ||
327 | leader = timr->it_process->group_leader; | ||
328 | put_task_struct(timr->it_process); | ||
329 | timr->it_process = leader; | ||
330 | } | ||
331 | |||
332 | return send_sigqueue(timr->sigq, timr->it_process, 1); | ||
333 | } | 334 | } |
334 | EXPORT_SYMBOL_GPL(posix_timer_event); | 335 | EXPORT_SYMBOL_GPL(posix_timer_event); |
335 | 336 | ||
@@ -441,7 +442,7 @@ static struct k_itimer * alloc_posix_timer(void) | |||
441 | return tmr; | 442 | return tmr; |
442 | if (unlikely(!(tmr->sigq = sigqueue_alloc()))) { | 443 | if (unlikely(!(tmr->sigq = sigqueue_alloc()))) { |
443 | kmem_cache_free(posix_timers_cache, tmr); | 444 | kmem_cache_free(posix_timers_cache, tmr); |
444 | tmr = NULL; | 445 | return NULL; |
445 | } | 446 | } |
446 | memset(&tmr->sigq->info, 0, sizeof(siginfo_t)); | 447 | memset(&tmr->sigq->info, 0, sizeof(siginfo_t)); |
447 | return tmr; | 448 | return tmr; |
@@ -468,11 +469,9 @@ sys_timer_create(const clockid_t which_clock, | |||
468 | struct sigevent __user *timer_event_spec, | 469 | struct sigevent __user *timer_event_spec, |
469 | timer_t __user * created_timer_id) | 470 | timer_t __user * created_timer_id) |
470 | { | 471 | { |
471 | int error = 0; | 472 | struct k_itimer *new_timer; |
472 | struct k_itimer *new_timer = NULL; | 473 | int error, new_timer_id; |
473 | int new_timer_id; | 474 | struct task_struct *process; |
474 | struct task_struct *process = NULL; | ||
475 | unsigned long flags; | ||
476 | sigevent_t event; | 475 | sigevent_t event; |
477 | int it_id_set = IT_ID_NOT_SET; | 476 | int it_id_set = IT_ID_NOT_SET; |
478 | 477 | ||
@@ -490,12 +489,11 @@ sys_timer_create(const clockid_t which_clock, | |||
490 | goto out; | 489 | goto out; |
491 | } | 490 | } |
492 | spin_lock_irq(&idr_lock); | 491 | spin_lock_irq(&idr_lock); |
493 | error = idr_get_new(&posix_timers_id, (void *) new_timer, | 492 | error = idr_get_new(&posix_timers_id, new_timer, &new_timer_id); |
494 | &new_timer_id); | ||
495 | spin_unlock_irq(&idr_lock); | 493 | spin_unlock_irq(&idr_lock); |
496 | if (error == -EAGAIN) | 494 | if (error) { |
497 | goto retry; | 495 | if (error == -EAGAIN) |
498 | else if (error) { | 496 | goto retry; |
499 | /* | 497 | /* |
500 | * Weird looking, but we return EAGAIN if the IDR is | 498 | * Weird looking, but we return EAGAIN if the IDR is |
501 | * full (proper POSIX return value for this) | 499 | * full (proper POSIX return value for this) |
@@ -526,67 +524,43 @@ sys_timer_create(const clockid_t which_clock, | |||
526 | error = -EFAULT; | 524 | error = -EFAULT; |
527 | goto out; | 525 | goto out; |
528 | } | 526 | } |
529 | new_timer->it_sigev_notify = event.sigev_notify; | 527 | rcu_read_lock(); |
530 | new_timer->it_sigev_signo = event.sigev_signo; | 528 | process = good_sigevent(&event); |
531 | new_timer->it_sigev_value = event.sigev_value; | 529 | if (process) |
532 | 530 | get_task_struct(process); | |
533 | read_lock(&tasklist_lock); | 531 | rcu_read_unlock(); |
534 | if ((process = good_sigevent(&event))) { | ||
535 | /* | ||
536 | * We may be setting up this process for another | ||
537 | * thread. It may be exiting. To catch this | ||
538 | * case the we check the PF_EXITING flag. If | ||
539 | * the flag is not set, the siglock will catch | ||
540 | * him before it is too late (in exit_itimers). | ||
541 | * | ||
542 | * The exec case is a bit more invloved but easy | ||
543 | * to code. If the process is in our thread | ||
544 | * group (and it must be or we would not allow | ||
545 | * it here) and is doing an exec, it will cause | ||
546 | * us to be killed. In this case it will wait | ||
547 | * for us to die which means we can finish this | ||
548 | * linkage with our last gasp. I.e. no code :) | ||
549 | */ | ||
550 | spin_lock_irqsave(&process->sighand->siglock, flags); | ||
551 | if (!(process->flags & PF_EXITING)) { | ||
552 | new_timer->it_process = process; | ||
553 | list_add(&new_timer->list, | ||
554 | &process->signal->posix_timers); | ||
555 | if (new_timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) | ||
556 | get_task_struct(process); | ||
557 | spin_unlock_irqrestore(&process->sighand->siglock, flags); | ||
558 | } else { | ||
559 | spin_unlock_irqrestore(&process->sighand->siglock, flags); | ||
560 | process = NULL; | ||
561 | } | ||
562 | } | ||
563 | read_unlock(&tasklist_lock); | ||
564 | if (!process) { | 532 | if (!process) { |
565 | error = -EINVAL; | 533 | error = -EINVAL; |
566 | goto out; | 534 | goto out; |
567 | } | 535 | } |
568 | } else { | 536 | } else { |
569 | new_timer->it_sigev_notify = SIGEV_SIGNAL; | 537 | event.sigev_notify = SIGEV_SIGNAL; |
570 | new_timer->it_sigev_signo = SIGALRM; | 538 | event.sigev_signo = SIGALRM; |
571 | new_timer->it_sigev_value.sival_int = new_timer->it_id; | 539 | event.sigev_value.sival_int = new_timer->it_id; |
572 | process = current->group_leader; | 540 | process = current->group_leader; |
573 | spin_lock_irqsave(&process->sighand->siglock, flags); | 541 | get_task_struct(process); |
574 | new_timer->it_process = process; | ||
575 | list_add(&new_timer->list, &process->signal->posix_timers); | ||
576 | spin_unlock_irqrestore(&process->sighand->siglock, flags); | ||
577 | } | 542 | } |
578 | 543 | ||
544 | new_timer->it_sigev_notify = event.sigev_notify; | ||
545 | new_timer->sigq->info.si_signo = event.sigev_signo; | ||
546 | new_timer->sigq->info.si_value = event.sigev_value; | ||
547 | new_timer->sigq->info.si_tid = new_timer->it_id; | ||
548 | new_timer->sigq->info.si_code = SI_TIMER; | ||
549 | |||
550 | spin_lock_irq(¤t->sighand->siglock); | ||
551 | new_timer->it_process = process; | ||
552 | list_add(&new_timer->list, ¤t->signal->posix_timers); | ||
553 | spin_unlock_irq(¤t->sighand->siglock); | ||
554 | |||
555 | return 0; | ||
579 | /* | 556 | /* |
580 | * In the case of the timer belonging to another task, after | 557 | * In the case of the timer belonging to another task, after |
581 | * the task is unlocked, the timer is owned by the other task | 558 | * the task is unlocked, the timer is owned by the other task |
582 | * and may cease to exist at any time. Don't use or modify | 559 | * and may cease to exist at any time. Don't use or modify |
583 | * new_timer after the unlock call. | 560 | * new_timer after the unlock call. |
584 | */ | 561 | */ |
585 | |||
586 | out: | 562 | out: |
587 | if (error) | 563 | release_posix_timer(new_timer, it_id_set); |
588 | release_posix_timer(new_timer, it_id_set); | ||
589 | |||
590 | return error; | 564 | return error; |
591 | } | 565 | } |
592 | 566 | ||
@@ -597,7 +571,7 @@ out: | |||
597 | * the find to the timer lock. To avoid a dead lock, the timer id MUST | 571 | * the find to the timer lock. To avoid a dead lock, the timer id MUST |
598 | * be release with out holding the timer lock. | 572 | * be release with out holding the timer lock. |
599 | */ | 573 | */ |
600 | static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags) | 574 | static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags) |
601 | { | 575 | { |
602 | struct k_itimer *timr; | 576 | struct k_itimer *timr; |
603 | /* | 577 | /* |
@@ -605,23 +579,20 @@ static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags) | |||
605 | * flags part over to the timer lock. Must not let interrupts in | 579 | * flags part over to the timer lock. Must not let interrupts in |
606 | * while we are moving the lock. | 580 | * while we are moving the lock. |
607 | */ | 581 | */ |
608 | |||
609 | spin_lock_irqsave(&idr_lock, *flags); | 582 | spin_lock_irqsave(&idr_lock, *flags); |
610 | timr = (struct k_itimer *) idr_find(&posix_timers_id, (int) timer_id); | 583 | timr = idr_find(&posix_timers_id, (int)timer_id); |
611 | if (timr) { | 584 | if (timr) { |
612 | spin_lock(&timr->it_lock); | 585 | spin_lock(&timr->it_lock); |
613 | 586 | if (timr->it_process && | |
614 | if ((timr->it_id != timer_id) || !(timr->it_process) || | 587 | same_thread_group(timr->it_process, current)) { |
615 | !same_thread_group(timr->it_process, current)) { | ||
616 | spin_unlock(&timr->it_lock); | ||
617 | spin_unlock_irqrestore(&idr_lock, *flags); | ||
618 | timr = NULL; | ||
619 | } else | ||
620 | spin_unlock(&idr_lock); | 588 | spin_unlock(&idr_lock); |
621 | } else | 589 | return timr; |
622 | spin_unlock_irqrestore(&idr_lock, *flags); | 590 | } |
591 | spin_unlock(&timr->it_lock); | ||
592 | } | ||
593 | spin_unlock_irqrestore(&idr_lock, *flags); | ||
623 | 594 | ||
624 | return timr; | 595 | return NULL; |
625 | } | 596 | } |
626 | 597 | ||
627 | /* | 598 | /* |
@@ -862,8 +833,7 @@ retry_delete: | |||
862 | * This keeps any tasks waiting on the spin lock from thinking | 833 | * This keeps any tasks waiting on the spin lock from thinking |
863 | * they got something (see the lock code above). | 834 | * they got something (see the lock code above). |
864 | */ | 835 | */ |
865 | if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) | 836 | put_task_struct(timer->it_process); |
866 | put_task_struct(timer->it_process); | ||
867 | timer->it_process = NULL; | 837 | timer->it_process = NULL; |
868 | 838 | ||
869 | unlock_timer(timer, flags); | 839 | unlock_timer(timer, flags); |
@@ -890,8 +860,7 @@ retry_delete: | |||
890 | * This keeps any tasks waiting on the spin lock from thinking | 860 | * This keeps any tasks waiting on the spin lock from thinking |
891 | * they got something (see the lock code above). | 861 | * they got something (see the lock code above). |
892 | */ | 862 | */ |
893 | if (timer->it_sigev_notify == (SIGEV_SIGNAL|SIGEV_THREAD_ID)) | 863 | put_task_struct(timer->it_process); |
894 | put_task_struct(timer->it_process); | ||
895 | timer->it_process = NULL; | 864 | timer->it_process = NULL; |
896 | 865 | ||
897 | unlock_timer(timer, flags); | 866 | unlock_timer(timer, flags); |
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index f011e0870b52..331f9836383f 100644 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/reboot.h> | 14 | #include <linux/reboot.h> |
15 | #include <linux/string.h> | 15 | #include <linux/string.h> |
16 | #include <linux/device.h> | 16 | #include <linux/device.h> |
17 | #include <linux/kmod.h> | ||
17 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
18 | #include <linux/fs.h> | 19 | #include <linux/fs.h> |
19 | #include <linux/mount.h> | 20 | #include <linux/mount.h> |
@@ -21,6 +22,7 @@ | |||
21 | #include <linux/console.h> | 22 | #include <linux/console.h> |
22 | #include <linux/cpu.h> | 23 | #include <linux/cpu.h> |
23 | #include <linux/freezer.h> | 24 | #include <linux/freezer.h> |
25 | #include <linux/ftrace.h> | ||
24 | 26 | ||
25 | #include "power.h" | 27 | #include "power.h" |
26 | 28 | ||
@@ -255,7 +257,7 @@ static int create_image(int platform_mode) | |||
255 | 257 | ||
256 | int hibernation_snapshot(int platform_mode) | 258 | int hibernation_snapshot(int platform_mode) |
257 | { | 259 | { |
258 | int error; | 260 | int error, ftrace_save; |
259 | 261 | ||
260 | /* Free memory before shutting down devices. */ | 262 | /* Free memory before shutting down devices. */ |
261 | error = swsusp_shrink_memory(); | 263 | error = swsusp_shrink_memory(); |
@@ -267,6 +269,7 @@ int hibernation_snapshot(int platform_mode) | |||
267 | goto Close; | 269 | goto Close; |
268 | 270 | ||
269 | suspend_console(); | 271 | suspend_console(); |
272 | ftrace_save = __ftrace_enabled_save(); | ||
270 | error = device_suspend(PMSG_FREEZE); | 273 | error = device_suspend(PMSG_FREEZE); |
271 | if (error) | 274 | if (error) |
272 | goto Recover_platform; | 275 | goto Recover_platform; |
@@ -296,6 +299,7 @@ int hibernation_snapshot(int platform_mode) | |||
296 | Resume_devices: | 299 | Resume_devices: |
297 | device_resume(in_suspend ? | 300 | device_resume(in_suspend ? |
298 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); | 301 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); |
302 | __ftrace_enabled_restore(ftrace_save); | ||
299 | resume_console(); | 303 | resume_console(); |
300 | Close: | 304 | Close: |
301 | platform_end(platform_mode); | 305 | platform_end(platform_mode); |
@@ -366,10 +370,11 @@ static int resume_target_kernel(void) | |||
366 | 370 | ||
367 | int hibernation_restore(int platform_mode) | 371 | int hibernation_restore(int platform_mode) |
368 | { | 372 | { |
369 | int error; | 373 | int error, ftrace_save; |
370 | 374 | ||
371 | pm_prepare_console(); | 375 | pm_prepare_console(); |
372 | suspend_console(); | 376 | suspend_console(); |
377 | ftrace_save = __ftrace_enabled_save(); | ||
373 | error = device_suspend(PMSG_QUIESCE); | 378 | error = device_suspend(PMSG_QUIESCE); |
374 | if (error) | 379 | if (error) |
375 | goto Finish; | 380 | goto Finish; |
@@ -384,6 +389,7 @@ int hibernation_restore(int platform_mode) | |||
384 | platform_restore_cleanup(platform_mode); | 389 | platform_restore_cleanup(platform_mode); |
385 | device_resume(PMSG_RECOVER); | 390 | device_resume(PMSG_RECOVER); |
386 | Finish: | 391 | Finish: |
392 | __ftrace_enabled_restore(ftrace_save); | ||
387 | resume_console(); | 393 | resume_console(); |
388 | pm_restore_console(); | 394 | pm_restore_console(); |
389 | return error; | 395 | return error; |
@@ -396,7 +402,7 @@ int hibernation_restore(int platform_mode) | |||
396 | 402 | ||
397 | int hibernation_platform_enter(void) | 403 | int hibernation_platform_enter(void) |
398 | { | 404 | { |
399 | int error; | 405 | int error, ftrace_save; |
400 | 406 | ||
401 | if (!hibernation_ops) | 407 | if (!hibernation_ops) |
402 | return -ENOSYS; | 408 | return -ENOSYS; |
@@ -411,6 +417,7 @@ int hibernation_platform_enter(void) | |||
411 | goto Close; | 417 | goto Close; |
412 | 418 | ||
413 | suspend_console(); | 419 | suspend_console(); |
420 | ftrace_save = __ftrace_enabled_save(); | ||
414 | error = device_suspend(PMSG_HIBERNATE); | 421 | error = device_suspend(PMSG_HIBERNATE); |
415 | if (error) { | 422 | if (error) { |
416 | if (hibernation_ops->recover) | 423 | if (hibernation_ops->recover) |
@@ -445,6 +452,7 @@ int hibernation_platform_enter(void) | |||
445 | hibernation_ops->finish(); | 452 | hibernation_ops->finish(); |
446 | Resume_devices: | 453 | Resume_devices: |
447 | device_resume(PMSG_RESTORE); | 454 | device_resume(PMSG_RESTORE); |
455 | __ftrace_enabled_restore(ftrace_save); | ||
448 | resume_console(); | 456 | resume_console(); |
449 | Close: | 457 | Close: |
450 | hibernation_ops->end(); | 458 | hibernation_ops->end(); |
@@ -513,6 +521,10 @@ int hibernate(void) | |||
513 | if (error) | 521 | if (error) |
514 | goto Exit; | 522 | goto Exit; |
515 | 523 | ||
524 | error = usermodehelper_disable(); | ||
525 | if (error) | ||
526 | goto Exit; | ||
527 | |||
516 | /* Allocate memory management structures */ | 528 | /* Allocate memory management structures */ |
517 | error = create_basic_memory_bitmaps(); | 529 | error = create_basic_memory_bitmaps(); |
518 | if (error) | 530 | if (error) |
@@ -551,6 +563,7 @@ int hibernate(void) | |||
551 | thaw_processes(); | 563 | thaw_processes(); |
552 | Finish: | 564 | Finish: |
553 | free_basic_memory_bitmaps(); | 565 | free_basic_memory_bitmaps(); |
566 | usermodehelper_enable(); | ||
554 | Exit: | 567 | Exit: |
555 | pm_notifier_call_chain(PM_POST_HIBERNATION); | 568 | pm_notifier_call_chain(PM_POST_HIBERNATION); |
556 | pm_restore_console(); | 569 | pm_restore_console(); |
@@ -627,6 +640,10 @@ static int software_resume(void) | |||
627 | if (error) | 640 | if (error) |
628 | goto Finish; | 641 | goto Finish; |
629 | 642 | ||
643 | error = usermodehelper_disable(); | ||
644 | if (error) | ||
645 | goto Finish; | ||
646 | |||
630 | error = create_basic_memory_bitmaps(); | 647 | error = create_basic_memory_bitmaps(); |
631 | if (error) | 648 | if (error) |
632 | goto Finish; | 649 | goto Finish; |
@@ -649,6 +666,7 @@ static int software_resume(void) | |||
649 | thaw_processes(); | 666 | thaw_processes(); |
650 | Done: | 667 | Done: |
651 | free_basic_memory_bitmaps(); | 668 | free_basic_memory_bitmaps(); |
669 | usermodehelper_enable(); | ||
652 | Finish: | 670 | Finish: |
653 | pm_notifier_call_chain(PM_POST_RESTORE); | 671 | pm_notifier_call_chain(PM_POST_RESTORE); |
654 | pm_restore_console(); | 672 | pm_restore_console(); |
diff --git a/kernel/power/main.c b/kernel/power/main.c index 0b7476f5d2a6..19122cf6d827 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/string.h> | 14 | #include <linux/string.h> |
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
17 | #include <linux/kmod.h> | ||
17 | #include <linux/init.h> | 18 | #include <linux/init.h> |
18 | #include <linux/console.h> | 19 | #include <linux/console.h> |
19 | #include <linux/cpu.h> | 20 | #include <linux/cpu.h> |
@@ -21,6 +22,7 @@ | |||
21 | #include <linux/freezer.h> | 22 | #include <linux/freezer.h> |
22 | #include <linux/vmstat.h> | 23 | #include <linux/vmstat.h> |
23 | #include <linux/syscalls.h> | 24 | #include <linux/syscalls.h> |
25 | #include <linux/ftrace.h> | ||
24 | 26 | ||
25 | #include "power.h" | 27 | #include "power.h" |
26 | 28 | ||
@@ -236,6 +238,10 @@ static int suspend_prepare(void) | |||
236 | if (error) | 238 | if (error) |
237 | goto Finish; | 239 | goto Finish; |
238 | 240 | ||
241 | error = usermodehelper_disable(); | ||
242 | if (error) | ||
243 | goto Finish; | ||
244 | |||
239 | if (suspend_freeze_processes()) { | 245 | if (suspend_freeze_processes()) { |
240 | error = -EAGAIN; | 246 | error = -EAGAIN; |
241 | goto Thaw; | 247 | goto Thaw; |
@@ -255,6 +261,7 @@ static int suspend_prepare(void) | |||
255 | 261 | ||
256 | Thaw: | 262 | Thaw: |
257 | suspend_thaw_processes(); | 263 | suspend_thaw_processes(); |
264 | usermodehelper_enable(); | ||
258 | Finish: | 265 | Finish: |
259 | pm_notifier_call_chain(PM_POST_SUSPEND); | 266 | pm_notifier_call_chain(PM_POST_SUSPEND); |
260 | pm_restore_console(); | 267 | pm_restore_console(); |
@@ -310,7 +317,7 @@ static int suspend_enter(suspend_state_t state) | |||
310 | */ | 317 | */ |
311 | int suspend_devices_and_enter(suspend_state_t state) | 318 | int suspend_devices_and_enter(suspend_state_t state) |
312 | { | 319 | { |
313 | int error; | 320 | int error, ftrace_save; |
314 | 321 | ||
315 | if (!suspend_ops) | 322 | if (!suspend_ops) |
316 | return -ENOSYS; | 323 | return -ENOSYS; |
@@ -321,6 +328,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
321 | goto Close; | 328 | goto Close; |
322 | } | 329 | } |
323 | suspend_console(); | 330 | suspend_console(); |
331 | ftrace_save = __ftrace_enabled_save(); | ||
324 | suspend_test_start(); | 332 | suspend_test_start(); |
325 | error = device_suspend(PMSG_SUSPEND); | 333 | error = device_suspend(PMSG_SUSPEND); |
326 | if (error) { | 334 | if (error) { |
@@ -352,6 +360,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
352 | suspend_test_start(); | 360 | suspend_test_start(); |
353 | device_resume(PMSG_RESUME); | 361 | device_resume(PMSG_RESUME); |
354 | suspend_test_finish("resume devices"); | 362 | suspend_test_finish("resume devices"); |
363 | __ftrace_enabled_restore(ftrace_save); | ||
355 | resume_console(); | 364 | resume_console(); |
356 | Close: | 365 | Close: |
357 | if (suspend_ops->end) | 366 | if (suspend_ops->end) |
@@ -373,6 +382,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
373 | static void suspend_finish(void) | 382 | static void suspend_finish(void) |
374 | { | 383 | { |
375 | suspend_thaw_processes(); | 384 | suspend_thaw_processes(); |
385 | usermodehelper_enable(); | ||
376 | pm_notifier_call_chain(PM_POST_SUSPEND); | 386 | pm_notifier_call_chain(PM_POST_SUSPEND); |
377 | pm_restore_console(); | 387 | pm_restore_console(); |
378 | } | 388 | } |
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/power/user.c b/kernel/power/user.c index a6332a313262..005b93d839ba 100644 --- a/kernel/power/user.c +++ b/kernel/power/user.c | |||
@@ -212,13 +212,20 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, | |||
212 | case SNAPSHOT_FREEZE: | 212 | case SNAPSHOT_FREEZE: |
213 | if (data->frozen) | 213 | if (data->frozen) |
214 | break; | 214 | break; |
215 | |||
215 | printk("Syncing filesystems ... "); | 216 | printk("Syncing filesystems ... "); |
216 | sys_sync(); | 217 | sys_sync(); |
217 | printk("done.\n"); | 218 | printk("done.\n"); |
218 | 219 | ||
219 | error = freeze_processes(); | 220 | error = usermodehelper_disable(); |
220 | if (error) | 221 | if (error) |
222 | break; | ||
223 | |||
224 | error = freeze_processes(); | ||
225 | if (error) { | ||
221 | thaw_processes(); | 226 | thaw_processes(); |
227 | usermodehelper_enable(); | ||
228 | } | ||
222 | if (!error) | 229 | if (!error) |
223 | data->frozen = 1; | 230 | data->frozen = 1; |
224 | break; | 231 | break; |
@@ -227,6 +234,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, | |||
227 | if (!data->frozen || data->ready) | 234 | if (!data->frozen || data->ready) |
228 | break; | 235 | break; |
229 | thaw_processes(); | 236 | thaw_processes(); |
237 | usermodehelper_enable(); | ||
230 | data->frozen = 0; | 238 | data->frozen = 0; |
231 | break; | 239 | break; |
232 | 240 | ||
diff --git a/kernel/printk.c b/kernel/printk.c index b51b1567bb55..6341af77eb65 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -13,7 +13,7 @@ | |||
13 | * Fixed SMP synchronization, 08/08/99, Manfred Spraul | 13 | * Fixed SMP synchronization, 08/08/99, Manfred Spraul |
14 | * manfred@colorfullife.com | 14 | * manfred@colorfullife.com |
15 | * Rewrote bits to get rid of console_lock | 15 | * Rewrote bits to get rid of console_lock |
16 | * 01Mar01 Andrew Morton <andrewm@uow.edu.au> | 16 | * 01Mar01 Andrew Morton |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
@@ -577,9 +577,6 @@ static int have_callable_console(void) | |||
577 | * @fmt: format string | 577 | * @fmt: format string |
578 | * | 578 | * |
579 | * This is printk(). It can be called from any context. We want it to work. | 579 | * This is printk(). It can be called from any context. We want it to work. |
580 | * Be aware of the fact that if oops_in_progress is not set, we might try to | ||
581 | * wake klogd up which could deadlock on runqueue lock if printk() is called | ||
582 | * from scheduler code. | ||
583 | * | 580 | * |
584 | * We try to grab the console_sem. If we succeed, it's easy - we log the output and | 581 | * We try to grab the console_sem. If we succeed, it's easy - we log the output and |
585 | * call the console drivers. If we fail to get the semaphore we place the output | 582 | * call the console drivers. If we fail to get the semaphore we place the output |
@@ -593,6 +590,8 @@ static int have_callable_console(void) | |||
593 | * | 590 | * |
594 | * See also: | 591 | * See also: |
595 | * printf(3) | 592 | * printf(3) |
593 | * | ||
594 | * See the vsnprintf() documentation for format string extensions over C99. | ||
596 | */ | 595 | */ |
597 | 596 | ||
598 | asmlinkage int printk(const char *fmt, ...) | 597 | asmlinkage int printk(const char *fmt, ...) |
@@ -982,10 +981,25 @@ int is_console_locked(void) | |||
982 | return console_locked; | 981 | return console_locked; |
983 | } | 982 | } |
984 | 983 | ||
985 | void wake_up_klogd(void) | 984 | static DEFINE_PER_CPU(int, printk_pending); |
985 | |||
986 | void printk_tick(void) | ||
986 | { | 987 | { |
987 | if (!oops_in_progress && waitqueue_active(&log_wait)) | 988 | if (__get_cpu_var(printk_pending)) { |
989 | __get_cpu_var(printk_pending) = 0; | ||
988 | wake_up_interruptible(&log_wait); | 990 | wake_up_interruptible(&log_wait); |
991 | } | ||
992 | } | ||
993 | |||
994 | int printk_needs_cpu(int cpu) | ||
995 | { | ||
996 | return per_cpu(printk_pending, cpu); | ||
997 | } | ||
998 | |||
999 | void wake_up_klogd(void) | ||
1000 | { | ||
1001 | if (waitqueue_active(&log_wait)) | ||
1002 | __raw_get_cpu_var(printk_pending) = 1; | ||
989 | } | 1003 | } |
990 | 1004 | ||
991 | /** | 1005 | /** |
@@ -1291,22 +1305,6 @@ static int __init disable_boot_consoles(void) | |||
1291 | } | 1305 | } |
1292 | late_initcall(disable_boot_consoles); | 1306 | late_initcall(disable_boot_consoles); |
1293 | 1307 | ||
1294 | /** | ||
1295 | * tty_write_message - write a message to a certain tty, not just the console. | ||
1296 | * @tty: the destination tty_struct | ||
1297 | * @msg: the message to write | ||
1298 | * | ||
1299 | * This is used for messages that need to be redirected to a specific tty. | ||
1300 | * We don't put it into the syslog queue right now maybe in the future if | ||
1301 | * really needed. | ||
1302 | */ | ||
1303 | void tty_write_message(struct tty_struct *tty, char *msg) | ||
1304 | { | ||
1305 | if (tty && tty->ops->write) | ||
1306 | tty->ops->write(tty, msg, strlen(msg)); | ||
1307 | return; | ||
1308 | } | ||
1309 | |||
1310 | #if defined CONFIG_PRINTK | 1308 | #if defined CONFIG_PRINTK |
1311 | 1309 | ||
1312 | /* | 1310 | /* |
diff --git a/kernel/profile.c b/kernel/profile.c index cd26bed4cc26..a9e422df6bf6 100644 --- a/kernel/profile.c +++ b/kernel/profile.c | |||
@@ -22,6 +22,8 @@ | |||
22 | #include <linux/cpu.h> | 22 | #include <linux/cpu.h> |
23 | #include <linux/highmem.h> | 23 | #include <linux/highmem.h> |
24 | #include <linux/mutex.h> | 24 | #include <linux/mutex.h> |
25 | #include <linux/slab.h> | ||
26 | #include <linux/vmalloc.h> | ||
25 | #include <asm/sections.h> | 27 | #include <asm/sections.h> |
26 | #include <asm/irq_regs.h> | 28 | #include <asm/irq_regs.h> |
27 | #include <asm/ptrace.h> | 29 | #include <asm/ptrace.h> |
@@ -50,11 +52,11 @@ static DEFINE_PER_CPU(int, cpu_profile_flip); | |||
50 | static DEFINE_MUTEX(profile_flip_mutex); | 52 | static DEFINE_MUTEX(profile_flip_mutex); |
51 | #endif /* CONFIG_SMP */ | 53 | #endif /* CONFIG_SMP */ |
52 | 54 | ||
53 | static int __init profile_setup(char *str) | 55 | int profile_setup(char *str) |
54 | { | 56 | { |
55 | static char __initdata schedstr[] = "schedule"; | 57 | static char schedstr[] = "schedule"; |
56 | static char __initdata sleepstr[] = "sleep"; | 58 | static char sleepstr[] = "sleep"; |
57 | static char __initdata kvmstr[] = "kvm"; | 59 | static char kvmstr[] = "kvm"; |
58 | int par; | 60 | int par; |
59 | 61 | ||
60 | if (!strncmp(str, sleepstr, strlen(sleepstr))) { | 62 | if (!strncmp(str, sleepstr, strlen(sleepstr))) { |
@@ -100,14 +102,33 @@ static int __init profile_setup(char *str) | |||
100 | __setup("profile=", profile_setup); | 102 | __setup("profile=", profile_setup); |
101 | 103 | ||
102 | 104 | ||
103 | void __init profile_init(void) | 105 | int profile_init(void) |
104 | { | 106 | { |
107 | int buffer_bytes; | ||
105 | if (!prof_on) | 108 | if (!prof_on) |
106 | return; | 109 | return 0; |
107 | 110 | ||
108 | /* only text is profiled */ | 111 | /* only text is profiled */ |
109 | prof_len = (_etext - _stext) >> prof_shift; | 112 | prof_len = (_etext - _stext) >> prof_shift; |
110 | prof_buffer = alloc_bootmem(prof_len*sizeof(atomic_t)); | 113 | buffer_bytes = prof_len*sizeof(atomic_t); |
114 | if (!slab_is_available()) { | ||
115 | prof_buffer = alloc_bootmem(buffer_bytes); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL); | ||
120 | if (prof_buffer) | ||
121 | return 0; | ||
122 | |||
123 | prof_buffer = alloc_pages_exact(buffer_bytes, GFP_KERNEL|__GFP_ZERO); | ||
124 | if (prof_buffer) | ||
125 | return 0; | ||
126 | |||
127 | prof_buffer = vmalloc(buffer_bytes); | ||
128 | if (prof_buffer) | ||
129 | return 0; | ||
130 | |||
131 | return -ENOMEM; | ||
111 | } | 132 | } |
112 | 133 | ||
113 | /* Profile event notifications */ | 134 | /* Profile event notifications */ |
@@ -527,7 +548,7 @@ static void __init profile_nop(void *unused) | |||
527 | { | 548 | { |
528 | } | 549 | } |
529 | 550 | ||
530 | static int __init create_hash_tables(void) | 551 | static int create_hash_tables(void) |
531 | { | 552 | { |
532 | int cpu; | 553 | int cpu; |
533 | 554 | ||
@@ -575,14 +596,14 @@ out_cleanup: | |||
575 | #define create_hash_tables() ({ 0; }) | 596 | #define create_hash_tables() ({ 0; }) |
576 | #endif | 597 | #endif |
577 | 598 | ||
578 | static int __init create_proc_profile(void) | 599 | int create_proc_profile(void) |
579 | { | 600 | { |
580 | struct proc_dir_entry *entry; | 601 | struct proc_dir_entry *entry; |
581 | 602 | ||
582 | if (!prof_on) | 603 | if (!prof_on) |
583 | return 0; | 604 | return 0; |
584 | if (create_hash_tables()) | 605 | if (create_hash_tables()) |
585 | return -1; | 606 | return -ENOMEM; |
586 | entry = proc_create("profile", S_IWUSR | S_IRUGO, | 607 | entry = proc_create("profile", S_IWUSR | S_IRUGO, |
587 | NULL, &proc_profile_operations); | 608 | NULL, &proc_profile_operations); |
588 | if (!entry) | 609 | if (!entry) |
diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c index aad93cdc9f68..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 | /* |
@@ -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/resource.c b/kernel/resource.c index f5b518eabefe..4089d12af6e0 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
@@ -38,10 +38,6 @@ EXPORT_SYMBOL(iomem_resource); | |||
38 | 38 | ||
39 | static DEFINE_RWLOCK(resource_lock); | 39 | static DEFINE_RWLOCK(resource_lock); |
40 | 40 | ||
41 | #ifdef CONFIG_PROC_FS | ||
42 | |||
43 | enum { MAX_IORES_LEVEL = 5 }; | ||
44 | |||
45 | static void *r_next(struct seq_file *m, void *v, loff_t *pos) | 41 | static void *r_next(struct seq_file *m, void *v, loff_t *pos) |
46 | { | 42 | { |
47 | struct resource *p = v; | 43 | struct resource *p = v; |
@@ -53,6 +49,10 @@ static void *r_next(struct seq_file *m, void *v, loff_t *pos) | |||
53 | return p->sibling; | 49 | return p->sibling; |
54 | } | 50 | } |
55 | 51 | ||
52 | #ifdef CONFIG_PROC_FS | ||
53 | |||
54 | enum { MAX_IORES_LEVEL = 5 }; | ||
55 | |||
56 | static void *r_start(struct seq_file *m, loff_t *pos) | 56 | static void *r_start(struct seq_file *m, loff_t *pos) |
57 | __acquires(resource_lock) | 57 | __acquires(resource_lock) |
58 | { | 58 | { |
@@ -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,70 @@ 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 | /* failed, split and try again */ | ||
553 | |||
554 | /* conflict covered whole area */ | ||
555 | if (conflict->start <= start && conflict->end >= end) | ||
556 | return; | ||
557 | |||
558 | if (conflict->start > start) | ||
559 | __reserve_region_with_split(root, start, conflict->start-1, name); | ||
560 | if (!(conflict->flags & IORESOURCE_BUSY)) { | ||
561 | resource_size_t common_start, common_end; | ||
562 | |||
563 | common_start = max(conflict->start, start); | ||
564 | common_end = min(conflict->end, end); | ||
565 | if (common_start < common_end) | ||
566 | __reserve_region_with_split(root, common_start, common_end, name); | ||
567 | } | ||
568 | if (conflict->end < end) | ||
569 | __reserve_region_with_split(root, conflict->end+1, end, name); | ||
570 | } | ||
571 | |||
572 | } | ||
573 | |||
574 | void reserve_region_with_split(struct resource *root, | ||
575 | resource_size_t start, resource_size_t end, | ||
576 | const char *name) | ||
577 | { | ||
578 | write_lock(&resource_lock); | ||
579 | __reserve_region_with_split(root, start, end, name); | ||
580 | write_unlock(&resource_lock); | ||
581 | } | ||
582 | |||
481 | EXPORT_SYMBOL(adjust_resource); | 583 | EXPORT_SYMBOL(adjust_resource); |
482 | 584 | ||
483 | /** | 585 | /** |
@@ -524,33 +626,34 @@ struct resource * __request_region(struct resource *parent, | |||
524 | { | 626 | { |
525 | struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL); | 627 | struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL); |
526 | 628 | ||
527 | if (res) { | 629 | if (!res) |
528 | res->name = name; | 630 | return NULL; |
529 | res->start = start; | ||
530 | res->end = start + n - 1; | ||
531 | res->flags = IORESOURCE_BUSY; | ||
532 | 631 | ||
533 | write_lock(&resource_lock); | 632 | res->name = name; |
633 | res->start = start; | ||
634 | res->end = start + n - 1; | ||
635 | res->flags = IORESOURCE_BUSY; | ||
534 | 636 | ||
535 | for (;;) { | 637 | write_lock(&resource_lock); |
536 | struct resource *conflict; | ||
537 | 638 | ||
538 | conflict = __request_resource(parent, res); | 639 | for (;;) { |
539 | if (!conflict) | 640 | struct resource *conflict; |
540 | break; | ||
541 | if (conflict != parent) { | ||
542 | parent = conflict; | ||
543 | if (!(conflict->flags & IORESOURCE_BUSY)) | ||
544 | continue; | ||
545 | } | ||
546 | 641 | ||
547 | /* Uhhuh, that didn't work out.. */ | 642 | conflict = __request_resource(parent, res); |
548 | kfree(res); | 643 | if (!conflict) |
549 | res = NULL; | ||
550 | break; | 644 | break; |
645 | if (conflict != parent) { | ||
646 | parent = conflict; | ||
647 | if (!(conflict->flags & IORESOURCE_BUSY)) | ||
648 | continue; | ||
551 | } | 649 | } |
552 | write_unlock(&resource_lock); | 650 | |
651 | /* Uhhuh, that didn't work out.. */ | ||
652 | kfree(res); | ||
653 | res = NULL; | ||
654 | break; | ||
553 | } | 655 | } |
656 | write_unlock(&resource_lock); | ||
554 | return res; | 657 | return res; |
555 | } | 658 | } |
556 | EXPORT_SYMBOL(__request_region); | 659 | EXPORT_SYMBOL(__request_region); |
@@ -725,3 +828,40 @@ static int __init reserve_setup(char *str) | |||
725 | } | 828 | } |
726 | 829 | ||
727 | __setup("reserve=", reserve_setup); | 830 | __setup("reserve=", reserve_setup); |
831 | |||
832 | /* | ||
833 | * Check if the requested addr and size spans more than any slot in the | ||
834 | * iomem resource tree. | ||
835 | */ | ||
836 | int iomem_map_sanity_check(resource_size_t addr, unsigned long size) | ||
837 | { | ||
838 | struct resource *p = &iomem_resource; | ||
839 | int err = 0; | ||
840 | loff_t l; | ||
841 | |||
842 | read_lock(&resource_lock); | ||
843 | for (p = p->child; p ; p = r_next(NULL, p, &l)) { | ||
844 | /* | ||
845 | * We can probably skip the resources without | ||
846 | * IORESOURCE_IO attribute? | ||
847 | */ | ||
848 | if (p->start >= addr + size) | ||
849 | continue; | ||
850 | if (p->end < addr) | ||
851 | continue; | ||
852 | if (p->start <= addr && (p->end >= addr + size - 1)) | ||
853 | continue; | ||
854 | printk(KERN_WARNING "resource map sanity check conflict: " | ||
855 | "0x%llx 0x%llx 0x%llx 0x%llx %s\n", | ||
856 | (unsigned long long)addr, | ||
857 | (unsigned long long)(addr + size - 1), | ||
858 | (unsigned long long)p->start, | ||
859 | (unsigned long long)p->end, | ||
860 | p->name); | ||
861 | err = -1; | ||
862 | break; | ||
863 | } | ||
864 | read_unlock(&resource_lock); | ||
865 | |||
866 | return err; | ||
867 | } | ||
diff --git a/kernel/sched.c b/kernel/sched.c index 9a1ddb84e26d..09a8c15748f1 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. |
@@ -604,9 +609,9 @@ struct rq { | |||
604 | 609 | ||
605 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); | 610 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); |
606 | 611 | ||
607 | 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) |
608 | { | 613 | { |
609 | rq->curr->sched_class->check_preempt_curr(rq, p); | 614 | rq->curr->sched_class->check_preempt_curr(rq, p, sync); |
610 | } | 615 | } |
611 | 616 | ||
612 | static inline int cpu_of(struct rq *rq) | 617 | static inline int cpu_of(struct rq *rq) |
@@ -1087,7 +1092,7 @@ hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
1087 | return NOTIFY_DONE; | 1092 | return NOTIFY_DONE; |
1088 | } | 1093 | } |
1089 | 1094 | ||
1090 | static void init_hrtick(void) | 1095 | static __init void init_hrtick(void) |
1091 | { | 1096 | { |
1092 | hotcpu_notifier(hotplug_hrtick, 0); | 1097 | hotcpu_notifier(hotplug_hrtick, 0); |
1093 | } | 1098 | } |
@@ -1102,7 +1107,7 @@ static void hrtick_start(struct rq *rq, u64 delay) | |||
1102 | 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); |
1103 | } | 1108 | } |
1104 | 1109 | ||
1105 | static void init_hrtick(void) | 1110 | static inline void init_hrtick(void) |
1106 | { | 1111 | { |
1107 | } | 1112 | } |
1108 | #endif /* CONFIG_SMP */ | 1113 | #endif /* CONFIG_SMP */ |
@@ -1119,9 +1124,9 @@ static void init_rq_hrtick(struct rq *rq) | |||
1119 | 1124 | ||
1120 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | 1125 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
1121 | rq->hrtick_timer.function = hrtick; | 1126 | rq->hrtick_timer.function = hrtick; |
1122 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 1127 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_PERCPU; |
1123 | } | 1128 | } |
1124 | #else | 1129 | #else /* CONFIG_SCHED_HRTICK */ |
1125 | static inline void hrtick_clear(struct rq *rq) | 1130 | static inline void hrtick_clear(struct rq *rq) |
1126 | { | 1131 | { |
1127 | } | 1132 | } |
@@ -1133,7 +1138,7 @@ static inline void init_rq_hrtick(struct rq *rq) | |||
1133 | static inline void init_hrtick(void) | 1138 | static inline void init_hrtick(void) |
1134 | { | 1139 | { |
1135 | } | 1140 | } |
1136 | #endif | 1141 | #endif /* CONFIG_SCHED_HRTICK */ |
1137 | 1142 | ||
1138 | /* | 1143 | /* |
1139 | * resched_task - mark a task 'to be rescheduled now'. | 1144 | * resched_task - mark a task 'to be rescheduled now'. |
@@ -1380,38 +1385,24 @@ static inline void dec_cpu_load(struct rq *rq, unsigned long load) | |||
1380 | update_load_sub(&rq->load, load); | 1385 | update_load_sub(&rq->load, load); |
1381 | } | 1386 | } |
1382 | 1387 | ||
1383 | #ifdef CONFIG_SMP | 1388 | #if (defined(CONFIG_SMP) && defined(CONFIG_FAIR_GROUP_SCHED)) || defined(CONFIG_RT_GROUP_SCHED) |
1384 | static unsigned long source_load(int cpu, int type); | 1389 | typedef int (*tg_visitor)(struct task_group *, void *); |
1385 | static unsigned long target_load(int cpu, int type); | ||
1386 | static int task_hot(struct task_struct *p, u64 now, struct sched_domain *sd); | ||
1387 | |||
1388 | static unsigned long cpu_avg_load_per_task(int cpu) | ||
1389 | { | ||
1390 | struct rq *rq = cpu_rq(cpu); | ||
1391 | |||
1392 | if (rq->nr_running) | ||
1393 | rq->avg_load_per_task = rq->load.weight / rq->nr_running; | ||
1394 | |||
1395 | return rq->avg_load_per_task; | ||
1396 | } | ||
1397 | |||
1398 | #ifdef CONFIG_FAIR_GROUP_SCHED | ||
1399 | |||
1400 | typedef void (*tg_visitor)(struct task_group *, int, struct sched_domain *); | ||
1401 | 1390 | ||
1402 | /* | 1391 | /* |
1403 | * 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 |
1404 | * leaving it for the final time. | 1393 | * leaving it for the final time. |
1405 | */ | 1394 | */ |
1406 | static void | 1395 | static int walk_tg_tree(tg_visitor down, tg_visitor up, void *data) |
1407 | walk_tg_tree(tg_visitor down, tg_visitor up, int cpu, struct sched_domain *sd) | ||
1408 | { | 1396 | { |
1409 | struct task_group *parent, *child; | 1397 | struct task_group *parent, *child; |
1398 | int ret; | ||
1410 | 1399 | ||
1411 | rcu_read_lock(); | 1400 | rcu_read_lock(); |
1412 | parent = &root_task_group; | 1401 | parent = &root_task_group; |
1413 | down: | 1402 | down: |
1414 | (*down)(parent, cpu, sd); | 1403 | ret = (*down)(parent, data); |
1404 | if (ret) | ||
1405 | goto out_unlock; | ||
1415 | list_for_each_entry_rcu(child, &parent->children, siblings) { | 1406 | list_for_each_entry_rcu(child, &parent->children, siblings) { |
1416 | parent = child; | 1407 | parent = child; |
1417 | goto down; | 1408 | goto down; |
@@ -1419,14 +1410,42 @@ down: | |||
1419 | up: | 1410 | up: |
1420 | continue; | 1411 | continue; |
1421 | } | 1412 | } |
1422 | (*up)(parent, cpu, sd); | 1413 | ret = (*up)(parent, data); |
1414 | if (ret) | ||
1415 | goto out_unlock; | ||
1423 | 1416 | ||
1424 | child = parent; | 1417 | child = parent; |
1425 | parent = parent->parent; | 1418 | parent = parent->parent; |
1426 | if (parent) | 1419 | if (parent) |
1427 | goto up; | 1420 | goto up; |
1421 | out_unlock: | ||
1428 | rcu_read_unlock(); | 1422 | rcu_read_unlock(); |
1423 | |||
1424 | return ret; | ||
1425 | } | ||
1426 | |||
1427 | static int tg_nop(struct task_group *tg, void *data) | ||
1428 | { | ||
1429 | return 0; | ||
1429 | } | 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 | ||
1430 | 1449 | ||
1431 | 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); |
1432 | 1451 | ||
@@ -1486,11 +1505,11 @@ __update_group_shares_cpu(struct task_group *tg, int cpu, | |||
1486 | * 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 |
1487 | * parent group depends on the shares of its child groups. | 1506 | * parent group depends on the shares of its child groups. |
1488 | */ | 1507 | */ |
1489 | static void | 1508 | static int tg_shares_up(struct task_group *tg, void *data) |
1490 | tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd) | ||
1491 | { | 1509 | { |
1492 | unsigned long rq_weight = 0; | 1510 | unsigned long rq_weight = 0; |
1493 | unsigned long shares = 0; | 1511 | unsigned long shares = 0; |
1512 | struct sched_domain *sd = data; | ||
1494 | int i; | 1513 | int i; |
1495 | 1514 | ||
1496 | for_each_cpu_mask(i, sd->span) { | 1515 | for_each_cpu_mask(i, sd->span) { |
@@ -1515,6 +1534,8 @@ tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd) | |||
1515 | __update_group_shares_cpu(tg, i, shares, rq_weight); | 1534 | __update_group_shares_cpu(tg, i, shares, rq_weight); |
1516 | spin_unlock_irqrestore(&rq->lock, flags); | 1535 | spin_unlock_irqrestore(&rq->lock, flags); |
1517 | } | 1536 | } |
1537 | |||
1538 | return 0; | ||
1518 | } | 1539 | } |
1519 | 1540 | ||
1520 | /* | 1541 | /* |
@@ -1522,10 +1543,10 @@ tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd) | |||
1522 | * 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 |
1523 | * group is a fraction of its parents load. | 1544 | * group is a fraction of its parents load. |
1524 | */ | 1545 | */ |
1525 | static void | 1546 | static int tg_load_down(struct task_group *tg, void *data) |
1526 | tg_load_down(struct task_group *tg, int cpu, struct sched_domain *sd) | ||
1527 | { | 1547 | { |
1528 | unsigned long load; | 1548 | unsigned long load; |
1549 | long cpu = (long)data; | ||
1529 | 1550 | ||
1530 | if (!tg->parent) { | 1551 | if (!tg->parent) { |
1531 | load = cpu_rq(cpu)->load.weight; | 1552 | load = cpu_rq(cpu)->load.weight; |
@@ -1536,11 +1557,8 @@ tg_load_down(struct task_group *tg, int cpu, struct sched_domain *sd) | |||
1536 | } | 1557 | } |
1537 | 1558 | ||
1538 | tg->cfs_rq[cpu]->h_load = load; | 1559 | tg->cfs_rq[cpu]->h_load = load; |
1539 | } | ||
1540 | 1560 | ||
1541 | static void | 1561 | return 0; |
1542 | tg_nop(struct task_group *tg, int cpu, struct sched_domain *sd) | ||
1543 | { | ||
1544 | } | 1562 | } |
1545 | 1563 | ||
1546 | static void update_shares(struct sched_domain *sd) | 1564 | static void update_shares(struct sched_domain *sd) |
@@ -1550,7 +1568,7 @@ static void update_shares(struct sched_domain *sd) | |||
1550 | 1568 | ||
1551 | if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) { | 1569 | if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) { |
1552 | sd->last_update = now; | 1570 | sd->last_update = now; |
1553 | walk_tg_tree(tg_nop, tg_shares_up, 0, sd); | 1571 | walk_tg_tree(tg_nop, tg_shares_up, sd); |
1554 | } | 1572 | } |
1555 | } | 1573 | } |
1556 | 1574 | ||
@@ -1561,9 +1579,9 @@ static void update_shares_locked(struct rq *rq, struct sched_domain *sd) | |||
1561 | spin_lock(&rq->lock); | 1579 | spin_lock(&rq->lock); |
1562 | } | 1580 | } |
1563 | 1581 | ||
1564 | static void update_h_load(int cpu) | 1582 | static void update_h_load(long cpu) |
1565 | { | 1583 | { |
1566 | walk_tg_tree(tg_load_down, tg_nop, cpu, NULL); | 1584 | walk_tg_tree(tg_load_down, tg_nop, (void *)cpu); |
1567 | } | 1585 | } |
1568 | 1586 | ||
1569 | #else | 1587 | #else |
@@ -1921,11 +1939,8 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state) | |||
1921 | running = task_running(rq, p); | 1939 | running = task_running(rq, p); |
1922 | on_rq = p->se.on_rq; | 1940 | on_rq = p->se.on_rq; |
1923 | ncsw = 0; | 1941 | ncsw = 0; |
1924 | if (!match_state || p->state == match_state) { | 1942 | if (!match_state || p->state == match_state) |
1925 | ncsw = p->nivcsw + p->nvcsw; | 1943 | ncsw = p->nvcsw | LONG_MIN; /* sets MSB */ |
1926 | if (unlikely(!ncsw)) | ||
1927 | ncsw = 1; | ||
1928 | } | ||
1929 | task_rq_unlock(rq, &flags); | 1944 | task_rq_unlock(rq, &flags); |
1930 | 1945 | ||
1931 | /* | 1946 | /* |
@@ -2285,7 +2300,7 @@ out_running: | |||
2285 | trace_mark(kernel_sched_wakeup, | 2300 | trace_mark(kernel_sched_wakeup, |
2286 | "pid %d state %ld ## rq %p task %p rq->curr %p", | 2301 | "pid %d state %ld ## rq %p task %p rq->curr %p", |
2287 | p->pid, p->state, rq, p, rq->curr); | 2302 | p->pid, p->state, rq, p, rq->curr); |
2288 | check_preempt_curr(rq, p); | 2303 | check_preempt_curr(rq, p, sync); |
2289 | 2304 | ||
2290 | p->state = TASK_RUNNING; | 2305 | p->state = TASK_RUNNING; |
2291 | #ifdef CONFIG_SMP | 2306 | #ifdef CONFIG_SMP |
@@ -2420,7 +2435,7 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags) | |||
2420 | trace_mark(kernel_sched_wakeup_new, | 2435 | trace_mark(kernel_sched_wakeup_new, |
2421 | "pid %d state %ld ## rq %p task %p rq->curr %p", | 2436 | "pid %d state %ld ## rq %p task %p rq->curr %p", |
2422 | p->pid, p->state, rq, p, rq->curr); | 2437 | p->pid, p->state, rq, p, rq->curr); |
2423 | check_preempt_curr(rq, p); | 2438 | check_preempt_curr(rq, p, 0); |
2424 | #ifdef CONFIG_SMP | 2439 | #ifdef CONFIG_SMP |
2425 | if (p->sched_class->task_wake_up) | 2440 | if (p->sched_class->task_wake_up) |
2426 | p->sched_class->task_wake_up(rq, p); | 2441 | p->sched_class->task_wake_up(rq, p); |
@@ -2880,7 +2895,7 @@ static void pull_task(struct rq *src_rq, struct task_struct *p, | |||
2880 | * 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 |
2881 | * to be always true for them. | 2896 | * to be always true for them. |
2882 | */ | 2897 | */ |
2883 | check_preempt_curr(this_rq, p); | 2898 | check_preempt_curr(this_rq, p, 0); |
2884 | } | 2899 | } |
2885 | 2900 | ||
2886 | /* | 2901 | /* |
@@ -4037,23 +4052,26 @@ DEFINE_PER_CPU(struct kernel_stat, kstat); | |||
4037 | EXPORT_PER_CPU_SYMBOL(kstat); | 4052 | EXPORT_PER_CPU_SYMBOL(kstat); |
4038 | 4053 | ||
4039 | /* | 4054 | /* |
4040 | * Return p->sum_exec_runtime plus any more ns on the sched_clock | 4055 | * Return any ns on the sched_clock that have not yet been banked in |
4041 | * that have not yet been banked in case the task is currently running. | 4056 | * @p in case that task is currently running. |
4042 | */ | 4057 | */ |
4043 | unsigned long long task_sched_runtime(struct task_struct *p) | 4058 | unsigned long long task_delta_exec(struct task_struct *p) |
4044 | { | 4059 | { |
4045 | unsigned long flags; | 4060 | unsigned long flags; |
4046 | u64 ns, delta_exec; | ||
4047 | struct rq *rq; | 4061 | struct rq *rq; |
4062 | u64 ns = 0; | ||
4048 | 4063 | ||
4049 | rq = task_rq_lock(p, &flags); | 4064 | rq = task_rq_lock(p, &flags); |
4050 | ns = p->se.sum_exec_runtime; | 4065 | |
4051 | if (task_current(rq, p)) { | 4066 | if (task_current(rq, p)) { |
4067 | u64 delta_exec; | ||
4068 | |||
4052 | update_rq_clock(rq); | 4069 | update_rq_clock(rq); |
4053 | delta_exec = rq->clock - p->se.exec_start; | 4070 | delta_exec = rq->clock - p->se.exec_start; |
4054 | if ((s64)delta_exec > 0) | 4071 | if ((s64)delta_exec > 0) |
4055 | ns += delta_exec; | 4072 | ns = delta_exec; |
4056 | } | 4073 | } |
4074 | |||
4057 | task_rq_unlock(rq, &flags); | 4075 | task_rq_unlock(rq, &flags); |
4058 | 4076 | ||
4059 | return ns; | 4077 | return ns; |
@@ -4070,6 +4088,7 @@ void account_user_time(struct task_struct *p, cputime_t cputime) | |||
4070 | cputime64_t tmp; | 4088 | cputime64_t tmp; |
4071 | 4089 | ||
4072 | p->utime = cputime_add(p->utime, cputime); | 4090 | p->utime = cputime_add(p->utime, cputime); |
4091 | account_group_user_time(p, cputime); | ||
4073 | 4092 | ||
4074 | /* Add user time to cpustat. */ | 4093 | /* Add user time to cpustat. */ |
4075 | tmp = cputime_to_cputime64(cputime); | 4094 | tmp = cputime_to_cputime64(cputime); |
@@ -4094,6 +4113,7 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime) | |||
4094 | tmp = cputime_to_cputime64(cputime); | 4113 | tmp = cputime_to_cputime64(cputime); |
4095 | 4114 | ||
4096 | p->utime = cputime_add(p->utime, cputime); | 4115 | p->utime = cputime_add(p->utime, cputime); |
4116 | account_group_user_time(p, cputime); | ||
4097 | p->gtime = cputime_add(p->gtime, cputime); | 4117 | p->gtime = cputime_add(p->gtime, cputime); |
4098 | 4118 | ||
4099 | cpustat->user = cputime64_add(cpustat->user, tmp); | 4119 | cpustat->user = cputime64_add(cpustat->user, tmp); |
@@ -4129,6 +4149,7 @@ void account_system_time(struct task_struct *p, int hardirq_offset, | |||
4129 | } | 4149 | } |
4130 | 4150 | ||
4131 | p->stime = cputime_add(p->stime, cputime); | 4151 | p->stime = cputime_add(p->stime, cputime); |
4152 | account_group_system_time(p, cputime); | ||
4132 | 4153 | ||
4133 | /* Add system time to cpustat. */ | 4154 | /* Add system time to cpustat. */ |
4134 | tmp = cputime_to_cputime64(cputime); | 4155 | tmp = cputime_to_cputime64(cputime); |
@@ -4170,6 +4191,7 @@ void account_steal_time(struct task_struct *p, cputime_t steal) | |||
4170 | 4191 | ||
4171 | if (p == rq->idle) { | 4192 | if (p == rq->idle) { |
4172 | p->stime = cputime_add(p->stime, steal); | 4193 | p->stime = cputime_add(p->stime, steal); |
4194 | account_group_system_time(p, steal); | ||
4173 | if (atomic_read(&rq->nr_iowait) > 0) | 4195 | if (atomic_read(&rq->nr_iowait) > 0) |
4174 | cpustat->iowait = cputime64_add(cpustat->iowait, tmp); | 4196 | cpustat->iowait = cputime64_add(cpustat->iowait, tmp); |
4175 | else | 4197 | else |
@@ -4179,6 +4201,65 @@ void account_steal_time(struct task_struct *p, cputime_t steal) | |||
4179 | } | 4201 | } |
4180 | 4202 | ||
4181 | /* | 4203 | /* |
4204 | * Use precise platform statistics if available: | ||
4205 | */ | ||
4206 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | ||
4207 | cputime_t task_utime(struct task_struct *p) | ||
4208 | { | ||
4209 | return p->utime; | ||
4210 | } | ||
4211 | |||
4212 | cputime_t task_stime(struct task_struct *p) | ||
4213 | { | ||
4214 | return p->stime; | ||
4215 | } | ||
4216 | #else | ||
4217 | cputime_t task_utime(struct task_struct *p) | ||
4218 | { | ||
4219 | clock_t utime = cputime_to_clock_t(p->utime), | ||
4220 | total = utime + cputime_to_clock_t(p->stime); | ||
4221 | u64 temp; | ||
4222 | |||
4223 | /* | ||
4224 | * Use CFS's precise accounting: | ||
4225 | */ | ||
4226 | temp = (u64)nsec_to_clock_t(p->se.sum_exec_runtime); | ||
4227 | |||
4228 | if (total) { | ||
4229 | temp *= utime; | ||
4230 | do_div(temp, total); | ||
4231 | } | ||
4232 | utime = (clock_t)temp; | ||
4233 | |||
4234 | p->prev_utime = max(p->prev_utime, clock_t_to_cputime(utime)); | ||
4235 | return p->prev_utime; | ||
4236 | } | ||
4237 | |||
4238 | cputime_t task_stime(struct task_struct *p) | ||
4239 | { | ||
4240 | clock_t stime; | ||
4241 | |||
4242 | /* | ||
4243 | * Use CFS's precise accounting. (we subtract utime from | ||
4244 | * the total, to make sure the total observed by userspace | ||
4245 | * grows monotonically - apps rely on that): | ||
4246 | */ | ||
4247 | stime = nsec_to_clock_t(p->se.sum_exec_runtime) - | ||
4248 | cputime_to_clock_t(task_utime(p)); | ||
4249 | |||
4250 | if (stime >= 0) | ||
4251 | p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime)); | ||
4252 | |||
4253 | return p->prev_stime; | ||
4254 | } | ||
4255 | #endif | ||
4256 | |||
4257 | inline cputime_t task_gtime(struct task_struct *p) | ||
4258 | { | ||
4259 | return p->gtime; | ||
4260 | } | ||
4261 | |||
4262 | /* | ||
4182 | * This function gets called by the timer code, with HZ frequency. | 4263 | * This function gets called by the timer code, with HZ frequency. |
4183 | * We call it with interrupts disabled. | 4264 | * We call it with interrupts disabled. |
4184 | * | 4265 | * |
@@ -4568,6 +4649,15 @@ __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive) | |||
4568 | } | 4649 | } |
4569 | EXPORT_SYMBOL_GPL(__wake_up_sync); /* For internal use only */ | 4650 | EXPORT_SYMBOL_GPL(__wake_up_sync); /* For internal use only */ |
4570 | 4651 | ||
4652 | /** | ||
4653 | * complete: - signals a single thread waiting on this completion | ||
4654 | * @x: holds the state of this particular completion | ||
4655 | * | ||
4656 | * This will wake up a single thread waiting on this completion. Threads will be | ||
4657 | * awakened in the same order in which they were queued. | ||
4658 | * | ||
4659 | * See also complete_all(), wait_for_completion() and related routines. | ||
4660 | */ | ||
4571 | void complete(struct completion *x) | 4661 | void complete(struct completion *x) |
4572 | { | 4662 | { |
4573 | unsigned long flags; | 4663 | unsigned long flags; |
@@ -4579,6 +4669,12 @@ void complete(struct completion *x) | |||
4579 | } | 4669 | } |
4580 | EXPORT_SYMBOL(complete); | 4670 | EXPORT_SYMBOL(complete); |
4581 | 4671 | ||
4672 | /** | ||
4673 | * complete_all: - signals all threads waiting on this completion | ||
4674 | * @x: holds the state of this particular completion | ||
4675 | * | ||
4676 | * This will wake up all threads waiting on this particular completion event. | ||
4677 | */ | ||
4582 | void complete_all(struct completion *x) | 4678 | void complete_all(struct completion *x) |
4583 | { | 4679 | { |
4584 | unsigned long flags; | 4680 | unsigned long flags; |
@@ -4599,10 +4695,7 @@ do_wait_for_common(struct completion *x, long timeout, int state) | |||
4599 | wait.flags |= WQ_FLAG_EXCLUSIVE; | 4695 | wait.flags |= WQ_FLAG_EXCLUSIVE; |
4600 | __add_wait_queue_tail(&x->wait, &wait); | 4696 | __add_wait_queue_tail(&x->wait, &wait); |
4601 | do { | 4697 | do { |
4602 | if ((state == TASK_INTERRUPTIBLE && | 4698 | if (signal_pending_state(state, current)) { |
4603 | signal_pending(current)) || | ||
4604 | (state == TASK_KILLABLE && | ||
4605 | fatal_signal_pending(current))) { | ||
4606 | timeout = -ERESTARTSYS; | 4699 | timeout = -ERESTARTSYS; |
4607 | break; | 4700 | break; |
4608 | } | 4701 | } |
@@ -4630,12 +4723,31 @@ wait_for_common(struct completion *x, long timeout, int state) | |||
4630 | return timeout; | 4723 | return timeout; |
4631 | } | 4724 | } |
4632 | 4725 | ||
4726 | /** | ||
4727 | * wait_for_completion: - waits for completion of a task | ||
4728 | * @x: holds the state of this particular completion | ||
4729 | * | ||
4730 | * This waits to be signaled for completion of a specific task. It is NOT | ||
4731 | * interruptible and there is no timeout. | ||
4732 | * | ||
4733 | * See also similar routines (i.e. wait_for_completion_timeout()) with timeout | ||
4734 | * and interrupt capability. Also see complete(). | ||
4735 | */ | ||
4633 | void __sched wait_for_completion(struct completion *x) | 4736 | void __sched wait_for_completion(struct completion *x) |
4634 | { | 4737 | { |
4635 | wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); | 4738 | wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); |
4636 | } | 4739 | } |
4637 | EXPORT_SYMBOL(wait_for_completion); | 4740 | EXPORT_SYMBOL(wait_for_completion); |
4638 | 4741 | ||
4742 | /** | ||
4743 | * wait_for_completion_timeout: - waits for completion of a task (w/timeout) | ||
4744 | * @x: holds the state of this particular completion | ||
4745 | * @timeout: timeout value in jiffies | ||
4746 | * | ||
4747 | * This waits for either a completion of a specific task to be signaled or for a | ||
4748 | * specified timeout to expire. The timeout is in jiffies. It is not | ||
4749 | * interruptible. | ||
4750 | */ | ||
4639 | unsigned long __sched | 4751 | unsigned long __sched |
4640 | wait_for_completion_timeout(struct completion *x, unsigned long timeout) | 4752 | wait_for_completion_timeout(struct completion *x, unsigned long timeout) |
4641 | { | 4753 | { |
@@ -4643,6 +4755,13 @@ wait_for_completion_timeout(struct completion *x, unsigned long timeout) | |||
4643 | } | 4755 | } |
4644 | EXPORT_SYMBOL(wait_for_completion_timeout); | 4756 | EXPORT_SYMBOL(wait_for_completion_timeout); |
4645 | 4757 | ||
4758 | /** | ||
4759 | * wait_for_completion_interruptible: - waits for completion of a task (w/intr) | ||
4760 | * @x: holds the state of this particular completion | ||
4761 | * | ||
4762 | * This waits for completion of a specific task to be signaled. It is | ||
4763 | * interruptible. | ||
4764 | */ | ||
4646 | int __sched wait_for_completion_interruptible(struct completion *x) | 4765 | int __sched wait_for_completion_interruptible(struct completion *x) |
4647 | { | 4766 | { |
4648 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); | 4767 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); |
@@ -4652,6 +4771,14 @@ int __sched wait_for_completion_interruptible(struct completion *x) | |||
4652 | } | 4771 | } |
4653 | EXPORT_SYMBOL(wait_for_completion_interruptible); | 4772 | EXPORT_SYMBOL(wait_for_completion_interruptible); |
4654 | 4773 | ||
4774 | /** | ||
4775 | * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr)) | ||
4776 | * @x: holds the state of this particular completion | ||
4777 | * @timeout: timeout value in jiffies | ||
4778 | * | ||
4779 | * This waits for either a completion of a specific task to be signaled or for a | ||
4780 | * specified timeout to expire. It is interruptible. The timeout is in jiffies. | ||
4781 | */ | ||
4655 | unsigned long __sched | 4782 | unsigned long __sched |
4656 | wait_for_completion_interruptible_timeout(struct completion *x, | 4783 | wait_for_completion_interruptible_timeout(struct completion *x, |
4657 | unsigned long timeout) | 4784 | unsigned long timeout) |
@@ -4660,6 +4787,13 @@ wait_for_completion_interruptible_timeout(struct completion *x, | |||
4660 | } | 4787 | } |
4661 | EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); | 4788 | EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); |
4662 | 4789 | ||
4790 | /** | ||
4791 | * wait_for_completion_killable: - waits for completion of a task (killable) | ||
4792 | * @x: holds the state of this particular completion | ||
4793 | * | ||
4794 | * This waits to be signaled for completion of a specific task. It can be | ||
4795 | * interrupted by a kill signal. | ||
4796 | */ | ||
4663 | int __sched wait_for_completion_killable(struct completion *x) | 4797 | int __sched wait_for_completion_killable(struct completion *x) |
4664 | { | 4798 | { |
4665 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); | 4799 | long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); |
@@ -5062,7 +5196,8 @@ recheck: | |||
5062 | * Do not allow realtime tasks into groups that have no runtime | 5196 | * Do not allow realtime tasks into groups that have no runtime |
5063 | * assigned. | 5197 | * assigned. |
5064 | */ | 5198 | */ |
5065 | if (rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0) | 5199 | if (rt_bandwidth_enabled() && rt_policy(policy) && |
5200 | task_group(p)->rt_bandwidth.rt_runtime == 0) | ||
5066 | return -EPERM; | 5201 | return -EPERM; |
5067 | #endif | 5202 | #endif |
5068 | 5203 | ||
@@ -5898,7 +6033,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
5898 | set_task_cpu(p, dest_cpu); | 6033 | set_task_cpu(p, dest_cpu); |
5899 | if (on_rq) { | 6034 | if (on_rq) { |
5900 | activate_task(rq_dest, p, 0); | 6035 | activate_task(rq_dest, p, 0); |
5901 | check_preempt_curr(rq_dest, p); | 6036 | check_preempt_curr(rq_dest, p, 0); |
5902 | } | 6037 | } |
5903 | done: | 6038 | done: |
5904 | ret = 1; | 6039 | ret = 1; |
@@ -6223,7 +6358,7 @@ set_table_entry(struct ctl_table *entry, | |||
6223 | static struct ctl_table * | 6358 | static struct ctl_table * |
6224 | sd_alloc_ctl_domain_table(struct sched_domain *sd) | 6359 | sd_alloc_ctl_domain_table(struct sched_domain *sd) |
6225 | { | 6360 | { |
6226 | struct ctl_table *table = sd_alloc_ctl_entry(12); | 6361 | struct ctl_table *table = sd_alloc_ctl_entry(13); |
6227 | 6362 | ||
6228 | if (table == NULL) | 6363 | if (table == NULL) |
6229 | return NULL; | 6364 | return NULL; |
@@ -6251,7 +6386,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd) | |||
6251 | sizeof(int), 0644, proc_dointvec_minmax); | 6386 | sizeof(int), 0644, proc_dointvec_minmax); |
6252 | set_table_entry(&table[10], "flags", &sd->flags, | 6387 | set_table_entry(&table[10], "flags", &sd->flags, |
6253 | sizeof(int), 0644, proc_dointvec_minmax); | 6388 | sizeof(int), 0644, proc_dointvec_minmax); |
6254 | /* &table[11] is terminator */ | 6389 | set_table_entry(&table[11], "name", sd->name, |
6390 | CORENAME_MAX_SIZE, 0444, proc_dostring); | ||
6391 | /* &table[12] is terminator */ | ||
6255 | 6392 | ||
6256 | return table; | 6393 | return table; |
6257 | } | 6394 | } |
@@ -7135,13 +7272,21 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) | |||
7135 | * Non-inlined to reduce accumulated stack pressure in build_sched_domains() | 7272 | * Non-inlined to reduce accumulated stack pressure in build_sched_domains() |
7136 | */ | 7273 | */ |
7137 | 7274 | ||
7275 | #ifdef CONFIG_SCHED_DEBUG | ||
7276 | # define SD_INIT_NAME(sd, type) sd->name = #type | ||
7277 | #else | ||
7278 | # define SD_INIT_NAME(sd, type) do { } while (0) | ||
7279 | #endif | ||
7280 | |||
7138 | #define SD_INIT(sd, type) sd_init_##type(sd) | 7281 | #define SD_INIT(sd, type) sd_init_##type(sd) |
7282 | |||
7139 | #define SD_INIT_FUNC(type) \ | 7283 | #define SD_INIT_FUNC(type) \ |
7140 | static noinline void sd_init_##type(struct sched_domain *sd) \ | 7284 | static noinline void sd_init_##type(struct sched_domain *sd) \ |
7141 | { \ | 7285 | { \ |
7142 | memset(sd, 0, sizeof(*sd)); \ | 7286 | memset(sd, 0, sizeof(*sd)); \ |
7143 | *sd = SD_##type##_INIT; \ | 7287 | *sd = SD_##type##_INIT; \ |
7144 | sd->level = SD_LV_##type; \ | 7288 | sd->level = SD_LV_##type; \ |
7289 | SD_INIT_NAME(sd, type); \ | ||
7145 | } | 7290 | } |
7146 | 7291 | ||
7147 | SD_INIT_FUNC(CPU) | 7292 | SD_INIT_FUNC(CPU) |
@@ -7637,24 +7782,27 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7637 | * and partition_sched_domains() will fallback to the single partition | 7782 | * and partition_sched_domains() will fallback to the single partition |
7638 | * 'fallback_doms', it also forces the domains to be rebuilt. | 7783 | * 'fallback_doms', it also forces the domains to be rebuilt. |
7639 | * | 7784 | * |
7785 | * If doms_new==NULL it will be replaced with cpu_online_map. | ||
7786 | * ndoms_new==0 is a special case for destroying existing domains. | ||
7787 | * It will not create the default domain. | ||
7788 | * | ||
7640 | * Call with hotplug lock held | 7789 | * Call with hotplug lock held |
7641 | */ | 7790 | */ |
7642 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | 7791 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, |
7643 | struct sched_domain_attr *dattr_new) | 7792 | struct sched_domain_attr *dattr_new) |
7644 | { | 7793 | { |
7645 | int i, j; | 7794 | int i, j, n; |
7646 | 7795 | ||
7647 | mutex_lock(&sched_domains_mutex); | 7796 | mutex_lock(&sched_domains_mutex); |
7648 | 7797 | ||
7649 | /* always unregister in case we don't destroy any domains */ | 7798 | /* always unregister in case we don't destroy any domains */ |
7650 | unregister_sched_domain_sysctl(); | 7799 | unregister_sched_domain_sysctl(); |
7651 | 7800 | ||
7652 | if (doms_new == NULL) | 7801 | n = doms_new ? ndoms_new : 0; |
7653 | ndoms_new = 0; | ||
7654 | 7802 | ||
7655 | /* Destroy deleted domains */ | 7803 | /* Destroy deleted domains */ |
7656 | for (i = 0; i < ndoms_cur; i++) { | 7804 | for (i = 0; i < ndoms_cur; i++) { |
7657 | for (j = 0; j < ndoms_new; j++) { | 7805 | for (j = 0; j < n; j++) { |
7658 | if (cpus_equal(doms_cur[i], doms_new[j]) | 7806 | if (cpus_equal(doms_cur[i], doms_new[j]) |
7659 | && dattrs_equal(dattr_cur, i, dattr_new, j)) | 7807 | && dattrs_equal(dattr_cur, i, dattr_new, j)) |
7660 | goto match1; | 7808 | goto match1; |
@@ -7667,7 +7815,6 @@ match1: | |||
7667 | 7815 | ||
7668 | if (doms_new == NULL) { | 7816 | if (doms_new == NULL) { |
7669 | ndoms_cur = 0; | 7817 | ndoms_cur = 0; |
7670 | ndoms_new = 1; | ||
7671 | doms_new = &fallback_doms; | 7818 | doms_new = &fallback_doms; |
7672 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | 7819 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); |
7673 | dattr_new = NULL; | 7820 | dattr_new = NULL; |
@@ -7704,8 +7851,13 @@ match2: | |||
7704 | int arch_reinit_sched_domains(void) | 7851 | int arch_reinit_sched_domains(void) |
7705 | { | 7852 | { |
7706 | get_online_cpus(); | 7853 | get_online_cpus(); |
7854 | |||
7855 | /* Destroy domains first to force the rebuild */ | ||
7856 | partition_sched_domains(0, NULL, NULL); | ||
7857 | |||
7707 | rebuild_sched_domains(); | 7858 | rebuild_sched_domains(); |
7708 | put_online_cpus(); | 7859 | put_online_cpus(); |
7860 | |||
7709 | return 0; | 7861 | return 0; |
7710 | } | 7862 | } |
7711 | 7863 | ||
@@ -7789,7 +7941,7 @@ static int update_sched_domains(struct notifier_block *nfb, | |||
7789 | case CPU_ONLINE_FROZEN: | 7941 | case CPU_ONLINE_FROZEN: |
7790 | case CPU_DEAD: | 7942 | case CPU_DEAD: |
7791 | case CPU_DEAD_FROZEN: | 7943 | case CPU_DEAD_FROZEN: |
7792 | partition_sched_domains(0, NULL, NULL); | 7944 | partition_sched_domains(1, NULL, NULL); |
7793 | return NOTIFY_OK; | 7945 | return NOTIFY_OK; |
7794 | 7946 | ||
7795 | default: | 7947 | default: |
@@ -8176,20 +8328,25 @@ void __might_sleep(char *file, int line) | |||
8176 | #ifdef in_atomic | 8328 | #ifdef in_atomic |
8177 | static unsigned long prev_jiffy; /* ratelimiting */ | 8329 | static unsigned long prev_jiffy; /* ratelimiting */ |
8178 | 8330 | ||
8179 | if ((in_atomic() || irqs_disabled()) && | 8331 | if ((!in_atomic() && !irqs_disabled()) || |
8180 | system_state == SYSTEM_RUNNING && !oops_in_progress) { | 8332 | system_state != SYSTEM_RUNNING || oops_in_progress) |
8181 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) | 8333 | return; |
8182 | return; | 8334 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) |
8183 | prev_jiffy = jiffies; | 8335 | return; |
8184 | printk(KERN_ERR "BUG: sleeping function called from invalid" | 8336 | prev_jiffy = jiffies; |
8185 | " context at %s:%d\n", file, line); | 8337 | |
8186 | printk("in_atomic():%d, irqs_disabled():%d\n", | 8338 | printk(KERN_ERR |
8187 | in_atomic(), irqs_disabled()); | 8339 | "BUG: sleeping function called from invalid context at %s:%d\n", |
8188 | debug_show_held_locks(current); | 8340 | file, line); |
8189 | if (irqs_disabled()) | 8341 | printk(KERN_ERR |
8190 | print_irqtrace_events(current); | 8342 | "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", |
8191 | dump_stack(); | 8343 | in_atomic(), irqs_disabled(), |
8192 | } | 8344 | current->pid, current->comm); |
8345 | |||
8346 | debug_show_held_locks(current); | ||
8347 | if (irqs_disabled()) | ||
8348 | print_irqtrace_events(current); | ||
8349 | dump_stack(); | ||
8193 | #endif | 8350 | #endif |
8194 | } | 8351 | } |
8195 | EXPORT_SYMBOL(__might_sleep); | 8352 | EXPORT_SYMBOL(__might_sleep); |
@@ -8687,73 +8844,95 @@ static DEFINE_MUTEX(rt_constraints_mutex); | |||
8687 | static unsigned long to_ratio(u64 period, u64 runtime) | 8844 | static unsigned long to_ratio(u64 period, u64 runtime) |
8688 | { | 8845 | { |
8689 | if (runtime == RUNTIME_INF) | 8846 | if (runtime == RUNTIME_INF) |
8690 | return 1ULL << 16; | 8847 | return 1ULL << 20; |
8691 | 8848 | ||
8692 | return div64_u64(runtime << 16, period); | 8849 | return div64_u64(runtime << 20, period); |
8693 | } | 8850 | } |
8694 | 8851 | ||
8695 | #ifdef CONFIG_CGROUP_SCHED | 8852 | /* Must be called with tasklist_lock held */ |
8696 | static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) | 8853 | static inline int tg_has_rt_tasks(struct task_group *tg) |
8697 | { | 8854 | { |
8698 | struct task_group *tgi, *parent = tg->parent; | 8855 | struct task_struct *g, *p; |
8699 | unsigned long total = 0; | ||
8700 | 8856 | ||
8701 | if (!parent) { | 8857 | do_each_thread(g, p) { |
8702 | if (global_rt_period() < period) | 8858 | if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg) |
8703 | return 0; | 8859 | return 1; |
8860 | } while_each_thread(g, p); | ||
8704 | 8861 | ||
8705 | return to_ratio(period, runtime) < | 8862 | return 0; |
8706 | to_ratio(global_rt_period(), global_rt_runtime()); | 8863 | } |
8707 | } | ||
8708 | 8864 | ||
8709 | if (ktime_to_ns(parent->rt_bandwidth.rt_period) < period) | 8865 | struct rt_schedulable_data { |
8710 | return 0; | 8866 | struct task_group *tg; |
8867 | u64 rt_period; | ||
8868 | u64 rt_runtime; | ||
8869 | }; | ||
8711 | 8870 | ||
8712 | rcu_read_lock(); | 8871 | static int tg_schedulable(struct task_group *tg, void *data) |
8713 | list_for_each_entry_rcu(tgi, &parent->children, siblings) { | 8872 | { |
8714 | if (tgi == tg) | 8873 | struct rt_schedulable_data *d = data; |
8715 | continue; | 8874 | struct task_group *child; |
8875 | unsigned long total, sum = 0; | ||
8876 | u64 period, runtime; | ||
8877 | |||
8878 | period = ktime_to_ns(tg->rt_bandwidth.rt_period); | ||
8879 | runtime = tg->rt_bandwidth.rt_runtime; | ||
8716 | 8880 | ||
8717 | total += to_ratio(ktime_to_ns(tgi->rt_bandwidth.rt_period), | 8881 | if (tg == d->tg) { |
8718 | tgi->rt_bandwidth.rt_runtime); | 8882 | period = d->rt_period; |
8883 | runtime = d->rt_runtime; | ||
8719 | } | 8884 | } |
8720 | rcu_read_unlock(); | ||
8721 | 8885 | ||
8722 | return total + to_ratio(period, runtime) <= | 8886 | /* |
8723 | to_ratio(ktime_to_ns(parent->rt_bandwidth.rt_period), | 8887 | * Cannot have more runtime than the period. |
8724 | parent->rt_bandwidth.rt_runtime); | 8888 | */ |
8725 | } | 8889 | if (runtime > period && runtime != RUNTIME_INF) |
8726 | #elif defined CONFIG_USER_SCHED | 8890 | return -EINVAL; |
8727 | static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) | ||
8728 | { | ||
8729 | struct task_group *tgi; | ||
8730 | unsigned long total = 0; | ||
8731 | unsigned long global_ratio = | ||
8732 | to_ratio(global_rt_period(), global_rt_runtime()); | ||
8733 | 8891 | ||
8734 | rcu_read_lock(); | 8892 | /* |
8735 | list_for_each_entry_rcu(tgi, &task_groups, list) { | 8893 | * Ensure we don't starve existing RT tasks. |
8736 | if (tgi == tg) | 8894 | */ |
8737 | continue; | 8895 | if (rt_bandwidth_enabled() && !runtime && tg_has_rt_tasks(tg)) |
8896 | return -EBUSY; | ||
8897 | |||
8898 | total = to_ratio(period, runtime); | ||
8738 | 8899 | ||
8739 | total += to_ratio(ktime_to_ns(tgi->rt_bandwidth.rt_period), | 8900 | /* |
8740 | tgi->rt_bandwidth.rt_runtime); | 8901 | * Nobody can have more than the global setting allows. |
8902 | */ | ||
8903 | if (total > to_ratio(global_rt_period(), global_rt_runtime())) | ||
8904 | return -EINVAL; | ||
8905 | |||
8906 | /* | ||
8907 | * The sum of our children's runtime should not exceed our own. | ||
8908 | */ | ||
8909 | list_for_each_entry_rcu(child, &tg->children, siblings) { | ||
8910 | period = ktime_to_ns(child->rt_bandwidth.rt_period); | ||
8911 | runtime = child->rt_bandwidth.rt_runtime; | ||
8912 | |||
8913 | if (child == d->tg) { | ||
8914 | period = d->rt_period; | ||
8915 | runtime = d->rt_runtime; | ||
8916 | } | ||
8917 | |||
8918 | sum += to_ratio(period, runtime); | ||
8741 | } | 8919 | } |
8742 | rcu_read_unlock(); | ||
8743 | 8920 | ||
8744 | return total + to_ratio(period, runtime) < global_ratio; | 8921 | if (sum > total) |
8922 | return -EINVAL; | ||
8923 | |||
8924 | return 0; | ||
8745 | } | 8925 | } |
8746 | #endif | ||
8747 | 8926 | ||
8748 | /* Must be called with tasklist_lock held */ | 8927 | static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) |
8749 | static inline int tg_has_rt_tasks(struct task_group *tg) | ||
8750 | { | 8928 | { |
8751 | struct task_struct *g, *p; | 8929 | struct rt_schedulable_data data = { |
8752 | do_each_thread(g, p) { | 8930 | .tg = tg, |
8753 | if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg) | 8931 | .rt_period = period, |
8754 | return 1; | 8932 | .rt_runtime = runtime, |
8755 | } while_each_thread(g, p); | 8933 | }; |
8756 | return 0; | 8934 | |
8935 | return walk_tg_tree(tg_schedulable, tg_nop, &data); | ||
8757 | } | 8936 | } |
8758 | 8937 | ||
8759 | static int tg_set_bandwidth(struct task_group *tg, | 8938 | static int tg_set_bandwidth(struct task_group *tg, |
@@ -8763,14 +8942,9 @@ static int tg_set_bandwidth(struct task_group *tg, | |||
8763 | 8942 | ||
8764 | mutex_lock(&rt_constraints_mutex); | 8943 | mutex_lock(&rt_constraints_mutex); |
8765 | read_lock(&tasklist_lock); | 8944 | read_lock(&tasklist_lock); |
8766 | if (rt_runtime == 0 && tg_has_rt_tasks(tg)) { | 8945 | err = __rt_schedulable(tg, rt_period, rt_runtime); |
8767 | err = -EBUSY; | 8946 | if (err) |
8768 | goto unlock; | 8947 | goto unlock; |
8769 | } | ||
8770 | if (!__rt_schedulable(tg, rt_period, rt_runtime)) { | ||
8771 | err = -EINVAL; | ||
8772 | goto unlock; | ||
8773 | } | ||
8774 | 8948 | ||
8775 | spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); | 8949 | spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); |
8776 | tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); | 8950 | tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); |
@@ -8839,16 +9013,25 @@ long sched_group_rt_period(struct task_group *tg) | |||
8839 | 9013 | ||
8840 | static int sched_rt_global_constraints(void) | 9014 | static int sched_rt_global_constraints(void) |
8841 | { | 9015 | { |
8842 | struct task_group *tg = &root_task_group; | 9016 | u64 runtime, period; |
8843 | u64 rt_runtime, rt_period; | ||
8844 | int ret = 0; | 9017 | int ret = 0; |
8845 | 9018 | ||
8846 | rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period); | 9019 | if (sysctl_sched_rt_period <= 0) |
8847 | rt_runtime = tg->rt_bandwidth.rt_runtime; | 9020 | return -EINVAL; |
9021 | |||
9022 | runtime = global_rt_runtime(); | ||
9023 | period = global_rt_period(); | ||
9024 | |||
9025 | /* | ||
9026 | * Sanity check on the sysctl variables. | ||
9027 | */ | ||
9028 | if (runtime > period && runtime != RUNTIME_INF) | ||
9029 | return -EINVAL; | ||
8848 | 9030 | ||
8849 | mutex_lock(&rt_constraints_mutex); | 9031 | mutex_lock(&rt_constraints_mutex); |
8850 | if (!__rt_schedulable(tg, rt_period, rt_runtime)) | 9032 | read_lock(&tasklist_lock); |
8851 | ret = -EINVAL; | 9033 | ret = __rt_schedulable(NULL, 0, 0); |
9034 | read_unlock(&tasklist_lock); | ||
8852 | mutex_unlock(&rt_constraints_mutex); | 9035 | mutex_unlock(&rt_constraints_mutex); |
8853 | 9036 | ||
8854 | return ret; | 9037 | return ret; |
@@ -8859,6 +9042,9 @@ static int sched_rt_global_constraints(void) | |||
8859 | unsigned long flags; | 9042 | unsigned long flags; |
8860 | int i; | 9043 | int i; |
8861 | 9044 | ||
9045 | if (sysctl_sched_rt_period <= 0) | ||
9046 | return -EINVAL; | ||
9047 | |||
8862 | spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags); | 9048 | spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags); |
8863 | for_each_possible_cpu(i) { | 9049 | for_each_possible_cpu(i) { |
8864 | struct rt_rq *rt_rq = &cpu_rq(i)->rt; | 9050 | struct rt_rq *rt_rq = &cpu_rq(i)->rt; |
@@ -8919,7 +9105,6 @@ cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
8919 | 9105 | ||
8920 | if (!cgrp->parent) { | 9106 | if (!cgrp->parent) { |
8921 | /* This is early initialization for the top cgroup */ | 9107 | /* This is early initialization for the top cgroup */ |
8922 | init_task_group.css.cgroup = cgrp; | ||
8923 | return &init_task_group.css; | 9108 | return &init_task_group.css; |
8924 | } | 9109 | } |
8925 | 9110 | ||
@@ -8928,9 +9113,6 @@ cpu_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
8928 | if (IS_ERR(tg)) | 9113 | if (IS_ERR(tg)) |
8929 | return ERR_PTR(-ENOMEM); | 9114 | return ERR_PTR(-ENOMEM); |
8930 | 9115 | ||
8931 | /* Bind the cgroup to task_group object we just created */ | ||
8932 | tg->css.cgroup = cgrp; | ||
8933 | |||
8934 | return &tg->css; | 9116 | return &tg->css; |
8935 | } | 9117 | } |
8936 | 9118 | ||
diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c index 204991a0bfa7..81787248b60f 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> |
@@ -54,7 +52,6 @@ struct sched_clock_data { | |||
54 | */ | 52 | */ |
55 | raw_spinlock_t lock; | 53 | raw_spinlock_t lock; |
56 | 54 | ||
57 | unsigned long tick_jiffies; | ||
58 | u64 tick_raw; | 55 | u64 tick_raw; |
59 | u64 tick_gtod; | 56 | u64 tick_gtod; |
60 | u64 clock; | 57 | u64 clock; |
@@ -75,14 +72,12 @@ static inline struct sched_clock_data *cpu_sdc(int cpu) | |||
75 | void sched_clock_init(void) | 72 | void sched_clock_init(void) |
76 | { | 73 | { |
77 | u64 ktime_now = ktime_to_ns(ktime_get()); | 74 | u64 ktime_now = ktime_to_ns(ktime_get()); |
78 | unsigned long now_jiffies = jiffies; | ||
79 | int cpu; | 75 | int cpu; |
80 | 76 | ||
81 | for_each_possible_cpu(cpu) { | 77 | for_each_possible_cpu(cpu) { |
82 | struct sched_clock_data *scd = cpu_sdc(cpu); | 78 | struct sched_clock_data *scd = cpu_sdc(cpu); |
83 | 79 | ||
84 | scd->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; | 80 | scd->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
85 | scd->tick_jiffies = now_jiffies; | ||
86 | scd->tick_raw = 0; | 81 | scd->tick_raw = 0; |
87 | scd->tick_gtod = ktime_now; | 82 | scd->tick_gtod = ktime_now; |
88 | scd->clock = ktime_now; | 83 | scd->clock = ktime_now; |
@@ -92,46 +87,51 @@ void sched_clock_init(void) | |||
92 | } | 87 | } |
93 | 88 | ||
94 | /* | 89 | /* |
90 | * min,max except they take wrapping into account | ||
91 | */ | ||
92 | |||
93 | static inline u64 wrap_min(u64 x, u64 y) | ||
94 | { | ||
95 | return (s64)(x - y) < 0 ? x : y; | ||
96 | } | ||
97 | |||
98 | static inline u64 wrap_max(u64 x, u64 y) | ||
99 | { | ||
100 | return (s64)(x - y) > 0 ? x : y; | ||
101 | } | ||
102 | |||
103 | /* | ||
95 | * update the percpu scd from the raw @now value | 104 | * update the percpu scd from the raw @now value |
96 | * | 105 | * |
97 | * - filter out backward motion | 106 | * - filter out backward motion |
98 | * - 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 |
99 | */ | 108 | */ |
100 | static u64 __update_sched_clock(struct sched_clock_data *scd, u64 now) | 109 | static u64 __update_sched_clock(struct sched_clock_data *scd, u64 now) |
101 | { | 110 | { |
102 | unsigned long now_jiffies = jiffies; | ||
103 | long delta_jiffies = now_jiffies - scd->tick_jiffies; | ||
104 | u64 clock = scd->clock; | ||
105 | u64 min_clock, max_clock; | ||
106 | s64 delta = now - scd->tick_raw; | 111 | s64 delta = now - scd->tick_raw; |
112 | u64 clock, min_clock, max_clock; | ||
107 | 113 | ||
108 | WARN_ON_ONCE(!irqs_disabled()); | 114 | WARN_ON_ONCE(!irqs_disabled()); |
109 | min_clock = scd->tick_gtod + delta_jiffies * TICK_NSEC; | ||
110 | 115 | ||
111 | if (unlikely(delta < 0)) { | 116 | if (unlikely(delta < 0)) |
112 | clock++; | 117 | delta = 0; |
113 | goto out; | ||
114 | } | ||
115 | 118 | ||
116 | max_clock = min_clock + TICK_NSEC; | 119 | /* |
120 | * scd->clock = clamp(scd->tick_gtod + delta, | ||
121 | * max(scd->tick_gtod, scd->clock), | ||
122 | * max(scd->clock, scd->tick_gtod + TICK_NSEC)); | ||
123 | */ | ||
117 | 124 | ||
118 | if (unlikely(clock + delta > max_clock)) { | 125 | clock = scd->tick_gtod + delta; |
119 | if (clock < max_clock) | 126 | min_clock = wrap_max(scd->tick_gtod, scd->clock); |
120 | clock = max_clock; | 127 | max_clock = wrap_max(scd->clock, scd->tick_gtod + TICK_NSEC); |
121 | else | ||
122 | clock++; | ||
123 | } else { | ||
124 | clock += delta; | ||
125 | } | ||
126 | 128 | ||
127 | out: | 129 | clock = wrap_max(clock, min_clock); |
128 | if (unlikely(clock < min_clock)) | 130 | clock = wrap_min(clock, max_clock); |
129 | clock = min_clock; | ||
130 | 131 | ||
131 | scd->tick_jiffies = now_jiffies; | ||
132 | scd->clock = clock; | 132 | scd->clock = clock; |
133 | 133 | ||
134 | return clock; | 134 | return scd->clock; |
135 | } | 135 | } |
136 | 136 | ||
137 | static void lock_double_clock(struct sched_clock_data *data1, | 137 | static void lock_double_clock(struct sched_clock_data *data1, |
@@ -171,7 +171,7 @@ u64 sched_clock_cpu(int cpu) | |||
171 | * larger time as the latest time for both | 171 | * larger time as the latest time for both |
172 | * runqueues. (this creates monotonic movement) | 172 | * runqueues. (this creates monotonic movement) |
173 | */ | 173 | */ |
174 | if (likely(remote_clock < this_clock)) { | 174 | if (likely((s64)(remote_clock - this_clock) < 0)) { |
175 | clock = this_clock; | 175 | clock = this_clock; |
176 | scd->clock = clock; | 176 | scd->clock = clock; |
177 | } else { | 177 | } else { |
@@ -207,14 +207,9 @@ void sched_clock_tick(void) | |||
207 | now = sched_clock(); | 207 | now = sched_clock(); |
208 | 208 | ||
209 | __raw_spin_lock(&scd->lock); | 209 | __raw_spin_lock(&scd->lock); |
210 | __update_sched_clock(scd, now); | ||
211 | /* | ||
212 | * update tick_gtod after __update_sched_clock() because that will | ||
213 | * already observe 1 new jiffy; adding a new tick_gtod to that would | ||
214 | * increase the clock 2 jiffies. | ||
215 | */ | ||
216 | scd->tick_raw = now; | 210 | scd->tick_raw = now; |
217 | scd->tick_gtod = now_gtod; | 211 | scd->tick_gtod = now_gtod; |
212 | __update_sched_clock(scd, now); | ||
218 | __raw_spin_unlock(&scd->lock); | 213 | __raw_spin_unlock(&scd->lock); |
219 | } | 214 | } |
220 | 215 | ||
@@ -232,18 +227,7 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_sleep_event); | |||
232 | */ | 227 | */ |
233 | void sched_clock_idle_wakeup_event(u64 delta_ns) | 228 | void sched_clock_idle_wakeup_event(u64 delta_ns) |
234 | { | 229 | { |
235 | struct sched_clock_data *scd = this_scd(); | 230 | sched_clock_tick(); |
236 | |||
237 | /* | ||
238 | * Override the previous timestamp and ignore all | ||
239 | * sched_clock() deltas that occured while we idled, | ||
240 | * and use the PM-provided delta_ns to advance the | ||
241 | * rq clock: | ||
242 | */ | ||
243 | __raw_spin_lock(&scd->lock); | ||
244 | scd->clock += delta_ns; | ||
245 | __raw_spin_unlock(&scd->lock); | ||
246 | |||
247 | touch_softlockup_watchdog(); | 231 | touch_softlockup_watchdog(); |
248 | } | 232 | } |
249 | EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); | 233 | EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); |
diff --git a/kernel/sched_debug.c b/kernel/sched_debug.c index bbe6b31c3c56..ad958c1ec708 100644 --- a/kernel/sched_debug.c +++ b/kernel/sched_debug.c | |||
@@ -333,12 +333,10 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m) | |||
333 | unsigned long flags; | 333 | unsigned long flags; |
334 | int num_threads = 1; | 334 | int num_threads = 1; |
335 | 335 | ||
336 | rcu_read_lock(); | ||
337 | if (lock_task_sighand(p, &flags)) { | 336 | if (lock_task_sighand(p, &flags)) { |
338 | num_threads = atomic_read(&p->signal->count); | 337 | num_threads = atomic_read(&p->signal->count); |
339 | unlock_task_sighand(p, &flags); | 338 | unlock_task_sighand(p, &flags); |
340 | } | 339 | } |
341 | rcu_read_unlock(); | ||
342 | 340 | ||
343 | SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, p->pid, num_threads); | 341 | SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, p->pid, num_threads); |
344 | SEQ_printf(m, | 342 | SEQ_printf(m, |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index fb8994c6d4bb..f604dae71316 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 | */ |
@@ -507,6 +449,7 @@ static void update_curr(struct cfs_rq *cfs_rq) | |||
507 | struct task_struct *curtask = task_of(curr); | 449 | struct task_struct *curtask = task_of(curr); |
508 | 450 | ||
509 | cpuacct_charge(curtask, delta_exec); | 451 | cpuacct_charge(curtask, delta_exec); |
452 | account_group_exec_runtime(curtask, delta_exec); | ||
510 | } | 453 | } |
511 | } | 454 | } |
512 | 455 | ||
@@ -586,11 +529,12 @@ account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
586 | update_load_add(&cfs_rq->load, se->load.weight); | 529 | update_load_add(&cfs_rq->load, se->load.weight); |
587 | if (!parent_entity(se)) | 530 | if (!parent_entity(se)) |
588 | inc_cpu_load(rq_of(cfs_rq), se->load.weight); | 531 | inc_cpu_load(rq_of(cfs_rq), se->load.weight); |
589 | if (entity_is_task(se)) | 532 | if (entity_is_task(se)) { |
590 | add_cfs_task_weight(cfs_rq, se->load.weight); | 533 | add_cfs_task_weight(cfs_rq, se->load.weight); |
534 | list_add(&se->group_node, &cfs_rq->tasks); | ||
535 | } | ||
591 | cfs_rq->nr_running++; | 536 | cfs_rq->nr_running++; |
592 | se->on_rq = 1; | 537 | se->on_rq = 1; |
593 | list_add(&se->group_node, &cfs_rq->tasks); | ||
594 | } | 538 | } |
595 | 539 | ||
596 | static void | 540 | static void |
@@ -599,11 +543,12 @@ account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
599 | update_load_sub(&cfs_rq->load, se->load.weight); | 543 | update_load_sub(&cfs_rq->load, se->load.weight); |
600 | if (!parent_entity(se)) | 544 | if (!parent_entity(se)) |
601 | dec_cpu_load(rq_of(cfs_rq), se->load.weight); | 545 | dec_cpu_load(rq_of(cfs_rq), se->load.weight); |
602 | if (entity_is_task(se)) | 546 | if (entity_is_task(se)) { |
603 | add_cfs_task_weight(cfs_rq, -se->load.weight); | 547 | add_cfs_task_weight(cfs_rq, -se->load.weight); |
548 | list_del_init(&se->group_node); | ||
549 | } | ||
604 | cfs_rq->nr_running--; | 550 | cfs_rq->nr_running--; |
605 | se->on_rq = 0; | 551 | se->on_rq = 0; |
606 | list_del_init(&se->group_node); | ||
607 | } | 552 | } |
608 | 553 | ||
609 | static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) | 554 | static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) |
@@ -1085,7 +1030,6 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1085 | long wl, long wg) | 1030 | long wl, long wg) |
1086 | { | 1031 | { |
1087 | struct sched_entity *se = tg->se[cpu]; | 1032 | struct sched_entity *se = tg->se[cpu]; |
1088 | long more_w; | ||
1089 | 1033 | ||
1090 | if (!tg->parent) | 1034 | if (!tg->parent) |
1091 | return wl; | 1035 | return wl; |
@@ -1097,18 +1041,17 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1097 | if (!wl && sched_feat(ASYM_EFF_LOAD)) | 1041 | if (!wl && sched_feat(ASYM_EFF_LOAD)) |
1098 | return wl; | 1042 | return wl; |
1099 | 1043 | ||
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) { | 1044 | for_each_sched_entity(se) { |
1109 | #define D(n) (likely(n) ? (n) : 1) | ||
1110 | |||
1111 | long S, rw, s, a, b; | 1045 | long S, rw, s, a, b; |
1046 | long more_w; | ||
1047 | |||
1048 | /* | ||
1049 | * Instead of using this increment, also add the difference | ||
1050 | * between when the shares were last updated and now. | ||
1051 | */ | ||
1052 | more_w = se->my_q->load.weight - se->my_q->rq_weight; | ||
1053 | wl += more_w; | ||
1054 | wg += more_w; | ||
1112 | 1055 | ||
1113 | S = se->my_q->tg->shares; | 1056 | S = se->my_q->tg->shares; |
1114 | s = se->my_q->shares; | 1057 | s = se->my_q->shares; |
@@ -1117,7 +1060,11 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1117 | a = S*(rw + wl); | 1060 | a = S*(rw + wl); |
1118 | b = S*rw + s*wg; | 1061 | b = S*rw + s*wg; |
1119 | 1062 | ||
1120 | wl = s*(a-b)/D(b); | 1063 | wl = s*(a-b); |
1064 | |||
1065 | if (likely(b)) | ||
1066 | wl /= b; | ||
1067 | |||
1121 | /* | 1068 | /* |
1122 | * Assume the group is already running and will | 1069 | * Assume the group is already running and will |
1123 | * thus already be accounted for in the weight. | 1070 | * thus already be accounted for in the weight. |
@@ -1126,7 +1073,6 @@ static long effective_load(struct task_group *tg, int cpu, | |||
1126 | * alter the group weight. | 1073 | * alter the group weight. |
1127 | */ | 1074 | */ |
1128 | wg = 0; | 1075 | wg = 0; |
1129 | #undef D | ||
1130 | } | 1076 | } |
1131 | 1077 | ||
1132 | return wl; | 1078 | return wl; |
@@ -1143,7 +1089,7 @@ static inline unsigned long effective_load(struct task_group *tg, int cpu, | |||
1143 | #endif | 1089 | #endif |
1144 | 1090 | ||
1145 | static int | 1091 | static int |
1146 | wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq, | 1092 | wake_affine(struct sched_domain *this_sd, struct rq *this_rq, |
1147 | struct task_struct *p, int prev_cpu, int this_cpu, int sync, | 1093 | struct task_struct *p, int prev_cpu, int this_cpu, int sync, |
1148 | int idx, unsigned long load, unsigned long this_load, | 1094 | int idx, unsigned long load, unsigned long this_load, |
1149 | unsigned int imbalance) | 1095 | unsigned int imbalance) |
@@ -1158,6 +1104,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)) | 1104 | if (!(this_sd->flags & SD_WAKE_AFFINE) || !sched_feat(AFFINE_WAKEUPS)) |
1159 | return 0; | 1105 | return 0; |
1160 | 1106 | ||
1107 | if (!sync && sched_feat(SYNC_WAKEUPS) && | ||
1108 | curr->se.avg_overlap < sysctl_sched_migration_cost && | ||
1109 | p->se.avg_overlap < sysctl_sched_migration_cost) | ||
1110 | sync = 1; | ||
1111 | |||
1161 | /* | 1112 | /* |
1162 | * If sync wakeup then subtract the (maximum possible) | 1113 | * If sync wakeup then subtract the (maximum possible) |
1163 | * effect of the currently running task from the load | 1114 | * effect of the currently running task from the load |
@@ -1182,17 +1133,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 | 1133 | * a reasonable amount of time then attract this newly |
1183 | * woken task: | 1134 | * woken task: |
1184 | */ | 1135 | */ |
1185 | if (sync && balanced) { | 1136 | if (sync && balanced) |
1186 | if (curr->se.avg_overlap < sysctl_sched_migration_cost && | 1137 | return 1; |
1187 | p->se.avg_overlap < sysctl_sched_migration_cost) | ||
1188 | return 1; | ||
1189 | } | ||
1190 | 1138 | ||
1191 | schedstat_inc(p, se.nr_wakeups_affine_attempts); | 1139 | schedstat_inc(p, se.nr_wakeups_affine_attempts); |
1192 | tl_per_task = cpu_avg_load_per_task(this_cpu); | 1140 | tl_per_task = cpu_avg_load_per_task(this_cpu); |
1193 | 1141 | ||
1194 | if ((tl <= load && tl + target_load(prev_cpu, idx) <= tl_per_task) || | 1142 | if (balanced || (tl <= load && tl + target_load(prev_cpu, idx) <= |
1195 | balanced) { | 1143 | tl_per_task)) { |
1196 | /* | 1144 | /* |
1197 | * This domain has SD_WAKE_AFFINE and | 1145 | * This domain has SD_WAKE_AFFINE and |
1198 | * p is cache cold in this domain, and | 1146 | * p is cache cold in this domain, and |
@@ -1211,16 +1159,17 @@ static int select_task_rq_fair(struct task_struct *p, int sync) | |||
1211 | struct sched_domain *sd, *this_sd = NULL; | 1159 | struct sched_domain *sd, *this_sd = NULL; |
1212 | int prev_cpu, this_cpu, new_cpu; | 1160 | int prev_cpu, this_cpu, new_cpu; |
1213 | unsigned long load, this_load; | 1161 | unsigned long load, this_load; |
1214 | struct rq *rq, *this_rq; | 1162 | struct rq *this_rq; |
1215 | unsigned int imbalance; | 1163 | unsigned int imbalance; |
1216 | int idx; | 1164 | int idx; |
1217 | 1165 | ||
1218 | prev_cpu = task_cpu(p); | 1166 | prev_cpu = task_cpu(p); |
1219 | rq = task_rq(p); | ||
1220 | this_cpu = smp_processor_id(); | 1167 | this_cpu = smp_processor_id(); |
1221 | this_rq = cpu_rq(this_cpu); | 1168 | this_rq = cpu_rq(this_cpu); |
1222 | new_cpu = prev_cpu; | 1169 | new_cpu = prev_cpu; |
1223 | 1170 | ||
1171 | if (prev_cpu == this_cpu) | ||
1172 | goto out; | ||
1224 | /* | 1173 | /* |
1225 | * 'this_sd' is the first domain that both | 1174 | * 'this_sd' is the first domain that both |
1226 | * this_cpu and prev_cpu are present in: | 1175 | * this_cpu and prev_cpu are present in: |
@@ -1248,13 +1197,10 @@ static int select_task_rq_fair(struct task_struct *p, int sync) | |||
1248 | load = source_load(prev_cpu, idx); | 1197 | load = source_load(prev_cpu, idx); |
1249 | this_load = target_load(this_cpu, idx); | 1198 | this_load = target_load(this_cpu, idx); |
1250 | 1199 | ||
1251 | if (wake_affine(rq, this_sd, this_rq, p, prev_cpu, this_cpu, sync, idx, | 1200 | if (wake_affine(this_sd, this_rq, p, prev_cpu, this_cpu, sync, idx, |
1252 | load, this_load, imbalance)) | 1201 | load, this_load, imbalance)) |
1253 | return this_cpu; | 1202 | return this_cpu; |
1254 | 1203 | ||
1255 | if (prev_cpu == this_cpu) | ||
1256 | goto out; | ||
1257 | |||
1258 | /* | 1204 | /* |
1259 | * Start passive balancing when half the imbalance_pct | 1205 | * Start passive balancing when half the imbalance_pct |
1260 | * limit is reached. | 1206 | * limit is reached. |
@@ -1281,62 +1227,20 @@ static unsigned long wakeup_gran(struct sched_entity *se) | |||
1281 | * + nice tasks. | 1227 | * + nice tasks. |
1282 | */ | 1228 | */ |
1283 | if (sched_feat(ASYM_GRAN)) | 1229 | if (sched_feat(ASYM_GRAN)) |
1284 | gran = calc_delta_asym(sysctl_sched_wakeup_granularity, se); | 1230 | gran = calc_delta_mine(gran, NICE_0_LOAD, &se->load); |
1285 | else | ||
1286 | gran = calc_delta_fair(sysctl_sched_wakeup_granularity, se); | ||
1287 | 1231 | ||
1288 | return gran; | 1232 | return gran; |
1289 | } | 1233 | } |
1290 | 1234 | ||
1291 | /* | 1235 | /* |
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: | 1236 | * Preempt the current task with a newly woken task if needed: |
1333 | */ | 1237 | */ |
1334 | static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) | 1238 | static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int sync) |
1335 | { | 1239 | { |
1336 | struct task_struct *curr = rq->curr; | 1240 | struct task_struct *curr = rq->curr; |
1337 | struct cfs_rq *cfs_rq = task_cfs_rq(curr); | 1241 | struct cfs_rq *cfs_rq = task_cfs_rq(curr); |
1338 | struct sched_entity *se = &curr->se, *pse = &p->se; | 1242 | struct sched_entity *se = &curr->se, *pse = &p->se; |
1339 | int se_depth, pse_depth; | 1243 | s64 delta_exec; |
1340 | 1244 | ||
1341 | if (unlikely(rt_prio(p->prio))) { | 1245 | if (unlikely(rt_prio(p->prio))) { |
1342 | update_rq_clock(rq); | 1246 | update_rq_clock(rq); |
@@ -1351,6 +1255,13 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) | |||
1351 | cfs_rq_of(pse)->next = pse; | 1255 | cfs_rq_of(pse)->next = pse; |
1352 | 1256 | ||
1353 | /* | 1257 | /* |
1258 | * We can come here with TIF_NEED_RESCHED already set from new task | ||
1259 | * wake up path. | ||
1260 | */ | ||
1261 | if (test_tsk_need_resched(curr)) | ||
1262 | return; | ||
1263 | |||
1264 | /* | ||
1354 | * Batch tasks do not preempt (their preemption is driven by | 1265 | * Batch tasks do not preempt (their preemption is driven by |
1355 | * the tick): | 1266 | * the tick): |
1356 | */ | 1267 | */ |
@@ -1360,33 +1271,15 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) | |||
1360 | if (!sched_feat(WAKEUP_PREEMPT)) | 1271 | if (!sched_feat(WAKEUP_PREEMPT)) |
1361 | return; | 1272 | return; |
1362 | 1273 | ||
1363 | /* | 1274 | if (sched_feat(WAKEUP_OVERLAP) && (sync || |
1364 | * preemption test can be made between sibling entities who are in the | 1275 | (se->avg_overlap < sysctl_sched_migration_cost && |
1365 | * same cfs_rq i.e who have a common parent. Walk up the hierarchy of | 1276 | pse->avg_overlap < sysctl_sched_migration_cost))) { |
1366 | * both tasks until we find their ancestors who are siblings of common | 1277 | resched_task(curr); |
1367 | * parent. | 1278 | 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 | } | 1279 | } |
1388 | 1280 | ||
1389 | if (wakeup_preempt_entity(se, pse) == 1) | 1281 | delta_exec = se->sum_exec_runtime - se->prev_sum_exec_runtime; |
1282 | if (delta_exec > wakeup_gran(pse)) | ||
1390 | resched_task(curr); | 1283 | resched_task(curr); |
1391 | } | 1284 | } |
1392 | 1285 | ||
@@ -1445,19 +1338,9 @@ __load_balance_iterator(struct cfs_rq *cfs_rq, struct list_head *next) | |||
1445 | if (next == &cfs_rq->tasks) | 1338 | if (next == &cfs_rq->tasks) |
1446 | return NULL; | 1339 | return NULL; |
1447 | 1340 | ||
1448 | /* Skip over entities that are not tasks */ | 1341 | se = list_entry(next, struct sched_entity, group_node); |
1449 | do { | 1342 | p = task_of(se); |
1450 | se = list_entry(next, struct sched_entity, group_node); | 1343 | cfs_rq->balance_iterator = next->next; |
1451 | next = next->next; | ||
1452 | } while (next != &cfs_rq->tasks && !entity_is_task(se)); | ||
1453 | |||
1454 | if (next == &cfs_rq->tasks) | ||
1455 | return NULL; | ||
1456 | |||
1457 | cfs_rq->balance_iterator = next; | ||
1458 | |||
1459 | if (entity_is_task(se)) | ||
1460 | p = task_of(se); | ||
1461 | 1344 | ||
1462 | return p; | 1345 | return p; |
1463 | } | 1346 | } |
@@ -1507,7 +1390,7 @@ load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest, | |||
1507 | rcu_read_lock(); | 1390 | rcu_read_lock(); |
1508 | update_h_load(busiest_cpu); | 1391 | update_h_load(busiest_cpu); |
1509 | 1392 | ||
1510 | list_for_each_entry(tg, &task_groups, list) { | 1393 | list_for_each_entry_rcu(tg, &task_groups, list) { |
1511 | struct cfs_rq *busiest_cfs_rq = tg->cfs_rq[busiest_cpu]; | 1394 | struct cfs_rq *busiest_cfs_rq = tg->cfs_rq[busiest_cpu]; |
1512 | unsigned long busiest_h_load = busiest_cfs_rq->h_load; | 1395 | unsigned long busiest_h_load = busiest_cfs_rq->h_load; |
1513 | unsigned long busiest_weight = busiest_cfs_rq->load.weight; | 1396 | unsigned long busiest_weight = busiest_cfs_rq->load.weight; |
@@ -1620,10 +1503,10 @@ static void task_new_fair(struct rq *rq, struct task_struct *p) | |||
1620 | * 'current' within the tree based on its new key value. | 1503 | * 'current' within the tree based on its new key value. |
1621 | */ | 1504 | */ |
1622 | swap(curr->vruntime, se->vruntime); | 1505 | swap(curr->vruntime, se->vruntime); |
1506 | resched_task(rq->curr); | ||
1623 | } | 1507 | } |
1624 | 1508 | ||
1625 | enqueue_task_fair(rq, p, 0); | 1509 | enqueue_task_fair(rq, p, 0); |
1626 | resched_task(rq->curr); | ||
1627 | } | 1510 | } |
1628 | 1511 | ||
1629 | /* | 1512 | /* |
@@ -1642,7 +1525,7 @@ static void prio_changed_fair(struct rq *rq, struct task_struct *p, | |||
1642 | if (p->prio > oldprio) | 1525 | if (p->prio > oldprio) |
1643 | resched_task(rq->curr); | 1526 | resched_task(rq->curr); |
1644 | } else | 1527 | } else |
1645 | check_preempt_curr(rq, p); | 1528 | check_preempt_curr(rq, p, 0); |
1646 | } | 1529 | } |
1647 | 1530 | ||
1648 | /* | 1531 | /* |
@@ -1659,7 +1542,7 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p, | |||
1659 | if (running) | 1542 | if (running) |
1660 | resched_task(rq->curr); | 1543 | resched_task(rq->curr); |
1661 | else | 1544 | else |
1662 | check_preempt_curr(rq, p); | 1545 | check_preempt_curr(rq, p, 0); |
1663 | } | 1546 | } |
1664 | 1547 | ||
1665 | /* Account for a task changing its policy or group. | 1548 | /* 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 998ba54b4543..b446dc87494f 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,17 +304,33 @@ 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 | ||
331 | /* | ||
332 | * Can't reclaim from ourselves or disabled runqueues. | ||
333 | */ | ||
301 | if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) | 334 | if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) |
302 | continue; | 335 | continue; |
303 | 336 | ||
@@ -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 | ||
@@ -484,16 +526,23 @@ static void update_curr_rt(struct rq *rq) | |||
484 | schedstat_set(curr->se.exec_max, max(curr->se.exec_max, delta_exec)); | 526 | schedstat_set(curr->se.exec_max, max(curr->se.exec_max, delta_exec)); |
485 | 527 | ||
486 | curr->se.sum_exec_runtime += delta_exec; | 528 | curr->se.sum_exec_runtime += delta_exec; |
529 | account_group_exec_runtime(curr, delta_exec); | ||
530 | |||
487 | curr->se.exec_start = rq->clock; | 531 | curr->se.exec_start = rq->clock; |
488 | cpuacct_charge(curr, delta_exec); | 532 | cpuacct_charge(curr, delta_exec); |
489 | 533 | ||
534 | if (!rt_bandwidth_enabled()) | ||
535 | return; | ||
536 | |||
490 | for_each_sched_rt_entity(rt_se) { | 537 | for_each_sched_rt_entity(rt_se) { |
491 | rt_rq = rt_rq_of_se(rt_se); | 538 | rt_rq = rt_rq_of_se(rt_se); |
492 | 539 | ||
493 | spin_lock(&rt_rq->rt_runtime_lock); | 540 | spin_lock(&rt_rq->rt_runtime_lock); |
494 | rt_rq->rt_time += delta_exec; | 541 | if (sched_rt_runtime(rt_rq) != RUNTIME_INF) { |
495 | if (sched_rt_runtime_exceeded(rt_rq)) | 542 | rt_rq->rt_time += delta_exec; |
496 | resched_task(curr); | 543 | if (sched_rt_runtime_exceeded(rt_rq)) |
544 | resched_task(curr); | ||
545 | } | ||
497 | spin_unlock(&rt_rq->rt_runtime_lock); | 546 | spin_unlock(&rt_rq->rt_runtime_lock); |
498 | } | 547 | } |
499 | } | 548 | } |
@@ -782,7 +831,7 @@ static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) | |||
782 | /* | 831 | /* |
783 | * Preempt the current task with a newly woken task if needed: | 832 | * Preempt the current task with a newly woken task if needed: |
784 | */ | 833 | */ |
785 | static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p) | 834 | static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int sync) |
786 | { | 835 | { |
787 | if (p->prio < rq->curr->prio) { | 836 | if (p->prio < rq->curr->prio) { |
788 | resched_task(rq->curr); | 837 | resched_task(rq->curr); |
@@ -1411,7 +1460,7 @@ static void watchdog(struct rq *rq, struct task_struct *p) | |||
1411 | p->rt.timeout++; | 1460 | p->rt.timeout++; |
1412 | next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ); | 1461 | next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ); |
1413 | if (p->rt.timeout > next) | 1462 | if (p->rt.timeout > next) |
1414 | p->it_sched_expires = p->se.sum_exec_runtime; | 1463 | p->cputime_expires.sched_exp = p->se.sum_exec_runtime; |
1415 | } | 1464 | } |
1416 | } | 1465 | } |
1417 | 1466 | ||
diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h index 8385d43987e2..b8c156979cf2 100644 --- a/kernel/sched_stats.h +++ b/kernel/sched_stats.h | |||
@@ -270,3 +270,89 @@ sched_info_switch(struct task_struct *prev, struct task_struct *next) | |||
270 | #define sched_info_switch(t, next) do { } while (0) | 270 | #define sched_info_switch(t, next) do { } while (0) |
271 | #endif /* CONFIG_SCHEDSTATS || CONFIG_TASK_DELAY_ACCT */ | 271 | #endif /* CONFIG_SCHEDSTATS || CONFIG_TASK_DELAY_ACCT */ |
272 | 272 | ||
273 | /* | ||
274 | * The following are functions that support scheduler-internal time accounting. | ||
275 | * These functions are generally called at the timer tick. None of this depends | ||
276 | * on CONFIG_SCHEDSTATS. | ||
277 | */ | ||
278 | |||
279 | /** | ||
280 | * account_group_user_time - Maintain utime for a thread group. | ||
281 | * | ||
282 | * @tsk: Pointer to task structure. | ||
283 | * @cputime: Time value by which to increment the utime field of the | ||
284 | * thread_group_cputime structure. | ||
285 | * | ||
286 | * If thread group time is being maintained, get the structure for the | ||
287 | * running CPU and update the utime field there. | ||
288 | */ | ||
289 | static inline void account_group_user_time(struct task_struct *tsk, | ||
290 | cputime_t cputime) | ||
291 | { | ||
292 | struct signal_struct *sig; | ||
293 | |||
294 | sig = tsk->signal; | ||
295 | if (unlikely(!sig)) | ||
296 | return; | ||
297 | if (sig->cputime.totals) { | ||
298 | struct task_cputime *times; | ||
299 | |||
300 | times = per_cpu_ptr(sig->cputime.totals, get_cpu()); | ||
301 | times->utime = cputime_add(times->utime, cputime); | ||
302 | put_cpu_no_resched(); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * account_group_system_time - Maintain stime for a thread group. | ||
308 | * | ||
309 | * @tsk: Pointer to task structure. | ||
310 | * @cputime: Time value by which to increment the stime field of the | ||
311 | * thread_group_cputime structure. | ||
312 | * | ||
313 | * If thread group time is being maintained, get the structure for the | ||
314 | * running CPU and update the stime field there. | ||
315 | */ | ||
316 | static inline void account_group_system_time(struct task_struct *tsk, | ||
317 | cputime_t cputime) | ||
318 | { | ||
319 | struct signal_struct *sig; | ||
320 | |||
321 | sig = tsk->signal; | ||
322 | if (unlikely(!sig)) | ||
323 | return; | ||
324 | if (sig->cputime.totals) { | ||
325 | struct task_cputime *times; | ||
326 | |||
327 | times = per_cpu_ptr(sig->cputime.totals, get_cpu()); | ||
328 | times->stime = cputime_add(times->stime, cputime); | ||
329 | put_cpu_no_resched(); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * account_group_exec_runtime - Maintain exec runtime for a thread group. | ||
335 | * | ||
336 | * @tsk: Pointer to task structure. | ||
337 | * @ns: Time value by which to increment the sum_exec_runtime field | ||
338 | * of the thread_group_cputime structure. | ||
339 | * | ||
340 | * If thread group time is being maintained, get the structure for the | ||
341 | * running CPU and update the sum_exec_runtime field there. | ||
342 | */ | ||
343 | static inline void account_group_exec_runtime(struct task_struct *tsk, | ||
344 | unsigned long long ns) | ||
345 | { | ||
346 | struct signal_struct *sig; | ||
347 | |||
348 | sig = tsk->signal; | ||
349 | if (unlikely(!sig)) | ||
350 | return; | ||
351 | if (sig->cputime.totals) { | ||
352 | struct task_cputime *times; | ||
353 | |||
354 | times = per_cpu_ptr(sig->cputime.totals, get_cpu()); | ||
355 | times->sum_exec_runtime += ns; | ||
356 | put_cpu_no_resched(); | ||
357 | } | ||
358 | } | ||
diff --git a/kernel/signal.c b/kernel/signal.c index e661b01d340f..6eea5826d618 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -1338,6 +1338,7 @@ int do_notify_parent(struct task_struct *tsk, int sig) | |||
1338 | struct siginfo info; | 1338 | struct siginfo info; |
1339 | unsigned long flags; | 1339 | unsigned long flags; |
1340 | struct sighand_struct *psig; | 1340 | struct sighand_struct *psig; |
1341 | struct task_cputime cputime; | ||
1341 | int ret = sig; | 1342 | int ret = sig; |
1342 | 1343 | ||
1343 | BUG_ON(sig == -1); | 1344 | BUG_ON(sig == -1); |
@@ -1368,10 +1369,9 @@ int do_notify_parent(struct task_struct *tsk, int sig) | |||
1368 | 1369 | ||
1369 | info.si_uid = tsk->uid; | 1370 | info.si_uid = tsk->uid; |
1370 | 1371 | ||
1371 | info.si_utime = cputime_to_clock_t(cputime_add(tsk->utime, | 1372 | thread_group_cputime(tsk, &cputime); |
1372 | tsk->signal->utime)); | 1373 | info.si_utime = cputime_to_jiffies(cputime.utime); |
1373 | info.si_stime = cputime_to_clock_t(cputime_add(tsk->stime, | 1374 | info.si_stime = cputime_to_jiffies(cputime.stime); |
1374 | tsk->signal->stime)); | ||
1375 | 1375 | ||
1376 | info.si_status = tsk->exit_code & 0x7f; | 1376 | info.si_status = tsk->exit_code & 0x7f; |
1377 | if (tsk->exit_code & 0x80) | 1377 | if (tsk->exit_code & 0x80) |
diff --git a/kernel/smp.c b/kernel/smp.c index 782e2b93e465..f362a8553777 100644 --- a/kernel/smp.c +++ b/kernel/smp.c | |||
@@ -210,8 +210,10 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
210 | { | 210 | { |
211 | struct call_single_data d; | 211 | struct call_single_data d; |
212 | unsigned long flags; | 212 | unsigned long flags; |
213 | /* prevent preemption and reschedule on another processor */ | 213 | /* prevent preemption and reschedule on another processor, |
214 | as well as CPU removal */ | ||
214 | int me = get_cpu(); | 215 | int me = get_cpu(); |
216 | int err = 0; | ||
215 | 217 | ||
216 | /* Can deadlock when called with interrupts disabled */ | 218 | /* Can deadlock when called with interrupts disabled */ |
217 | WARN_ON(irqs_disabled()); | 219 | WARN_ON(irqs_disabled()); |
@@ -220,7 +222,7 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
220 | local_irq_save(flags); | 222 | local_irq_save(flags); |
221 | func(info); | 223 | func(info); |
222 | local_irq_restore(flags); | 224 | local_irq_restore(flags); |
223 | } else { | 225 | } else if ((unsigned)cpu < NR_CPUS && cpu_online(cpu)) { |
224 | struct call_single_data *data = NULL; | 226 | struct call_single_data *data = NULL; |
225 | 227 | ||
226 | if (!wait) { | 228 | if (!wait) { |
@@ -236,10 +238,12 @@ int smp_call_function_single(int cpu, void (*func) (void *info), void *info, | |||
236 | data->func = func; | 238 | data->func = func; |
237 | data->info = info; | 239 | data->info = info; |
238 | generic_exec_single(cpu, data); | 240 | generic_exec_single(cpu, data); |
241 | } else { | ||
242 | err = -ENXIO; /* CPU not online */ | ||
239 | } | 243 | } |
240 | 244 | ||
241 | put_cpu(); | 245 | put_cpu(); |
242 | return 0; | 246 | return err; |
243 | } | 247 | } |
244 | EXPORT_SYMBOL(smp_call_function_single); | 248 | EXPORT_SYMBOL(smp_call_function_single); |
245 | 249 | ||
diff --git a/kernel/softirq.c b/kernel/softirq.c index c506f266a6b9..7110daeb9a90 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
@@ -6,6 +6,8 @@ | |||
6 | * Distribute under GPLv2. | 6 | * Distribute under GPLv2. |
7 | * | 7 | * |
8 | * Rewritten. Old one was good in 2.2, but in 2.3 it was immoral. --ANK (990903) | 8 | * Rewritten. Old one was good in 2.2, but in 2.3 it was immoral. --ANK (990903) |
9 | * | ||
10 | * Remote softirq infrastructure is by Jens Axboe. | ||
9 | */ | 11 | */ |
10 | 12 | ||
11 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -46,7 +48,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned; | |||
46 | EXPORT_SYMBOL(irq_stat); | 48 | EXPORT_SYMBOL(irq_stat); |
47 | #endif | 49 | #endif |
48 | 50 | ||
49 | static struct softirq_action softirq_vec[32] __cacheline_aligned_in_smp; | 51 | static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp; |
50 | 52 | ||
51 | static DEFINE_PER_CPU(struct task_struct *, ksoftirqd); | 53 | static DEFINE_PER_CPU(struct task_struct *, ksoftirqd); |
52 | 54 | ||
@@ -205,7 +207,18 @@ restart: | |||
205 | 207 | ||
206 | do { | 208 | do { |
207 | if (pending & 1) { | 209 | if (pending & 1) { |
210 | int prev_count = preempt_count(); | ||
211 | |||
208 | h->action(h); | 212 | h->action(h); |
213 | |||
214 | if (unlikely(prev_count != preempt_count())) { | ||
215 | printk(KERN_ERR "huh, entered softirq %td %p" | ||
216 | "with preempt_count %08x," | ||
217 | " exited with %08x?\n", h - softirq_vec, | ||
218 | h->action, prev_count, preempt_count()); | ||
219 | preempt_count() = prev_count; | ||
220 | } | ||
221 | |||
209 | rcu_bh_qsctr_inc(cpu); | 222 | rcu_bh_qsctr_inc(cpu); |
210 | } | 223 | } |
211 | h++; | 224 | h++; |
@@ -254,16 +267,12 @@ asmlinkage void do_softirq(void) | |||
254 | */ | 267 | */ |
255 | void irq_enter(void) | 268 | void irq_enter(void) |
256 | { | 269 | { |
257 | #ifdef CONFIG_NO_HZ | ||
258 | int cpu = smp_processor_id(); | 270 | int cpu = smp_processor_id(); |
271 | |||
259 | if (idle_cpu(cpu) && !in_interrupt()) | 272 | if (idle_cpu(cpu) && !in_interrupt()) |
260 | tick_nohz_stop_idle(cpu); | 273 | tick_check_idle(cpu); |
261 | #endif | 274 | |
262 | __irq_enter(); | 275 | __irq_enter(); |
263 | #ifdef CONFIG_NO_HZ | ||
264 | if (idle_cpu(cpu)) | ||
265 | tick_nohz_update_jiffies(); | ||
266 | #endif | ||
267 | } | 276 | } |
268 | 277 | ||
269 | #ifdef __ARCH_IRQ_EXIT_IRQS_DISABLED | 278 | #ifdef __ARCH_IRQ_EXIT_IRQS_DISABLED |
@@ -463,17 +472,144 @@ void tasklet_kill(struct tasklet_struct *t) | |||
463 | 472 | ||
464 | EXPORT_SYMBOL(tasklet_kill); | 473 | EXPORT_SYMBOL(tasklet_kill); |
465 | 474 | ||
475 | DEFINE_PER_CPU(struct list_head [NR_SOFTIRQS], softirq_work_list); | ||
476 | EXPORT_PER_CPU_SYMBOL(softirq_work_list); | ||
477 | |||
478 | static void __local_trigger(struct call_single_data *cp, int softirq) | ||
479 | { | ||
480 | struct list_head *head = &__get_cpu_var(softirq_work_list[softirq]); | ||
481 | |||
482 | list_add_tail(&cp->list, head); | ||
483 | |||
484 | /* Trigger the softirq only if the list was previously empty. */ | ||
485 | if (head->next == &cp->list) | ||
486 | raise_softirq_irqoff(softirq); | ||
487 | } | ||
488 | |||
489 | #ifdef CONFIG_USE_GENERIC_SMP_HELPERS | ||
490 | static void remote_softirq_receive(void *data) | ||
491 | { | ||
492 | struct call_single_data *cp = data; | ||
493 | unsigned long flags; | ||
494 | int softirq; | ||
495 | |||
496 | softirq = cp->priv; | ||
497 | |||
498 | local_irq_save(flags); | ||
499 | __local_trigger(cp, softirq); | ||
500 | local_irq_restore(flags); | ||
501 | } | ||
502 | |||
503 | static int __try_remote_softirq(struct call_single_data *cp, int cpu, int softirq) | ||
504 | { | ||
505 | if (cpu_online(cpu)) { | ||
506 | cp->func = remote_softirq_receive; | ||
507 | cp->info = cp; | ||
508 | cp->flags = 0; | ||
509 | cp->priv = softirq; | ||
510 | |||
511 | __smp_call_function_single(cpu, cp); | ||
512 | return 0; | ||
513 | } | ||
514 | return 1; | ||
515 | } | ||
516 | #else /* CONFIG_USE_GENERIC_SMP_HELPERS */ | ||
517 | static int __try_remote_softirq(struct call_single_data *cp, int cpu, int softirq) | ||
518 | { | ||
519 | return 1; | ||
520 | } | ||
521 | #endif | ||
522 | |||
523 | /** | ||
524 | * __send_remote_softirq - try to schedule softirq work on a remote cpu | ||
525 | * @cp: private SMP call function data area | ||
526 | * @cpu: the remote cpu | ||
527 | * @this_cpu: the currently executing cpu | ||
528 | * @softirq: the softirq for the work | ||
529 | * | ||
530 | * Attempt to schedule softirq work on a remote cpu. If this cannot be | ||
531 | * done, the work is instead queued up on the local cpu. | ||
532 | * | ||
533 | * Interrupts must be disabled. | ||
534 | */ | ||
535 | void __send_remote_softirq(struct call_single_data *cp, int cpu, int this_cpu, int softirq) | ||
536 | { | ||
537 | if (cpu == this_cpu || __try_remote_softirq(cp, cpu, softirq)) | ||
538 | __local_trigger(cp, softirq); | ||
539 | } | ||
540 | EXPORT_SYMBOL(__send_remote_softirq); | ||
541 | |||
542 | /** | ||
543 | * send_remote_softirq - try to schedule softirq work on a remote cpu | ||
544 | * @cp: private SMP call function data area | ||
545 | * @cpu: the remote cpu | ||
546 | * @softirq: the softirq for the work | ||
547 | * | ||
548 | * Like __send_remote_softirq except that disabling interrupts and | ||
549 | * computing the current cpu is done for the caller. | ||
550 | */ | ||
551 | void send_remote_softirq(struct call_single_data *cp, int cpu, int softirq) | ||
552 | { | ||
553 | unsigned long flags; | ||
554 | int this_cpu; | ||
555 | |||
556 | local_irq_save(flags); | ||
557 | this_cpu = smp_processor_id(); | ||
558 | __send_remote_softirq(cp, cpu, this_cpu, softirq); | ||
559 | local_irq_restore(flags); | ||
560 | } | ||
561 | EXPORT_SYMBOL(send_remote_softirq); | ||
562 | |||
563 | static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self, | ||
564 | unsigned long action, void *hcpu) | ||
565 | { | ||
566 | /* | ||
567 | * If a CPU goes away, splice its entries to the current CPU | ||
568 | * and trigger a run of the softirq | ||
569 | */ | ||
570 | if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) { | ||
571 | int cpu = (unsigned long) hcpu; | ||
572 | int i; | ||
573 | |||
574 | local_irq_disable(); | ||
575 | for (i = 0; i < NR_SOFTIRQS; i++) { | ||
576 | struct list_head *head = &per_cpu(softirq_work_list[i], cpu); | ||
577 | struct list_head *local_head; | ||
578 | |||
579 | if (list_empty(head)) | ||
580 | continue; | ||
581 | |||
582 | local_head = &__get_cpu_var(softirq_work_list[i]); | ||
583 | list_splice_init(head, local_head); | ||
584 | raise_softirq_irqoff(i); | ||
585 | } | ||
586 | local_irq_enable(); | ||
587 | } | ||
588 | |||
589 | return NOTIFY_OK; | ||
590 | } | ||
591 | |||
592 | static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = { | ||
593 | .notifier_call = remote_softirq_cpu_notify, | ||
594 | }; | ||
595 | |||
466 | void __init softirq_init(void) | 596 | void __init softirq_init(void) |
467 | { | 597 | { |
468 | int cpu; | 598 | int cpu; |
469 | 599 | ||
470 | for_each_possible_cpu(cpu) { | 600 | for_each_possible_cpu(cpu) { |
601 | int i; | ||
602 | |||
471 | per_cpu(tasklet_vec, cpu).tail = | 603 | per_cpu(tasklet_vec, cpu).tail = |
472 | &per_cpu(tasklet_vec, cpu).head; | 604 | &per_cpu(tasklet_vec, cpu).head; |
473 | per_cpu(tasklet_hi_vec, cpu).tail = | 605 | per_cpu(tasklet_hi_vec, cpu).tail = |
474 | &per_cpu(tasklet_hi_vec, cpu).head; | 606 | &per_cpu(tasklet_hi_vec, cpu).head; |
607 | for (i = 0; i < NR_SOFTIRQS; i++) | ||
608 | INIT_LIST_HEAD(&per_cpu(softirq_work_list[i], cpu)); | ||
475 | } | 609 | } |
476 | 610 | ||
611 | register_hotcpu_notifier(&remote_softirq_cpu_notifier); | ||
612 | |||
477 | open_softirq(TASKLET_SOFTIRQ, tasklet_action); | 613 | open_softirq(TASKLET_SOFTIRQ, tasklet_action); |
478 | open_softirq(HI_SOFTIRQ, tasklet_hi_action); | 614 | open_softirq(HI_SOFTIRQ, tasklet_hi_action); |
479 | } | 615 | } |
diff --git a/kernel/softlockup.c b/kernel/softlockup.c index b75b492fbfcf..3953e4aed733 100644 --- a/kernel/softlockup.c +++ b/kernel/softlockup.c | |||
@@ -226,14 +226,15 @@ static void check_hung_uninterruptible_tasks(int this_cpu) | |||
226 | * If the system crashed already then all bets are off, | 226 | * If the system crashed already then all bets are off, |
227 | * do not report extra hung tasks: | 227 | * do not report extra hung tasks: |
228 | */ | 228 | */ |
229 | if ((tainted & TAINT_DIE) || did_panic) | 229 | if (test_taint(TAINT_DIE) || did_panic) |
230 | return; | 230 | return; |
231 | 231 | ||
232 | read_lock(&tasklist_lock); | 232 | read_lock(&tasklist_lock); |
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: |
diff --git a/kernel/sys.c b/kernel/sys.c index 038a7bc0901d..53879cdae483 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -853,38 +853,28 @@ asmlinkage long sys_setfsgid(gid_t gid) | |||
853 | return old_fsgid; | 853 | return old_fsgid; |
854 | } | 854 | } |
855 | 855 | ||
856 | void do_sys_times(struct tms *tms) | ||
857 | { | ||
858 | struct task_cputime cputime; | ||
859 | cputime_t cutime, cstime; | ||
860 | |||
861 | spin_lock_irq(¤t->sighand->siglock); | ||
862 | thread_group_cputime(current, &cputime); | ||
863 | cutime = current->signal->cutime; | ||
864 | cstime = current->signal->cstime; | ||
865 | spin_unlock_irq(¤t->sighand->siglock); | ||
866 | tms->tms_utime = cputime_to_clock_t(cputime.utime); | ||
867 | tms->tms_stime = cputime_to_clock_t(cputime.stime); | ||
868 | tms->tms_cutime = cputime_to_clock_t(cutime); | ||
869 | tms->tms_cstime = cputime_to_clock_t(cstime); | ||
870 | } | ||
871 | |||
856 | asmlinkage long sys_times(struct tms __user * tbuf) | 872 | asmlinkage long sys_times(struct tms __user * tbuf) |
857 | { | 873 | { |
858 | /* | ||
859 | * In the SMP world we might just be unlucky and have one of | ||
860 | * the times increment as we use it. Since the value is an | ||
861 | * atomically safe type this is just fine. Conceptually its | ||
862 | * as if the syscall took an instant longer to occur. | ||
863 | */ | ||
864 | if (tbuf) { | 874 | if (tbuf) { |
865 | struct tms tmp; | 875 | struct tms tmp; |
866 | struct task_struct *tsk = current; | 876 | |
867 | struct task_struct *t; | 877 | do_sys_times(&tmp); |
868 | cputime_t utime, stime, cutime, cstime; | ||
869 | |||
870 | spin_lock_irq(&tsk->sighand->siglock); | ||
871 | utime = tsk->signal->utime; | ||
872 | stime = tsk->signal->stime; | ||
873 | t = tsk; | ||
874 | do { | ||
875 | utime = cputime_add(utime, t->utime); | ||
876 | stime = cputime_add(stime, t->stime); | ||
877 | t = next_thread(t); | ||
878 | } while (t != tsk); | ||
879 | |||
880 | cutime = tsk->signal->cutime; | ||
881 | cstime = tsk->signal->cstime; | ||
882 | spin_unlock_irq(&tsk->sighand->siglock); | ||
883 | |||
884 | tmp.tms_utime = cputime_to_clock_t(utime); | ||
885 | tmp.tms_stime = cputime_to_clock_t(stime); | ||
886 | tmp.tms_cutime = cputime_to_clock_t(cutime); | ||
887 | tmp.tms_cstime = cputime_to_clock_t(cstime); | ||
888 | if (copy_to_user(tbuf, &tmp, sizeof(struct tms))) | 878 | if (copy_to_user(tbuf, &tmp, sizeof(struct tms))) |
889 | return -EFAULT; | 879 | return -EFAULT; |
890 | } | 880 | } |
@@ -1060,9 +1050,7 @@ asmlinkage long sys_setsid(void) | |||
1060 | group_leader->signal->leader = 1; | 1050 | group_leader->signal->leader = 1; |
1061 | __set_special_pids(sid); | 1051 | __set_special_pids(sid); |
1062 | 1052 | ||
1063 | spin_lock(&group_leader->sighand->siglock); | 1053 | proc_clear_tty(group_leader); |
1064 | group_leader->signal->tty = NULL; | ||
1065 | spin_unlock(&group_leader->sighand->siglock); | ||
1066 | 1054 | ||
1067 | err = session; | 1055 | err = session; |
1068 | out: | 1056 | out: |
@@ -1351,8 +1339,10 @@ asmlinkage long sys_sethostname(char __user *name, int len) | |||
1351 | down_write(&uts_sem); | 1339 | down_write(&uts_sem); |
1352 | errno = -EFAULT; | 1340 | errno = -EFAULT; |
1353 | if (!copy_from_user(tmp, name, len)) { | 1341 | if (!copy_from_user(tmp, name, len)) { |
1354 | memcpy(utsname()->nodename, tmp, len); | 1342 | struct new_utsname *u = utsname(); |
1355 | utsname()->nodename[len] = 0; | 1343 | |
1344 | memcpy(u->nodename, tmp, len); | ||
1345 | memset(u->nodename + len, 0, sizeof(u->nodename) - len); | ||
1356 | errno = 0; | 1346 | errno = 0; |
1357 | } | 1347 | } |
1358 | up_write(&uts_sem); | 1348 | up_write(&uts_sem); |
@@ -1364,15 +1354,17 @@ asmlinkage long sys_sethostname(char __user *name, int len) | |||
1364 | asmlinkage long sys_gethostname(char __user *name, int len) | 1354 | asmlinkage long sys_gethostname(char __user *name, int len) |
1365 | { | 1355 | { |
1366 | int i, errno; | 1356 | int i, errno; |
1357 | struct new_utsname *u; | ||
1367 | 1358 | ||
1368 | if (len < 0) | 1359 | if (len < 0) |
1369 | return -EINVAL; | 1360 | return -EINVAL; |
1370 | down_read(&uts_sem); | 1361 | down_read(&uts_sem); |
1371 | i = 1 + strlen(utsname()->nodename); | 1362 | u = utsname(); |
1363 | i = 1 + strlen(u->nodename); | ||
1372 | if (i > len) | 1364 | if (i > len) |
1373 | i = len; | 1365 | i = len; |
1374 | errno = 0; | 1366 | errno = 0; |
1375 | if (copy_to_user(name, utsname()->nodename, i)) | 1367 | if (copy_to_user(name, u->nodename, i)) |
1376 | errno = -EFAULT; | 1368 | errno = -EFAULT; |
1377 | up_read(&uts_sem); | 1369 | up_read(&uts_sem); |
1378 | return errno; | 1370 | return errno; |
@@ -1397,8 +1389,10 @@ asmlinkage long sys_setdomainname(char __user *name, int len) | |||
1397 | down_write(&uts_sem); | 1389 | down_write(&uts_sem); |
1398 | errno = -EFAULT; | 1390 | errno = -EFAULT; |
1399 | if (!copy_from_user(tmp, name, len)) { | 1391 | if (!copy_from_user(tmp, name, len)) { |
1400 | memcpy(utsname()->domainname, tmp, len); | 1392 | struct new_utsname *u = utsname(); |
1401 | utsname()->domainname[len] = 0; | 1393 | |
1394 | memcpy(u->domainname, tmp, len); | ||
1395 | memset(u->domainname + len, 0, sizeof(u->domainname) - len); | ||
1402 | errno = 0; | 1396 | errno = 0; |
1403 | } | 1397 | } |
1404 | up_write(&uts_sem); | 1398 | up_write(&uts_sem); |
@@ -1445,21 +1439,28 @@ asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *r | |||
1445 | asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim) | 1439 | asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim) |
1446 | { | 1440 | { |
1447 | struct rlimit new_rlim, *old_rlim; | 1441 | struct rlimit new_rlim, *old_rlim; |
1448 | unsigned long it_prof_secs; | ||
1449 | int retval; | 1442 | int retval; |
1450 | 1443 | ||
1451 | if (resource >= RLIM_NLIMITS) | 1444 | if (resource >= RLIM_NLIMITS) |
1452 | return -EINVAL; | 1445 | return -EINVAL; |
1453 | if (copy_from_user(&new_rlim, rlim, sizeof(*rlim))) | 1446 | if (copy_from_user(&new_rlim, rlim, sizeof(*rlim))) |
1454 | return -EFAULT; | 1447 | return -EFAULT; |
1455 | if (new_rlim.rlim_cur > new_rlim.rlim_max) | ||
1456 | return -EINVAL; | ||
1457 | old_rlim = current->signal->rlim + resource; | 1448 | old_rlim = current->signal->rlim + resource; |
1458 | if ((new_rlim.rlim_max > old_rlim->rlim_max) && | 1449 | if ((new_rlim.rlim_max > old_rlim->rlim_max) && |
1459 | !capable(CAP_SYS_RESOURCE)) | 1450 | !capable(CAP_SYS_RESOURCE)) |
1460 | return -EPERM; | 1451 | return -EPERM; |
1461 | if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open) | 1452 | |
1462 | return -EPERM; | 1453 | if (resource == RLIMIT_NOFILE) { |
1454 | if (new_rlim.rlim_max == RLIM_INFINITY) | ||
1455 | new_rlim.rlim_max = sysctl_nr_open; | ||
1456 | if (new_rlim.rlim_cur == RLIM_INFINITY) | ||
1457 | new_rlim.rlim_cur = sysctl_nr_open; | ||
1458 | if (new_rlim.rlim_max > sysctl_nr_open) | ||
1459 | return -EPERM; | ||
1460 | } | ||
1461 | |||
1462 | if (new_rlim.rlim_cur > new_rlim.rlim_max) | ||
1463 | return -EINVAL; | ||
1463 | 1464 | ||
1464 | retval = security_task_setrlimit(resource, &new_rlim); | 1465 | retval = security_task_setrlimit(resource, &new_rlim); |
1465 | if (retval) | 1466 | if (retval) |
@@ -1491,18 +1492,7 @@ asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim) | |||
1491 | if (new_rlim.rlim_cur == RLIM_INFINITY) | 1492 | if (new_rlim.rlim_cur == RLIM_INFINITY) |
1492 | goto out; | 1493 | goto out; |
1493 | 1494 | ||
1494 | it_prof_secs = cputime_to_secs(current->signal->it_prof_expires); | 1495 | update_rlimit_cpu(new_rlim.rlim_cur); |
1495 | if (it_prof_secs == 0 || new_rlim.rlim_cur <= it_prof_secs) { | ||
1496 | unsigned long rlim_cur = new_rlim.rlim_cur; | ||
1497 | cputime_t cputime; | ||
1498 | |||
1499 | cputime = secs_to_cputime(rlim_cur); | ||
1500 | read_lock(&tasklist_lock); | ||
1501 | spin_lock_irq(¤t->sighand->siglock); | ||
1502 | set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL); | ||
1503 | spin_unlock_irq(¤t->sighand->siglock); | ||
1504 | read_unlock(&tasklist_lock); | ||
1505 | } | ||
1506 | out: | 1496 | out: |
1507 | return 0; | 1497 | return 0; |
1508 | } | 1498 | } |
@@ -1540,11 +1530,8 @@ out: | |||
1540 | * | 1530 | * |
1541 | */ | 1531 | */ |
1542 | 1532 | ||
1543 | static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r, | 1533 | static void accumulate_thread_rusage(struct task_struct *t, struct rusage *r) |
1544 | cputime_t *utimep, cputime_t *stimep) | ||
1545 | { | 1534 | { |
1546 | *utimep = cputime_add(*utimep, t->utime); | ||
1547 | *stimep = cputime_add(*stimep, t->stime); | ||
1548 | r->ru_nvcsw += t->nvcsw; | 1535 | r->ru_nvcsw += t->nvcsw; |
1549 | r->ru_nivcsw += t->nivcsw; | 1536 | r->ru_nivcsw += t->nivcsw; |
1550 | r->ru_minflt += t->min_flt; | 1537 | r->ru_minflt += t->min_flt; |
@@ -1558,12 +1545,13 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1558 | struct task_struct *t; | 1545 | struct task_struct *t; |
1559 | unsigned long flags; | 1546 | unsigned long flags; |
1560 | cputime_t utime, stime; | 1547 | cputime_t utime, stime; |
1548 | struct task_cputime cputime; | ||
1561 | 1549 | ||
1562 | memset((char *) r, 0, sizeof *r); | 1550 | memset((char *) r, 0, sizeof *r); |
1563 | utime = stime = cputime_zero; | 1551 | utime = stime = cputime_zero; |
1564 | 1552 | ||
1565 | if (who == RUSAGE_THREAD) { | 1553 | if (who == RUSAGE_THREAD) { |
1566 | accumulate_thread_rusage(p, r, &utime, &stime); | 1554 | accumulate_thread_rusage(p, r); |
1567 | goto out; | 1555 | goto out; |
1568 | } | 1556 | } |
1569 | 1557 | ||
@@ -1586,8 +1574,9 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1586 | break; | 1574 | break; |
1587 | 1575 | ||
1588 | case RUSAGE_SELF: | 1576 | case RUSAGE_SELF: |
1589 | utime = cputime_add(utime, p->signal->utime); | 1577 | thread_group_cputime(p, &cputime); |
1590 | stime = cputime_add(stime, p->signal->stime); | 1578 | utime = cputime_add(utime, cputime.utime); |
1579 | stime = cputime_add(stime, cputime.stime); | ||
1591 | r->ru_nvcsw += p->signal->nvcsw; | 1580 | r->ru_nvcsw += p->signal->nvcsw; |
1592 | r->ru_nivcsw += p->signal->nivcsw; | 1581 | r->ru_nivcsw += p->signal->nivcsw; |
1593 | r->ru_minflt += p->signal->min_flt; | 1582 | r->ru_minflt += p->signal->min_flt; |
@@ -1596,7 +1585,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) | |||
1596 | r->ru_oublock += p->signal->oublock; | 1585 | r->ru_oublock += p->signal->oublock; |
1597 | t = p; | 1586 | t = p; |
1598 | do { | 1587 | do { |
1599 | accumulate_thread_rusage(t, r, &utime, &stime); | 1588 | accumulate_thread_rusage(t, r); |
1600 | t = next_thread(t); | 1589 | t = next_thread(t); |
1601 | } while (t != p); | 1590 | } while (t != p); |
1602 | break; | 1591 | break; |
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 08d6e1bb99ac..a77b27b11b04 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c | |||
@@ -125,6 +125,12 @@ cond_syscall(sys_vm86old); | |||
125 | cond_syscall(sys_vm86); | 125 | cond_syscall(sys_vm86); |
126 | cond_syscall(compat_sys_ipc); | 126 | cond_syscall(compat_sys_ipc); |
127 | cond_syscall(compat_sys_sysctl); | 127 | cond_syscall(compat_sys_sysctl); |
128 | cond_syscall(sys_flock); | ||
129 | cond_syscall(sys_io_setup); | ||
130 | cond_syscall(sys_io_destroy); | ||
131 | cond_syscall(sys_io_submit); | ||
132 | cond_syscall(sys_io_cancel); | ||
133 | cond_syscall(sys_io_getevents); | ||
128 | 134 | ||
129 | /* arch-specific weak syscall entries */ | 135 | /* arch-specific weak syscall entries */ |
130 | cond_syscall(sys_pciconfig_read); | 136 | cond_syscall(sys_pciconfig_read); |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index fe4713347275..617d41e4d6a0 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -80,7 +80,6 @@ extern int pid_max_min, pid_max_max; | |||
80 | extern int sysctl_drop_caches; | 80 | extern int sysctl_drop_caches; |
81 | extern int percpu_pagelist_fraction; | 81 | extern int percpu_pagelist_fraction; |
82 | extern int compat_log; | 82 | extern int compat_log; |
83 | extern int maps_protect; | ||
84 | extern int latencytop_enabled; | 83 | extern int latencytop_enabled; |
85 | extern int sysctl_nr_open_min, sysctl_nr_open_max; | 84 | extern int sysctl_nr_open_min, sysctl_nr_open_max; |
86 | #ifdef CONFIG_RCU_TORTURE_TEST | 85 | #ifdef CONFIG_RCU_TORTURE_TEST |
@@ -97,7 +96,7 @@ static int sixty = 60; | |||
97 | static int neg_one = -1; | 96 | static int neg_one = -1; |
98 | #endif | 97 | #endif |
99 | 98 | ||
100 | #ifdef CONFIG_MMU | 99 | #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING) |
101 | static int two = 2; | 100 | static int two = 2; |
102 | #endif | 101 | #endif |
103 | 102 | ||
@@ -118,10 +117,8 @@ extern char modprobe_path[]; | |||
118 | extern int sg_big_buff; | 117 | extern int sg_big_buff; |
119 | #endif | 118 | #endif |
120 | 119 | ||
121 | #ifdef __sparc__ | 120 | #ifdef CONFIG_SPARC |
122 | extern char reboot_command []; | 121 | #include <asm/system.h> |
123 | extern int stop_a_enabled; | ||
124 | extern int scons_pwroff; | ||
125 | #endif | 122 | #endif |
126 | 123 | ||
127 | #ifdef __hppa__ | 124 | #ifdef __hppa__ |
@@ -152,13 +149,14 @@ extern int max_lock_depth; | |||
152 | #ifdef CONFIG_PROC_SYSCTL | 149 | #ifdef CONFIG_PROC_SYSCTL |
153 | static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, | 150 | static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, |
154 | void __user *buffer, size_t *lenp, loff_t *ppos); | 151 | void __user *buffer, size_t *lenp, loff_t *ppos); |
155 | static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, | 152 | static int proc_taint(struct ctl_table *table, int write, struct file *filp, |
156 | void __user *buffer, size_t *lenp, loff_t *ppos); | 153 | void __user *buffer, size_t *lenp, loff_t *ppos); |
157 | #endif | 154 | #endif |
158 | 155 | ||
159 | static struct ctl_table root_table[]; | 156 | static struct ctl_table root_table[]; |
160 | static struct ctl_table_root sysctl_table_root; | 157 | static struct ctl_table_root sysctl_table_root; |
161 | static struct ctl_table_header root_table_header = { | 158 | static struct ctl_table_header root_table_header = { |
159 | .count = 1, | ||
162 | .ctl_table = root_table, | 160 | .ctl_table = root_table, |
163 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), | 161 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), |
164 | .root = &sysctl_table_root, | 162 | .root = &sysctl_table_root, |
@@ -381,10 +379,9 @@ static struct ctl_table kern_table[] = { | |||
381 | #ifdef CONFIG_PROC_SYSCTL | 379 | #ifdef CONFIG_PROC_SYSCTL |
382 | { | 380 | { |
383 | .procname = "tainted", | 381 | .procname = "tainted", |
384 | .data = &tainted, | 382 | .maxlen = sizeof(long), |
385 | .maxlen = sizeof(int), | ||
386 | .mode = 0644, | 383 | .mode = 0644, |
387 | .proc_handler = &proc_dointvec_taint, | 384 | .proc_handler = &proc_taint, |
388 | }, | 385 | }, |
389 | #endif | 386 | #endif |
390 | #ifdef CONFIG_LATENCYTOP | 387 | #ifdef CONFIG_LATENCYTOP |
@@ -414,7 +411,7 @@ static struct ctl_table kern_table[] = { | |||
414 | .mode = 0644, | 411 | .mode = 0644, |
415 | .proc_handler = &proc_dointvec, | 412 | .proc_handler = &proc_dointvec, |
416 | }, | 413 | }, |
417 | #ifdef __sparc__ | 414 | #ifdef CONFIG_SPARC |
418 | { | 415 | { |
419 | .ctl_name = KERN_SPARC_REBOOT, | 416 | .ctl_name = KERN_SPARC_REBOOT, |
420 | .procname = "reboot-cmd", | 417 | .procname = "reboot-cmd", |
@@ -809,16 +806,6 @@ static struct ctl_table kern_table[] = { | |||
809 | .proc_handler = &proc_dointvec, | 806 | .proc_handler = &proc_dointvec, |
810 | }, | 807 | }, |
811 | #endif | 808 | #endif |
812 | #ifdef CONFIG_PROC_FS | ||
813 | { | ||
814 | .ctl_name = CTL_UNNUMBERED, | ||
815 | .procname = "maps_protect", | ||
816 | .data = &maps_protect, | ||
817 | .maxlen = sizeof(int), | ||
818 | .mode = 0644, | ||
819 | .proc_handler = &proc_dointvec, | ||
820 | }, | ||
821 | #endif | ||
822 | { | 809 | { |
823 | .ctl_name = CTL_UNNUMBERED, | 810 | .ctl_name = CTL_UNNUMBERED, |
824 | .procname = "poweroff_cmd", | 811 | .procname = "poweroff_cmd", |
@@ -1260,6 +1247,7 @@ static struct ctl_table fs_table[] = { | |||
1260 | .extra1 = &minolduid, | 1247 | .extra1 = &minolduid, |
1261 | .extra2 = &maxolduid, | 1248 | .extra2 = &maxolduid, |
1262 | }, | 1249 | }, |
1250 | #ifdef CONFIG_FILE_LOCKING | ||
1263 | { | 1251 | { |
1264 | .ctl_name = FS_LEASES, | 1252 | .ctl_name = FS_LEASES, |
1265 | .procname = "leases-enable", | 1253 | .procname = "leases-enable", |
@@ -1268,6 +1256,7 @@ static struct ctl_table fs_table[] = { | |||
1268 | .mode = 0644, | 1256 | .mode = 0644, |
1269 | .proc_handler = &proc_dointvec, | 1257 | .proc_handler = &proc_dointvec, |
1270 | }, | 1258 | }, |
1259 | #endif | ||
1271 | #ifdef CONFIG_DNOTIFY | 1260 | #ifdef CONFIG_DNOTIFY |
1272 | { | 1261 | { |
1273 | .ctl_name = FS_DIR_NOTIFY, | 1262 | .ctl_name = FS_DIR_NOTIFY, |
@@ -1279,6 +1268,7 @@ static struct ctl_table fs_table[] = { | |||
1279 | }, | 1268 | }, |
1280 | #endif | 1269 | #endif |
1281 | #ifdef CONFIG_MMU | 1270 | #ifdef CONFIG_MMU |
1271 | #ifdef CONFIG_FILE_LOCKING | ||
1282 | { | 1272 | { |
1283 | .ctl_name = FS_LEASE_TIME, | 1273 | .ctl_name = FS_LEASE_TIME, |
1284 | .procname = "lease-break-time", | 1274 | .procname = "lease-break-time", |
@@ -1290,6 +1280,8 @@ static struct ctl_table fs_table[] = { | |||
1290 | .extra1 = &zero, | 1280 | .extra1 = &zero, |
1291 | .extra2 = &two, | 1281 | .extra2 = &two, |
1292 | }, | 1282 | }, |
1283 | #endif | ||
1284 | #ifdef CONFIG_AIO | ||
1293 | { | 1285 | { |
1294 | .procname = "aio-nr", | 1286 | .procname = "aio-nr", |
1295 | .data = &aio_nr, | 1287 | .data = &aio_nr, |
@@ -1304,6 +1296,7 @@ static struct ctl_table fs_table[] = { | |||
1304 | .mode = 0644, | 1296 | .mode = 0644, |
1305 | .proc_handler = &proc_doulongvec_minmax, | 1297 | .proc_handler = &proc_doulongvec_minmax, |
1306 | }, | 1298 | }, |
1299 | #endif /* CONFIG_AIO */ | ||
1307 | #ifdef CONFIG_INOTIFY_USER | 1300 | #ifdef CONFIG_INOTIFY_USER |
1308 | { | 1301 | { |
1309 | .ctl_name = FS_INOTIFY, | 1302 | .ctl_name = FS_INOTIFY, |
@@ -1509,7 +1502,6 @@ void register_sysctl_root(struct ctl_table_root *root) | |||
1509 | /* Perform the actual read/write of a sysctl table entry. */ | 1502 | /* Perform the actual read/write of a sysctl table entry. */ |
1510 | static int do_sysctl_strategy(struct ctl_table_root *root, | 1503 | static int do_sysctl_strategy(struct ctl_table_root *root, |
1511 | struct ctl_table *table, | 1504 | struct ctl_table *table, |
1512 | int __user *name, int nlen, | ||
1513 | void __user *oldval, size_t __user *oldlenp, | 1505 | void __user *oldval, size_t __user *oldlenp, |
1514 | void __user *newval, size_t newlen) | 1506 | void __user *newval, size_t newlen) |
1515 | { | 1507 | { |
@@ -1523,8 +1515,7 @@ static int do_sysctl_strategy(struct ctl_table_root *root, | |||
1523 | return -EPERM; | 1515 | return -EPERM; |
1524 | 1516 | ||
1525 | if (table->strategy) { | 1517 | if (table->strategy) { |
1526 | rc = table->strategy(table, name, nlen, oldval, oldlenp, | 1518 | rc = table->strategy(table, oldval, oldlenp, newval, newlen); |
1527 | newval, newlen); | ||
1528 | if (rc < 0) | 1519 | if (rc < 0) |
1529 | return rc; | 1520 | return rc; |
1530 | if (rc > 0) | 1521 | if (rc > 0) |
@@ -1534,8 +1525,7 @@ static int do_sysctl_strategy(struct ctl_table_root *root, | |||
1534 | /* If there is no strategy routine, or if the strategy returns | 1525 | /* If there is no strategy routine, or if the strategy returns |
1535 | * zero, proceed with automatic r/w */ | 1526 | * zero, proceed with automatic r/w */ |
1536 | if (table->data && table->maxlen) { | 1527 | if (table->data && table->maxlen) { |
1537 | rc = sysctl_data(table, name, nlen, oldval, oldlenp, | 1528 | rc = sysctl_data(table, oldval, oldlenp, newval, newlen); |
1538 | newval, newlen); | ||
1539 | if (rc < 0) | 1529 | if (rc < 0) |
1540 | return rc; | 1530 | return rc; |
1541 | } | 1531 | } |
@@ -1567,7 +1557,7 @@ repeat: | |||
1567 | table = table->child; | 1557 | table = table->child; |
1568 | goto repeat; | 1558 | goto repeat; |
1569 | } | 1559 | } |
1570 | error = do_sysctl_strategy(root, table, name, nlen, | 1560 | error = do_sysctl_strategy(root, table, |
1571 | oldval, oldlenp, | 1561 | oldval, oldlenp, |
1572 | newval, newlen); | 1562 | newval, newlen); |
1573 | return error; | 1563 | return error; |
@@ -2236,49 +2226,39 @@ int proc_dointvec(struct ctl_table *table, int write, struct file *filp, | |||
2236 | NULL,NULL); | 2226 | NULL,NULL); |
2237 | } | 2227 | } |
2238 | 2228 | ||
2239 | #define OP_SET 0 | ||
2240 | #define OP_AND 1 | ||
2241 | #define OP_OR 2 | ||
2242 | |||
2243 | static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp, | ||
2244 | int *valp, | ||
2245 | int write, void *data) | ||
2246 | { | ||
2247 | int op = *(int *)data; | ||
2248 | if (write) { | ||
2249 | int val = *negp ? -*lvalp : *lvalp; | ||
2250 | switch(op) { | ||
2251 | case OP_SET: *valp = val; break; | ||
2252 | case OP_AND: *valp &= val; break; | ||
2253 | case OP_OR: *valp |= val; break; | ||
2254 | } | ||
2255 | } else { | ||
2256 | int val = *valp; | ||
2257 | if (val < 0) { | ||
2258 | *negp = -1; | ||
2259 | *lvalp = (unsigned long)-val; | ||
2260 | } else { | ||
2261 | *negp = 0; | ||
2262 | *lvalp = (unsigned long)val; | ||
2263 | } | ||
2264 | } | ||
2265 | return 0; | ||
2266 | } | ||
2267 | |||
2268 | /* | 2229 | /* |
2269 | * Taint values can only be increased | 2230 | * Taint values can only be increased |
2231 | * This means we can safely use a temporary. | ||
2270 | */ | 2232 | */ |
2271 | static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, | 2233 | static int proc_taint(struct ctl_table *table, int write, struct file *filp, |
2272 | void __user *buffer, size_t *lenp, loff_t *ppos) | 2234 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2273 | { | 2235 | { |
2274 | int op; | 2236 | struct ctl_table t; |
2237 | unsigned long tmptaint = get_taint(); | ||
2238 | int err; | ||
2275 | 2239 | ||
2276 | if (write && !capable(CAP_SYS_ADMIN)) | 2240 | if (write && !capable(CAP_SYS_ADMIN)) |
2277 | return -EPERM; | 2241 | return -EPERM; |
2278 | 2242 | ||
2279 | op = OP_OR; | 2243 | t = *table; |
2280 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | 2244 | t.data = &tmptaint; |
2281 | do_proc_dointvec_bset_conv,&op); | 2245 | err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos); |
2246 | if (err < 0) | ||
2247 | return err; | ||
2248 | |||
2249 | if (write) { | ||
2250 | /* | ||
2251 | * Poor man's atomic or. Not worth adding a primitive | ||
2252 | * to everyone's atomic.h for this | ||
2253 | */ | ||
2254 | int i; | ||
2255 | for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { | ||
2256 | if ((tmptaint >> i) & 1) | ||
2257 | add_taint(i); | ||
2258 | } | ||
2259 | } | ||
2260 | |||
2261 | return err; | ||
2282 | } | 2262 | } |
2283 | 2263 | ||
2284 | struct do_proc_dointvec_minmax_conv_param { | 2264 | struct do_proc_dointvec_minmax_conv_param { |
@@ -2726,7 +2706,7 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, | |||
2726 | */ | 2706 | */ |
2727 | 2707 | ||
2728 | /* The generic sysctl data routine (used if no strategy routine supplied) */ | 2708 | /* The generic sysctl data routine (used if no strategy routine supplied) */ |
2729 | int sysctl_data(struct ctl_table *table, int __user *name, int nlen, | 2709 | int sysctl_data(struct ctl_table *table, |
2730 | void __user *oldval, size_t __user *oldlenp, | 2710 | void __user *oldval, size_t __user *oldlenp, |
2731 | void __user *newval, size_t newlen) | 2711 | void __user *newval, size_t newlen) |
2732 | { | 2712 | { |
@@ -2760,7 +2740,7 @@ int sysctl_data(struct ctl_table *table, int __user *name, int nlen, | |||
2760 | } | 2740 | } |
2761 | 2741 | ||
2762 | /* The generic string strategy routine: */ | 2742 | /* The generic string strategy routine: */ |
2763 | int sysctl_string(struct ctl_table *table, int __user *name, int nlen, | 2743 | int sysctl_string(struct ctl_table *table, |
2764 | void __user *oldval, size_t __user *oldlenp, | 2744 | void __user *oldval, size_t __user *oldlenp, |
2765 | void __user *newval, size_t newlen) | 2745 | void __user *newval, size_t newlen) |
2766 | { | 2746 | { |
@@ -2806,7 +2786,7 @@ int sysctl_string(struct ctl_table *table, int __user *name, int nlen, | |||
2806 | * are between the minimum and maximum values given in the arrays | 2786 | * are between the minimum and maximum values given in the arrays |
2807 | * table->extra1 and table->extra2, respectively. | 2787 | * table->extra1 and table->extra2, respectively. |
2808 | */ | 2788 | */ |
2809 | int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, | 2789 | int sysctl_intvec(struct ctl_table *table, |
2810 | void __user *oldval, size_t __user *oldlenp, | 2790 | void __user *oldval, size_t __user *oldlenp, |
2811 | void __user *newval, size_t newlen) | 2791 | void __user *newval, size_t newlen) |
2812 | { | 2792 | { |
@@ -2842,7 +2822,7 @@ int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, | |||
2842 | } | 2822 | } |
2843 | 2823 | ||
2844 | /* Strategy function to convert jiffies to seconds */ | 2824 | /* Strategy function to convert jiffies to seconds */ |
2845 | int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, | 2825 | int sysctl_jiffies(struct ctl_table *table, |
2846 | void __user *oldval, size_t __user *oldlenp, | 2826 | void __user *oldval, size_t __user *oldlenp, |
2847 | void __user *newval, size_t newlen) | 2827 | void __user *newval, size_t newlen) |
2848 | { | 2828 | { |
@@ -2876,7 +2856,7 @@ int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, | |||
2876 | } | 2856 | } |
2877 | 2857 | ||
2878 | /* Strategy function to convert jiffies to seconds */ | 2858 | /* Strategy function to convert jiffies to seconds */ |
2879 | int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, | 2859 | int sysctl_ms_jiffies(struct ctl_table *table, |
2880 | void __user *oldval, size_t __user *oldlenp, | 2860 | void __user *oldval, size_t __user *oldlenp, |
2881 | void __user *newval, size_t newlen) | 2861 | void __user *newval, size_t newlen) |
2882 | { | 2862 | { |
@@ -2931,35 +2911,35 @@ asmlinkage long sys_sysctl(struct __sysctl_args __user *args) | |||
2931 | return error; | 2911 | return error; |
2932 | } | 2912 | } |
2933 | 2913 | ||
2934 | int sysctl_data(struct ctl_table *table, int __user *name, int nlen, | 2914 | int sysctl_data(struct ctl_table *table, |
2935 | void __user *oldval, size_t __user *oldlenp, | 2915 | void __user *oldval, size_t __user *oldlenp, |
2936 | void __user *newval, size_t newlen) | 2916 | void __user *newval, size_t newlen) |
2937 | { | 2917 | { |
2938 | return -ENOSYS; | 2918 | return -ENOSYS; |
2939 | } | 2919 | } |
2940 | 2920 | ||
2941 | int sysctl_string(struct ctl_table *table, int __user *name, int nlen, | 2921 | int sysctl_string(struct ctl_table *table, |
2942 | void __user *oldval, size_t __user *oldlenp, | 2922 | void __user *oldval, size_t __user *oldlenp, |
2943 | void __user *newval, size_t newlen) | 2923 | void __user *newval, size_t newlen) |
2944 | { | 2924 | { |
2945 | return -ENOSYS; | 2925 | return -ENOSYS; |
2946 | } | 2926 | } |
2947 | 2927 | ||
2948 | int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, | 2928 | int sysctl_intvec(struct ctl_table *table, |
2949 | void __user *oldval, size_t __user *oldlenp, | 2929 | void __user *oldval, size_t __user *oldlenp, |
2950 | void __user *newval, size_t newlen) | 2930 | void __user *newval, size_t newlen) |
2951 | { | 2931 | { |
2952 | return -ENOSYS; | 2932 | return -ENOSYS; |
2953 | } | 2933 | } |
2954 | 2934 | ||
2955 | int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, | 2935 | int sysctl_jiffies(struct ctl_table *table, |
2956 | void __user *oldval, size_t __user *oldlenp, | 2936 | void __user *oldval, size_t __user *oldlenp, |
2957 | void __user *newval, size_t newlen) | 2937 | void __user *newval, size_t newlen) |
2958 | { | 2938 | { |
2959 | return -ENOSYS; | 2939 | return -ENOSYS; |
2960 | } | 2940 | } |
2961 | 2941 | ||
2962 | int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, | 2942 | int sysctl_ms_jiffies(struct ctl_table *table, |
2963 | void __user *oldval, size_t __user *oldlenp, | 2943 | void __user *oldval, size_t __user *oldlenp, |
2964 | void __user *newval, size_t newlen) | 2944 | void __user *newval, size_t newlen) |
2965 | { | 2945 | { |
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index 8d53106a0a92..95ed42951e0a 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig | |||
@@ -3,7 +3,6 @@ | |||
3 | # | 3 | # |
4 | config TICK_ONESHOT | 4 | config TICK_ONESHOT |
5 | bool | 5 | bool |
6 | default n | ||
7 | 6 | ||
8 | config NO_HZ | 7 | config NO_HZ |
9 | bool "Tickless System (Dynamic Ticks)" | 8 | bool "Tickless System (Dynamic Ticks)" |
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/clocksource.c b/kernel/time/clocksource.c index 093d4acf993b..9ed2eec97526 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c | |||
@@ -325,6 +325,9 @@ int clocksource_register(struct clocksource *c) | |||
325 | unsigned long flags; | 325 | unsigned long flags; |
326 | int ret; | 326 | int ret; |
327 | 327 | ||
328 | /* save mult_orig on registration */ | ||
329 | c->mult_orig = c->mult; | ||
330 | |||
328 | spin_lock_irqsave(&clocksource_lock, flags); | 331 | spin_lock_irqsave(&clocksource_lock, flags); |
329 | ret = clocksource_enqueue(c); | 332 | ret = clocksource_enqueue(c); |
330 | if (!ret) | 333 | if (!ret) |
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index 4c256fdb8875..1ca99557e929 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c | |||
@@ -61,6 +61,7 @@ struct clocksource clocksource_jiffies = { | |||
61 | .read = jiffies_read, | 61 | .read = jiffies_read, |
62 | .mask = 0xffffffff, /*32bits*/ | 62 | .mask = 0xffffffff, /*32bits*/ |
63 | .mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ | 63 | .mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */ |
64 | .mult_orig = NSEC_PER_JIFFY << JIFFIES_SHIFT, | ||
64 | .shift = JIFFIES_SHIFT, | 65 | .shift = JIFFIES_SHIFT, |
65 | }; | 66 | }; |
66 | 67 | ||
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 5125ddd8196b..1a20715bfd6e 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c | |||
@@ -10,13 +10,13 @@ | |||
10 | 10 | ||
11 | #include <linux/mm.h> | 11 | #include <linux/mm.h> |
12 | #include <linux/time.h> | 12 | #include <linux/time.h> |
13 | #include <linux/timer.h> | ||
14 | #include <linux/timex.h> | 13 | #include <linux/timex.h> |
15 | #include <linux/jiffies.h> | 14 | #include <linux/jiffies.h> |
16 | #include <linux/hrtimer.h> | 15 | #include <linux/hrtimer.h> |
17 | #include <linux/capability.h> | 16 | #include <linux/capability.h> |
18 | #include <linux/math64.h> | 17 | #include <linux/math64.h> |
19 | #include <linux/clocksource.h> | 18 | #include <linux/clocksource.h> |
19 | #include <linux/workqueue.h> | ||
20 | #include <asm/timex.h> | 20 | #include <asm/timex.h> |
21 | 21 | ||
22 | /* | 22 | /* |
@@ -218,11 +218,11 @@ void second_overflow(void) | |||
218 | /* Disable the cmos update - used by virtualization and embedded */ | 218 | /* Disable the cmos update - used by virtualization and embedded */ |
219 | int no_sync_cmos_clock __read_mostly; | 219 | int no_sync_cmos_clock __read_mostly; |
220 | 220 | ||
221 | static void sync_cmos_clock(unsigned long dummy); | 221 | static void sync_cmos_clock(struct work_struct *work); |
222 | 222 | ||
223 | static DEFINE_TIMER(sync_cmos_timer, sync_cmos_clock, 0, 0); | 223 | static DECLARE_DELAYED_WORK(sync_cmos_work, sync_cmos_clock); |
224 | 224 | ||
225 | static void sync_cmos_clock(unsigned long dummy) | 225 | static void sync_cmos_clock(struct work_struct *work) |
226 | { | 226 | { |
227 | struct timespec now, next; | 227 | struct timespec now, next; |
228 | int fail = 1; | 228 | int fail = 1; |
@@ -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 | ||
@@ -258,13 +258,13 @@ static void sync_cmos_clock(unsigned long dummy) | |||
258 | next.tv_sec++; | 258 | next.tv_sec++; |
259 | next.tv_nsec -= NSEC_PER_SEC; | 259 | next.tv_nsec -= NSEC_PER_SEC; |
260 | } | 260 | } |
261 | mod_timer(&sync_cmos_timer, jiffies + timespec_to_jiffies(&next)); | 261 | schedule_delayed_work(&sync_cmos_work, timespec_to_jiffies(&next)); |
262 | } | 262 | } |
263 | 263 | ||
264 | static void notify_cmos_timer(void) | 264 | static void notify_cmos_timer(void) |
265 | { | 265 | { |
266 | if (!no_sync_cmos_clock) | 266 | if (!no_sync_cmos_clock) |
267 | mod_timer(&sync_cmos_timer, jiffies + 1); | 267 | schedule_delayed_work(&sync_cmos_work, 0); |
268 | } | 268 | } |
269 | 269 | ||
270 | #else | 270 | #else |
@@ -277,38 +277,50 @@ static inline void notify_cmos_timer(void) { } | |||
277 | int do_adjtimex(struct timex *txc) | 277 | int do_adjtimex(struct timex *txc) |
278 | { | 278 | { |
279 | struct timespec ts; | 279 | struct timespec ts; |
280 | long save_adjust, sec; | ||
281 | int result; | 280 | int result; |
282 | 281 | ||
283 | /* In order to modify anything, you gotta be super-user! */ | 282 | /* Validate the data before disabling interrupts */ |
284 | if (txc->modes && !capable(CAP_SYS_TIME)) | 283 | if (txc->modes & ADJ_ADJTIME) { |
285 | return -EPERM; | ||
286 | |||
287 | /* Now we validate the data before disabling interrupts */ | ||
288 | |||
289 | if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT) { | ||
290 | /* singleshot must not be used with any other mode bits */ | 284 | /* singleshot must not be used with any other mode bits */ |
291 | if (txc->modes & ~ADJ_OFFSET_SS_READ) | 285 | if (!(txc->modes & ADJ_OFFSET_SINGLESHOT)) |
292 | return -EINVAL; | 286 | return -EINVAL; |
287 | if (!(txc->modes & ADJ_OFFSET_READONLY) && | ||
288 | !capable(CAP_SYS_TIME)) | ||
289 | return -EPERM; | ||
290 | } else { | ||
291 | /* In order to modify anything, you gotta be super-user! */ | ||
292 | if (txc->modes && !capable(CAP_SYS_TIME)) | ||
293 | return -EPERM; | ||
294 | |||
295 | /* if the quartz is off by more than 10% something is VERY wrong! */ | ||
296 | if (txc->modes & ADJ_TICK && | ||
297 | (txc->tick < 900000/USER_HZ || | ||
298 | txc->tick > 1100000/USER_HZ)) | ||
299 | return -EINVAL; | ||
300 | |||
301 | if (txc->modes & ADJ_STATUS && time_state != TIME_OK) | ||
302 | hrtimer_cancel(&leap_timer); | ||
293 | } | 303 | } |
294 | 304 | ||
295 | /* if the quartz is off by more than 10% something is VERY wrong ! */ | ||
296 | if (txc->modes & ADJ_TICK) | ||
297 | if (txc->tick < 900000/USER_HZ || | ||
298 | txc->tick > 1100000/USER_HZ) | ||
299 | return -EINVAL; | ||
300 | |||
301 | if (time_state != TIME_OK && txc->modes & ADJ_STATUS) | ||
302 | hrtimer_cancel(&leap_timer); | ||
303 | getnstimeofday(&ts); | 305 | getnstimeofday(&ts); |
304 | 306 | ||
305 | write_seqlock_irq(&xtime_lock); | 307 | write_seqlock_irq(&xtime_lock); |
306 | 308 | ||
307 | /* Save for later - semantics of adjtime is to return old value */ | ||
308 | save_adjust = time_adjust; | ||
309 | |||
310 | /* If there are input parameters, then process them */ | 309 | /* If there are input parameters, then process them */ |
310 | if (txc->modes & ADJ_ADJTIME) { | ||
311 | long save_adjust = time_adjust; | ||
312 | |||
313 | if (!(txc->modes & ADJ_OFFSET_READONLY)) { | ||
314 | /* adjtime() is independent from ntp_adjtime() */ | ||
315 | time_adjust = txc->offset; | ||
316 | ntp_update_frequency(); | ||
317 | } | ||
318 | txc->offset = save_adjust; | ||
319 | goto adj_done; | ||
320 | } | ||
311 | if (txc->modes) { | 321 | if (txc->modes) { |
322 | long sec; | ||
323 | |||
312 | if (txc->modes & ADJ_STATUS) { | 324 | if (txc->modes & ADJ_STATUS) { |
313 | if ((time_status & STA_PLL) && | 325 | if ((time_status & STA_PLL) && |
314 | !(txc->status & STA_PLL)) { | 326 | !(txc->status & STA_PLL)) { |
@@ -375,13 +387,8 @@ int do_adjtimex(struct timex *txc) | |||
375 | if (txc->modes & ADJ_TAI && txc->constant > 0) | 387 | if (txc->modes & ADJ_TAI && txc->constant > 0) |
376 | time_tai = txc->constant; | 388 | time_tai = txc->constant; |
377 | 389 | ||
378 | if (txc->modes & ADJ_OFFSET) { | 390 | if (txc->modes & ADJ_OFFSET) |
379 | if (txc->modes == ADJ_OFFSET_SINGLESHOT) | 391 | ntp_update_offset(txc->offset); |
380 | /* adjtime() is independent from ntp_adjtime() */ | ||
381 | time_adjust = txc->offset; | ||
382 | else | ||
383 | ntp_update_offset(txc->offset); | ||
384 | } | ||
385 | if (txc->modes & ADJ_TICK) | 392 | if (txc->modes & ADJ_TICK) |
386 | tick_usec = txc->tick; | 393 | tick_usec = txc->tick; |
387 | 394 | ||
@@ -389,22 +396,18 @@ int do_adjtimex(struct timex *txc) | |||
389 | ntp_update_frequency(); | 396 | ntp_update_frequency(); |
390 | } | 397 | } |
391 | 398 | ||
399 | txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, | ||
400 | NTP_SCALE_SHIFT); | ||
401 | if (!(time_status & STA_NANO)) | ||
402 | txc->offset /= NSEC_PER_USEC; | ||
403 | |||
404 | adj_done: | ||
392 | result = time_state; /* mostly `TIME_OK' */ | 405 | result = time_state; /* mostly `TIME_OK' */ |
393 | if (time_status & (STA_UNSYNC|STA_CLOCKERR)) | 406 | if (time_status & (STA_UNSYNC|STA_CLOCKERR)) |
394 | result = TIME_ERROR; | 407 | result = TIME_ERROR; |
395 | 408 | ||
396 | if ((txc->modes == ADJ_OFFSET_SINGLESHOT) || | 409 | txc->freq = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * |
397 | (txc->modes == ADJ_OFFSET_SS_READ)) | 410 | (s64)PPM_SCALE_INV, NTP_SCALE_SHIFT); |
398 | txc->offset = save_adjust; | ||
399 | else { | ||
400 | txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ, | ||
401 | NTP_SCALE_SHIFT); | ||
402 | if (!(time_status & STA_NANO)) | ||
403 | txc->offset /= NSEC_PER_USEC; | ||
404 | } | ||
405 | txc->freq = shift_right((s32)(time_freq >> PPM_SCALE_INV_SHIFT) * | ||
406 | (s64)PPM_SCALE_INV, | ||
407 | NTP_SCALE_SHIFT); | ||
408 | txc->maxerror = time_maxerror; | 411 | txc->maxerror = time_maxerror; |
409 | txc->esterror = time_esterror; | 412 | txc->esterror = time_esterror; |
410 | txc->status = time_status; | 413 | txc->status = time_status; |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index 31463d370b94..f98a1b7b16e9 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) |
@@ -383,6 +384,19 @@ int tick_resume_broadcast_oneshot(struct clock_event_device *bc) | |||
383 | } | 384 | } |
384 | 385 | ||
385 | /* | 386 | /* |
387 | * Called from irq_enter() when idle was interrupted to reenable the | ||
388 | * per cpu device. | ||
389 | */ | ||
390 | void tick_check_oneshot_broadcast(int cpu) | ||
391 | { | ||
392 | if (cpu_isset(cpu, tick_broadcast_oneshot_mask)) { | ||
393 | struct tick_device *td = &per_cpu(tick_cpu_device, cpu); | ||
394 | |||
395 | clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_ONESHOT); | ||
396 | } | ||
397 | } | ||
398 | |||
399 | /* | ||
386 | * Handle oneshot mode broadcasting | 400 | * Handle oneshot mode broadcasting |
387 | */ | 401 | */ |
388 | static void tick_handle_oneshot_broadcast(struct clock_event_device *dev) | 402 | static void tick_handle_oneshot_broadcast(struct clock_event_device *dev) |
@@ -491,14 +505,52 @@ static void tick_broadcast_clear_oneshot(int cpu) | |||
491 | cpu_clear(cpu, tick_broadcast_oneshot_mask); | 505 | cpu_clear(cpu, tick_broadcast_oneshot_mask); |
492 | } | 506 | } |
493 | 507 | ||
508 | static void tick_broadcast_init_next_event(cpumask_t *mask, ktime_t expires) | ||
509 | { | ||
510 | struct tick_device *td; | ||
511 | int cpu; | ||
512 | |||
513 | for_each_cpu_mask_nr(cpu, *mask) { | ||
514 | td = &per_cpu(tick_cpu_device, cpu); | ||
515 | if (td->evtdev) | ||
516 | td->evtdev->next_event = expires; | ||
517 | } | ||
518 | } | ||
519 | |||
494 | /** | 520 | /** |
495 | * tick_broadcast_setup_oneshot - setup the broadcast device | 521 | * tick_broadcast_setup_oneshot - setup the broadcast device |
496 | */ | 522 | */ |
497 | void tick_broadcast_setup_oneshot(struct clock_event_device *bc) | 523 | void tick_broadcast_setup_oneshot(struct clock_event_device *bc) |
498 | { | 524 | { |
499 | bc->event_handler = tick_handle_oneshot_broadcast; | 525 | /* Set it up only once ! */ |
500 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); | 526 | if (bc->event_handler != tick_handle_oneshot_broadcast) { |
501 | bc->next_event.tv64 = KTIME_MAX; | 527 | int was_periodic = bc->mode == CLOCK_EVT_MODE_PERIODIC; |
528 | int cpu = smp_processor_id(); | ||
529 | cpumask_t mask; | ||
530 | |||
531 | bc->event_handler = tick_handle_oneshot_broadcast; | ||
532 | clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT); | ||
533 | |||
534 | /* Take the do_timer update */ | ||
535 | tick_do_timer_cpu = cpu; | ||
536 | |||
537 | /* | ||
538 | * We must be careful here. There might be other CPUs | ||
539 | * waiting for periodic broadcast. We need to set the | ||
540 | * oneshot_mask bits for those and program the | ||
541 | * broadcast device to fire. | ||
542 | */ | ||
543 | mask = tick_broadcast_mask; | ||
544 | cpu_clear(cpu, mask); | ||
545 | cpus_or(tick_broadcast_oneshot_mask, | ||
546 | tick_broadcast_oneshot_mask, mask); | ||
547 | |||
548 | if (was_periodic && !cpus_empty(mask)) { | ||
549 | tick_broadcast_init_next_event(&mask, tick_next_period); | ||
550 | tick_broadcast_set_event(tick_next_period, 1); | ||
551 | } else | ||
552 | bc->next_event.tv64 = KTIME_MAX; | ||
553 | } | ||
502 | } | 554 | } |
503 | 555 | ||
504 | /* | 556 | /* |
@@ -538,4 +590,12 @@ void tick_shutdown_broadcast_oneshot(unsigned int *cpup) | |||
538 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); | 590 | spin_unlock_irqrestore(&tick_broadcast_lock, flags); |
539 | } | 591 | } |
540 | 592 | ||
593 | /* | ||
594 | * Check, whether the broadcast device is in one shot mode | ||
595 | */ | ||
596 | int tick_broadcast_oneshot_active(void) | ||
597 | { | ||
598 | return tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT; | ||
599 | } | ||
600 | |||
541 | #endif | 601 | #endif |
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 80c4336f4188..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; |
@@ -248,7 +250,7 @@ static int tick_check_new_device(struct clock_event_device *newdev) | |||
248 | * not give it back to the clockevents layer ! | 250 | * not give it back to the clockevents layer ! |
249 | */ | 251 | */ |
250 | if (tick_is_broadcast_device(curdev)) { | 252 | if (tick_is_broadcast_device(curdev)) { |
251 | clockevents_set_mode(curdev, CLOCK_EVT_MODE_SHUTDOWN); | 253 | clockevents_shutdown(curdev); |
252 | curdev = NULL; | 254 | curdev = NULL; |
253 | } | 255 | } |
254 | clockevents_exchange_device(curdev, newdev); | 256 | clockevents_exchange_device(curdev, newdev); |
@@ -299,7 +301,8 @@ static void tick_shutdown(unsigned int *cpup) | |||
299 | if (*cpup == tick_do_timer_cpu) { | 301 | if (*cpup == tick_do_timer_cpu) { |
300 | int cpu = first_cpu(cpu_online_map); | 302 | int cpu = first_cpu(cpu_online_map); |
301 | 303 | ||
302 | tick_do_timer_cpu = (cpu != NR_CPUS) ? cpu : -1; | 304 | tick_do_timer_cpu = (cpu != NR_CPUS) ? cpu : |
305 | TICK_DO_TIMER_NONE; | ||
303 | } | 306 | } |
304 | spin_unlock_irqrestore(&tick_device_lock, flags); | 307 | spin_unlock_irqrestore(&tick_device_lock, flags); |
305 | } | 308 | } |
@@ -310,7 +313,7 @@ static void tick_suspend(void) | |||
310 | unsigned long flags; | 313 | unsigned long flags; |
311 | 314 | ||
312 | spin_lock_irqsave(&tick_device_lock, flags); | 315 | spin_lock_irqsave(&tick_device_lock, flags); |
313 | clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_SHUTDOWN); | 316 | clockevents_shutdown(td->evtdev); |
314 | spin_unlock_irqrestore(&tick_device_lock, flags); | 317 | spin_unlock_irqrestore(&tick_device_lock, flags); |
315 | } | 318 | } |
316 | 319 | ||
diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h index f13f2b7f4fd4..b1c05bf75ee0 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,8 @@ 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); | ||
39 | extern void tick_check_oneshot_broadcast(int cpu); | ||
30 | # else /* BROADCAST */ | 40 | # else /* BROADCAST */ |
31 | static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) | 41 | static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) |
32 | { | 42 | { |
@@ -35,6 +45,8 @@ static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) | |||
35 | static inline void tick_broadcast_oneshot_control(unsigned long reason) { } | 45 | static inline void tick_broadcast_oneshot_control(unsigned long reason) { } |
36 | static inline void tick_broadcast_switch_to_oneshot(void) { } | 46 | static inline void tick_broadcast_switch_to_oneshot(void) { } |
37 | static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } | 47 | static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } |
48 | static inline int tick_broadcast_oneshot_active(void) { return 0; } | ||
49 | static inline void tick_check_oneshot_broadcast(int cpu) { } | ||
38 | # endif /* !BROADCAST */ | 50 | # endif /* !BROADCAST */ |
39 | 51 | ||
40 | #else /* !ONESHOT */ | 52 | #else /* !ONESHOT */ |
@@ -64,6 +76,7 @@ static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc) | |||
64 | { | 76 | { |
65 | return 0; | 77 | return 0; |
66 | } | 78 | } |
79 | static inline int tick_broadcast_oneshot_active(void) { return 0; } | ||
67 | #endif /* !TICK_ONESHOT */ | 80 | #endif /* !TICK_ONESHOT */ |
68 | 81 | ||
69 | /* | 82 | /* |
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 f5da526424a9..0581c11fe6c6 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 | } |
@@ -151,7 +155,7 @@ void tick_nohz_update_jiffies(void) | |||
151 | touch_softlockup_watchdog(); | 155 | touch_softlockup_watchdog(); |
152 | } | 156 | } |
153 | 157 | ||
154 | void tick_nohz_stop_idle(int cpu) | 158 | static void tick_nohz_stop_idle(int cpu) |
155 | { | 159 | { |
156 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | 160 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); |
157 | 161 | ||
@@ -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)) |
@@ -255,7 +270,7 @@ void tick_nohz_stop_sched_tick(int inidle) | |||
255 | next_jiffies = get_next_timer_interrupt(last_jiffies); | 270 | next_jiffies = get_next_timer_interrupt(last_jiffies); |
256 | delta_jiffies = next_jiffies - last_jiffies; | 271 | delta_jiffies = next_jiffies - last_jiffies; |
257 | 272 | ||
258 | if (rcu_needs_cpu(cpu)) | 273 | if (rcu_needs_cpu(cpu) || printk_needs_cpu(cpu)) |
259 | delta_jiffies = 1; | 274 | delta_jiffies = 1; |
260 | /* | 275 | /* |
261 | * Do not stop the tick, if we are only one off | 276 | * Do not stop the tick, if we are only one off |
@@ -300,7 +315,7 @@ void tick_nohz_stop_sched_tick(int inidle) | |||
300 | * invoked. | 315 | * invoked. |
301 | */ | 316 | */ |
302 | if (cpu == tick_do_timer_cpu) | 317 | if (cpu == tick_do_timer_cpu) |
303 | tick_do_timer_cpu = -1; | 318 | tick_do_timer_cpu = TICK_DO_TIMER_NONE; |
304 | 319 | ||
305 | ts->idle_sleeps++; | 320 | ts->idle_sleeps++; |
306 | 321 | ||
@@ -362,6 +377,32 @@ ktime_t tick_nohz_get_sleep_length(void) | |||
362 | return ts->sleep_length; | 377 | return ts->sleep_length; |
363 | } | 378 | } |
364 | 379 | ||
380 | static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) | ||
381 | { | ||
382 | hrtimer_cancel(&ts->sched_timer); | ||
383 | ts->sched_timer.expires = ts->idle_tick; | ||
384 | |||
385 | while (1) { | ||
386 | /* Forward the time to expire in the future */ | ||
387 | hrtimer_forward(&ts->sched_timer, now, tick_period); | ||
388 | |||
389 | if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { | ||
390 | hrtimer_start(&ts->sched_timer, | ||
391 | ts->sched_timer.expires, | ||
392 | HRTIMER_MODE_ABS); | ||
393 | /* Check, if the timer was already in the past */ | ||
394 | if (hrtimer_active(&ts->sched_timer)) | ||
395 | break; | ||
396 | } else { | ||
397 | if (!tick_program_event(ts->sched_timer.expires, 0)) | ||
398 | break; | ||
399 | } | ||
400 | /* Update jiffies and reread time */ | ||
401 | tick_do_update_jiffies64(now); | ||
402 | now = ktime_get(); | ||
403 | } | ||
404 | } | ||
405 | |||
365 | /** | 406 | /** |
366 | * tick_nohz_restart_sched_tick - restart the idle tick from the idle task | 407 | * tick_nohz_restart_sched_tick - restart the idle tick from the idle task |
367 | * | 408 | * |
@@ -415,28 +456,7 @@ void tick_nohz_restart_sched_tick(void) | |||
415 | */ | 456 | */ |
416 | ts->tick_stopped = 0; | 457 | ts->tick_stopped = 0; |
417 | ts->idle_exittime = now; | 458 | ts->idle_exittime = now; |
418 | hrtimer_cancel(&ts->sched_timer); | 459 | tick_nohz_restart(ts, now); |
419 | ts->sched_timer.expires = ts->idle_tick; | ||
420 | |||
421 | while (1) { | ||
422 | /* Forward the time to expire in the future */ | ||
423 | hrtimer_forward(&ts->sched_timer, now, tick_period); | ||
424 | |||
425 | if (ts->nohz_mode == NOHZ_MODE_HIGHRES) { | ||
426 | hrtimer_start(&ts->sched_timer, | ||
427 | ts->sched_timer.expires, | ||
428 | HRTIMER_MODE_ABS); | ||
429 | /* Check, if the timer was already in the past */ | ||
430 | if (hrtimer_active(&ts->sched_timer)) | ||
431 | break; | ||
432 | } else { | ||
433 | if (!tick_program_event(ts->sched_timer.expires, 0)) | ||
434 | break; | ||
435 | } | ||
436 | /* Update jiffies and reread time */ | ||
437 | tick_do_update_jiffies64(now); | ||
438 | now = ktime_get(); | ||
439 | } | ||
440 | local_irq_enable(); | 460 | local_irq_enable(); |
441 | } | 461 | } |
442 | 462 | ||
@@ -465,7 +485,7 @@ static void tick_nohz_handler(struct clock_event_device *dev) | |||
465 | * this duty, then the jiffies update is still serialized by | 485 | * this duty, then the jiffies update is still serialized by |
466 | * xtime_lock. | 486 | * xtime_lock. |
467 | */ | 487 | */ |
468 | if (unlikely(tick_do_timer_cpu == -1)) | 488 | if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) |
469 | tick_do_timer_cpu = cpu; | 489 | tick_do_timer_cpu = cpu; |
470 | 490 | ||
471 | /* Check, if the jiffies need an update */ | 491 | /* Check, if the jiffies need an update */ |
@@ -488,10 +508,6 @@ static void tick_nohz_handler(struct clock_event_device *dev) | |||
488 | update_process_times(user_mode(regs)); | 508 | update_process_times(user_mode(regs)); |
489 | profile_tick(CPU_PROFILING); | 509 | profile_tick(CPU_PROFILING); |
490 | 510 | ||
491 | /* Do not restart, when we are in the idle loop */ | ||
492 | if (ts->tick_stopped) | ||
493 | return; | ||
494 | |||
495 | while (tick_nohz_reprogram(ts, now)) { | 511 | while (tick_nohz_reprogram(ts, now)) { |
496 | now = ktime_get(); | 512 | now = ktime_get(); |
497 | tick_do_update_jiffies64(now); | 513 | tick_do_update_jiffies64(now); |
@@ -537,6 +553,27 @@ static void tick_nohz_switch_to_nohz(void) | |||
537 | smp_processor_id()); | 553 | smp_processor_id()); |
538 | } | 554 | } |
539 | 555 | ||
556 | /* | ||
557 | * When NOHZ is enabled and the tick is stopped, we need to kick the | ||
558 | * tick timer from irq_enter() so that the jiffies update is kept | ||
559 | * alive during long running softirqs. That's ugly as hell, but | ||
560 | * correctness is key even if we need to fix the offending softirq in | ||
561 | * the first place. | ||
562 | * | ||
563 | * Note, this is different to tick_nohz_restart. We just kick the | ||
564 | * timer and do not touch the other magic bits which need to be done | ||
565 | * when idle is left. | ||
566 | */ | ||
567 | static void tick_nohz_kick_tick(int cpu) | ||
568 | { | ||
569 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | ||
570 | |||
571 | if (!ts->tick_stopped) | ||
572 | return; | ||
573 | |||
574 | tick_nohz_restart(ts, ktime_get()); | ||
575 | } | ||
576 | |||
540 | #else | 577 | #else |
541 | 578 | ||
542 | static inline void tick_nohz_switch_to_nohz(void) { } | 579 | static inline void tick_nohz_switch_to_nohz(void) { } |
@@ -544,6 +581,19 @@ static inline void tick_nohz_switch_to_nohz(void) { } | |||
544 | #endif /* NO_HZ */ | 581 | #endif /* NO_HZ */ |
545 | 582 | ||
546 | /* | 583 | /* |
584 | * Called from irq_enter to notify about the possible interruption of idle() | ||
585 | */ | ||
586 | void tick_check_idle(int cpu) | ||
587 | { | ||
588 | tick_check_oneshot_broadcast(cpu); | ||
589 | #ifdef CONFIG_NO_HZ | ||
590 | tick_nohz_stop_idle(cpu); | ||
591 | tick_nohz_update_jiffies(); | ||
592 | tick_nohz_kick_tick(cpu); | ||
593 | #endif | ||
594 | } | ||
595 | |||
596 | /* | ||
547 | * High resolution timer specific code | 597 | * High resolution timer specific code |
548 | */ | 598 | */ |
549 | #ifdef CONFIG_HIGH_RES_TIMERS | 599 | #ifdef CONFIG_HIGH_RES_TIMERS |
@@ -567,7 +617,7 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer) | |||
567 | * this duty, then the jiffies update is still serialized by | 617 | * this duty, then the jiffies update is still serialized by |
568 | * xtime_lock. | 618 | * xtime_lock. |
569 | */ | 619 | */ |
570 | if (unlikely(tick_do_timer_cpu == -1)) | 620 | if (unlikely(tick_do_timer_cpu == TICK_DO_TIMER_NONE)) |
571 | tick_do_timer_cpu = cpu; | 621 | tick_do_timer_cpu = cpu; |
572 | #endif | 622 | #endif |
573 | 623 | ||
@@ -596,10 +646,6 @@ static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer) | |||
596 | profile_tick(CPU_PROFILING); | 646 | profile_tick(CPU_PROFILING); |
597 | } | 647 | } |
598 | 648 | ||
599 | /* Do not restart, when we are in the idle loop */ | ||
600 | if (ts->tick_stopped) | ||
601 | return HRTIMER_NORESTART; | ||
602 | |||
603 | hrtimer_forward(timer, now, tick_period); | 649 | hrtimer_forward(timer, now, tick_period); |
604 | 650 | ||
605 | return HRTIMER_RESTART; | 651 | return HRTIMER_RESTART; |
@@ -619,7 +665,7 @@ void tick_setup_sched_timer(void) | |||
619 | */ | 665 | */ |
620 | hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); | 666 | hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
621 | ts->sched_timer.function = tick_sched_timer; | 667 | ts->sched_timer.function = tick_sched_timer; |
622 | ts->sched_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 668 | ts->sched_timer.cb_mode = HRTIMER_CB_IRQSAFE_PERCPU; |
623 | 669 | ||
624 | /* Get the next period (per cpu) */ | 670 | /* Get the next period (per cpu) */ |
625 | ts->sched_timer.expires = tick_init_jiffy_update(); | 671 | ts->sched_timer.expires = tick_init_jiffy_update(); |
@@ -643,17 +689,21 @@ void tick_setup_sched_timer(void) | |||
643 | ts->nohz_mode = NOHZ_MODE_HIGHRES; | 689 | ts->nohz_mode = NOHZ_MODE_HIGHRES; |
644 | #endif | 690 | #endif |
645 | } | 691 | } |
692 | #endif /* HIGH_RES_TIMERS */ | ||
646 | 693 | ||
694 | #if defined CONFIG_NO_HZ || defined CONFIG_HIGH_RES_TIMERS | ||
647 | void tick_cancel_sched_timer(int cpu) | 695 | void tick_cancel_sched_timer(int cpu) |
648 | { | 696 | { |
649 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | 697 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); |
650 | 698 | ||
699 | # ifdef CONFIG_HIGH_RES_TIMERS | ||
651 | if (ts->sched_timer.base) | 700 | if (ts->sched_timer.base) |
652 | hrtimer_cancel(&ts->sched_timer); | 701 | hrtimer_cancel(&ts->sched_timer); |
702 | # endif | ||
653 | 703 | ||
654 | ts->nohz_mode = NOHZ_MODE_INACTIVE; | 704 | ts->nohz_mode = NOHZ_MODE_INACTIVE; |
655 | } | 705 | } |
656 | #endif /* HIGH_RES_TIMERS */ | 706 | #endif |
657 | 707 | ||
658 | /** | 708 | /** |
659 | * Async notification about clocksource changes | 709 | * Async notification about clocksource changes |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index e91c29f961c9..e7acfb482a68 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -58,27 +58,26 @@ struct clocksource *clock; | |||
58 | 58 | ||
59 | #ifdef CONFIG_GENERIC_TIME | 59 | #ifdef CONFIG_GENERIC_TIME |
60 | /** | 60 | /** |
61 | * __get_nsec_offset - Returns nanoseconds since last call to periodic_hook | 61 | * clocksource_forward_now - update clock to the current time |
62 | * | 62 | * |
63 | * private function, must hold xtime_lock lock when being | 63 | * Forward the current clock to update its state since the last call to |
64 | * called. Returns the number of nanoseconds since the | 64 | * update_wall_time(). This is useful before significant clock changes, |
65 | * last call to update_wall_time() (adjusted by NTP scaling) | 65 | * as it avoids having to deal with this time offset explicitly. |
66 | */ | 66 | */ |
67 | static inline s64 __get_nsec_offset(void) | 67 | static void clocksource_forward_now(void) |
68 | { | 68 | { |
69 | cycle_t cycle_now, cycle_delta; | 69 | cycle_t cycle_now, cycle_delta; |
70 | s64 ns_offset; | 70 | s64 nsec; |
71 | 71 | ||
72 | /* read clocksource: */ | ||
73 | cycle_now = clocksource_read(clock); | 72 | cycle_now = clocksource_read(clock); |
74 | |||
75 | /* calculate the delta since the last update_wall_time: */ | ||
76 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | 73 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; |
74 | clock->cycle_last = cycle_now; | ||
77 | 75 | ||
78 | /* convert to nanoseconds: */ | 76 | nsec = cyc2ns(clock, cycle_delta); |
79 | ns_offset = cyc2ns(clock, cycle_delta); | 77 | timespec_add_ns(&xtime, nsec); |
80 | 78 | ||
81 | return ns_offset; | 79 | nsec = ((s64)cycle_delta * clock->mult_orig) >> clock->shift; |
80 | clock->raw_time.tv_nsec += nsec; | ||
82 | } | 81 | } |
83 | 82 | ||
84 | /** | 83 | /** |
@@ -89,6 +88,7 @@ static inline s64 __get_nsec_offset(void) | |||
89 | */ | 88 | */ |
90 | void getnstimeofday(struct timespec *ts) | 89 | void getnstimeofday(struct timespec *ts) |
91 | { | 90 | { |
91 | cycle_t cycle_now, cycle_delta; | ||
92 | unsigned long seq; | 92 | unsigned long seq; |
93 | s64 nsecs; | 93 | s64 nsecs; |
94 | 94 | ||
@@ -96,7 +96,15 @@ void getnstimeofday(struct timespec *ts) | |||
96 | seq = read_seqbegin(&xtime_lock); | 96 | seq = read_seqbegin(&xtime_lock); |
97 | 97 | ||
98 | *ts = xtime; | 98 | *ts = xtime; |
99 | nsecs = __get_nsec_offset(); | 99 | |
100 | /* read clocksource: */ | ||
101 | cycle_now = clocksource_read(clock); | ||
102 | |||
103 | /* calculate the delta since the last update_wall_time: */ | ||
104 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | ||
105 | |||
106 | /* convert to nanoseconds: */ | ||
107 | nsecs = cyc2ns(clock, cycle_delta); | ||
100 | 108 | ||
101 | } while (read_seqretry(&xtime_lock, seq)); | 109 | } while (read_seqretry(&xtime_lock, seq)); |
102 | 110 | ||
@@ -129,22 +137,22 @@ EXPORT_SYMBOL(do_gettimeofday); | |||
129 | */ | 137 | */ |
130 | int do_settimeofday(struct timespec *tv) | 138 | int do_settimeofday(struct timespec *tv) |
131 | { | 139 | { |
140 | struct timespec ts_delta; | ||
132 | unsigned long flags; | 141 | unsigned long flags; |
133 | time_t wtm_sec, sec = tv->tv_sec; | ||
134 | long wtm_nsec, nsec = tv->tv_nsec; | ||
135 | 142 | ||
136 | if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) | 143 | if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) |
137 | return -EINVAL; | 144 | return -EINVAL; |
138 | 145 | ||
139 | write_seqlock_irqsave(&xtime_lock, flags); | 146 | write_seqlock_irqsave(&xtime_lock, flags); |
140 | 147 | ||
141 | nsec -= __get_nsec_offset(); | 148 | clocksource_forward_now(); |
149 | |||
150 | ts_delta.tv_sec = tv->tv_sec - xtime.tv_sec; | ||
151 | ts_delta.tv_nsec = tv->tv_nsec - xtime.tv_nsec; | ||
152 | wall_to_monotonic = timespec_sub(wall_to_monotonic, ts_delta); | ||
142 | 153 | ||
143 | wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec); | 154 | xtime = *tv; |
144 | wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec); | ||
145 | 155 | ||
146 | set_normalized_timespec(&xtime, sec, nsec); | ||
147 | set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); | ||
148 | update_xtime_cache(0); | 156 | update_xtime_cache(0); |
149 | 157 | ||
150 | clock->error = 0; | 158 | clock->error = 0; |
@@ -170,22 +178,19 @@ EXPORT_SYMBOL(do_settimeofday); | |||
170 | static void change_clocksource(void) | 178 | static void change_clocksource(void) |
171 | { | 179 | { |
172 | struct clocksource *new; | 180 | struct clocksource *new; |
173 | cycle_t now; | ||
174 | u64 nsec; | ||
175 | 181 | ||
176 | new = clocksource_get_next(); | 182 | new = clocksource_get_next(); |
177 | 183 | ||
178 | if (clock == new) | 184 | if (clock == new) |
179 | return; | 185 | return; |
180 | 186 | ||
181 | new->cycle_last = 0; | 187 | clocksource_forward_now(); |
182 | now = clocksource_read(new); | ||
183 | nsec = __get_nsec_offset(); | ||
184 | timespec_add_ns(&xtime, nsec); | ||
185 | 188 | ||
186 | clock = new; | 189 | new->raw_time = clock->raw_time; |
187 | clock->cycle_last = now; | ||
188 | 190 | ||
191 | clock = new; | ||
192 | clock->cycle_last = 0; | ||
193 | clock->cycle_last = clocksource_read(new); | ||
189 | clock->error = 0; | 194 | clock->error = 0; |
190 | clock->xtime_nsec = 0; | 195 | clock->xtime_nsec = 0; |
191 | clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); | 196 | clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); |
@@ -200,11 +205,44 @@ static void change_clocksource(void) | |||
200 | */ | 205 | */ |
201 | } | 206 | } |
202 | #else | 207 | #else |
208 | static inline void clocksource_forward_now(void) { } | ||
203 | static inline void change_clocksource(void) { } | 209 | static inline void change_clocksource(void) { } |
204 | static inline s64 __get_nsec_offset(void) { return 0; } | ||
205 | #endif | 210 | #endif |
206 | 211 | ||
207 | /** | 212 | /** |
213 | * getrawmonotonic - Returns the raw monotonic time in a timespec | ||
214 | * @ts: pointer to the timespec to be set | ||
215 | * | ||
216 | * Returns the raw monotonic time (completely un-modified by ntp) | ||
217 | */ | ||
218 | void getrawmonotonic(struct timespec *ts) | ||
219 | { | ||
220 | unsigned long seq; | ||
221 | s64 nsecs; | ||
222 | cycle_t cycle_now, cycle_delta; | ||
223 | |||
224 | do { | ||
225 | seq = read_seqbegin(&xtime_lock); | ||
226 | |||
227 | /* read clocksource: */ | ||
228 | cycle_now = clocksource_read(clock); | ||
229 | |||
230 | /* calculate the delta since the last update_wall_time: */ | ||
231 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | ||
232 | |||
233 | /* convert to nanoseconds: */ | ||
234 | nsecs = ((s64)cycle_delta * clock->mult_orig) >> clock->shift; | ||
235 | |||
236 | *ts = clock->raw_time; | ||
237 | |||
238 | } while (read_seqretry(&xtime_lock, seq)); | ||
239 | |||
240 | timespec_add_ns(ts, nsecs); | ||
241 | } | ||
242 | EXPORT_SYMBOL(getrawmonotonic); | ||
243 | |||
244 | |||
245 | /** | ||
208 | * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres | 246 | * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres |
209 | */ | 247 | */ |
210 | int timekeeping_valid_for_hres(void) | 248 | int timekeeping_valid_for_hres(void) |
@@ -265,8 +303,6 @@ void __init timekeeping_init(void) | |||
265 | static int timekeeping_suspended; | 303 | static int timekeeping_suspended; |
266 | /* time in seconds when suspend began */ | 304 | /* time in seconds when suspend began */ |
267 | static unsigned long timekeeping_suspend_time; | 305 | static unsigned long timekeeping_suspend_time; |
268 | /* xtime offset when we went into suspend */ | ||
269 | static s64 timekeeping_suspend_nsecs; | ||
270 | 306 | ||
271 | /** | 307 | /** |
272 | * timekeeping_resume - Resumes the generic timekeeping subsystem. | 308 | * timekeeping_resume - Resumes the generic timekeeping subsystem. |
@@ -292,8 +328,6 @@ static int timekeeping_resume(struct sys_device *dev) | |||
292 | wall_to_monotonic.tv_sec -= sleep_length; | 328 | wall_to_monotonic.tv_sec -= sleep_length; |
293 | total_sleep_time += sleep_length; | 329 | total_sleep_time += sleep_length; |
294 | } | 330 | } |
295 | /* Make sure that we have the correct xtime reference */ | ||
296 | timespec_add_ns(&xtime, timekeeping_suspend_nsecs); | ||
297 | update_xtime_cache(0); | 331 | update_xtime_cache(0); |
298 | /* re-base the last cycle value */ | 332 | /* re-base the last cycle value */ |
299 | clock->cycle_last = 0; | 333 | clock->cycle_last = 0; |
@@ -319,8 +353,7 @@ static int timekeeping_suspend(struct sys_device *dev, pm_message_t state) | |||
319 | timekeeping_suspend_time = read_persistent_clock(); | 353 | timekeeping_suspend_time = read_persistent_clock(); |
320 | 354 | ||
321 | write_seqlock_irqsave(&xtime_lock, flags); | 355 | write_seqlock_irqsave(&xtime_lock, flags); |
322 | /* Get the current xtime offset */ | 356 | clocksource_forward_now(); |
323 | timekeeping_suspend_nsecs = __get_nsec_offset(); | ||
324 | timekeeping_suspended = 1; | 357 | timekeeping_suspended = 1; |
325 | write_sequnlock_irqrestore(&xtime_lock, flags); | 358 | write_sequnlock_irqrestore(&xtime_lock, flags); |
326 | 359 | ||
@@ -454,23 +487,29 @@ void update_wall_time(void) | |||
454 | #else | 487 | #else |
455 | offset = clock->cycle_interval; | 488 | offset = clock->cycle_interval; |
456 | #endif | 489 | #endif |
457 | clock->xtime_nsec += (s64)xtime.tv_nsec << clock->shift; | 490 | clock->xtime_nsec = (s64)xtime.tv_nsec << clock->shift; |
458 | 491 | ||
459 | /* normally this loop will run just once, however in the | 492 | /* normally this loop will run just once, however in the |
460 | * case of lost or late ticks, it will accumulate correctly. | 493 | * case of lost or late ticks, it will accumulate correctly. |
461 | */ | 494 | */ |
462 | while (offset >= clock->cycle_interval) { | 495 | while (offset >= clock->cycle_interval) { |
463 | /* accumulate one interval */ | 496 | /* accumulate one interval */ |
464 | clock->xtime_nsec += clock->xtime_interval; | ||
465 | clock->cycle_last += clock->cycle_interval; | ||
466 | offset -= clock->cycle_interval; | 497 | offset -= clock->cycle_interval; |
498 | clock->cycle_last += clock->cycle_interval; | ||
467 | 499 | ||
500 | clock->xtime_nsec += clock->xtime_interval; | ||
468 | if (clock->xtime_nsec >= (u64)NSEC_PER_SEC << clock->shift) { | 501 | if (clock->xtime_nsec >= (u64)NSEC_PER_SEC << clock->shift) { |
469 | clock->xtime_nsec -= (u64)NSEC_PER_SEC << clock->shift; | 502 | clock->xtime_nsec -= (u64)NSEC_PER_SEC << clock->shift; |
470 | xtime.tv_sec++; | 503 | xtime.tv_sec++; |
471 | second_overflow(); | 504 | second_overflow(); |
472 | } | 505 | } |
473 | 506 | ||
507 | clock->raw_time.tv_nsec += clock->raw_interval; | ||
508 | if (clock->raw_time.tv_nsec >= NSEC_PER_SEC) { | ||
509 | clock->raw_time.tv_nsec -= NSEC_PER_SEC; | ||
510 | clock->raw_time.tv_sec++; | ||
511 | } | ||
512 | |||
474 | /* accumulate error between NTP and clock interval */ | 513 | /* accumulate error between NTP and clock interval */ |
475 | clock->error += tick_length; | 514 | clock->error += tick_length; |
476 | clock->error -= clock->xtime_interval << (NTP_SCALE_SHIFT - clock->shift); | 515 | clock->error -= clock->xtime_interval << (NTP_SCALE_SHIFT - clock->shift); |
@@ -479,9 +518,12 @@ void update_wall_time(void) | |||
479 | /* correct the clock when NTP error is too big */ | 518 | /* correct the clock when NTP error is too big */ |
480 | clocksource_adjust(offset); | 519 | clocksource_adjust(offset); |
481 | 520 | ||
482 | /* store full nanoseconds into xtime */ | 521 | /* store full nanoseconds into xtime after rounding it up and |
483 | xtime.tv_nsec = (s64)clock->xtime_nsec >> clock->shift; | 522 | * add the remainder to the error difference. |
523 | */ | ||
524 | xtime.tv_nsec = ((s64)clock->xtime_nsec >> clock->shift) + 1; | ||
484 | clock->xtime_nsec -= (s64)xtime.tv_nsec << clock->shift; | 525 | clock->xtime_nsec -= (s64)xtime.tv_nsec << clock->shift; |
526 | clock->error += clock->xtime_nsec << (NTP_SCALE_SHIFT - clock->shift); | ||
485 | 527 | ||
486 | update_xtime_cache(cyc2ns(clock, offset)); | 528 | update_xtime_cache(cyc2ns(clock, offset)); |
487 | 529 | ||
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index a40e20fd0001..f6426911e35a 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c | |||
@@ -47,13 +47,14 @@ static void print_name_offset(struct seq_file *m, void *sym) | |||
47 | } | 47 | } |
48 | 48 | ||
49 | static void | 49 | static void |
50 | print_timer(struct seq_file *m, struct hrtimer *timer, int idx, u64 now) | 50 | print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer, |
51 | int idx, u64 now) | ||
51 | { | 52 | { |
52 | #ifdef CONFIG_TIMER_STATS | 53 | #ifdef CONFIG_TIMER_STATS |
53 | char tmp[TASK_COMM_LEN + 1]; | 54 | char tmp[TASK_COMM_LEN + 1]; |
54 | #endif | 55 | #endif |
55 | SEQ_printf(m, " #%d: ", idx); | 56 | SEQ_printf(m, " #%d: ", idx); |
56 | print_name_offset(m, timer); | 57 | print_name_offset(m, taddr); |
57 | SEQ_printf(m, ", "); | 58 | SEQ_printf(m, ", "); |
58 | print_name_offset(m, timer->function); | 59 | print_name_offset(m, timer->function); |
59 | SEQ_printf(m, ", S:%02lx", timer->state); | 60 | SEQ_printf(m, ", S:%02lx", timer->state); |
@@ -99,7 +100,7 @@ next_one: | |||
99 | tmp = *timer; | 100 | tmp = *timer; |
100 | spin_unlock_irqrestore(&base->cpu_base->lock, flags); | 101 | spin_unlock_irqrestore(&base->cpu_base->lock, flags); |
101 | 102 | ||
102 | print_timer(m, &tmp, i, now); | 103 | print_timer(m, timer, &tmp, i, now); |
103 | next++; | 104 | next++; |
104 | goto next_one; | 105 | goto next_one; |
105 | } | 106 | } |
@@ -109,6 +110,7 @@ next_one: | |||
109 | static void | 110 | static void |
110 | print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now) | 111 | print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now) |
111 | { | 112 | { |
113 | SEQ_printf(m, " .base: %p\n", base); | ||
112 | SEQ_printf(m, " .index: %d\n", | 114 | SEQ_printf(m, " .index: %d\n", |
113 | base->index); | 115 | base->index); |
114 | SEQ_printf(m, " .resolution: %Lu nsecs\n", | 116 | SEQ_printf(m, " .resolution: %Lu nsecs\n", |
@@ -183,12 +185,16 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now) | |||
183 | 185 | ||
184 | #ifdef CONFIG_GENERIC_CLOCKEVENTS | 186 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
185 | static void | 187 | static void |
186 | print_tickdevice(struct seq_file *m, struct tick_device *td) | 188 | print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu) |
187 | { | 189 | { |
188 | struct clock_event_device *dev = td->evtdev; | 190 | struct clock_event_device *dev = td->evtdev; |
189 | 191 | ||
190 | SEQ_printf(m, "\n"); | 192 | SEQ_printf(m, "\n"); |
191 | SEQ_printf(m, "Tick Device: mode: %d\n", td->mode); | 193 | SEQ_printf(m, "Tick Device: mode: %d\n", td->mode); |
194 | if (cpu < 0) | ||
195 | SEQ_printf(m, "Broadcast device\n"); | ||
196 | else | ||
197 | SEQ_printf(m, "Per CPU device: %d\n", cpu); | ||
192 | 198 | ||
193 | SEQ_printf(m, "Clock Event Device: "); | 199 | SEQ_printf(m, "Clock Event Device: "); |
194 | if (!dev) { | 200 | if (!dev) { |
@@ -222,7 +228,7 @@ static void timer_list_show_tickdevices(struct seq_file *m) | |||
222 | int cpu; | 228 | int cpu; |
223 | 229 | ||
224 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST | 230 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
225 | print_tickdevice(m, tick_get_broadcast_device()); | 231 | print_tickdevice(m, tick_get_broadcast_device(), -1); |
226 | SEQ_printf(m, "tick_broadcast_mask: %08lx\n", | 232 | SEQ_printf(m, "tick_broadcast_mask: %08lx\n", |
227 | tick_get_broadcast_mask()->bits[0]); | 233 | tick_get_broadcast_mask()->bits[0]); |
228 | #ifdef CONFIG_TICK_ONESHOT | 234 | #ifdef CONFIG_TICK_ONESHOT |
@@ -232,7 +238,7 @@ static void timer_list_show_tickdevices(struct seq_file *m) | |||
232 | SEQ_printf(m, "\n"); | 238 | SEQ_printf(m, "\n"); |
233 | #endif | 239 | #endif |
234 | for_each_online_cpu(cpu) | 240 | for_each_online_cpu(cpu) |
235 | print_tickdevice(m, tick_get_device(cpu)); | 241 | print_tickdevice(m, tick_get_device(cpu), cpu); |
236 | SEQ_printf(m, "\n"); | 242 | SEQ_printf(m, "\n"); |
237 | } | 243 | } |
238 | #else | 244 | #else |
@@ -244,7 +250,7 @@ static int timer_list_show(struct seq_file *m, void *v) | |||
244 | u64 now = ktime_to_ns(ktime_get()); | 250 | u64 now = ktime_to_ns(ktime_get()); |
245 | int cpu; | 251 | int cpu; |
246 | 252 | ||
247 | SEQ_printf(m, "Timer List Version: v0.3\n"); | 253 | SEQ_printf(m, "Timer List Version: v0.4\n"); |
248 | SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES); | 254 | SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES); |
249 | SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now); | 255 | SEQ_printf(m, "now at %Ld nsecs\n", (unsigned long long)now); |
250 | 256 | ||
diff --git a/kernel/timer.c b/kernel/timer.c index e8019cc3418d..56becf373c58 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -978,6 +978,7 @@ void update_process_times(int user_tick) | |||
978 | run_local_timers(); | 978 | run_local_timers(); |
979 | if (rcu_pending(cpu)) | 979 | if (rcu_pending(cpu)) |
980 | rcu_check_callbacks(cpu, user_tick); | 980 | rcu_check_callbacks(cpu, user_tick); |
981 | printk_tick(); | ||
981 | scheduler_tick(); | 982 | scheduler_tick(); |
982 | run_posix_cpu_timers(p); | 983 | run_posix_cpu_timers(p); |
983 | } | 984 | } |
diff --git a/kernel/trace/trace_sysprof.c b/kernel/trace/trace_sysprof.c index bb948e52ce20..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 | } |
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..3b34b3545936 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) |
@@ -61,7 +60,7 @@ static int proc_do_uts_string(ctl_table *table, int write, struct file *filp, | |||
61 | 60 | ||
62 | #ifdef CONFIG_SYSCTL_SYSCALL | 61 | #ifdef CONFIG_SYSCTL_SYSCALL |
63 | /* The generic string strategy routine: */ | 62 | /* The generic string strategy routine: */ |
64 | static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen, | 63 | static int sysctl_uts_string(ctl_table *table, |
65 | void __user *oldval, size_t __user *oldlenp, | 64 | void __user *oldval, size_t __user *oldlenp, |
66 | void __user *newval, size_t newlen) | 65 | void __user *newval, size_t newlen) |
67 | { | 66 | { |
@@ -70,8 +69,7 @@ static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen, | |||
70 | write = newval && newlen; | 69 | write = newval && newlen; |
71 | memcpy(&uts_table, table, sizeof(uts_table)); | 70 | memcpy(&uts_table, table, sizeof(uts_table)); |
72 | uts_table.data = get_uts(table, write); | 71 | uts_table.data = get_uts(table, write); |
73 | r = sysctl_string(&uts_table, name, nlen, | 72 | r = sysctl_string(&uts_table, oldval, oldlenp, newval, newlen); |
74 | oldval, oldlenp, newval, newlen); | ||
75 | put_uts(table, write, uts_table.data); | 73 | put_uts(table, write, uts_table.data); |
76 | return r; | 74 | return r; |
77 | } | 75 | } |
diff --git a/kernel/wait.c b/kernel/wait.c index c275c56cf2d3..cd87131f2fc2 100644 --- a/kernel/wait.c +++ b/kernel/wait.c | |||
@@ -72,12 +72,7 @@ prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state) | |||
72 | spin_lock_irqsave(&q->lock, flags); | 72 | spin_lock_irqsave(&q->lock, flags); |
73 | if (list_empty(&wait->task_list)) | 73 | if (list_empty(&wait->task_list)) |
74 | __add_wait_queue(q, wait); | 74 | __add_wait_queue(q, wait); |
75 | /* | 75 | set_current_state(state); |
76 | * don't alter the task state if this is just going to | ||
77 | * queue an async wait queue callback | ||
78 | */ | ||
79 | if (is_sync_wait(wait)) | ||
80 | set_current_state(state); | ||
81 | spin_unlock_irqrestore(&q->lock, flags); | 76 | spin_unlock_irqrestore(&q->lock, flags); |
82 | } | 77 | } |
83 | EXPORT_SYMBOL(prepare_to_wait); | 78 | EXPORT_SYMBOL(prepare_to_wait); |
@@ -91,12 +86,7 @@ prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state) | |||
91 | spin_lock_irqsave(&q->lock, flags); | 86 | spin_lock_irqsave(&q->lock, flags); |
92 | if (list_empty(&wait->task_list)) | 87 | if (list_empty(&wait->task_list)) |
93 | __add_wait_queue_tail(q, wait); | 88 | __add_wait_queue_tail(q, wait); |
94 | /* | 89 | set_current_state(state); |
95 | * don't alter the task state if this is just going to | ||
96 | * queue an async wait queue callback | ||
97 | */ | ||
98 | if (is_sync_wait(wait)) | ||
99 | set_current_state(state); | ||
100 | spin_unlock_irqrestore(&q->lock, flags); | 90 | spin_unlock_irqrestore(&q->lock, flags); |
101 | } | 91 | } |
102 | EXPORT_SYMBOL(prepare_to_wait_exclusive); | 92 | EXPORT_SYMBOL(prepare_to_wait_exclusive); |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 4048e92aa04f..714afad46539 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * Derived from the taskqueue/keventd code by: | 9 | * Derived from the taskqueue/keventd code by: |
10 | * | 10 | * |
11 | * David Woodhouse <dwmw2@infradead.org> | 11 | * David Woodhouse <dwmw2@infradead.org> |
12 | * Andrew Morton <andrewm@uow.edu.au> | 12 | * Andrew Morton |
13 | * Kai Petzke <wpp@marie.physik.tu-berlin.de> | 13 | * Kai Petzke <wpp@marie.physik.tu-berlin.de> |
14 | * Theodore Ts'o <tytso@mit.edu> | 14 | * Theodore Ts'o <tytso@mit.edu> |
15 | * | 15 | * |