diff options
Diffstat (limited to 'kernel/sched.c')
| -rw-r--r-- | kernel/sched.c | 339 |
1 files changed, 274 insertions, 65 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index 18d38e4ec7b..c8e40b7005c 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -324,7 +324,7 @@ struct cfs_rq { | |||
| 324 | * 'curr' points to currently running entity on this cfs_rq. | 324 | * 'curr' points to currently running entity on this cfs_rq. |
| 325 | * It is set to NULL otherwise (i.e when none are currently running). | 325 | * It is set to NULL otherwise (i.e when none are currently running). |
| 326 | */ | 326 | */ |
| 327 | struct sched_entity *curr, *next, *last; | 327 | struct sched_entity *curr, *next, *last, *skip; |
| 328 | 328 | ||
| 329 | unsigned int nr_spread_over; | 329 | unsigned int nr_spread_over; |
| 330 | 330 | ||
| @@ -606,9 +606,6 @@ static inline struct task_group *task_group(struct task_struct *p) | |||
| 606 | struct task_group *tg; | 606 | struct task_group *tg; |
| 607 | struct cgroup_subsys_state *css; | 607 | struct cgroup_subsys_state *css; |
| 608 | 608 | ||
| 609 | if (p->flags & PF_EXITING) | ||
| 610 | return &root_task_group; | ||
| 611 | |||
| 612 | css = task_subsys_state_check(p, cpu_cgroup_subsys_id, | 609 | css = task_subsys_state_check(p, cpu_cgroup_subsys_id, |
| 613 | lockdep_is_held(&task_rq(p)->lock)); | 610 | lockdep_is_held(&task_rq(p)->lock)); |
| 614 | tg = container_of(css, struct task_group, css); | 611 | tg = container_of(css, struct task_group, css); |
| @@ -1686,6 +1683,39 @@ static void double_rq_unlock(struct rq *rq1, struct rq *rq2) | |||
| 1686 | __release(rq2->lock); | 1683 | __release(rq2->lock); |
| 1687 | } | 1684 | } |
| 1688 | 1685 | ||
| 1686 | #else /* CONFIG_SMP */ | ||
| 1687 | |||
| 1688 | /* | ||
| 1689 | * double_rq_lock - safely lock two runqueues | ||
| 1690 | * | ||
| 1691 | * Note this does not disable interrupts like task_rq_lock, | ||
| 1692 | * you need to do so manually before calling. | ||
| 1693 | */ | ||
| 1694 | static void double_rq_lock(struct rq *rq1, struct rq *rq2) | ||
| 1695 | __acquires(rq1->lock) | ||
| 1696 | __acquires(rq2->lock) | ||
| 1697 | { | ||
| 1698 | BUG_ON(!irqs_disabled()); | ||
| 1699 | BUG_ON(rq1 != rq2); | ||
| 1700 | raw_spin_lock(&rq1->lock); | ||
| 1701 | __acquire(rq2->lock); /* Fake it out ;) */ | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | /* | ||
| 1705 | * double_rq_unlock - safely unlock two runqueues | ||
| 1706 | * | ||
| 1707 | * Note this does not restore interrupts like task_rq_unlock, | ||
| 1708 | * you need to do so manually after calling. | ||
| 1709 | */ | ||
| 1710 | static void double_rq_unlock(struct rq *rq1, struct rq *rq2) | ||
| 1711 | __releases(rq1->lock) | ||
| 1712 | __releases(rq2->lock) | ||
| 1713 | { | ||
| 1714 | BUG_ON(rq1 != rq2); | ||
| 1715 | raw_spin_unlock(&rq1->lock); | ||
| 1716 | __release(rq2->lock); | ||
| 1717 | } | ||
| 1718 | |||
| 1689 | #endif | 1719 | #endif |
| 1690 | 1720 | ||
| 1691 | static void calc_load_account_idle(struct rq *this_rq); | 1721 | static void calc_load_account_idle(struct rq *this_rq); |
| @@ -1880,7 +1910,7 @@ void account_system_vtime(struct task_struct *curr) | |||
| 1880 | */ | 1910 | */ |
| 1881 | if (hardirq_count()) | 1911 | if (hardirq_count()) |
| 1882 | __this_cpu_add(cpu_hardirq_time, delta); | 1912 | __this_cpu_add(cpu_hardirq_time, delta); |
| 1883 | else if (in_serving_softirq() && !(curr->flags & PF_KSOFTIRQD)) | 1913 | else if (in_serving_softirq() && curr != this_cpu_ksoftirqd()) |
| 1884 | __this_cpu_add(cpu_softirq_time, delta); | 1914 | __this_cpu_add(cpu_softirq_time, delta); |
| 1885 | 1915 | ||
| 1886 | irq_time_write_end(); | 1916 | irq_time_write_end(); |
| @@ -1920,8 +1950,40 @@ static void update_rq_clock_task(struct rq *rq, s64 delta) | |||
| 1920 | sched_rt_avg_update(rq, irq_delta); | 1950 | sched_rt_avg_update(rq, irq_delta); |
| 1921 | } | 1951 | } |
| 1922 | 1952 | ||
| 1953 | static int irqtime_account_hi_update(void) | ||
| 1954 | { | ||
| 1955 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | ||
| 1956 | unsigned long flags; | ||
| 1957 | u64 latest_ns; | ||
| 1958 | int ret = 0; | ||
| 1959 | |||
| 1960 | local_irq_save(flags); | ||
| 1961 | latest_ns = this_cpu_read(cpu_hardirq_time); | ||
| 1962 | if (cputime64_gt(nsecs_to_cputime64(latest_ns), cpustat->irq)) | ||
| 1963 | ret = 1; | ||
| 1964 | local_irq_restore(flags); | ||
| 1965 | return ret; | ||
| 1966 | } | ||
| 1967 | |||
| 1968 | static int irqtime_account_si_update(void) | ||
| 1969 | { | ||
| 1970 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | ||
| 1971 | unsigned long flags; | ||
| 1972 | u64 latest_ns; | ||
| 1973 | int ret = 0; | ||
| 1974 | |||
| 1975 | local_irq_save(flags); | ||
| 1976 | latest_ns = this_cpu_read(cpu_softirq_time); | ||
| 1977 | if (cputime64_gt(nsecs_to_cputime64(latest_ns), cpustat->softirq)) | ||
| 1978 | ret = 1; | ||
| 1979 | local_irq_restore(flags); | ||
| 1980 | return ret; | ||
| 1981 | } | ||
| 1982 | |||
| 1923 | #else /* CONFIG_IRQ_TIME_ACCOUNTING */ | 1983 | #else /* CONFIG_IRQ_TIME_ACCOUNTING */ |
| 1924 | 1984 | ||
| 1985 | #define sched_clock_irqtime (0) | ||
| 1986 | |||
| 1925 | static void update_rq_clock_task(struct rq *rq, s64 delta) | 1987 | static void update_rq_clock_task(struct rq *rq, s64 delta) |
| 1926 | { | 1988 | { |
| 1927 | rq->clock_task += delta; | 1989 | rq->clock_task += delta; |
| @@ -2025,14 +2087,14 @@ inline int task_curr(const struct task_struct *p) | |||
| 2025 | 2087 | ||
| 2026 | static inline void check_class_changed(struct rq *rq, struct task_struct *p, | 2088 | static inline void check_class_changed(struct rq *rq, struct task_struct *p, |
| 2027 | const struct sched_class *prev_class, | 2089 | const struct sched_class *prev_class, |
| 2028 | int oldprio, int running) | 2090 | int oldprio) |
| 2029 | { | 2091 | { |
| 2030 | if (prev_class != p->sched_class) { | 2092 | if (prev_class != p->sched_class) { |
| 2031 | if (prev_class->switched_from) | 2093 | if (prev_class->switched_from) |
| 2032 | prev_class->switched_from(rq, p, running); | 2094 | prev_class->switched_from(rq, p); |
| 2033 | p->sched_class->switched_to(rq, p, running); | 2095 | p->sched_class->switched_to(rq, p); |
| 2034 | } else | 2096 | } else if (oldprio != p->prio) |
| 2035 | p->sched_class->prio_changed(rq, p, oldprio, running); | 2097 | p->sched_class->prio_changed(rq, p, oldprio); |
| 2036 | } | 2098 | } |
| 2037 | 2099 | ||
| 2038 | static void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) | 2100 | static void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) |
| @@ -2224,7 +2286,10 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state) | |||
| 2224 | * yield - it could be a while. | 2286 | * yield - it could be a while. |
| 2225 | */ | 2287 | */ |
| 2226 | if (unlikely(on_rq)) { | 2288 | if (unlikely(on_rq)) { |
| 2227 | schedule_timeout_uninterruptible(1); | 2289 | ktime_t to = ktime_set(0, NSEC_PER_SEC/HZ); |
| 2290 | |||
| 2291 | set_current_state(TASK_UNINTERRUPTIBLE); | ||
| 2292 | schedule_hrtimeout(&to, HRTIMER_MODE_REL); | ||
| 2228 | continue; | 2293 | continue; |
| 2229 | } | 2294 | } |
| 2230 | 2295 | ||
| @@ -2265,27 +2330,6 @@ void kick_process(struct task_struct *p) | |||
| 2265 | EXPORT_SYMBOL_GPL(kick_process); | 2330 | EXPORT_SYMBOL_GPL(kick_process); |
| 2266 | #endif /* CONFIG_SMP */ | 2331 | #endif /* CONFIG_SMP */ |
| 2267 | 2332 | ||
| 2268 | /** | ||
| 2269 | * task_oncpu_function_call - call a function on the cpu on which a task runs | ||
| 2270 | * @p: the task to evaluate | ||
| 2271 | * @func: the function to be called | ||
| 2272 | * @info: the function call argument | ||
| 2273 | * | ||
| 2274 | * Calls the function @func when the task is currently running. This might | ||
| 2275 | * be on the current CPU, which just calls the function directly | ||
| 2276 | */ | ||
| 2277 | void task_oncpu_function_call(struct task_struct *p, | ||
| 2278 | void (*func) (void *info), void *info) | ||
| 2279 | { | ||
| 2280 | int cpu; | ||
| 2281 | |||
| 2282 | preempt_disable(); | ||
| 2283 | cpu = task_cpu(p); | ||
| 2284 | if (task_curr(p)) | ||
| 2285 | smp_call_function_single(cpu, func, info, 1); | ||
| 2286 | preempt_enable(); | ||
| 2287 | } | ||
| 2288 | |||
| 2289 | #ifdef CONFIG_SMP | 2333 | #ifdef CONFIG_SMP |
| 2290 | /* | 2334 | /* |
| 2291 | * ->cpus_allowed is protected by either TASK_WAKING or rq->lock held. | 2335 | * ->cpus_allowed is protected by either TASK_WAKING or rq->lock held. |
| @@ -2566,6 +2610,7 @@ static void __sched_fork(struct task_struct *p) | |||
| 2566 | p->se.sum_exec_runtime = 0; | 2610 | p->se.sum_exec_runtime = 0; |
| 2567 | p->se.prev_sum_exec_runtime = 0; | 2611 | p->se.prev_sum_exec_runtime = 0; |
| 2568 | p->se.nr_migrations = 0; | 2612 | p->se.nr_migrations = 0; |
| 2613 | p->se.vruntime = 0; | ||
| 2569 | 2614 | ||
| 2570 | #ifdef CONFIG_SCHEDSTATS | 2615 | #ifdef CONFIG_SCHEDSTATS |
| 2571 | memset(&p->se.statistics, 0, sizeof(p->se.statistics)); | 2616 | memset(&p->se.statistics, 0, sizeof(p->se.statistics)); |
| @@ -2776,9 +2821,12 @@ static inline void | |||
| 2776 | prepare_task_switch(struct rq *rq, struct task_struct *prev, | 2821 | prepare_task_switch(struct rq *rq, struct task_struct *prev, |
| 2777 | struct task_struct *next) | 2822 | struct task_struct *next) |
| 2778 | { | 2823 | { |
| 2824 | sched_info_switch(prev, next); | ||
| 2825 | perf_event_task_sched_out(prev, next); | ||
| 2779 | fire_sched_out_preempt_notifiers(prev, next); | 2826 | fire_sched_out_preempt_notifiers(prev, next); |
| 2780 | prepare_lock_switch(rq, next); | 2827 | prepare_lock_switch(rq, next); |
| 2781 | prepare_arch_switch(next); | 2828 | prepare_arch_switch(next); |
| 2829 | trace_sched_switch(prev, next); | ||
| 2782 | } | 2830 | } |
| 2783 | 2831 | ||
| 2784 | /** | 2832 | /** |
| @@ -2911,7 +2959,7 @@ context_switch(struct rq *rq, struct task_struct *prev, | |||
| 2911 | struct mm_struct *mm, *oldmm; | 2959 | struct mm_struct *mm, *oldmm; |
| 2912 | 2960 | ||
| 2913 | prepare_task_switch(rq, prev, next); | 2961 | prepare_task_switch(rq, prev, next); |
| 2914 | trace_sched_switch(prev, next); | 2962 | |
| 2915 | mm = next->mm; | 2963 | mm = next->mm; |
| 2916 | oldmm = prev->active_mm; | 2964 | oldmm = prev->active_mm; |
| 2917 | /* | 2965 | /* |
| @@ -3568,6 +3616,32 @@ static void account_guest_time(struct task_struct *p, cputime_t cputime, | |||
| 3568 | } | 3616 | } |
| 3569 | 3617 | ||
| 3570 | /* | 3618 | /* |
| 3619 | * Account system cpu time to a process and desired cpustat field | ||
| 3620 | * @p: the process that the cpu time gets accounted to | ||
| 3621 | * @cputime: the cpu time spent in kernel space since the last update | ||
| 3622 | * @cputime_scaled: cputime scaled by cpu frequency | ||
| 3623 | * @target_cputime64: pointer to cpustat field that has to be updated | ||
| 3624 | */ | ||
| 3625 | static inline | ||
| 3626 | void __account_system_time(struct task_struct *p, cputime_t cputime, | ||
| 3627 | cputime_t cputime_scaled, cputime64_t *target_cputime64) | ||
| 3628 | { | ||
| 3629 | cputime64_t tmp = cputime_to_cputime64(cputime); | ||
| 3630 | |||
| 3631 | /* Add system time to process. */ | ||
| 3632 | p->stime = cputime_add(p->stime, cputime); | ||
| 3633 | p->stimescaled = cputime_add(p->stimescaled, cputime_scaled); | ||
| 3634 | account_group_system_time(p, cputime); | ||
| 3635 | |||
| 3636 | /* Add system time to cpustat. */ | ||
| 3637 | *target_cputime64 = cputime64_add(*target_cputime64, tmp); | ||
| 3638 | cpuacct_update_stats(p, CPUACCT_STAT_SYSTEM, cputime); | ||
| 3639 | |||
| 3640 | /* Account for system time used */ | ||
| 3641 | acct_update_integrals(p); | ||
| 3642 | } | ||
| 3643 | |||
| 3644 | /* | ||
| 3571 | * Account system cpu time to a process. | 3645 | * Account system cpu time to a process. |
| 3572 | * @p: the process that the cpu time gets accounted to | 3646 | * @p: the process that the cpu time gets accounted to |
| 3573 | * @hardirq_offset: the offset to subtract from hardirq_count() | 3647 | * @hardirq_offset: the offset to subtract from hardirq_count() |
| @@ -3578,36 +3652,26 @@ void account_system_time(struct task_struct *p, int hardirq_offset, | |||
| 3578 | cputime_t cputime, cputime_t cputime_scaled) | 3652 | cputime_t cputime, cputime_t cputime_scaled) |
| 3579 | { | 3653 | { |
| 3580 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | 3654 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; |
| 3581 | cputime64_t tmp; | 3655 | cputime64_t *target_cputime64; |
| 3582 | 3656 | ||
| 3583 | if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) { | 3657 | if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) { |
| 3584 | account_guest_time(p, cputime, cputime_scaled); | 3658 | account_guest_time(p, cputime, cputime_scaled); |
| 3585 | return; | 3659 | return; |
| 3586 | } | 3660 | } |
| 3587 | 3661 | ||
| 3588 | /* Add system time to process. */ | ||
| 3589 | p->stime = cputime_add(p->stime, cputime); | ||
| 3590 | p->stimescaled = cputime_add(p->stimescaled, cputime_scaled); | ||
| 3591 | account_group_system_time(p, cputime); | ||
| 3592 | |||
| 3593 | /* Add system time to cpustat. */ | ||
| 3594 | tmp = cputime_to_cputime64(cputime); | ||
| 3595 | if (hardirq_count() - hardirq_offset) | 3662 | if (hardirq_count() - hardirq_offset) |
| 3596 | cpustat->irq = cputime64_add(cpustat->irq, tmp); | 3663 | target_cputime64 = &cpustat->irq; |
| 3597 | else if (in_serving_softirq()) | 3664 | else if (in_serving_softirq()) |
| 3598 | cpustat->softirq = cputime64_add(cpustat->softirq, tmp); | 3665 | target_cputime64 = &cpustat->softirq; |
| 3599 | else | 3666 | else |
| 3600 | cpustat->system = cputime64_add(cpustat->system, tmp); | 3667 | target_cputime64 = &cpustat->system; |
| 3601 | 3668 | ||
| 3602 | cpuacct_update_stats(p, CPUACCT_STAT_SYSTEM, cputime); | 3669 | __account_system_time(p, cputime, cputime_scaled, target_cputime64); |
| 3603 | |||
| 3604 | /* Account for system time used */ | ||
| 3605 | acct_update_integrals(p); | ||
| 3606 | } | 3670 | } |
| 3607 | 3671 | ||
| 3608 | /* | 3672 | /* |
| 3609 | * Account for involuntary wait time. | 3673 | * Account for involuntary wait time. |
| 3610 | * @steal: the cpu time spent in involuntary wait | 3674 | * @cputime: the cpu time spent in involuntary wait |
| 3611 | */ | 3675 | */ |
| 3612 | void account_steal_time(cputime_t cputime) | 3676 | void account_steal_time(cputime_t cputime) |
| 3613 | { | 3677 | { |
| @@ -3635,6 +3699,73 @@ void account_idle_time(cputime_t cputime) | |||
| 3635 | 3699 | ||
| 3636 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | 3700 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING |
| 3637 | 3701 | ||
| 3702 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING | ||
| 3703 | /* | ||
| 3704 | * Account a tick to a process and cpustat | ||
| 3705 | * @p: the process that the cpu time gets accounted to | ||
| 3706 | * @user_tick: is the tick from userspace | ||
| 3707 | * @rq: the pointer to rq | ||
| 3708 | * | ||
| 3709 | * Tick demultiplexing follows the order | ||
| 3710 | * - pending hardirq update | ||
| 3711 | * - pending softirq update | ||
| 3712 | * - user_time | ||
| 3713 | * - idle_time | ||
| 3714 | * - system time | ||
| 3715 | * - check for guest_time | ||
| 3716 | * - else account as system_time | ||
| 3717 | * | ||
| 3718 | * Check for hardirq is done both for system and user time as there is | ||
| 3719 | * no timer going off while we are on hardirq and hence we may never get an | ||
| 3720 | * opportunity to update it solely in system time. | ||
| 3721 | * p->stime and friends are only updated on system time and not on irq | ||
| 3722 | * softirq as those do not count in task exec_runtime any more. | ||
| 3723 | */ | ||
| 3724 | static void irqtime_account_process_tick(struct task_struct *p, int user_tick, | ||
| 3725 | struct rq *rq) | ||
| 3726 | { | ||
| 3727 | cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy); | ||
| 3728 | cputime64_t tmp = cputime_to_cputime64(cputime_one_jiffy); | ||
| 3729 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | ||
| 3730 | |||
| 3731 | if (irqtime_account_hi_update()) { | ||
| 3732 | cpustat->irq = cputime64_add(cpustat->irq, tmp); | ||
| 3733 | } else if (irqtime_account_si_update()) { | ||
| 3734 | cpustat->softirq = cputime64_add(cpustat->softirq, tmp); | ||
| 3735 | } else if (this_cpu_ksoftirqd() == p) { | ||
| 3736 | /* | ||
| 3737 | * ksoftirqd time do not get accounted in cpu_softirq_time. | ||
| 3738 | * So, we have to handle it separately here. | ||
| 3739 | * Also, p->stime needs to be updated for ksoftirqd. | ||
| 3740 | */ | ||
| 3741 | __account_system_time(p, cputime_one_jiffy, one_jiffy_scaled, | ||
| 3742 | &cpustat->softirq); | ||
| 3743 | } else if (user_tick) { | ||
| 3744 | account_user_time(p, cputime_one_jiffy, one_jiffy_scaled); | ||
| 3745 | } else if (p == rq->idle) { | ||
| 3746 | account_idle_time(cputime_one_jiffy); | ||
| 3747 | } else if (p->flags & PF_VCPU) { /* System time or guest time */ | ||
| 3748 | account_guest_time(p, cputime_one_jiffy, one_jiffy_scaled); | ||
| 3749 | } else { | ||
| 3750 | __account_system_time(p, cputime_one_jiffy, one_jiffy_scaled, | ||
| 3751 | &cpustat->system); | ||
| 3752 | } | ||
| 3753 | } | ||
| 3754 | |||
| 3755 | static void irqtime_account_idle_ticks(int ticks) | ||
| 3756 | { | ||
| 3757 | int i; | ||
| 3758 | struct rq *rq = this_rq(); | ||
| 3759 | |||
| 3760 | for (i = 0; i < ticks; i++) | ||
| 3761 | irqtime_account_process_tick(current, 0, rq); | ||
| 3762 | } | ||
| 3763 | #else /* CONFIG_IRQ_TIME_ACCOUNTING */ | ||
| 3764 | static void irqtime_account_idle_ticks(int ticks) {} | ||
| 3765 | static void irqtime_account_process_tick(struct task_struct *p, int user_tick, | ||
| 3766 | struct rq *rq) {} | ||
| 3767 | #endif /* CONFIG_IRQ_TIME_ACCOUNTING */ | ||
| 3768 | |||
| 3638 | /* | 3769 | /* |
| 3639 | * Account a single tick of cpu time. | 3770 | * Account a single tick of cpu time. |
| 3640 | * @p: the process that the cpu time gets accounted to | 3771 | * @p: the process that the cpu time gets accounted to |
| @@ -3645,6 +3776,11 @@ void account_process_tick(struct task_struct *p, int user_tick) | |||
| 3645 | cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy); | 3776 | cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy); |
| 3646 | struct rq *rq = this_rq(); | 3777 | struct rq *rq = this_rq(); |
| 3647 | 3778 | ||
| 3779 | if (sched_clock_irqtime) { | ||
| 3780 | irqtime_account_process_tick(p, user_tick, rq); | ||
| 3781 | return; | ||
| 3782 | } | ||
| 3783 | |||
| 3648 | if (user_tick) | 3784 | if (user_tick) |
| 3649 | account_user_time(p, cputime_one_jiffy, one_jiffy_scaled); | 3785 | account_user_time(p, cputime_one_jiffy, one_jiffy_scaled); |
| 3650 | else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) | 3786 | else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) |
| @@ -3670,6 +3806,12 @@ void account_steal_ticks(unsigned long ticks) | |||
| 3670 | */ | 3806 | */ |
| 3671 | void account_idle_ticks(unsigned long ticks) | 3807 | void account_idle_ticks(unsigned long ticks) |
| 3672 | { | 3808 | { |
| 3809 | |||
| 3810 | if (sched_clock_irqtime) { | ||
| 3811 | irqtime_account_idle_ticks(ticks); | ||
| 3812 | return; | ||
| 3813 | } | ||
| 3814 | |||
| 3673 | account_idle_time(jiffies_to_cputime(ticks)); | 3815 | account_idle_time(jiffies_to_cputime(ticks)); |
| 3674 | } | 3816 | } |
| 3675 | 3817 | ||
| @@ -3989,9 +4131,6 @@ need_resched_nonpreemptible: | |||
| 3989 | rq->skip_clock_update = 0; | 4131 | rq->skip_clock_update = 0; |
| 3990 | 4132 | ||
| 3991 | if (likely(prev != next)) { | 4133 | if (likely(prev != next)) { |
| 3992 | sched_info_switch(prev, next); | ||
| 3993 | perf_event_task_sched_out(prev, next); | ||
| 3994 | |||
| 3995 | rq->nr_switches++; | 4134 | rq->nr_switches++; |
| 3996 | rq->curr = next; | 4135 | rq->curr = next; |
| 3997 | ++*switch_count; | 4136 | ++*switch_count; |
| @@ -4213,6 +4352,7 @@ void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key) | |||
| 4213 | { | 4352 | { |
| 4214 | __wake_up_common(q, mode, 1, 0, key); | 4353 | __wake_up_common(q, mode, 1, 0, key); |
| 4215 | } | 4354 | } |
| 4355 | EXPORT_SYMBOL_GPL(__wake_up_locked_key); | ||
| 4216 | 4356 | ||
| 4217 | /** | 4357 | /** |
| 4218 | * __wake_up_sync_key - wake up threads blocked on a waitqueue. | 4358 | * __wake_up_sync_key - wake up threads blocked on a waitqueue. |
| @@ -4570,11 +4710,10 @@ void rt_mutex_setprio(struct task_struct *p, int prio) | |||
| 4570 | 4710 | ||
| 4571 | if (running) | 4711 | if (running) |
| 4572 | p->sched_class->set_curr_task(rq); | 4712 | p->sched_class->set_curr_task(rq); |
| 4573 | if (on_rq) { | 4713 | if (on_rq) |
| 4574 | enqueue_task(rq, p, oldprio < prio ? ENQUEUE_HEAD : 0); | 4714 | enqueue_task(rq, p, oldprio < prio ? ENQUEUE_HEAD : 0); |
| 4575 | 4715 | ||
| 4576 | check_class_changed(rq, p, prev_class, oldprio, running); | 4716 | check_class_changed(rq, p, prev_class, oldprio); |
| 4577 | } | ||
| 4578 | task_rq_unlock(rq, &flags); | 4717 | task_rq_unlock(rq, &flags); |
| 4579 | } | 4718 | } |
| 4580 | 4719 | ||
| @@ -4822,12 +4961,15 @@ recheck: | |||
| 4822 | param->sched_priority > rlim_rtprio) | 4961 | param->sched_priority > rlim_rtprio) |
| 4823 | return -EPERM; | 4962 | return -EPERM; |
| 4824 | } | 4963 | } |
| 4964 | |||
| 4825 | /* | 4965 | /* |
| 4826 | * Like positive nice levels, dont allow tasks to | 4966 | * Treat SCHED_IDLE as nice 20. Only allow a switch to |
| 4827 | * move out of SCHED_IDLE either: | 4967 | * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. |
| 4828 | */ | 4968 | */ |
| 4829 | if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) | 4969 | if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) { |
| 4830 | return -EPERM; | 4970 | if (!can_nice(p, TASK_NICE(p))) |
| 4971 | return -EPERM; | ||
| 4972 | } | ||
| 4831 | 4973 | ||
| 4832 | /* can't change other user's priorities */ | 4974 | /* can't change other user's priorities */ |
| 4833 | if (!check_same_owner(p)) | 4975 | if (!check_same_owner(p)) |
| @@ -4902,11 +5044,10 @@ recheck: | |||
| 4902 | 5044 | ||
| 4903 | if (running) | 5045 | if (running) |
| 4904 | p->sched_class->set_curr_task(rq); | 5046 | p->sched_class->set_curr_task(rq); |
| 4905 | if (on_rq) { | 5047 | if (on_rq) |
| 4906 | activate_task(rq, p, 0); | 5048 | activate_task(rq, p, 0); |
| 4907 | 5049 | ||
| 4908 | check_class_changed(rq, p, prev_class, oldprio, running); | 5050 | check_class_changed(rq, p, prev_class, oldprio); |
| 4909 | } | ||
| 4910 | __task_rq_unlock(rq); | 5051 | __task_rq_unlock(rq); |
| 4911 | raw_spin_unlock_irqrestore(&p->pi_lock, flags); | 5052 | raw_spin_unlock_irqrestore(&p->pi_lock, flags); |
| 4912 | 5053 | ||
| @@ -5323,6 +5464,65 @@ void __sched yield(void) | |||
| 5323 | } | 5464 | } |
| 5324 | EXPORT_SYMBOL(yield); | 5465 | EXPORT_SYMBOL(yield); |
| 5325 | 5466 | ||
| 5467 | /** | ||
| 5468 | * yield_to - yield the current processor to another thread in | ||
| 5469 | * your thread group, or accelerate that thread toward the | ||
| 5470 | * processor it's on. | ||
| 5471 | * | ||
| 5472 | * It's the caller's job to ensure that the target task struct | ||
| 5473 | * can't go away on us before we can do any checks. | ||
| 5474 | * | ||
| 5475 | * Returns true if we indeed boosted the target task. | ||
| 5476 | */ | ||
| 5477 | bool __sched yield_to(struct task_struct *p, bool preempt) | ||
| 5478 | { | ||
| 5479 | struct task_struct *curr = current; | ||
| 5480 | struct rq *rq, *p_rq; | ||
| 5481 | unsigned long flags; | ||
| 5482 | bool yielded = 0; | ||
| 5483 | |||
| 5484 | local_irq_save(flags); | ||
| 5485 | rq = this_rq(); | ||
| 5486 | |||
| 5487 | again: | ||
| 5488 | p_rq = task_rq(p); | ||
| 5489 | double_rq_lock(rq, p_rq); | ||
| 5490 | while (task_rq(p) != p_rq) { | ||
| 5491 | double_rq_unlock(rq, p_rq); | ||
| 5492 | goto again; | ||
| 5493 | } | ||
| 5494 | |||
| 5495 | if (!curr->sched_class->yield_to_task) | ||
| 5496 | goto out; | ||
| 5497 | |||
| 5498 | if (curr->sched_class != p->sched_class) | ||
| 5499 | goto out; | ||
| 5500 | |||
| 5501 | if (task_running(p_rq, p) || p->state) | ||
| 5502 | goto out; | ||
| 5503 | |||
| 5504 | yielded = curr->sched_class->yield_to_task(rq, p, preempt); | ||
| 5505 | if (yielded) { | ||
| 5506 | schedstat_inc(rq, yld_count); | ||
| 5507 | /* | ||
| 5508 | * Make p's CPU reschedule; pick_next_entity takes care of | ||
| 5509 | * fairness. | ||
| 5510 | */ | ||
| 5511 | if (preempt && rq != p_rq) | ||
| 5512 | resched_task(p_rq->curr); | ||
| 5513 | } | ||
| 5514 | |||
| 5515 | out: | ||
| 5516 | double_rq_unlock(rq, p_rq); | ||
| 5517 | local_irq_restore(flags); | ||
| 5518 | |||
| 5519 | if (yielded) | ||
| 5520 | schedule(); | ||
| 5521 | |||
| 5522 | return yielded; | ||
| 5523 | } | ||
| 5524 | EXPORT_SYMBOL_GPL(yield_to); | ||
| 5525 | |||
| 5326 | /* | 5526 | /* |
| 5327 | * This task is about to go to sleep on IO. Increment rq->nr_iowait so | 5527 | * This task is about to go to sleep on IO. Increment rq->nr_iowait so |
| 5328 | * that process accounting knows that this is a task in IO wait state. | 5528 | * that process accounting knows that this is a task in IO wait state. |
| @@ -5571,7 +5771,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
| 5571 | * The idle tasks have their own, simple scheduling class: | 5771 | * The idle tasks have their own, simple scheduling class: |
| 5572 | */ | 5772 | */ |
| 5573 | idle->sched_class = &idle_sched_class; | 5773 | idle->sched_class = &idle_sched_class; |
| 5574 | ftrace_graph_init_task(idle); | 5774 | ftrace_graph_init_idle_task(idle, cpu); |
| 5575 | } | 5775 | } |
| 5576 | 5776 | ||
| 5577 | /* | 5777 | /* |
| @@ -7796,6 +7996,10 @@ static void init_cfs_rq(struct cfs_rq *cfs_rq, struct rq *rq) | |||
| 7796 | INIT_LIST_HEAD(&cfs_rq->tasks); | 7996 | INIT_LIST_HEAD(&cfs_rq->tasks); |
| 7797 | #ifdef CONFIG_FAIR_GROUP_SCHED | 7997 | #ifdef CONFIG_FAIR_GROUP_SCHED |
| 7798 | cfs_rq->rq = rq; | 7998 | cfs_rq->rq = rq; |
| 7999 | /* allow initial update_cfs_load() to truncate */ | ||
| 8000 | #ifdef CONFIG_SMP | ||
| 8001 | cfs_rq->load_stamp = 1; | ||
| 8002 | #endif | ||
| 7799 | #endif | 8003 | #endif |
| 7800 | cfs_rq->min_vruntime = (u64)(-(1LL << 20)); | 8004 | cfs_rq->min_vruntime = (u64)(-(1LL << 20)); |
| 7801 | } | 8005 | } |
| @@ -8109,6 +8313,8 @@ EXPORT_SYMBOL(__might_sleep); | |||
| 8109 | #ifdef CONFIG_MAGIC_SYSRQ | 8313 | #ifdef CONFIG_MAGIC_SYSRQ |
| 8110 | static void normalize_task(struct rq *rq, struct task_struct *p) | 8314 | static void normalize_task(struct rq *rq, struct task_struct *p) |
| 8111 | { | 8315 | { |
| 8316 | const struct sched_class *prev_class = p->sched_class; | ||
| 8317 | int old_prio = p->prio; | ||
| 8112 | int on_rq; | 8318 | int on_rq; |
| 8113 | 8319 | ||
| 8114 | on_rq = p->se.on_rq; | 8320 | on_rq = p->se.on_rq; |
| @@ -8119,6 +8325,8 @@ static void normalize_task(struct rq *rq, struct task_struct *p) | |||
| 8119 | activate_task(rq, p, 0); | 8325 | activate_task(rq, p, 0); |
| 8120 | resched_task(rq->curr); | 8326 | resched_task(rq->curr); |
| 8121 | } | 8327 | } |
| 8328 | |||
| 8329 | check_class_changed(rq, p, prev_class, old_prio); | ||
| 8122 | } | 8330 | } |
| 8123 | 8331 | ||
| 8124 | void normalize_rt_tasks(void) | 8332 | void normalize_rt_tasks(void) |
| @@ -8510,7 +8718,7 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares) | |||
| 8510 | /* Propagate contribution to hierarchy */ | 8718 | /* Propagate contribution to hierarchy */ |
| 8511 | raw_spin_lock_irqsave(&rq->lock, flags); | 8719 | raw_spin_lock_irqsave(&rq->lock, flags); |
| 8512 | for_each_sched_entity(se) | 8720 | for_each_sched_entity(se) |
| 8513 | update_cfs_shares(group_cfs_rq(se), 0); | 8721 | update_cfs_shares(group_cfs_rq(se)); |
| 8514 | raw_spin_unlock_irqrestore(&rq->lock, flags); | 8722 | raw_spin_unlock_irqrestore(&rq->lock, flags); |
| 8515 | } | 8723 | } |
| 8516 | 8724 | ||
| @@ -8884,7 +9092,8 @@ cpu_cgroup_attach(struct cgroup_subsys *ss, struct cgroup *cgrp, | |||
| 8884 | } | 9092 | } |
| 8885 | 9093 | ||
| 8886 | static void | 9094 | static void |
| 8887 | cpu_cgroup_exit(struct cgroup_subsys *ss, struct task_struct *task) | 9095 | cpu_cgroup_exit(struct cgroup_subsys *ss, struct cgroup *cgrp, |
| 9096 | struct cgroup *old_cgrp, struct task_struct *task) | ||
| 8888 | { | 9097 | { |
| 8889 | /* | 9098 | /* |
| 8890 | * cgroup_exit() is called in the copy_process() failure path. | 9099 | * cgroup_exit() is called in the copy_process() failure path. |
