<dfn id="is4kg"></dfn>
  • <ul id="is4kg"></ul>
  • <abbr id="is4kg"></abbr>
  • <ul id="is4kg"></ul>
    <bdo id="is4kg"></bdo>

    曙海教育集團論壇Linux專區Linux驅動開發 → Linux驅動開發必看:詳解神秘內核(1)


      共有8992人關注過本帖樹形打印

    主題:Linux驅動開發必看:詳解神秘內核(1)

    美女呀,離線,留言給我吧!
    wangxinxin
      1樓 個性首頁 | 博客 | 信息 | 搜索 | 郵箱 | 主頁 | UC


    加好友 發短信
    等級:青蜂俠 帖子:1393 積分:14038 威望:0 精華:0 注冊:2010-11-12 11:08:23
    Linux驅動開發必看:詳解神秘內核(1)  發帖心情 Post By:2010-11-24 11:27:27

    命令行參數將影響啟動過程中的代碼執行路徑。舉一個例子,假設某命令行參數為bootmode,如果該參數被設置為1,意味著你希望在啟動過程中打印一些調試信息并在啟動結束時切換到runlevel的第3級(初始化進程的啟動信息打印后就會了解runlevel的含義);如果bootmode參數被設置為0,意味著你希望啟動過程相對簡潔,并且設置runlevel為2。既然已經熟悉了init/main.c文件,下面就在該文件中增加如下修改:
    <!--

    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    -->static unsigned int bootmode = 1;
    static int __init
    is_bootmode_setup(
    char *str)
    {
      get_option(
    &str, &bootmode);
      
    return 1;
    }

    /* Handle parameter "bootmode=" */
    __setup(
    "bootmode=", is_bootmode_setup);

    if (bootmode) {
      
    /* Print verbose output */
      
    /* ... */
    }

    /* ... */

    /* If bootmode is 1, choose an init runlevel of 3, else
       switch to a run level of 2
    */
    if (bootmode) {
      argv_init[
    ++args] = "3";
    }
    else {
      argv_init[
    ++args] = "2";
    }

    /* ... */

      請重新編譯內核并嘗試運行新的修改。


      2.1.4 Calibrating delay...1197.46 BogoMIPS (lpj=2394935)

      在啟動過程中,內核會計算處理器在一個jiffy時間內運行一個內部的延遲循環的次數。jiffy的含義是系統定時器2個連續的節拍之間的間隔。正如所料,該計算必須被校準到所用CPU的處理速度。校準的結果被存儲 target=_blank>存儲在稱為loops_per_jiffy的內核變量中。使用loops_per_jiffy的一種情況是某設備驅動程序希望進行小的微秒級別的延遲的時候。

      為了理解延遲—循環校準代碼,讓我們看一下定義于init/calibrate.c文件中的calibrate_ delay()函數。該函數靈活地使用整型運算得到了浮點的精度。如下的代碼片段(有一些注釋)顯示了該函數的開始部分,這部分用于得到一個loops_per_jiffy的粗略值:

    <!--

    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    -->loops_per_jiffy = (1 << 12); /* Initial approximation = 4096 */
    printk(KERN_DEBUG “Calibrating delay loop...“);
    while ((loops_per_jiffy <<= 1) != 0) {
    ticks
    = jiffies;  /* As you will find out in the section, “Kernel
                         Timers," the jiffies variable contains the
                         number of timer ticks since the kernel
                         started, and is incremented in the timer
                         interrupt handler
    */

      
    while (ticks == jiffies); /* Wait until the start of the next jiffy */
      ticks
    = jiffies;
      
    /* Delay */
      __delay(loops_per_jiffy);
      
    /* Did the wait outlast the current jiffy? Continue if it didn't */
      ticks
    = jiffies - ticks;
      
    if (ticks) break;
    }

    loops_per_jiffy
    >>= 1; /* This fixes the most significant bit and is
                              the lower-bound of loops_per_jiffy
    */

      上述代碼首先假定loops_per_jiffy大于4096,這可以轉化為處理器速度大約為每秒100萬條指令,即1 MIPS。接下來,它等待jiffy被刷新(1個新的節拍的開始),并開始運行延遲循環__delay(loops_per_jiffy)。如果這個延遲循環持續了1個jiffy以上,將使用以前的loops_per_jiffy值(將當前值右移1位)修復當前loops_per_jiffy的最高位;否則,該函數繼續通過左移loops_per_jiffy值來探測出其最高位。在內核計算出最高位后,它開始計算低位并微調其精度:

    <!--

    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    -->loopbit = loops_per_jiffy;

    /* Gradually work on the lower-order bits */
    while (lps_precision-- && (loopbit >>= 1)) {
      loops_per_jiffy
    |= loopbit;
      ticks
    = jiffies;
      
    while (ticks == jiffies); /* Wait until the start of the next jiffy */
    ticks
    = jiffies;

      
    /* Delay */
      __delay(loops_per_jiffy);

      
    if (jiffies != ticks)        /* longer than 1 tick */
        loops_per_jiffy
    &= ~loopbit;
    }

      上述代碼計算出了延遲循環跨越jiffy邊界時loops_per_jiffy的低位值。這個被校準的值可被用于獲取BogoMIPS(其實它是一個并非科學的處理器速度指標)。可以使用BogoMIPS作為衡量處理器運行速度的相對尺度。在1.6G Hz 基于Pentium M的筆記本電腦上,根據前述啟動過程的打印信息,循環校準的結果是:loops_per_jiffy的值為2394935。獲得BogoMIPS的方式如下:

    <!--

    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    -->BogoMIPS = loops_per_jiffy * 1秒內的jiffy數*延遲循環消耗的指令數(以百萬為單位)
    = (2394935 * HZ * 2) / (1000000)
    = (2394935 * 250 * 2) / (1000000)
    = 1197.46(與啟動過程打印信息中的值一致)

      在2.4節將更深入闡述jiffy、HZ和loops_per_jiffy。


      2.1.5 Checking HLT instruction

      由于Linux內核支持多種硬件平臺,啟動代碼會檢查體系架構相關的bug。其中一項工作就是驗證停機(HLT)指令。

      x86處理器的HLT指令會將CPU置入一種低功耗睡眠模式,直到下一次硬件中斷發生之前維持不變。當內核想讓CPU進入空閑狀態時(查看arch/x86/kernel/process_32.c文件中定義的cpu_idle()函數),它會使用HLT指令。對于有問題的CPU而言,命令行參數no-hlt可以禁止HLT指令。如果no-hlt被設置,在空閑的時候,內核會進行忙等待而不是通過HLT給CPU降溫。

      當init/main.c中的啟動代碼調用include/asm-your-arch/bugs.h中定義的check_bugs()時,會打印上述信息。


    支持(0中立(0反對(0單帖管理 | 引用 | 回復 回到頂部

    返回版面帖子列表

    Linux驅動開發必看:詳解神秘內核(1)








    簽名
    主站蜘蛛池模板: 欧美国产日韩久久久| 国产一区二区精品久久| 国产激情无码视频在线播放性色 | 乱子伦xxxx| 中美日韩在线网免费毛片视频| 一本到在线观看视频| 97大香伊在人人线色| 蜜桃精品免费久久久久影院| 精品久久久久国产免费| 欧美日韩中文字幕在线| 日韩欧美三级在线| 性欧美高清come| 国产精品毛片一区二区| 国产亚洲欧美日韩精品一区二区| 再深点灬舒服灬太大了添网站| 亚洲精品乱码久久久久久按摩| 亚洲av永久综合在线观看尤物| 中日韩精品视频在线观看| AV无码久久久久久不卡网站 | jizz视频在线观看| 青青青青啪视频在线观看| 男女一进一出猛进式抽搐视频| 欧美三级不卡在线观看| 成在人线av无码免费高潮水| 国内外一级毛片| 国产免费怕怕免费视频观看| 免费a在线观看| 久热这里只有精品视频6| tom影院亚洲国产一区二区| 青青青青青草原| 波多野结衣电影免费在线观看 | 玩弄丰满少妇视频| 日韩亚洲欧美综合一区二区三区| 好男人在线社区www| 国产成人欧美一区二区三区| 免费a级毛片在线观看| 久久午夜国产电影| 91黑丝国产线观看免费| 窝窝午夜看片国产精品人体宴| 最近中文字幕完整国语视频| 天天色综合天天|