]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/sched.c
sched: prevent wakeup over-scheduling
[linux-2.6-omap-h63xx.git] / kernel / sched.c
index 23da93360b221ba02c8d0b0fe16cf0d0e2aafff9..e8051bd59acbc17436b99a31fbd887f90adc08dd 100644 (file)
@@ -156,12 +156,14 @@ struct rt_prio_array {
 struct cfs_rq;
 
 /* task group related information */
-struct task_grp {
+struct task_group {
        /* schedulable entities of this group on each cpu */
        struct sched_entity **se;
        /* runqueue "owned" by this group on each cpu */
        struct cfs_rq **cfs_rq;
        unsigned long shares;
+       /* spinlock to serialize modification to shares */
+       spinlock_t lock;
 };
 
 /* Default task group's sched entity on each cpu */
@@ -175,7 +177,7 @@ static struct cfs_rq *init_cfs_rq_p[NR_CPUS];
 /* Default task group.
  *     Every task in system belong to this group at bootup.
  */
-struct task_grp init_task_grp = {
+struct task_group init_task_group = {
        .se     = init_sched_entity_p,
        .cfs_rq = init_cfs_rq_p,
 };
@@ -186,17 +188,17 @@ struct task_grp init_task_grp = {
 # define INIT_TASK_GRP_LOAD    NICE_0_LOAD
 #endif
 
-static int init_task_grp_load = INIT_TASK_GRP_LOAD;
+static int init_task_group_load = INIT_TASK_GRP_LOAD;
 
 /* return group to which a task belongs */
-static inline struct task_grp *task_grp(struct task_struct *p)
+static inline struct task_group *task_group(struct task_struct *p)
 {
-       struct task_grp *tg;
+       struct task_group *tg;
 
 #ifdef CONFIG_FAIR_USER_SCHED
        tg = p->user->tg;
 #else
-       tg  = &init_task_grp;
+       tg  = &init_task_group;
 #endif
 
        return tg;
@@ -205,8 +207,8 @@ static inline struct task_grp *task_grp(struct task_struct *p)
 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
 static inline void set_task_cfs_rq(struct task_struct *p)
 {
-       p->se.cfs_rq = task_grp(p)->cfs_rq[task_cpu(p)];
-       p->se.parent = task_grp(p)->se[task_cpu(p)];
+       p->se.cfs_rq = task_group(p)->cfs_rq[task_cpu(p)];
+       p->se.parent = task_group(p)->se[task_cpu(p)];
 }
 
 #else
@@ -244,7 +246,7 @@ struct cfs_rq {
         * list is used during load balance.
         */
        struct list_head leaf_cfs_rq_list; /* Better name : task_cfs_rq_list? */
-       struct task_grp *tg;    /* group that "owns" this runqueue */
+       struct task_group *tg;    /* group that "owns" this runqueue */
        struct rcu_head rcu;
 #endif
 };
@@ -440,15 +442,19 @@ static void update_rq_clock(struct rq *rq)
 enum {
        SCHED_FEAT_NEW_FAIR_SLEEPERS    = 1,
        SCHED_FEAT_START_DEBIT          = 2,
-       SCHED_FEAT_USE_TREE_AVG         = 4,
+       SCHED_FEAT_TREE_AVG             = 4,
        SCHED_FEAT_APPROX_AVG           = 8,
+       SCHED_FEAT_WAKEUP_PREEMPT       = 16,
+       SCHED_FEAT_PREEMPT_RESTRICT     = 32,
 };
 
 const_debug unsigned int sysctl_sched_features =
                SCHED_FEAT_NEW_FAIR_SLEEPERS    *1 |
                SCHED_FEAT_START_DEBIT          *1 |
-               SCHED_FEAT_USE_TREE_AVG         *0 |
-               SCHED_FEAT_APPROX_AVG           *0;
+               SCHED_FEAT_TREE_AVG             *0 |
+               SCHED_FEAT_APPROX_AVG           *0 |
+               SCHED_FEAT_WAKEUP_PREEMPT       *1 |
+               SCHED_FEAT_PREEMPT_RESTRICT     *1;
 
 #define sched_feat(x) (sysctl_sched_features & SCHED_FEAT_##x)
 
@@ -470,6 +476,7 @@ unsigned long long cpu_clock(int cpu)
 
        return now;
 }
+EXPORT_SYMBOL_GPL(cpu_clock);
 
 #ifndef prepare_arch_switch
 # define prepare_arch_switch(next)     do { } while (0)
@@ -1130,7 +1137,7 @@ repeat:
         * yield - it could be a while.
         */
        if (unlikely(on_rq)) {
-               yield();
+               schedule_timeout_uninterruptible(1);
                goto repeat;
        }
 
@@ -1660,17 +1667,14 @@ void fastcall wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
 {
        unsigned long flags;
        struct rq *rq;
-       int this_cpu;
 
        rq = task_rq_lock(p, &flags);
        BUG_ON(p->state != TASK_RUNNING);
-       this_cpu = smp_processor_id(); /* parent's CPU */
        update_rq_clock(rq);
 
        p->prio = effective_prio(p);
 
-       if (task_cpu(p) != this_cpu || !p->sched_class->task_new ||
-                                                       !current->se.on_rq) {
+       if (!p->sched_class->task_new || !current->se.on_rq || !rq->cfs.curr) {
                activate_task(rq, p, 0);
        } else {
                /*
@@ -5284,7 +5288,7 @@ set_table_entry(struct ctl_table *entry,
 static struct ctl_table *
 sd_alloc_ctl_domain_table(struct sched_domain *sd)
 {
-       struct ctl_table *table = sd_alloc_ctl_entry(14);
+       struct ctl_table *table = sd_alloc_ctl_entry(12);
 
        set_table_entry(&table[0], "min_interval", &sd->min_interval,
                sizeof(long), 0644, proc_doulongvec_minmax);
@@ -5304,10 +5308,10 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
                sizeof(int), 0644, proc_dointvec_minmax);
        set_table_entry(&table[8], "imbalance_pct", &sd->imbalance_pct,
                sizeof(int), 0644, proc_dointvec_minmax);
-       set_table_entry(&table[10], "cache_nice_tries",
+       set_table_entry(&table[9], "cache_nice_tries",
                &sd->cache_nice_tries,
                sizeof(int), 0644, proc_dointvec_minmax);
-       set_table_entry(&table[12], "flags", &sd->flags,
+       set_table_entry(&table[10], "flags", &sd->flags,
                sizeof(int), 0644, proc_dointvec_minmax);
 
        return table;
@@ -6522,19 +6526,20 @@ void __init sched_init(void)
 
                        init_cfs_rq_p[i] = cfs_rq;
                        init_cfs_rq(cfs_rq, rq);
-                       cfs_rq->tg = &init_task_grp;
+                       cfs_rq->tg = &init_task_group;
                        list_add(&cfs_rq->leaf_cfs_rq_list,
                                                         &rq->leaf_cfs_rq_list);
 
                        init_sched_entity_p[i] = se;
                        se->cfs_rq = &rq->cfs;
                        se->my_q = cfs_rq;
-                       se->load.weight = init_task_grp_load;
+                       se->load.weight = init_task_group_load;
                        se->load.inv_weight =
-                                div64_64(1ULL<<32, init_task_grp_load);
+                                div64_64(1ULL<<32, init_task_group_load);
                        se->parent = NULL;
                }
-               init_task_grp.shares = init_task_grp_load;
+               init_task_group.shares = init_task_group_load;
+               spin_lock_init(&init_task_group.lock);
 #endif
 
                for (j = 0; j < CPU_LOAD_IDX_MAX; j++)
@@ -6725,9 +6730,9 @@ void set_curr_task(int cpu, struct task_struct *p)
 #ifdef CONFIG_FAIR_GROUP_SCHED
 
 /* allocate runqueue etc for a new task group */
-struct task_grp *sched_create_group(void)
+struct task_group *sched_create_group(void)
 {
-       struct task_grp *tg;
+       struct task_group *tg;
        struct cfs_rq *cfs_rq;
        struct sched_entity *se;
        struct rq *rq;
@@ -6779,6 +6784,7 @@ struct task_grp *sched_create_group(void)
        }
 
        tg->shares = NICE_0_LOAD;
+       spin_lock_init(&tg->lock);
 
        return tg;
 
@@ -6800,7 +6806,7 @@ err:
 static void free_sched_group(struct rcu_head *rhp)
 {
        struct cfs_rq *cfs_rq = container_of(rhp, struct cfs_rq, rcu);
-       struct task_grp *tg = cfs_rq->tg;
+       struct task_group *tg = cfs_rq->tg;
        struct sched_entity *se;
        int i;
 
@@ -6819,7 +6825,7 @@ static void free_sched_group(struct rcu_head *rhp)
 }
 
 /* Destroy runqueue etc associated with a task group */
-void sched_destroy_group(struct task_grp *tg)
+void sched_destroy_group(struct task_group *tg)
 {
        struct cfs_rq *cfs_rq;
        int i;
@@ -6895,12 +6901,13 @@ static void set_se_shares(struct sched_entity *se, unsigned long shares)
        spin_unlock_irq(&rq->lock);
 }
 
-int sched_group_set_shares(struct task_grp *tg, unsigned long shares)
+int sched_group_set_shares(struct task_group *tg, unsigned long shares)
 {
        int i;
 
+       spin_lock(&tg->lock);
        if (tg->shares == shares)
-               return 0;
+               goto done;
 
        /* return -EINVAL if the new value is not sane */
 
@@ -6908,7 +6915,14 @@ int sched_group_set_shares(struct task_grp *tg, unsigned long shares)
        for_each_possible_cpu(i)
                set_se_shares(tg->se[i], shares);
 
+done:
+       spin_unlock(&tg->lock);
        return 0;
 }
 
+unsigned long sched_group_shares(struct task_group *tg)
+{
+       return tg->shares;
+}
+
 #endif /* CONFIG_FAIR_GROUP_SCHED */