[ARM-assembly]-ARMV8的exclusive和inexclusive的介绍

本文探讨了ARMv8架构中引入Exclusive指令的背景,重点讲述在多核环境中如何通过这些指令来管理共享资源锁,防止竞态条件。讲解了LDXR和STXR指令在支持exclusive操作中的作用,以及它们在A32和T32扩展中的对应指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

快速链接:
.
👉👉👉 个人博客笔记导读目录(全部) 👈👈👈

在这里插入图片描述

AMRv8-aarch64架构中的A64指令中,提供了如下的一些exclusive指令,用来支持exclusive操作
在这里插入图片描述

那为什么,arm在加入exclusive指令呢?加入这个,主要是为了解决多核情况下,锁的竞争问题。

在软件层面,对于共享资源的访问,会设定一个锁,只有能拿到这个锁的程序,才能够访问共享资源,而没有拿到锁的程序,就不能访问该共享资源。

static int g_lock;

void lock()
{
	while(!g_lock);
	g_lock = 1;  // 上锁
}

void unlock()
{
	g_lock = 0;  //释放锁
}

在使用操作系统后,这个程序也可能会出现潜在的问题,因为操作系统会调度应用程序。假设应用程序A在读取到锁状态后,值为0,表示当前锁没有被其他程序占有,正当自己要将锁锁上的时候,操作系统进行了调度,应用程序B执行。程序B也读取锁状态,发现值为0,表示当前锁没有被其他程序占有,然后将锁给锁上,访问共享资源。此时,操作系统又进行了调度,应用程序A执行,将锁给锁上,然后访问共享资源。那此时,就出现了2个应用程序,同时访问共享资源,锁的作用,被屏蔽了。

(单核的情况下)为了解决这个问题,可以在获取锁的时候,屏蔽中断,那这个时候,操作系统就不能调度,也就避免上面出现的问题

static int g_lock;

void lock()
{
	mask_interrupt();
	while(!g_lock);
	g_lock = 1;  // 上锁
	unmask_interrupt();
}

void unlock()
{
	g_lock = 0;  //释放锁
}

但是在多核的情况下,各个cpu是并行执行的,因此这个时候,还会出现,上面描述的2个程序,同时获取到锁的状态,而这个时候,通过禁止中断,是没有效果的.
为了解决多核情况下的锁竞争问题,arm引入了exclusive操作,并添加了相应的指令
exclusive的操作的核心,就是会将锁,用一个状态机进行维护,该状态机有2种状态,open状态和exclusive状态。要想成功的对锁进行上锁,状态必须要从exclusive状态切换到open状态,其他状态,都是失败的。

为了支持exclusive操作,在A64,新增了LDXR和STXR指令。

在A32和T32下,也加入LDREX和STREX指令来支持
在这里插入图片描述

LDXR指令,将状态从open状态切换到exclusive状态,STXR指令,将状态从exclusive状态切换到open状态,这个就表示store exclusive操作成功
在这里插入图片描述


2) Who uses ARM? Currently ARM CPU is licensed and produced by more than 100 companies and is the dominant CPU chip in both cell phones and tablets. Given its RISC architecture and powerful 32-bit instructions set, it can be used for both 8-bit and 32-bit embedded products. The ARM corp. has already defined the 64-bit instruction extension and for that reason many Laptop and Server manufactures are planning to introduce ARM-based Laptop and Servers. 3) Who will use our textbook? The primary audience of our textbook on ARM (ARM Assembly Language Programming & Architecture by Mazidi & Naimi) is undergraduate engineering students in Electrical and Computer Engineering departments. It can also be used by practicing engineers who need to move away from 8- and 16-bit legacy chips such as the 8051, AVR, PIC and HCS08/12 family of microcontrollers to ARM. Designers of the x86-based systems wanting to design ARM-based products can also benefit from this textbook. Table of Contents Chapter 1: The History of ARM and Microcontrollers Chapter 2: ARM Architecture and Assembly Language Programming Chapter 3: Arithmetic and Logic Instructions and Programs Chapter 4: Branch, Call, and Looping in ARM Chapter 5: Signed Numbers and IEEE 754 Floating Point Chapter 6: ARM Memory Map, Memory Access, and Stack Chapter 7: ARM Pipeline and CPU Evolution Appendix A: ARM Cortex-M3 Instruction Description Appendix B: ARM Assembler Directives Appendix C: Macros Appendix D: Flowcharts and Pseudocode Appendix E: Passing Arguments into Functions Appendix F: ASCII Codes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arm精选

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值