ARM双核平台下POSIX定时器引发总CPU负载异常过高问题
500us POSIX定时器引发系统总CPU负载异常飙升问题
现象描述
- 在双核ARM Cortex-A9处理器上运行含500us间隔POSIX定时器的测试程序
timertest,进程自身CPU负载约25%,但系统总CPU负载有时会达到100% - 终止该进程后,系统总CPU负载立即降至1%
- 替换为
setitimer定时器,同时使用htop、procps-ng top等工具验证,现象完全一致 - 将定时器间隔调整为499us后,系统总CPU负载与进程负载匹配,约为24%
相关附件信息
测试代码
#include <stdio.h> #include <signal.h> #include <time.h> static void timer_callback(int sig) { // 空回调,仅触发信号 } int main(void) { timer_t timer_id; struct sigevent sev; struct itimerspec timer_spec; // 设置定时器通知方式为信号 sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = SIGUSR1; sev.sigev_value.sival_ptr = &timer_id; signal(SIGUSR1, timer_callback); // 创建定时器 if (timer_create(CLOCK_MONOTONIC, &sev, &timer_id) == -1) { perror("timer_create failed"); return 1; } // 设置定时器间隔为500us timer_spec.it_value.tv_sec = 0; timer_spec.it_value.tv_nsec = 500 * 1000; timer_spec.it_interval = timer_spec.it_value; if (timer_settime(timer_id, 0, &timer_spec, NULL) == -1) { perror("timer_settime failed"); return 1; } // 主循环挂起 while (1) { pause(); } return 0; }
Linux系统信息
- 内核版本:3.14.0
- 系统:基于Yocto构建的嵌入式Linux系统
CPU信息
- 架构:双核ARM Cortex-A9
- 主频:1GHz
内容的提问来源于stack exchange,提问作者Shu Zhong Hua
相关产品推荐
相关产品推荐

