外观
高性能测试示例
2025-10-29
概述
本示例演示如何在 RC3506 开发板上进行线程抖动和中断延迟性能测试,通过在多个 CPU 核心上模拟 80%的负载,评估 RT-Thread 在高负载场景下的实时性能表现,包括线程调度的稳定性和中断响应速度。
运行高性能测试体验
用本示例测试 RT-Thread 线程抖动和中断延迟性能,在 3 个 CPU 上增加 80% 的负载,模拟在实际高负载项目场景下,RT-Thread 的实时性能。
创建工程点击展开
依次点击 “文件” -> “新建” -> "RT-Thread RuiChing App 项目"。

在弹出新建向导中选择 开发版 、BSP: 、示例 、 调试器/下载器。选择好之后点击 “完成”。

点击 “完成” 后,等待工程创建完成。

创建完成。

构建工程点击展开
单击工程使工程进入 Active-Debug 模式。

点击工具栏上的构建按钮进行工程编译。

构建成功后,会显示构建成功的信息。

固件下载点击展开
固化设备树

固化 APP

核心示例代码
applications/load_perf.c
void load_perf_thread(void)
{
// 3个CPU加载80%负载,然后测试线程抖动
loadctl(3, (char *[]){"loadctl", "0", "80"});
loadctl(3, (char *[]){"loadctl", "1", "80"});
loadctl(3, (char *[]){"loadctl", "2", "80"});
rt_perf(2, (char *[]){"rt_perf", "thread_jitter"});
rt_thread_mdelay(100);
loadctl(2, (char *[]){"loadctl", "stop"});
}
MSH_CMD_EXPORT(load_perf_thread, Load Thread Performance Test);
void load_perf_irq(void)
{
// 3个CPU加载80%负载,然后测试中断延迟
loadctl(2, (char *[]){"loadctl", "stop"});
loadctl(3, (char *[]){"loadctl", "0", "80"});
loadctl(3, (char *[]){"loadctl", "1", "80"});
loadctl(3, (char *[]){"loadctl", "2", "80"});
rt_perf(2, (char *[]){"rt_perf", "irq_latency"});
rt_thread_mdelay(100);
loadctl(2, (char *[]){"loadctl", "stop"});
}
MSH_CMD_EXPORT(load_perf_irq, Load irq Performance Test);运行示例
操作步骤
- 将程序下载到开发板
- 打开串口终端连接开发板
- 输入
load_perf_thread命令测试线程抖动性能 - 输入
load_perf_irq命令测试中断延迟性能
预期结果
- 运行线程抖动测试:CPU0、CPU1 和 CPU2 的负载达到 80%,然后执行线程抖动测试,在高负载下线程抖动<5us
- 运行中断延迟测试:CPU0、CPU1 和 CPU2 的负载达到 80%,然后执行中断延迟测试,在高负载下中断延迟<5us
rtt 终端
msh />load_perf_thread
Started load thread on CPU0 with 80%
Started load thread on CPU1 with 80%
Started load thread on CPU2 with 80%
perf count total(us) min(us) max(us) avg(us) speed(MB/s)
------------------- ---------- ---------- --------- --------- --------- -------------
thread_jitter 10000 1491 0.1250 1.3333 0.1250 -
All load threads stopped.rtt 终端
msh />load_perf_irq
All load threads stopped.
Started load thread on CPU0 with 80%
Started load thread on CPU1 with 80%
Started load thread on CPU2 with 80%
perf count total(us) min(us) max(us) avg(us) speed(MB/s)
------------------- ---------- ---------- --------- --------- --------- -------------
irq_latency 10000 7620 0.7083 1.8750 0.7500 -
All load threads stopped.