AXI (Advanced extensible Interface) 协议是ARM公司提出的AMBA(Advanced Microcontroller Bus Architecture)协议中最重要的部分,是一种面向高性能、高带宽、低延迟的片内总线。当前最新为 AXI 5.0 (2020年)。
AXI5 Spec download AMBA
AXI5 的一个重要更新,就是增加了对atomic transaction (或称之为 atomic operation,原子操作)的支持。
Atomic transactions are suited to situations where the data is located a significant distance from the agent that must perform the operation. Compared with using Exclusive Accesses, this approach reduces the amount of time during which the data must be made inaccessible to other agents in the system.
AXI5支持4大类的atomic,分别为atomic store、atomic load、atomic swap和atomic compare。其中,atomic store和atomic load 会再细分为多种不同的atomic operation,比如ADD、CLR等等;atomic swap和atomic compare则没有细分的atomic operation,因为其操作是固定的。
atomic的request 会通过AW和W channel 发送出去, atomic response 会通过 B 和R channel 进行返回。其中AW channel会在AXI4的基础上增加AWATOP[5:0]的signal,用来标识atomic的类型和具体的operation类型;W channel会传递 原始的操作数(operand)。如上的read modify write 操作,atomic 类型为store atomic,atomic operation为ADD,原始的操作数 就是 1。
atomic store和atomic load都需要通过AW 和W channel发送 addr、length、atomic type and operation,都需要从memory读取addr位置的原始数据,都需要进行ALU运算,然后将新的value再存入addr位置。两者的主要区别体现在 atomic 操作完成的response和data返回上:atomic store会通过B channel返回一个 atomic response;而 atomic load会通过R channel 返回 访问地址空间的 原始数据(也就是进行atomic operation之前的数据)。
如下是spec中对atomic 四大类的描述,其中outbound和inbound 的表述都是站在 master的角度来看的。
Atomic type | Description |
Atomic store | • Sends a single data value with an address and the atomic operation to be performed. • The target performs the operation using the sent data and value at the addressed location as operands. • The result is stored in the address location. • A single response is given without data. • Outbound data size is 1, 2, 4, or 8 bytes. 也就是master发出的数据 |
atomic load | • Sends a single data value with an address and the atomic operation to be performed. • The original data value at the addressed location is returned. 一定要注意,此处返回的不是 ALU计算后的数据,而是addr位置的原始数据。 • The target performs the operation using the sent data and value at the addressed location as operands. • The result is stored in the address location. • Outbound data size is 1, 2, 4, or 8 bytes. 也就是master发出的数据 • Inbound data size is the same as the outbound data size.也就是 memory需要返回的数据 |
atomic swap | • Sends a single data value with an address. 不需要 atomic operation • The target swaps the value at the addressed location with the data value that is supplied in the transaction. • The original data value at the addressed location is returned. • Outbound data size is 1, 2, 4, or 8 bytes. • Inbound data size is the same as the outbound data size |
atomic compare | • Sends two data values, the compare value and the swap value, to the addressed location. The compare and swap values are of equal size. 不需要 atomic operation。 • The data value at the addressed location is checked against the compare value: — If the values match, the swap value is written to the addressed location. — If the values do not match, the swap value is not written to the addressed location. • The original data value at the addressed location is returned. • Outbound data size is 2, 4, 8, 16, or 32 bytes. Compare需要携带 两个操作数,一个为compare value,一个是 swap value。 • Inbound data size is half of the outbound data size because the outbound data contains both compare and swap values, whereas the inbound data has only the original data value. |