aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-11-26 04:50:39 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-26 04:50:42 -0500
commit16bc67edeb49b531940b2ba6c183780a1b5c472d (patch)
tree71b4bc48e47e54f2c0b3126d8f81d2f31b707ea8 /kernel/sched.c
parentf6630114d9198aa959ac95c131334c020038f253 (diff)
parent047106adcc85e3023da210143a6ab8a55df9e0fc (diff)
Merge branch 'sched/urgent' into sched/core
Merge reason: Pick up fixes that did not make it into .32.0 Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c86
1 files changed, 64 insertions, 22 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 48ff66a6892d..315ba4059f93 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -309,6 +309,8 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rt_rq, init_rt_rq);
309 */ 309 */
310static DEFINE_SPINLOCK(task_group_lock); 310static DEFINE_SPINLOCK(task_group_lock);
311 311
312#ifdef CONFIG_FAIR_GROUP_SCHED
313
312#ifdef CONFIG_SMP 314#ifdef CONFIG_SMP
313static int root_task_group_empty(void) 315static int root_task_group_empty(void)
314{ 316{
@@ -316,7 +318,6 @@ static int root_task_group_empty(void)
316} 318}
317#endif 319#endif
318 320
319#ifdef CONFIG_FAIR_GROUP_SCHED
320#ifdef CONFIG_USER_SCHED 321#ifdef CONFIG_USER_SCHED
321# define INIT_TASK_GROUP_LOAD (2*NICE_0_LOAD) 322# define INIT_TASK_GROUP_LOAD (2*NICE_0_LOAD)
322#else /* !CONFIG_USER_SCHED */ 323#else /* !CONFIG_USER_SCHED */
@@ -1564,11 +1565,7 @@ static unsigned long cpu_avg_load_per_task(int cpu)
1564 1565
1565#ifdef CONFIG_FAIR_GROUP_SCHED 1566#ifdef CONFIG_FAIR_GROUP_SCHED
1566 1567
1567struct update_shares_data { 1568static __read_mostly unsigned long *update_shares_data;
1568 unsigned long rq_weight[NR_CPUS];
1569};
1570
1571static DEFINE_PER_CPU(struct update_shares_data, update_shares_data);
1572 1569
1573static void __set_se_shares(struct sched_entity *se, unsigned long shares); 1570static void __set_se_shares(struct sched_entity *se, unsigned long shares);
1574 1571
@@ -1578,12 +1575,12 @@ static void __set_se_shares(struct sched_entity *se, unsigned long shares);
1578static void update_group_shares_cpu(struct task_group *tg, int cpu, 1575static void update_group_shares_cpu(struct task_group *tg, int cpu,
1579 unsigned long sd_shares, 1576 unsigned long sd_shares,
1580 unsigned long sd_rq_weight, 1577 unsigned long sd_rq_weight,
1581 struct update_shares_data *usd) 1578 unsigned long *usd_rq_weight)
1582{ 1579{
1583 unsigned long shares, rq_weight; 1580 unsigned long shares, rq_weight;
1584 int boost = 0; 1581 int boost = 0;
1585 1582
1586 rq_weight = usd->rq_weight[cpu]; 1583 rq_weight = usd_rq_weight[cpu];
1587 if (!rq_weight) { 1584 if (!rq_weight) {
1588 boost = 1; 1585 boost = 1;
1589 rq_weight = NICE_0_LOAD; 1586 rq_weight = NICE_0_LOAD;
@@ -1618,7 +1615,7 @@ static void update_group_shares_cpu(struct task_group *tg, int cpu,
1618static int tg_shares_up(struct task_group *tg, void *data) 1615static int tg_shares_up(struct task_group *tg, void *data)
1619{ 1616{
1620 unsigned long weight, rq_weight = 0, shares = 0; 1617 unsigned long weight, rq_weight = 0, shares = 0;
1621 struct update_shares_data *usd; 1618 unsigned long *usd_rq_weight;
1622 struct sched_domain *sd = data; 1619 struct sched_domain *sd = data;
1623 unsigned long flags; 1620 unsigned long flags;
1624 int i; 1621 int i;
@@ -1627,11 +1624,11 @@ static int tg_shares_up(struct task_group *tg, void *data)
1627 return 0; 1624 return 0;
1628 1625
1629 local_irq_save(flags); 1626 local_irq_save(flags);
1630 usd = &__get_cpu_var(update_shares_data); 1627 usd_rq_weight = per_cpu_ptr(update_shares_data, smp_processor_id());
1631 1628
1632 for_each_cpu(i, sched_domain_span(sd)) { 1629 for_each_cpu(i, sched_domain_span(sd)) {
1633 weight = tg->cfs_rq[i]->load.weight; 1630 weight = tg->cfs_rq[i]->load.weight;
1634 usd->rq_weight[i] = weight; 1631 usd_rq_weight[i] = weight;
1635 1632
1636 /* 1633 /*
1637 * If there are currently no tasks on the cpu pretend there 1634 * If there are currently no tasks on the cpu pretend there
@@ -1652,7 +1649,7 @@ static int tg_shares_up(struct task_group *tg, void *data)
1652 shares = tg->shares; 1649 shares = tg->shares;
1653 1650
1654 for_each_cpu(i, sched_domain_span(sd)) 1651 for_each_cpu(i, sched_domain_span(sd))
1655 update_group_shares_cpu(tg, i, shares, rq_weight, usd); 1652 update_group_shares_cpu(tg, i, shares, rq_weight, usd_rq_weight);
1656 1653
1657 local_irq_restore(flags); 1654 local_irq_restore(flags);
1658 1655
@@ -1996,6 +1993,39 @@ static inline void check_class_changed(struct rq *rq, struct task_struct *p,
1996 p->sched_class->prio_changed(rq, p, oldprio, running); 1993 p->sched_class->prio_changed(rq, p, oldprio, running);
1997} 1994}
1998 1995
1996/**
1997 * kthread_bind - bind a just-created kthread to a cpu.
1998 * @p: thread created by kthread_create().
1999 * @cpu: cpu (might not be online, must be possible) for @k to run on.
2000 *
2001 * Description: This function is equivalent to set_cpus_allowed(),
2002 * except that @cpu doesn't need to be online, and the thread must be
2003 * stopped (i.e., just returned from kthread_create()).
2004 *
2005 * Function lives here instead of kthread.c because it messes with
2006 * scheduler internals which require locking.
2007 */
2008void kthread_bind(struct task_struct *p, unsigned int cpu)
2009{
2010 struct rq *rq = cpu_rq(cpu);
2011 unsigned long flags;
2012
2013 /* Must have done schedule() in kthread() before we set_task_cpu */
2014 if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE)) {
2015 WARN_ON(1);
2016 return;
2017 }
2018
2019 spin_lock_irqsave(&rq->lock, flags);
2020 update_rq_clock(rq);
2021 set_task_cpu(p, cpu);
2022 p->cpus_allowed = cpumask_of_cpu(cpu);
2023 p->rt.nr_cpus_allowed = 1;
2024 p->flags |= PF_THREAD_BOUND;
2025 spin_unlock_irqrestore(&rq->lock, flags);
2026}
2027EXPORT_SYMBOL(kthread_bind);
2028
1999#ifdef CONFIG_SMP 2029#ifdef CONFIG_SMP
2000/* 2030/*
2001 * Is this task likely cache-hot: 2031 * Is this task likely cache-hot:
@@ -2008,7 +2038,7 @@ task_hot(struct task_struct *p, u64 now, struct sched_domain *sd)
2008 /* 2038 /*
2009 * Buddy candidates are cache hot: 2039 * Buddy candidates are cache hot:
2010 */ 2040 */
2011 if (sched_feat(CACHE_HOT_BUDDY) && 2041 if (sched_feat(CACHE_HOT_BUDDY) && this_rq()->nr_running &&
2012 (&p->se == cfs_rq_of(&p->se)->next || 2042 (&p->se == cfs_rq_of(&p->se)->next ||
2013 &p->se == cfs_rq_of(&p->se)->last)) 2043 &p->se == cfs_rq_of(&p->se)->last))
2014 return 1; 2044 return 1;
@@ -2085,6 +2115,7 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req)
2085 * it is sufficient to simply update the task's cpu field. 2115 * it is sufficient to simply update the task's cpu field.
2086 */ 2116 */
2087 if (!p->se.on_rq && !task_running(rq, p)) { 2117 if (!p->se.on_rq && !task_running(rq, p)) {
2118 update_rq_clock(rq);
2088 set_task_cpu(p, dest_cpu); 2119 set_task_cpu(p, dest_cpu);
2089 return 0; 2120 return 0;
2090 } 2121 }
@@ -2346,14 +2377,15 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state,
2346 task_rq_unlock(rq, &flags); 2377 task_rq_unlock(rq, &flags);
2347 2378
2348 cpu = p->sched_class->select_task_rq(p, SD_BALANCE_WAKE, wake_flags); 2379 cpu = p->sched_class->select_task_rq(p, SD_BALANCE_WAKE, wake_flags);
2349 if (cpu != orig_cpu) 2380 if (cpu != orig_cpu) {
2381 local_irq_save(flags);
2382 rq = cpu_rq(cpu);
2383 update_rq_clock(rq);
2350 set_task_cpu(p, cpu); 2384 set_task_cpu(p, cpu);
2351 2385 local_irq_restore(flags);
2386 }
2352 rq = task_rq_lock(p, &flags); 2387 rq = task_rq_lock(p, &flags);
2353 2388
2354 if (rq != orig_rq)
2355 update_rq_clock(rq);
2356
2357 WARN_ON(p->state != TASK_WAKING); 2389 WARN_ON(p->state != TASK_WAKING);
2358 cpu = task_cpu(p); 2390 cpu = task_cpu(p);
2359 2391
@@ -2526,6 +2558,7 @@ static void __sched_fork(struct task_struct *p)
2526void sched_fork(struct task_struct *p, int clone_flags) 2558void sched_fork(struct task_struct *p, int clone_flags)
2527{ 2559{
2528 int cpu = get_cpu(); 2560 int cpu = get_cpu();
2561 unsigned long flags;
2529 2562
2530 __sched_fork(p); 2563 __sched_fork(p);
2531 2564
@@ -2562,7 +2595,10 @@ void sched_fork(struct task_struct *p, int clone_flags)
2562#ifdef CONFIG_SMP 2595#ifdef CONFIG_SMP
2563 cpu = p->sched_class->select_task_rq(p, SD_BALANCE_FORK, 0); 2596 cpu = p->sched_class->select_task_rq(p, SD_BALANCE_FORK, 0);
2564#endif 2597#endif
2598 local_irq_save(flags);
2599 update_rq_clock(cpu_rq(cpu));
2565 set_task_cpu(p, cpu); 2600 set_task_cpu(p, cpu);
2601 local_irq_restore(flags);
2566 2602
2567#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 2603#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
2568 if (likely(sched_info_on())) 2604 if (likely(sched_info_on()))
@@ -2732,9 +2768,9 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
2732 prev_state = prev->state; 2768 prev_state = prev->state;
2733 finish_arch_switch(prev); 2769 finish_arch_switch(prev);
2734 perf_event_task_sched_in(current, cpu_of(rq)); 2770 perf_event_task_sched_in(current, cpu_of(rq));
2771 fire_sched_in_preempt_notifiers(current);
2735 finish_lock_switch(rq, prev); 2772 finish_lock_switch(rq, prev);
2736 2773
2737 fire_sched_in_preempt_notifiers(current);
2738 if (mm) 2774 if (mm)
2739 mmdrop(mm); 2775 mmdrop(mm);
2740 if (unlikely(prev_state == TASK_DEAD)) { 2776 if (unlikely(prev_state == TASK_DEAD)) {
@@ -7898,6 +7934,8 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent)
7898 7934
7899static void free_rootdomain(struct root_domain *rd) 7935static void free_rootdomain(struct root_domain *rd)
7900{ 7936{
7937 synchronize_sched();
7938
7901 cpupri_cleanup(&rd->cpupri); 7939 cpupri_cleanup(&rd->cpupri);
7902 7940
7903 free_cpumask_var(rd->rto_mask); 7941 free_cpumask_var(rd->rto_mask);
@@ -9449,6 +9487,10 @@ void __init sched_init(void)
9449#endif /* CONFIG_USER_SCHED */ 9487#endif /* CONFIG_USER_SCHED */
9450#endif /* CONFIG_GROUP_SCHED */ 9488#endif /* CONFIG_GROUP_SCHED */
9451 9489
9490#if defined CONFIG_FAIR_GROUP_SCHED && defined CONFIG_SMP
9491 update_shares_data = __alloc_percpu(nr_cpu_ids * sizeof(unsigned long),
9492 __alignof__(unsigned long));
9493#endif
9452 for_each_possible_cpu(i) { 9494 for_each_possible_cpu(i) {
9453 struct rq *rq; 9495 struct rq *rq;
9454 9496
@@ -9576,13 +9618,13 @@ void __init sched_init(void)
9576 current->sched_class = &fair_sched_class; 9618 current->sched_class = &fair_sched_class;
9577 9619
9578 /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */ 9620 /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */
9579 alloc_cpumask_var(&nohz_cpu_mask, GFP_NOWAIT); 9621 zalloc_cpumask_var(&nohz_cpu_mask, GFP_NOWAIT);
9580#ifdef CONFIG_SMP 9622#ifdef CONFIG_SMP
9581#ifdef CONFIG_NO_HZ 9623#ifdef CONFIG_NO_HZ
9582 alloc_cpumask_var(&nohz.cpu_mask, GFP_NOWAIT); 9624 zalloc_cpumask_var(&nohz.cpu_mask, GFP_NOWAIT);
9583 alloc_cpumask_var(&nohz.ilb_grp_nohz_mask, GFP_NOWAIT); 9625 alloc_cpumask_var(&nohz.ilb_grp_nohz_mask, GFP_NOWAIT);
9584#endif 9626#endif
9585 alloc_cpumask_var(&cpu_isolated_map, GFP_NOWAIT); 9627 zalloc_cpumask_var(&cpu_isolated_map, GFP_NOWAIT);
9586#endif /* SMP */ 9628#endif /* SMP */
9587 9629
9588 perf_event_init(); 9630 perf_event_init();