小型 Linux 应用程序生成 SCHED_FIFO 线程并休眠。长按键锁定系统
在多核系统 (Ubuntu 11.04 x86-32) 上运行下面的代码(使用 -lpthread 编译),它只是生成一个 SCHED_FIFO 线程并进入睡眠状态,显示一些奇怪的行为。如果你按下一个键,它就会很好地回显出来。但是,如果按住某个键,进程将挂起,并且您将需要硬重新启动(软重新启动会挂起,就像kill -9一样)。通过 telnet 会话执行相同的操作效果很好。
#include <sched.h>
#include <pthread.h>
#include <assert.h>
void* schedtest_busy_wait_thread_entry(void *arg)
{
struct sched_param sp;
sp.__sched_priority = sched_get_priority_min(SCHED_FIFO);
assert(sched_setscheduler(0, SCHED_FIFO, &sp) == 0);
while (1);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread_id;
assert(pthread_create(&thread_id, NULL, schedtest_busy_wait_thread_entry, NULL) == 0);
while (1) sleep(1);
return 0;
}
显然,这只是一个更大、更复杂的系统的摘录,该系统需要繁忙的等待 SCHED_FIFO 线程(具有硬编码亲和力),但显示相同的行为。 /proc/sys/kernel/sched_rt_runtime_us 默认为 950000。
有任何指针吗?
Running the code below (compiled with -lpthread) on a multicore system (Ubuntu 11.04 x86-32), which simply spawns a SCHED_FIFO thread and goes to sleep, displays some strange behavior. If you press a key it echoes it out just fine. However, if you hold down a key the process will hang and you will need to hard reboot (soft reboot hangs as does kill -9). Doing the same via a telnet session works just fine.
#include <sched.h>
#include <pthread.h>
#include <assert.h>
void* schedtest_busy_wait_thread_entry(void *arg)
{
struct sched_param sp;
sp.__sched_priority = sched_get_priority_min(SCHED_FIFO);
assert(sched_setscheduler(0, SCHED_FIFO, &sp) == 0);
while (1);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread_id;
assert(pthread_create(&thread_id, NULL, schedtest_busy_wait_thread_entry, NULL) == 0);
while (1) sleep(1);
return 0;
}
Obviously this is just an excerpt of a much larger and more complex system that requires a busy waiting SCHED_FIFO thread (with hard coded affinity) but displays this same behavior. /proc/sys/kernel/sched_rt_runtime_us is at the default 950000.
Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论