亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 25469 | 回復(fù): 2
打印 上一主題 下一主題

[FreeBSD] freebsd9.2-ULE線程調(diào)度-確定cpu運(yùn)行隊(duì)列負(fù)載最高的cpu-sched_highest函數(shù) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-06-28 16:29 |只看該作者 |倒序?yàn)g覽
本帖最后由 71v5 于 2014-06-29 22:44 編輯

[sched_highest函數(shù)]-確定系統(tǒng)中cpu運(yùn)行隊(duì)列負(fù)載最高的cpu,并返回該cpu的logical cpu id,繼續(xù)以cpu拓?fù)鋱D開始,因?yàn)闄z查cpu負(fù)載
的過程跟cpu拓?fù)鋱D密切相關(guān),這里為了簡(jiǎn)化分析,做下面的假設(shè):
1:cpuset_t類型的大小為1字節(jié),并且bit位以從左到右的順序編號(hào),那么:
   對(duì)于cpu_top中的cg_mask成員,其編碼為11111111, 表示該group中包含的cpu的logical id為0,1,2,3,4,5,6,7。
   對(duì)于group[1]中的cg_mask成員,其編碼為11110000,表示該group中包含的cpu的logical id為0,1,2,3。
   對(duì)于group[2]中的cg_mask成員,其編碼為00001111,表示該group中包含的cpu的logical id為4,5,6,7。

2:因?yàn)椴还苁谴_定負(fù)載最高的cpu還是負(fù)載最低的cpu,最終都是通過函數(shù)cpu_search來操作的,所以在cpu_search函數(shù)中
   略去了一些不相關(guān)的操作,比如檢查負(fù)載最高的cpu時(shí),就略去了和檢查負(fù)載最低的cpu相關(guān)的代碼,略去的代碼以下面
   的"。。。。。。。。。。。。。。。。。。。"標(biāo)識(shí)。
   
3:cpu運(yùn)行隊(duì)列分別為tdq_cpu[0],tdq_cpu[1],tdq_cpu[2],tdq_cpu[3]等




[數(shù)據(jù)類型struct cpu_search]:
  1. /************************************************************************
  2. * struct cpu_search類型的數(shù)據(jù)對(duì)象在函數(shù)cpu_search中使用,用來保存
  3.    查找的結(jié)果。

  4.    cs_mask:一個(gè)cpu掩碼位圖,位圖中設(shè)置為1的bit位對(duì)應(yīng)的cpu將在
  5.             函數(shù)cpu_search中檢查其負(fù)載。
  6.    cs_prefer:在檢查cpu運(yùn)行隊(duì)列負(fù)載最低cpu的時(shí)候使用,一般設(shè)置為
  7.               上一次調(diào)用函數(shù)sched_highest返回的cpu的logical cpu id,當(dāng)所
  8.               檢查的cpu和cs_prefer相同時(shí),將cs_prefer運(yùn)行隊(duì)列的負(fù)載減去
  9.               一個(gè)常數(shù)。
  10.    cs_limit:一個(gè)負(fù)載閾值。
  11.    cs_cpu:cpu運(yùn)行隊(duì)列負(fù)載最低或者最高的cpu對(duì)應(yīng)的logical cpu id。
  12.    cs_load:相應(yīng)的負(fù)載。
  13.    cs_pri:一般情況下,可以忽略。
  14. *********************************/
  15.    577        struct cpu_search {
  16.    578                cpuset_t cs_mask;
  17.    579                u_int        cs_prefer;
  18.    580                int        cs_pri;                /* Min priority for low. */
  19.    581                int        cs_limit;        /* Max load for low, min load for high. */
  20.    582                int        cs_cpu;
  21.    583                int        cs_load;
  22.    584        };
  23. /************************************************************
  24. * 傳遞給cpu_search函數(shù)的標(biāo)志,含義如下:
  25.    CPU_SEARCH_LOWEST:只確定cpu運(yùn)行隊(duì)列負(fù)載最低的cpu。
  26.    CPU_SEARCH_HIGHEST:只確定cpu運(yùn)行隊(duì)列負(fù)載最高的cpu。
  27.    CPU_SEARCH_BOTH:同時(shí)確定cpu運(yùn)行隊(duì)列負(fù)載最高和最低的cpu。
  28. *****************************/
  29.    586        #define        CPU_SEARCH_LOWEST        0x1
  30.    587        #define        CPU_SEARCH_HIGHEST        0x2
  31.    588        #define        CPU_SEARCH_BOTH                (CPU_SEARCH_LOWEST|CPU_SEARCH_HIGHEST)
