少妇伦子伦精品无吗,国产在线精品一区在线观看,精品久久久久久无码专区不卡,99久久免费国产精精品

Hero Circle Shape
Hero Moon Shape
Hero Right Shape
比特派新版本下載官網(wǎng)|1000hz realtime

比特派新版本下載官網(wǎng)|1000hz realtime

  • 作者: 比特派新版本下載官網(wǎng)
  • 2024-03-14 16:01:22

[技術(shù)干貨]淺談Linux內(nèi)核的實(shí)時(shí)性優(yōu)化 - 知乎

[技術(shù)干貨]淺談Linux內(nèi)核的實(shí)時(shí)性優(yōu)化 - 知乎首發(fā)于Linux內(nèi)核切換模式寫文章登錄/注冊[技術(shù)干貨]淺談Linux內(nèi)核的實(shí)時(shí)性優(yōu)化玩轉(zhuǎn)Linux內(nèi)核專注于C/C++領(lǐng)域技術(shù)、職業(yè)發(fā)展,公眾號/深度Linux實(shí)時(shí)系統(tǒng)的概念1.1什么是實(shí)時(shí)操作系統(tǒng)什么是實(shí)時(shí)操作系統(tǒng)?接觸過嵌入式的小伙伴可能會(huì)知道,實(shí)時(shí)操作系統(tǒng)是指在嵌入式領(lǐng)域廣泛應(yīng)用的各類RTOS(Real Time Operating System)。其中最具代表性的有國外的μC/OS-III、FreeRTOS、Vxworks等,國內(nèi)的代表有RT-Thread和LiteOS。在這些眾多的RTOS系統(tǒng)里面既有開源的也有商業(yè)的,同時(shí)還有一些是行業(yè)專用的,比如enea公司推出的OSE系統(tǒng)就是通信行業(yè)早期的基站設(shè)備應(yīng)用比較廣泛的系統(tǒng)。無論是開源或是商業(yè),這類系統(tǒng)都有一個(gè)最顯著的特點(diǎn),就是它們都具有很高的實(shí)時(shí)性。也是因?yàn)檫@個(gè)特點(diǎn),它們都被集中應(yīng)用在了嵌入式領(lǐng)域,特別是工控領(lǐng)域,例如工業(yè)制造控制、導(dǎo)彈飛機(jī)導(dǎo)航、電力設(shè)備監(jiān)控等。歷史上有很多著名的航空航天設(shè)備都使用到了實(shí)時(shí)的操作系統(tǒng)。比如登陸火星的鳳凰號、好奇號火星探測器,它們所采用的操作系統(tǒng)就是美國WindRiver公司推出的Vxworks。那什么是系統(tǒng)的實(shí)時(shí)性呢?Linux系統(tǒng)在嵌入式領(lǐng)域也有大量使用,那Linux系統(tǒng)支不支持實(shí)時(shí)性呢?往期回顧:2022年嵌入式開發(fā)想進(jìn)互聯(lián)網(wǎng)大廠,你技術(shù)過硬嗎?嵌入式進(jìn)階從小白到大神學(xué)習(xí)全攻略(學(xué)習(xí)路線+課程+學(xué)習(xí)書籍+練習(xí)項(xiàng)目)從事十年嵌入式轉(zhuǎn)內(nèi)核開發(fā)(23K到45K),給兄弟們的一些建議騰訊首發(fā)Linux內(nèi)核源碼《嵌入式開發(fā)進(jìn)階筆記》差距差的不止一點(diǎn)點(diǎn)哦1.2 Linux實(shí)時(shí)性、軟實(shí)時(shí)和硬實(shí)時(shí)實(shí)時(shí)性指的是一個(gè)操作系統(tǒng)能夠在規(guī)定的時(shí)間點(diǎn)內(nèi)完成指定的任務(wù)操作,一旦超過這個(gè)時(shí)間點(diǎn)會(huì)對整個(gè)系統(tǒng)帶來不可估量的后果。與此相對的是一般操作系統(tǒng),它更注重用戶體驗(yàn),系統(tǒng)偶爾卡頓不會(huì)給用戶帶來災(zāi)難性后果。實(shí)時(shí)性反映了一個(gè)系統(tǒng)行為控制的精準(zhǔn)能力,具體體現(xiàn)在定時(shí)器的精準(zhǔn)度高,中斷響應(yīng)及時(shí)以及系統(tǒng)的行為固定且可預(yù)估等。Linux系統(tǒng)最初是按照分時(shí)系統(tǒng)設(shè)計(jì)并推出的,再加上在歷史版本中使用的調(diào)度算法目的是公平的分配和使用各種系統(tǒng)資源,保證CPU被各個(gè)進(jìn)程公平的使用,所以早期并不支持實(shí)時(shí)性。但是在后來的2.6版本開始,加入了內(nèi)核搶占的功能,使它的實(shí)時(shí)性得到了提升,在某種程度上具備了軟實(shí)時(shí)的能力。軟實(shí)時(shí)指的是系統(tǒng)對于時(shí)限要求并不是十分的嚴(yán)格,在一些情況下允許系統(tǒng)超限完成。舉個(gè)例子,我們在PC機(jī)上使用鼠標(biāo)操作,偶爾會(huì)出現(xiàn)卡頓延遲,這種情況除了讓我們抓狂影響使用體驗(yàn)之外并不會(huì)給我們帶來嚴(yán)重的影響,大家平時(shí)在使用電腦時(shí)遇到鼠標(biāo)圖標(biāo)轉(zhuǎn)圈圈同時(shí)界面不響應(yīng)操作就是一個(gè)例子。再比如視頻信號采集,偶爾丟失幾個(gè)數(shù)據(jù)幀,并不會(huì)對視頻最后的播放帶來嚴(yán)重的畫面缺失。但是硬實(shí)時(shí)就不一樣,它對操作系統(tǒng)的行為有著嚴(yán)格的時(shí)限要求,超出時(shí)限往往會(huì)帶來災(zāi)難性后果。比如在我們?nèi)粘I钪惺褂玫钠嚩寂鋫淞税踩珰饽?,汽車在發(fā)生激烈碰撞時(shí)可能會(huì)在0.2s內(nèi)停下,那就要求氣囊在0.02s內(nèi)充氣完畢并彈出,超出這個(gè)時(shí)間乘客可能就會(huì)面臨生命危險(xiǎn)。再比如導(dǎo)彈防御系統(tǒng),當(dāng)敵方導(dǎo)彈來襲時(shí)攔截系統(tǒng)必須做出100%的精準(zhǔn)反應(yīng)并計(jì)算出彈道軌跡進(jìn)行攔截,稍有延遲就會(huì)造成攔截失敗,這種后果是不可接受的。這就是硬實(shí)時(shí)系統(tǒng)和軟實(shí)時(shí)系統(tǒng)的區(qū)別。但是由于Linux系統(tǒng)內(nèi)核過于龐大且模塊眾多,內(nèi)核中仍然有不少影響實(shí)時(shí)性的因素,比如使用大量自旋鎖、中斷禁止、時(shí)鐘粒度等,使其距離us級別的控制精度還有很大的距離。但是也不能因此認(rèn)定Linux系統(tǒng)今后就不能用于實(shí)時(shí)控制領(lǐng)域。其實(shí)Linux內(nèi)核一路發(fā)展過來,在歷史的版本主線中仍然有很多技術(shù)公司或者大牛為了提升Linux系統(tǒng)的實(shí)時(shí)性而努力著,他們或是在某個(gè)版本上發(fā)布實(shí)時(shí)補(bǔ)丁,或是對內(nèi)核進(jìn)行一定程度上的改造,具體的代表有RTLinux、RTAI(Real-Time Application Interface)和Xenomai等。RTLinux全稱叫做AReal-Time Linux,它由美國新墨西哥礦業(yè)及科技學(xué)院的V. Yodaiken開發(fā)。RTLinux采用了雙內(nèi)核的做法,可以說是開創(chuàng)了雙內(nèi)核法的先河。簡單理解就是系統(tǒng)中存在兩個(gè)內(nèi)核,實(shí)時(shí)核和非實(shí)時(shí)核。底層硬件資源和實(shí)時(shí)的內(nèi)核打交道繞開非實(shí)時(shí)核,來自硬件的中斷源由實(shí)時(shí)核全面接管,把非實(shí)時(shí)的Linux內(nèi)核當(dāng)成實(shí)時(shí)核上的一個(gè)低優(yōu)先級的進(jìn)程來運(yùn)行,通過這種方式確保實(shí)時(shí)核上的中斷和任務(wù)得到優(yōu)先響應(yīng),提升了實(shí)時(shí)性。Xenomai也借鑒了RTLinux的雙內(nèi)核做法,內(nèi)部也有實(shí)時(shí)核和非實(shí)時(shí)核。但不同的是Xenomai在底層硬件和兩個(gè)內(nèi)核之間還加了一層硬件抽象層ADEOS(Adoptive Domain Environment for Operating System),實(shí)時(shí)核和非實(shí)時(shí)核作為硬件抽象層的兩個(gè)域而存在,Xenomai內(nèi)核屬于實(shí)時(shí)域,Linux內(nèi)核屬于非實(shí)時(shí)域。ADEOS在系統(tǒng)的關(guān)鍵路徑中對中斷進(jìn)行攔截,優(yōu)先響應(yīng)Xenomai實(shí)時(shí)域的中斷,當(dāng)沒有實(shí)時(shí)任務(wù)和中斷需要處理的時(shí)候才會(huì)輪到Linux內(nèi)核執(zhí)行。兩者對比如下?!疚恼赂@啃【幫扑]自己的Linux內(nèi)核技術(shù)交流群:【865977150】整理了一些個(gè)人覺得比較好的學(xué)習(xí)書籍、視頻資料共享在群文件里面,有需要的可以自行添加哦?。?!前100名進(jìn)群領(lǐng)取,額外贈(zèng)送一份價(jià)值699的內(nèi)核資料包(含視頻教程、電子書、實(shí)戰(zhàn)項(xiàng)目及代碼)內(nèi)核資料直通車:最新Linux內(nèi)核源碼資料文檔+視頻資料學(xué)習(xí)直通車:Linux內(nèi)核源碼/內(nèi)存調(diào)優(yōu)/文件系統(tǒng)/進(jìn)程管理/設(shè)備驅(qū)動(dòng)/網(wǎng)絡(luò)協(xié)議棧圖2:RTLinux和Xenomai框架對比由于版權(quán)、技術(shù)專利等因素,RTLinux已經(jīng)不再更新。而Xenomai因?yàn)樽⒅赝卣剐?,可移植性和可維護(hù)性,對開發(fā)者相對友好,目前還在不斷推出補(bǔ)丁,并且在社區(qū)活躍度很高,在工控領(lǐng)域也有不少成功應(yīng)用的案例。這些基于Linux系統(tǒng)去改造從而提升實(shí)時(shí)性的系統(tǒng)的出現(xiàn),使得Linux系統(tǒng)在發(fā)展過程中在實(shí)時(shí)性的研究上熱度不減。甚至有不少人從Linux系統(tǒng)實(shí)時(shí)性研究入手,深入去學(xué)習(xí)Linux內(nèi)核的調(diào)度機(jī)制、中斷機(jī)制、定時(shí)器機(jī)制等,逐漸發(fā)展成自己的興趣和愛好。從我們作為普通技術(shù)族的實(shí)力來說,可能不具備像國外的公司或者一些技術(shù)組織大改并發(fā)布實(shí)時(shí)Linux的能力。而想要提升系統(tǒng)實(shí)時(shí)性,有的是出于自身工作的需要,有的則是帶著個(gè)人的興趣愛好去鉆研,那么如果想提升Linux內(nèi)核的實(shí)時(shí)性,我們該怎么做呢?Linux實(shí)時(shí)性優(yōu)化2.1 實(shí)時(shí)性優(yōu)化和時(shí)鐘精度知其然并知其所以然,知道影響實(shí)時(shí)性的因素才能很好地優(yōu)化改造它。目前影響Linux內(nèi)核實(shí)時(shí)性因素主要有時(shí)鐘精度、系統(tǒng)中斷、進(jìn)程調(diào)度算法和內(nèi)核可搶占性等。每一塊都可以深入研究并做出相應(yīng)的優(yōu)化。首先是時(shí)鐘精度,時(shí)鐘就像是一個(gè)系統(tǒng)的脈搏,系統(tǒng)進(jìn)程的調(diào)度切換是按照時(shí)鐘節(jié)拍來進(jìn)行的。目前Linux內(nèi)核支持幾種不同的系統(tǒng)節(jié)拍,可以在用戶編譯內(nèi)核時(shí)配置。假設(shè)當(dāng)前的系統(tǒng)節(jié)拍是100Hz,那么系統(tǒng)的時(shí)鐘粒度就是10ms,如果提升到1000Hz,那么時(shí)鐘粒度就是1ms,精度提升了10倍。圖3:編譯內(nèi)核系統(tǒng)節(jié)拍設(shè)置上面這張圖是CentOS7.6發(fā)行版系統(tǒng)默認(rèn)的系統(tǒng)節(jié)拍設(shè)置。時(shí)鐘精度的提升最直接的影響就是系統(tǒng)中的調(diào)度動(dòng)作加快了,進(jìn)程的響應(yīng)也更為及時(shí),但隨著而來的是時(shí)鐘中斷頻率的加快,這也加大了系統(tǒng)的開銷和壓力,因?yàn)闀?huì)頻繁的響應(yīng)系統(tǒng)的時(shí)鐘中斷。在某些CPU消耗型的進(jìn)程上會(huì)由于系統(tǒng)頻繁的進(jìn)行進(jìn)程切換而導(dǎo)致CPU資源浪費(fèi),CPU的時(shí)間會(huì)浪費(fèi)在進(jìn)程切換上,因?yàn)閺倪M(jìn)程切換到實(shí)際被調(diào)度執(zhí)行之間有一個(gè)時(shí)間差,叫做進(jìn)程切換開銷,所以好和壞我們還是需要根據(jù)自己的系統(tǒng)表現(xiàn)來看待。2.2 中斷其次是中斷。無論是RTOS還是Linux,硬件中斷在系統(tǒng)當(dāng)中的響應(yīng)優(yōu)先級永遠(yuǎn)是最高的。RTOS由于支持中斷優(yōu)先級,在實(shí)際使用過程中可以根據(jù)產(chǎn)品的實(shí)際情況針對不同的外設(shè)場景設(shè)置不同的優(yōu)先級,且高優(yōu)先級的中斷可以搶占低優(yōu)先級的中斷,使得RTOS的中斷響應(yīng)非常迅速。Linux系統(tǒng)中的中斷模塊遠(yuǎn)比RTOS系統(tǒng)復(fù)雜得多。通常,Linux系統(tǒng)在進(jìn)入一個(gè)中斷時(shí)候,會(huì)禁止本地CPU的中斷。在處理具體某一個(gè)中斷的時(shí)候,由于禁止了本地CPU中斷(NMI類型的中斷除外),當(dāng)有新的中斷到來的時(shí)候只好掛起,只有當(dāng)前的中斷處理完才打開本地中斷并響應(yīng)新的中斷。如果系統(tǒng)中存在大量不同類型的中斷,勢必會(huì)有一些中斷被延遲得不到及時(shí)響應(yīng),這種延遲現(xiàn)象在單核CPU上表現(xiàn)尤為明顯。針對這種情況,就要求我們在編寫實(shí)際中斷處理函數(shù)的時(shí)候,盡量在中斷處理函數(shù)中不做復(fù)雜的操作,堅(jiān)守中斷處理函數(shù)“快進(jìn)快出”的原則。比如只讀取硬件寄存器等簡單操作即可,剩下的數(shù)據(jù)處理的操作放到中斷下半部中去執(zhí)行,這就是所謂的“中斷線程化”。傳統(tǒng)上的中斷下半部有軟中斷、tasklet、工作隊(duì)列,它們的優(yōu)先級也從高到低。軟中斷和tasklet工作在中斷上下文不允許休眠它的優(yōu)先級比工作隊(duì)列高,工作隊(duì)列工作在進(jìn)程上下文允許休眠但是優(yōu)先級最低,所以在實(shí)際編程開發(fā)中需要我們根據(jù)場景選擇性的使用。如果是多核CPU,那么可以根據(jù)實(shí)際的中斷情況把不同類型的中斷遷移綁定到不同的CPU上,避免不同中斷之間的干擾。下面以I.MX6DL硬件平臺(tái)為例子介紹中斷遷移的使用。首先,通過#cat /proc/interrupts指令查看系統(tǒng)的所有中斷,如下圖所示:圖4:綁定中斷前的系統(tǒng)中斷分布從上面圖中可以看出,當(dāng)前的硬件平臺(tái)一共有4顆CPU,其中IMX-uart和imx-i2c的中斷集中發(fā)生在CPU0和CPU3,從第一列可以知道它們的中斷號分別是58和69。接下來我們可以將IMX-uart中斷全部遷移到CPU1上,讓CPU0只響應(yīng)imx-i2c中斷。通過# echo "2" > /proc/irq/58/smp_affinity指令即可完成遷移。注意,這里的數(shù)字“2”表示CPU編號,它是從1開始。遷移后IMX-uart中斷情況如下:圖5:綁定中斷后的系統(tǒng)中斷分布從前后兩張圖對比可以看出,中斷遷移前,IMX-uart在CPU3上的中斷次數(shù)為1824次,在CPU0上中斷次數(shù)為727次。中斷遷移后,CPU0和CPU3不再響應(yīng)IMX-uart中斷,CPU1上IMX-uart中斷次數(shù)由15次增加到了115次。我曾經(jīng)在一個(gè)雙核硬件平臺(tái)上遇到過串口和SPI同時(shí)需要響應(yīng)大量中斷,它們互相影響導(dǎo)致中斷響應(yīng)不及時(shí)而出現(xiàn)數(shù)據(jù)丟失和輸出不及時(shí)的情況,最終就是通過中斷綁核解決的。中斷綁核其實(shí)不能完全消除對實(shí)時(shí)性的影響,只能最大程度去降低中斷對進(jìn)程的影響,因?yàn)橄到y(tǒng)中NMI中斷和本地時(shí)鐘中斷無法遷移和禁止。除了中斷可以綁核,應(yīng)用層的進(jìn)程和線程也可以改變它們與CPU的親和性,比如遷移到中斷較少的核上,也能在一定程度上提升進(jìn)程的實(shí)時(shí)性。2.3進(jìn)程調(diào)度算法除了前面提到的時(shí)鐘和中斷外,還有一個(gè)影響實(shí)時(shí)性最大的因素就是操作系統(tǒng)的調(diào)度算法。Linux系統(tǒng)目前默認(rèn)采用的是完全公平調(diào)度算法(CFS),它按照各個(gè)進(jìn)程的權(quán)重來分配運(yùn)行時(shí)間,在默認(rèn)使用CFS的情況下,我們可以給有實(shí)時(shí)性需求的進(jìn)程分配更高的優(yōu)先級和權(quán)重,可以看做是通過賦予更高的優(yōu)先級來獲得更好的實(shí)時(shí)性。 Linux內(nèi)核目前支持多種調(diào)度類,每一種調(diào)度類都是同一類型調(diào)度策略的集合,目前支持的調(diào)度類有:stop、deadline、realtime、CFS、idle。通常情況下進(jìn)程都可選以上的幾種調(diào)度類,他們的優(yōu)先級依次由高到低排序,其中deadline調(diào)度類可選的調(diào)度策略有SCHED_DEADLINE,realtime調(diào)度類可選的調(diào)度策略有SCHED_FIFO和SCHED_RR,CFS可選的調(diào)度類有SCHED_NORMAI、SCHED_BATCH和SCHED_IDLE。在實(shí)際開發(fā)過程中,如果對時(shí)間有嚴(yán)格要求的實(shí)時(shí)進(jìn)程可以選擇deadline調(diào)度類,其他情況可以參考使用對應(yīng)的調(diào)度策略,改變調(diào)度策略,是最直接的一種優(yōu)化方式。其中deadline調(diào)度類的使用參考如下:圖6:deadline調(diào)度策略編程參考2.4 內(nèi)核其他限制除了內(nèi)核本身的調(diào)度算法的原因,Linux內(nèi)核的調(diào)度模塊當(dāng)中還有其他限制因素。比如為了防止某個(gè)進(jìn)程或某一個(gè)進(jìn)程組長時(shí)間的占用CPU時(shí)間,Linux內(nèi)核引入了一個(gè)“運(yùn)行帶寬”的概念,也就是說某一個(gè)進(jìn)程或進(jìn)程組使用CPU的總時(shí)間不能超過這個(gè)“帶寬”閾值,默認(rèn)值是0.95s。圖7:“運(yùn)行帶寬”默認(rèn)值實(shí)際開發(fā)過程中為了提高我們進(jìn)程的實(shí)時(shí)性,需要進(jìn)程長時(shí)間地占用CPU資源,我們可以把這個(gè)“運(yùn)行帶寬”給禁止掉。實(shí)際上不同的產(chǎn)品和使用場景也會(huì)有著不同的優(yōu)化措施,如果設(shè)備的CPU核數(shù)比較多,我們可以從整體上去規(guī)劃系統(tǒng)對于CPU的使用,大量的使用中斷綁核和進(jìn)程、線程綁核達(dá)到對CPU的獨(dú)占使用。比如DPDK,它是Intel公司開發(fā)的一種高性能網(wǎng)絡(luò)加速組件。在Linux內(nèi)核中,傳統(tǒng)的網(wǎng)絡(luò)數(shù)據(jù)包的收發(fā)都是經(jīng)過網(wǎng)卡驅(qū)動(dòng)和內(nèi)核協(xié)議棧,網(wǎng)卡驅(qū)動(dòng)針對大數(shù)據(jù)包場景也做了大量的應(yīng)對措施,但是從本質(zhì)上來說,網(wǎng)絡(luò)包的收發(fā)在內(nèi)核中也還是依賴系統(tǒng)給我們實(shí)現(xiàn)好的軟中斷機(jī)制。而DPDK則是使用輪詢代替了中斷,它繞過了Linux內(nèi)核的網(wǎng)絡(luò)模塊(驅(qū)動(dòng)和協(xié)議棧),不需要頻繁的進(jìn)行數(shù)據(jù)的拷貝,使得用戶空間可以直接看到硬件網(wǎng)卡的數(shù)據(jù),這大大減小了數(shù)據(jù)傳遞路程上的開銷。下面這張圖就是使用輪詢和DPDK獨(dú)占CPU的一個(gè)例子。圖8:DPDK輪詢獨(dú)占CPU再比如,irqbalance,它用于終端收集分配,會(huì)根據(jù)系統(tǒng)的負(fù)載情況自動(dòng)進(jìn)入性能模式和節(jié)能模式,會(huì)將中斷平均分配到不同的CPU上去處理,特殊情況下我們需要禁止這個(gè)功能。還有其他比如禁止軟鎖、虛擬內(nèi)存管理優(yōu)化等。從上面可以看出,實(shí)時(shí)性優(yōu)化的方法多種多樣,甚至使用使用輪詢代替了中斷。但是關(guān)鍵還是在于我們要了解Linux內(nèi)核模塊的一些運(yùn)行機(jī)制,和這些機(jī)制在實(shí)現(xiàn)上本身就存在的缺點(diǎn),只有這樣我們才能針對具體問題作出對應(yīng)的優(yōu)化措施。以上提到的這些方法只是從大的方向而且很淺顯去分析和介紹Linux內(nèi)核的實(shí)時(shí)性影響因素和對應(yīng)的優(yōu)化措施??偨Y(jié)起來有以下幾點(diǎn):1. 中斷優(yōu)先級高,要減少中斷對進(jìn)程的影響;2. 進(jìn)程之間有優(yōu)先級之分,要合理改變優(yōu)先級;3. 內(nèi)核模塊的實(shí)現(xiàn)機(jī)制限制,在特殊情況下使用輪訓(xùn);4. 提升系統(tǒng)節(jié)拍,提升定時(shí)精度;5. 禁止irqbalance,防止進(jìn)入節(jié)能或休眠模式;還有其他更為深入的細(xì)節(jié)我們沒有深入分析,比如Linux進(jìn)程切換耗時(shí),中斷響應(yīng)耗時(shí)、內(nèi)存分配開銷以及普通定時(shí)器精度和高精度定時(shí)器精度等,這些都是從細(xì)分的模塊方向去研究并優(yōu)化。進(jìn)程的切換涉及到主調(diào)度器和周期調(diào)度器,它們都不可避免地涉及到定時(shí)器,目前Linux內(nèi)核的高精度定時(shí)器也很難做到us級別,這也就決定了在調(diào)度的時(shí)間上也不是那么地準(zhǔn)確,再加上內(nèi)核中充斥著大量的自旋鎖,而自旋鎖的使用會(huì)關(guān)閉CPU的中斷進(jìn)而影響實(shí)時(shí)性,所以在開發(fā)過程中更加提高了對我們自身的水平要求。3.總結(jié)前面列舉的這些優(yōu)化措施實(shí)施起來很簡單,但對于我們自身來說更要理解為什么要這么做。深入去分析Linux內(nèi)核的機(jī)制,實(shí)際的去閱讀內(nèi)核的模塊源碼,才會(huì)在實(shí)時(shí)性或者Linux內(nèi)核的學(xué)習(xí)道路上收獲更多。比如閱讀內(nèi)核源碼才會(huì)知道tasklet和workqueue的應(yīng)用場景的不同,盡管它們都是“中斷下半部”之一,但是它們在內(nèi)核當(dāng)中執(zhí)行的優(yōu)先級還是有很大區(qū)別。只有閱讀內(nèi)核源碼,才會(huì)知道tasklet和hrtimer也是基于軟中斷的,而且這個(gè)軟中斷也有優(yōu)先級之分。也只有閱讀內(nèi)核源碼,才會(huì)知道系統(tǒng)目前實(shí)現(xiàn)了多少種軟中斷,甚至我們自己也可以實(shí)現(xiàn)軟中斷獲得實(shí)時(shí)性的提升,盡管Linux內(nèi)核不建議我們這么做。除了閱讀內(nèi)核的源碼,掌握調(diào)試跟蹤內(nèi)核的工具也必不可少,比如ftrace、trace-cmd、kernelshark、perf等。俗話說,工欲善其事必先利其器,熟練掌握這些工具的使用會(huì)讓我們的優(yōu)化工作更高效。ftrace是一個(gè)很強(qiáng)大的調(diào)試工具,除了常用的函數(shù)跟蹤器能讓我們輕松知道一個(gè)函數(shù)的執(zhí)行耗時(shí)之外,它強(qiáng)大的event機(jī)制,更是可以直接讓我們在驅(qū)動(dòng)或者內(nèi)核中添加跟蹤點(diǎn),輸出內(nèi)核執(zhí)行過程中的各類數(shù)據(jù),讓我們輕松洞察內(nèi)核的執(zhí)行過程??傊?,實(shí)時(shí)性優(yōu)化是一條漫長的道路,一路上也充滿了各種未知,鉆研越深越對它充滿好奇,也越覺得Linux內(nèi)核神奇。比如你可能會(huì)好奇在Linux內(nèi)核中一個(gè)進(jìn)程從被喚醒到真正去執(zhí)行這個(gè)過程花了多長時(shí)間。又比如一個(gè)外部中斷,從它被觸發(fā)到真正走到用戶注冊的中斷處理函數(shù),這個(gè)過程又花了多長時(shí)間。只有自己親自到設(shè)備上去調(diào)試,去嘗試弄明白這些問題了才會(huì)發(fā)現(xiàn)Linux內(nèi)核有趣的地方,也才會(huì)越走越充實(shí)。以上只是我自己在工作過程中積累的一點(diǎn)觀點(diǎn)看法,如果讀者面對Linux內(nèi)核不知道從何處入手的話,個(gè)人建議不妨從實(shí)時(shí)性優(yōu)化這個(gè)方向入手,逐漸深入。原文地址:https://mp.weixin.qq.com/s/Mq_sVpZYM3BrX2NpixBgaw 侵權(quán)請私信刪除發(fā)布于 2022-06-09 21:06操作系統(tǒng)內(nèi)核LinuxLinux 內(nèi)核?贊同 5??添加評論?分享?喜歡?收藏?申請轉(zhuǎn)載?文章被以下專欄收錄Linux內(nèi)核一種開源電腦操作系統(tǒng)內(nèi)核。C語

一文入門linux內(nèi)核高精度定時(shí)器hrtimer機(jī)制 - 知乎

一文入門linux內(nèi)核高精度定時(shí)器hrtimer機(jī)制 - 知乎首發(fā)于embedded guy切換模式寫文章登錄/注冊一文入門linux內(nèi)核高精度定時(shí)器hrtimer機(jī)制Haonan操作系統(tǒng)工程師,熱愛底層系統(tǒng)與原理。 文中代碼來自linux5.4-rc8內(nèi)核 全文大概5000字,建議收藏閱讀 0 背景timer子系統(tǒng)因?yàn)榫染窒拊诤撩爰墑e(時(shí)鐘頻率可設(shè)置在100HZ到1000HZ之間),無法滿足對時(shí)間要求高精度的場景(比如看門狗、usb、ethernet、塊設(shè)備、kvm等子系統(tǒng))。因此linux社區(qū)設(shè)計(jì)了hrtimer(High Resolution Timer,高精度定時(shí)器)子系統(tǒng),提供納秒級別的時(shí)鐘精度。1 如何使用高精度定時(shí)器?先從用戶的角度了解一下如何使用hrtimer,之后再逐漸深入hrtimer子系統(tǒng)的實(shí)現(xiàn)細(xì)節(jié)。以watchdog使用hrtimer的代碼為例:

static void watchdog_enable(unsigned int cpu)

{

struct hrtimer *hrtimer = this_cpu_ptr(&watchdog_hrtimer);

......

/*

* Start the timer first to prevent the NMI watchdog triggering

* before the timer has a chance to fire.

*/

hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);

hrtimer->function = watchdog_timer_fn;

hrtimer_start(hrtimer, ns_to_ktime(sample_period),

HRTIMER_MODE_REL_PINNED_HARD);

......

}

static void watchdog_disable(unsigned int cpu)

{

struct hrtimer *hrtimer = this_cpu_ptr(&watchdog_hrtimer);

......

hrtimer_cancel(hrtimer);

......

}

(1)定義一個(gè)struct hrtimer的instance(實(shí)例);(2)通過hrtimer_init()初始化hrtimer實(shí)例;

void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,

enum hrtimer_mode mode)

{

debug_init(timer, clock_id, mode);

__hrtimer_init(timer, clock_id, mode);

}

EXPORT_SYMBOL_GPL(hrtimer_init);

其中,clock_id是時(shí)鐘的種類。

/*

* The IDs of the various system clocks (for POSIX.1b interval timers):

*/

/* REALTIME記錄的是從1970.1.1到當(dāng)前的時(shí)間,常說的wall time(墻上時(shí)鐘) */

#define CLOCK_REALTIME 0

/* MONOTIC記錄的是從開機(jī)到當(dāng)前的時(shí)間,suspend時(shí)不會(huì)增加 */

#define CLOCK_MONOTONIC 1

#define CLOCK_PROCESS_CPUTIME_ID 2

#define CLOCK_THREAD_CPUTIME_ID 3

#define CLOCK_MONOTONIC_RAW 4

#define CLOCK_REALTIME_COARSE 5

#define CLOCK_MONOTONIC_COARSE 6

/* BOOTTIME記錄的是從開機(jī)到當(dāng)前的時(shí)間,suspend時(shí)依然會(huì)增加 */

#define CLOCK_BOOTTIME 7

#define CLOCK_REALTIME_ALARM 8

#define CLOCK_BOOTTIME_ALARM 9

mode是定時(shí)器的模式。

enum hrtimer_mode {

/* 有以下5中基本模式,其他都是基本模式的組合 */

HRTIMER_MODE_ABS = 0x00, /* 定時(shí)器到期時(shí)間是絕對值 */

HRTIMER_MODE_REL = 0x01, /* 定時(shí)器到期時(shí)間是相對值 */

HRTIMER_MODE_PINNED = 0x02, /* 定時(shí)器需要綁定到某個(gè)CPU上 */

HRTIMER_MODE_SOFT = 0x04, /* 定時(shí)器是“軟”的,即該定時(shí)器的回調(diào)函數(shù)在軟中斷上下文執(zhí)行 */

HRTIMER_MODE_HARD = 0x08, /* 定時(shí)器是“硬”的,即該定時(shí)器的回調(diào)函數(shù)在硬中斷上下文執(zhí)行即使是PREEMPT_RT打開的情況 */

HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED,

HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED,

HRTIMER_MODE_ABS_SOFT = HRTIMER_MODE_ABS | HRTIMER_MODE_SOFT,

HRTIMER_MODE_REL_SOFT = HRTIMER_MODE_REL | HRTIMER_MODE_SOFT,

HRTIMER_MODE_ABS_PINNED_SOFT = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_SOFT,

HRTIMER_MODE_REL_PINNED_SOFT = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_SOFT,

HRTIMER_MODE_ABS_HARD = HRTIMER_MODE_ABS | HRTIMER_MODE_HARD,

HRTIMER_MODE_REL_HARD = HRTIMER_MODE_REL | HRTIMER_MODE_HARD,

HRTIMER_MODE_ABS_PINNED_HARD = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_HARD,

HRTIMER_MODE_REL_PINNED_HARD = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_HARD,

};

(3)hrtimer->function = xxx;通過hrtimer實(shí)例的function指定高精度定時(shí)器到期的回調(diào)函數(shù);(4)hrtimer_start()/hrtimer_start_range_ns()開啟定時(shí)器;如果定時(shí)器不需要指定到期范圍就使用hrtimer_start(),如果定時(shí)器需要指定到期范圍就使用hrtimer_start_range_ns()。

/* 參數(shù)tim是到期時(shí)間;參數(shù)mode是定時(shí)器模式,見前文 */

static inline void hrtimer_start(struct hrtimer *timer, ktime_t tim,

const enum hrtimer_mode mode)

{

hrtimer_start_range_ns(timer, tim, 0, mode);

}

/* 參數(shù)delta_ns是指松弛(slack)時(shí)間,可以理解為一個(gè)寬限期,定時(shí)器可以在[tim, tim + delta_ns]區(qū)間到期 */

void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,

u64 delta_ns, const enum hrtimer_mode mode)

{

struct hrtimer_clock_base *base;

unsigned long flags;

/*

* Check whether the HRTIMER_MODE_SOFT bit and hrtimer.is_soft

* match on CONFIG_PREEMPT_RT = n. With PREEMPT_RT check the hard

* expiry mode because unmarked timers are moved to softirq expiry.

*/

if (!IS_ENABLED(CONFIG_PREEMPT_RT))

WARN_ON_ONCE(!(mode & HRTIMER_MODE_SOFT) ^ !timer->is_soft);

else

WARN_ON_ONCE(!(mode & HRTIMER_MODE_HARD) ^ !timer->is_hard);

base = lock_hrtimer_base(timer, &flags);

if (__hrtimer_start_range_ns(timer, tim, delta_ns, mode, base))

hrtimer_reprogram(timer, true);

unlock_hrtimer_base(timer, &flags);

}

EXPORT_SYMBOL_GPL(hrtimer_start_range_ns);

(5)通過hrtimer_cancel()取消一個(gè)hrtimer。

/* 等hrtimer的回調(diào)運(yùn)行完,再取消hrtimer */

int hrtimer_cancel(struct hrtimer *timer)

{

int ret;

do {

ret = hrtimer_try_to_cancel(timer);

if (ret < 0)

hrtimer_cancel_wait_running(timer);

} while (ret < 0);

return ret;

}

EXPORT_SYMBOL_GPL(hrtimer_cancel);

2 hrtimer的組織方式如圖所示:(1)因?yàn)榧t黑樹在查詢、插入、刪除時(shí)的性能優(yōu)勢,hrtimer的核心組織結(jié)構(gòu)選擇了紅黑樹,樹的最左下節(jié)點(diǎn)就是最早到期的定時(shí)器;(2)每個(gè)cpu上定義了一個(gè)hrtimer_cpu_base的全局變量,用于管理屬于自己的hrtimer;

struct hrtimer_cpu_base {

/* hrtimer_cpu_base每個(gè)cpu只有一個(gè),存在并發(fā)訪問,lock是用來保護(hù)該結(jié)構(gòu)體的自旋鎖 */

raw_spinlock_t lock;

/* 所屬的cpu編號 */

unsigned int cpu;

/* 表示clock_base數(shù)組中哪些時(shí)鐘基準(zhǔn)下的紅黑樹中存在hrtimer */

unsigned int active_bases;

unsigned int clock_was_set_seq;

/* 標(biāo)識(shí)是否處在高精度模式下 */

unsigned int hres_active : 1,

/* 標(biāo)識(shí)是否正在執(zhí)行hrtimer_interrupt回調(diào)函數(shù) */

in_hrtirq : 1,

/* 標(biāo)識(shí)是否上一次執(zhí)行hrtimer_interrupt出現(xiàn)了錯(cuò)誤 */

hang_detected : 1,

/* 標(biāo)識(shí)是否正在執(zhí)行軟中斷處理程序hrtimer_run_softirq */

softirq_activated : 1;

#ifdef CONFIG_HIGH_RES_TIMERS

/* 標(biāo)識(shí)一共執(zhí)行了多少次hrtimer_interrupt回調(diào)函數(shù) */

unsigned int nr_events;

/* 標(biāo)識(shí)在執(zhí)行hrtimer_interrupt時(shí)對定時(shí)事件設(shè)備編程錯(cuò)誤后重試的次數(shù) */

unsigned short nr_retries;

/* 標(biāo)識(shí)在執(zhí)行hrtimer_interrupt時(shí)發(fā)生錯(cuò)誤的次數(shù) */

unsigned short nr_hangs;

/* 出現(xiàn)錯(cuò)誤后,在hrtimer_interrupt中停留的最長時(shí)間 */

unsigned int max_hang_time;

#endif

#ifdef CONFIG_PREEMPT_RT

spinlock_t softirq_expiry_lock;

atomic_t timer_waiters;

#endif

/* 該CPU上即將到期hrtimer的到期時(shí)間,包括硬hrtimer和軟hrtimer */

ktime_t expires_next;

/* 該CPU上即將到期的hrtimer,包括硬hrtimer和軟hrtimer */

struct hrtimer *next_timer;

/* 該CPU上即將到期的軟hrtimer的到期時(shí)間 */

ktime_t softirq_expires_next;

/* 該CPU上即將到期的軟hrtimer */

struct hrtimer *softirq_next_timer;

/* hrtimer的到期時(shí)間可以基于不同的時(shí)鐘類型,每個(gè)類型都對應(yīng)一個(gè)hrtimer_clock_base結(jié)構(gòu)體 */

struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];

} ____cacheline_aligned;

(3)每個(gè)CPU的hrtimer_cpu_base全局變量對應(yīng)著HRTIMER_MAX_CLOCK_BASES(當(dāng)前是8)個(gè)hrtimer_clock_base變量。每個(gè)hrtimer_clock_base對應(yīng)一種不同的時(shí)鐘類型。

