11

Dskpimc? · 2020年07月15日

CHI Exclusive操作

本节描述exclusive monitor,Snoopable和Non-snoopable exclusive accesses等
作者:谷公子

本文描述CHI协议中Exclusive accesses相关的知识,包含如下三部分:

  • Overview
  • Exclusive monitors
  • Exclusive transactions
一、Overview

Exclusive访问的原则是Logical Processor(LP)执行exclusive sequence包含:

  • 执行对A地址的Exclusive Load;
  • 对A地址的数据进行计算;
  • 执行对A地址的Exclusive Store;

Exclusive access支持两种形式:

  • 对Snoopable memory地址的Exclusive访问;
  • 对Non-snoopable memory地址的Exclusive访问;

如果地址A在Exclusive Load之后被另一个LP更新了,那么在执行Exclusive Store时必须失败。在这种情况下,该store操作不能完成,即store的数据无法写入到A地址。
注意:

  • 术语Exclusive Load是用于描述LP执行特定的程序指令的行为,如LDREX,该操作包含:1. 获得想要执行exclusive操作序列的地址的数据;2. 指示LP开始执行exclusive sequence;
  • 如果数据没有的LP的cache中存在,术语Exclusive Load transaction描述interface发送一笔transaction来获取用于Exclusive Load的数据。不是每一笔Exclusive Load要求一笔Exclusive Load transaction;
  • 术语Exclusive Store是用于描述LP执行特定的程序指令的行为,如STREX,该操作包含:1. 决定是否exclusive sequence失败还是成功;2. 如果可以的话,更新地址所在的数据;另:executing processor知道Exclusive Store是成功还是失败的,如果Exclusive Store失败,那么地址所对应的数据不能被更新,并且Exclusive sequence必须重新开始;
  • 术语Exclusive Store transaction用于描述interface发送一笔transaction来完成需要的Exclusive Store。不是每一笔Exclusive Store都需要一笔Exclusive Store transaction,一笔Exclusive Store transaction成功与否可以通过transaction response的RespErr域段告知LP;
二、Exclusive monitors

可以采用exclusive monitor来追踪exclusive sequence的进行。monitor的位置和为了支持exclusive accesses需要产生的request type是依赖于地址的memory attributes。

2.1 Snoopable memory location

对于Snoopable memory地址的exclusive访问,需要采用两个monitors:
LP monitor:
RN-F内的每个LP都必须实现一个exclusive monitor,用于检查exclusive sequence访问使用的地址信息。LP在执行Exclusive Load时,LP monitor置位;LP monitor在以下情况会复位:

  • LP收到同地址的invalidating snoop request,表明该地址已经被其它LP更新了;
  • 同一个LP对该地址产生的store。如果store是由同一个LP采用non-exclusive命令产生的,monitor的复位是由实现具体决定的;

PoC monitor:
HN-F必须实现一个PoC monitor,用于判定Exclusive Store transaction的结果是成功还是失败。如果成功,表明该transaction已经对其它一致性RN-F可见。如果失败,表明该transaction没有对其它一致性RN-F可见,因此Exclusive Store不能成功;
该monitor用于保证来自一个LP的Exclusive Store transactions的成功只有在该LP没有接收到一笔同地址的snoop transaction,该snoop transaction是由其它RN-F对同地址的Exclusive Store产生的;
对PoC monitor的最低要求就是它能记录任何LP对Snoopable地址产生的exclusive sequence;

  • 如果一个LP已经执行一笔exclusive sequence相关的transaction,然后在其它LP成功的执行Exclusive Store transaction之前,该LP先执行了Exclusive Store transaction,那么该Exclusive Store transaction必须成功;

