CPU和device controllers可以平行處理並且爭取memory cycles。為了保證對memory的存取都是按照正確順序,memory controller會負責同步對memory的存取。
一般來說程式都是在rewritable memory也就是main memory中執行,而這種memory一般是用DRAM實作。
但memory controller做的到底是什麼事情?
電腦開機時,由通常是儲存在ROM或EEPROM中的bootstrap program負責initial program to run,這即是所謂的firmware(韌體)。Bootstrap program會找出kernel所在的位置並將其讀入記憶體。
在UNIX中,第一個system process稱作"init",由他去執行其他的daemons。System processes或system daemons會和kernel同時運作。
不論是軟體或硬體都可以產生interrupt。硬體通常通過system bus送出signal給CPU來達成,軟體則透過呼叫system call(或monitor call)的方式產生interrupt。
當interrupt發生時,CPU通常會跳到固定的interrupt service routine(ISR,又稱為interrupt handler)的位址去執行,當執行完畢後CPU回去繼續執行被中斷前未完成的計算。
Interrupt是電腦系統中重要的一環,雖然每種系統實現的方式不太一樣,但某些功能是共通的。Interrupt發生後,必須要把control交給正確的interrupt service routine,這可以透過多種方式來實現。因為interrupt的種類數量不多,可以將interrupt service routine的位址記錄在interrupt vector中,它就像是一個pointer的table。
Interrupt當然也需要儲存被中斷的位址,在較新的設計中,這位址被儲存在system stack中。
一般來說程式都是在rewritable memory也就是main memory中執行,而這種memory一般是用DRAM實作。
透過load和store指令,CPU的register可以和main memory互相存取(也就是計算機組織的內容!)
CPU和device controllers一般透過common bus來連結,一個device controller可以連結超過一種裝置,舉例來說,small computer-systems interface(SCSI)可以連結七種以上的裝置。
Device controller由local buffer storage和一些register所組成。而OS則是透過device driver和device controller溝通。
當I/O發生時,device driver先寫入device controller中對應的register,而controller則是讀取register中的值來判斷要進行何種命令(例如說"從鍵盤讀取一個字元"),接著controller把資料從device傳送到local buffer,當傳送完成時,controller透過interrupt通知driver,driver再將control交還給OS。
以上所述的interrupt-drive I/O可用來傳送小量資料,但若是大量(bulk data)的movement例如說disk I/O,就會產生很高的overhead。
這時就改用direct memory access(DMA),只要先指定buffer、pointer、counter(?)給I/O device,接著就將整個block of data直接從buffer storage和memory之間傳輸。相比於少量傳輸的裝置來說,傳輸一整個block只需要一次interrupt,而非每個byte都要一次,且CPU可在這同時完成其他工作。
CPU對device發出I/O request,device則對CPU發出interrput,兩者之間並互相傳送資料。
CPU和device controllers一般透過common bus來連結,一個device controller可以連結超過一種裝置,舉例來說,small computer-systems interface(SCSI)可以連結七種以上的裝置。
Device controller由local buffer storage和一些register所組成。而OS則是透過device driver和device controller溝通。
當I/O發生時,device driver先寫入device controller中對應的register,而controller則是讀取register中的值來判斷要進行何種命令(例如說"從鍵盤讀取一個字元"),接著controller把資料從device傳送到local buffer,當傳送完成時,controller透過interrupt通知driver,driver再將control交還給OS。
以上所述的interrupt-drive I/O可用來傳送小量資料,但若是大量(bulk data)的movement例如說disk I/O,就會產生很高的overhead。
這時就改用direct memory access(DMA),只要先指定buffer、pointer、counter(?)給I/O device,接著就將整個block of data直接從buffer storage和memory之間傳輸。相比於少量傳輸的裝置來說,傳輸一整個block只需要一次interrupt,而非每個byte都要一次,且CPU可在這同時完成其他工作。
CPU對device發出I/O request,device則對CPU發出interrput,兩者之間並互相傳送資料。
留言
張貼留言