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

2012年(3)

2011年(10)

2010年(100)

2009年(10)

我的朋友

分类: LINUX

2010-09-06 11:21:53

KERNEL VERSION: linux-2.6.34
DATA STRUCTURE:
struct sd_lb_stats {
    struct sched_group *busiest; /* Busiest group in this sd */
    struct sched_group *this;  /* Local group in this sd */
    unsigned long total_load;  /* Total load of all groups in sd */
    unsigned long total_pwr;   /*    Total power of all groups in sd */
    unsigned long avg_load;       /* Average load across all groups in sd */

    /** Statistics of this group */
    unsigned long this_load;
    unsigned long this_load_per_task;
    unsigned long this_nr_running;

    /* Statistics of the busiest group */
    unsigned long max_load;
    unsigned long busiest_load_per_task;
    unsigned long busiest_nr_running;
    unsigned long busiest_group_capacity;

    int group_imb; /* Is there imbalance in this sd */
#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
    int power_savings_balance; /* Is powersave balance needed for this sd */
    struct sched_group *group_min; /* Least loaded group in sd */
    struct sched_group *group_leader; /* Group which relieves group_min */
    unsigned long min_load_per_task; /* load_per_task in group_min */
    unsigned long leader_nr_running; /* Nr running of group_leader */
    unsigned long min_nr_running; /* Nr running of group_min */
#endif
};

[load_balance() > find_busiest_group()]

/**
 * find_busiest_group - Returns the busiest group within the sched_domain
 * if there is an imbalance. If there isn't an imbalance, and
 * the user has opted for power-savings, it returns a group whose
 * CPUs can be put to idle by rebalancing those tasks elsewhere, if
 * such a group exists.
 *
 * Also calculates the amount of weighted load which should be moved
 * to restore balance.
 *
 * @sd: The sched_domain whose busiest group is to be returned.
 * @this_cpu: The cpu for which load balancing is currently being performed.
 * @imbalance: Variable which stores amount of weighted load which should
 *        be moved to restore balance/put a group to idle.
 * @idle: The idle status of this_cpu.
 * @sd_idle: The idleness of sd
 * @cpus: The set of CPUs under consideration for load-balancing.
 * @balance: Pointer to a variable indicating if this_cpu
 *    is the appropriate cpu to perform load balancing at this_level.
 *
 * Returns:    - the busiest group if imbalance exists.
 *        - If no imbalance and user has opted for power-savings balance,
 *           return the least loaded group whose CPUs can be
 *           put to idle by rebalancing its tasks onto our group.
 */



static struct sched_group *
find_busiest_group(struct sched_domain *sd, int this_cpu,
         unsigned long *imbalance, enum cpu_idle_type idle,
         int *sd_idle, const struct cpumask *cpus, int *balance)
{


/*struct sd_lb_stats: structures to store statistics of a schedule domain during loadbalancing */
    struct sd_lb_stats sds;

    memset(&sds, 0, sizeof(sds));

    /*
     * Compute the various statistics relavent for load balancing at
     * this level. This function is very important,it update each group in this schedule domain by calling update_sg_lb_stats().
     */

    update_sd_lb_stats(sd, this_cpu, idle, sd_idle, cpus,
                    balance, &sds);

    /* Cases where imbalance does not exist from POV of this_cpu */
    /* 1) this_cpu is not the appropriate cpu to perform load balancing
     * at this level.
     * 2) There is no busy sibling group to pull from.
     * 3) This group is the busiest group.
     * 4) This group is more busy than the avg busieness at this
     * sched_domain.
     * 5) The imbalance is within the specified limit.
     */

    if (!(*balance))
        goto ret;

    if (!sds.busiest || sds.busiest_nr_running == 0)
        goto out_balanced;

    if (sds.this_load >= sds.max_load)
        goto out_balanced;

    sds.avg_load = (SCHED_LOAD_SCALE * sds.total_load) / sds.total_pwr;

    if (sds.this_load >= sds.avg_load)
        goto out_balanced;

    if (100 * sds.max_load <= sd->imbalance_pct * sds.this_load)
        goto out_balanced;

/* Looks like there is an imbalance. Compute it.

Calculate the amount of imbalance present within the
   groups of a given sched_domain during load balance.*/

    calculate_imbalance(&sds, this_cpu, imbalance);


/* Actually, when call update_sd_lb_stats(), the busiest group has been set */
    return sds.busiest;

out_balanced:
    /*
     * There is no obvious imbalance. But check if we can do some balancing
     * to save power.
     */

    if (check_power_save_busiest_group(&sds, this_cpu, imbalance))
        return sds.busiest;
ret:
    *imbalance = 0;
    return NULL;
}


阅读(3251) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

wangm122019-09-19 06:17:58

您这哪是详解啊。。。这只是把源码和注释复制粘贴嘛。。。

wangm122019-09-19 06:17:55

您这哪是详解啊。。。这只是把源码和注释复制粘贴嘛。。。