该monitor必须支持并行监控系统中所有支持exclusive能力的LP;
当HN-F收到一笔和Exclusive Load或Exclusive Store相关的transaction后,该monitor会注册LP正尝试一个exclusive sequence;
当HN-F收到一笔Exclusive Store transaction:

  • 如果PoC monitor中已经记录了该LP正在执行exclusive sequence,也就是说该LP的exclusive sequence还没有被其它Exclusive Store transaction给reset掉,那么该Exclusive Store肯定成功并且允许继续进行处理。在这种情况下,其它LPs的相关注册都应该被复位,CHI协议建议但不要求PoC monitor对于已经成功的LP的注册仍然保留;

如果PoC monitor没有注册LP正在进行的exclusive sequence,也就是说LP的注册位已经被其它LP的Exclusive Store给复位了,那么该LP的Exclusive Store transaction失败且不允许被继续处理。但是PoC monitor必须注册该LP的正在进行exclusive sequence。
注意:

1、对于一个LP,如果Exclusive Store transaction执行成功,那么该LP在PoC monitor的注册位不需要被复位,这样的话,该LP可以继续成功执行一系列的Exclusive Store transaction,直到其它LP成功执行Exclusive Store transaction。对于LP不确定的store transactions,该store transaction必须被处理为来自不同LP的访问;
2、在系统复位初始化,第一个LP执行Exclusive Store transaction可以成功,但是CHI协议不要求有这个功能。在这点上之后,所有其他LPs必须注册它们exclusive sequence的开始,为它们后续Exclusive Store transaction的成功进行;
3、当LP的Exclusive Store transaction成功后,其它LP的注册位都被复位掉,只有成功的exclusive store transaction的CompAck响应成功后,其它LP才可以注册新的exclusive sequence;
4、为了支持Exclusive访问Snoopable memory空间,LP monitor和PoC monitor都需要;

2.2 Additional address comparison

PoC monitor的功能通过增加一些地址比较来增强,只需要记录地址的某些bits就行,不需要全地址的匹配。这种方法可以减少其它LPs访问不同地址的Exclusive Store transaction的失败导致的风险,需要比较的地址位数由具体实现决定的。
当使用额外地址比较的monitor,在exclusive sequence(Load Exclusive or Store Exclusive)的最开始,监控的地址需要被记录下来。只有在其它地址匹配的LP成功的Exclusive Store transaction才会将其复位;
包含额外地址比较的monitor仍然包含最小1bit monitor用于监控每个支持Exclusive能力的LP。
在以下条件发生时,Exclusive Store transaction才允许继续进行:

  • 地址monitor已经给同一个LP的匹配地址的exclusive sequence注册过,且没有被其它地址匹配的Exclusive Store transaction复位了;
  • 最小1bit monitor已经给同一个LP的exclusive sequence注册过,且没有被其它任何值的LP的Exclusive Store transaction复位了。
2.3 Non-snoopable memory location

对于Non-snoopable memory地址区间,使用一个monitor。
System monitor:系统monitor会跟踪访问Non-snoopable地址空间的Exclusive访问。该monitor在有ReadNoSnp(Excl)操作时置位,会被其它同地址LP的改写而复位;
System monitor可以放置于PoS或endpoint devices处。潜在的,系统中endpoint devices的数据比PoS的数目多,将System monitor放置于PoS处可以:

减少System monitor的重复;
减少系统检测Exclusive访问失败的时间;
System monitor应该放置于可以观察到所有访问监控地址的transactions的地方。

三、 Exclusive transactions

以下操作可以使用Excl bit来支持Exclusive访问:

  • Exclusive Load transaction to a Snoopable location:ReadClean、ReadNotSharedDirty、ReadShared;
  • Exclusive Store transaction to a Snoopable location:CleanUnique;
  • Exclusive Load transaction to a Non-Snoopable location:ReadNoSnp;
  • Exclusive Store transaction to a Non-Snoopable location:WriteNoSnp;

Exclusive操作的通讯节点对有:

  • For Exclusives to a Snoopable location:RN-F to ICN(HN-F).
  • For Exclusives to a Non-Snoopable location:1. RN-F, RN-D, RN-I to ICN(HN-F, HN-I);2. ICN(HN-F) to SN-F;3. ICN(HN-I) to SN-I;

