打印
[开发工具]

ARM上下文同步事件和指令同步障碍物

[复制链接]
290|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
在Arm architecture里,经常提到Context synchronization event(CSE)和Explicit synchronization,Context synchronization events在之前是叫作context synchronization operations。Explicit synchronization是Context synchronization event的结果,也就是CSE发生时,会伴随着Explicit synchronization。从概念上将,Explicit synchronization发生在每个CSE event的第一步,因此,如果CSE event使用之前已更改但在CSE event发生时尚未同步的状态,则保证CSE event使用已同步的状态。另外,任何导致写system registers的system instructions都必须同步,然后才能保证写的结果对该system register的后续direct read可见。
  CSE的触发来源有:
  One of:
  Performing an ISB operation. An ISB operation is performed when an ISB instruction is executed and does not fail its condition code check.
  Exception entry, if FEAT_ExS is not implemented or the exception is taken to AArch32 or if FEAT_ExS is implemented and the appropriate SCTLR_ELx.EIS bit is set.
  Return from an exception, if FEAT_ExS is not implemented, or the exception is returning from AArch32 or if FEAT_ExS is implemented and the appropriate SCTLR_ELx.EOS bit is set.
  Exit from Debug state.
  Executing a DCPS instruction in Debug state.
  Executing a DRPS instruction in Debug state.
  以上这些源头中,4,5,6这三个和debug state相关的。ISB和exception entry events可用于Debug state和Non-debug state。

使用特权

评论回复
沙发
powerantone|  楼主 | 2023-5-10 10:31 | 只看该作者
Context synchronization event的影响有:

重点的几点保证:
  在CSE之前pending的unmasked interrupt和halting debug event是要先于ISB之后指令做完;
  在CSE之前的所有direct或indirect写system registers会影响任何在CSE之后的instruction,包括direct read;
  在CSE之前的所有已完成对TLB/Instruction caches/branch predictor的invalidation操作对CSE之后的指令要可见;
  在CSE之后的所有指令都不能执行任何功能,要等到CSE完成后才行;
  Arm architecture要求产生CSE的instructions不应该是投机执行的,除非允许performance monitors counter证明这种投机。
  现在我们来分析下Instruction Synchronization Barrier(ISB)指令。在Arm architecture是这么定义的:“Instruction Synchronization Barrier flushes the pipeline in the PE and is a context synchronization event.”。从这句话可以看出ISB两个作用:1.flush执行该ISB指令PE的pipeline的指令,也包括core内可能存在的instruction queue/buffer。2.产生1个CSE事件。因此结合最开始分析的CSE,可以得出执行ISB指令后:
  (flush功劳)可以确保在ISB指令complete后,在program order上处于ISB之后的所有instructions是从cache或memory中重新取出的,而不是core内部可能存在的instruction queue/buffer。
  (CSE功劳)可以确保在ISB之前执行的context-changing operations的效果对ISB指令之后取到的指令是可见。需要插入ISB指令以确保operation的效果对ISB指令之后取到的指令可见的context-changing operation的例子有:Completed cache and TLB maintenance instructions和Changes to System registers。
  (CSE功劳)可以确保在program order上位于ISB指令之后的任何context-changing operations只有在ISB执行完成后才能生效。
  (CSE功劳)可以确保在ISB之后的读system registers指令必须要等ISB结束了,才能读取system register。
  “Completed cache and TLB maintenance instructions”指的是completed的才能被ISB保证,如果cache或TLB maintenance instruction还没有completed,那么就算执行ISB也是无法保证这些maintenance instructions的效果对ISB之后的指令可见。因此在执行cache/TLB maintenance instructions之后,通常需要执行DSB来确保它们的completed,这样再执行ISB的时候,就可以确保maintenance instruction被之后指令observer(看到)了。总得instruction sequence应该是这样的:cache/TLB maintenance instructions + DSB + ISB。
  “Changes to System registers”指的是在ISB之前所有对system register的更改都必须对ISB之后指令可见,也就是ISB要保证对system register的更改要completed,只有这样才能确保被ISB后续指令可见。因此,这点和上述cache/TLB maintenance instructions的要求还不大一样。

使用特权

评论回复
板凳
powerantone|  楼主 | 2023-5-10 10:32 | 只看该作者
 ISB的功能示意图如下:


使用特权

评论回复
地板
Pulitzer| | 2024-4-1 07:06 | 只看该作者

STM32芯片中有多个工作时钟源的外设很常见

使用特权

评论回复
5
童雨竹| | 2024-4-1 09:02 | 只看该作者

CPU借助于APB总线访问相关寄存器达到对I2C1工作模块的控制

使用特权

评论回复
6
Wordsworth| | 2024-4-1 10:05 | 只看该作者

ART2固定使用PCLK时钟,只有开启和关闭的问题,不存在其它时钟源选择

使用特权

评论回复
7
Clyde011| | 2024-4-1 11:08 | 只看该作者

一部分是I2C1的工作模块,另外一部分是其控制模块

使用特权

评论回复
8
公羊子丹| | 2024-4-1 12:01 | 只看该作者

控制模块的时钟仍然由外设时钟PCLK提供

使用特权

评论回复
9
万图| | 2024-4-1 13:04 | 只看该作者

USART1可以有多个时钟源

使用特权

评论回复
10
Uriah| | 2024-4-1 14:07 | 只看该作者

STM32CUBEMX配置生成初始化代码

使用特权

评论回复
11
帛灿灿| | 2024-4-1 16:03 | 只看该作者

通过访问寄存器来控制I2C1工作时钟的开启。

使用特权

评论回复
12
Bblythe| | 2024-4-1 17:06 | 只看该作者

I2C1的时钟可以自行选择HSI或者SYSCLK

使用特权

评论回复
13
周半梅| | 2024-4-1 19:02 | 只看该作者

I2C1工作时钟源选择;I2C1模块工作时钟的开启使能。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

411

主题

1458

帖子

4

粉丝