Chinaunix首页 | 论坛 | 博客
  • 博客访问: 439606
  • 博文数量: 123
  • 博客积分: 2686
  • 博客等级: 少校
  • 技术积分: 1349
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-23 22:11
文章分类
文章存档

2012年(3)

2011年(10)

2010年(100)

2009年(10)

我的朋友

分类: LINUX

2010-08-28 16:16:09

Kernel:linux-2.6.34

idle_balance is called by schedule() if this_cpu is about to become idle. Attempts to pull tasks from other CPUs.


static void idle_balance(int this_cpu, struct rq *this_rq)
{
    struct sched_domain *sd;
    int pulled_task = 0;
    unsigned long next_balance = jiffies + HZ;

/* store current clock to idle_stamp, indicates that at this moment, this_rq is idle. */
    this_rq->idle_stamp = this_rq->clock;

/* sysctl_sched_migration_cost is migration overhead defined by kernel hack, if this_rq's average idle time less than it, means that after average idle time there will be at least one task executing on this run queue, however, if by migrating tasks, it will take cycles (sysctl_sched_migration_cost). If average idle time is smaller, there is no need to migrate tasks, the best choice is just waiting. */
    if (this_rq->avg_idle < sysctl_sched_migration_cost)
        return;

    /*
     * Drop the rq->lock, but keep IRQ/preempt disabled.
     */

    raw_spin_unlock(&this_rq->lock);


/* #define for_each_domain(cpu, __sd) \
    for (__sd =rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent)

*/

    for_each_domain(this_cpu, sd) {
        unsigned long interval;
        int balance = 1;


/*#ifdef CONFIG_SMP
#define SD_LOAD_BALANCE        0x0001    /* Do load balancing on this domain. */
#define SD_BALANCE_NEWIDLE    0x0002    /* Balance when about to become idle */
#define SD_BALANCE_EXEC        0x0004    /* Balance on exec */
#define SD_BALANCE_FORK        0x0008    /* Balance on fork, clone */
#define SD_BALANCE_WAKE        0x0010  /* Balance on wakeup */
#define SD_WAKE_AFFINE        0x0020    /* Wake task to waking CPU */
#define SD_PREFER_LOCAL        0x0040  /* Prefer to keep tasks local to this domain */
#define SD_SHARE_CPUPOWER    0x0080    /* Domain members share cpu power */
#define SD_POWERSAVINGS_BALANCE    0x0100    /* Balance for power savings */
#define SD_SHARE_PKG_RESOURCES    0x0200    /* Domain members share cpu pkg resources */
#define SD_SERIALIZE        0x0400    /* Only a single load balancing instance */

#define SD_PREFER_SIBLING    0x1000    /* Prefer to place tasks in a sibling domain */

*/


/*Doing load balance working must under the condition of schedule domain set as SD_LOAD_BALANCE, if this schedule domain' flags set as SD_LOAD_BALANCE, it is permitted to do load balance working, otherwise, check the next schedule domain*/

        if (!(sd->flags & SD_LOAD_BALANCE))
            continue;


/*if the type of this schedule domain is SD_BALANCE_NEWIDLE, which means the action of load balance is triggered when this cpu is about to idle. */

/* static int load_balance(int this_cpu, struct rq *this_rq,
            struct sched_domain *sd, enum cpu_idle_type idle,
            int *balance)

 * load balance happens here: this_cpu

 * related run queue: this_rq

 * limited domain: sd

 * idle type of this cpu: idle

 * balance ??

 * Check this_cpu to ensure it is balanced within domain. Attempt to move
 * tasks if there is an imbalance.
 */

        if (sd->flags & SD_BALANCE_NEWIDLE) {
            /* If we've pulled tasks over stop searching: */
            pulled_task = load_balance(this_cpu, this_rq,
                         sd, CPU_NEWLY_IDLE, &balance);
        }


/* calculate this time for next balance */
        interval = msecs_to_jiffies(sd->balance_interval);
        if (time_after(next_balance, sd->last_balance + interval))
            next_balance = sd->last_balance + interval;
        if (pulled_task) {
            this_rq->idle_stamp = 0;
            break;
        }
    }

    raw_spin_lock(&this_rq->lock);

    if (pulled_task || time_after(jiffies, this_rq->next_balance)) {
        /*
         * We are going idle. next_balance may be set based on
         * a busy processor. So reset next_balance.
         */

        this_rq->next_balance = next_balance;
    }
}


阅读(1770) | 评论(2) | 转发(0) |
0

上一篇:schedule()详解

下一篇:load_balance详解

给主人留下些什么吧!~~

chinaunix网友2010-08-30 21:22:26

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com

chinaunix网友2010-08-30 15:25:00

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com