EricccTaiwan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # fb_0413 :::success 可以搭配參考 [2025-04-15 問答簡記](https://hackmd.io/V7bD2XjnQuCZqDMt4ZizGA#EricccTaiwan) ::: > 目前的主要參考資料 〈[Linux Kernel Development](https://www.doc-developpement-durable.org/file/Projets-informatiques/cours-&-manuels-informatiques/Linux/Linux%20Kernel%20Development,%203rd%20Edition.pdf)〉v2.6 (許多 API 已過時) 和 [Interrupts and Interrupt Handling](https://0xax.gitbooks.io/linux-insides/content/Interrupts/) 近日我與帥潮繼寬同學一同討論 Linux2025 核心實作第三份作業(kxo),在理解程式碼的過程中遇到不少疑問,查閱資料後仍有許多不解之處。在老師的建議下,發文向各位大神與同學們請益,相關問題整理如下,並附上連結供參考,謝謝大家! 1. top 與 bottom 的差異是否僅在於「是否屏蔽其他中斷」? 還是 top 和 bot half 是一種「功能導向」的概念性區分(僅是一種抽象的概念)? > 原本以為是透過「是否會屏蔽中斷」來區分 top half 和 bottom half,例如 top half 會屏蔽 (Hard IRQ)、bottom half 則不會。不過在閱讀 tasklet_action() 的時候注意到它其實也會使用 local_irq_save() 去關中斷 (繼寬發現的),而根據 〈LKMPG〉 與 〈Linux Kernel Development〉 兩本書,tasklet 又明確被歸類為 bottom half 的一種。 這樣一來,是否就推翻了「以是否屏蔽中斷」作為 top/bottom 劃分依據的說法? 另外我在這兩本書中也沒有找到關於 top/bottom half 劃分的明確定義 2. 若 top half 與 bottom half 並非僅為抽象概念,在 top half 與 bottom half 各自內部,是否還能依照具體功能再細分出自己的「top / bottom」結構呢? 3. 討論如何區分兩者(top / bottom half)是否有意義? 4. tasklet 和 workqueue 的具體差異為何? 它們在 interrupt context 中的角色與行為如何區分? 5. 如何判斷目前執行環境是否處於 interrupt context? 是透過下方的 MARCO 嘛? [include/linux/preempt.h](https://elixir.bootlin.com/linux/v6.13.7/source/include/linux/preempt.h#L141) ```c /* * The following macros are deprecated and should not be used in new code: * in_irq() - Obsolete version of in_hardirq() * in_softirq() - We have BH disabled, or are processing softirqs * in_interrupt() - We're in NMI,IRQ,SoftIRQ context or have BH disabled */ #define in_irq() (hardirq_count()) #define in_softirq() (softirq_count()) #define in_interrupt() (irq_count()) ``` 6. Interrupt context 與 process context 有哪些具體差異?為何在設計上需要明確區分這兩者? 書中提到 interrupt handler 執行時的場景就稱為 Interrupt context ,程式處於該場景無法進入 sleeping state, 但為何要這樣? 此外書中強調 Interrupt context 又稱 Atomic context, 在 workqueue 與 tasklet 的比較中也能看到 tasklet 相較與 workqueue 具有 atomic 的特性: >This means that workqueue functions must not be atomic as tasklet functions. "Atomic" 在中斷處理中的意義為何? # 已經解決 0. 在閱讀 [Interrupts and Interrupt Handling. Part 9.](https://0xax.gitbooks.io/linux-insides/content/Interrupts/linux-interrupts-9.html) 時,不理解為什麼會說把 tasklets 存放在 `tasklet_vec` 和 `tasklet_hi_vec` 的 "Array" 中,這兩者的資料結構不應該是鏈結串列? > Tasklets and high-priority tasklets are stored in the `tasklet_vec` and `tasklet_hi_vec` arrays, respectively 經過**帥潮繼寬**的查證,`tasklet_vec` 和 `tasklet_hi_vec` 都是鏈結串列(It's the head of the linked list in fact),目前也以著手提交 patch 修正! [Fix incorrect description of tasklet #861](https://github.com/0xAX/linux-insides/pull/861),已被 merge ,恨帥潮。 0. 乘上,透過 `tasklet_vec.tail` 推斷 `tasklet_vec` 是鏈結串列,但卻找不到此結構體的定義 該段落末段提到: >These two per-cpu variables defined in the same source code file as the softirq_init function and represent two `tasklet_head` structures. 因此該變數的結構應該是 `struct tasklet_head` 沒錯 ```c struct tasklet_head { struct tasklet_struct *head; struct tasklet_struct **tail; }; ``` 但問題來了,要如何儲存 tasklets ? -> 就是個平凡的 linked list, 但我不知道為何要儲存「指向最後一個元素」的指標? 只有 head 會怎樣? ```c struct tasklet_struct { struct tasklet_struct *next; unsigned long state; atomic_t count; void (*func)(unsigned long); unsigned long data; }; ``` 所以 tasklet_struct 的 \*func 會用來除存 handler 的指標 --- ~~0414: 謝謝仁廷學長的回覆,我禮拜一晚上前會看完並回覆,謝謝!~~

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully