<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仍然存在,但它僅用于真正的老代碼,不能輕易移動到一些更細化的鎖。現在是完全可能的多核框有有用的運行內核代碼的每個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 小高 閱讀(294) 評論(0)  編輯  收藏 所屬分類: Concurrency 并發


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


    網站導航:
     

    導航

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

    統計

    常用鏈接

    留言簿(3)

    隨筆分類(352)

    收藏夾(19)

    關注的blog

    手冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 69影院毛片免费观看视频在线| 日本一区二区在线免费观看| 亚洲一区二区三区四区在线观看 | jizz免费在线影视观看网站| eeuss影院www天堂免费| 一本久到久久亚洲综合| 伊人亚洲综合青草青草久热| 亚洲高清无在码在线电影不卡| 亚洲人成无码网站在线观看| 人碰人碰人成人免费视频| 91麻豆最新在线人成免费观看| 国产色婷婷精品免费视频| 亚洲中文字幕无码爆乳AV| 精品国产免费一区二区三区| 最近最新中文字幕完整版免费高清 | 五月天网站亚洲小说| 亚洲熟妇无码AV| A国产一区二区免费入口| 国产精品亚洲一区二区三区在线| 亚洲AV无码精品蜜桃| 中文字幕看片在线a免费| 操美女视频免费网站| 亚洲av无码日韩av无码网站冲| 久久狠狠躁免费观看| 免费人成激情视频| 色婷五月综激情亚洲综合| 久久国产免费一区二区三区| 亚洲网站免费观看| 成人精品一区二区三区不卡免费看| 精品无码国产污污污免费| 亚洲韩国在线一卡二卡| 国产成人免费网站| 91久久亚洲国产成人精品性色| www.免费在线观看| 无码专区—VA亚洲V天堂| 免费可以看黄的视频s色| 亚洲精品白色在线发布| 成人啪精品视频免费网站| 成人免费ā片在线观看| 亚洲精品视频免费在线观看| 国产最新凸凹视频免费|