[bsp][cvitek] add dcache opration functions for cache coherence#9696
[bsp][cvitek] add dcache opration functions for cache coherence#9696Rbb666 merged 1 commit intoRT-Thread:masterfrom
Conversation
| #include <stdint.h> | ||
| #include <sys/types.h> | ||
|
|
||
| void flush_dcache_range(uintptr_t addr, size_t size); |
|
|
||
| #include "cache.h" | ||
|
|
||
| inline void rt_hw_cpu_dcache_enable(void) |
There was a problem hiding this comment.
根据数据手册添加了icache相关操作,修改了config防止cache相关函数定义为空
4bf57af to
15ea743
Compare
|
@zdtyuiop4444 请问你在做什么实验时发现了这个问题?难道你有做大小核通过共享内存通讯吗?这个场景是什么? |
|
@zdtyuiop4444 请补全 commit 信息。具体要求参考:https://github.com/plctlab/plct-rt-thread/tree/notes/0.notes#%E5%A6%82%E4%BD%95%E6%8F%90%E4%BA%A4-git-commit 而且这个 commit 的标题需要修改(包括整个 PR 的标题),不仅仅是 dcache,还有 icache |
bsp/cvitek/c906_little/board/cache.c
Outdated
| CACHE_OP_RANGE(DCACHE_IPA_A0, start, size); | ||
| } | ||
|
|
||
| inline void inv_icache_range(uintptr_t start, size_t size) { |
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2024/11/27 zdtyuiop4444 Add Icache operation | ||
| * 2024/11/26 zdtyuiop4444 The first version |
目前 riscv 这边我希望所有的 pr 之前能够通过 issue 充分讨论一下修改的需求,为此我新建了一个 issue: 请麻烦您去这个 issue 上再把遇到的问题和需求再描述一下。 特别的我有个问题,按照你在 pr 上的说法,
那么目前这么改是采用了 flush 的策略?我想确认一下这里对内核哪里的 RT_HW_CACHE_FLUSH 操作有影响了? 以上问题请在 #9769 中描述一下,谢谢。 |
我最近正在做一个这样的应用:小核采集传感器数据发给大核,大核通过网络传输到云端。
之前没有看到这个,我研究一下改掉。
首先确实是采用了flush的策略,然后第二个问题有点没看懂,RT_HW_CACHE_FLUSH似乎是一个宏定义,我看在libcpu下也有c906相关的cache定义,但这些代码应该只在RT SMART才会被编译,所以在小核上应该不会有影响。 |
我原来是想问增加你的改动后,内核中哪里会调用到你增加的 cache update 操作,不过看了你在 issue 中的描述,我理解你增加这些函数后,应该会是在你的测试程序中调用 flush 的操作,只不过这部分代码目前并不在 RTT 中,对吧? |
|
备注一下,我发现对 ICACHE/DCACHE 的操作会涉及 c906 的专有寄存器 mhcr,这导致工具链必须使用 玄铁的 |
是的,测试代码要配合mailbox用,那个修改我还没整理好 |
|
This PR fixed #9769 |
By default, the small core enables D-Cache without ensuring cache coherence. Therefore, when using shared memory, inconsistencies can occur in the data read by the small core and the big core. Solution: Migrate cache-related functions from the official duo-buildroot-sdk library to implement cache-related operations in rthw.h. This allows you to either disable D-Cache or call the flush_dcache_range function before reading and after writing for synchronization. It is recommended to use the flush_dcache_range function, as disabling D-Cache can have a significant performance impact. Signed-off-by: zdtyuiop4444 <ign7798540@gmail.com>
|
@zdtyuiop4444 你为什么在 review approve 后还 push 代码,如果这样是需要重新 review 的。 我不确定你又改了什么,所以我重新发起了 review。 |
非常抱歉,我看这个pullrequest一直没有合并,以为原因是因为我这边有一个check没有通过,所以更改了一个空行来重新触发check,排查check不通过的原因,没有意识到不实际修改任何内容也需要重新approve。 |
我看 CI 上的 check 现实都是 pass 的。没有合并应该只是 maintainer 没有 merge 而已。你可以采用各种方式催促(PR 上 comment 也是其中之一)。但不要修改代码,否则 review 就失去意义了。 |
感谢,以后有疑问一定先在PR里面讨论好 |
|
@zdtyuiop4444 这个 PR 合入后,编译小核会有不少 warnings: See #9920 你还有空 fix 一下?只fix cache 相关的吧。还有些其他的 warning ,目前由另外一个 pr #9865 在 fixing。 |
好的,我提一个新pr修一下 |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
由于小核默认开启了D-Cache且没有缓存一致性保证,所以在使用共享内存时会出现大小核读取的数据不一致的情况
你的解决方案是什么 (what is your solution)
从官方的duo-buildroot-sdk库中迁移D-Cache相关函数,这样就可以选择关闭D-Cache或在读前写后调用flush_dcache_range函数进行同步
请提供验证的bsp和config (provide the config and bsp)
BSP: bsp/cvitek/c906_little/board
.config:
action:
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up