Skip to content

Conversation

@BernardXiong
Copy link
Member

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

rt-link在64位系统上构建会存在问题;

你的解决方案是什么 (what is your solution)

在类型转换上使用更通用的rt_base_t/rt_ubase_t,而不是强制32位。

请提供验证的bsp和config (provide the config and bsp)

  • BSP:

qemu-virt64-aarch64/qemu-virt64-riscv

  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:fix_rt-link
  • 设置PR number为 \ Set the PR number to:11018
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 fix_rt-link 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fix_rt-link branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/utilities/rt-link/src/rtlink.c
  • components/utilities/rt-link/src/rtlink_dev.c

📊 Current Review Status (Last Updated: 2025-12-04 21:28 CST)

  • Maihuanyi Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes compilation issues in the rt-link component when building for 64-bit architectures. The changes ensure type safety by using architecture-agnostic types (rt_ubase_t, ssize_t) instead of hardcoded 32-bit types, addressing pointer size and data type mismatches on 64-bit platforms.

Key Changes:

  • Converted timer parameter type casts from rt_uint32_t to rt_ubase_t for 64-bit pointer compatibility
  • Updated DFS file operation function signatures to use ssize_t return type per standard interface requirements
  • Increased thread stack size from 1KB to 4KB to accommodate 64-bit stack frame requirements

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
components/utilities/rt-link/src/rtlink_dev.c Added explicit includes for dfs_file.h and fcntl.h; changed read/write function return types and local variables from int to ssize_t for 64-bit compatibility with DFS file operations interface
components/utilities/rt-link/src/rtlink.c Changed timer parameter handling from rt_uint32_t to rt_ubase_t casts (5 locations); increased thread stack size from 1KB to 4KB; reordered hardware deinitialization before critical section entry; added error checking for rt_link_hw_init()

Comment on lines 1177 to +1178
{
rt_enter_critical();
rt_link_hw_deinit();
rt_enter_critical();
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Concurrency/并发] Potential race condition in critical section reordering / 临界区重排可能引入竞争条件

English: Moving rt_link_hw_deinit() before rt_enter_critical() creates a potential race condition. If another thread accesses rt_link_scb between rt_link_hw_deinit() and rt_enter_critical(), it may observe inconsistent state.

Consider this ordering instead:

  1. Enter critical section first
  2. Save a local copy of rt_link_scb
  3. Set rt_link_scb = RT_NULL
  4. Exit critical section
  5. Call rt_link_hw_deinit() and other cleanup using the local copy

中文:将 rt_link_hw_deinit() 移到 rt_enter_critical() 之前可能引入竞争条件。如果其他线程在 rt_link_hw_deinit()rt_enter_critical() 之间访问 rt_link_scb,可能会观察到不一致的状态。

建议采用以下顺序:

  1. 先进入临界区
  2. 保存 rt_link_scb 的本地副本
  3. 设置 rt_link_scb = RT_NULL
  4. 退出临界区
  5. 使用本地副本调用 rt_link_hw_deinit() 和其他清理操作

Copilot uses AI. Check for mistakes.
#define RT_LINK_THREAD_TICK 20
#define RT_LINK_THREAD_PRIORITY 25
#define RT_LINK_THREAD_STACK_SIZE 1024 /* 32 bytes aligned */
#define RT_LINK_THREAD_STACK_SIZE (4 * 1024) /* 32 bytes aligned */
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Maintainability/可维护性] Stack size increase needs justification / 栈大小增加需要说明理由

English: The stack size is increased from 1024 to 4096 bytes (4x increase). While this may be necessary for 64-bit architectures due to larger pointer sizes and stack frame alignment requirements, the change lacks documentation explaining:

  1. Why this specific size (4KB) was chosen
  2. Whether this has been tested on resource-constrained devices
  3. The actual stack usage observed on 64-bit platforms

Consider adding a comment explaining the rationale, or using conditional compilation to set different stack sizes for 32-bit vs 64-bit architectures:

#ifdef ARCH_CPU_64BIT
#define RT_LINK_THREAD_STACK_SIZE   (4 * 1024) /* Larger stack for 64-bit */
#else
#define RT_LINK_THREAD_STACK_SIZE   1024       /* Original size for 32-bit */
#endif

中文:栈大小从 1024 字节增加到 4096 字节(增加了 4 倍)。虽然这对于 64 位架构可能是必要的(由于更大的指针大小和栈帧对齐要求),但此更改缺少文档说明:

  1. 为什么选择这个特定大小(4KB)
  2. 是否在资源受限的设备上进行了测试
  3. 在 64 位平台上观察到的实际栈使用情况

建议添加注释说明理由,或使用条件编译为 32 位和 64 位架构设置不同的栈大小(见示例代码)。

Suggested change
#define RT_LINK_THREAD_STACK_SIZE (4 * 1024) /* 32 bytes aligned */
/*
* RT_LINK_THREAD_STACK_SIZE:
* For 64-bit architectures, stack frames and pointers are larger, requiring more stack space.
* For 32-bit architectures, 1024 bytes is sufficient for typical usage.
* If you are running on a resource-constrained device, consider profiling actual stack usage.
*/
#ifdef ARCH_CPU_64BIT
#define RT_LINK_THREAD_STACK_SIZE (4 * 1024) /* Larger stack for 64-bit arch */
#else
#define RT_LINK_THREAD_STACK_SIZE 1024 /* Original size for 32-bit arch */
#endif

Copilot uses AI. Check for mistakes.
@Rbb666 Rbb666 merged commit f7b3a8f into RT-Thread:master Dec 8, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants