Index: MM-2.6.16/kernel/sched_spa_ws.c =================================================================== --- MM-2.6.16.orig/kernel/sched_spa_ws.c 2006-01-21 16:42:45.000000000 +1100 +++ MM-2.6.16/kernel/sched_spa_ws.c 2006-01-23 11:42:32.000000000 +1100 @@ -44,7 +44,8 @@ static unsigned int initial_ia_bonus = D #define LSHARES_AVG_OFFSET 7 #define LSHARES_AVG_ALPHA ((1 << LSHARES_AVG_OFFSET) - 2) #define LSHARES_AVG_INCR(a) ((a) << 1) -#define LSHARES_AVG_ONE (1UL << LSHARES_AVG_OFFSET) +#define LSHARES_AVG_REAL(s) ((s) << LSHARES_AVG_OFFSET) +#define LSHARES_AVG_ONE LSAHRES_AVG_REAL(1UL) #define LSHARES_AVG_MUL(a, b) (((a) * (b)) >> LSHARES_AVG_OFFSET) static unsigned int max_fairness_bonus = DEF_MAX_FAIRNESS_BONUS; @@ -121,32 +122,9 @@ static inline void zero_interactive_bonu p->sdu.spa.interactive_bonus = 0; } -static inline int current_fairness_bonus(const struct task_struct *p) -{ - return p->sdu.spa.auxilary_bonus >> FAIRNESS_BONUS_OFFSET; -} - -static inline int current_fairness_bonus_rnd(const struct task_struct *p) -{ - return (p->sdu.spa.auxilary_bonus + (1UL << (FAIRNESS_BONUS_OFFSET - 1))) - >> FAIRNESS_BONUS_OFFSET; -} - -static inline void decr_fairness_bonus(struct task_struct *p) -{ - p->sdu.spa.auxilary_bonus *= ((1UL << FAIRNESS_BONUS_OFFSET) - 2); - p->sdu.spa.auxilary_bonus >>= FAIRNESS_BONUS_OFFSET; -} - -static inline void incr_fairness_bonus(struct task_struct *p) -{ - decr_fairness_bonus(p); - p->sdu.spa.auxilary_bonus += (max_fairness_bonus << 1); -} - static inline int bonuses(const struct task_struct *p) { - return current_ia_bonus_rnd(p) + current_fairness_bonus_rnd(p); + return current_ia_bonus_rnd(p) + p->sdu.spa.auxilary_bonus; } static int spa_ws_effective_prio(const struct task_struct *p) @@ -211,43 +189,36 @@ static inline unsigned int map_ratio(uns static void spa_ws_reassess_fairness_bonus(struct task_struct *p) { - unsigned long long expected_delay; + unsigned long long expected_delay, adjusted_delay; unsigned long long avg_lshares; + unsigned long pshares = LSHARES_AVG_REAL(p->sdu.spa.eb_shares); -#if 0 p->sdu.spa.auxilary_bonus = 0; if (max_fairness_bonus == 0) return; -#endif avg_lshares = per_cpu(rq_avg_lshares, task_cpu(p)); - if (avg_lshares <= p->sdu.spa.eb_shares) + if (avg_lshares <= pshares) expected_delay = 0; else { expected_delay = LSHARES_AVG_MUL(p->sdu.spa.avg_cpu_per_cycle, - (avg_lshares - p->sdu.spa.eb_shares)); - (void)do_div(expected_delay, p->sdu.spa.eb_shares); + (avg_lshares - pshares)); + (void)do_div(expected_delay, pshares); } -#if 1 - if (p->sdu.spa.avg_delay_per_cycle > expected_delay) - incr_fairness_bonus(p); - else - decr_fairness_bonus(p); -#else + /* * No delay means no bonus, but * NB this test also avoids a possible divide by zero error if * cpu is also zero and negative bonuses */ - lhs = p->sdu.spa.avg_delay_per_cycle; - if (lhs <= rhs) + if (p->sdu.spa.avg_delay_per_cycle <= expected_delay) return; - lhs -= rhs; + adjusted_delay = p->sdu.spa.avg_delay_per_cycle - expected_delay; p->sdu.spa.auxilary_bonus = - map_ratio(lhs, lhs + p->sdu.spa.avg_cpu_per_cycle, + map_ratio(adjusted_delay, + adjusted_delay + p->sdu.spa.avg_cpu_per_cycle, max_fairness_bonus); -#endif } static inline int spa_ws_eligible(struct task_struct *p) @@ -255,6 +226,15 @@ static inline int spa_ws_eligible(struct return p->sdu.spa.avg_sleep_per_cycle < WS_BIG_SLEEP; } +static inline int spa_sleepiness_exceeds_ppt(const struct task_struct *p, + unsigned int ppt) +{ + return RATIO_EXCEEDS_PPT(p->sdu.spa.avg_sleep_per_cycle, + p->sdu.spa.avg_sleep_per_cycle + + p->sdu.spa.avg_cpu_per_cycle, + ppt); +} + static void spa_ws_reassess_at_activation(struct task_struct *p) { spa_ws_reassess_fairness_bonus(p); @@ -264,7 +244,7 @@ static void spa_ws_reassess_at_activatio else partial_incr_interactive_bonus(p); } - else if (!spa_ia_sleepiness_exceeds_ppt(p, iab_decr_threshold)) + else if (!spa_sleepiness_exceeds_ppt(p, iab_decr_threshold)) decr_interactive_bonus(p); else if (!spa_ia_sleepiness_exceeds_ppt(p, (iab_decr_threshold + iab_incr_threshold) / 2)) partial_decr_interactive_bonus(p); @@ -284,7 +264,7 @@ static void spa_ws_reassess_at_end_of_ts /* Don't punish tasks that have done a lot of sleeping for the * occasional run of short sleeps unless they become a cpu hog. */ - if (!spa_ia_sleepiness_exceeds_ppt(p, iab_decr_threshold)) + if (!spa_sleepiness_exceeds_ppt(p, iab_decr_threshold)) decr_interactive_bonus(p); else if (!spa_ia_sleepiness_exceeds_ppt(p, (iab_decr_threshold + iab_incr_threshold) / 2)) partial_decr_interactive_bonus(p);