jollen.org

Jollen 的 Blog
Jollen's email: jollen # jollen.org
more:  Jollen's Training

Linux 驅動程式的中斷處理, #3: Bottom Half 的觀念

.作者:jollen/
.日期:March 3, 2008 11:36 PM


為了能寫出很棒的 interrupt handle,Linux 採用一種稱為 bottom half 的觀念來實作 interrupt handler。

bottom_half.PNG

Linux 將完整的 interrupt handler 切成2個部份(half):top half 與 bottom half。Top half 是在呼叫 request_irq() 時所指定的 interrupt handler 函數,bottom half 則是由 top half 所排程(scheduling),真正負責回應中斷的 task。

一般來說,top half 的基本實作原則如下:

1. 儲存裝置相關資料,這個部份會涉及「中斷不同步」的議題,在這裡先不做解釋。
2. 將 bottom half 排程後結束執行。

Top half 是真正接受中斷請求的 task,因此應避免執行過久。由 top half 的實作原則可以看出,top half 真正要做的工作其實只有排程 bottom half,因此執行的速度將會非常快。Top half 與 bottom half 的最大差別為,bottom half 在執行時,interrupt 是開啟的,因此 CPU 仍然可以接受中斷請求。

由此也可以看出另外一個 bottom half 機制的特點:當 bottom half 尚未結束執行時,top half 仍然可以處理中斷請求。另外,bottom half 就是 interrupt handler,因此「也視為」在 interrupt mode 下執行。

Tags:

純手工打造說明:技術專欄文章為 Jollen 原創,內容皆為人工撰寫,無 AI 生成。轉載請註明出處與作者,並全文引用。轉載時請在文章開頭或結尾明顯處註明「本文出處:https://www.jollen.org,已取得原作者同意並授權使用。」
訂閱電子報:不定期 Jollen's Blog 精選文章隨 Moko365 電子報寄送;請透過 Moko365 電子報訂閱(可隨時取消)。

Copyright(c) 2001–2008 www.jollen.org. All rights reserved.
Last update: 2026-07-22