diff options
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index c9dec2aa1976..788ecce1e0e4 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -521,7 +521,7 @@ static inline void sched_info_dequeued(task_t *t) | |||
521 | * long it was waiting to run. We also note when it began so that we | 521 | * long it was waiting to run. We also note when it began so that we |
522 | * can keep stats on how long its timeslice is. | 522 | * can keep stats on how long its timeslice is. |
523 | */ | 523 | */ |
524 | static inline void sched_info_arrive(task_t *t) | 524 | static void sched_info_arrive(task_t *t) |
525 | { | 525 | { |
526 | unsigned long now = jiffies, diff = 0; | 526 | unsigned long now = jiffies, diff = 0; |
527 | struct runqueue *rq = task_rq(t); | 527 | struct runqueue *rq = task_rq(t); |
@@ -748,10 +748,14 @@ static int recalc_task_prio(task_t *p, unsigned long long now) | |||
748 | unsigned long long __sleep_time = now - p->timestamp; | 748 | unsigned long long __sleep_time = now - p->timestamp; |
749 | unsigned long sleep_time; | 749 | unsigned long sleep_time; |
750 | 750 | ||
751 | if (__sleep_time > NS_MAX_SLEEP_AVG) | 751 | if (unlikely(p->policy == SCHED_BATCH)) |
752 | sleep_time = NS_MAX_SLEEP_AVG; | 752 | sleep_time = 0; |
753 | else | 753 | else { |
754 | sleep_time = (unsigned long)__sleep_time; | 754 | if (__sleep_time > NS_MAX_SLEEP_AVG) |
755 | sleep_time = NS_MAX_SLEEP_AVG; | ||
756 | else | ||
757 | sleep_time = (unsigned long)__sleep_time; | ||
758 | } | ||
755 | 759 | ||
756 | if (likely(sleep_time > 0)) { | 760 | if (likely(sleep_time > 0)) { |
757 | /* | 761 | /* |
@@ -1003,7 +1007,7 @@ void kick_process(task_t *p) | |||
1003 | * We want to under-estimate the load of migration sources, to | 1007 | * We want to under-estimate the load of migration sources, to |
1004 | * balance conservatively. | 1008 | * balance conservatively. |
1005 | */ | 1009 | */ |
1006 | static inline unsigned long __source_load(int cpu, int type, enum idle_type idle) | 1010 | static unsigned long __source_load(int cpu, int type, enum idle_type idle) |
1007 | { | 1011 | { |
1008 | runqueue_t *rq = cpu_rq(cpu); | 1012 | runqueue_t *rq = cpu_rq(cpu); |
1009 | unsigned long running = rq->nr_running; | 1013 | unsigned long running = rq->nr_running; |
@@ -1866,7 +1870,7 @@ void sched_exec(void) | |||
1866 | * pull_task - move a task from a remote runqueue to the local runqueue. | 1870 | * pull_task - move a task from a remote runqueue to the local runqueue. |
1867 | * Both runqueues must be locked. | 1871 | * Both runqueues must be locked. |
1868 | */ | 1872 | */ |
1869 | static inline | 1873 | static |
1870 | void pull_task(runqueue_t *src_rq, prio_array_t *src_array, task_t *p, | 1874 | void pull_task(runqueue_t *src_rq, prio_array_t *src_array, task_t *p, |
1871 | runqueue_t *this_rq, prio_array_t *this_array, int this_cpu) | 1875 | runqueue_t *this_rq, prio_array_t *this_array, int this_cpu) |
1872 | { | 1876 | { |
@@ -1888,7 +1892,7 @@ void pull_task(runqueue_t *src_rq, prio_array_t *src_array, task_t *p, | |||
1888 | /* | 1892 | /* |
1889 | * can_migrate_task - may task p from runqueue rq be migrated to this_cpu? | 1893 | * can_migrate_task - may task p from runqueue rq be migrated to this_cpu? |
1890 | */ | 1894 | */ |
1891 | static inline | 1895 | static |
1892 | int can_migrate_task(task_t *p, runqueue_t *rq, int this_cpu, | 1896 | int can_migrate_task(task_t *p, runqueue_t *rq, int this_cpu, |
1893 | struct sched_domain *sd, enum idle_type idle, | 1897 | struct sched_domain *sd, enum idle_type idle, |
1894 | int *all_pinned) | 1898 | int *all_pinned) |
@@ -2374,7 +2378,7 @@ out_balanced: | |||
2374 | * idle_balance is called by schedule() if this_cpu is about to become | 2378 | * idle_balance is called by schedule() if this_cpu is about to become |
2375 | * idle. Attempts to pull tasks from other CPUs. | 2379 | * idle. Attempts to pull tasks from other CPUs. |
2376 | */ | 2380 | */ |
2377 | static inline void idle_balance(int this_cpu, runqueue_t *this_rq) | 2381 | static void idle_balance(int this_cpu, runqueue_t *this_rq) |
2378 | { | 2382 | { |
2379 | struct sched_domain *sd; | 2383 | struct sched_domain *sd; |
2380 | 2384 | ||
@@ -2758,7 +2762,7 @@ static inline void wakeup_busy_runqueue(runqueue_t *rq) | |||
2758 | resched_task(rq->idle); | 2762 | resched_task(rq->idle); |
2759 | } | 2763 | } |
2760 | 2764 | ||
2761 | static inline void wake_sleeping_dependent(int this_cpu, runqueue_t *this_rq) | 2765 | static void wake_sleeping_dependent(int this_cpu, runqueue_t *this_rq) |
2762 | { | 2766 | { |
2763 | struct sched_domain *tmp, *sd = NULL; | 2767 | struct sched_domain *tmp, *sd = NULL; |
2764 | cpumask_t sibling_map; | 2768 | cpumask_t sibling_map; |
@@ -2812,7 +2816,7 @@ static inline unsigned long smt_slice(task_t *p, struct sched_domain *sd) | |||
2812 | return p->time_slice * (100 - sd->per_cpu_gain) / 100; | 2816 | return p->time_slice * (100 - sd->per_cpu_gain) / 100; |
2813 | } | 2817 | } |
2814 | 2818 | ||
2815 | static inline int dependent_sleeper(int this_cpu, runqueue_t *this_rq) | 2819 | static int dependent_sleeper(int this_cpu, runqueue_t *this_rq) |
2816 | { | 2820 | { |
2817 | struct sched_domain *tmp, *sd = NULL; | 2821 | struct sched_domain *tmp, *sd = NULL; |
2818 | cpumask_t sibling_map; | 2822 | cpumask_t sibling_map; |
@@ -3560,7 +3564,7 @@ void set_user_nice(task_t *p, long nice) | |||
3560 | * The RT priorities are set via sched_setscheduler(), but we still | 3564 | * The RT priorities are set via sched_setscheduler(), but we still |
3561 | * allow the 'normal' nice value to be set - but as expected | 3565 | * allow the 'normal' nice value to be set - but as expected |
3562 | * it wont have any effect on scheduling until the task is | 3566 | * it wont have any effect on scheduling until the task is |
3563 | * not SCHED_NORMAL: | 3567 | * not SCHED_NORMAL/SCHED_BATCH: |
3564 | */ | 3568 | */ |
3565 | if (rt_task(p)) { | 3569 | if (rt_task(p)) { |
3566 | p->static_prio = NICE_TO_PRIO(nice); | 3570 | p->static_prio = NICE_TO_PRIO(nice); |
@@ -3706,10 +3710,16 @@ static void __setscheduler(struct task_struct *p, int policy, int prio) | |||
3706 | BUG_ON(p->array); | 3710 | BUG_ON(p->array); |
3707 | p->policy = policy; | 3711 | p->policy = policy; |
3708 | p->rt_priority = prio; | 3712 | p->rt_priority = prio; |
3709 | if (policy != SCHED_NORMAL) | 3713 | if (policy != SCHED_NORMAL && policy != SCHED_BATCH) { |
3710 | p->prio = MAX_RT_PRIO-1 - p->rt_priority; | 3714 | p->prio = MAX_RT_PRIO-1 - p->rt_priority; |
3711 | else | 3715 | } else { |
3712 | p->prio = p->static_prio; | 3716 | p->prio = p->static_prio; |
3717 | /* | ||
3718 | * SCHED_BATCH tasks are treated as perpetual CPU hogs: | ||
3719 | */ | ||
3720 | if (policy == SCHED_BATCH) | ||
3721 | p->sleep_avg = 0; | ||
3722 | } | ||
3713 | } | 3723 | } |
3714 | 3724 | ||
3715 | /** | 3725 | /** |
@@ -3733,29 +3743,35 @@ recheck: | |||
3733 | if (policy < 0) | 3743 | if (policy < 0) |
3734 | policy = oldpolicy = p->policy; | 3744 | policy = oldpolicy = p->policy; |
3735 | else if (policy != SCHED_FIFO && policy != SCHED_RR && | 3745 | else if (policy != SCHED_FIFO && policy != SCHED_RR && |
3736 | policy != SCHED_NORMAL) | 3746 | policy != SCHED_NORMAL && policy != SCHED_BATCH) |
3737 | return -EINVAL; | 3747 | return -EINVAL; |
3738 | /* | 3748 | /* |
3739 | * Valid priorities for SCHED_FIFO and SCHED_RR are | 3749 | * Valid priorities for SCHED_FIFO and SCHED_RR are |
3740 | * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL is 0. | 3750 | * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL and |
3751 | * SCHED_BATCH is 0. | ||
3741 | */ | 3752 | */ |
3742 | if (param->sched_priority < 0 || | 3753 | if (param->sched_priority < 0 || |
3743 | (p->mm && param->sched_priority > MAX_USER_RT_PRIO-1) || | 3754 | (p->mm && param->sched_priority > MAX_USER_RT_PRIO-1) || |
3744 | (!p->mm && param->sched_priority > MAX_RT_PRIO-1)) | 3755 | (!p->mm && param->sched_priority > MAX_RT_PRIO-1)) |
3745 | return -EINVAL; | 3756 | return -EINVAL; |
3746 | if ((policy == SCHED_NORMAL) != (param->sched_priority == 0)) | 3757 | if ((policy == SCHED_NORMAL || policy == SCHED_BATCH) |
3758 | != (param->sched_priority == 0)) | ||
3747 | return -EINVAL; | 3759 | return -EINVAL; |
3748 | 3760 | ||
3749 | /* | 3761 | /* |
3750 | * Allow unprivileged RT tasks to decrease priority: | 3762 | * Allow unprivileged RT tasks to decrease priority: |
3751 | */ | 3763 | */ |
3752 | if (!capable(CAP_SYS_NICE)) { | 3764 | if (!capable(CAP_SYS_NICE)) { |
3753 | /* can't change policy */ | 3765 | /* |
3754 | if (policy != p->policy && | 3766 | * can't change policy, except between SCHED_NORMAL |
3755 | !p->signal->rlim[RLIMIT_RTPRIO].rlim_cur) | 3767 | * and SCHED_BATCH: |
3768 | */ | ||
3769 | if (((policy != SCHED_NORMAL && p->policy != SCHED_BATCH) && | ||
3770 | (policy != SCHED_BATCH && p->policy != SCHED_NORMAL)) && | ||
3771 | !p->signal->rlim[RLIMIT_RTPRIO].rlim_cur) | ||
3756 | return -EPERM; | 3772 | return -EPERM; |
3757 | /* can't increase priority */ | 3773 | /* can't increase priority */ |
3758 | if (policy != SCHED_NORMAL && | 3774 | if ((policy != SCHED_NORMAL && policy != SCHED_BATCH) && |
3759 | param->sched_priority > p->rt_priority && | 3775 | param->sched_priority > p->rt_priority && |
3760 | param->sched_priority > | 3776 | param->sched_priority > |
3761 | p->signal->rlim[RLIMIT_RTPRIO].rlim_cur) | 3777 | p->signal->rlim[RLIMIT_RTPRIO].rlim_cur) |
@@ -4233,6 +4249,7 @@ asmlinkage long sys_sched_get_priority_max(int policy) | |||
4233 | ret = MAX_USER_RT_PRIO-1; | 4249 | ret = MAX_USER_RT_PRIO-1; |
4234 | break; | 4250 | break; |
4235 | case SCHED_NORMAL: | 4251 | case SCHED_NORMAL: |
4252 | case SCHED_BATCH: | ||
4236 | ret = 0; | 4253 | ret = 0; |
4237 | break; | 4254 | break; |
4238 | } | 4255 | } |
@@ -4256,6 +4273,7 @@ asmlinkage long sys_sched_get_priority_min(int policy) | |||
4256 | ret = 1; | 4273 | ret = 1; |
4257 | break; | 4274 | break; |
4258 | case SCHED_NORMAL: | 4275 | case SCHED_NORMAL: |
4276 | case SCHED_BATCH: | ||
4259 | ret = 0; | 4277 | ret = 0; |
4260 | } | 4278 | } |
4261 | return ret; | 4279 | return ret; |
@@ -5990,7 +6008,7 @@ next_sg: | |||
5990 | * Detach sched domains from a group of cpus specified in cpu_map | 6008 | * Detach sched domains from a group of cpus specified in cpu_map |
5991 | * These cpus will now be attached to the NULL domain | 6009 | * These cpus will now be attached to the NULL domain |
5992 | */ | 6010 | */ |
5993 | static inline void detach_destroy_domains(const cpumask_t *cpu_map) | 6011 | static void detach_destroy_domains(const cpumask_t *cpu_map) |
5994 | { | 6012 | { |
5995 | int i; | 6013 | int i; |
5996 | 6014 | ||