enum hrtimer_base_type {

HRTIMER_BASE_MONOTONIC,

HRTIMER_BASE_REALTIME,

HRTIMER_BASE_BOOTTIME,

HRTIMER_BASE_TAI,

HRTIMER_BASE_MONOTONIC_SOFT,

HRTIMER_BASE_REALTIME_SOFT,

HRTIMER_BASE_BOOTTIME_SOFT,

HRTIMER_BASE_TAI_SOFT,

HRTIMER_MAX_CLOCK_BASES,

};

根據(jù)hrtimer_init時(shí)傳入的clock_id,決定對應(yīng)的hrtimer實(shí)例掛在哪個(gè)hrtimer_clock_base對應(yīng)的紅黑樹下。

struct hrtimer_clock_base {

/* 標(biāo)識(shí)自己屬于哪個(gè)cpu的hrtimer_cpu_base */

struct hrtimer_cpu_base *cpu_base;

/* 標(biāo)識(shí)自己在hrtimer_cpu_base的clock_base數(shù)組的下標(biāo) */

unsigned int index;

/* 標(biāo)識(shí)當(dāng)前時(shí)鐘類型的id */

clockid_t clockid;

seqcount_t seq;

/* 指向當(dāng)前正在處理的定時(shí)器 */

struct hrtimer *running;

/* 屬于本clock_base的定時(shí)器紅黑樹 */

struct timerqueue_head active;

/* 獲取該時(shí)間類型當(dāng)前時(shí)間的回調(diào)函數(shù) */

ktime_t (*get_time)(void);

/* 標(biāo)識(shí)當(dāng)前時(shí)間類型和單調(diào)時(shí)間之間的差值,因?yàn)榕袛喽〞r(shí)器超時(shí)最后都會(huì)轉(zhuǎn)化為單調(diào)時(shí)間進(jìn)行對比 */

ktime_t offset;

} __hrtimer_clock_base_align;

3 hrtimer子系統(tǒng)的初始化在start_kernel()中會(huì)調(diào)用hrtimers_init()初始化hrtimer子系統(tǒng)。

void __init hrtimers_init(void)

{

/* 初始化當(dāng)前cpu的hrtimer_cpu_base */

hrtimers_prepare_cpu(smp_processor_id());

/* 注冊HRTIMER的軟中斷回調(diào)函數(shù) */

open_softirq(HRTIMER_SOFTIRQ, hrtimer_run_softirq);

}

int hrtimers_prepare_cpu(unsigned int cpu)

{

struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);

int i;

/* 初始化當(dāng)前cpu的hrtimer_cpu_base中所有時(shí)鐘類型的hrtimer_clock_base */

for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {

cpu_base->clock_base[i].cpu_base = cpu_base;

/* 初始化本hrtimer_clock_base的紅黑樹 */

timerqueue_init_head(&cpu_base->clock_base[i].active);

}

cpu_base->cpu = cpu;

cpu_base->active_bases = 0;

cpu_base->hres_active = 0;

cpu_base->hang_detected = 0;

cpu_base->next_timer = NULL;

cpu_base->softirq_next_timer = NULL;

cpu_base->expires_next = KTIME_MAX;

cpu_base->softirq_expires_next = KTIME_MAX;

hrtimer_cpu_base_init_expiry_lock(cpu_base);

return 0;

}

4 定時(shí)事件設(shè)備clock_event_device簡單介紹一下clock_event_device,它是理解timer/hrtimer子系統(tǒng)的關(guān)鍵。clock_event_device可以理解為硬件定時(shí)器的封裝,它是軟件可編程的,即可以控制硬件定時(shí)器什么時(shí)候觸發(fā)中斷。 系統(tǒng)中可以存在多個(gè)clock_event_device,系統(tǒng)會(huì)根據(jù)它們的精度和能力,選擇合適的clock_event_device對系統(tǒng)提供時(shí)鐘事件服務(wù)。在smp系統(tǒng)中,為了減少處理器間的通信開銷,基本上每個(gè)cpu都會(huì)具備一個(gè)屬于自己的本地clock_event_device,獨(dú)立地為該cpu提供時(shí)鐘事件服務(wù),smp中的每個(gè)cpu基于本地的clock_event_device,建立自己的tick_device,普通定時(shí)器和高精度定時(shí)器。 ———————————————— 版權(quán)聲明:本文為CSDN博主「DroidPhone」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。 原文鏈接:https://blog.csdn.net/DroidPhone/article/details/8017604 關(guān)于clock_event_device的詳細(xì)內(nèi)容可參考文章Linux時(shí)間子系統(tǒng)之四:定時(shí)器的引擎:clock_event_device5 hrtimer的到期處理處理hrtimer的函數(shù)是__hrtimer_run_queues(),看看有誰調(diào)用該函數(shù):因此hrtimer的處理有3個(gè)入口:在hrtimer軟中斷處理程序中,只處理軟timer;在低精度模式下,在每個(gè)jiffies的tick中斷處理函數(shù)中執(zhí)行,只處理硬timer;在高精度模式下,在每個(gè)clock_event_device的到期中斷處理函數(shù)hrtimer_interrupt中執(zhí)行,只處理硬timer。5.1 低精度模式在系統(tǒng)運(yùn)行早期,hrtimer子系統(tǒng)先運(yùn)行在低精度模式,這時(shí)是在每個(gè)jiffies的tick事件中斷(tick_handle_periodic())中處理到期的hrtimer,因此此時(shí)的時(shí)間精度和timer子系統(tǒng)是一致的,都是HZ級別的。函數(shù)調(diào)用鏈:tick_handle_periodic()---->tick_periodic()---->update_process_times()---->run_local_timers()---->hrtimer_run_queues()

void hrtimer_run_queues(void)

{

struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);

unsigned long flags;

ktime_t now;

/* 如果當(dāng)前是高精度模式,則直接退出 */

if (__hrtimer_hres_active(cpu_base))

return;

/*

* This _is_ ugly: We have to check periodically, whether we

* can switch to highres and / or nohz mode. The clocksource

* switch happens with xtime_lock held. Notification from

* there only sets the check bit in the tick_oneshot code,

* otherwise we might deadlock vs. xtime_lock.

*/

/* 檢查是否可以切換到高精度模式 */

if (tick_check_oneshot_change(!hrtimer_is_hres_enabled())) {

hrtimer_switch_to_hres();

return;

}

raw_spin_lock_irqsave(&cpu_base->lock, flags);

/* 獲得當(dāng)前時(shí)間 */

now = hrtimer_update_base(cpu_base);

/* 如果當(dāng)前時(shí)間 > 下一個(gè)到期的軟timer的過期時(shí)間,表示有軟timer到期了 */

if (!ktime_before(now, cpu_base->softirq_expires_next)) {

/* 將下個(gè)到期的軟超時(shí)間設(shè)置為最大值,這算是默認(rèn)值,等待hrtimer軟中斷處理函數(shù)重新更新下一個(gè)即將超時(shí)的軟timer的過期時(shí)間*/

cpu_base->softirq_expires_next = KTIME_MAX;

/* 設(shè)置softirq_activated表示已經(jīng)激活了本CPU的hrtimer軟中斷 */

cpu_base->softirq_activated = 1;

/* 觸發(fā)HRTIMER軟中斷 */

raise_softirq_irqoff(HRTIMER_SOFTIRQ);

}

/* 處理所有到期的硬timer,用戶指定的hrtimer->function會(huì)在這里執(zhí)行 */

__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD);

raw_spin_unlock_irqrestore(&cpu_base->lock, flags);

}

低精度模式下,每次執(zhí)行到hrtimer_run_queues都會(huì)檢查是否符合切換到高精度的條件:高精度模式?jīng)]有被禁止(打開了內(nèi)核選項(xiàng)CONFIG_HIGH_RES_TIMERS);當(dāng)前存在高分辨率的時(shí)鐘源設(shè)備;當(dāng)前定時(shí)設(shè)備是支持單次觸發(fā)(oneshot)的。當(dāng)以上條件滿足時(shí),切換到高精度模式:

/*

* Switch to high resolution mode

*/

static void hrtimer_switch_to_hres(void)

{

struct hrtimer_cpu_base *base = this_cpu_ptr(&hrtimer_bases);

/*

* 將clock_event_device的中斷回調(diào)函數(shù)注冊為hrtimer_interrupt(之前是tick_handle_periodic),

* 同時(shí)時(shí)鐘中斷的觸發(fā)模式從周期觸發(fā)變成了oneshot模式

*/

if (tick_init_highres()) {

pr_warn("Could not switch to high resolution mode on CPU %u\n",

base->cpu);

return;

}

base->hres_active = 1;

hrtimer_resolution = HIGH_RES_NSEC;

/*

* 因?yàn)闀r(shí)鐘中斷變成了oneshot模式,但是jiffies的更新、進(jìn)程調(diào)度還是依賴于低精度的tick,

* 因此專門通過一個(gè)hrtimer循環(huán)模擬低精度的tick

*/

tick_setup_sched_timer();

/* "Retrigger" the interrupt to get things going */

retrigger_next_event(NULL);

}

我們再稍微關(guān)心一下模擬tick的hrtimer的回調(diào)函數(shù):

static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)

{

struct tick_sched *ts =

container_of(timer, struct tick_sched, sched_timer);

struct pt_regs *regs = get_irq_regs();

ktime_t now = ktime_get();

/* 主要是更新jiffies時(shí)間,注意smp系統(tǒng)中只有一個(gè)cpu負(fù)責(zé)更新jiffiies */

tick_sched_do_timer(ts, now);

/*

* Do not call, when we are not in irq context and have

* no valid regs pointer

*/

if (regs)

tick_sched_handle(ts, regs);

else

ts->next_tick = 0;

/* No need to reprogram if we are in idle or full dynticks mode */

if (unlikely(ts->tick_stopped))

return HRTIMER_NORESTART;

/* 將該hrtimer的到期時(shí)間推后tick_period時(shí)間 */

hrtimer_forward(timer, now, tick_period);

/* 返回HRTIMER_RESTART表示該hrtimer需要再次執(zhí)行,這就實(shí)現(xiàn)了每tick_period時(shí)間觸發(fā)一次tick中斷了 */

return HRTIMER_RESTART;

}

5.2 高精度模式當(dāng)系統(tǒng)切換到高精度定時(shí)器模式后,某個(gè)hrtimer到期后會(huì)調(diào)用中斷處理函數(shù)hrtimer_interrupt()。需要強(qiáng)調(diào)的是,即使在開了PREEMPT_RT的系統(tǒng)上,hrtimer_interrupt也是在硬中斷上下文中執(zhí)行。

/*

* High resolution timer interrupt

* Called with interrupts disabled

*/

void hrtimer_interrupt(struct clock_event_device *dev)

{

struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);

ktime_t expires_next, now, entry_time, delta;

unsigned long flags;

int retries = 0;

/* 如果當(dāng)前不是高精度定時(shí)器模式,則觸發(fā)oops使系統(tǒng)panic */

BUG_ON(!cpu_base->hres_active);

cpu_base->nr_events++;

dev->next_event = KTIME_MAX;

raw_spin_lock_irqsave(&cpu_base->lock, flags);

/* 獲得當(dāng)前時(shí)間 */

entry_time = now = hrtimer_update_base(cpu_base);

retry:

/* 標(biāo)識(shí)當(dāng)前處于hrtimer_interrupt函數(shù)中 */

cpu_base->in_hrtirq = 1;

/*

* We set expires_next to KTIME_MAX here with cpu_base->lock

* held to prevent that a timer is enqueued in our queue via

* the migration code. This does not affect enqueueing of

* timers which run their callback and need to be requeued on

* this CPU.

*/

cpu_base->expires_next = KTIME_MAX;

/* 如果當(dāng)前時(shí)間 > 下一個(gè)到期的軟timer的過期時(shí)間,表示有軟timer到期了 */

if (!ktime_before(now, cpu_base->softirq_expires_next)) {

/* 將下個(gè)到期的軟超時(shí)間設(shè)置為最大值,這算是默認(rèn)值,等待hrtimer軟中斷處理函數(shù)重新更新下一個(gè)即將超時(shí)的軟timer的過期時(shí)間*/

cpu_base->softirq_expires_next = KTIME_MAX;

/* 設(shè)置softirq_activated表示已經(jīng)激活了本CPU的hrtimer軟中斷 */

cpu_base->softirq_activated = 1;

/* 觸發(fā)HRTIMER軟中斷 */

raise_softirq_irqoff(HRTIMER_SOFTIRQ);

}

/* 處理所有到期的硬timer,用戶指定的hrtimer->function會(huì)在這里執(zhí)行 */

__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_HARD);

/* 更新接下來即將到期的定時(shí)器 */

/* Reevaluate the clock bases for the next expiry */

expires_next = __hrtimer_get_next_event(cpu_base, HRTIMER_ACTIVE_ALL);

/*

* Store the new expiry value so the migration code can verify

* against it.

*/

cpu_base->expires_next = expires_next;

cpu_base->in_hrtirq = 0;

raw_spin_unlock_irqrestore(&cpu_base->lock, flags);

/* 使用最新的超時(shí)時(shí)間對定時(shí)事件設(shè)備(clock_event_device)進(jìn)行重新編程,即指定下一次arch_timer的中斷什么時(shí)候到來 */

/* Reprogramming necessary ? */

if (!tick_program_event(expires_next, 0)) {

cpu_base->hang_detected = 0;

return;

}

/*

* The next timer was already expired due to:

* - tracing

* - long lasting callbacks

* - being scheduled away when running in a VM

*

* We need to prevent that we loop forever in the hrtimer

* interrupt routine. We give it 3 attempts to avoid

* overreacting on some spurious event.

*

* Acquire base lock for updating the offsets and retrieving

* the current time.

*/

raw_spin_lock_irqsave(&cpu_base->lock, flags);

/* 重新獲取當(dāng)前時(shí)間,retry處理定時(shí)器 & 對定時(shí)事件設(shè)備進(jìn)行編程 */

now = hrtimer_update_base(cpu_base);

cpu_base->nr_retries++;

if (++retries < 3)

goto retry;

/*

* Give the system a chance to do something else than looping

* here. We stored the entry time, so we know exactly how long

* we spent here. We schedule the next event this amount of

* time away.

*/

/* 如果走到這里說明3次對定時(shí)事件設(shè)備編程都失敗了,更新與hang有關(guān)的信息統(tǒng)計(jì) */

cpu_base->nr_hangs++;

cpu_base->hang_detected = 1;

raw_spin_unlock_irqrestore(&cpu_base->lock, flags);

/* 計(jì)算在hrtimer_interrupt中花費(fèi)了多少時(shí)間,更新max_hang_time */

delta = ktime_sub(now, entry_time);

if ((unsigned int)delta > cpu_base->max_hang_time)

cpu_base->max_hang_time = (unsigned int) delta;

/*

* Limit it to a sensible value as we enforce a longer

* delay. Give the CPU at least 100ms to catch up.

*/

/* 適當(dāng)延后下一次到期時(shí)間,最多100毫秒 */

if (delta > 100 * NSEC_PER_MSEC)

expires_next = ktime_add_ns(now, 100 * NSEC_PER_MSEC);

else

expires_next = ktime_add(now, delta);

/* 強(qiáng)制對定時(shí)事件設(shè)備進(jìn)程重新編程,否則收不到arch_timer中斷了 */

tick_program_event(expires_next, 1);

pr_warn_once("hrtimer: interrupt took %llu ns\n", ktime_to_ns(delta));

}

5.3 軟中斷中處理軟hrtimer前文在低精度模式/高精度模式中,在硬中斷上下文中處理了硬timer們,對于軟timer只是raise了HRTIMER的軟中斷。我們看一下軟timer是怎么被處理的。軟中斷執(zhí)行邏輯參考文章代碼量很少的linux軟中斷機(jī)制,這里只聊HRTIMER軟中斷處理函數(shù)。

static __latent_entropy void hrtimer_run_softirq(struct softirq_action *h)

{

struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);

unsigned long flags;

ktime_t now;

hrtimer_cpu_base_lock_expiry(cpu_base);

raw_spin_lock_irqsave(&cpu_base->lock, flags);

/* 獲得當(dāng)前時(shí)間 */

now = hrtimer_update_base(cpu_base);

/* 處理所有到期的軟timer,用戶指定的hrtimer->function會(huì)在這里執(zhí)行 */

__hrtimer_run_queues(cpu_base, now, flags, HRTIMER_ACTIVE_SOFT);

/* 將本cpu的softirq_activated狀態(tài)位置0,表示沒有激活HRTIMER的軟中斷 */

cpu_base->softirq_activated = 0;

hrtimer_update_softirq_timer(cpu_base, true);

/*

* 更新即將到期的軟timer,對clock_event_device重新編程,

* 同時(shí)更新cpu_base->softirq_expires_next,將其從在

* hrtimer_interrupt中置的KTIME_MAX更新為下一個(gè)到期的軟timer的時(shí)間

*/

raw_spin_unlock_irqrestore(&cpu_base->lock, flags);

hrtimer_cpu_base_unlock_expiry(cpu_base);

}

結(jié)合hrtimer_run_softirq()與hrtimer_interrupt()對軟中斷的處理,可以看出如果某一次HRTIMER的軟中斷處理函數(shù)hrtimer_run_softirq()因?yàn)椴僮鞑划?dāng)沒有得到執(zhí)行,那么所有的軟hrtimer將永遠(yuǎn)不會(huì)得到執(zhí)行,因此需要確保軟中斷子系統(tǒng)是穩(wěn)定的。筆者在生產(chǎn)環(huán)境中遇到過網(wǎng)絡(luò)驅(qū)動(dòng)程序在未關(guān)中斷的情況下調(diào)用raise_softirq_irqoff(NETRX_SOFTIRQ)修改軟中斷的pending位,此時(shí)正好來了arch_timer的中斷,從而觸發(fā)hrtimer_interrupt調(diào)用raise_softirq_irqoff(HRTIMER_SOFTIRQ)也來修改軟中斷的pending位;這種對全局變量非原子的操作,會(huì)導(dǎo)致變量RMW(Read-Modify-Write)過程中出現(xiàn)競爭,從而丟掉HRTIMER_SOFTIRQ的pending置位,在高頻網(wǎng)絡(luò)收發(fā)包情況下會(huì)必現(xiàn)軟timer超時(shí),且永遠(yuǎn)得不到處理的情況,因此當(dāng)前對軟timer的處理邏輯不得不說是十分脆弱的。原創(chuàng)文章,轉(zhuǎn)載請注明出處。更多l(xiāng)inux內(nèi)核文章,點(diǎn)擊傳送門 Haonan:embedded guy專欄文章目錄,會(huì)持續(xù)更新!參考文章Linux時(shí)間子系統(tǒng)之六:高精度定時(shí)器(HRTIMER)的原理和實(shí)現(xiàn)Linux時(shí)間子系統(tǒng)之高分辨率定時(shí)器層(HR Timer)arm_arch_timer代碼閱讀Linux時(shí)間子系統(tǒng)之(十七):ARM generic timer驅(qū)動(dòng)代碼分析Linux內(nèi)核時(shí)鐘系統(tǒng)和定時(shí)器實(shí)現(xiàn)Linux時(shí)間子系統(tǒng)之三:時(shí)間的維護(hù)者:timekeeperLinux時(shí)間子系統(tǒng)之四:定時(shí)器的引擎:clock_event_device編輯于 2022-04-18 00:37Linux 內(nèi)核Linux定時(shí)器(程序開發(fā))?贊同 28??8 條評論?分享?喜歡?收藏?申請轉(zhuǎn)載?文章被以下專欄收錄embedded guyread the code, write s

Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED] | Blur Busters

Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED] | Blur Busters

Official Monitor List

1000Hz Journey

Framerate Amplification

