分享到plurk 分享到twitter 分享到facebook

版本 047ed7a408391fd4f341e0b7d816ebaa69ff2299

Lab40: Scheduling (2015q1 Week #4)

預期目標

  • 分析 FreeRTOS</embedded/freertos>_ 排程行為
  • 學習 ARM Cortex-M3 架構並且理解 SysTick<http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s08.html>_
  • 設計出一個具體而微的 FreeRTOS 視覺化機制

Grasp

.. image:: /embedded/Lab40/grasp-n-os.png - Understanding and validating the timing behavior of real-time systems is not trivial. - Many real-time operating systems and their development environments do not provide tracing support, and provide only limited visualization, measurements and analysis tools. - Grasp<http://www.win.tue.nl/san/grasp/>_ is a tool for tracing, visualizing and measuring the behavior of real-time systems. It provides a simple plugin infrastructure for extending Grasp with custom visualization and measurement methods.

  • mutex 視覺化輸出

.. image:: /embedded/Lab12/mutex.png

  • RTOS scheduling 視覺化輸出

.. image:: /embedded/Lab12/hsf.png

Grasp 安裝

  • 抓取預先編譯的程式碼 (x86/linux): 假設和 Lab-39</embedded/Lab39>_ 的工作目錄一樣是 workspace

.. code-block:: prettyprint

sudo apt-get install zip
wget http://www.win.tue.nl/san/grasp/grasp_linux.zip
unzip grasp_linux.zip
  • 如果你的系統是 x86_64,需要額外安裝以下套件才能執行 Grasp

.. code-block:: prettyprint

sudo apt-get install libxft2:i386 libxss1:i386
  • 執行 Grasp、點選 examples 目錄並且挑選副檔名為 .grasp 的檔案,之後觀察視覺化輸出

.. image:: /embedded/Lab40/grasp.png

取得 Visualizer 並測試

  • Visualizer 需要 GDB,所以需要事先準備好

.. code-block:: prettyprint

sudo apt-get install gdb-arm-none-eabi
  • 假設 Lab-39</embedded/Lab39>_ 的 freertos-basicqemu_stm32 都放在 workspace 目錄
    • cd worksapce
  • 取得原始程式碼並且執行

.. code-block:: prettyprint

git clone git://github.com:embedded2015/visualizer.git || git clone https://github.com/embedded2015/visualizer.git
cd visualizer
make qemuauto
  • 可以見到 idle task 和相關圖例
  • 運作原理
    • 讀取 SysTick<http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s08.html>_ 中 current & reload 的數值,用來計算更精確的時間單位
    • 增加追蹤執行狀態的 break point,藉以了解程式目前運作的位置
      • 增加程式 context switch 的 Hook
      • 將程式在 idle 時的 function 也列入追蹤

參考作業要求

  • 改寫 main.c 並且引入兩個週期性 Task,使其得以使用 CPU 資源,並且讓 grasp 予以視覺化
  • 試著用程式碼自動計算出 context switch 的時間成本

挑戰題

  • 自動測試 USART</embedded/USART>_ 的中斷處理 (對應於 USART2_IRQHandler),並且透過 grasp 視覺化

繳交作業

  • 截止日期:
    • Mar 28, 2015 (含) 之前
  • 更新開發過程到共筆網站: Lab 40 / 作業共筆<https://embedded2015.hackpad.com/2015q3-Week-4-Lab40>_,需要標注自己的 ID
    • 將符合作業提案的程式碼,提交到自行 fork 的 repository: https://github.com/embedded2015/visualizer
    • 注意: 要記得 fork visualizer<https://github.com/embedded2015/visualizer>_

參考資料

  • Grasp: Tracing, Visualizing and Measuring the Behavior of Real-Time Systems<http://www.win.tue.nl/~mholende/publications/Holenderski2010.pdf>_
  • RTOS Visualization</embedded/Sol12>_
  • RTOS context switch</embedded/Sol8>_
  • Context switching time<https://www.segger.com/embos-context-switching-time.html>_