aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c205
1 files changed, 166 insertions, 39 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 4de2bfb28c58..669c49aa57f0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -609,9 +609,9 @@ struct rq {
609 609
610static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); 610static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
611 611
612static inline void check_preempt_curr(struct rq *rq, struct task_struct *p) 612static inline void check_preempt_curr(struct rq *rq, struct task_struct *p, int sync)
613{ 613{
614 rq->curr->sched_class->check_preempt_curr(rq, p); 614 rq->curr->sched_class->check_preempt_curr(rq, p, sync);
615} 615}
616 616
617static inline int cpu_of(struct rq *rq) 617static inline int cpu_of(struct rq *rq)
@@ -1092,7 +1092,7 @@ hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu)
1092 return NOTIFY_DONE; 1092 return NOTIFY_DONE;
1093} 1093}
1094 1094
1095static void init_hrtick(void) 1095static __init void init_hrtick(void)
1096{ 1096{
1097 hotcpu_notifier(hotplug_hrtick, 0); 1097 hotcpu_notifier(hotplug_hrtick, 0);
1098} 1098}
@@ -1107,7 +1107,7 @@ static void hrtick_start(struct rq *rq, u64 delay)
1107 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);
1108} 1108}
1109 1109
1110static void init_hrtick(void) 1110static inline void init_hrtick(void)
1111{ 1111{
1112} 1112}
1113#endif /* CONFIG_SMP */ 1113#endif /* CONFIG_SMP */
@@ -1126,7 +1126,7 @@ static void init_rq_hrtick(struct rq *rq)
1126 rq->hrtick_timer.function = hrtick; 1126 rq->hrtick_timer.function = hrtick;
1127 rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; 1127 rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
1128} 1128}
1129#else 1129#else /* CONFIG_SCHED_HRTICK */
1130static inline void hrtick_clear(struct rq *rq) 1130static inline void hrtick_clear(struct rq *rq)
1131{ 1131{
1132} 1132}
@@ -1138,7 +1138,7 @@ static inline void init_rq_hrtick(struct rq *rq)
1138static inline void init_hrtick(void) 1138static inline void init_hrtick(void)
1139{ 1139{
1140} 1140}
1141#endif 1141#endif /* CONFIG_SCHED_HRTICK */
1142 1142
1143/* 1143/*
1144 * resched_task - mark a task 'to be rescheduled now'. 1144 * resched_task - mark a task 'to be rescheduled now'.
@@ -1939,11 +1939,8 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
1939 running = task_running(rq, p); 1939 running = task_running(rq, p);
1940 on_rq = p->se.on_rq; 1940 on_rq = p->se.on_rq;
1941 ncsw = 0; 1941 ncsw = 0;
1942 if (!match_state || p->state == match_state) { 1942 if (!match_state || p->state == match_state)
1943 ncsw = p->nivcsw + p->nvcsw; 1943 ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
1944 if (unlikely(!ncsw))
1945 ncsw = 1;
1946 }
1947 task_rq_unlock(rq, &flags); 1944 task_rq_unlock(rq, &flags);
1948 1945
1949 /* 1946 /*
@@ -2303,7 +2300,7 @@ out_running:
2303 trace_mark(kernel_sched_wakeup, 2300 trace_mark(kernel_sched_wakeup,
2304 "pid %d state %ld ## rq %p task %p rq->curr %p", 2301 "pid %d state %ld ## rq %p task %p rq->curr %p",
2305 p->pid, p->state, rq, p, rq->curr); 2302 p->pid, p->state, rq, p, rq->curr);
2306 check_preempt_curr(rq, p); 2303 check_preempt_curr(rq, p, sync);
2307 2304
2308 p->state = TASK_RUNNING; 2305 p->state = TASK_RUNNING;
2309#ifdef CONFIG_SMP 2306#ifdef CONFIG_SMP
@@ -2438,7 +2435,7 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
2438 trace_mark(kernel_sched_wakeup_new, 2435 trace_mark(kernel_sched_wakeup_new,
2439 "pid %d state %ld ## rq %p task %p rq->curr %p", 2436 "pid %d state %ld ## rq %p task %p rq->curr %p",
2440 p->pid, p->state, rq, p, rq->curr); 2437 p->pid, p->state, rq, p, rq->curr);
2441 check_preempt_curr(rq, p); 2438 check_preempt_curr(rq, p, 0);
2442#ifdef CONFIG_SMP 2439#ifdef CONFIG_SMP
2443 if (p->sched_class->task_wake_up) 2440 if (p->sched_class->task_wake_up)
2444 p->sched_class->task_wake_up(rq, p); 2441 p->sched_class->task_wake_up(rq, p);
@@ -2898,7 +2895,7 @@ static void pull_task(struct rq *src_rq, struct task_struct *p,
2898 * 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
2899 * to be always true for them. 2896 * to be always true for them.
2900 */ 2897 */
2901 check_preempt_curr(this_rq, p); 2898 check_preempt_curr(this_rq, p, 0);
2902} 2899}
2903 2900
2904/* 2901/*
@@ -4197,6 +4194,65 @@ void account_steal_time(struct task_struct *p, cputime_t steal)
4197} 4194}
4198 4195
4199/* 4196/*
4197 * Use precise platform statistics if available:
4198 */
4199#ifdef CONFIG_VIRT_CPU_ACCOUNTING
4200cputime_t task_utime(struct task_struct *p)
4201{
4202 return p->utime;
4203}
4204
4205cputime_t task_stime(struct task_struct *p)
4206{
4207 return p->stime;
4208}
4209#else
4210cputime_t task_utime(struct task_struct *p)
4211{
4212 clock_t utime = cputime_to_clock_t(p->utime),
4213 total = utime + cputime_to_clock_t(p->stime);
4214 u64 temp;
4215
4216 /*
4217 * Use CFS's precise accounting:
4218 */
4219 temp = (u64)nsec_to_clock_t(p->se.sum_exec_runtime);
4220
4221 if (total) {
4222 temp *= utime;
4223 do_div(temp, total);
4224 }
4225 utime = (clock_t)temp;
4226
4227 p->prev_utime = max(p->prev_utime, clock_t_to_cputime(utime));
4228 return p->prev_utime;
4229}
4230
4231cputime_t task_stime(struct task_struct *p)
4232{
4233 clock_t stime;
4234
4235 /*
4236 * Use CFS's precise accounting. (we subtract utime from
4237 * the total, to make sure the total observed by userspace
4238 * grows monotonically - apps rely on that):
4239 */
4240 stime = nsec_to_clock_t(p->se.sum_exec_runtime) -
4241 cputime_to_clock_t(task_utime(p));
4242
4243 if (stime >= 0)
4244 p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime));
4245
4246 return p->prev_stime;
4247}
4248#endif
4249
4250inline cputime_t task_gtime(struct task_struct *p)
4251{
4252 return p->gtime;
4253}
4254
4255/*
4200 * This function gets called by the timer code, with HZ frequency. 4256 * This function gets called by the timer code, with HZ frequency.
4201 * We call it with interrupts disabled. 4257 * We call it with interrupts disabled.
4202 * 4258 *
@@ -4586,6 +4642,15 @@ __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
4586} 4642}
4587EXPORT_SYMBOL_GPL(__wake_up_sync); /* For internal use only */ 4643EXPORT_SYMBOL_GPL(__wake_up_sync); /* For internal use only */
4588 4644
4645/**
4646 * complete: - signals a single thread waiting on this completion
4647 * @x: holds the state of this particular completion
4648 *
4649 * This will wake up a single thread waiting on this completion. Threads will be
4650 * awakened in the same order in which they were queued.
4651 *
4652 * See also complete_all(), wait_for_completion() and related routines.
4653 */
4589void complete(struct completion *x) 4654void complete(struct completion *x)
4590{ 4655{
4591 unsigned long flags; 4656 unsigned long flags;
@@ -4597,6 +4662,12 @@ void complete(struct completion *x)
4597} 4662}
4598EXPORT_SYMBOL(complete); 4663EXPORT_SYMBOL(complete);
4599 4664
4665/**
4666 * complete_all: - signals all threads waiting on this completion
4667 * @x: holds the state of this particular completion
4668 *
4669 * This will wake up all threads waiting on this particular completion event.
4670 */
4600void complete_all(struct completion *x) 4671void complete_all(struct completion *x)
4601{ 4672{
4602 unsigned long flags; 4673 unsigned long flags;
@@ -4617,10 +4688,7 @@ do_wait_for_common(struct completion *x, long timeout, int state)
4617 wait.flags |= WQ_FLAG_EXCLUSIVE; 4688 wait.flags |= WQ_FLAG_EXCLUSIVE;
4618 __add_wait_queue_tail(&x->wait, &wait); 4689 __add_wait_queue_tail(&x->wait, &wait);
4619 do { 4690 do {
4620 if ((state == TASK_INTERRUPTIBLE && 4691 if (signal_pending_state(state, current)) {
4621 signal_pending(current)) ||
4622 (state == TASK_KILLABLE &&
4623 fatal_signal_pending(current))) {
4624 timeout = -ERESTARTSYS; 4692 timeout = -ERESTARTSYS;
4625 break; 4693 break;
4626 } 4694 }
@@ -4648,12 +4716,31 @@ wait_for_common(struct completion *x, long timeout, int state)
4648 return timeout; 4716 return timeout;
4649} 4717}
4650 4718
4719/**
4720 * wait_for_completion: - waits for completion of a task
4721 * @x: holds the state of this particular completion
4722 *
4723 * This waits to be signaled for completion of a specific task. It is NOT
4724 * interruptible and there is no timeout.
4725 *
4726 * See also similar routines (i.e. wait_for_completion_timeout()) with timeout
4727 * and interrupt capability. Also see complete().
4728 */
4651void __sched wait_for_completion(struct completion *x) 4729void __sched wait_for_completion(struct completion *x)
4652{ 4730{
4653 wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE); 4731 wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE);
4654} 4732}
4655EXPORT_SYMBOL(wait_for_completion); 4733EXPORT_SYMBOL(wait_for_completion);
4656 4734
4735/**
4736 * wait_for_completion_timeout: - waits for completion of a task (w/timeout)
4737 * @x: holds the state of this particular completion
4738 * @timeout: timeout value in jiffies
4739 *
4740 * This waits for either a completion of a specific task to be signaled or for a
4741 * specified timeout to expire. The timeout is in jiffies. It is not
4742 * interruptible.
4743 */
4657unsigned long __sched 4744unsigned long __sched
4658wait_for_completion_timeout(struct completion *x, unsigned long timeout) 4745wait_for_completion_timeout(struct completion *x, unsigned long timeout)
4659{ 4746{
@@ -4661,6 +4748,13 @@ wait_for_completion_timeout(struct completion *x, unsigned long timeout)
4661} 4748}
4662EXPORT_SYMBOL(wait_for_completion_timeout); 4749EXPORT_SYMBOL(wait_for_completion_timeout);
4663 4750
4751/**
4752 * wait_for_completion_interruptible: - waits for completion of a task (w/intr)
4753 * @x: holds the state of this particular completion
4754 *
4755 * This waits for completion of a specific task to be signaled. It is
4756 * interruptible.
4757 */
4664int __sched wait_for_completion_interruptible(struct completion *x) 4758int __sched wait_for_completion_interruptible(struct completion *x)
4665{ 4759{
4666 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE); 4760 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE);
@@ -4670,6 +4764,14 @@ int __sched wait_for_completion_interruptible(struct completion *x)
4670} 4764}
4671EXPORT_SYMBOL(wait_for_completion_interruptible); 4765EXPORT_SYMBOL(wait_for_completion_interruptible);
4672 4766
4767/**
4768 * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr))
4769 * @x: holds the state of this particular completion
4770 * @timeout: timeout value in jiffies
4771 *
4772 * This waits for either a completion of a specific task to be signaled or for a
4773 * specified timeout to expire. It is interruptible. The timeout is in jiffies.
4774 */
4673unsigned long __sched 4775unsigned long __sched
4674wait_for_completion_interruptible_timeout(struct completion *x, 4776wait_for_completion_interruptible_timeout(struct completion *x,
4675 unsigned long timeout) 4777 unsigned long timeout)
@@ -4678,6 +4780,13 @@ wait_for_completion_interruptible_timeout(struct completion *x,
4678} 4780}
4679EXPORT_SYMBOL(wait_for_completion_interruptible_timeout); 4781EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
4680 4782
4783/**
4784 * wait_for_completion_killable: - waits for completion of a task (killable)
4785 * @x: holds the state of this particular completion
4786 *
4787 * This waits to be signaled for completion of a specific task. It can be
4788 * interrupted by a kill signal.
4789 */
4681int __sched wait_for_completion_killable(struct completion *x) 4790int __sched wait_for_completion_killable(struct completion *x)
4682{ 4791{
4683 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE); 4792 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
@@ -5917,7 +6026,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu)
5917 set_task_cpu(p, dest_cpu); 6026 set_task_cpu(p, dest_cpu);
5918 if (on_rq) { 6027 if (on_rq) {
5919 activate_task(rq_dest, p, 0); 6028 activate_task(rq_dest, p, 0);
5920 check_preempt_curr(rq_dest, p); 6029 check_preempt_curr(rq_dest, p, 0);
5921 } 6030 }
5922done: 6031done:
5923 ret = 1; 6032 ret = 1;
@@ -7656,24 +7765,27 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
7656 * and partition_sched_domains() will fallback to the single partition 7765 * and partition_sched_domains() will fallback to the single partition
7657 * 'fallback_doms', it also forces the domains to be rebuilt. 7766 * 'fallback_doms', it also forces the domains to be rebuilt.
7658 * 7767 *
7768 * If doms_new==NULL it will be replaced with cpu_online_map.
7769 * ndoms_new==0 is a special case for destroying existing domains.
7770 * It will not create the default domain.
7771 *
7659 * Call with hotplug lock held 7772 * Call with hotplug lock held
7660 */ 7773 */
7661void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, 7774void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
7662 struct sched_domain_attr *dattr_new) 7775 struct sched_domain_attr *dattr_new)
7663{ 7776{
7664 int i, j; 7777 int i, j, n;
7665 7778
7666 mutex_lock(&sched_domains_mutex); 7779 mutex_lock(&sched_domains_mutex);
7667 7780
7668 /* always unregister in case we don't destroy any domains */ 7781 /* always unregister in case we don't destroy any domains */
7669 unregister_sched_domain_sysctl(); 7782 unregister_sched_domain_sysctl();
7670 7783
7671 if (doms_new == NULL) 7784 n = doms_new ? ndoms_new : 0;
7672 ndoms_new = 0;
7673 7785
7674 /* Destroy deleted domains */ 7786 /* Destroy deleted domains */
7675 for (i = 0; i < ndoms_cur; i++) { 7787 for (i = 0; i < ndoms_cur; i++) {
7676 for (j = 0; j < ndoms_new; j++) { 7788 for (j = 0; j < n; j++) {
7677 if (cpus_equal(doms_cur[i], doms_new[j]) 7789 if (cpus_equal(doms_cur[i], doms_new[j])
7678 && dattrs_equal(dattr_cur, i, dattr_new, j)) 7790 && dattrs_equal(dattr_cur, i, dattr_new, j))
7679 goto match1; 7791 goto match1;
@@ -7686,7 +7798,6 @@ match1:
7686 7798
7687 if (doms_new == NULL) { 7799 if (doms_new == NULL) {
7688 ndoms_cur = 0; 7800 ndoms_cur = 0;
7689 ndoms_new = 1;
7690 doms_new = &fallback_doms; 7801 doms_new = &fallback_doms;
7691 cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); 7802 cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map);
7692 dattr_new = NULL; 7803 dattr_new = NULL;
@@ -7723,8 +7834,13 @@ match2:
7723int arch_reinit_sched_domains(void) 7834int arch_reinit_sched_domains(void)
7724{ 7835{
7725 get_online_cpus(); 7836 get_online_cpus();
7837
7838 /* Destroy domains first to force the rebuild */
7839 partition_sched_domains(0, NULL, NULL);
7840
7726 rebuild_sched_domains(); 7841 rebuild_sched_domains();
7727 put_online_cpus(); 7842 put_online_cpus();
7843
7728 return 0; 7844 return 0;
7729} 7845}
7730 7846
@@ -7808,7 +7924,7 @@ static int update_sched_domains(struct notifier_block *nfb,
7808 case CPU_ONLINE_FROZEN: 7924 case CPU_ONLINE_FROZEN:
7809 case CPU_DEAD: 7925 case CPU_DEAD:
7810 case CPU_DEAD_FROZEN: 7926 case CPU_DEAD_FROZEN:
7811 partition_sched_domains(0, NULL, NULL); 7927 partition_sched_domains(1, NULL, NULL);
7812 return NOTIFY_OK; 7928 return NOTIFY_OK;
7813 7929
7814 default: 7930 default:
@@ -8195,20 +8311,25 @@ void __might_sleep(char *file, int line)
8195#ifdef in_atomic 8311#ifdef in_atomic
8196 static unsigned long prev_jiffy; /* ratelimiting */ 8312 static unsigned long prev_jiffy; /* ratelimiting */
8197 8313
8198 if ((in_atomic() || irqs_disabled()) && 8314 if ((!in_atomic() && !irqs_disabled()) ||
8199 system_state == SYSTEM_RUNNING && !oops_in_progress) { 8315 system_state != SYSTEM_RUNNING || oops_in_progress)
8200 if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) 8316 return;
8201 return; 8317 if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
8202 prev_jiffy = jiffies; 8318 return;
8203 printk(KERN_ERR "BUG: sleeping function called from invalid" 8319 prev_jiffy = jiffies;
8204 " context at %s:%d\n", file, line); 8320
8205 printk("in_atomic():%d, irqs_disabled():%d\n", 8321 printk(KERN_ERR
8206 in_atomic(), irqs_disabled()); 8322 "BUG: sleeping function called from invalid context at %s:%d\n",
8207 debug_show_held_locks(current); 8323 file, line);
8208 if (irqs_disabled()) 8324 printk(KERN_ERR
8209 print_irqtrace_events(current); 8325 "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n",
8210 dump_stack(); 8326 in_atomic(), irqs_disabled(),
8211 } 8327 current->pid, current->comm);
8328
8329 debug_show_held_locks(current);
8330 if (irqs_disabled())
8331 print_irqtrace_events(current);
8332 dump_stack();
8212#endif 8333#endif
8213} 8334}
8214EXPORT_SYMBOL(__might_sleep); 8335EXPORT_SYMBOL(__might_sleep);
@@ -8861,6 +8982,9 @@ static int sched_rt_global_constraints(void)
8861 u64 rt_runtime, rt_period; 8982 u64 rt_runtime, rt_period;
8862 int ret = 0; 8983 int ret = 0;
8863 8984
8985 if (sysctl_sched_rt_period <= 0)
8986 return -EINVAL;
8987
8864 rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period); 8988 rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period);
8865 rt_runtime = tg->rt_bandwidth.rt_runtime; 8989 rt_runtime = tg->rt_bandwidth.rt_runtime;
8866 8990
@@ -8878,6 +9002,9 @@ static int sched_rt_global_constraints(void)
8878 unsigned long flags; 9002 unsigned long flags;
8879 int i; 9003 int i;
8880 9004
9005 if (sysctl_sched_rt_period <= 0)
9006 return -EINVAL;
9007
8881 spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags); 9008 spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags);
8882 for_each_possible_cpu(i) { 9009 for_each_possible_cpu(i) {
8883 struct rt_rq *rt_rq = &cpu_rq(i)->rt; 9010 struct rt_rq *rt_rq = &cpu_rq(i)->rt;