G-SYNC 101: Input Lag

BenQ Strobe Utility

Motion Blur Reduction

Login / RegisterMonitor List

View all Monitor Lists

List of Best Gaming Monitors

List of G-SYNC Monitors

List of FreeSync Monitors

List of Best Ultrawide Monitors

G-SYNC

View all G-SYNC Articles

G-SYNC 101 Series

01 — G-SYNC 101: Control Panel

02 — G-SYNC 101: Range

03 — G-SYNC 101: Input Lag & Test Methodology

04 — G-SYNC 101: G-SYNC Ceiling vs. V-SYNC

05 — G-SYNC 101: G-SYNC Ceiling vs. FPS Limit

06 — G-SYNC 101: G-SYNC vs. V-SYNC OFF w/FPS Limit

07 — G-SYNC 101: G-SYNC vs. V-SYNC w/FPS Limit

08 — G-SYNC 101: G-SYNC vs. Fast Sync

09 — G-SYNC 101: G-SYNC vs. V-SYNC OFF

10 — G-SYNC 101: G-SYNC Fullscreen vs. Borderless/Windowed

11 — G-SYNC 101: In-game vs. External FPS Limiters

12 — G-SYNC 101: External FPS Limiter HOWTO

13 — G-SYNC 101: Hidden Benefits of High Refresh Rate G-SYNC

14 — G-SYNC 101: Optimal G-SYNC Settings & Conclusion

15 — G-SYNC 101: Closing FAQ

How Does G-SYNC Fix Stutters?

Preview of NVIDIA G-SYNC, Part #1 (Fluidity)

Preview of NVIDIA G-SYNC, Part #2 (Input Lag)

List of G-SYNC Monitors

FreeSync

TestUFO

Research

Motion Blur

Company

About This Site

About Founder Mark Rejhon

Consulting Services

Display Testing Inventions

Press Releases

Contact Blur Busters

More

Input Lag

PC Gaming & Esports

Virtual Reality

Mice & Accessories

Gaming Laptops & Phones

Gaming Consoles

Televisions

GPUs

AMD

NVIDIA

HFR and UltraHFR Video

Web Browsers

Industry Standards

Menu

Light Mode

Dark Mode

OS-controlled

Login / Register

Forums

Login / RegisterMonitor List

View all Monitor Lists

List of Best Gaming Monitors

List of G-SYNC Monitors

List of FreeSync Monitors

List of Best Ultrawide Monitors

G-SYNC

View all G-SYNC Articles

G-SYNC 101 Series

01 — G-SYNC 101: Control Panel

02 — G-SYNC 101: Range

03 — G-SYNC 101: Input Lag & Test Methodology

04 — G-SYNC 101: G-SYNC Ceiling vs. V-SYNC

05 — G-SYNC 101: G-SYNC Ceiling vs. FPS Limit

06 — G-SYNC 101: G-SYNC vs. V-SYNC OFF w/FPS Limit

07 — G-SYNC 101: G-SYNC vs. V-SYNC w/FPS Limit

08 — G-SYNC 101: G-SYNC vs. Fast Sync

09 — G-SYNC 101: G-SYNC vs. V-SYNC OFF

10 — G-SYNC 101: G-SYNC Fullscreen vs. Borderless/Windowed

11 — G-SYNC 101: In-game vs. External FPS Limiters

12 — G-SYNC 101: External FPS Limiter HOWTO

13 — G-SYNC 101: Hidden Benefits of High Refresh Rate G-SYNC

14 — G-SYNC 101: Optimal G-SYNC Settings & Conclusion

15 — G-SYNC 101: Closing FAQ

How Does G-SYNC Fix Stutters?

Preview of NVIDIA G-SYNC, Part #1 (Fluidity)

Preview of NVIDIA G-SYNC, Part #2 (Input Lag)

List of G-SYNC Monitors

FreeSync

TestUFO

Research

Motion Blur

Company

About This Site

About Founder Mark Rejhon

Consulting Services

Display Testing Inventions

Press Releases

Contact Blur Busters

More

Input Lag

PC Gaming & Esports

Virtual Reality

Mice & Accessories

Gaming Laptops & Phones

Gaming Consoles

Televisions

GPUs

AMD

NVIDIA

HFR and UltraHFR Video

Web Browsers

Industry Standards

Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED]

Posted Jun 12, 2020 by Mark Rejhon

in:

Area 51: Display Research HFR Video

Share

ORIGINALLY WRITTEN FEB 2018. Updated June 2020 with new information.

Ever since the Blur Busters Holiday Special article about the Amazing Journey to 1000Hz Displays?and the earlier true 480Hz monitor tests, Blur Busters has been paying much more attention to HFR video developments.

We are the only website in the world to exclusively talk about “Better Than 60Hz”. This universe also includes 120fps HFR. However, there are also experiments with Ultra HFR — the art of displaying video at ultra high frame rates (HFR 240fps, 480fps and 1000fps) in real-time on ultra high refresh rate displays. Not slow motion!

Longtime readers are familiar with our world’s first embedded 120fps HFR web browser videos and world’s first 120fps gameplay video five years ago (Year 2013)

World’s First 1080p Embedded 120fps Video Game Recording?

120fps HFR Video in Real Time

Now, we are testing video beyond 120 frames per second!

Ultra HFR: True 240 fps Real Time

Here is a method of creating 240 frame per second HFR video, for play back on today’s 240 Hz eSports monitor.

Get any favourite slo-mo camera capable of 240fps.

…From smartphones to GoPros to Phantom Flex cameras, many cameras now can do 240fps.

Get a GPU capable of 4K60 playback.

…GPUs capable of 4K 60fps playback are also able to do 1080p 240fps playback.

Get a true-240Hz gaming monitor. See List of Best Gaming Monitors.

Download and install ffmpeg.

Record video in normal 240fps slo-mo. Resulting file is 30fps.

If you need to use a video editor, edit while video is still slo-mo. Then export an .MP4 video.

Finally, run this ffmpeg command line to speed up the video back to real-time playback.

This speeds up video to play at?8 times the frame rate, converting 30fps to 240fps.

ffmpeg -i slowmo240.mp4 -r 240 -vf "setpts=(1/8)*PTS" -an realtime240.mp4

Play the video in your player (VLC, MPC-HC, Windows Media, etc) on your 240 Hz display.

…You may need to experiment with different video players to find the best 240fps experience.

High speed cameras, designed for slo-mo, often do not record audio well. At the moment, the best way to add audio is to record the audio separately, and use a command line utility to dub the audio onto the sped-up file.

The same general instructions apply to 480fps and 1000fps HFR, with different speedup factors (replace number “8” with the appropriate speedup factor).

Share your results in the new Blur Busters Forums?High Frame Rate (HFR) Video discussion area!

Future 1000fps HFR: 240fps is not the final frontier

In the newly created Blur Busters HFR Forum, there is a thread worth reading about Ultra HFR.

The art of playing true 1000fps real time on true 1000Hz displays:?Cinematography of 2030s: Ultra HFR (1000fps at 1000Hz!)

Experimental 1000 Hz displays are already available, and will eventually be cheap within one human generation. Now even some smartphones are also gaining ultra-high frame rate video recording capabilities too. This presents opportunities for cheap Ultra HFR in the coming years!

By doing 1000fps HFR on a 1000Hz display, you can simultaneously avoid camera motion blur and?avoid display motion blur?and avoid stroboscopic effects.?Strobless low-persistence (blurless sample-and-hold) without flicker is successfully achieved with 1000 Hz experimental laboratory displays, and is also useful with Ultra HFR video.

But why do UltraHFR?

Source Camera Blur and Destination Display Blur is Additive

Today, modern displays are sample-and-hold, for ergonomic flicker-free reasons, which creates a Hz bottleneck. No CRT flicker, but far more motion blur than a CRT tube.

A camera shutter 1/60sec combined with common display 1/60sec persistence = creates 2/60sec worth of motion blur. That’s 1/30sec of motion blurring seen by human eyes when playing 60fps video taken with 1/60sec shutter, played onto a 60Hz sample-and-hold display! This is even assuming instant pixel response GtG 0ms, otherwise, there’s worse motion blur than 1/30sec!

To reduce camera-side motion blur massively, a content creator can use a fast sports shutter 1/1000sec on the camera. But this will always be bottlenecked by destination display blur, from the sample-and-hold effect.

This diagram below is from our Pixel Response FAQ, GtG versus MPRT (the two different pixel response benchmarks). Flickerfree displays (sample-and-hold displays such as LCDs, OLEDs, MicroLEDs) produces a mandatory guaranteed added display-side motion blur:

To see this for yourself, we have TestUFO motion animations that demonstrates enforced motion blur caused by display persistence: TestUFO animation demo #1, TestUFO animation demo #2. As a general rule of thumb, the refresh rate of a flickerfree display is typically the guaranteed minimum display motion blur: 120Hz = 1/120sec = 8.3ms of motion blur = 8.3 pixels of blurring per 1000 pixels/sec motion.

To eliminate all motion blur weak links, both source shutter (1/1000sec) and display persistence (1ms MPRT) should be fast. There are two ways to reduce display motion blur:

Shorten display’s frame visibility time via impulsing (CRT, plasma, black frames, etc)

Shorten display’s frame visibility time via higher frame rate

The problem with approach (1) is you can produce stroboscopic stepping effects (phantom arrays) for fast-camera-shutter material such as sports, see The Stroboscopic Effect of Finite Frame Rate Displays. Besides, real life doesn’t flicker or strobe, so impulsing is a humankind band-aid for simulating reality.

Solving motion blur and stroboscopic effect simultaneously requires ultra high frame rates: 1000fps at 1000Hz! One can do a 360-degree camera shutter blurlessly. A full-open shutter is only 1 millisecond during 1000fps video. A 1000Hz display is blurless sample-and-hold via sheer brute Hz.

This makes video look closer to real life, closer to a Holodeck — with no framerate-induced limitations like forced motionblur or forced stroboscopic effects. This can make 1000fps UltraHFR less nauseating than 120fps HFR.

Diminishing Curve: Next Step After 120fps HFR should be 1000fps UltraHFR

Time-wise, the difference between 120fps HFR versus 1000fps HFR is roughly as big as the difference between 60fps and 120fps.? This is because 1/60sec and 1/120sec is an 8.3ms difference, while the difference between 1/120sec and 1/1000sec is a 7.3ms difference.? There is a curve of diminishing points of returns, but the massive jump up to 1000fps HFR greatly compensates.

1/60sec = 16.7ms?blur

1/120sec = 8.33ms blur — observe 8.3ms improvement over 1/60sec

1/1000sec = 1ms?blur?— observe 7.3ms improvement over 1/120sec

As a result, a large jump up the diminishing curve of returns is required to get as dramatic improvement as the jump between 60fps and 120fps HFR.? Therefore we believe that the next step after 120fps HFR should now be 1000fps HFR.

Also, UltraHFR benefits higher resolution more. 1000fps UltraHFR would not be nearly as useful for standard-definition video material (less than 1 pixel of motion blur for one-screen-width-per-second motion) but would be hugely beneficial to 8K material (8 pixels of motion blur for one-screen-width-per-second panning motion)

Very Important UltraHFR Tips For Max Frame Rate Video

When trying to force a display to go maximum motion clarity, there are some best practices.

In the world of experiments with 240fps, 480fps and 1000fps real-time video playback on ultra-high Hz displays, these are very important considerations from recent research:

Display persistence is additive to camera persistence (shutter). A 1/60sec persistence display combined with a 1/60sec shutter video, generates a combined 2/60sec of human-perceived motion blur.? As a rule of thumb, your common? perceived blur is often at least?twice the camera shutter, and often much worse (e.g. 1/1000sec shutter combined with 1/60sec display persistence). This means that on most displays, a 1/1000sec shutter at 60fps only has barely half the motion blur of 1/60sec shutter, simply because it is bottlenecked by 1/60sec display persistence! Also, a?display that has a pixel response (GtG) that is a significant percentage of a refresh cycle at its max Hz — will also limit UltraHFR benefits even further.

You must be aware of how?both source (Camera) and destination (Display) persistence combines in motion blur in order to understand limitations to UltraHFR benefits

Resolution reduction is a big problem at higher frame rates on current cameras.? Recommended is to oversample by recording at about 2x resolution (e.g. true 4K) and then downconvert (e.g. to 1080p).? For this reason, it is hugely preferable to get a superior high speed camera (e.g. Phantom Flex 4K) instead of smartphone camera (e.g. iPhone in Slo-mo) when generating source footage.

You must minimize resolution loss to preserve UltraHFR benefits

Compression is a big blur problem.? Use less compression

You must minimize compression to preserve UltraHFR benefits

Lens autofocus is sometimes difficult during filming moving imagery.? It is especially amplified when your motion clarity is extremely sharp, to the point where any camera focus issues begin to become visible.

You must make sure focus is sharp during fast motion to preserve UltraHFR benefits

Be aware of the vicious cycle effect where higher resolutions demands higher refresh rates to eliminate resolution limitations. The difference between static images and moving images become much more pronounced at 8K than it is for 1080p, since motion blur is time-based (e.g. same amount of blur per inch, affects more pixels on higher DPI displays).? This is especially hard because current camera technology often goes lower resolution at higher frame rates.

You must use a higher resolution to preserve UltraHFR benefits

High frame rates benefits high motion material.? A great example is sportsfield panning, downhill skiing, BMX racing, car racing, etc.? When the first HDTVs arrived, some camera operators reported they had to intentionally slow down panning and operate slightly differently because LCD HDTV blur (of the first flat panel HDTVs) was much worse than old CRT motion clarity.

UltraHFR benefits fast motion material very significantly.

Many historical frame rate tests about frame rate benefits have often neglected to consider (1) (2) (3) (4) (5) (6)?simultaneously.

Research indicates that any one of the above can be a weak link in eliminating the benefits of UltraHFR video, and one must carefully control the variables to give truly human-visible benefits of UltraHFR. If you are planning any experiments in UltraHFR at maximum frame rates for the best possible Holodeck-league motion clarity, it is very important to know and understand the above variables.

Four Simple Fixes for Temporally Accurate Reality Simulation

To eliminate all weak links, so that remaining limitations is human-vision based. No camera-based or display-based limitations above and beyond natural human vision/brain limitations.

Fix source stroboscopic effect (camera): Must use a 360-degree camera shutter;

Fix destination stroboscopic effect (display): Must use a sample-and-hold display;

Fix source motion blur (camera): Must use a short camera exposure per frame;

Fix destination motion blur (display): Must use a short persistence per refresh cycle.

Therefore;

Ultra high frame rate with 360-degree camera shutter is also short camera exposure per frame;

Ultra high refresh rate with sample-and-hold display is also short persistence per refresh cycle,

Therefor, to solve (1), (2), (3), (4) simultaneously requires ultra high frame rates at ultra high refresh rates.

We Love Hollywood Movie Maker Mode Too: Full Control Of Entire Blur Chain

1000fps UltraHFR gives the director full control of motion blur, too.??1000fps UltraHFR is a huge venn digram capable of embedding the entire range of framerates in humankind.

With such fine granularities on an ultra-high-Hz displays, refresh rates no longer need to be evenly divisible by frame rate, in order to look smooth!

When 18fps, 23.97fps, 24fps, 25fps, 50fps, 59.94fps, 48fps, 60fps, are all played to a 1000Hz display, all framerates have their original look and motion blur. They play judderlessly without noticable pulldown judder (i.e. 3:2 pulldown) because of the unnoticeable ultrafine refresh rate granularity.

In other words, 24fps video embedded inside a UltraHFR-capable video file, played on a 1000Hz display, looks exactly like a 24Hz display — all with original camera motion blur and persistence blur.

The ability to go as blurry as you want (preserve camera blur / old frame rates) — and the ability to go virtually zero-blur as you want — is an amazing property of UltraHFR video files in the quadruple-digit framerate range.

Conclusion

At Blur Busters, we are among the few people in the world to have witnessed Ultra HFR video!

Being the founder of Blur Busters (Mark Rejhon), I used to work with video processor companies (RUNCO, Key Digital, and a PCI card containing a Faroudja chip). I was the author of the world’s first open source 3:2 pulldown deinterlacer algorithm twenty years ago in dScaler (Year 2000, Internet Archive).

We believe this is very useful for many applications in the coming decade, from speciality theatre, virtual reality, amusement park rides, advanced cinema, truly immersive virtual vacations, “Holodeck” video, and other applications once more 1000 Hz displays are commercially available beginning sometime within the next decade and beyond.

Related Reading

480Hz Displays —?World’s First 480Hz Monitor Review

1000Hz Displays —?Blur Busters Law: The Amazing Journey To Future 1000Hz Displays

Frame Rate Amplification Technology?— More Frame Rate With Less GPU Power Per Frame

Stroboscopic Effects — The Stroboscopic Effect of Finite Frame Rate Displays

Discussion Forum — High Frame Rate Video (HFR)

← LG’s UltraGear 38GN950 Priced and Released

Iiyama Announce the Curved G-Master GB3466WQSU For Gaming →

Share

About Mark Rejhon

Also known as Chief Blur Buster. Founder of Blur Busters. Inventor of TestUFO. Read more about him on the About Mark page.

View all posts by Mark Rejhon →

4 Comments For “Ultra HFR: 240fps Real Time Video Now Possible Today. 1000fps Tomorrow. [UPDATED]”

You must be logged in to post a comment.

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sort by: ?

newest |

oldest

| most liked

MemberDCGI made an older post with a game video sample at 4k 480fps.

Now I made new videos in 1080p and 1440p with higher motion scenes. Links below

1080p

https://1drv.ms/u/s!AiWtAukksSo7gxoGCKcuSwD1PsHS?e=yKRIfR

1440p

https://1drv.ms/u/s!AiWtAukksSo7gxsCD0sj5qQ4ecLO?e=DeNXF5

BRs

Like1Vote Down?3 years 8 months agoMemberPOVHFR VideosI do exactly this, only I have cameras that actually take 240fps with good sound. I have a Sony X1000v and a new GoPro Hero 6 black which take 720p and 1080p at 240fps. But I have been experimenting with higher frame rates up to 480fps and 960fps, they are on my YouTube. I even feature your website in my latest video. You are truly awesome, and it’s like we are on the same page with HFR Video and aiming to completely remove stroboscopic effects from video! Here is my Youtube Channel: https://www.youtube.com/channel/UCbevNF5HCoqWHoaotMoQMpw

Like1Vote Down?5 years 10 months agoAuthorMark RejhonGreat stuff, the problem is the best I’ve been able to get out of YouTube is 120fps — any HFR videos uploaded are downconverted, and so one has to upload 120fps slo-mo videos to YouTube, and then select “2x” YouTube playback speed.

So a lot of the 480fps and 960fps information is lost by YouTube if you speed up the videos to realtime HFR rather than slo-mo HFR. So we have to rely on *.mp4 downloads for HFR videos, rather than YouTube which decimates the framerate of non-slo-mo HFR videos.

Do you have the original 480fps and 960fps video files on disk? Maybe share them to me, so I can take a look directly at them, to see what can be done for presentation (e.g. on existing 240Hz gaming monitors, and my experimental 480Hz monitor).

Like1Vote Down?5 years 10 months agoAuthorMark RejhonOngoing UltraHFR experiments in the forums:

https://forums.blurbusters.com/viewtopic.php?f=20&t=4071&p=32839#p32838

Also a thread on reduser.net:

http://www.reduser.net/forum/showthread.php?165183-Cinematography-of-2030s-Ultra-HFR!-I-have-witnessed-realtime-1000fps-on-real-1000Hz

Test 720p 240fps realtime video:

GOOD:

MPV: Plays 720p 240fps UltraHFR fine

Windows Media Player: Plays 720p 240fps UltraHFR fine