復(fù)制代碼
[sched_highest函數(shù)]:
  1. /********************************************************************************************
  2. * Find the cpu with the highest load via the highest loaded path.
  3.    一般情況下,在確定系統(tǒng)中cpu運(yùn)行隊(duì)列負(fù)載最高的cpu時(shí),會(huì)以下面的參數(shù)調(diào)用sched_highest函數(shù):
  4.    cg:cpu_top。
  5.    mask:類型為cpuset_t的cpu位圖,這里的編碼為11111111,在隨后從sched_balance_group函數(shù)中
  6.          的for循環(huán)中繼續(xù)調(diào)用sched_highest函數(shù)時(shí),mask的值會(huì)改變,不過mask中bit位為1的cpu
  7.          都要被檢查。
  8.    minload:這里的值為1。

  9.    該函數(shù)實(shí)際上使用參數(shù)mask,minload初始化一個(gè)struct cpu_serach類型的數(shù)據(jù)對(duì)象,
  10.    然后再調(diào)用cpu_search_highest函數(shù),該函數(shù)為函數(shù)cpu_search的簡(jiǎn)單封裝。

  11.    函數(shù)sched_highest返回值如果為-1:在一般情況下,如果返回值為-1,就表示所檢查cpu運(yùn)行隊(duì)列
  12.    中可遷移thread的數(shù)目為0.

  13.    函數(shù)sched_highest返回其它值:相應(yīng)cpu的logical cpu id,該cpu運(yùn)行隊(duì)列中可遷移thread的數(shù)目
  14.    非零,并且負(fù)載最高。
  15. **************************************/
  16.    762        static inline int
  17.    763        sched_highest(const struct cpu_group *cg, cpuset_t mask, int minload)
  18.    764        {
  19.    765                struct cpu_search high;
  20.    766       
  21.    767                high.cs_cpu = -1;
  22.    768                high.cs_mask = mask;
  23.    769                high.cs_limit = minload;
  24.    770                cpu_search_highest(cg, &high);
  25.    771                return high.cs_cpu;
  26.    772        }
  27.    726        int
  28.    727        cpu_search_highest(const struct cpu_group *cg, struct cpu_search *high)
  29.    728        {
  30.    729                return cpu_search(cg, NULL, high, CPU_SEARCH_HIGHEST);
  31.    730        }
復(fù)制代碼
[函數(shù)cpu_search]-該函數(shù)實(shí)際上是一個(gè)遞歸過程,根據(jù)之前的假定,遞歸深度為1,這里分檢查cpu_top和檢查child cpu_group兩種情況來分析該函數(shù),因?yàn)?br /> 這兩種情況cpu_search函數(shù)的執(zhí)行流程不一樣。