exclusive transaction必须使用正确的LPID值;Exclusive reads不能使用Direct data transfer flow。

3.1 Responses to exclusive requests

对于Exclusive requests的响应和其它正常读写的响应类似,除了:

  • Exclusive reads不能使用分离Comp和Data响应;
  • Exclusive reads不会失败,且不能使用DMT或DCT;

exclusive request的响应的RespErr域段可以指示exclusive操作成功与否。RespErr域值为0b01表示Exclusive Okay,即exclusive成功,RespErr域值为0b00表示Normal Okay,即exclusive失败;
只有一笔transaction的Excl置位,才可能返回Exclusive Okay响应;
不是所有的memory空间都支持Exclusive访问。对于不支持Exclusive访问的地址不能回Exclusive Okay响应;
对于访问不支持Exclusive操作的地址,执行Exclusive Store是否会将数据更新到地址中是由具体实现决定的;
CHI协议建议不要对不支持Exclusive访问的地址发送Exclusive Store transaction。
表1为request的Snoopable属性、相关monitor类型、exclusive失败的可能原因以及相应需求。
1.png

3.2 System responsibility

使用CHI协议实现的系统必须遵循以下原则:

  • 为了有效处理Exclusive访问,每个LP应该包含一个monitor;
  • 不管是使用monitor机制还是其它方法,对于所有的exclusive requests,都应该有防饥饿机制;
  • CHI协议建议安全exclusive访问和非安全exclusive访问独立分开处理。
3.3 Exclusive accesses to Snoopable locations

本小节描述当使用exclusive访问Snoopable地址空间时,LP需要执行的行为。

Snoopable Exclusive Load
LP使用Exclusive Load开始一次exclusive sequence。exclusive sequence的开始必须将LP exclusive monitor置位。
LP要执行一笔Snoopable地址的Exclusive访问的数据可能在local cache中已经存在了:

  • 如果LP中该cacheline为Unique状态,CHI协议允许但不推荐LP执行Exclusive Load transaction;
  • 如果LP中该cacheline为Shared状态,CHI协议允许但不要求LP执行Exclusive Load transaction;
  • 如果LP中该cacheline不存在,CHI协议推荐LP执行Exclusive Load transaction来获取一份cacheline数据,但是允许Excl bit不置位的ReadClean或ReadShared或ReadNotSharedDirty transaction;

Snoopable Exclusive Load to Snoopable Exclusive Store
在执行完Exclusive Load之后,LP通常会计算该地址的新值,用于后续Exclusive Store存储。
CHI协议不要求LP完成一次exclusive sequence。例如,Exclusive Load获得数据可以指示旗语有没有被其它LP拿走了,如果被拿走了的话,则不能改变该值直到其它LP释放了该旗语。因此,新产生的exclusive sequence不需等待当前exclusive sequence的完成。
在Exclusive Load和Exclusive Store之间,LP exclusive monitor必须监控该地址的数据来判断是否已经被其它LP改变了。

Snoopable Exclusive Store
同一个LP不允许和任何注册且正在执行exclusive sequence的transaction同时执行Exclusive Store transaction。在发送一笔Exclusive Store transaction之前,LP必须等到任何这样的transaction的message已经交换完,或者接收到RetryAck响应。LP正在执行的已经注册的transactions的exclusive sequence有:

  • Exclusive Load transactions to any location.
  • Exclusive Storetransactions to any location.