Google Chrome embedded player: Plays 720p 240fps UltraHFR fine

BAD:

VLC: Plays but microstutters too much

FireFox embedded player: Plays but microstutters too much

We tested 540p 480fps on the Zisworks 480Hz display and it works, but only MPV succeeded. None of the other players could properly play 480fps.

Like0Vote Down?5 years 10 months ago

Recent Content

TestUFO 2.0 Display Motion Test Gaining HDR Support, Public Beta Launch on January 18th, 2024 January 10, 2024

NanoSys Exhibiting New Color Ghosting Demo on TestUFO 2.0 Beta January 10, 2024

New Blur Busters Logo Program 2.2 for OLED, LCD & Video Processors January 5, 2024

NVIDIA Announces ULMB 2 — Improved Motion Blur Reduction May 29, 2023

Blur Busters Forums

TestUFO Motion Tests

The #1 Site of Everything Better Than 60Hz?

Search for:

Best Gaming Monitors

Official Monitor List

AdvertisementFeatured Content

GtG versus MPRT: Frequently Asked Questions About Pixel Response On Displays May 7, 2019

The Basics of Network Lag – with Battle(non)sense September 27, 2017

Motion Blur Reduction (ULMB, LightBoost, etc) April 29, 2018

Test Results: 4K 120 Hz Display with bonus 1080p 240 Hz & 540p 480 Hz Modes August 16, 2017

Blur Busters Law: The Amazing Journey To Future 1000Hz Displays December 15, 2020

Home

Forums

TestUFO

About

Privacy

? 2024 Blur Busters | Theme by

jor-folio.com

1000 HZ linux kernel necessary if I have tickless and high resolution timer? - Server Fault

1000 HZ linux kernel necessary if I have tickless and high resolution timer? - Server Fault

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Loading…

Tour

Start here for a quick overview of the site

Help Center

Detailed answers to any questions you might have

Meta

Discuss the workings and policies of this site

About Us

Learn more about Stack Overflow the company, and our products

current community

Server Fault

help

chat

Meta Server Fault

your communities

Sign up or log in to customize your list.

more stack exchange communities

company blog

Log in

Sign up

Home

Questions

Tags

Users

Companies

Unanswered

Teams

Stack Overflow for Teams

– Start collaborating and sharing organizational knowledge.

Create a free Team

Why Teams?

Teams

Create free Team

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

1000 HZ linux kernel necessary if I have tickless and high resolution timer?

Ask Question

Asked

11 years, 11 months ago

Modified

7 years, 7 months ago

Viewed

19k times

14

I am trying to improve performance on my server. I have a few processes that need low jitter (less than 10ms variance).

I have a load average of 4 maximum on an i7-920 (4 physical cores, 8 with HT). There are about 10 processes ranging from 40% to 90% of a core user mode. System usage is 3% total. Total CPU usage is 80% max.

Will setting the kernel from 100hz to 1000hz improve the jitter if tickless and high resolution timers are already set?

This page seems to indicate it still does something. https://lkml.org/lkml/2009/4/28/401

How about changing from voluntary (PREEMPT_VOLUNTARY) to preemptible (PREEMPT)?

linuxlinux-kernel

Share

Improve this question

Follow

edited Apr 9, 2012 at 21:48

Bob

asked Apr 9, 2012 at 21:40

BobBob

19522 gold badges22 silver badges88 bronze badges

4

OS distribution details/version?

–?ewwhite

Apr 9, 2012 at 21:44

Ubuntu 11.10 64bit server Linux 3.3 kernel.

–?Bob

Apr 9, 2012 at 21:47

You have plenty of user mode load; system time is comparatively negligible. I wouldn't suggest to dance around kernel tunables there. Or obtaining realtime-like scheduling is what you hope to achive?

–?yrk

Apr 10, 2012 at 8:40

So are you saying if the system usage is low, none of this makes a difference on responsiveness?

–?Bob

Apr 10, 2012 at 20:21

Add a comment

?|?

3 Answers

3

Sorted by:

Reset to default

Highest score (default)

Date modified (newest first)

Date created (oldest first)

4

If low jitter is important to you, yes, you may want to use both 1000hz and PREEMPT.

If those processes are really time-sensitive, thought, you will probably need

some more realtime-oriented patches/kernels, or at least some process-level

scheduling parameters, like rtprio.

Typical uses are audio servers, see for example advice from jackaudio

Share

Improve this answer

Follow

answered Apr 11, 2012 at 16:43

koollmankoollman

13122 bronze badges

Add a comment

?|?

4

I am trying to improve performance on my server. I have a few processes that need low jitter (less than 10ms variance).

Any real time won't improve performance, it'd make the whole system running smoother but a bit slower, in fact. In other words, it's throughput vs. latency. If it's really what you need, then several options:

Use 300 Hz or even 1KHz, PREEMPT, and don't use tickless

Use nice, schedtool to assign proper priorities/classes according to your needs

Give a try to RT or BFS

Share

Improve this answer

Follow

answered Apr 11, 2012 at 16:54

poigepoige

9,51322 gold badges2626 silver badges5252 bronze badges

2

What's wrong with using tickless?

–?Bob

Apr 11, 2012 at 22:19

1

@Bob, It's good for powersaving, but in case you care about latency, it's recommended to be off, for e. g. ck.kolivas.org/patches/bfs/bfs-configuration-faq.txt

–?poige

Apr 12, 2012 at 1:16

Add a comment

?|?

3

1) Don't use tickless, it's still highly experimental and not recommended to anyone but developers working on it, it is also meant to help to powersave.

2) Fully preemtible system is supposed to increase responsiveness of desktor, while voluntary preemptible is for general use (mix of responsiveness and troughput).

If your server got SMP (multiple cores), you should probably go for non-preemptible, since most work will be executed on their cores and without interrupts, which generally 1) take time 2) trash cache

