Try   HackMD

2025q1 Homework3 (KXO)

contributed by < devarajabc >

作業書寫規範:

  • 無論標題和內文中,中文和英文字元之間要有空白字元 (對排版和文字搜尋有利)
  • 文字訊息 (尤其是程式執行結果) 請避免用圖片來表示,否則不好搜尋和分類
  • 共筆書寫請考慮到日後協作,避免過多的個人色彩,用詞儘量中性
  • 不要在筆記內加入 [TOC] : 筆記左上方已有 Table of Contents (TOC) 功能,不需要畫蛇添足
  • 不要變更預設的 CSS 也不要加入任何佈景主題: 這是「開發紀錄」,用於評分和接受同儕的檢閱
  • 在筆記中貼入程式碼時,避免非必要的行號,也就是該手動將 c=cpp= 變更為 ccpp。行號只在後續討論明確需要行號時,才要出現,否則維持精簡的展現。可留意「你所不知道的 C 語言: linked list 和非連續記憶體」裡頭程式碼展現的方式
  • HackMD 不是讓你張貼完整程式碼的地方,GitHub 才是!因此你在開發紀錄只該列出關鍵程式碼 (善用 diff 標示),可附上對應 GitHub commit 的超連結,列出程式碼是為了「檢討」和「便於他人參與討論」
  • 留意科技詞彙的使用,請參見「資訊科技詞彙翻譯」及「詞彙對照表
  • 不要濫用 :::info, :::success, :::warning 等標示,儘量用清晰的文字書寫。:::danger 則僅限授課教師作為批注使用
  • 避免過多的中英文混用,已有明確翻譯詞彙者,例如「鏈結串列」(linked list) 和「佇列」(queue),就使用該中文詞彙,英文則留給變數名稱、人名,或者缺乏通用翻譯詞彙的場景
  • 在中文敘述中,使用全形標點符號,例如該用「,」,而非 ","。注意書名號的使用,即 ,非「小於」和「大於」符號
  • 避免使用不必要的 emoji 字元

Introduction to deferred interrupts (Softirq, Tasklets and Workqueues)

Softirqs

  1. The bottom half of the processor -> a common noun referring to all the different ways of organizing deferred processing of an interrupt.

An interrupt handler can do large amount of work that is impermissible as it executes in the context where interrupts are disabled.

為什麼 interrupts are disabled ? 如何做到的?

  1. spawn_ksoftirqd ->

  2. softirq_vec -> An array of softirq_action which contains an action pointer to the softirq function

The local_irq_save saves the state of the IF flag of the eflags register and disables interrupts on the local processor.
The local_irq_restore macro does the opposite thing: restores the interrupt flag and enables interrupts.
We disable interrupts here because a softirq interrupt runs in the interrupt context and that one softirq (and no others) will be run.

  1. 為何要儲存 IF flag
  2. 為何要 disable interrupts ?

The raise_softirq_irqoff function marks the softirq as deffered by setting the bit corresponding to the given index nr in the softirq bit mask (__softirq_pending) of the local processor.

softirq bit mask 是什麼呢?如何運作?

Registration of a softirq with the open_softirq function.
Activation of a softirq by marking it as deferred with the raise_softirq function.
After this, all marked softirqs will be triggered in the next time the Linux kernel schedules a round of executions of deferrable functions.
And execution of the deferred functions that have the same type.

have the same type 是什麼意思? type 是指 softirq_vec 的 index 嗎。

  1. How softirqs run on multiple processors at a time.

  1. possible cpus 是啥

  2. tasklet_trylock 是啥?單一處理器為何需要 lock ? -> pdates state of the given tasklet

  3. WORK_STRUCT_PENDING_BIT 是什麼?

The __queue_work function gets the work pool. Yes, the work pool not workqueue. Actually, all works are not placed in the workqueue, but to the work pool that is represented by the worker_pool structure in the Linux kernel. As you can see above, the workqueue_struct structure has the pwqs field which is list of worker_pools

  1. workqueue_struct structure 是啥
  2. worker_poolsworkqueue_struct structure 的關係是? 跟 pool_workqueue 以及 workqueue 的關係是?

更新以上