[PATCH] sched: clean up fallout of recent changes

Clean up some of the impact of recent (and not so recent) scheduler
changes:

- turning macros into nice inline functions
- sanitizing and unifying variable definitions
- whitespace, style consistency, 80-lines, comment correctness, spelling
and curly braces police

Due to the macro hell and variable placement simplifications there's even 26
bytes of .text saved:

text data bss dec hex filename
25510 4153 192 29855 749f sched.o.before
25484 4153 192 29829 7485 sched.o.after

[akpm@osdl.org: build fix]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Ingo Molnar and committed by Linus Torvalds 48f24c4d 829035fd

+195 -167
+195 -167
kernel/sched.c
··· 184 184 return static_prio_timeslice(p->static_prio); 185 185 } 186 186 187 - #define task_hot(p, now, sd) ((long long) ((now) - (p)->last_ran) \ 188 - < (long long) (sd)->cache_hot_time) 189 - 190 187 /* 191 188 * These are the runqueue data structures: 192 189 */ ··· 275 278 * The domain tree of any CPU may only be accessed from within 276 279 * preempt-disabled sections. 277 280 */ 278 - #define for_each_domain(cpu, domain) \ 279 - for (domain = rcu_dereference(cpu_rq(cpu)->sd); domain; domain = domain->parent) 281 + #define for_each_domain(cpu, __sd) \ 282 + for (__sd = rcu_dereference(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent) 280 283 281 284 #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu))) 282 285 #define this_rq() (&__get_cpu_var(runqueues)) ··· 1036 1039 req->task = p; 1037 1040 req->dest_cpu = dest_cpu; 1038 1041 list_add(&req->list, &rq->migration_queue); 1042 + 1039 1043 return 1; 1040 1044 } 1041 1045 ··· 1133 1135 runqueue_t *rq = cpu_rq(cpu); 1134 1136 unsigned long n = rq->nr_running; 1135 1137 1136 - return n ? rq->raw_weighted_load / n : SCHED_LOAD_SCALE; 1138 + return n ? rq->raw_weighted_load / n : SCHED_LOAD_SCALE; 1137 1139 } 1138 1140 1139 1141 /* ··· 1492 1494 return try_to_wake_up(p, TASK_STOPPED | TASK_TRACED | 1493 1495 TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE, 0); 1494 1496 } 1495 - 1496 1497 EXPORT_SYMBOL(wake_up_process); 1497 1498 1498 1499 int fastcall wake_up_state(task_t *p, unsigned int state) ··· 1864 1867 #ifdef CONFIG_SMP 1865 1868 1866 1869 /* 1870 + * Is this task likely cache-hot: 1871 + */ 1872 + static inline int 1873 + task_hot(struct task_struct *p, unsigned long long now, struct sched_domain *sd) 1874 + { 1875 + return (long long)(now - p->last_ran) < (long long)sd->cache_hot_time; 1876 + } 1877 + 1878 + /* 1867 1879 * double_rq_lock - safely lock two runqueues 1868 1880 * 1869 1881 * Note this does not disable interrupts like task_rq_lock, ··· 2035 2029 } 2036 2030 2037 2031 #define rq_best_prio(rq) min((rq)->curr->prio, (rq)->best_expired_prio) 2032 + 2038 2033 /* 2039 2034 * move_tasks tries to move up to max_nr_move tasks and max_load_move weighted 2040 2035 * load from busiest to this_rq, as part of a balancing operation within ··· 2048 2041 struct sched_domain *sd, enum idle_type idle, 2049 2042 int *all_pinned) 2050 2043 { 2044 + int idx, pulled = 0, pinned = 0, this_best_prio, best_prio, 2045 + best_prio_seen, skip_for_load; 2051 2046 prio_array_t *array, *dst_array; 2052 2047 struct list_head *head, *curr; 2053 - int idx, pulled = 0, pinned = 0, this_best_prio, busiest_best_prio; 2054 - int busiest_best_prio_seen; 2055 - int skip_for_load; /* skip the task based on weighted load issues */ 2056 2048 long rem_load_move; 2057 2049 task_t *tmp; 2058 2050 ··· 2061 2055 rem_load_move = max_load_move; 2062 2056 pinned = 1; 2063 2057 this_best_prio = rq_best_prio(this_rq); 2064 - busiest_best_prio = rq_best_prio(busiest); 2058 + best_prio = rq_best_prio(busiest); 2065 2059 /* 2066 2060 * Enable handling of the case where there is more than one task 2067 2061 * with the best priority. If the current running task is one 2068 - * of those with prio==busiest_best_prio we know it won't be moved 2062 + * of those with prio==best_prio we know it won't be moved 2069 2063 * and therefore it's safe to override the skip (based on load) of 2070 2064 * any task we find with that prio. 2071 2065 */ 2072 - busiest_best_prio_seen = busiest_best_prio == busiest->curr->prio; 2066 + best_prio_seen = best_prio == busiest->curr->prio; 2073 2067 2074 2068 /* 2075 2069 * We first consider expired tasks. Those will likely not be ··· 2116 2110 */ 2117 2111 skip_for_load = tmp->load_weight > rem_load_move; 2118 2112 if (skip_for_load && idx < this_best_prio) 2119 - skip_for_load = !busiest_best_prio_seen && idx == busiest_best_prio; 2113 + skip_for_load = !best_prio_seen && idx == best_prio; 2120 2114 if (skip_for_load || 2121 2115 !can_migrate_task(tmp, busiest, this_cpu, sd, idle, &pinned)) { 2122 - busiest_best_prio_seen |= idx == busiest_best_prio; 2116 + 2117 + best_prio_seen |= idx == best_prio; 2123 2118 if (curr != head) 2124 2119 goto skip_queue; 2125 2120 idx++; ··· 2163 2156 2164 2157 /* 2165 2158 * find_busiest_group finds and returns the busiest CPU group within the 2166 - * domain. It calculates and returns the amount of weighted load which should be 2167 - * moved to restore balance via the imbalance parameter. 2159 + * domain. It calculates and returns the amount of weighted load which 2160 + * should be moved to restore balance via the imbalance parameter. 2168 2161 */ 2169 2162 static struct sched_group * 2170 2163 find_busiest_group(struct sched_domain *sd, int this_cpu, ··· 2286 2279 * capacity but still has some space to pick up some load 2287 2280 * from other group and save more power 2288 2281 */ 2289 - if (sum_nr_running <= group_capacity - 1) 2282 + if (sum_nr_running <= group_capacity - 1) { 2290 2283 if (sum_nr_running > leader_nr_running || 2291 2284 (sum_nr_running == leader_nr_running && 2292 2285 first_cpu(group->cpumask) > ··· 2294 2287 group_leader = group; 2295 2288 leader_nr_running = sum_nr_running; 2296 2289 } 2297 - 2290 + } 2298 2291 group_next: 2299 2292 #endif 2300 2293 group = group->next; ··· 2349 2342 * moved 2350 2343 */ 2351 2344 if (*imbalance < busiest_load_per_task) { 2352 - unsigned long pwr_now, pwr_move; 2353 - unsigned long tmp; 2345 + unsigned long tmp, pwr_now, pwr_move; 2354 2346 unsigned int imbn; 2355 2347 2356 2348 small_imbalance: ··· 2421 2415 /* 2422 2416 * find_busiest_queue - find the busiest runqueue among the cpus in group. 2423 2417 */ 2424 - static runqueue_t *find_busiest_queue(struct sched_group *group, 2425 - enum idle_type idle, unsigned long imbalance) 2418 + static runqueue_t * 2419 + find_busiest_queue(struct sched_group *group, enum idle_type idle, 2420 + unsigned long imbalance) 2426 2421 { 2422 + runqueue_t *busiest = NULL, *rq; 2427 2423 unsigned long max_load = 0; 2428 - runqueue_t *busiest = NULL, *rqi; 2429 2424 int i; 2430 2425 2431 2426 for_each_cpu_mask(i, group->cpumask) { 2432 - rqi = cpu_rq(i); 2427 + rq = cpu_rq(i); 2433 2428 2434 - if (rqi->nr_running == 1 && rqi->raw_weighted_load > imbalance) 2429 + if (rq->nr_running == 1 && rq->raw_weighted_load > imbalance) 2435 2430 continue; 2436 2431 2437 - if (rqi->raw_weighted_load > max_load) { 2438 - max_load = rqi->raw_weighted_load; 2439 - busiest = rqi; 2432 + if (rq->raw_weighted_load > max_load) { 2433 + max_load = rq->raw_weighted_load; 2434 + busiest = rq; 2440 2435 } 2441 2436 } 2442 2437 ··· 2450 2443 */ 2451 2444 #define MAX_PINNED_INTERVAL 512 2452 2445 2453 - #define minus_1_or_zero(n) ((n) > 0 ? (n) - 1 : 0) 2446 + static inline unsigned long minus_1_or_zero(unsigned long n) 2447 + { 2448 + return n > 0 ? n - 1 : 0; 2449 + } 2450 + 2454 2451 /* 2455 2452 * Check this_cpu to ensure it is balanced within domain. Attempt to move 2456 2453 * tasks if there is an imbalance. ··· 2464 2453 static int load_balance(int this_cpu, runqueue_t *this_rq, 2465 2454 struct sched_domain *sd, enum idle_type idle) 2466 2455 { 2456 + int nr_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; 2467 2457 struct sched_group *group; 2468 - runqueue_t *busiest; 2469 2458 unsigned long imbalance; 2470 - int nr_moved, all_pinned = 0; 2471 - int active_balance = 0; 2472 - int sd_idle = 0; 2459 + runqueue_t *busiest; 2473 2460 2474 2461 if (idle != NOT_IDLE && sd->flags & SD_SHARE_CPUPOWER && 2475 2462 !sched_smt_power_savings) ··· 2501 2492 */ 2502 2493 double_rq_lock(this_rq, busiest); 2503 2494 nr_moved = move_tasks(this_rq, this_cpu, busiest, 2504 - minus_1_or_zero(busiest->nr_running), 2505 - imbalance, sd, idle, &all_pinned); 2495 + minus_1_or_zero(busiest->nr_running), 2496 + imbalance, sd, idle, &all_pinned); 2506 2497 double_rq_unlock(this_rq, busiest); 2507 2498 2508 2499 /* All tasks on this runqueue were pinned by CPU affinity */ ··· 2575 2566 (sd->balance_interval < sd->max_interval)) 2576 2567 sd->balance_interval *= 2; 2577 2568 2578 - if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER && !sched_smt_power_savings) 2569 + if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER && 2570 + !sched_smt_power_savings) 2579 2571 return -1; 2580 2572 return 0; 2581 2573 } ··· 2588 2578 * Called from schedule when this_rq is about to become idle (NEWLY_IDLE). 2589 2579 * this_rq is locked. 2590 2580 */ 2591 - static int load_balance_newidle(int this_cpu, runqueue_t *this_rq, 2592 - struct sched_domain *sd) 2581 + static int 2582 + load_balance_newidle(int this_cpu, runqueue_t *this_rq, struct sched_domain *sd) 2593 2583 { 2594 2584 struct sched_group *group; 2595 2585 runqueue_t *busiest = NULL; ··· 2638 2628 2639 2629 out_balanced: 2640 2630 schedstat_inc(sd, lb_balanced[NEWLY_IDLE]); 2641 - if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER && !sched_smt_power_savings) 2631 + if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER && 2632 + !sched_smt_power_savings) 2642 2633 return -1; 2643 2634 sd->nr_balance_failed = 0; 2635 + 2644 2636 return 0; 2645 2637 } 2646 2638 ··· 2656 2644 2657 2645 for_each_domain(this_cpu, sd) { 2658 2646 if (sd->flags & SD_BALANCE_NEWIDLE) { 2659 - if (load_balance_newidle(this_cpu, this_rq, sd)) { 2660 - /* We've pulled tasks over so stop searching */ 2647 + /* If we've pulled tasks over stop searching: */ 2648 + if (load_balance_newidle(this_cpu, this_rq, sd)) 2661 2649 break; 2662 - } 2663 2650 } 2664 2651 } 2665 2652 } ··· 2677 2666 runqueue_t *target_rq; 2678 2667 int target_cpu = busiest_rq->push_cpu; 2679 2668 2669 + /* Is there any task to move? */ 2680 2670 if (busiest_rq->nr_running <= 1) 2681 - /* no task to move */ 2682 2671 return; 2683 2672 2684 2673 target_rq = cpu_rq(target_cpu); ··· 2696 2685 /* Search for an sd spanning us and the target CPU. */ 2697 2686 for_each_domain(target_cpu, sd) { 2698 2687 if ((sd->flags & SD_LOAD_BALANCE) && 2699 - cpu_isset(busiest_cpu, sd->span)) 2688 + cpu_isset(busiest_cpu, sd->span)) 2700 2689 break; 2701 2690 } 2702 2691 2703 - if (unlikely(sd == NULL)) 2704 - goto out; 2692 + if (likely(sd)) { 2693 + schedstat_inc(sd, alb_cnt); 2705 2694 2706 - schedstat_inc(sd, alb_cnt); 2707 - 2708 - if (move_tasks(target_rq, target_cpu, busiest_rq, 1, 2709 - RTPRIO_TO_LOAD_WEIGHT(100), sd, SCHED_IDLE, NULL)) 2710 - schedstat_inc(sd, alb_pushed); 2711 - else 2712 - schedstat_inc(sd, alb_failed); 2713 - out: 2695 + if (move_tasks(target_rq, target_cpu, busiest_rq, 1, 2696 + RTPRIO_TO_LOAD_WEIGHT(100), sd, SCHED_IDLE, 2697 + NULL)) 2698 + schedstat_inc(sd, alb_pushed); 2699 + else 2700 + schedstat_inc(sd, alb_failed); 2701 + } 2714 2702 spin_unlock(&target_rq->lock); 2715 2703 } 2716 2704 ··· 2722 2712 * Balancing parameters are set up in arch_init_sched_domains. 2723 2713 */ 2724 2714 2725 - /* Don't have all balancing operations going off at once */ 2726 - #define CPU_OFFSET(cpu) (HZ * cpu / NR_CPUS) 2727 - 2728 - static void rebalance_tick(int this_cpu, runqueue_t *this_rq, 2729 - enum idle_type idle) 2715 + /* Don't have all balancing operations going off at once: */ 2716 + static inline unsigned long cpu_offset(int cpu) 2730 2717 { 2731 - unsigned long old_load, this_load; 2732 - unsigned long j = jiffies + CPU_OFFSET(this_cpu); 2718 + return jiffies + cpu * HZ / NR_CPUS; 2719 + } 2720 + 2721 + static void 2722 + rebalance_tick(int this_cpu, runqueue_t *this_rq, enum idle_type idle) 2723 + { 2724 + unsigned long this_load, interval, j = cpu_offset(this_cpu); 2733 2725 struct sched_domain *sd; 2734 - int i; 2726 + int i, scale; 2735 2727 2736 2728 this_load = this_rq->raw_weighted_load; 2737 - /* Update our load */ 2738 - for (i = 0; i < 3; i++) { 2739 - unsigned long new_load = this_load; 2740 - int scale = 1 << i; 2729 + 2730 + /* Update our load: */ 2731 + for (i = 0, scale = 1; i < 3; i++, scale <<= 1) { 2732 + unsigned long old_load, new_load; 2733 + 2741 2734 old_load = this_rq->cpu_load[i]; 2735 + new_load = this_load; 2742 2736 /* 2743 2737 * Round up the averaging division if load is increasing. This 2744 2738 * prevents us from getting stuck on 9 if the load is 10, for ··· 2754 2740 } 2755 2741 2756 2742 for_each_domain(this_cpu, sd) { 2757 - unsigned long interval; 2758 - 2759 2743 if (!(sd->flags & SD_LOAD_BALANCE)) 2760 2744 continue; 2761 2745 ··· 2794 2782 static inline int wake_priority_sleeper(runqueue_t *rq) 2795 2783 { 2796 2784 int ret = 0; 2785 + 2797 2786 #ifdef CONFIG_SCHED_SMT 2798 2787 spin_lock(&rq->lock); 2799 2788 /* ··· 2818 2805 * This is called on clock ticks and on context switches. 2819 2806 * Bank in p->sched_time the ns elapsed since the last tick or switch. 2820 2807 */ 2821 - static inline void update_cpu_clock(task_t *p, runqueue_t *rq, 2822 - unsigned long long now) 2808 + static inline void 2809 + update_cpu_clock(task_t *p, runqueue_t *rq, unsigned long long now) 2823 2810 { 2824 - unsigned long long last = max(p->timestamp, rq->timestamp_last_tick); 2825 - p->sched_time += now - last; 2811 + p->sched_time += now - max(p->timestamp, rq->timestamp_last_tick); 2826 2812 } 2827 2813 2828 2814 /* 2829 2815 * Return current->sched_time plus any more ns on the sched_clock 2830 2816 * that have not yet been banked. 2831 2817 */ 2832 - unsigned long long current_sched_time(const task_t *tsk) 2818 + unsigned long long current_sched_time(const task_t *p) 2833 2819 { 2834 2820 unsigned long long ns; 2835 2821 unsigned long flags; 2822 + 2836 2823 local_irq_save(flags); 2837 - ns = max(tsk->timestamp, task_rq(tsk)->timestamp_last_tick); 2838 - ns = tsk->sched_time + (sched_clock() - ns); 2824 + ns = max(p->timestamp, task_rq(p)->timestamp_last_tick); 2825 + ns = p->sched_time + sched_clock() - ns; 2839 2826 local_irq_restore(flags); 2827 + 2840 2828 return ns; 2841 2829 } 2842 2830 ··· 2851 2837 * increasing number of running tasks. We also ignore the interactivity 2852 2838 * if a better static_prio task has expired: 2853 2839 */ 2854 - #define EXPIRED_STARVING(rq) \ 2855 - ((STARVATION_LIMIT && ((rq)->expired_timestamp && \ 2856 - (jiffies - (rq)->expired_timestamp >= \ 2857 - STARVATION_LIMIT * ((rq)->nr_running) + 1))) || \ 2858 - ((rq)->curr->static_prio > (rq)->best_expired_prio)) 2840 + static inline int expired_starving(runqueue_t *rq) 2841 + { 2842 + if (rq->curr->static_prio > rq->best_expired_prio) 2843 + return 1; 2844 + if (!STARVATION_LIMIT || !rq->expired_timestamp) 2845 + return 0; 2846 + if (jiffies - rq->expired_timestamp > STARVATION_LIMIT * rq->nr_running) 2847 + return 1; 2848 + return 0; 2849 + } 2859 2850 2860 2851 /* 2861 2852 * Account user cpu time to a process. ··· 2944 2925 */ 2945 2926 void scheduler_tick(void) 2946 2927 { 2928 + unsigned long long now = sched_clock(); 2947 2929 int cpu = smp_processor_id(); 2948 2930 runqueue_t *rq = this_rq(); 2949 2931 task_t *p = current; 2950 - unsigned long long now = sched_clock(); 2951 2932 2952 2933 update_cpu_clock(p, rq, now); 2953 2934 ··· 2997 2978 2998 2979 if (!rq->expired_timestamp) 2999 2980 rq->expired_timestamp = jiffies; 3000 - if (!TASK_INTERACTIVE(p) || EXPIRED_STARVING(rq)) { 2981 + if (!TASK_INTERACTIVE(p) || expired_starving(rq)) { 3001 2982 enqueue_task(p, rq->expired); 3002 2983 if (p->static_prio < rq->best_expired_prio) 3003 2984 rq->best_expired_prio = p->static_prio; ··· 3156 3137 static inline void wake_sleeping_dependent(int this_cpu) 3157 3138 { 3158 3139 } 3159 - 3160 - static inline int dependent_sleeper(int this_cpu, runqueue_t *this_rq, 3161 - task_t *p) 3140 + static inline int 3141 + dependent_sleeper(int this_cpu, runqueue_t *this_rq, task_t *p) 3162 3142 { 3163 3143 return 0; 3164 3144 } ··· 3211 3193 */ 3212 3194 asmlinkage void __sched schedule(void) 3213 3195 { 3214 - long *switch_count; 3215 - task_t *prev, *next; 3216 - runqueue_t *rq; 3217 - prio_array_t *array; 3218 3196 struct list_head *queue; 3219 3197 unsigned long long now; 3220 3198 unsigned long run_time; 3221 3199 int cpu, idx, new_prio; 3200 + task_t *prev, *next; 3201 + prio_array_t *array; 3202 + long *switch_count; 3203 + runqueue_t *rq; 3222 3204 3223 3205 /* 3224 3206 * Test if we are atomic. Since do_exit() needs to call into ··· 3371 3353 if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) 3372 3354 goto need_resched; 3373 3355 } 3374 - 3375 3356 EXPORT_SYMBOL(schedule); 3376 3357 3377 3358 #ifdef CONFIG_PREEMPT ··· 3415 3398 if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) 3416 3399 goto need_resched; 3417 3400 } 3418 - 3419 3401 EXPORT_SYMBOL(preempt_schedule); 3420 3402 3421 3403 /* ··· 3463 3447 int default_wake_function(wait_queue_t *curr, unsigned mode, int sync, 3464 3448 void *key) 3465 3449 { 3466 - task_t *p = curr->private; 3467 - return try_to_wake_up(p, mode, sync); 3450 + return try_to_wake_up(curr->private, mode, sync); 3468 3451 } 3469 - 3470 3452 EXPORT_SYMBOL(default_wake_function); 3471 3453 3472 3454 /* ··· 3482 3468 struct list_head *tmp, *next; 3483 3469 3484 3470 list_for_each_safe(tmp, next, &q->task_list) { 3485 - wait_queue_t *curr; 3486 - unsigned flags; 3487 - curr = list_entry(tmp, wait_queue_t, task_list); 3488 - flags = curr->flags; 3471 + wait_queue_t *curr = list_entry(tmp, wait_queue_t, task_list); 3472 + unsigned flags = curr->flags; 3473 + 3489 3474 if (curr->func(curr, mode, sync, key) && 3490 - (flags & WQ_FLAG_EXCLUSIVE) && 3491 - !--nr_exclusive) 3475 + (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive) 3492 3476 break; 3493 3477 } 3494 3478 } ··· 3507 3495 __wake_up_common(q, mode, nr_exclusive, 0, key); 3508 3496 spin_unlock_irqrestore(&q->lock, flags); 3509 3497 } 3510 - 3511 3498 EXPORT_SYMBOL(__wake_up); 3512 3499 3513 3500 /* ··· 3575 3564 void fastcall __sched wait_for_completion(struct completion *x) 3576 3565 { 3577 3566 might_sleep(); 3567 + 3578 3568 spin_lock_irq(&x->wait.lock); 3579 3569 if (!x->done) { 3580 3570 DECLARE_WAITQUEUE(wait, current); ··· 3720 3708 schedule(); 3721 3709 SLEEP_ON_TAIL 3722 3710 } 3723 - 3724 3711 EXPORT_SYMBOL(interruptible_sleep_on); 3725 3712 3726 3713 long fastcall __sched ··· 3735 3724 3736 3725 return timeout; 3737 3726 } 3738 - 3739 3727 EXPORT_SYMBOL(interruptible_sleep_on_timeout); 3740 3728 3741 3729 void fastcall __sched sleep_on(wait_queue_head_t *q) ··· 3747 3737 schedule(); 3748 3738 SLEEP_ON_TAIL 3749 3739 } 3750 - 3751 3740 EXPORT_SYMBOL(sleep_on); 3752 3741 3753 3742 long fastcall __sched sleep_on_timeout(wait_queue_head_t *q, long timeout) ··· 3819 3810 3820 3811 void set_user_nice(task_t *p, long nice) 3821 3812 { 3813 + int old_prio, delta; 3822 3814 unsigned long flags; 3823 3815 prio_array_t *array; 3824 3816 runqueue_t *rq; 3825 - int old_prio, delta; 3826 3817 3827 3818 if (TASK_NICE(p) == nice || nice < -20 || nice > 19) 3828 3819 return; ··· 3877 3868 { 3878 3869 /* convert nice value [19,-20] to rlimit style value [1,40] */ 3879 3870 int nice_rlim = 20 - nice; 3871 + 3880 3872 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur || 3881 3873 capable(CAP_SYS_NICE)); 3882 3874 } ··· 3893 3883 */ 3894 3884 asmlinkage long sys_nice(int increment) 3895 3885 { 3896 - int retval; 3897 - long nice; 3886 + long nice, retval; 3898 3887 3899 3888 /* 3900 3889 * Setpriority might change our priority at the same moment. ··· 3978 3969 static void __setscheduler(struct task_struct *p, int policy, int prio) 3979 3970 { 3980 3971 BUG_ON(p->array); 3972 + 3981 3973 p->policy = policy; 3982 3974 p->rt_priority = prio; 3983 3975 p->normal_prio = normal_prio(p); ··· 4002 3992 int sched_setscheduler(struct task_struct *p, int policy, 4003 3993 struct sched_param *param) 4004 3994 { 4005 - int retval; 4006 - int oldprio, oldpolicy = -1; 3995 + int retval, oldprio, oldpolicy = -1; 4007 3996 prio_array_t *array; 4008 3997 unsigned long flags; 4009 3998 runqueue_t *rq; ··· 4504 4495 set_current_state(TASK_RUNNING); 4505 4496 sys_sched_yield(); 4506 4497 } 4507 - 4508 4498 EXPORT_SYMBOL(yield); 4509 4499 4510 4500 /* ··· 4521 4513 schedule(); 4522 4514 atomic_dec(&rq->nr_iowait); 4523 4515 } 4524 - 4525 4516 EXPORT_SYMBOL(io_schedule); 4526 4517 4527 4518 long __sched io_schedule_timeout(long timeout) ··· 4622 4615 4623 4616 static inline struct task_struct *eldest_child(struct task_struct *p) 4624 4617 { 4625 - if (list_empty(&p->children)) return NULL; 4618 + if (list_empty(&p->children)) 4619 + return NULL; 4626 4620 return list_entry(p->children.next,struct task_struct,sibling); 4627 4621 } 4628 4622 4629 4623 static inline struct task_struct *older_sibling(struct task_struct *p) 4630 4624 { 4631 - if (p->sibling.prev==&p->parent->children) return NULL; 4625 + if (p->sibling.prev==&p->parent->children) 4626 + return NULL; 4632 4627 return list_entry(p->sibling.prev,struct task_struct,sibling); 4633 4628 } 4634 4629 4635 4630 static inline struct task_struct *younger_sibling(struct task_struct *p) 4636 4631 { 4637 - if (p->sibling.next==&p->parent->children) return NULL; 4632 + if (p->sibling.next==&p->parent->children) 4633 + return NULL; 4638 4634 return list_entry(p->sibling.next,struct task_struct,sibling); 4639 4635 } 4640 4636 ··· 4796 4786 int set_cpus_allowed(task_t *p, cpumask_t new_mask) 4797 4787 { 4798 4788 unsigned long flags; 4799 - int ret = 0; 4800 4789 migration_req_t req; 4801 4790 runqueue_t *rq; 4791 + int ret = 0; 4802 4792 4803 4793 rq = task_rq_lock(p, &flags); 4804 4794 if (!cpus_intersects(new_mask, cpu_online_map)) { ··· 4821 4811 } 4822 4812 out: 4823 4813 task_rq_unlock(rq, &flags); 4814 + 4824 4815 return ret; 4825 4816 } 4826 - 4827 4817 EXPORT_SYMBOL_GPL(set_cpus_allowed); 4828 4818 4829 4819 /* ··· 4884 4874 */ 4885 4875 static int migration_thread(void *data) 4886 4876 { 4887 - runqueue_t *rq; 4888 4877 int cpu = (long)data; 4878 + runqueue_t *rq; 4889 4879 4890 4880 rq = cpu_rq(cpu); 4891 4881 BUG_ON(rq->migration_thread != current); ··· 4942 4932 4943 4933 #ifdef CONFIG_HOTPLUG_CPU 4944 4934 /* Figure out where task on dead CPU should go, use force if neccessary. */ 4945 - static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *tsk) 4935 + static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) 4946 4936 { 4947 4937 runqueue_t *rq; 4948 4938 unsigned long flags; ··· 4952 4942 restart: 4953 4943 /* On same node? */ 4954 4944 mask = node_to_cpumask(cpu_to_node(dead_cpu)); 4955 - cpus_and(mask, mask, tsk->cpus_allowed); 4945 + cpus_and(mask, mask, p->cpus_allowed); 4956 4946 dest_cpu = any_online_cpu(mask); 4957 4947 4958 4948 /* On any allowed CPU? */ 4959 4949 if (dest_cpu == NR_CPUS) 4960 - dest_cpu = any_online_cpu(tsk->cpus_allowed); 4950 + dest_cpu = any_online_cpu(p->cpus_allowed); 4961 4951 4962 4952 /* No more Mr. Nice Guy. */ 4963 4953 if (dest_cpu == NR_CPUS) { 4964 - rq = task_rq_lock(tsk, &flags); 4965 - cpus_setall(tsk->cpus_allowed); 4966 - dest_cpu = any_online_cpu(tsk->cpus_allowed); 4954 + rq = task_rq_lock(p, &flags); 4955 + cpus_setall(p->cpus_allowed); 4956 + dest_cpu = any_online_cpu(p->cpus_allowed); 4967 4957 task_rq_unlock(rq, &flags); 4968 4958 4969 4959 /* ··· 4971 4961 * kernel threads (both mm NULL), since they never 4972 4962 * leave kernel. 4973 4963 */ 4974 - if (tsk->mm && printk_ratelimit()) 4964 + if (p->mm && printk_ratelimit()) 4975 4965 printk(KERN_INFO "process %d (%s) no " 4976 4966 "longer affine to cpu%d\n", 4977 - tsk->pid, tsk->comm, dead_cpu); 4967 + p->pid, p->comm, dead_cpu); 4978 4968 } 4979 - if (!__migrate_task(tsk, dead_cpu, dest_cpu)) 4969 + if (!__migrate_task(p, dead_cpu, dest_cpu)) 4980 4970 goto restart; 4981 4971 } 4982 4972 ··· 5003 4993 /* Run through task list and migrate tasks from the dead cpu. */ 5004 4994 static void migrate_live_tasks(int src_cpu) 5005 4995 { 5006 - struct task_struct *tsk, *t; 4996 + struct task_struct *p, *t; 5007 4997 5008 4998 write_lock_irq(&tasklist_lock); 5009 4999 5010 - do_each_thread(t, tsk) { 5011 - if (tsk == current) 5000 + do_each_thread(t, p) { 5001 + if (p == current) 5012 5002 continue; 5013 5003 5014 - if (task_cpu(tsk) == src_cpu) 5015 - move_task_off_dead_cpu(src_cpu, tsk); 5016 - } while_each_thread(t, tsk); 5004 + if (task_cpu(p) == src_cpu) 5005 + move_task_off_dead_cpu(src_cpu, p); 5006 + } while_each_thread(t, p); 5017 5007 5018 5008 write_unlock_irq(&tasklist_lock); 5019 5009 } 5020 5010 5021 5011 /* Schedules idle task to be the next runnable task on current CPU. 5022 5012 * It does so by boosting its priority to highest possible and adding it to 5023 - * the _front_ of runqueue. Used by CPU offline code. 5013 + * the _front_ of the runqueue. Used by CPU offline code. 5024 5014 */ 5025 5015 void sched_idle_next(void) 5026 5016 { 5027 - int cpu = smp_processor_id(); 5028 - runqueue_t *rq = this_rq(); 5017 + int this_cpu = smp_processor_id(); 5018 + runqueue_t *rq = cpu_rq(this_cpu); 5029 5019 struct task_struct *p = rq->idle; 5030 5020 unsigned long flags; 5031 5021 5032 5022 /* cpu has to be offline */ 5033 - BUG_ON(cpu_online(cpu)); 5023 + BUG_ON(cpu_online(this_cpu)); 5034 5024 5035 - /* Strictly not necessary since rest of the CPUs are stopped by now 5036 - * and interrupts disabled on current cpu. 5025 + /* 5026 + * Strictly not necessary since rest of the CPUs are stopped by now 5027 + * and interrupts disabled on the current cpu. 5037 5028 */ 5038 5029 spin_lock_irqsave(&rq->lock, flags); 5039 5030 5040 5031 __setscheduler(p, SCHED_FIFO, MAX_RT_PRIO-1); 5041 - /* Add idle task to _front_ of it's priority queue */ 5032 + 5033 + /* Add idle task to the _front_ of its priority queue: */ 5042 5034 __activate_idle_task(p, rq); 5043 5035 5044 5036 spin_unlock_irqrestore(&rq->lock, flags); 5045 5037 } 5046 5038 5047 - /* Ensures that the idle task is using init_mm right before its cpu goes 5039 + /* 5040 + * Ensures that the idle task is using init_mm right before its cpu goes 5048 5041 * offline. 5049 5042 */ 5050 5043 void idle_task_exit(void) ··· 5061 5048 mmdrop(mm); 5062 5049 } 5063 5050 5064 - static void migrate_dead(unsigned int dead_cpu, task_t *tsk) 5051 + static void migrate_dead(unsigned int dead_cpu, task_t *p) 5065 5052 { 5066 5053 struct runqueue *rq = cpu_rq(dead_cpu); 5067 5054 5068 5055 /* Must be exiting, otherwise would be on tasklist. */ 5069 - BUG_ON(tsk->exit_state != EXIT_ZOMBIE && tsk->exit_state != EXIT_DEAD); 5056 + BUG_ON(p->exit_state != EXIT_ZOMBIE && p->exit_state != EXIT_DEAD); 5070 5057 5071 5058 /* Cannot have done final schedule yet: would have vanished. */ 5072 - BUG_ON(tsk->flags & PF_DEAD); 5059 + BUG_ON(p->flags & PF_DEAD); 5073 5060 5074 - get_task_struct(tsk); 5061 + get_task_struct(p); 5075 5062 5076 5063 /* 5077 5064 * Drop lock around migration; if someone else moves it, ··· 5079 5066 * fine. 5080 5067 */ 5081 5068 spin_unlock_irq(&rq->lock); 5082 - move_task_off_dead_cpu(dead_cpu, tsk); 5069 + move_task_off_dead_cpu(dead_cpu, p); 5083 5070 spin_lock_irq(&rq->lock); 5084 5071 5085 - put_task_struct(tsk); 5072 + put_task_struct(p); 5086 5073 } 5087 5074 5088 5075 /* release_task() removes task from tasklist, so we won't find dead tasks. */ 5089 5076 static void migrate_dead_tasks(unsigned int dead_cpu) 5090 5077 { 5091 - unsigned arr, i; 5092 5078 struct runqueue *rq = cpu_rq(dead_cpu); 5079 + unsigned int arr, i; 5093 5080 5094 5081 for (arr = 0; arr < 2; arr++) { 5095 5082 for (i = 0; i < MAX_PRIO; i++) { 5096 5083 struct list_head *list = &rq->arrays[arr].queue[i]; 5084 + 5097 5085 while (!list_empty(list)) 5098 5086 migrate_dead(dead_cpu, 5099 5087 list_entry(list->next, task_t, ··· 5108 5094 * migration_call - callback that gets triggered when a CPU is added. 5109 5095 * Here we can start up the necessary migration thread for the new CPU. 5110 5096 */ 5111 - static int __cpuinit migration_call(struct notifier_block *nfb, 5112 - unsigned long action, 5113 - void *hcpu) 5097 + static int __cpuinit 5098 + migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) 5114 5099 { 5115 - int cpu = (long)hcpu; 5116 5100 struct task_struct *p; 5101 + int cpu = (long)hcpu; 5117 5102 struct runqueue *rq; 5118 5103 unsigned long flags; 5119 5104 ··· 5129 5116 task_rq_unlock(rq, &flags); 5130 5117 cpu_rq(cpu)->migration_thread = p; 5131 5118 break; 5119 + 5132 5120 case CPU_ONLINE: 5133 5121 /* Strictly unneccessary, as first user will wake it. */ 5134 5122 wake_up_process(cpu_rq(cpu)->migration_thread); 5135 5123 break; 5124 + 5136 5125 #ifdef CONFIG_HOTPLUG_CPU 5137 5126 case CPU_UP_CANCELED: 5138 5127 if (!cpu_rq(cpu)->migration_thread) ··· 5145 5130 kthread_stop(cpu_rq(cpu)->migration_thread); 5146 5131 cpu_rq(cpu)->migration_thread = NULL; 5147 5132 break; 5133 + 5148 5134 case CPU_DEAD: 5149 5135 migrate_live_tasks(cpu); 5150 5136 rq = cpu_rq(cpu); ··· 5190 5174 int __init migration_init(void) 5191 5175 { 5192 5176 void *cpu = (void *)(long)smp_processor_id(); 5193 - /* Start one for boot CPU. */ 5177 + 5178 + /* Start one for the boot CPU: */ 5194 5179 migration_call(&migration_notifier, CPU_UP_PREPARE, cpu); 5195 5180 migration_call(&migration_notifier, CPU_ONLINE, cpu); 5196 5181 register_cpu_notifier(&migration_notifier); 5182 + 5197 5183 return 0; 5198 5184 } 5199 5185 #endif ··· 5291 5273 } while (sd); 5292 5274 } 5293 5275 #else 5294 - #define sched_domain_debug(sd, cpu) {} 5276 + # define sched_domain_debug(sd, cpu) do { } while (0) 5295 5277 #endif 5296 5278 5297 5279 static int sd_degenerate(struct sched_domain *sd) ··· 5317 5299 return 1; 5318 5300 } 5319 5301 5320 - static int sd_parent_degenerate(struct sched_domain *sd, 5321 - struct sched_domain *parent) 5302 + static int 5303 + sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) 5322 5304 { 5323 5305 unsigned long cflags = sd->flags, pflags = parent->flags; 5324 5306 ··· 5613 5595 /* 5614 5596 * Measure the cache-cost of one task migration. Returns in units of nsec. 5615 5597 */ 5616 - static unsigned long long measure_one(void *cache, unsigned long size, 5617 - int source, int target) 5598 + static unsigned long long 5599 + measure_one(void *cache, unsigned long size, int source, int target) 5618 5600 { 5619 5601 cpumask_t mask, saved_mask; 5620 5602 unsigned long long t0, t1, t2, t3, cost; ··· 5964 5946 */ 5965 5947 static cpumask_t sched_domain_node_span(int node) 5966 5948 { 5967 - int i; 5968 - cpumask_t span, nodemask; 5969 5949 DECLARE_BITMAP(used_nodes, MAX_NUMNODES); 5950 + cpumask_t span, nodemask; 5951 + int i; 5970 5952 5971 5953 cpus_clear(span); 5972 5954 bitmap_zero(used_nodes, MAX_NUMNODES); ··· 5977 5959 5978 5960 for (i = 1; i < SD_NODES_PER_DOMAIN; i++) { 5979 5961 int next_node = find_next_best_node(node, used_nodes); 5962 + 5980 5963 nodemask = node_to_cpumask(next_node); 5981 5964 cpus_or(span, span, nodemask); 5982 5965 } ··· 5987 5968 #endif 5988 5969 5989 5970 int sched_smt_power_savings = 0, sched_mc_power_savings = 0; 5971 + 5990 5972 /* 5991 - * At the moment, CONFIG_SCHED_SMT is never defined, but leave it in so we 5992 - * can switch it on easily if needed. 5973 + * SMT sched-domains: 5993 5974 */ 5994 5975 #ifdef CONFIG_SCHED_SMT 5995 5976 static DEFINE_PER_CPU(struct sched_domain, cpu_domains); 5996 5977 static struct sched_group sched_group_cpus[NR_CPUS]; 5978 + 5997 5979 static int cpu_to_cpu_group(int cpu) 5998 5980 { 5999 5981 return cpu; 6000 5982 } 6001 5983 #endif 6002 5984 5985 + /* 5986 + * multi-core sched-domains: 5987 + */ 6003 5988 #ifdef CONFIG_SCHED_MC 6004 5989 static DEFINE_PER_CPU(struct sched_domain, core_domains); 6005 5990 static struct sched_group *sched_group_core_bycpu[NR_CPUS]; ··· 6023 6000 6024 6001 static DEFINE_PER_CPU(struct sched_domain, phys_domains); 6025 6002 static struct sched_group *sched_group_phys_bycpu[NR_CPUS]; 6003 + 6026 6004 static int cpu_to_phys_group(int cpu) 6027 6005 { 6028 - #if defined(CONFIG_SCHED_MC) 6006 + #ifdef CONFIG_SCHED_MC 6029 6007 cpumask_t mask = cpu_coregroup_map(cpu); 6030 6008 return first_cpu(mask); 6031 6009 #elif defined(CONFIG_SCHED_SMT) ··· 6572 6548 int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls) 6573 6549 { 6574 6550 int err = 0; 6551 + 6575 6552 #ifdef CONFIG_SCHED_SMT 6576 6553 if (smt_capable()) 6577 6554 err = sysfs_create_file(&cls->kset.kobj, ··· 6592 6567 { 6593 6568 return sprintf(page, "%u\n", sched_mc_power_savings); 6594 6569 } 6595 - static ssize_t sched_mc_power_savings_store(struct sys_device *dev, const char *buf, size_t count) 6570 + static ssize_t sched_mc_power_savings_store(struct sys_device *dev, 6571 + const char *buf, size_t count) 6596 6572 { 6597 6573 return sched_power_savings_store(buf, count, 0); 6598 6574 } ··· 6606 6580 { 6607 6581 return sprintf(page, "%u\n", sched_smt_power_savings); 6608 6582 } 6609 - static ssize_t sched_smt_power_savings_store(struct sys_device *dev, const char *buf, size_t count) 6583 + static ssize_t sched_smt_power_savings_store(struct sys_device *dev, 6584 + const char *buf, size_t count) 6610 6585 { 6611 6586 return sched_power_savings_store(buf, count, 1); 6612 6587 } ··· 6669 6642 { 6670 6643 /* Linker adds these: start and end of __sched functions */ 6671 6644 extern char __sched_text_start[], __sched_text_end[]; 6645 + 6672 6646 return in_lock_functions(addr) || 6673 6647 (addr >= (unsigned long)__sched_text_start 6674 6648 && addr < (unsigned long)__sched_text_end); ··· 6677 6649 6678 6650 void __init sched_init(void) 6679 6651 { 6680 - runqueue_t *rq; 6681 6652 int i, j, k; 6682 6653 6683 6654 for_each_possible_cpu(i) { 6684 6655 prio_array_t *array; 6656 + runqueue_t *rq; 6685 6657 6686 6658 rq = cpu_rq(i); 6687 6659 spin_lock_init(&rq->lock); ··· 6732 6704 #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP 6733 6705 void __might_sleep(char *file, int line) 6734 6706 { 6735 - #if defined(in_atomic) 6707 + #ifdef in_atomic 6736 6708 static unsigned long prev_jiffy; /* ratelimiting */ 6737 6709 6738 6710 if ((in_atomic() || irqs_disabled()) &&