3) 1000Hz is desktop value which introduces overhead, but allows to for example play games and stuff. 300 hz is value that is recommended for video (so stuff can reschedule and you still won't miss frames), while 100Hz provides best troughput (though not geared for lowlatency network stuff).

If you want to go as stable as it gets (without using RT patches), you should go:

periodic ticks (stability)

non-preemptible (stability)

timer-frequency (up to you, 1000 for best responsiveness and low latiencies, 100 for best troughput but 10ms resolution on timer, e.g. stuff will run at least 10ms)

Hope this somewhat helps.

Share

Improve this answer

Follow

answered Nov 24, 2013 at 15:30

Tomas PruzinaTomas Pruzina

13133 bronze badges

Add a comment

?|?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged linuxlinux-kernel.

The Overflow Blog

How Stack Overflow is partnering with Google to encourage socially...

Featured on Meta

Our partnership with Google and commitment to socially responsible AI

Shifting the data dump schedule: A proposal

Visit chat

Related

0

High %system and %si cpu time on Linux

1

Need rpcsec_gss_krb5 and Linux kernel 2.6.35+ on EC2

0

ESXi :: vmxnet3 vNIC and Linux kernel errors

4

Linux Kernel and the init process

3

Linux high load with ImageMagick convert utility and server freezes (blktrack output attached)

0

Infiniband P_Keys and the Linux kernel

2

Why does my Linux Kernel have missing directories / files that are crucial for ip_tables to run?

0

Why do some servers have /etc/sysconfig/kernel and others do not?

Hot Network Questions

What is the etymology of “Israel”

Root incursion into a pipe under our house, I'm hoping there are bandaids because I can't afford the repair

Why is a filename surrounded by double quotes with single quotes around a character when displayed in terminal?

Are spacecraft visits to Uranus and Neptune hard to plan?

What game is this featured on the MSI Claw?

How to scale the weight of a RC model aircraft?

Is there some kind of law that even if data is legally compiled from public sources, it is illegal to collect too much and share it?

Are there languages L1 ? L2 ? L3 when L1 and L3 are NP-Complete languages and L2 ∈ P?

Lattice points visible from the origin

Scan input for numbers and add thousands separators

Would Lesser/Greater Restoration be able to cure a mental illness?

Does the official length of a movie include the credits?

SSH parameterized config entries?

Zero set of prime ideal

Strange comb spectrum found during EMI precompliance

Stealing when it is free?

Origin of the word "Tholian" in Star Trek

Is there another way to put an age limit to Congress members without making a constitutional amendment in the U.S.?

Why would a warrior tribe be dependant on a pacifist tribe?

Are there situations where a vertical bar chart is preferable to a horizontal one?

Why are bases corrosive?

Is it legal to sell emails?

Algebraic equation of a specific six-degree polynomial

Safe, easy way to tap into taut NM cable in wall?

more hot questions

Question feed

Subscribe to RSS

Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Server Fault

Tour

Help

Chat

Contact

Feedback

Company

Stack Overflow

Teams

Advertising

Collectives

Talent

About

Press

Legal

Privacy Policy

Terms of Service

Cookie Settings

Cookie Policy

Stack Exchange Network

Technology

Culture & recreation

Life & arts

Science

Professional

Business

API

Data

Blog

Facebook

Twitter

LinkedIn

Instagram

Site design / logo ? 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev?2024.3.12.6097

【FPS手柄科普】玄學(xué)?智商稅?1000Hz有沒有用?3分鐘帶你了解手柄回報(bào)率_嗶哩嗶哩_bilibili

【FPS手柄科普】玄學(xué)?智商稅?1000Hz有沒有用?3分鐘帶你了解手柄回報(bào)率_嗶哩嗶哩_bilibili 首頁番劇直播游戲中心會(huì)員購漫畫賽事投稿【FPS手柄科普】玄學(xué)?智商稅?1000Hz有沒有用?3分鐘帶你了解手柄回報(bào)率

1.6萬

9

2023-07-19 17:51:09

未經(jīng)作者授權(quán),禁止轉(zhuǎn)載311976236墨將一直以玩家需求為已任,只要玩家有需求,我們就努力做

一個(gè)好的搖桿需要綜合的指標(biāo),硬件只是參數(shù)之一,包括回報(bào)率和采樣精度,還要有優(yōu)秀的搖桿算法

一個(gè)好的產(chǎn)品也不單是搖桿為評判單項(xiàng),致力打造國內(nèi)優(yōu)秀手柄,是我們國內(nèi)廠商一起努力的目標(biāo)游戲知識(shí)分享官科技數(shù)碼超頻射擊游戲APEX英雄FPS手柄手柄回報(bào)率手柄采樣精度ps51000Hz墨將彩虹2pro

墨將BIGBIG-WON官方賬號

發(fā)消息

PLAY BIG . WON BIG.

關(guān)注 3.0萬

AI女友太香了,邊玩游戲邊戀愛~

接下來播放

自動(dòng)連播超頻1000hz的ds5手柄遠(yuǎn)距離壓槍是怎么樣的草苺餡餃子

7393

0

【APEX手柄】手柄超頻保姆級教學(xué)丨輸入延遲?檢測?輪詢率?統(tǒng)統(tǒng)搞定!EMC-

4.2萬

7

1000hz回報(bào)率太吃性能了吧!WallyGonzalez

2.5萬

1

這就是dse原生1000hz給我的自信1nfpBlue

5917

0

深夜淺試一下手柄超頻的手感叭Kazephyr4

9717

0

手柄超頻第二天Kazephyr4

3021

0

DPI800,回報(bào)率500,垂直1,其它全部是調(diào)的30小晗游戲解說

3206

2

【包】2023年了 4K鼠標(biāo)有必要了嗎?Bread包包

4.7萬

56

【APEX】當(dāng)我把鼠標(biāo)回報(bào)率調(diào)到8000hz會(huì)怎樣?-卡岡都亞-

1.9萬

4

1000hz回報(bào)率的手柄,你見過嗎劉玥于凈又衛(wèi)生

937

1

致動(dòng)o+與墨將彩虹2pro到底誰更適合打apex,回報(bào)率造假風(fēng)波下到底選擇誰更合適?佘林SL

2.2萬

6

我現(xiàn)在才知道1000鼠標(biāo)回報(bào)率有多吃性能!MockingBird1216

24.9萬

48

全方向TS!禁用steam輸入的新方法,ps手柄可用,不會(huì)降低手柄回報(bào)率Iris_dantalion

4.7萬

1

(APEX)原來鼠標(biāo)125hz回報(bào)率跟1000回報(bào)率差距這么大?VVVZQ

3.8萬

2

實(shí)測鍵盤回報(bào)率與輸入延遲的關(guān)系:125,250,500,1000Hz USB vs PS2_問天_

3.8萬

8

300起步的手柄打Apex能鎖住嗎?快樂滋崩在這里

15.6萬

54

如何進(jìn)行手柄超頻,首個(gè)手柄超頻教學(xué)?。u5enPai

4.9萬

9

dualsense edge 純純垃圾手柄Yujraaa

2.2萬

11

關(guān)于手柄回報(bào)率的個(gè)人觀點(diǎn)-搬運(yùn)測評看空間新視頻鹿鳴淺夏_Official

2537

3

4000赫茲回報(bào)率能帶來提升嗎?帶帶稚寶

1.3萬

4

展開

小窗

客服

頂部

賽事庫 課堂 2021

赫茲到每秒幀數(shù)轉(zhuǎn)換表:赫茲到每秒幀數(shù)(Hz到FPS)計(jì)算器

赫茲到每秒幀數(shù)轉(zhuǎn)換表:赫茲到每秒幀數(shù)(Hz到FPS)計(jì)算器

CitizenMaths

頻率

亮度

體積

力量

力量

加速

化學(xué)用量

區(qū)域

壓力

發(fā)光強(qiáng)度

密度

扭矩

數(shù)據(jù)存儲(chǔ)

時(shí)間

溫度

照度

燃油經(jīng)濟(jì)性(里程)

電位

電流

電荷

能量、功和熱

角度

貨幣

質(zhì)量流量

資料傳輸率

速度

重量和質(zhì)量

長度

面積密度

頻率

簡體中文

English

Deutsch

Nederlands

Fran?ais

Espa?ol

Italiano

Português (PT)

Norsk

Suomi

Svenska

Dansk

?e?tina

Magyar

Roman?

日本語

簡體中文

繁體中文

Polski

Ελληνικ?

Русский

Türk?e

Български

???????

???

?????

Latviski

Укра?нська

Bahasa Indonesia

???????

Eesti

Hrvatski

Lietuvi?

Sloven?ina

Srpski

Sloven??ina

Ti?ng Vi?t

íslenska

從赫茲到每秒幀數(shù)的轉(zhuǎn)換

赫茲

兆赫

分赫茲

十赫茲

千兆赫茲

千赫

厘赫茲

太赫茲

太赫茲

度每秒

微赫茲

每分鐘動(dòng)作

每分鐘度數(shù)

每分鐘弧度

每分鐘循環(huán)

每分鐘轉(zhuǎn)數(shù)

每天循環(huán)

每小時(shí)度數(shù)

每小時(shí)弧度

每小時(shí)循環(huán)

每年周期

每微秒周期

每月周期

每毫秒周期

每毫秒度數(shù)

每毫秒弧度

每皮秒周期

每秒周期

每秒幀數(shù)

每秒弧度

每納秒周期

毫赫茲

澤塔赫茲

澤普赫茲

皮赫茲

約塔赫茲

約赫茲

納赫茲

艾赫茲

菲涅爾

赫茲

赫茲

阿托赫茲

飛赫茲

每秒幀數(shù)

兆赫

分赫茲

十赫茲

千兆赫茲

千赫

厘赫茲

太赫茲

太赫茲

度每秒

微赫茲

每分鐘動(dòng)作

每分鐘度數(shù)

每分鐘弧度

每分鐘循環(huán)

每分鐘轉(zhuǎn)數(shù)

每天循環(huán)

每小時(shí)度數(shù)

每小時(shí)弧度

每小時(shí)循環(huán)

每年周期

每微秒周期

每月周期

每毫秒周期

每毫秒度數(shù)

每毫秒弧度

每皮秒周期

每秒周期

每秒幀數(shù)

每秒弧度

每納秒周期

毫赫茲

澤塔赫茲

澤普赫茲

皮赫茲

約塔赫茲

約赫茲

納赫茲

艾赫茲

菲涅爾

赫茲

赫茲

阿托赫茲

飛赫茲

兌換

公式 1295 Hz = 1295 / 1 FPS = 1295.0 FPS

每秒幀數(shù) to 赫茲

如何從赫茲轉(zhuǎn)換為每秒幀數(shù)

1 赫茲 相當(dāng)于 1 每秒幀數(shù):

1 Hz = 1 FPS

例如, 如果赫茲的數(shù)字為(600),則其等效的每秒幀數(shù)的數(shù)字為(600).

公式:

600 Hz = 600 / 1 FPS = 600 FPS

從赫茲到每秒幀數(shù)的轉(zhuǎn)換表

赫茲 (Hz)

每秒幀數(shù) (FPS)

1 Hz

1 FPS

2 Hz

2 FPS

3 Hz

3 FPS

4 Hz

4 FPS

5 Hz

5 FPS

6 Hz

6 FPS

7 Hz

7 FPS

8 Hz

8 FPS

9 Hz

9 FPS

10 Hz

10 FPS

11 Hz

11 FPS

12 Hz

12 FPS

13 Hz

13 FPS

14 Hz

14 FPS

15 Hz

15 FPS

16 Hz

16 FPS

17 Hz

17 FPS

18 Hz

18 FPS

19 Hz

19 FPS

20 Hz

20 FPS

21 Hz

21 FPS

22 Hz

22 FPS

23 Hz

23 FPS

24 Hz

24 FPS

25 Hz

25 FPS

26 Hz

26 FPS

27 Hz

27 FPS

28 Hz

28 FPS

29 Hz

29 FPS

30 Hz

30 FPS

31 Hz

31 FPS

32 Hz

32 FPS

33 Hz

33 FPS

34 Hz

34 FPS

35 Hz

35 FPS

36 Hz

36 FPS

37 Hz

37 FPS

38 Hz

38 FPS

39 Hz

39 FPS

40 Hz

40 FPS

41 Hz

41 FPS

42 Hz

42 FPS

43 Hz

43 FPS

44 Hz

44 FPS

45 Hz

45 FPS

46 Hz

46 FPS

47 Hz

47 FPS

48 Hz

48 FPS

49 Hz

49 FPS

50 Hz

50 FPS

51 Hz

51 FPS

52 Hz

52 FPS

53 Hz

53 FPS

54 Hz

54 FPS

55 Hz

55 FPS

56 Hz

56 FPS

57 Hz

57 FPS

58 Hz

58 FPS

59 Hz

59 FPS

60 Hz

60 FPS

61 Hz

61 FPS

62 Hz

62 FPS

63 Hz

63 FPS

64 Hz

64 FPS

65 Hz

65 FPS

66 Hz

66 FPS

67 Hz

67 FPS

68 Hz

68 FPS

69 Hz

69 FPS

70 Hz

70 FPS

71 Hz

71 FPS

72 Hz

72 FPS

73 Hz

73 FPS

74 Hz

74 FPS

75 Hz

75 FPS

76 Hz

76 FPS

77 Hz

77 FPS

78 Hz

78 FPS

79 Hz

79 FPS

80 Hz

80 FPS

81 Hz

81 FPS

82 Hz

82 FPS

83 Hz

83 FPS

84 Hz

84 FPS

85 Hz

85 FPS

86 Hz

86 FPS

87 Hz

87 FPS

88 Hz

88 FPS

89 Hz

89 FPS

90 Hz

90 FPS

91 Hz

91 FPS

92 Hz

92 FPS

93 Hz

93 FPS

94 Hz

94 FPS

95 Hz

95 FPS

96 Hz

96 FPS

97 Hz

97 FPS

98 Hz

98 FPS

99 Hz

99 FPS

100 Hz

100 FPS

200 Hz

200 FPS

300 Hz

300 FPS

400 Hz

400 FPS

500 Hz

500 FPS

600 Hz

600 FPS

700 Hz

700 FPS

800 Hz

800 FPS

900 Hz

900 FPS

1000 Hz

1000 FPS

1100 Hz

1100 FPS

赫茲轉(zhuǎn)換為不同的單位

赫茲 to 兆赫

赫茲 to 分赫茲

赫茲 to 十赫茲

赫茲 to 千兆赫茲

赫茲 to 千赫

赫茲 to 厘赫茲

赫茲 to 太赫茲

赫茲 to 太赫茲

赫茲 to 度每秒

赫茲 to 微赫茲

赫茲 to 每分鐘動(dòng)作

赫茲 to 每分鐘度數(shù)

赫茲 to 每分鐘弧度

赫茲 to 每分鐘循環(huán)

赫茲 to 每分鐘轉(zhuǎn)數(shù)

赫茲 to 每天循環(huán)

赫茲 to 每小時(shí)度數(shù)

赫茲 to 每小時(shí)弧度

赫茲 to 每小時(shí)循環(huán)

赫茲 to 每年周期

赫茲 to 每微秒周期

赫茲 to 每月周期

赫茲 to 每毫秒周期

赫茲 to 每毫秒度數(shù)

赫茲 to 每毫秒弧度

赫茲 to 每皮秒周期

赫茲 to 每秒周期

赫茲 to 每秒弧度

赫茲 to 每納秒周期

赫茲 to 毫赫茲

赫茲 to 澤塔赫茲

赫茲 to 澤普赫茲

赫茲 to 皮赫茲

赫茲 to 約塔赫茲

赫茲 to 約赫茲

赫茲 to 納赫茲

赫茲 to 艾赫茲

赫茲 to 菲涅爾

赫茲 to 赫茲

赫茲 to 阿托赫茲

赫茲 to 飛赫茲

頻率

赫茲

Hz 至 FPS

版權(quán) ? UnitConverter 閱讀我們的 使用條款 和 隱私政策

鼠標(biāo)的技術(shù)參數(shù):125HZ、1000HZ 和 1800dpi、3500dpi 分別是描述什么特性的?有什么參考價(jià)值? - 知乎

鼠標(biāo)的技術(shù)參數(shù):125HZ、1000HZ 和 1800dpi、3500dpi 分別是描述什么特性的?有什么參考價(jià)值? - 知乎首頁知乎知學(xué)堂發(fā)現(xiàn)等你來答?切換模式登錄/注冊鼠標(biāo)鼠標(biāo)的技術(shù)參數(shù):125HZ、1000HZ 和 1800dpi、3500dpi 分別是描述什么特性的?有什么參考價(jià)值?關(guān)注者7被瀏覽89,403關(guān)注問題?寫回答?邀請回答?好問題?添加評論?分享?3 個(gè)回答默認(rèn)排序知乎用戶游戲鼠標(biāo)推薦前瞻篇:一些我們選購時(shí)需要考慮的技術(shù)參數(shù) 由 土老逼 發(fā)表在·游戲區(qū) https://bbs.hupu.com/game大家好,這里是破廢玩家一年N++次次次的游戲外設(shè)推薦時(shí)間啦,因?yàn)檫@次選購?fù)扑]是來自虎撲游戲區(qū)的大佬舊城的邀請。因此我們這次選購?fù)扑]也會(huì)從游戲角度出發(fā),分別為FPS類游戲和MOBA類游戲推薦各自適合的外設(shè)產(chǎn)品。本篇是一個(gè)前瞻篇,主要目的是給大家講解一下我們常見的游戲鼠標(biāo)的參數(shù)含義和術(shù)語,目的仍然是讓大家在閱讀之后做到心里有譜,不僅僅知道知道我們推薦的哪些鼠標(biāo),同時(shí)也能知道我們?yōu)槭裁磿?huì)推薦這些鼠標(biāo)。同時(shí)也歡迎大家閱讀我們之前的選購思路文:理清思路,如何選擇一款適合自己的游戲鼠標(biāo)?第一部分:常見的技術(shù)參數(shù)首先就是我們常見的技術(shù)參數(shù)啦,網(wǎng)上大部分鼠標(biāo)在銷售介紹頁面都會(huì)清晰的標(biāo)明自己的傳感器參數(shù),比如CPI和IPS這些技術(shù)縮寫。因此我們需要知道光學(xué)鼠標(biāo)基礎(chǔ)的工作原理:光學(xué)鼠標(biāo)的傳感器可以理解成一個(gè)微型的相機(jī)鏡頭,通過高速拍照對比分析從而計(jì)算出鼠標(biāo)在桌面的移動(dòng)方向和距離等信息。接下來,就讓我們就來了解一下這些參數(shù)分別代表什么意思,以及是如何影響我們的游戲性能。靈敏度(DPI/CPI):DPI英文全稱是“dots per inch”,翻譯為“每英寸像素”,意思是每英寸的像素?cái)?shù)。(1 英寸=2.54cm),是指鼠標(biāo)內(nèi)的解碼裝置所能辨認(rèn)每英寸長度內(nèi)像素?cái)?shù)。換言之就是:我們用了一款最大DPI為18000的旗艦級別游戲鼠標(biāo),那么鼠標(biāo)在鼠標(biāo)墊上每移動(dòng)一英寸,鼠標(biāo)指針便會(huì)在屏幕上移動(dòng)18000個(gè)像素點(diǎn)。這也是為什么在1080P和4K顯示器上使用同樣的DPI鼠標(biāo),卻會(huì)感覺到鼠標(biāo)的移動(dòng)速度有差別。而除了DPI之外,我們也可以經(jīng)??匆娨恍┦髽?biāo)品牌會(huì)使用CPI來描述傳感器的參數(shù),并且看起來和DPI并沒有多大差別。其實(shí)CPI的英文全稱是“count per inch”,翻譯為“每英寸的測量次數(shù)”,指的是鼠標(biāo)在物理表面上每移動(dòng)1英寸(約2.54厘米)時(shí)其傳感器所能接收到的坐標(biāo)數(shù)量。兩者的區(qū)別主要在于一個(gè)是以靜態(tài)為標(biāo)準(zhǔn)計(jì)算,一個(gè)是以動(dòng)態(tài)為標(biāo)準(zhǔn)計(jì)算。所以其實(shí)本質(zhì)上兩者僅僅是說法上的不同,在中文中都可以簡單的稱之為靈敏度。同時(shí)我們在選購產(chǎn)品的時(shí)候也都能發(fā)現(xiàn),目前主流鼠標(biāo)產(chǎn)品的最大DPI/CPI值早已遠(yuǎn)遠(yuǎn)超過我們?nèi)粘J褂玫脑O(shè)置值。因此,目前鼠標(biāo)宣傳的最大DPI和CPI值更多是廠商對鼠標(biāo)傳感器級別的展示,并不是我們選購鼠標(biāo)首先要考慮的剛性需求。追蹤速度(IPS):IPS的英文全稱是Inches Per Second,直譯為每秒移動(dòng)的最大英寸數(shù)。通常指的是光學(xué)鼠標(biāo)傳感器的最大的識(shí)別速度值。如果玩家移動(dòng)鼠標(biāo)的速度超過這個(gè)速度,傳感器將不能識(shí)別,同時(shí)屏幕上的指針可能是跳一下,或者直接從屏幕一段飛到另一端,也就是大家常說的“跳幀”。通常情況下如今的大部分游戲鼠標(biāo)即使是入門游戲鼠標(biāo)的IPS值也能達(dá)到150以上,旗艦級別游戲鼠標(biāo)的IPS值則普遍在400以上。同時(shí)根據(jù)原相官網(wǎng)與其他社區(qū)的一些相關(guān)資料可以得知:我們正常在使用鼠標(biāo)的時(shí)候瞬時(shí)IPS速度在50左右,即使是職業(yè)的FPS選手在大范圍甩拉瞄準(zhǔn)時(shí)的瞬時(shí)爆發(fā)IPS往往也不會(huì)超過150。因此IPS這個(gè)參數(shù)對于大部分玩家來說也同樣是一個(gè)性能相對溢出的參數(shù)。加速度值(G)鼠標(biāo)加速度值指的是鼠標(biāo)由慢到突然加速,然后后又慢下來的過程。整體行動(dòng)過程類似于物理移動(dòng)中的加速度現(xiàn)象。加速度是矢量的形式,即同時(shí)有數(shù)值大小與方向變化的物理量,因此加速度值的單位為G,鼠標(biāo)的G值就是鼠標(biāo)每秒之間移動(dòng)速度變化不能超過的單位值。目前市面上的游戲鼠標(biāo)加速度大多在20G-50G之間,已經(jīng)能夠很好的滿足玩家的日常游戲需求,當(dāng)然如果同樣價(jià)位,選G值大一些的產(chǎn)品總歸是不虧。響應(yīng)回報(bào)速度鼠標(biāo)響應(yīng)速度又稱報(bào)告率,是指每秒鐘鼠標(biāo)傳送數(shù)據(jù)給計(jì)算機(jī)的次數(shù)。例如:響應(yīng)500Hz即表示在一秒鐘之內(nèi)鼠標(biāo)向計(jì)算機(jī)傳送了500次數(shù)據(jù);通常情況下次數(shù)越多則鼠標(biāo)光標(biāo)的移動(dòng)越細(xì)膩滑順,點(diǎn)擊也更為精準(zhǔn)。目前大多數(shù)主流游戲均能夠支持1000hz的報(bào)告率,當(dāng)然少數(shù)古代游戲如CF無法做到支持1000hz,因此專業(yè)游戲鼠標(biāo)仍然可以自由切換報(bào)告率的同時(shí)響應(yīng)速度均能達(dá)到1000HZ(不過也有一些高端千元鼠標(biāo)只能達(dá)到500HZ的),同時(shí)大多數(shù)藍(lán)牙鼠標(biāo)則無法達(dá)到一個(gè)很好的響應(yīng)速度,這也是為什么藍(lán)牙技術(shù)往往可以用在不需要記錄軌跡的機(jī)械鍵盤上,卻無法使用在高性能游戲鼠標(biāo)上的原因。靈敏度、追蹤速度、加速度值與響應(yīng)速度在一起被稱為游戲鼠標(biāo)引擎的四大參數(shù)指標(biāo)。其實(shí)在如今大多數(shù)正規(guī)品牌的游戲鼠標(biāo)的這些參數(shù)已經(jīng)性能大幅度溢出,并不會(huì)影響我們?nèi)粘5氖褂谩2贿^通過對比這些參數(shù)也能夠初步判斷出一款鼠標(biāo)引擎的級別與檔次,換言之:這些參數(shù)本身并不重要,但卻是我們選購鼠標(biāo)時(shí)候的重要參考信息。第二部分:抖動(dòng)、修正1:1追蹤:1:1追蹤也是我們經(jīng)常見到的一些高端游戲鼠標(biāo)的主打賣點(diǎn),“1:1追蹤在電子競技中尤為重要,可以理解為減少鼠標(biāo)移動(dòng)過程中的抖動(dòng)問題,并且在修正抖動(dòng)算法作用下,保持鼠標(biāo)的高速響應(yīng)。我們可以看到很多不同類型游戲的職業(yè)選手會(huì)有“打樁”等重復(fù)性的訓(xùn)練,是為了訓(xùn)練大腦對某些特定動(dòng)作做出下意識(shí)反應(yīng)和肌肉記憶,而在這種操作中任何細(xì)微的偏差都會(huì)影響肌肉記憶的準(zhǔn)確度。而1:1追蹤的性能則可以對任何不準(zhǔn)確的動(dòng)作進(jìn)行修正,無論是平滑修正還是直線修正都準(zhǔn)確無誤。對于職業(yè)選手來說,這種穩(wěn)定的競技性能也更適合訓(xùn)練肌肉記憶,把日常訓(xùn)練的效果更好地運(yùn)用在競技賽場上;而對于普通玩家來說,不僅能有更穩(wěn)定的游戲操縱體驗(yàn),而且能更暢快的投入游戲?!逼鋵?shí)嚴(yán)格來說只要是光學(xué)設(shè)備都有偏差值造成的抖動(dòng),因此沒有產(chǎn)品可以完全達(dá)到1:1追蹤,所以廠商們所說的“1:1追蹤”通常指的是將抖動(dòng)控制在一個(gè)極小的正負(fù)偏差范圍之內(nèi),無限接近1:1。(某型號鼠標(biāo)追蹤抖動(dòng)實(shí)際測試值)直線修正與1:1追蹤一同出現(xiàn)的往往還有另外一個(gè)名詞:“直線修正”。直線修正是指通過軟件算法的手段對鼠標(biāo)移動(dòng)過程中的抖動(dòng)進(jìn)行修正,通俗的說就是能讓我們畫的線更直,畫的圓更圓。這個(gè)功能在各種辦公鼠標(biāo)當(dāng)中大量運(yùn)用,在畫圖做表等場景中可以起到良好的輔助作用。而在游戲鼠標(biāo)中,直線修正往往就非常致命且多余,尤其是在一些FPS競技類游戲中,會(huì)讓我們的瞄準(zhǔn)出現(xiàn)偏差。因此選購FPS游戲鼠標(biāo),一定要注意選擇不帶直線修正的產(chǎn)品。鼠標(biāo)LODLOD即為鼠標(biāo)的響應(yīng)高度,為鼠標(biāo)抬起多少高度以后傳感器停止響應(yīng)定的數(shù)值,鼠標(biāo)LOD高度對于一些有抬鼠習(xí)慣的玩家來說比較重要。在早年間大部分光學(xué)引擎的LOD值都是固定的,后來的一些鼠標(biāo)則能通過定制透鏡來等一些手段改變引擎響應(yīng)高度。近兩年則出現(xiàn)了可以調(diào)節(jié)LOD高度的鼠標(biāo)產(chǎn)品,而最新的頂級游戲鼠標(biāo)引擎則已經(jīng)發(fā)展出了非對稱終止技術(shù),即可以分別設(shè)置鼠標(biāo)抬起和放下時(shí)的LOD高度,從而在抬起鼠標(biāo)時(shí)保留一定工作高度避免傳感器降速,再放下鼠標(biāo)時(shí)則不讓鼠標(biāo)過早進(jìn)入工作區(qū)域,避免對焦造成的抖動(dòng)。第三部分:重量、尺寸、連接方式等常見參數(shù)相較于之前的一些硬件參數(shù),鼠標(biāo)的重量、尺寸、外形等相對更加主觀,更多的取決于玩家主觀的使用體驗(yàn)以及握持習(xí)慣、手掌大小,鼠標(biāo)外形等等,因此這里就不過多贅述。這里放一張初篩表,更多的外型選購的思路和內(nèi)容大家可以閱讀之前的文章:理清思路,如何選擇一款適合自己的游戲鼠標(biāo)?好了,以上就是一些鼠標(biāo)參數(shù)名詞的解釋和解讀,本期相對有些枯燥乏味,主要還是科普為主,給大家分享一些鼠標(biāo)選購中需要注意的參數(shù)信息。對于破廢玩家而言,我們更希望讓大家懂產(chǎn)品,能夠和我們一樣閱讀出產(chǎn)品設(shè)計(jì)中的思路和亮點(diǎn)。接下來的后續(xù)部分則會(huì)更加簡單直接的給大家推薦適合FPS和MOBA的外設(shè)產(chǎn)品,還請大家多多關(guān)注支持我們喲。發(fā)布于 2021-01-29 10:33?贊同 72??3 條評論?分享?收藏?喜歡收起?莊明浩(rosicky311)?2020 年度新知答主? 關(guān)注 HZ那個(gè) 是相應(yīng)頻率 其實(shí)這個(gè)東西和你顯示器的頻率也有關(guān)系~現(xiàn)在一般好一些的鼠標(biāo) 驅(qū)動(dòng)里都支持125-1000HZ的調(diào)節(jié)DPI樓上的哥們已經(jīng)說了 1800DPI是蝰蛇老版本的DPI 3500是新版的 具體介紹看這里:http://www.pcwaishe.cn/viewthread.php?tid=7569&highlight=DPI關(guān)于鼠標(biāo)的DPI,掃描頻率,像素處理能力 以及 USB報(bào)告率的一些知識(shí)專業(yè)文檔 如果你需要的話~ 發(fā)布于 2011-03-14 09:29?贊同 11??添加評論?分享?收藏?喜歡收起??

csv - How can I increase the frequency rate of my Python programme in VSCode? Input: GSV2 Measuring amplifier 1000Hz. Realtime - Stack Overflow

csv - How can I increase the frequency rate of my Python programme in VSCode? Input: GSV2 Measuring amplifier 1000Hz. Realtime - Stack Overflow

Stack Overflow

About

Products

For Teams

Stack Overflow

Public questions & answers

Stack Overflow for Teams

Where developers & technologists share private knowledge with coworkers

Talent

Build your employer brand

Advertising

Reach developers & technologists worldwide

Labs

The future of collective knowledge sharing

About the company

Loading…

current community

Stack Overflow

help

chat

Meta Stack Overflow

your communities

Sign up or log in to customize your list.

more stack exchange communities

company blog

Log in

Sign up

Home

Questions

Tags

Users

Companies

Labs

Discussions

New

Collectives

Explore Collectives

Teams

Stack Overflow for Teams

– Start collaborating and sharing organizational knowledge.

Create a free Team

Why Teams?

Teams

Create free Team

Collectives? on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs

How can I increase the frequency rate of my Python programme in VSCode? Input: GSV2 Measuring amplifier 1000Hz. Realtime

Ask Question

Asked

1 year ago

Modified

1 year ago

Viewed

16 times

0

I have written a code in Python that should read a Measuring amplifier value with 1000Hz and save it with the current time in a CSV file. However, only a maximum of around 100Hz is achieved. Although the sensor/Measuring amplifier actually sends 1000Hz. Reducing the data frequency from the measuring amplifier works perfectly. Increasing it also only works up to 100Hz. Is there a way to save the 1000 measurement data per second in my CSV? Or to process it in real time in Python?

PS: Baud rate is high enough

Datasheet Measuring amplifier

import serial

import csv

import time

from datetime import datetime

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as FuncAnimation

def gsvStart():

serialConnection.write(b'\x24')

def gsvStop():

serialConnection.write(b'\x23')

def gsvSetZero():

serialConnection.write(b'\x0C')

def gsvWriteSamplingRate():

serialConnection.write(b'\x8A')

# 8000 Samples per Second / 8 -- Manual Page 44

def gsvWriteSamplingRate8000():

serialConnection.write(b'\x8A\x08\xFD\xF8')

# 9765 Samples per Second / 8

def gsvWriteSamplingRate9765():

serialConnection.write(b'\x8A08FE00')

def convertMeasFrameToMeasValue(MeasFrame):

return ((MeasFrame[0] * 256 + MeasFrame[1])-32768)/32768

#Moving Average

readings=[]

max_samples=10

def mean(nums):

return float(sum(nums)) / max (len(nums), 1)

#create a csv file

now = datetime.now()

filename = now.strftime("%d-%b-%Y-%H_%M_%S")

fname = lambda : "{}.csv".format(filename)

fieldnames = ["Zeit", "Kraft ungefiltert", "Kraft AVG 0,2s"]

with open(fname(), 'w', newline='') as csv_file:

csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)

csv_writer.writeheader()

if __name__ == '__main__':

serialConnection = serial.Serial("COM3", 38400, timeout=1)

serialConnection.isOpen()

gsvStop()

serialConnection.write(b'\x25')

serialConnection.flushInput()

serialConnection.flushOutput()

serialConnection.write(b'\x8A')

serialConnection.write(b'\x08\xFD\x8F')

serialConnection.write(b'\x8B')

