<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    JUST DO IT ~

    我只想當(dāng)個程序員

    spinlock

    待填坑.

    自旋鎖是一種方法來保護共享資源從通過同時兩個或多個進程被修改。試圖修改的資源的第一工藝“獲取”鎖定,并繼續(xù)在它的途中,在做什么,它需要與資源。任何其他進程隨后試圖獲取鎖得到停止;它們被表示為“旋到位”等待鎖到被所述第一過程被釋放,因而命名自旋鎖。
    Linux內(nèi)核使用旋轉(zhuǎn)鎖的很多事情,將數(shù)據(jù)發(fā)送到特定外設(shè)如。大多數(shù)硬件外設(shè)不是設(shè)計來處理多個并發(fā)狀態(tài)更新。如果兩個不同的修改必須發(fā)生,就必須嚴(yán)格遵循其它,它們不能重疊。自旋鎖提供了必要的保障,確保修改發(fā)生一次。
    自旋鎖是一個問題,因為紡紗阻止做任何其他工作線程的CPU核心。而Linux內(nèi)核并提供給其下運行的用戶空間程序的多任務(wù)服務(wù),即通用的多任務(wù)處理設(shè)施沒有延伸到內(nèi)核代碼。
    這種情況正在發(fā)生變化,并一直為大多數(shù)Linux的存在。向上穿過Linux 2.0中,內(nèi)核幾乎純粹是一個單任務(wù)程序:每當(dāng)CPU正在運行的內(nèi)核代碼中,只有一個CPU內(nèi)核使用,因為有一個自旋鎖保護所有共享資源,被稱為大內(nèi)核鎖(BKL )。使用Linux 2.2開始,BKL正在慢慢分解成每保護一個更集中的資源類的許多獨立的鎖。如今,隨著2.6內(nèi)核,在BKL仍然存在,但它僅用于真正的老代碼,不能輕易移動到一些更細化的鎖。現(xiàn)在是完全可能的多核框有有用的運行內(nèi)核代碼的每個CPU。
    有一個限制分手BKL因為Linux內(nèi)核一般缺乏多任務(wù)的效用。如果CPU內(nèi)核被阻塞紡內(nèi)核的自旋鎖,它不能被重新定義,去做些別的事情,直到鎖被釋放。它只是坐在和旋轉(zhuǎn),直到鎖被釋放。
    自旋鎖可以有效地把一個怪物16芯盒成單核中,如果工作負載是這樣的,每一個核心總是等待一個單一自旋鎖。這是主要的限制Linux內(nèi)核的可擴展性:CPU核心增加一倍,從2到4可能會在Linux中的近兩倍的速度,但它從16倍增至32可能不會,大多數(shù)的工作負載。



    A spin lock is a way to protect a shared resource from being modified by two or more processes simultaneously. The first process that tries to modify the resource "acquires" the lock and continues on its way, doing what it needed to with the resource. Any other processes that subsequently try to acquire the lock get stopped; they are said to "spin in place" waiting on the lock to be released by the first process, thus the name spin lock.
    The Linux kernel uses spin locks for many things, such as when sending data to a particular peripheral. Most hardware peripherals aren't designed to handle multiple simultaneous state updates. If two different modifications have to happen, one has to strictly follow the other, they can't overlap. A spin lock provides the necessary protection, ensuring that the modifications happen one at a time.
    Spin locks are a problem because spinning blocks that thread's CPU core from doing any other work. While the Linux kernel does provide multitasking services to user space programs running under it, that general-purpose multitasking facility doesn't extend to kernel code.
    This situation is changing, and has been for most of Linux's existence. Up through Linux 2.0, the kernel was almost purely a single-tasking program: whenever the CPU was running kernel code, only one CPU core was used, because there was a single spin lock protecting all shared resources, called the Big Kernel Lock (BKL). Beginning with Linux 2.2, the BKL is slowly being broken up into many independent locks that each protect a more focused class of resource. Today, with kernel 2.6, the BKL still exists, but it's only used by really old code that can't be readily moved to some more granular lock. It is now quite possible for a multicore box to have every CPU running useful kernel code.
    There's a limit to the utility of breaking up the BKL because the Linux kernel lacks general multitasking. If a CPU core gets blocked spinning on a kernel spin lock, it can't be retasked, to go do something else until the lock is released. It just sits and spins until the lock is released.
    Spin locks can effectively turn a monster 16-core box into a single-core box, if the workload is such that every core is always waiting for a single spin lock. This is the main limit to the scalability of the Linux kernel: doubling CPU cores from 2 to 4 probably will nearly double the speed of a Linux box, but doubling it from 16 to 32 probably won't, with most workloads.

    參考: 
    taobao 計算文章寫的很好. 

    spinlock剖析與改進
    http://www.searchtb.com/2011/06/spinlock%E5%89%96%E6%9E%90%E4%B8%8E%E6%94%B9%E8%BF%9B.html

    http://blog.chinaunix.net/uid-25871104-id-3052138.html
      
    http://www.searchtb.com/2011/01/pthreads-mutex-vs-pthread-spinlock.html 
    https://en.wikipedia.org/wiki/Spinlock#Example_implementation  

    posted on 2015-07-01 13:52 小高 閱讀(282) 評論(0)  編輯  收藏 所屬分類: Concurrency 并發(fā)


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    <2015年7月>
    2829301234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    統(tǒng)計

    常用鏈接

    留言簿(3)

    隨筆分類(352)

    收藏夾(19)

    關(guān)注的blog

    手冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产午夜无码片免费| 丰满亚洲大尺度无码无码专线| gogo免费在线观看| 亚洲精品NV久久久久久久久久| 国产成人精品日本亚洲语音| 看全色黄大色大片免费久久| 亚洲成aⅴ人片久青草影院按摩| 免费无码又黄又爽又刺激| 久久久久精品国产亚洲AV无码| 18勿入网站免费永久| 亚洲国产片在线观看| 亚洲免费综合色在线视频| 亚洲中文字幕无码av永久| 永久免费无码网站在线观看| 在线观看亚洲网站| 亚洲精品A在线观看| 免费网站观看WWW在线观看| 91亚洲国产成人久久精品网站| **aaaaa毛片免费同男同女| 亚洲精品伊人久久久久| 波多野结衣一区二区免费视频| 色多多A级毛片免费看| 亚洲精品美女久久777777| 久久w5ww成w人免费| 亚洲性无码一区二区三区| 国产成人精品免费视频大全五级 | 亚洲国产精品国自产拍AV| 国产免费爽爽视频在线观看 | 理论片在线观看免费| 亚洲色成人中文字幕网站| 6080午夜一级毛片免费看| 国产亚洲一卡2卡3卡4卡新区| 久久久久国产亚洲AV麻豆| 在线看片免费人成视久网| 亚洲老熟女五十路老熟女bbw| 亚洲片一区二区三区| 8x成人永久免费视频| 国产av无码专区亚洲av毛片搜 | 国产h肉在线视频免费观看| 国产精品亚洲а∨天堂2021| 亚洲AV午夜成人影院老师机影院|