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

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

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

    JUST DO IT ~

    我只想當個程序員

    spinlock

    待填坑.

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



    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 并發


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


    網站導航:
     

    導航

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

    統計

    常用鏈接

    留言簿(3)

    隨筆分類(352)

    收藏夾(19)

    關注的blog

    手冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 18禁止看的免费污网站| 国内永久免费crm系统z在线| 99久久99热精品免费观看国产| 亚洲色欲一区二区三区在线观看| yellow视频免费在线观看| 亚洲精品国产电影| 一级视频免费观看| 亚洲人成影院在线无码按摩店| 三年片免费高清版 | 巨胸喷奶水www永久免费| 亚洲真人日本在线| 在线观看免费视频一区| 亚洲bt加勒比一区二区| 2021国产精品成人免费视频| 亚洲精品亚洲人成在线播放| 免费无码成人AV片在线在线播放| 国产亚洲欧美在线观看| 久久久久亚洲?V成人无码| 中文字幕免费观看全部电影| 亚洲av永久无码精品漫画| 麻花传媒剧在线mv免费观看| 一本天堂ⅴ无码亚洲道久久| 国产一级一片免费播放| 国产精品1024在线永久免费 | 95老司机免费福利| 亚洲中文字幕无码一去台湾| 国产无遮挡裸体免费视频| 国产精品免费久久久久影院 | 在线涩涩免费观看国产精品 | 激情婷婷成人亚洲综合| 亚洲人成影院在线无码按摩店| 亚洲精品免费在线视频| 在线观看亚洲专区| 亚洲AV永久无码精品| 特级做A爰片毛片免费69| 二级毛片免费观看全程| 亚洲视频免费在线观看| 免费看小12萝裸体视频国产| 毛片在线全部免费观看| 亚洲Av永久无码精品黑人 | 午夜免费啪视频在线观看 |