当LP正在执行Exclusive Store时,需要以下操作:

  • 如果LP exclusive monitor已经被复位了,那么Exclusive Store必须失败,且LP不能发送Exclusive Store transaction。LP必须重新开始exclusive sequence;注意:当LP monitor被置位了,不能发送最终失败的Exclusive Store transaction,避免不需要的无效掉cacheline数据。
  • 如果cacheline为Unique状态,且LP exclusive monitor置位,那么Exclusive Store已经PASS了,不需要发送Exclusive Store transaction就可以更新该地址的数据;
  • 如果cacheline是Shared状态,且LP exclusive monitor置位,那么LP必须发送一笔Exclusive Store transaction。必须使用Excl比特置位的CleanUnique transaction。LP exclusive monitor必须继续监控在CleanUnique执行过程中,该数据没有被更新。

CleanUnique transaction将会受到Normal Okay或者Exclusive Okay响应。
如果收到Exclusive Okay响应,意味着该transaction已经成功并且把其它RN中有该cacheline的备份失效掉。在该笔exclusive transaction完成后,LP必须再次确认LP exclusive monitor:1. 如果LP exclusive monitor置位,那么Exclusive Store成功且数据更新已经执行完成;2. 如果LP exclusive monitor没有置位,表明该cacheline在Store transaction完成之前已经被更新了,因此Exclusive Store必须失败,exclusive sequence必须重新开始;3. 如果LP无法跟踪到cacheline的exclusive状态,因为该cacheline已经驱逐掉,那么exclusive store必须失败,exclusive sequence必须重新开始。
如果收到Normal Okay响应,意味着其它LP已经完成了Exclusive Store,因此LP的Exclusive Store产生的transaction失败,不能传播给系统中的其它LPs。一笔Exclusive Store transaction以Normal Okay响应结束后,接下来可选选项有:1. 在访问完成后,LP可以检查或不检查cacheline状态,LP将Exclusive Store失败掉并且重新开始exclusive sequence;2. LP可以检查LP exclusive monitor,如果LP exclusive monitor已经被复位了,那么LP必须将Exclusive Store失效掉,并且重启exclusive sequence;3. LP可以检查LP exclusive monitor,如果LP exclusive monitor置位,LP可以再次发起Exclusive Store transaction。

3.4 Exclusive accesses to Non-snoopable locations

对于Non-snoopable的exclusive访问,有以下限制:

  • Exclusive access的地址必须和transaction总的bytes数对其;
  • Exclusive access传输总的bytes数目必须是合法数据size,即1、2、4、8、16、32bytes;

对于不遵循这些限制的行为将导致UNPREDICTABLE;
对于Exclusive read和Exclusive write transaction被认为是一对传输,必须遵守如下准则:

  • Exclusive read和Exclusive write的地址必须相等;
  • Exclusive read和Exclusive write的控制信号,即MemAttr和SnpAttr,必须相等;
  • Exclusive read和Exclusive write的data size必须一样;
  • Exclusive read和Exclusive write的LPID必须一样;

Exclusive operation的最小bytes数是transaction size决定的。System monitor可以监控更大的bytes范围,最多可达Exclusive access的最大size 64。然而,这样可能导致成功的Exclusive访问被认为是失败的,由于在exclusive传输过程中,相邻byte被改写了。
多个访问Non-snoopable memory地址的Exclusive transactions,不管是写还是读,是同一个地址还是不同地址,来自同一个LP的必须不能同时outstanding发送。
如果SN通过Exclusive ReadNoSnp的响应返回Exclusive Fail表示不支持Exclusive访问,那么如果写操作返回的是Exclusive Fail响应,其写数据仍然会被更新到地址的存储空间;
如果SN通过Exclusive ReadNoSnp的响应返回Exclusive Pass表示支持Exclusive访问,那么如果写操作返回的是Exclusive Fail响应,其写数据不会被更新到地址的存储空间。
————————————————

版权声明:本文为CSDN博主「谷公子」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/W1Z1Q/article/details/104232169

CHI系列篇


更多AMBA CHI的知识请关注Arm AMBA 协议集专栏。
推荐阅读
关注数
7875
内容数
81
Arm AMBA协议集,APB,AHB,AXI,CHI等相关公开课回放及文章
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息