[檢查cpu_top-調(diào)用函數(shù)cpu_search]:
  1. /***********************************************************************************************
  2. * 參數(shù)描述:
  3.    cg:cpu_top

  4.    low:NULL。

  5.    high:類型為struct cpu_search的數(shù)據(jù)對(duì)象,各成員如下:
  6.          high.cs_cpu = -1;
  7.          high.cs_mask = mask; // 11111111
  8.          high.cs_limit = minload;// 1

  9.    match:CPU_SEARCH_HIGHEST

  10.    當(dāng)函數(shù)cpu_search返回時(shí),high指向的struct cpu_search對(duì)象中包含了group[1]和group[2]中
  11.    cpu運(yùn)行隊(duì)列負(fù)載最高cpu的logical cpu id和相應(yīng)運(yùn)行隊(duì)列的負(fù)載。

  12.    函數(shù)的返回值為group[2]和group[1]中cpu運(yùn)行隊(duì)列的總負(fù)載。
  13. ******************************************/
  14.    612        static __inline int
  15.    613        cpu_search(const struct cpu_group *cg, struct cpu_search *low,
  16.    614            struct cpu_search *high, const int match)
  17.    615        {
  18. /****************************************************************************
  19. * 局部變量描述:
  20.    lgroup:檢查負(fù)載最低的cpu時(shí)使用。
  21.    hgroup:檢查負(fù)載最低的cpu時(shí)使用
  22.    cpumask:cpu位圖。
  23.    child:指向child cpu_group。
  24.    tdq:指向相應(yīng)cpu的運(yùn)行隊(duì)列。
  25.    cpu:相應(yīng)cpu的logical cpu id。
  26.    i:child cpu_group的數(shù)目。
  27.    hload:cpu的最高負(fù)載。
  28.    load:
  29.    total:總負(fù)載。
  30.    rnd,*rndptr:一個(gè)隨機(jī)數(shù)值,不明白其含義,但是不影響這里的分析,眾會(huì)員
  31.                  知道的話請(qǐng)及時(shí)聯(lián)系啊。
  32. *************************************/
  33.    616                struct cpu_search lgroup;
  34.    617                struct cpu_search hgroup;
  35.    618                cpuset_t cpumask;
  36.    619                struct cpu_group *child;
  37.    620                struct tdq *tdq;
  38.    621                int cpu, i, hload, lload, load, total, rnd, *rndptr;
  39.    622       
  40. /**************************************************************************
  41. * cpumask:此時(shí)的編碼為11111111.
  42.    
  43. *****************/
  44.    623                total = 0;
  45.    624                cpumask = cg->cg_mask;
  46. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  47.    629                if (match & CPU_SEARCH_HIGHEST) {
  48.    630                        hload = INT_MIN;
  49.    631                        hgroup = *high;
  50.    632                }
  51.    633
  52. /***********************************************************************************
  53. * mp_maxid:
  54.    Max CPU ID,初始化時(shí)被設(shè)置為mp_maxid = mp_ncpus - 1;  被初始化為7.

  55.    635-712:之間的for循環(huán)執(zhí)行兩次,每次循環(huán)都檢查一個(gè)child cpu_group。

  56.    第一次for循環(huán):調(diào)用函數(shù)cpu_search檢查group[2]
  57.    i = 2,cpu = 7;
  58.    
  59.    636-643:執(zhí)行else語句,child為&group[2];
  60.    
  61.    649-685:這里將執(zhí)行if語句,即將調(diào)用函數(shù)cpu_search檢查group[2].

  62.    650:group[2]中的cg_mask成員編碼為00001111,CPU_NAND執(zhí)行完后,
  63.         cpumask的編碼為11110000。

  64.    
  65.    第二次for循環(huán):調(diào)用函數(shù)cpu_search檢查group[1].
  66.    i = 1,cpu = 7.

  67.    636-643:執(zhí)行else語句,child為&group[1];
  68.    
  69.    649-685:這里將執(zhí)行if語句,即將調(diào)用函數(shù)cpu_search檢查group[1].

  70.    650:group[1]中的cg_mask成員編碼為11110000,CPU_NAND執(zhí)行完后,
  71.         cpumask的編碼為00000000。   

  72. *************************************************/         
  73.    634                /* Iterate through the child CPU groups and then remaining CPUs. */
  74.    635                for (i = cg->cg_children, cpu = mp_maxid; i >= 0; ) {
  75.    636                        if (i == 0) {
  76.    637                                while (cpu >= 0 && !CPU_ISSET(cpu, &cpumask))
  77.    638                                        cpu--;
  78.    639                                if (cpu < 0)
  79.    640                                        break;
  80.    641                                child = NULL;
  81.    642                        } else
  82.    643                                child = &cg->cg_child[i - 1];
  83.    644       
  84. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  85.    647                        if (match & CPU_SEARCH_HIGHEST)
  86.    648                                hgroup.cs_cpu = -1;
  87.    649                        if (child) {                        /* Handle child CPU group. */
  88.    650                                CPU_NAND(&cpumask, &child->cg_mask);
  89.    651                                switch (match) {
  90. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  91.    655                                case CPU_SEARCH_HIGHEST:
  92.    656                                        load = cpu_search_highest(child, &hgroup);
  93.    657                                        break;
  94. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  95.    661                                }
  96.    662                        } else {                        /* Handle child CPU. */
  97.    663                                tdq = TDQ_CPU(cpu);
  98.    664                                load = tdq->tdq_load * 256;
  99.    665                                rndptr = DPCPU_PTR(randomval);
  100.    666                                rnd = (*rndptr = *rndptr * 69069 + 5) >> 26;
  101. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  102.    678                                if (match & CPU_SEARCH_HIGHEST)
  103.    679                                        if (tdq->tdq_load >= hgroup.cs_limit &&
  104.    680                                            tdq->tdq_transferable &&
  105.    681                                            CPU_ISSET(cpu, &hgroup.cs_mask)) {
  106.    682                                                hgroup.cs_cpu = cpu;
  107.    683                                                hgroup.cs_load = load - rnd;
  108.    684                                        }
  109.    685                        }
  110. /*************************************************************************************************
  111. * cpu_search函數(shù)檢查完group[2]完成后:
  112.   
  113.    686:遞增total。

  114.    698-705:變量high指向的struct cpu_search對(duì)象包含了group[2]中運(yùn)行隊(duì)列負(fù)載最高cpu的
  115.             logical cpu id及其運(yùn)行隊(duì)列的負(fù)載。

  116.    706-711:執(zhí)行if語句前child為&group[2],i = 2,cpumask的編碼為11110000
  117.             執(zhí)行if語句后i = 1。

  118.    此時(shí)進(jìn)行下一次for循環(huán),將調(diào)用函數(shù)cpu_search檢查group[1].


  119.    cpu_search函數(shù)檢查完group[1]完成后:
  120.   
  121.    686:遞增total。

  122.    698-705:變量high指向的struct cpu_search對(duì)象包含了group[1]和group[2]中運(yùn)行隊(duì)列負(fù)載最高cpu的
  123.             logical cpu id及其運(yùn)行隊(duì)列的負(fù)載。

  124.    706-711:執(zhí)行if語句前child為&group[2],i = 1,cpumask的編碼為00000000
  125.             執(zhí)行if語句后i = 0。

  126.    此時(shí)708-709行就直接跳出了for循環(huán)。
  127. ************************************/
  128.    686                        total += load;
  129.    687       
  130. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  131.    698                        if (match & CPU_SEARCH_HIGHEST)
  132.    699                                if (hgroup.cs_cpu >= 0 &&
  133.    700                                    (load > hload ||
  134.    701                                     (load == hload && hgroup.cs_load > high->cs_load))) {
  135.    702                                        hload = load;
  136.    703                                        high->cs_cpu = hgroup.cs_cpu;
  137.    704                                        high->cs_load = hgroup.cs_load;
  138.    705                                }
  139.    706                        if (child) {
  140.    707                                i--;
  141.    708                                if (i == 0 && CPU_EMPTY(&cpumask))
  142.    709                                        break;
  143.    710                        } else
  144.    711                                cpu--;
  145.    712                }
  146.    713                return (total);
  147.    714        }
