




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、iilifEcrucjt- eg - e l d keiltu-1eceasel-e-aea-agsi-jtsaer er-iitrtve -aee- e a- a srliaeaittu-ayi-yesfet- -r .ties - te. .t> i.、 lxii-eescsc-u-ee c i i s cl- c - ye st -1- cte ai vete i . ftve Bakte s kigegvt -i tPk - - dr y dvr f5 - - ie d riis Hgl.itgg.yei1ad dvr eg-e. eei1ad-cda-e.fiiesls-oea
2、sc- c d a g a v g 1s-e iise-n-ss-We-eesairurr-1 ad-s a .e- si- i-ee iesiss a.l ae iigge Ig esTf-eeu-adadi-i Ia.n-i asi-.*.a i ki v fiiy - -1cs-ay el r .-c-ccc-ligul- g- -s - -g r-cksi"dlgysi-edu-gkes -g - ru ali-c-Wlc rk eilsi-adec- c-eig- r-l sg - sl-a.-i i-a-i- -sl sc-sld-cieiiauesa.ria-y - l
3、il id g l - g - c - - p e-l ace -i-> - a- - - 一- - lrs - -e-c-l au -eig i i s -ig esacigrc - s e-elsg u-a- ade as - i-e-esu-c- -dc-.-.-eg-eeeseaesl-e l s -gieeie.-clevc-erdf-一個IO的傳奇一生前言前幾天同事提議寫一篇文章來仔細(xì)分析一下一個IO從創(chuàng)建到消亡的整個過程,我覺得這個想法很好,一個IO從創(chuàng)建到消亡經(jīng)歷了千山萬水,從軟件到硬件涉及到很多很多的技 術(shù)。一個看似簡單的IO讀寫操作,其實(shí)匯集了從計算機(jī)軟件技術(shù)、硬件技
4、術(shù)、電子技術(shù)、 信號處理等各個方面的內(nèi)容。所以,我想把 IO的一生通過自己的認(rèn)識把他描述一下,讓世 人看清在執(zhí)行一個簡單的IO操作究竟匯集了多少的智慧!匯集了工程師、科學(xué)家多少的心血!在此,將此系列文章定名為一個IO的傳奇一生,與大家一起分享。針對不同的操作系統(tǒng),IO歷程是有所差別的,但是很多基本思想是相同的。在此,我 想以Linux操作系統(tǒng)為樣本,對整個IO歷程進(jìn)行深入分析,最主要的是設(shè)計思想方面的考慮。 cl- c - ye st -a(c cte a-veste-. fctvBakte s -.e-g vt-r - tPk - - s dvf5- ie d r-is -”.ei1ad .
5、e-e- t- a u - a*.-.-.1 -.1-gy -P .-.-.e -.- a- a 一一- - -.- - -gv-s I-. c - e al.u.上圖描述了 IO操作中所涉及到的軟硬件模塊,從這張圖中我們可以一窺整個系統(tǒng)還是很龐大的,主要涉及了文件系統(tǒng)、塊設(shè)備層、SCSI層、PCI層、SAS/Ethernet網(wǎng)絡(luò)以及磁盤/U盤。本文會根據(jù)彳者的理解對IO在上述各個層次的游歷過程進(jìn)行詳細(xì)闡述。文件基本操作如果你想保存你的 Word資料至本地硬盤,你就會觸發(fā)一個文件系統(tǒng)寫操作。如果你想 將一個文件從本地電腦拷貝到U盤時,你會觸發(fā)一次文件系統(tǒng)的讀寫過程。大家知道,為primaryf
6、irst-hand an i nadequate graspofthe problem,which i s to be strengthe ne d in thefut ure.Se cond, constructi on, strictlyina ccorda nce wit h the provisi onstostreamlinea nd im provethe quality of meetings ofthe Conference.Thir d,streamlini ng file briefs, culture involves al laspe cts ofpropagandaa
7、 ndideol og y,sometimes duetothe practical ne eds of inventi on notifications,t his area needs furtherSince thee ducational practi ceofthe mass li neofthe party, himselfseri ously i n thee ducation, pra ctical controlce ntral"n astnadtirounrealdicnoanrsetructioansldaenddiicnactreeasde taocoordi
8、nnadtidencgreandasseo,lvrienplgapcerombelnetmisndaicatssocoirastefdorwpitrihoribtuysaireansespsresinojtecht.iCshsearges,citnotr.Whenthoetrheearpersoujebscttasntoifalwiater,electrissues,csiteyc,taorledminaisdterrastiavreracngheardgteosapenrsdopnraelferelyintnetriavlepnoel,iicnie-sp.eInrthseoan,reian-
9、persofotnaxation,paunsdhtsaenttglieble aread inbarueiladingsaogfrienedustrnyliaght,nedaitssyliprnode.uTcotiofunrcthoemrrepadnuyc,ewiatnhdistandnar5dyiears aftezretahdemieightrule s"and opposing "the four winds" andpracti cing"three S uns",and checkthe spirit ofJiaoYulu,ide o
10、logy,sol icitopini ons ba sed on outstanding problems che cked sw ing, careful a nalysi s andr eflection. Will nowcheckre portis asfollow s: first,adhere ncetot heparty's politicaldiscipline,eighti n thencecentral pr ovisi on, chadisciplinesg.Conscientiouslyanmentcre dit+ busibide bythe party
11、9;s politicaldiscipline, abi de by t heConstit ution andthe rulesand regulationa nd moder nization of thei nvestmenta nd fina nci ngplatform;effectiveons of the party, i n the political, ide ologi cala ndmaintai n hig hlyconsi stent withtBank -enter prise docking, encourage s private ca pital int ot
12、he Park ,toraise i ndustrydevel opme ntfund.5, optimizethe environmenta nd servicei ndustrie s.Tocreate "policyl owla nds, Highla nds,integrity ofservi ce la nd, devel opment la nd" ast hegoal,t ooptimizeCPC Central Committeeonthe action,t here is no violati on oftheparty's politi cald
13、i sci pline problems. 2,inthe implementation ofthece ntralauthor itiesoftheeig ht provi sions.Impr oving re search,improvi ng resear chmethods,butthere arelessgrass-roots units,了簡化用戶對文件的管理,操作系統(tǒng)提供了文件系統(tǒng)對數(shù)據(jù)資料進(jìn)行了管理,文件系統(tǒng)是操作系統(tǒng)最為重要的組成部分。一旦你想往文件系統(tǒng)寫入數(shù)據(jù)時,一個新的IO 請求就會在用戶態(tài)誕生,但是,其絕大部分的人生旅程都會在內(nèi)核空間。對于不同的應(yīng)用類型,IO 請求的
14、屬性會大相徑庭。除了文件本身應(yīng)該具備的基本屬性(讀寫權(quán)限等)之外, 我們還需要考慮文件的訪問模式:異步 IO還是同步IO?對文件系統(tǒng)的 Cache是如何控制的?應(yīng)用程序和內(nèi)核程序之間是如何交互的?所以,在創(chuàng)建一個 IO時,我們需要考慮很多這樣的因素。我們知道,當(dāng)我們需要進(jìn)行文件操作的時候,5 個 API 函數(shù)是必不可少的。Create, Open,Close, Write 和 Read 函數(shù)實(shí)現(xiàn)了對文件的所有操作。Create 函數(shù)用來打開一個文件,如果該文件不存在,那么需要在磁盤上創(chuàng)建該文件。Open 函數(shù)用于打開一個指定的文件。如果在Open函數(shù)中指定 O_CREAT麻記,那么Open函數(shù)
15、同樣可以實(shí)現(xiàn) Create函數(shù)的功能。Close 函數(shù)用于釋放文件句柄。Write和Read函數(shù)用于實(shí)現(xiàn)文件的讀寫過程。舉個例子,如果用戶 需要對一個文件進(jìn)行寫操作,那么首先調(diào)用Open 函數(shù)打開想要操作的文件,函數(shù)完成之后獲取所要操作文件的句柄;然后調(diào)用Write 函數(shù)將數(shù)據(jù)寫入文件;最后采用Close 函數(shù)釋放文件句柄,結(jié)束文件寫入過程。上述過程大家應(yīng)該都非常的熟悉,在上述過程中,整個系統(tǒng)到底發(fā)生了哪些操作呢?打開文件眾所周知,用戶態(tài)的API 函數(shù)通過系統(tǒng)調(diào)用陷入內(nèi)核。對于Open 函數(shù)對應(yīng)了sys_open函數(shù)例程。該函數(shù)的主要職責(zé)是查找指定文件的inode , 然后在內(nèi)核中生成對應(yīng)的文
16、件對象。在 Linux 中, Sys_open 函數(shù)調(diào)用do_sys_open 完成具體功能。在do_sys_open 中通過do_filp_open 函數(shù)完成文件名解析、inode 對象查找,然后創(chuàng)建file 對象, 最后執(zhí)行特定文件對應(yīng)的 file->open 函數(shù)。 Do_filp_open 過程中的核心處理函數(shù)是link_path_walk 。 該函數(shù)完成了基本的文件路徑的解析功能,是名字字符串解析處理實(shí)現(xiàn)的核心。該函數(shù)的實(shí)現(xiàn)基于分級解析處理的思想。例如,當(dāng)需要解析“/dev/mapper/map0 ”字符串時,其首先需要判斷從何處開始解析,根目錄還是當(dāng)前目錄?這個例子是從根目錄
17、開始解析的,那么首先獲取根目錄的 dentry 對象并開始分析后繼字符串。處理過程是以/ 字符為界按序提取字符串。根據(jù)規(guī)則,首先我們可以提取“ dev”字符串,并且計算該字符串的 Hash值,通過該Hash值 查找dentry下的inode Hash表,就可以很快的找到 /dev/目錄下的inode對象。Hash值的計 算是比較簡單的,把所有字符對應(yīng)的值累加起來就可以得到一個Hash 值。根據(jù)規(guī)則,依此treamlining.F our aresta ndar dvisits,ex ceptasr equir edtosto improve new sreporting,for propaga
18、 ndawork stri ctlyaccordi ngtothe regulati ons.Sixis strictly y ourpre sentati on published stri ctlyaccordi ngtothe regulati ons.Seven isstrictlyt hrift, require d the use ofvehicl esand office spacea nd corporate hospitalit y.3, change the style.Propaganda a nd ideol ogicalw ork ofthenew situati o
19、n a nd new requirement s ofthe newtasks,ha ddonea l ot of fruitfulw ork,ha s made many a chi evements, butfurt hercl oser to t he grass r oots,cl ose t o reality, close tothe masse s andalso ina dequate innovati on must continueto improve.Ses 1, oppose formali sm.Onetheoryis t hathe didn't,with
20、le ss closecontact. Theoreticalst udy ofconsciousnessi snot highenough, system perform ancei s not strong e nough;more passive le arni ng,active l earni ng fewgeneralitie sand learn m ore,delving int o less.Especiallyba sed onrationalthinking on majorissues,ade thework doneis notgood eo ugh, not rea
21、llyI-d daringto, rehespirit andessenceofthescientificOutlookondevel opme nt, di d nottr uly achievemotofpower, but no tangi ble results. Third, innovation,lackof motivation.Emancipation diyd,o acertai n extent,affect the nnovati on doesnot exist.nd impleme ntationof idea sand initiative s.Second, wo
22、rk arra ngements,and less supervisiwork,notyour head, previ ousw orkexperi ence, la ckof innovation initiatives,studyon theologi calw ork istheopaga nda a nd ideolobjective,w hich neogical workunderthenew sitedst okeept he continuity efforts deuation through,grid, butstressed i nthew orktime,lesssup
23、ervisi on. Forexample, col or weekends i nthe summer theatdeol ogicaltre nds andchanges are notdee p,to promote new initiatives andexplore ne wmethodsricalactivitie s,citysquare performances, urging townships, communitiesand ruralareaofideol ogicala nd cult uralworki s not much,and some lackof relev
24、ance andtimelinesshowstss.4,disciplihe impleme ntation ine,l oweri ng,and harsina dequate,insufficie nt culturala n ed ucationalrolacki ng.Whilew orking a nde nterprisieto pla y.Tng spiritdown.hird ba se enough,mastergrass-leNo rea lsol ution to treatyourselfsituation ofcharacterindw orktoseetheirde
25、ep enoughforgrass-rs own shortcomings,c opi nion Dynamipraise,cs survey, forgrass-rsatisfied face, onliness real. Propaganda andide,correctly treatologi calw ork inthe newpasthonors,their complacency,aootsty pically drivepromoti on,t hereariilifEcrucjt - eg - e l d keiltu-1eceasel-e-aea-ags i-jtsaer
26、 er-".ee- e atasrli a ea.- tu -a y i- - ye s fet- -r .ties - te. .t> icg-.a- l x i i -e e scs c -u -ee c i i s cl- c - ye st -1- cteaivetei . ftveBaktes kigegvt -i tPk - -dr y dvrf5- ie d riisHgl.itgg.yei1ad dvr eg-e. eei1 ad-acda-e.fiiesls-oeasc- c d a . a v .1s-e iirsrii s-We-e e sairurr-1
27、 ad-s a .e- si- i-ee ies-ssa.l ae iigge Ig esTf-e e u - a dadi-i Ia.n-i aaesi".".a i ki v fiiyailcs-ay el e .-a-c -cc c c -ligul- aigf- -s a- -g esacksi"d i.- si-edu-gkes-g ali"c-Wlcek ei l- - ad e ca-s l-a ic- e ig- e-l sg-sl-asciu-i i- a- iia -s-l s c -sl da-s-c ieiia u es a*a&
28、gt;a-y- lil id g l -g - c - -p e-l-ace - - a- a一一-es- ee-c-a a- -eigr i s -ig esa-iglac -s e als.u-a- aadea as - ei-e-esu- - -dci- se.i-v-.eig-ee ese.i-eesl-e l s -gieeie.-cle viici- . e ed"-類推,最后解析得到”/dev/mapper/ ”目錄的inode對象以及文件名字符串"map。"。到這 一步為止,link_path_walk函數(shù)的使命完成,最后可以通過 do_last函
29、數(shù)獲取或者創(chuàng)建文件 inode。如果用戶態(tài)程序設(shè)置了O_CREATE標(biāo)記,那么系統(tǒng)如果找不到用戶指定的inode,do_last會創(chuàng)建一個新的文件inode,并且把這些信息以元數(shù)據(jù)的形式寫入磁盤。當(dāng)指定文件 的inode找到之后,另一件很重要的事情就是初始化file文件對象。初始化文件對象通過_dentry_open函數(shù)來實(shí)現(xiàn)。文件對象通過inode參數(shù)進(jìn)行初始化,并且把 inode的操作方法函數(shù)集告訴給file對象。一旦file對象初始化成功之后,調(diào)用文件對象的open函數(shù)執(zhí)行進(jìn)一步的初始化工作。通過上述分析,整個過程看似比較復(fù)雜,涉及到 dentry , inode以及file對象。其實(shí)這
30、 個模型還是很簡單的。Dentry用來描述文件目錄,在磁盤上會采用元數(shù)據(jù)的方式存儲在一個 block中,文件目錄本身在Linux中也是一個文件。Inode描述一個具體的文件,也通過元數(shù)據(jù)的方式在磁盤上保存。如果對一個文件系統(tǒng)從根目錄開始往下看,整個文件系統(tǒng)是一顆龐大的inode樹:在打開一個文件的過程中,文件系統(tǒng)所要做的事情就是找到指定文件的inode,所以在這個過程中會有磁盤元數(shù)據(jù)讀操作。一旦文件所屬的inode被找到,那么需要在內(nèi)存中初始化一個描述被打開文件的象,這個對象就是file o所以,dentry , inode之類的信息在磁盤上是永久存儲的,file對象是在內(nèi)存中是臨時存在的,它
31、會隨著文件的創(chuàng)建而生成,隨著文 件的關(guān)閉而消亡。在Linux系統(tǒng)中文件類型是多種多樣的,一個USB設(shè)備也是一個文件,一個普通的Word 文檔也是一個文件,一個RAID設(shè)備也是一個文件。雖然他們在系統(tǒng)中都是文件,但是,他們的操作方式是截然不同的。USB設(shè)備可能需要采用字符設(shè)備的方式和設(shè)備驅(qū)動交互;RAID設(shè)備可能需要采用塊設(shè)備的方式和設(shè)備驅(qū)動進(jìn)行交互;普通Word文件需要通過cache機(jī)制iilifEcrucjt - eg - e l d keiltu-1ecease l-e -aea-ags i- jtsaer er-".ee- e atasrli a ea.-tu-ayi- - y
32、e s fet- -rties - te. .t> icg-.a- lxii-e escs c -u -ee c i i s cl- c- yest Is1- cte aivetei. ftveBakteskigegvt -i tPk - - dr y dvrf5- - ied riisHgl.itgg.yei1ad dvr eg-e. eeiI ad-a. da-e.fiiesis-oeasc- c d a . a v . is-e iirsriis- We-e e sairurr-l ad-s a .e- s 1y i-ee is-ss a.i ae iigge IgesTf-eeu
33、- a dadi-i Ia.n-i aaesi".".aikivf-y .ailcs-ay el e .-a-c -cc c c -l-gul- aigf- -s a- -g es a ck s i "d igy sii-edu-gekes-g alifc-Wl c ek ei is i- ad e caysl-aic e eg - e-l sg - sle-asciu-ii-a-iia -s-i sc -Idays i-ccieiia u es a*a>a-y - -il idg I -gyc-pe-l-ace - - a- - a 一一 -es -ee-
34、c-lau-e egi i s -ig esa-igeac-s e a Isgau-a- aadea as - ei-e- esu-c- -dc-s - seai-.I-eig-eeeseai 11rs ul-eIs-giesieacle vii>i-aeed"-進(jìn)行性能優(yōu)化。所以,雖然都是文件,但是,文件表面下的這些設(shè)備是不相同的,需要采用 的操作方法顯然是截然不同的。作為一個通用的文件系統(tǒng),如何封裝不同的底層設(shè)備是需要考慮的問題。在 Linux中,為了達(dá)到這個目的,推出了VFS概念。在VFS層次對用戶接口進(jìn)行了統(tǒng)一封裝,并且實(shí)現(xiàn)了通用的文件操作功能。例如打開一個文件和關(guān)閉一
35、個文件的操作都是相同的。在VFS下面會有針對不同需求的具體文件系統(tǒng),例如針對Word文檔可以采用EXT3文件系統(tǒng)進(jìn)行操作,對于磁盤設(shè)備可以采用bdev塊設(shè)備文件系統(tǒng)進(jìn)行操作。在打開一個文件,對文件對象file進(jìn)行初始化的時候,會將具體的文件系統(tǒng)操作方法關(guān)聯(lián)到file->f_op和file->f_mapping對象。在后面的讀寫過程中,我們將會看到針對不同的文件類型,會采用不同的 f_op 和f_mapping 方法。讀寫文件當(dāng)一個文件被打開之后,用戶態(tài)程序就可以得到一個文件對象,即文件句柄。一旦獲取文件句柄之后就可以對其進(jìn)行讀寫了。用戶態(tài)的讀寫函數(shù)write對應(yīng)內(nèi)核空間的 sys_
36、write例程。通過系統(tǒng)調(diào)用可以陷入sys_write。Sys_write函數(shù)在VFS層做的工作及其有限,其會調(diào)用文件對象中指定的操作函數(shù)file->f_op->write 。對于不同的文件系統(tǒng),file->f_op->write指向的操作函數(shù)是不同的。對于EXT3文件系統(tǒng)而言,在文件 inode初始化的時候會指定ext3_file_operations操作方法集。該方法集說明了EXT3文件系統(tǒng)的讀寫操作方法,說明如下: const struct -ile_operations ext3_file_operat ions - + llieek» generic
37、-File_LLseek,read= do_sync_read do_sync_write, ,aic_read= generic_file_aio_ .aio_wri'te=i le_wr ite ,.ioctl= 4tifde-F CONFIG_COMPAT + corpat_ioctl» ext3_campat_iocti, ifendi-F .rrirap=r generic_File_ffirapj open- gencriC_-f 11pcn xrelease= extS_relea5e_FilE t .fsync- ext3_sync_f£lej ,s
38、plce_rtad= £entr±c_file_splice_readf + spLice_write» generic_file_s|jlice_write, 17如果文件設(shè)備是一個 USB設(shè)備,并且采用的是字符設(shè)備的接口,那么在初始化文件inode的時候會調(diào)用init_special_inode初始化這些特殊的設(shè)備文件。對于字符設(shè)備會采用默認(rèn)的 def_chr_fops方法集,對于塊設(shè)備會采用def_blk_fops方法集。不同的文件類型會調(diào)用各自的方法集。下面章節(jié)會對EXT3文件寫和塊設(shè)備文件寫進(jìn)行詳細(xì)闡述。由于字符設(shè)備類型比iilifEcrucjt - e
39、g - e l d keiltu-1eceasel-e - a ea- ags i- jtsaer er-".ee- e atasrliaea.-tu -a y i- - ye s fet- -r .ties - te. .t> icg-.a- lx i i-eescsc-u-ee c i i s cl- c - ye st - 1- cte aivetei . ftveBaktes kigeg vt-itPk - - dr y dvrf5-ie d riisHgl.itgg.yei1ad dvr eg-e. eei1 ad-acda-e.fiiesls-oeasc- c d
40、a . a v .1s-e iirsri i s-We-e e sairurr-1 ad-s a .e- si- i-ee ies-ss a.l ae iigge Ig esTf-e e u - a dadi-i Ia.n-i aaesi ".".ai ki v fiiy ailcs-ay el e .-a-c -cc c c -ligul- aigf- -s a- -g esack s i "d i.- si-edu-gkes-g ali"c-Wlc ek eil-adeca-s l-a ic- e ig- e-l sg - sl-asc iu-ii-
41、a- iia -s-l sc-sld a-s-c ie i i a u es a*a>a-y - lil idg l-g - c -p e-l-ace- a-a一一- es -ee-c-a a- -e igr i s -ig esa-iglac -s e als.u-a- aadea as - ei-e-esu- - -dci- se.i-v- .eig-e e ese.i -eesl-e l s -gieeie.-cle viici- . e ed"-較簡單,在此進(jìn)行簡單說明。Def_chr_fops方法集其實(shí)就定義了 open方法,其它的方法都沒有定義。其實(shí)字符設(shè)備 的操作
42、方法都需要字符設(shè)備驅(qū)動程序自己定義,每個設(shè)備驅(qū)動程序都需要定義自己的write、read、open和close方法,這些方法保存在字符設(shè)備對象中。當(dāng)用戶調(diào)用文件系統(tǒng)接口open函數(shù)打開指定字符設(shè)備文件時,VFS會通過上述講述的sys_open函數(shù)找到設(shè)備文件inode中保存的def_chr_fops方法,并且執(zhí)行該方法中的open函數(shù)(chrdev_open ), chrdev_open函數(shù)完成的一個重要功能就是將文件對象file中采用的方法替換成驅(qū)動程序設(shè)定的設(shè)備操作方法。完成這個偷梁換柱的代碼是:filp->f_op - -ep5_get(p->eps)一旦這個過程完成,后繼用
43、戶程序通過文件系統(tǒng)的write方法都將會調(diào)用字符設(shè)備驅(qū)動程序設(shè)定的write方法。即對于字符設(shè)備文件而言,在VFS的sys_write函數(shù)將直接調(diào)用字符設(shè)備驅(qū)動程序的 write方法。所以,對于字符設(shè)備驅(qū)動程序而言,整個過程很簡單,用戶態(tài) 程序可以直接通過系統(tǒng)調(diào)用執(zhí)行字符設(shè)備驅(qū)動程序的代碼。而對于塊設(shè)備和普通文件,這個過程將會復(fù)雜的多。在用戶程序發(fā)起寫請求的時候, 通常會考慮如下三個問題: 第一個問題是用戶態(tài)數(shù)據(jù)如 何高效傳遞給內(nèi)核?第二個問題是采用同步或者異步的方式執(zhí)行IO請求。第三個問題是如果執(zhí)行普通文件操作,需不需要文件 Cache?第一個問題是數(shù)據(jù)拷貝的問題。對于普通文件,如果采用了
44、page cache機(jī)制,那么這種拷貝合并在很大程度上是避免不了的。但是對于網(wǎng)卡之類的設(shè)備,我們在讀寫數(shù)據(jù)的時候, 需要避免這樣的數(shù)據(jù)拷貝,否則數(shù)據(jù)傳輸效率將會變的很低。我第一次關(guān)注這個問題是在做本科畢業(yè)設(shè)計的時候,那時候我設(shè)計了一塊PCI數(shù)據(jù)采集卡。在PCI采集卡上集成了 4KB的FIFO,數(shù)據(jù)采集電路會將數(shù)據(jù)不斷的壓入FIFO,當(dāng)FIFO半滿的時候會對 PCI主控芯片產(chǎn)生一個中斷信號,通知 PCI主控制器將FIFO中的2KB數(shù)據(jù)DMA至主機(jī)內(nèi)存。CPU接收到這個中 斷信號之后,分配 DMA內(nèi)存,初始化DMA控制器,并且啟動 DMA操作,將2KB數(shù)據(jù)傳輸 至內(nèi)存。并且當(dāng) DMA完成操作之后,
45、會對 CPU產(chǎn)生一個中斷。板卡的設(shè)備驅(qū)動程序在接收 到這個中斷請求之后,面臨一個重要的問題:如何將內(nèi)核空間DMA過來的數(shù)據(jù)傳輸給用戶空間?通常有兩種方法:一種是直接將內(nèi)核內(nèi)存映射給用戶程序;另一種是進(jìn)行數(shù)據(jù)拷貝的方式。對于PCI數(shù)據(jù)采集卡而言,一個很重要的特性是實(shí)時數(shù)據(jù)采集,在板卡硬件FIFO很小的情況下,如果主機(jī)端的數(shù)據(jù)傳輸、處理耗費(fèi)太多的時間,那么整條IO流水線將無法運(yùn)轉(zhuǎn),導(dǎo)致FIFO溢出,數(shù)據(jù)采集出現(xiàn)漏點(diǎn)的情況。所以,為了避免這樣的情況,在這些很嚴(yán)primaryfirst-hand an i nadequate graspofthe problem,which i s to be str
46、engthe ne d in thefut ure.Se cond, constructi on, strictlyina ccorda nce wit h the provisi onstostreamlinea nd im provethe quality of meetings ofthe Conference.Thir d,streamlini ng file briefs, culture involves al laspe cts ofpropagandaa ndideol og y,sometimes duetothe practical ne eds of inventi on
47、 notifications,t his area needs furtherSince thee ducational practi ceofthe mass li neofthe party, himselfseri ously i n thee ducation, pra ctical controlce ntral"n astnadtirounrealdicnoanrsetructioansldaenddiicnactreeasde taocoordinnadtidencgreandasseo,lvrienplgapcerombelnetmisndaicatssocoiras
48、tefdorwpitrihoribtuysaireansespsresinojtecht.iCshsearges,citnotr.Whenthoetrheearpersoujebscttasntoifalwiater,electrissues,csiteyc,taorledminaisdterrastiavreracngheardgteosapenrsdopnraelferelyintnetriavlepnoel,iicnie-sp.eInrthseoan,reian-persofotnaxation,paunsdhtsaenttglieble aread inbarueiladingsaog
49、frienedustrnyliaght,nedaitssyliprnode.uTcotiofunrcthoemrrepadnuyc,ewiatnhdistandnar5dyiears aftezretahdemieightrule s"and opposing "the four winds" andpracti cing"three S uns",and checkthe spirit ofJiaoYulu,ide ology,sol icitopini ons ba sed on outstanding problems che cked
50、sw ing, careful a nalysi s andr eflection. Will nowcheckre portis asfollow s: first,adhere ncetot heparty's politicaldiscipline,eighti n thencecentral pr ovisi on, chadisciplinesg.Conscientiouslyanmentcre dit+ busibide bythe party's politicaldiscipline, abi de by t heConstit ution andthe rul
51、esand regulationa nd moder nization of thei nvestmenta nd fina nci ngplatform;effectiveons of the party, i n the political, ide ologi cala ndmaintai n hig hlyconsi stent withtBank -enter prise docking, encourage s private ca pital int othe Park ,toraise i ndustrydevel opme ntfund.5, optimizethe envi
52、ronmenta nd servicei ndustrie s.Tocreate "policyl owla nds, Highla nds,integrity ofservi ce la nd, devel opment la nd" ast hegoal,t ooptimizeCPC Central Committeeonthe action,t here is no violati on oftheparty's politi caldi sci pline problems. 2,inthe implementation ofthece ntralautho
53、r itiesoftheeig ht provi sions.Impr oving re search,improvi ng resear chmethods,butthere arelessgrass-roots units,格應(yīng)用的場合只能采用內(nèi)存映射的方法,從而實(shí)現(xiàn)數(shù)據(jù)在操作系統(tǒng)層面的零拷貝。在Linux中, 我們可以采用memory map 的方法將內(nèi)核空間內(nèi)存映射給用戶程序,從而實(shí)現(xiàn)用戶程序?qū)?nèi)核內(nèi)存的直接訪問。在Windows 操作系統(tǒng)中,這種內(nèi)核空間和用戶空間的數(shù)據(jù)交互方式定義成兩種:Map IO 和 Direct IO。 Map IO 就是采用內(nèi)存拷貝的方式,Direct IO
54、 就是采用MDL 內(nèi)存映射的方式。在編寫 WDM Windows 設(shè)備驅(qū)動程序的時候經(jīng)常會用到這兩種數(shù)據(jù)傳輸模式。值得注意的是,Windows中的Direct IO和Linux中的Direct IO是完全不同的兩個概念。在Linux中Direct IO是指寫穿page cache的一種IO方法。第二個問題是異步IO和同步IO的問題。對于普通文件而言,為了提高效率,通常會采 用page cache對文件數(shù)據(jù)在內(nèi)存進(jìn)行緩存。Cache雖然提高了效率,但是有些應(yīng)用一旦發(fā)出寫請求,并且執(zhí)行完畢之后,其期望是將數(shù)據(jù)寫入磁盤,而不是內(nèi)存。例如,有些應(yīng)用會有一些元數(shù)據(jù)操作,在元數(shù)據(jù)操作的過程中,通常期望將數(shù)
55、據(jù)直接刷新至磁盤,而不是Cache在內(nèi)存。這就提出了同步IO的需求。為了達(dá)到這個效果,可以在打開文件的時候設(shè)置 O_SYNC 標(biāo)記。當(dāng)數(shù)據(jù)在page cache中聚合之后,如果發(fā)現(xiàn)O_SYNCjH己被設(shè)置,那么就會將page cache 中的數(shù)據(jù)強(qiáng)制的刷新到磁盤。對于EXT3文件系統(tǒng),該過程在 ext3_file_write函數(shù)中實(shí)現(xiàn)。第三個問題是普通文件的cache 問題。對于普通文件,由于磁盤性能比較低,為了提高讀寫性能,通常會采用內(nèi)存作為磁盤的cache o文件系統(tǒng)會采用預(yù)讀等機(jī)制對文件讀寫性能進(jìn)行優(yōu)化,避免磁盤隨機(jī)IO性能過低對文件讀寫性能造成影響。但是, page cache雖然提高了性能,但是也會對文件系統(tǒng)的可靠性造成一定影響。例如, 當(dāng)數(shù)據(jù)已經(jīng)被寫入內(nèi)存之后,系統(tǒng)Crash,內(nèi)存中的磁盤數(shù)據(jù)將會遭到破壞。為了避免這種情況,Linux文件系統(tǒng)提供了Direct I
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025房產(chǎn)抵押借款合同樣本
- ??谑卸V锌紨?shù)學(xué)試卷
- 城市空間文化映射-洞察及研究
- 呼吸道腫瘤免疫特征-洞察及研究
- 口腔外科試題及答案
- 員工健康促進(jìn)方案設(shè)計-洞察及研究
- android面試題及答案
- 2025安徽省二級vb考試試題及答案
- 桂陽縣初二數(shù)學(xué)試卷
- 廣東省1月學(xué)考數(shù)學(xué)試卷
- GB/T 9074.18-2017自攻螺釘和平墊圈組合件
- 長沙梅溪湖國際新城產(chǎn)業(yè)組織與西區(qū)土地一級開發(fā)
- GB/T 3768-2017聲學(xué)聲壓法測定噪聲源聲功率級和聲能量級采用反射面上方包絡(luò)測量面的簡易法
- 臨床診療指南(急診醫(yī)學(xué))
- GB 2811-2007安全帽
- 語言學(xué)綱要(新)課件
- 胸腔積液PPT.ppt 課件
- 斷指再植術(shù)后的切口
- 曾國藩為官之道
- 李中瑩心理創(chuàng)傷簡快輔導(dǎo)技巧(課堂PPT)
- Q∕GDW 12205-2022 高壓柔性直流輸電系統(tǒng)控制保護(hù)聯(lián)調(diào)試驗(yàn)技術(shù)規(guī)范
評論
0/150
提交評論