Try   HackMD

H09: kecho

tags: linux2020

主講人: jserv / 課程討論區: 2020 年系統軟體課程

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
返回「Linux 核心設計」課程進度表

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
預期目標

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
kecho: 執行在 Linux 核心模式的 TCP 伺服器

取得 kecho 原始程式碼並編譯:

$ git clone https://github.com/sysprog21/kecho
$ cd kecho
$ make

預期會見到以下:

  • 執行檔: benchuser-echo-server
  • 核心模組 kecho.kodrop-tcp-socket.ko

接著可進行測試:

$ make check

參考輸出:

Preparing...
Send message via telnet
Progress : [########################################] 100%
Complete

該操作由以下動作組成:

$ sudo insmod kecho.ko
$ telnet localhost 12345

會出現以下輸出:

Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

可輸入任何字元 (記得按下 Enter),然後就會看到 telnet 回應你剛才輸入的字元。

按下 Ctrl] 組合鍵,之後按下 q,即可離開 telnet 畫面。接著可以試著在 $ telnet localhost 12345 時不要輸入任何字元,只是等待,會看到以下的 kernel 訊息 (可用 $ dmesg 觀察):

                 cope
                 le:	    4404 kB
                 RssShmem:	       0 kB
                 VmData:	     880 kB
                 VmStk:	     132 kB
                 VmExe:	     136 kB
                 VmLib:	    6336 kB
                 VmPTE:	     212 kB
                 VmSwap:	       0 kB
                 HugetlbPages:	       0 kB
                 CoreDumping:	0
                 Threads:	1
                 SigQ:	0/31543

kecho 掛載時可指定 port 號碼: (預設是 port=12345)

$ sudo insmod kecho.ko port=1999

修改或測試 kecho 的過程,可能因為 TIME-WAIT sockets 持續佔用,導致 rmmod 無法成功,這時可透過給定的 drop-tcp-socket 核心模組來剔除特定的 TCP 連線。請詳細閱讀 kecho 以得知必要的設定和準備工作。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
user-echo-server: 執行於使用者層級的 TCP 伺服器

user-echo-serverkecho 的使用者層級的實作,可對照功能和比較效能,運用 epoll 系統呼叫,會傾聽 port 12345。

不管是 user-echo-server 抑或 kecho,都可搭配給定的 bench 程式來分析效能。請詳細閱讀 kecho 以得知必要的設定和準備工作。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
自我檢查清單

  • 給定的 kecho 已使用 CMWQ,請陳述其優勢和用法
  • 核心文件 Concurrency Managed Workqueue (cmwq) 提到 "The original create_*workqueue() functions are deprecated and scheduled for removal",請參閱 Linux 核心的 git log (不要用 Google 搜尋!),揣摩 Linux 核心開發者的考量
  • 解釋 user-echo-server 運作原理,特別是 epoll 系統呼叫的使用
  • 是否理解 bench 原理,能否比較 kechouser-echo-server 表現?佐以製圖
  • 解釋 drop-tcp-socket 核心模組運作原理。TIME-WAIT sockets 又是什麼?

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
作業要求

  • 回答上述「自我檢查清單」的所有問題,需要附上對應的參考資料和必要的程式碼,以第一手材料 (包含自己設計的實驗) 為佳

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
如果你在 2020 年 3 月 30 日前,已從 GitHub sysprog21/kecho 進行 fork,請依據 Alternatives to forking into the same account 一文,對舊的 repository 做對應處置,然後重新 fork

  • 在 GitHub 上 fork kecho,目標是修正 kecho 的執行時期的缺失,提升效能和穩健度 (robustness)
    • 若使用者層級的程式頻繁傳遞過長的字串給 kecho 核心模組,會發生什麼事?
    • 參照 kecho pull request #1,嘗試比較 kthread 為基礎的實作和 CMWQ,指出兩者效能的落差並解釋
    • 如果使用者層級的程式建立與 kecho 核心模組的連線後,就長期等待,會導致什麼問題?
    • 研讀 Linux Applications Performance: Introduction,嘗試將上述實作列入考量,比較多種 TCP 伺服器實作手法的效能表現

繳交方式

編輯 Homework5 作業區共筆,將你的觀察、上述要求的解說、應用場合探討,以及各式效能改善過程,善用 gnuplot 製圖,紀錄於新建立的共筆

截止日期

  • Apr 25, 2020 (含) 之前

越早在 GitHub 上有動態、越早接受 code review,評分越高