serialConnection.write(b'\x83')

SRregcontent = serialConnection.read(2)

print("SR: ", SRregcontent)

gsvStart()

for i in range(10):

praefix = serialConnection.read(1)

if praefix == 0xA5.to_bytes(1, byteorder='big'):

MeasVal = serialConnection.read(2) # .hex()

print(convertMeasFrameToMeasValue(MeasVal))

gsvSetZero()

try:

while 1:

praefix = serialConnection.read(1)

if praefix == 0xA5.to_bytes(1, byteorder='big'):

MeasVal = serialConnection.read(2) # .hex()

#Scale in [N]

wert=999.101*convertMeasFrameToMeasValue(MeasVal)

#Moving Average

readings.append(wert)

avg = mean(readings)

if len(readings) == max_samples:

readings.pop(0)

#Time

now = datetime.now()

current_time = now.strftime("%H:%M:%S:%f")

#In Csv

with open(fname(), 'a', newline='') as csv_file:

csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)

info = {

"Zeit": current_time,

"Kraft ungefiltert": wert,

"Kraft AVG 0,2s": avg

}

csv_writer.writerow(info)

except:

pass

serialConnection.close()```

Frequency reduced works.

Even if I only output the time 1000 times in another programme, I reach a maximum of 300Hz (without measuring amplifier input).

csvfrequency

Share

Improve this question

Follow

asked Mar 10, 2023 at 9:27

TinoTino

1

Add a comment

?|?

Related questions

315

How to skip the headers when processing a csv file using Python?

116

How can I compute a histogram (frequency table) for a single Series?

2

How can you get the sample rate frequency of the iphone accelerometer?

Related questions

315

How to skip the headers when processing a csv file using Python?

116

How can I compute a histogram (frequency table) for a single Series?

2

How can you get the sample rate frequency of the iphone accelerometer?

0

How to get the frequency of the input from mic

2

Pharo: How to increase MouseMoveEvent Frequency?

1

How can i extract the frequency from WAV file - python

0

How can I select a frequency if the frequency range is given?

1

Python-3.x Count the frequency of a specific number from user input

1

how can I find the frequency?

Load 6 more related questions

Show fewer related questions

0

Sorted by:

Reset to default

Highest score (default)

Trending (recent votes count more)

Date modified (newest first)

Date created (oldest first)

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved

Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email

Required, but never shown

Post as a guest

Name

Email

Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged csvfrequency or ask your own question.

The Overflow Blog

How Stack Overflow is partnering with Google to encourage socially...

Featured on Meta

Our partnership with Google and commitment to socially responsible AI

Shifting the data dump schedule: A proposal

Temporary policy: Generative AI (e.g., ChatGPT) is banned

2024 Community Moderator Election Results

Hot Network Questions

Is it legal to sell emails?

Scan input for numbers and add thousands separators

What's the biggest hurdle that prevents the EPA from implementing stricter limits on particulate matter?

Showing inequality involving log

Would Lesser/Greater Restoration be able to cure a mental illness?

Who pays for the damages caused by the government attempting to enforce a preempted or unconstitutional law?

Regular expression to match a concatenation of fixed strings, and alternative expressions

Command for Multiplying Integers

String.join() vs. .toString() in Apex

What are Christian guidelines for making the transition from "knowing about God" to "knowing God"?

Chee Ops stations

Safe, easy way to tap into taut NM cable in wall?

Is linear regression still relevant in a mid-level DS interview?

What is the origin of the simulacrum spell?

How many hours spending learning a day

Proving the Value of a Unique Infinitely Nested Radical

Proving formula for feedback for operational amplifiers

Cut folder names out of string

Is utilizing a singleton for a cache an antipattern?

Why is a filename surrounded by double quotes with single quotes around a character when displayed in terminal?

Lattice points visible from the origin

Are there languages L1 ? L2 ? L3 when L1 and L3 are NP-Complete languages and L2 ∈ P?

PTIJ: Why get drunk specifically in bed?

Linking quaver and semiquaver beams over a rest with LilyPond

more hot questions

Question feed

Subscribe to RSS

Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Stack Overflow

Questions

Help

Products

Teams

Advertising

Collectives

Talent

Company

About

Press

Work Here

Legal

Privacy Policy

Terms of Service

Contact Us

Cookie Settings

Cookie Policy

Stack Exchange Network

Technology

Culture & recreation

Life & arts

Science

Professional

Business

API

Data

Blog

Facebook

Twitter

LinkedIn

Instagram

Site design / logo ? 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev?2024.3.12.6097

從光電算法到1000Hz回報(bào)率:北通宙斯pro 游戲手柄的獨(dú)特之處 - 知乎

從光電算法到1000Hz回報(bào)率:北通宙斯pro 游戲手柄的獨(dú)特之處 - 知乎切換模式寫文章登錄/注冊從光電算法到1000Hz回報(bào)率:北通宙斯pro 游戲手柄的獨(dú)特之處時(shí)光之光專注數(shù)碼產(chǎn)品評測與體驗(yàn)/商業(yè)影像圖像處理從業(yè)者/人像攝影師引入最近拿到了一款新手柄,北通宙斯pro

游戲手柄——作為北通宙斯系列的旗艦手柄,這款產(chǎn)品的升級可謂不小。這次的升級中,最引人注目的一項(xiàng)就是首創(chuàng)的光電算法。通過對優(yōu)秀手柄性能的深入探索,它為玩家提供了卓越的游戲體驗(yàn)。北通這次采用了頂配的1000Hz超頻搖桿,此外,真六軸體感技術(shù)結(jié)合3.0算法校準(zhǔn),這款手柄的升級可謂是前所未有的,為游戲愛好者提供了更加出色的游戲體驗(yàn)。開箱宙斯Pro的包裝延續(xù)了北通一貫的設(shè)計(jì)風(fēng)格,外包裝是堅(jiān)固的硬紙盒,正面印有宙斯Pro的渲染圖案,LOGO和Slogan。打開后,手柄。附件方面,隨機(jī)器附贈(zèng)了無線接收器、數(shù)據(jù)線以及說明書和保修卡。但是并沒有配備替換用的搖桿帽與按鈕,這表明它的定位應(yīng)該介于宙斯和宙斯2之間,填補(bǔ)了中高端價(jià)位的產(chǎn)品。外觀宙斯Pro采用了深灰色的整體設(shè)計(jì),北通的LOGO采用了RGB燈光,以及握把兩側(cè)的小型燈帶,造型簡潔,不會(huì)過于炫目。背部的上半部分包括Profile配置文件、手柄電源開關(guān)、體感開關(guān)以及四個(gè)背部按鍵。面殼采用了PC材質(zhì),在光線下呈現(xiàn)出略帶金屬質(zhì)感的光澤。整體風(fēng)格延續(xù)了宙斯系列的未來機(jī)械風(fēng),硬朗的外觀給人一種強(qiáng)烈的競技感。搖桿宙斯Pro在眾多升級中,采用了霍爾搖桿,這可以說是硬件升級的重要部分。宙斯Pro的搖桿分辨率基本都在2000級以上。同時(shí),北通游戲廳更新后,集成了手柄測試軟件,但目前僅對宙斯Pro開放,期待后續(xù)可以支持更多北通甚至其他品牌的手柄測試。宙斯Pro采用了主流的控銀JH16霍爾搖桿方案,并在側(cè)面定制了北通的LOGO。宙斯Pro的搖桿在超頻模式下,有線連接的回報(bào)率達(dá)到驚人的1000Hz,搖桿分辨率達(dá)到2000級。按鍵宙斯Pro的XYAB四個(gè)按鍵鍵帽采用了黑透的制作工藝,這半透明的鍵帽真的很吸引人。此外,XYAB按鍵還支持位置更換。當(dāng)你拆開面殼后,可以輕松地調(diào)換XYAB按鍵的位置。進(jìn)一步拆解手柄,你會(huì)看到宙斯Pro采用了機(jī)械按鍵、導(dǎo)電膠和按鍵帽多段式結(jié)構(gòu)組合,官方宣傳顯示按鍵的按壓力度為60g,實(shí)際使用時(shí)確實(shí)觸感非常輕快,觸發(fā)速度很快。與宙斯2的50g按壓力度相比,你可以感受到差異,但整體差距并不大。扳機(jī)霍爾扳機(jī)采用電磁感應(yīng)技術(shù),實(shí)現(xiàn)了扳機(jī)行程的信號輸出,消除了絕大部分扳機(jī)所帶來的摩擦力。由于這種純電子工作原理,霍爾扳機(jī)提供了非常順滑的操作手感。宙斯Pro在扳機(jī)和肩鍵方面也進(jìn)行了改進(jìn)。手柄表面的北通紋理設(shè)計(jì)使得手指與手柄之間的摩擦力得到有效增加,不容易滑動(dòng),而且扳機(jī)末端微微上翹,使整體手感更加舒適。實(shí)測宙斯Pro搭載了北通自家研發(fā)的真六軸體感+

3.0算法,具備非常高的靈敏度。此外,這套自家研發(fā)的體感算法還通過軟件升級,實(shí)現(xiàn)了體感與右搖桿的映射不會(huì)發(fā)生沖突。這是之前北通手柄系列一直被批評的問題,而現(xiàn)在希望這一功能可以在未來的固件升級中應(yīng)用到其他系列手柄上。在Switch上的體驗(yàn)幾乎沒有延遲,同時(shí)體感的精度也非常高,幾乎可以媲美原廠的水準(zhǔn)。作為一個(gè)多平臺(tái)手柄,宙斯Pro自然適用于Switch。在Switch上,大多數(shù)游戲需要使用體感功能進(jìn)行操作。至于電池,宙斯Pro搭載了一顆1000毫安時(shí)的電池。由于整體RGB燈光的節(jié)制,充滿電后,你完全可以高強(qiáng)度游戲兩天而無需擔(dān)心電池耗盡。總結(jié)總的來說,宙斯Pro提供了一種非常獨(dú)特的游戲體驗(yàn)。特別是在霍爾搖桿、最高1000Hz回報(bào)率、霍爾扳機(jī)和機(jī)械按鍵等方面,這款手柄表現(xiàn)出了極高的操作靈敏度。通過科學(xué)的調(diào)教,它成功地達(dá)到了速度、準(zhǔn)確性和適應(yīng)性的平衡點(diǎn)。無論是玩動(dòng)作、FPS還是賽車游戲,都能夠顯著提升響應(yīng)速度,并且實(shí)現(xiàn)更加精細(xì)化的操控。可以說,宙斯Pro將電競的理念融入了其中,盡管需要玩家們花一些時(shí)間來適應(yīng),但這種游戲體驗(yàn)是獨(dú)一無二的。發(fā)布于 2023-10-20 22:29?IP 屬地廣東游戲手柄游戲電競選手?贊同??添加評論?分享?喜歡?收藏?申請

FreeRTOS教程1 基礎(chǔ)知識(shí) - OSnotes - 博客園

FreeRTOS教程1 基礎(chǔ)知識(shí) - OSnotes - 博客園

會(huì)員

周邊

新聞

博問

AI培訓(xùn)

云市場

所有博客

當(dāng)前博客

我的博客

我的園子

賬號設(shè)置

簡潔模式 ...

退出登錄

注冊

登錄

lc-guo

博客園

首頁

新隨筆

聯(lián)系

訂閱

管理

FreeRTOS教程1 基礎(chǔ)知識(shí)

了解 FreeRTOS 相關(guān)知識(shí),并熟悉使用 STM32CubeMX 軟件配置 FreeRTOS 工程的流程

1、準(zhǔn)備材料

正點(diǎn)原子stm32f407探索者開發(fā)板V2.4

STM32CubeMX軟件(Version 6.10.0)

Keil μVision5 IDE(MDK-Arm)

野火DAP仿真器

2、學(xué)習(xí)目標(biāo)

了解 FreeRTOS 相關(guān)知識(shí),并熟悉使用 STM32CubeMX 軟件配置 FreeRTOS 工程的流程

3、前提知識(shí)

讀者須知:本系列教程中關(guān)于 FreeRTOS 的學(xué)習(xí)重點(diǎn)為應(yīng)用,不會(huì)剖析源碼內(nèi)容,利用 STM32CubeMX 軟件生成的 FreeRTOS 工程源代碼中一般不會(huì)直接調(diào)用 FreeRTOS 的 API 函數(shù),而是調(diào)用了 CMSIS-RTOS 封裝好的上層API函數(shù),但此系列教程主要介紹屬于 FreeRTOS 的各類 API 函數(shù)及其應(yīng)用,對于 CMSIS-RTOS 的 API 函數(shù)僅簡單描述,讀者需自行理解,另外對于常見硬件原理不再詳細(xì)說明,感興趣讀者可閱讀筆者的 “STM32CubeMX+STM32F4系列教程”

3.1、FreeRTOS簡介

FreeRTOS是一個(gè)完全免費(fèi)且開源的嵌入式實(shí)時(shí)操作系統(tǒng)(Real-Time Operating System,簡稱RTOS) ,其一般將任務(wù)稱為線程,以下列表為FreeRTOS的一些特點(diǎn),筆者認(rèn)為學(xué)習(xí)FreeRTOS的應(yīng)用正是掌握和理解下列各個(gè)特性

搶占式(pre-emptive)或合作式(co-operative)任務(wù)調(diào)度方式

非常靈活的優(yōu)先級管理

靈活、快速且輕量化的任務(wù)通知機(jī)制(task notification)

消息隊(duì)列(Queue)

二值信號量(Binary Semaphores)

計(jì)數(shù)信號量(Counting Semaphores)

互斥量(Mutex)

遞歸互斥量(Recursive Mutex)

軟件定時(shí)器(Timers)

事件組(Events)

時(shí)間節(jié)拍鉤子函數(shù)

空閑任務(wù)鉤子函數(shù)

棧溢出檢測

任務(wù)運(yùn)行時(shí)間統(tǒng)計(jì)收集

完整的中斷嵌套模型

用于低功耗的無節(jié)拍(Tickless)特性

RTOS主要應(yīng)用于對實(shí)時(shí)性有要求的嵌入式系統(tǒng),所謂實(shí)時(shí)性就是任務(wù)完成的時(shí)間是確定的,實(shí)時(shí)性又分為軟實(shí)時(shí)和硬實(shí)時(shí)

軟實(shí)時(shí)指任務(wù)完成時(shí)間是確定的,但是如果任務(wù)超時(shí)了也不會(huì)對整個(gè)系統(tǒng)產(chǎn)生破壞性影響;硬實(shí)時(shí)是指任務(wù)完成時(shí)間是確定的,但是如果任務(wù)超時(shí)未完成則會(huì)對整個(gè)系統(tǒng)產(chǎn)生災(zāi)難性影響,基于FreeRTOS開發(fā)的系統(tǒng)可以完成硬實(shí)時(shí)的要求

3.2、源碼函數(shù)命名規(guī)律

FreeRTOS源碼中函數(shù)命名規(guī)律:FreeRTOS源碼中各個(gè)函數(shù)并非隨機(jī)命名,而是有規(guī)律的命名,這樣方便使用者看到名字就能獲得該函數(shù)更多的信息,其函數(shù)名一般由 ① 函數(shù)返回值類型簡寫,② 函數(shù)所在文件 和 ③ 函數(shù)作用名稱這三部分組成

① 函數(shù)返回值類型簡寫主要有:

'u'表示'unsigned'

'c'表示'char'

's'表示'int16_t(short)'

'l'表示'int32_t(long)'

'p'表示指針類型變量

'x'表示'BaseType_t'結(jié)構(gòu)體和其他非標(biāo)準(zhǔn)類型的變量名

'uc'表示'UBaseType_t'結(jié)構(gòu)體

'v'表示'void'

'prv'表示私有函數(shù)無返回值

這些簡寫可以自由組合在一起,例如 'pc' 表示 'char *' 類型,'uc' 表示 'unsigned char' 類型

② 函數(shù)所在文件:

'CoRoutine'表示該函數(shù)定義在'coroutine.c'文件中的

'EventGroup'表示該函數(shù)定義在'event_groups.c'文件中的

'List'表示該函數(shù)定義在'list.c'文件中的

'Queue'表示該函數(shù)定義在'queue.c'文件中的

'StreamBuffer'表示該函數(shù)定義在'stream_buffer.c'文件中的

'Task'表示該函數(shù)定義在'tasks.c'文件中的

'Timer'表示該函數(shù)定義在'timers.c'文件中的

'Port'表示該函數(shù)定義在'port.c'或'heap_x.c'文件中的

舉幾個(gè)例子:

xTaskCreate 表示函數(shù)返回值為 BaseType_t 結(jié)構(gòu)體類型,函數(shù)被定義在 'tasks.c' 文件中,函數(shù)作用為“創(chuàng)建”

vTaskSuspend 表示函數(shù)返回值為 void 類型,函數(shù)被定義在 'tasks.c' 文件中,函數(shù)作用為“掛起”

prvTaskIsTaskSuspended 表示該函數(shù)為私有函數(shù),僅能在 'tasks.c' 文件中使用,函數(shù)作用為“判斷任務(wù)是否被掛起”

4、動(dòng)手創(chuàng)建一個(gè)FreeRTOS空工程

4.1、CubeMX相關(guān)配置

4.1.1、工程基本配置

打開STM32CubeMX軟件,單擊ACCESS TO MCU SELECTOR選擇開發(fā)板MCU(選擇你使用開發(fā)板的主控MCU型號),選中MCU型號后單擊頁面右上角Start Project開始工程,具體如下圖所示

開始工程之后在配置主頁面System Core/RCC中配置HSE/LSE晶振,在System Core/SYS中配置Debug模式,因?yàn)橄到y(tǒng)滴答定時(shí)器SysTick要被FreeRTOS所使用,所以需要配置HAL庫的時(shí)基源為除系統(tǒng)滴答定時(shí)器SysTick外的選項(xiàng),筆者這里選擇了基本定時(shí)器TIM6,這兩個(gè)時(shí)基源均為1ms,具體配置如下圖所示

4.1.2、時(shí)鐘樹配置

系統(tǒng)時(shí)鐘使用8MHz外部高速時(shí)鐘HSE,HCLK、PCLK1和PCLK2均設(shè)置為STM32F407能達(dá)到的最高時(shí)鐘頻率,具體如下圖所示

4.1.3、外設(shè)參數(shù)配置

單擊Pinout & Configuration頁面左邊功能分類欄目Middleware and SoftwarePacks中的FREERTOS,在模式配置欄中將其接口設(shè)置為CMSIS_V2(CMSIS_V2只是對CMSIS_V1的某些功能進(jìn)行了擴(kuò)展)

下方的Configuration配置頁面中可以對9個(gè)選項(xiàng)卡關(guān)于FreeRTOS的所有參數(shù)做配置,目前均保持默認(rèn)即可,具體配置如下圖所示

以下列表為對上圖所示這9個(gè)配置選項(xiàng)卡及其包含的參數(shù)做簡單的介紹

Tasks and Queues:任務(wù)和隊(duì)列管理

Timers and Semaphores :定時(shí)器和信號量管理

Mutexes:互斥量管理

Events:事件組管理

FreeRTOS Heap Usage:FreeRTOS內(nèi)存使用詳情

Config parameters:Config參數(shù)配置(對應(yīng)FreeRTOSConfig.h中變量名config開始的宏定義)

Include parameters:Include參數(shù)配置(對應(yīng)FreeRTOSConfig.h中變量名INCLUDE開始的宏定義)

Advanced settings:高級設(shè)置

User Constants:用戶自定義常量

對于上面9個(gè)選項(xiàng)卡中的前4個(gè),CubeMX都提供了圖形化配置的界面,在對應(yīng)的頁面中可以通過按鈕非常方便的增加/刪除任務(wù)、隊(duì)列、定時(shí)器、信號量、互斥量和事件組等實(shí)例,而不需要用戶在程序中手動(dòng)編程生成實(shí)例

FreeRTOS Heap Usage 選項(xiàng)卡提供了一個(gè)顯示當(dāng)前FreeRTOS內(nèi)存使用詳情的頁面,該頁面無參數(shù)可配置,僅僅顯示內(nèi)存占用信息和剩余可用堆大小

Config parameters 和 Include parameters 選項(xiàng)卡中的參數(shù)分別對應(yīng) FreeRTOSConfig.h 文件中 config 開頭和 INCLUDE 開頭的宏定義,用來設(shè)置FreeRTOS的相關(guān)參數(shù)及功能裁剪,下面是所有參數(shù)列表,讀者可簡單瀏覽,后面遇到需要修改的具體參數(shù)可以回過頭來尋找,如下述列表所示

參數(shù)

函數(shù)功能

Config parameters/ MPU/FPU

ENABLE_MPU

設(shè)置是否使用MPU內(nèi)存保護(hù)單元

ENABLE_FPU

設(shè)置是否使用FPU浮點(diǎn)數(shù)單元

Kernel settings

USE_PREEMPTION

設(shè)置任務(wù)調(diào)度方式,Enable 表示使用搶占式調(diào)度,Disable 表示使用合作式調(diào)度

CPU_CLOCK_HZ

設(shè)置MCU的HCLK始終頻率,默認(rèn)為系統(tǒng)時(shí)鐘且不可修改

TICK_RATE_HZ

設(shè)置FreeRTOS滴答定時(shí)器中斷頻率,默認(rèn)為1000Hz(1ms),設(shè)置范圍為1-1000

MAX_PRIORITIES

設(shè)置最高優(yōu)先級,值越大內(nèi)核花銷的內(nèi)存空間就越多,總是建議將此常量設(shè)為能夠用到的最小值,STM32CubeMX軟件中默認(rèn)為56且不可修改

MINIMAL_STACK_SIZE

設(shè)置空閑任務(wù)使用的堆棧大小,默認(rèn)為128words

MAX_TASK_NAME_LEN

設(shè)置任務(wù)名的最大長度(包括'\0'結(jié)束符),如果創(chuàng)建任務(wù)時(shí)傳入的任務(wù)名字符串長度超過該參數(shù)定義的長度,則任務(wù)名會(huì)被自動(dòng)截?cái)?,默認(rèn)為16

USE_16_BIT_TICKS

設(shè)置節(jié)拍數(shù)據(jù)類型TickType_t的具體類型,Enable 表示設(shè)置類型為 uint16_t,Disable 表示設(shè)置類型為 uint32_t

IDLE_SHOULD_YIELD

設(shè)置空閑任務(wù)是否對同優(yōu)先級的任務(wù)主動(dòng)讓出CPU使用權(quán)

USE_MUTEXES

設(shè)置是否使用互斥量

USE_RECURSIVE_MUTEXES

設(shè)置是否使用遞歸互斥量

USE_COUNTING_SEMAPHORES

設(shè)置是否使用計(jì)數(shù)信號量

QUEUE_REGISTRY_SIZE

設(shè)置可注冊隊(duì)列和信號量的最大數(shù)量,默認(rèn)為8,設(shè)置范圍為0-255

USE_APPLICATION_TASK_TAG

設(shè)置是否使用應(yīng)用程序的任務(wù)標(biāo)簽

ENABLE_BACKWARD_COMPATIBILITY

設(shè)置是否向后兼容舊版本

USE_PORT_OPTIMISED_TASK_SELECTION

設(shè)置任務(wù)調(diào)度時(shí),選擇下一個(gè)任務(wù)的方法,Disable 表示使用通用方法,不依賴硬件,此處使用 CMSIS-RTOS V2 時(shí)該參數(shù)默認(rèn)為 Disable 且不可修改

USE_TICKLESS_IDLE

設(shè)置是否使用無節(jié)拍(tickless)低功耗模式

USE_TASK_NOTIFICATIONS

設(shè)置是否使用任務(wù)通知功能

RECORD_STACK_HIGH_ADDRESS

設(shè)置是否將棧的起始地址保存到每個(gè)任務(wù)的任務(wù)控制塊中

Memory management settings

Memory_Allocation

設(shè)置內(nèi)存分配方式,默認(rèn)為 Dynamic / Static 且不可修改

TOTAL_HEAP_SIZE

設(shè)置FreeRTOS總的堆空間大小,設(shè)置范圍為 512B~128KB

Memory_Management_scheme

設(shè)置內(nèi)存管理方案,有 heap_x.h 共計(jì)5中可選方案,默認(rèn)選擇 heap_4.h

Hook function related definitions

USE_IDLE_HOOK

設(shè)置是否使用空閑任務(wù)鉤子函數(shù) vApplicationIdleHook()

USE_TICK_HOOK

設(shè)置是否使用滴答定時(shí)器鉤子函數(shù) vApplicationTickHook()

USE_MALLOC_FAILED_HOOK

設(shè)置是否使用內(nèi)存分配失敗鉤子函數(shù) vApplicationMallocFailedHook()

USE_DAEMON_TASK_STARTUP_HOOK

設(shè)置是否使用內(nèi)存分配失敗鉤子函數(shù) vApplicationMallocFailedHook()

CHECK_FOR_STACK_OVERFLOW

設(shè)置是否使用守護(hù)任務(wù)啟動(dòng)鉤子函數(shù) vApplicationDaemonTaskStartupHook()

Run time and task stats gathering related definitions

GENERATE_RUN_TIME_STATS

設(shè)置是否啟動(dòng)任務(wù)運(yùn)行時(shí)間統(tǒng)計(jì)功能,啟用后可以通過 vTaskGetRunTimeStats() API 函數(shù)讀取這些信息

USE_TRACE_FACILITY

設(shè)置是否啟用可視化和跟蹤調(diào)試,默認(rèn)為 Enabled

USE_STATS_FORMATTING_FUNCTIONS

設(shè)置是否編譯 vTaskList() 和 vTaskGetRunTimeStats() API 函數(shù),將 USE_TRACE_FACILITY 和 USE_STATS_FORMATTING_FUNCTIONS 設(shè)置為 1 將編譯構(gòu)建這兩個(gè)函數(shù),設(shè)置為 0 將不編譯構(gòu)建

Co-routine related definitions

USE_CO_ROUTINES

設(shè)置是否使用協(xié)程

MAX_CO_ROUTINE_PRIORITIES

設(shè)置協(xié)程最大優(yōu)先級

Software timer definitions

USE_TIMERS

設(shè)置是否使用軟件定時(shí)器

TIMER_TASK_PRIORITY

設(shè)置定時(shí)器服務(wù)任務(wù)優(yōu)先級

TIMER_QUEUE_LENGTH

設(shè)置定時(shí)器指令隊(duì)列長度

TIMER_TASK_STACK_DEPTH

設(shè)置定時(shí)器服務(wù)任務(wù)棧空間大小

Interrupt nesting behaviour configuration

LIBRARY_LOWEST_INTERRUPT_PRIORITY

設(shè)置最低中斷優(yōu)先級

LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY

設(shè)置系統(tǒng)能管理的最高中斷優(yōu)先級

Added with 10.2.1 support

MESSAGE_BUFFER_LENGTH_TYPE

設(shè)置消息緩沖區(qū)長度類型

USE_POSIX_ERRNO

設(shè)置使用POSIX標(biāo)準(zhǔn)的錯(cuò)誤編號

CMSIS-RTOS V2 flags (僅適用于 FreeRTOS >= 10.3.1 版本)

THREAD_SUSPEND_RESUME

設(shè)置是否使用 CMSIS-RTOS2 的線程掛起 osThreadSuspend() 和恢復(fù) osThreadResume() API 函數(shù)

USE_OS2_THREAD_ENUMERATE

設(shè)置是否使用 CMSIS-RTOS2 的返回線程枚舉數(shù)量 osThreadEnumerate() API 函數(shù)

USE_OS2_EVENTFLAGS_FROM_ISR

設(shè)置是否使用來自 ISR 的 CMSIS-RTOS2 函數(shù) osEventFlagsSet() 和 osEventFlagsClear() 操作

USE_OS2_THREAD_FLAGS

設(shè)置是否從應(yīng)用程序映像中排除 CMSIS-RTOS2 線程標(biāo)志 API 函數(shù)

USE_OS2_TIMER

設(shè)置是否從應(yīng)用程序映像中排除 CMSIS-RTOS2 定時(shí)器 API 函數(shù)

USE_OS2_MUTEX

設(shè)置是否從應(yīng)用程序映像中排除 CMSIS-RTOS2 Mutex API 函數(shù)數(shù)

Include parameters/ Include definitions

vTaskPrioritySet

設(shè)置是否包含 vTaskPrioritySet() API 函數(shù)

uxTaskPriorityGet

設(shè)置是否包含 uxTaskPriorityGet() API 函數(shù)

vTaskDelete

設(shè)置是否包含 vTaskDelete() API 函數(shù)

vTaskCleanUpResources

設(shè)置是否包含 vTaskCleanUpResources() API 函數(shù)

vTaskSuspend

設(shè)置是否包含 vTaskSuspend() API 函數(shù)

vTaskDelayUntil

設(shè)置是否包含 vTaskDelayUntil() API 函數(shù)

vTaskDelay

設(shè)置是否包含 vTaskDelay() API 函數(shù)

xTaskGetSchedulerState

設(shè)置是否包含 xTaskGetSchedulerState() API 函數(shù)

xTaskResumeFromlSR

設(shè)置是否包含 xTaskResumeFromlSR() API 函數(shù)

xQueueGetMutexHolder

設(shè)置是否包含 xQueueGetMutexHolder() API 函數(shù),默認(rèn)啟用(某些工具鏈(例如MDK-ARM)可能需要編譯cmsis_os2.c)

pcTaskGetTaskName

設(shè)置是否包含 pcTaskGetTaskName() API 函數(shù)

uxTaskGetStackHighWaterMark

設(shè)置是否包含 uxTaskGetStackHighWaterMark() API 函數(shù)

xTaskGetCurrentTaskHandle

設(shè)置是否包含 xTaskGetCurrentTaskHandle() API 函數(shù)

eTaskGetState

設(shè)置是否包含 eTaskGetState() API 函數(shù)

xEventGroupSetBitFromlSR

設(shè)置是否包含 xEventGroupSetBitFromlSR() API 函數(shù),INCLUDE_xTimerPendFunctionCall 必須設(shè)置為 1 使 xEventGroupSetBitFromISR() 函數(shù)可用

xTimerPendFunctionCall

設(shè)置是否包含 xTimerPendFunctionCall() API 函數(shù),configUSE_TIMERS 必須設(shè)置為 1 使 xTimerPendFunctionCall() 函數(shù)可用

xTaskAbortDelay

設(shè)置是否包含 xTaskAbortDelay() API 函數(shù)

xTaskGetHandle

設(shè)置是否包含 xTaskGetHandle() API 函數(shù)

uxTaskGetStackHighWaterMark2

設(shè)置是否包含 uxTaskGetStackHighWaterMark2() API 函數(shù),適用于支持 FreeRTOS >= 10.2.1 的系列

Advanced settings 選項(xiàng)卡中只有兩個(gè)參數(shù), USE_NEWLIB_REENTRANT 用于配置 Newlib 相關(guān)內(nèi)容,一般不使用; Use FW pack heap file 用于配置是否使用固件包提供的堆管理文件(heap_x.c),不使用的話需要由用戶自己提供堆管理文件,這里一般選擇使用

User Constants 選項(xiàng)卡可以創(chuàng)建一些用戶需要使用的常量參數(shù),創(chuàng)建的常量將以宏定義的形式被定義在main.h文件中

4.1.4、外設(shè)中斷配置

當(dāng)啟用了FREERTOS之后,整個(gè)系統(tǒng)的NVIC會(huì)自動(dòng)發(fā)生一些變化,F(xiàn)reeRTOS使用的系統(tǒng)服務(wù)可掛起請求中斷和系統(tǒng)滴答定時(shí)器中斷將被強(qiáng)制開啟,均為最低優(yōu)先級且不可設(shè)置,這兩個(gè)中斷對于FreeRTOS來說是相當(dāng)重要的,系統(tǒng)滴答定時(shí)器會(huì)為FreeRTOS提供時(shí)間基準(zhǔn),系統(tǒng)服務(wù)可掛起請求中斷用于任務(wù)切換等管理

另外HAL庫的時(shí)基源TIM6中斷也會(huì)被強(qiáng)制打開不可關(guān)閉,但是其中斷的優(yōu)先級仍可調(diào)節(jié),我們將TIM6中斷設(shè)置為硬件最高優(yōu)先級0,其他均按照默認(rèn)中斷優(yōu)先級即可,具體配置如下圖所示

將啟用FreeRTOS之后的NVIC與啟用之前的NVIC對比可以發(fā)現(xiàn),在配置頁面多了一列“Uses FreeRTOS functions”,在增加的這一列的某個(gè)硬件中斷后面勾選選項(xiàng)框則會(huì)改變該硬件中斷的搶占優(yōu)先級,讀者目前僅作了解,有關(guān)中斷具體管理會(huì)在后續(xù)教程中講到

4.2、生成代碼

4.2.1、配置Project Manager頁面

單擊進(jìn)入Project Manager頁面,在左邊Project分欄中修改工程名稱、工程目錄和工具鏈,然后在Code Generator中勾選“Gnerate peripheral initialization as a pair of 'c/h' files per peripheral”,最后單擊頁面右上角GENERATE CODE生成工程,具體如下圖所示

4.2.2、工程代碼結(jié)構(gòu)分析

打開生成的工程代碼,觀察其目錄結(jié)構(gòu),發(fā)現(xiàn)在Core目錄下相比較以往的工程增加了freertos.c 和 stm32f4xx_hal_timebase_tim.c 兩個(gè)文件,在工程下還增加了Middlewares/FreeRTOS的源碼文件,該源碼文件下所有文件均無需用戶修改,生成工程代碼具體工程目錄結(jié)構(gòu)如下圖所示

為了減少在使用不同的第三方RTOS嵌入式操作系統(tǒng)(eg:FreeRTOS、UCOS等)對用戶應(yīng)用代碼帶來的差異,ARM公司為RTOS內(nèi)核制定了一套通用的接口協(xié)議CMSIS-RTOS(cmsis_osx.c),在該文件中規(guī)定了RTOS中使用的某些功能函數(shù)的統(tǒng)一名稱及參數(shù)等等

在應(yīng)用上,用戶只需要調(diào)用CMSS-RTOS規(guī)定的API函數(shù)來對任務(wù)進(jìn)行操作,而CMSS-RTOS規(guī)定的API函數(shù)會(huì)使用不同第三方RTOS嵌入式操作系統(tǒng)的接口函數(shù)對CMSS-CORE(HAL庫等函數(shù))操作,最終控制底層MCU,其中CMSS、RTOS和MCU等的關(guān)系圖如下圖所示 (注釋1)

接下來我們來看看空的FreeRTOS工程初始化流程,打開main.c文件,在主函數(shù)中分別執(zhí)行了以下幾個(gè)函數(shù),下面簡單介紹下這些空工程中就使用到的函數(shù),讀者了解即可

最后調(diào)用osKernelStart()函數(shù)時(shí)會(huì)先創(chuàng)建一個(gè)空閑任務(wù),然后啟動(dòng)FreeRTOS調(diào)度器,將STM32內(nèi)核控制權(quán)交給FreeRTOS調(diào)度器,F(xiàn)reeRTOS調(diào)度器啟動(dòng)之后必須要至少有一個(gè)任務(wù)在不斷運(yùn)行,之后調(diào)度器就會(huì)按照一定的任務(wù)優(yōu)先級順序執(zhí)行用戶定義的各種任務(wù),每個(gè)任務(wù)都應(yīng)該是一個(gè)死循環(huán),所以程序不會(huì)運(yùn)行到osKernelStart()函數(shù)之后的任何部分

讀者在使用FreeRTOS時(shí),如果需要自己手動(dòng)創(chuàng)建某些任務(wù)、信號量、互斥量等可以直接在freertos.c文件中實(shí)現(xiàn)即可,也可以在CubeMX圖形化配置界面中創(chuàng)建(推薦后者)

MX_FREERTOS_Init()函數(shù)中,ST公司也使用者貼心的提供了各種不同功能的沙箱代碼段,當(dāng)在CubeMX圖形化配置界面中創(chuàng)建了對應(yīng)的實(shí)例,該沙箱代碼段中就會(huì)出現(xiàn)對應(yīng)實(shí)現(xiàn)的程序,如下圖所示

4.3、燒錄驗(yàn)證

使用STM32CubeMX生成工程代碼后,不做任何修改,直接單擊KEIL軟件的編譯按鈕應(yīng)該可以順利通過,通過編譯信息可知出現(xiàn)0錯(cuò)誤和0警告,如下圖所示

單擊魔術(shù)手,在debug選項(xiàng)卡中選擇使用DAP下載器(該下載器無需下載驅(qū)動(dòng)),單擊后方的設(shè)置可以在其中看到識(shí)別到的下載器,具體如下圖所示

將接入電源的開發(fā)板通過DAP下載器與PC連接,單擊KEIL軟件的LOAD按鈕將程序燒錄進(jìn)入開發(fā)板MCU中,等待下方進(jìn)度條走完,可以發(fā)現(xiàn) Flash Load finished ,由于是空工程因此無任何現(xiàn)象發(fā)生,具體如下圖所示

5、注釋詳解

注釋1:圖片來源 Getting Started with STM32 - Introduction to FreeRTOS

注釋2:圖片來源 CMSIS-Core Device Templates

參考資料

STM32Cube高效開發(fā)教程(高級篇)

posted @

2024-03-11 09:44?

OSnotes?

閱讀(139)?

評論(0)?

編輯?

收藏?

舉報(bào)

會(huì)員力量,點(diǎn)亮園子希望

刷新頁面返回頂部

公告

Copyright ? 2024 OSnotes

Powered by .NET 8.0 on Kubernetes

404 Not Found


nginx/1.25.2
精品无码国产一区二区三区麻豆| 潮喷大喷水系列无码久久精品| 日韩免费无码一区二区视频| 久久久久亚洲波多野结衣| 国产成人精品优优AV| 巨大巨粗巨长 黑人长吊| 亚洲a∨国产av综合av| 人人澡人人踫天堂京东热社区| 精品国精品自拍自在线| 欧美丰满少妇xxxxx| 国产精品一国产AV麻豆| 国产精品久久久久久久久电影网| 少妇被粗大的猛烈进出免费视频| 亚洲av无码久久精品蜜桃| 乱人伦中文视频在线| 国产真实乱对白精彩| 果冻传媒2021精品影视| 2021国产麻豆剧传媒仙踪林| 18黑白丝水手服自慰喷水| 亚洲AV无码男人的天堂| 亚洲VA无码VA在线VA天堂| 色综合久久中文字幕有码| 久久久久亚洲AV成人人电影| 国产亚洲精品资源在线26u| 亚洲精品国产精品国自产观看| 手机在线看永久av片免费| 久久综合五月丁香六月丁香| 极品无码国模国产在线观看| yw尤物av无码国产在线观看| 一区二区三区日产| 国产精品嫩草影院AV| 精品无码国产自产拍在线观看蜜桃| 高清不卡一区二区三区| 99精品热在线在线观看视频| 亚洲国产欧美在线成人APP| 亚洲熟妇成人精品一区| 国产太嫩了在线观看| 亚洲AV成人无码久久精品| 国产美女精品一区二区三区| 国产一本二卡三卡四卡乱码| 99久久人妻精品免费二区|