復(fù)制代碼
[檢查child cpu_group-調(diào)用函數(shù)cpu_search]:
  1. /****************************************************************************
  2. * 檢查group[2]:
  3.    參數(shù)描述:
  4.    cg:&group[2]

  5.    low:NULL。

  6.    high:類型為struct cpu_search的數(shù)據(jù)對(duì)象,各成員如下:
  7.          high.cs_cpu = -1;
  8.          high.cs_mask = mask; // 11111111
  9.          high.cs_limit = minload;// 1

  10.    match:CPU_SEARCH_HIGHEST


  11.    檢查group[1]:
  12.    參數(shù)描述:
  13.    cg:&group[1]

  14.    low:NULL。

  15.    high:類型為struct cpu_search的數(shù)據(jù)對(duì)象,各成員如下:
  16.          high.cs_cpu = -1;
  17.          high.cs_mask = mask; // 11111111
  18.          high.cs_limit = minload;// 1

  19.    match:CPU_SEARCH_HIGHEST

  20.    檢查group[2],當(dāng)函數(shù)cpu_search返回時(shí),high指向的struct cpu_search對(duì)象
  21.    中包含了group[2]中負(fù)載最高cpu的logical cpu id和相應(yīng)運(yùn)行隊(duì)列的負(fù)載。
  22.    函數(shù)的返回值為group[2]中cpu運(yùn)行隊(duì)列的總負(fù)載。


  23.    檢查group[1],當(dāng)函數(shù)cpu_search返回時(shí),high指向的struct cpu_search對(duì)象
  24.    中包含了group[1]中負(fù)載最高cpu的logical cpu id和相應(yīng)運(yùn)行隊(duì)列的負(fù)載。
  25.    函數(shù)的返回值為group[1]中cpu運(yùn)行隊(duì)列的總負(fù)載。
  26. ******************************************/
  27.    612        static __inline int
  28.    613        cpu_search(const struct cpu_group *cg, struct cpu_search *low,
  29.    614            struct cpu_search *high, const int match)
  30.    615        {
  31. /****************************************************************************
  32. * 局部變量描述:
  33.    lgroup:檢查負(fù)載最低的cpu時(shí)使用。
  34.    hgroup:檢查負(fù)載最低的cpu時(shí)使用
  35.    cpumask:cpu位圖。
  36.    child:指向child cpu_group。
  37.    tdq:指向相應(yīng)cpu的運(yùn)行隊(duì)列。
  38.    cpu:相應(yīng)cpu的logical cpu id。
  39.    i:child cpu_group的數(shù)目。
  40.    hload:cpu的最高負(fù)載。
  41.    load:
  42.    total:總負(fù)載。
  43.    rnd,*rndptr:一個(gè)隨機(jī)數(shù)值,不明白其含義,但是不影響這里的分析,眾會(huì)員
  44.                  知道的話請(qǐng)及時(shí)聯(lián)系啊。
  45. *************************************/
  46.    616                struct cpu_search lgroup;
  47.    617                struct cpu_search hgroup;
  48.    618                cpuset_t cpumask;
  49.    619                struct cpu_group *child;
  50.    620                struct tdq *tdq;
  51.    621                int cpu, i, hload, lload, load, total, rnd, *rndptr;
  52.    622       
  53. /**************************************************************************
  54. * 檢查group[2]:
  55.    cpumask:此時(shí)的編碼為00001111.

  56.    檢查group[1]:
  57.    cpumask:此時(shí)的編碼為11110000.   
  58. *******************************************/
  59.    623                total = 0;
  60.    624                cpumask = cg->cg_mask;
  61. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  62.    629                if (match & CPU_SEARCH_HIGHEST) {
  63.    630                        hload = INT_MIN;
  64.    631                        hgroup = *high;
  65.    632                }
  66.    633
  67. /***********************************************************************************
  68. * 檢查group[2]:  
  69.    mp_maxid:
  70.    Max CPU ID,初始化時(shí)被設(shè)置為mp_maxid = mp_ncpus - 1;  被初始化為7.

  71.    635-712:之間的for循環(huán)執(zhí)行四次,檢查child cpu_group,即group[2]中包含的cpu上運(yùn)行
  72.             隊(duì)列的負(fù)載。

  73.    第一次for循環(huán):
  74.    i = 0,cpu = 7
  75.    
  76.    第二次for循環(huán):
  77.    i = 0,cpu = 6

  78.    第三次for循環(huán):
  79.    i = 0,cpu = 5

  80.    第四次for循環(huán):
  81.    i = 0,cpu = 4

  82.    636-643:執(zhí)行if語句,因?yàn)間roup[2]沒有child cpu_group,所以child為NULL。

  83.    637-638:跳過不屬于group[2]中包含的cpu。

  84.    639-640:group[2]中的cpu已檢查完畢,執(zhí)行跳出for循環(huán)的操作。

  85.    649-685:這里將執(zhí)行else語句,檢查相應(yīng)cpu運(yùn)行隊(duì)列的負(fù)載。

  86.    
  87.    檢查group[1]:  
  88.    mp_maxid:
  89.    Max CPU ID,初始化時(shí)被設(shè)置為mp_maxid = mp_ncpus - 1;  被初始化為7.

  90.    635-712:之間的for循環(huán)執(zhí)行四次,檢查child cpu_group,即group[1]中包含的cpu上運(yùn)行
  91.             隊(duì)列的負(fù)載。

  92.    第一次for循環(huán):
  93.    i = 0,cpu = 3
  94.    
  95.    第二次for循環(huán):
  96.    i = 0,cpu = 2

  97.    第三次for循環(huán):
  98.    i = 0,cpu = 1

  99.    第四次for循環(huán):
  100.    i = 0,cpu = 0

  101.    從上面可以看出,每個(gè)cpu_group中的cpu都要被檢查,但是下面678-683之間的宏CPU_ISSET
  102.    會(huì)再次將cpu限制在一個(gè)特定的cpu集合中。

  103.    636-643:執(zhí)行if語句,因?yàn)間roup[1]沒有child cpu_group,所以child為NULL。

  104.    637-638:跳過不屬于group[1]中包含的cpu。

  105.    639-640:group[1]中的cpu已檢查完畢,執(zhí)行跳出for循環(huán)的操作。

  106.    649-685:這里將執(zhí)行else語句,檢查相應(yīng)cpu運(yùn)行隊(duì)列的負(fù)載。
  107.    
  108. *************************************************/         
  109.    634                /* Iterate through the child CPU groups and then remaining CPUs. */
  110.    635                for (i = cg->cg_children, cpu = mp_maxid; i >= 0; ) {
  111.    636                        if (i == 0) {
  112.    637                                while (cpu >= 0 && !CPU_ISSET(cpu, &cpumask))
  113.    638                                        cpu--;
  114.    639                                if (cpu < 0)
  115.    640                                        break;
  116.    641                                child = NULL;
  117.    642                        } else
  118.    643                                child = &cg->cg_child[i - 1];
  119.    644       
  120. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  121.    647                        if (match & CPU_SEARCH_HIGHEST)
  122.    648                                hgroup.cs_cpu = -1;
  123.    649                        if (child) {                        /* Handle child CPU group. */
  124.    650                                CPU_NAND(&cpumask, &child->cg_mask);
  125.    651                                switch (match) {
  126. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  127.    655                                case CPU_SEARCH_HIGHEST:
  128.    656                                        load = cpu_search_highest(child, &hgroup);
  129.    657                                        break;
  130. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  131.    661                                }
  132.    662                        } else {
  133. /**********************************************************************************
  134. * tdq_load:對(duì)應(yīng)cpu運(yùn)行隊(duì)列的負(fù)載,當(dāng)把一個(gè)thread添加到struct tdq中三個(gè)運(yùn)行
  135.              隊(duì)列中的一個(gè)時(shí),就會(huì)遞增tdq_load成員,該成員同時(shí)也用來
  136.              選擇運(yùn)行隊(duì)列負(fù)載最高和最低的CPU。

  137.    tdq_transferable: 一個(gè)計(jì)數(shù)器,相應(yīng)cpu運(yùn)行隊(duì)列中可遷移線程的數(shù)目。在函數(shù)
  138.                      tdq_runq_add中遞增。

  139.    663-684:檢查相應(yīng)cpu運(yùn)行隊(duì)列上的負(fù)載, Handle child CPU.
  140.    
  141.    663:tdq為&tdq_cpu[cpu]。

  142.    665-666:更新一個(gè)每cpu變量randomval。

  143.    678-684:將當(dāng)前檢查cpu運(yùn)行隊(duì)列的負(fù)載即logical cpu id保存到局部變量hgroup中。
  144.             從這里可以看出,上面636-641之間的while循環(huán)將cpu限定在相應(yīng)的cpu_group中
  145.             ,這里的CPU_ISSET宏再次將cpu限制在所要檢查的特定cpu集合中。
  146.             在一般情況下,只有當(dāng)相應(yīng)cpu運(yùn)行隊(duì)列中可遷移的thread數(shù)目非零時(shí),
  147.             變量hgroup中才包含有意義的值。

  148.    686:遞增total。
  149. ***************************************/
  150.    663                                tdq = TDQ_CPU(cpu);
  151.    664                                load = tdq->tdq_load * 256;
  152.    665                                rndptr = DPCPU_PTR(randomval);
  153.    666                                rnd = (*rndptr = *rndptr * 69069 + 5) >> 26;
  154. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  155.    678                                if (match & CPU_SEARCH_HIGHEST)
  156.    679                                        if (tdq->tdq_load >= hgroup.cs_limit &&
  157.    680                                            tdq->tdq_transferable &&
  158.    681                                            CPU_ISSET(cpu, &hgroup.cs_mask)) {
  159.    682                                                hgroup.cs_cpu = cpu;
  160.    683                                                hgroup.cs_load = load - rnd;
  161.    684                                        }
  162.    685                        }
  163.    686                        total += load;
  164.    687       
  165. 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  166. /*********************************************************************************
  167. * 698-705:
  168.    變量high指向的struct cpu_search對(duì)象始終包含的是當(dāng)前cpu_group中運(yùn)行隊(duì)列負(fù)載
  169.    最高cpu的logical cpu id及其運(yùn)行隊(duì)列的負(fù)載。
  170. **********************/
  171.    698                        if (match & CPU_SEARCH_HIGHEST)
  172.    699                                if (hgroup.cs_cpu >= 0 &&
  173.    700                                    (load > hload ||
  174.    701                                     (load == hload && hgroup.cs_load > high->cs_load))) {
  175.    702                                        hload = load;
  176.    703                                        high->cs_cpu = hgroup.cs_cpu;
  177.    704                                        high->cs_load = hgroup.cs_load;
  178.    705                                }
  179. /********************************************************************************
  180. * 706-711:
  181.    這里將執(zhí)行else語句,遞減cpu.
  182. ***********************************/
  183.    706                        if (child) {
  184.    707                                i--;
  185.    708                                if (i == 0 && CPU_EMPTY(&cpumask))
  186.    709                                        break;
  187.    710                        } else
  188.    711                                cpu--;
  189.    712                }
  190.    713                return (total);
  191.    714        }
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2015-04-17 12:42 |只看該作者
太好了!對(duì)樓主贊一個(gè) !。。。。!

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2015-04-28 20:07 |只看該作者
學(xué)習(xí)學(xué)習(xí)!               
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP