Spinlock implementation in ARM architecture

 
SEV and WFE are the main instructions used for implementing spinlock in case of ARM architecture. Let's look briefly at those two instructions before looking into actual spinlock implementation.

SEV

SEV causes an event to be signaled to all cores within a multiprocessor system. If SEV is implemented, WFE must also be implemented.

WFE

If the Event Register is not set, WFE suspends execution until one of the following events occurs:

  • an IRQ interrupt, unless masked by the CPSR I-bit
  • an FIQ interrupt, unless masked by the CPSR F-bit
  • an Imprecise Data abort, unless masked by the CPSR A-bit
  • a Debug Entry request, if Debug is enabled
  • an Event signaled by another processor using the SEV instruction.

In case of spin_lock_irq( )/spin_lock_irqsave( ),

  • as IRQs are disabled, the only way to to resume after WFE intruction has executed is to execute SEV instruction on some other core.

In case of spin_lock( ),

  • If IRQs are enabled even before we had called spin_lock( ) and we executed WFE and execution got suspended,
    • Scenario 1: Interrupt occured and handled; we resume, but as the lock was still unreleased, we will loopback and execute WFE.
    • Scenario 2: Some other core executed WFE and released some other lock (but didn't release our lock); we resume; as the lock is still unreleased, we will loopback and execute WFE.
    • Scenario 3: Some other core executed WFE and released this lock; we resume; as the lock was released, we will acquire the lock.
  • If IRQs are disabled before calling spin_lock(), then the situation is same as spin_lock_irqsave().

In case of spin_unlock( ),

  • lock is released and SEV instruction is executed.

Check out the following code snippets for actual implementation:

static inline void arch_spin_lock(arch_spinlock_t *lock)
{
        unsigned long tmp;

__asm__ __volatile__(
"1:     ldrex   %0, [%1]\n"
"       teq     %0, #0\n"
        WFE("ne")
"       strexeq %0, %2, [%1]\n"
"       teqeq   %0, #0\n"
"       bne     1b"
        : "=&r" (tmp)
        : "r" (&lock->lock), "r" (1)
        : "cc");

smp_mb();
}

static inline void arch_spin_unlock(arch_spinlock_t *lock)
{
        smp_mb();

__asm__ __volatile__(
"       str     %1, [%0]\n"
        :
        : "r" (&lock->lock), "r" (0)
        : "cc");

dsb_sev();
}

static inline void dsb_sev(void)
{
#if __LINUX_ARM_ARCH__ >= 7
        __asm__ __volatile__ (
                "dsb\n"
                SEV
        );
#else
        __asm__ __volatile__ (
                "mcr p15, 0, %0, c7, c10, 4\n"
                SEV
                : : "r" (0)
        );
#endif
}

For more information, check arch/arm/include/asm/spinlock.h in Linux kernel source code. The above code snippet is from 3.4 kernel.

Spinlock implementation in ARM architecture的更多相关文章

  1. ARM architecture

    http://en.wikipedia.org/wiki/ARM_architecture ARM architecture     ARM architectures The ARM logo De ...

  2. ARM architectures

    https://gitorious.org/freebsd/freebsd/raw/56c5165837bf08f50ca4a08c6b2da91f73852960:sys/arm/include/a ...

  3. [转]ARM/Thumb2PortingHowto

    src: https://wiki.edubuntu.org/ARM/Thumb2PortingHowto#ARM_Assembler_Overview When you see some assem ...

  4. [转]ARM/Thumb/Thumb-2

    ref:http://kmittal82.wordpress.com/2012/02/17/armthumbthumb-2/ A few months ago I gave a presentatio ...

  5. [转]iOS Assembly Tutorial: Understanding ARM

    iOS Assembly Tutorial: Understanding ARM Do you speak assembly? When you write Objective-C code, it ...

  6. An Exploration of ARM TrustZone Technology

    墙外通道:https://genode.org/documentation/articles/trustzone ARM TrustZone technology has been around fo ...

  7. ARM Holdings

    http://en.wikipedia.org/wiki/Advanced_RISC_Machines ARM Holdings  (Redirected from Advanced RISC Mac ...

  8. ARM WFI和WFE指令【转】

    本文转载至:http://www.wowotech.net/armv8a_arch/wfe_wfi.html 1. 前言 蜗蜗很早以前就知道有WFI和WFE这两个指令存在,但一直似懂非懂.最近准备研究 ...

  9. 附录:ARM 手册 词汇表

    来自:<DDI0406C_C_arm_architecture_reference_manual.pdf>p2723 能够查询到:“RAZ RAO WI 等的意思” RAZ:Read-As ...

随机推荐

  1. Android仿Win8界面的button点击

    今天没事的时候,感觉Win8的扁平化的button还是挺好看的,就研究了下怎样在安卓界面实现Win8的扁平化button点击效果. 发现了一个自己定义的View能够实现扁平化button效果,话不多说 ...

  2. Git管理软件

    软件下载地址 首先下载库 https://code.google.com/p/msysgit/ 接着安装 https://code.google.com/p/tortoisegit/ 然后就能够用了

  3. 制作 wordpress 博客静态化到本地

    wget 克隆 wordpress 博客镜像 wget -e robots=off -w 1 -xq -np -nH -pk -m -t 1 -P "./wordpress.org" ...

  4. 初步使用RecyclerView实现瀑布流

    先看效果 关于RecyclerView,真的是很强大. 个人觉得主要方便的地方是 1.直接可以设置条目布局,通过setLayoutManager LinearLayoutManager:线性布局,横向 ...

  5. 1.20 Python基础知识 - python常用模块-1

    一.time和datetime 1.time模块 1)time.process_time() >>> import time >>> time.process_ti ...

  6. Linux桌面新彩虹-Fedora 14 炫酷应用新体验

    Linux桌面新彩虹 --Fedora 14 炫酷应用新体验 650) this.width=650;" hspace="12" align="left&quo ...

  7. java 位操作 bitwise(按位) operation bit

    java 位操作 bitwise(按位) operation bit //一篇对于 原码 反码 补码 的介绍 http://www.cnblogs.com/zhangziqiu/archive/201 ...

  8. Angularjs:实现全选

    html: <div class="input-group"> <span class="input-group-addon" style=& ...

  9. Spring MVC框架实例

    Spring  MVC 背景介绍 Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring 可插入的 MVC 架构,能够选择是使用内置的 Spring Web 框架还是 ...

  10. 课程与教学管理系统(CMS):Sakai

    课程与教学管理系统(CMS):Sakai 一.总结 java的spring.Hibernate等框架开发的 J2EE的开源cms 二.SAKAI Sakai是一个自由.开源的在线协作和学习环境,由Sa ...