[bsp][c908]Added support for rt-smart and mmu Sv39/48 to QEMU xiaohui c908, and added mmu_demo for test. - #11775
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: libcpu_riscvReviewers: @Yaochenger Changed Files (Click to expand)
🏷️ Tag: workflowReviewers: @Rbb666 @kurisaW @supperthomas Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-09-07 20:31 CST)
📝 Review Instructions
|
|
ff47c99 to
c56c6d2
Compare
|
@rcitach 帮忙review下 |
42dd44b to
c5e65c4
Compare
|
|
||
| /* Runtime level index extraction: get the page table index at given level (1-based) */ | ||
| #define GET_LVL_INDEX(addr, level) \ | ||
| (((rt_ubase_t)(addr) >> (ARCH_PAGE_SHIFT + (ARCH_PAGE_TBL_LEVELS - (level)) * ARCH_INDEX_WIDTH)) & VPN_MASK) |
There was a problem hiding this comment.
对于通用页表级数,这里将 VPN_MASK 替换为 ((1UL << ARCH_INDEX_WIDTH) - 1)) 是否会好一些
| #define PTE_BITS 10 | ||
| #define VPN_BITS 9 | ||
| #define VPN_MASK 0x1ffUL | ||
| #define PTE_BITS 10 |
There was a problem hiding this comment.
这个应该是和 PTE_PPN_SHIFT 表示的同一个意思吧,这里建议统一,不要维护两个名字
| void rt_hw_ipi_send(int ipi_vector, unsigned int cpu_mask) | ||
| { | ||
| int cpuid = __builtin_ctz(cpu_mask); // get the bit position of the lowest set bit | ||
| ipi_vectors[cpuid] |= (uint8_t)ipi_vector; | ||
| sbi_send_ipi((const unsigned long *)&cpu_mask); | ||
| } |
There was a problem hiding this comment.
Line 666 in 7fa651b
确认一下系统运行是否会涉及到 https://github.com/RT-Thread/rt-thread/blob/master/src/scheduler_mp.c 中的
rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask);
否则函数内部会出现一个这种场景:
ipi_vector == 0;
ipi_vectors[cpuid] |= 0;
导致 pending 位图没有任何一位被置为 1
| void rt_hw_ipi_send(int ipi_vector, unsigned int cpu_mask) | ||
| { | ||
| int cpuid = __builtin_ctz(cpu_mask); // get the bit position of the lowest set bit | ||
| ipi_vectors[cpuid] |= (uint8_t)ipi_vector; |
| ipi_vector &= ~(1U << bitpos); | ||
| if (bitpos < RT_MAX_IPI && ipi_desc[bitpos].handler != RT_NULL) | ||
| { | ||
| rt_hw_atomic_and((volatile rt_atomic_t *)&ipi_vectors[rt_cpu_get_id()], ~((rt_atomic_t)(1 << bitpos))); |
There was a problem hiding this comment.
rt_hw_atomic_and 的实现最终使用的是 amoand.d,要求地址至少 8 字节对齐。此处强制转换成 rt_atomic_t * 可能会触发异常和越界读写
There was a problem hiding this comment.
感谢指正!这一块的实现在这个版本中我只是简单迁移了rt-thread\libcpu\risc-v\virt64\interrupt.c中的相应实现,确实没有细看,稍后我一并修改
| { | ||
| int cpuid = __builtin_ctz(cpu_mask); // get the bit position of the lowest set bit | ||
| ipi_vectors[cpuid] |= (uint8_t)ipi_vector; | ||
| sbi_send_ipi((const unsigned long *)&cpu_mask); |
There was a problem hiding this comment.
这里的强制转换数据长度有些问题,建议先构造一个真正的 unsigned long hart_mask
|
有关于SMP的部分应该是迁移了rt-thread\libcpu\risc-v\virt64\interrupt.c中的相应实现,但是RISCV中关于SMP的支持还不足够完善,仍有一些问题需要解决,并且 riscv 的调整也在进行中 #11246 对于这个PR的主要目的(rt-smart and mmu Sv39/48 )来说是没什么问题的,问题主要涉及到SMP的方面,并且Kconfig默认关闭了SMP。 建议拆分成两部分分开合入master:
|
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
在QEMU xiaohui平台上,增加c908对rt-smart支持,并接入libcpu以支持mmu
你的解决方案是什么 (what is your solution)
1.修改原有libcpu中mmu框架,增加SV48/SV57支持,并提供测试mmu_demo
2.参考K230和Virt/C906实现方式,增加c908对rt-smart支持
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 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