为什么线程的状态正在运行,但是不使用任何CPU? [英] Why is a thread's status running but it doesn't use any CPU?

查看:190
本文介绍了为什么线程的状态正在运行,但是不使用任何CPU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我发现了一个非常奇怪的问题. 我运行Redhat Enterprise Linux 6,CPU是Intel E31275(4核,8线程).我发现一个内核线程(我称其为my_thread)无法正常工作. 通过"ps"命令,我发现my_thread的状态始终在运行:

Today I found a very strange problem. I ran Redhat Enterprise Linux 6, and the CPU was Intel E31275 (4 cores, 8 threads). I found one kernel thread (I called it as my_thread) didn't work correctly. With "ps" command, I found the status of my_thread was always running:

ps ax
5545 ?        R      3:14 [my_thread]
15774 ttyS0    Ss     0:00 -bash
...

但是它的运行时间始终是3:14.既然运行了,为什么总时间没有增加? 从proc文件/proc/5545/sched中,我发现此线程的所有统计信息(包括唤醒计数(se.nr_wakeups))也始终相同.

But its running time was always 3:14. Since it ws running, why didn't the total time increase? From the proc file /proc/5545/sched, I found the all statistics including wakeups count (se.nr_wakeups) for this thread was always the same, too.

在/proc/5545/stack中,我发现此线程称为此函数,但从未返回:

From /proc/5545/stack, I found this thread called this function and never returned:

interruptible_sleep_on_timeout(&q, 3*HZ);

理论上,如果没有其他线程唤醒该线程,则此函数将每3秒返回一次.每次函数返回后,/proc/5545/sched中的se.nr_wakeups都会增加1.但这在我发现线程有问题之后再也没有发生过.

In theory this function would return every 3 seconds if no other threads woke up the thread. Each time after the function returned, se.nr_wakeups in /proc/5545/sched would be increased by 1. But this never happened after I found the thread had some problems.

有人有什么想法吗?

更新: 我发现如果我为此线程设置CPU亲和力,则不会发生此问题.如果我将其固定到专用内核,则一切正常. SMP调度是否存在任何问题?

Update: I find the problem won't occur if I set CPU affinity for this thread. If I pin it to a dedicated core, then everything is OK. Are there any problems with SMP scheduling?

再次更新: 在我取消了BIOS中的超线程后,直到现在我还没有看到过这样的问题.

Update again: After I disalbe hyperthread in BIOS, I have not seen such a problem until now.

推荐答案

首先,R指示线程不是处于运行状态而是可运行的.也就是说,这并不意味着它正在运行,这意味着它处于允许调度程序选择运行状态的状态.两者之间有很大的区别.

First off, R indicates the thread is not in running state but runnable. That is, it does not mean it runs, it means it is in a state the scheduler is allowed to pick it for running. There is a big difference between the two.

类似地,interruptible_sleep_on_timeout(& q,3 * HZ);不会在3个jiffies之后运行线程,而是使其在3个jiffies之后可以运行-实际上,您在"ps"中看到它可以运行,因此可能确实发生了超时.

In a similar sense interruptible_sleep_on_timeout(&q, 3*HZ); will not run the thread after 3 jiffies, but rather make it available for running after 3 jiffies - and indeed you see it in "ps" as available for running, so possibly the timeout has indeed occurred.

由于您没有谈论有关内核线程的任何事情,我什至都不知道它是在您自己的代码还是标准内核代码中,所以我无法真正详细地回答.

Since you did not say anything about the kernel thread in question I don't even know if it is in your own code or standard kernel code so I cannot really answer in detail.

您描述的情况的一个可能原因是某些其他线程(用户或内核)的优先级高于您的线程,因此调度程序从不选择它来运行.如果是这样,则它不可能是实时优先级运行的线程(SCHED_FIFO或SCHED_RR).

One possible reason for the situation you described is that some other thread (user or kernel) has higher priority then your thread and so the scheduler never picks it for running. If so, it is not probably a thread running in real time priority (SCHED_FIFO or SCHED_RR).

这篇关于为什么线程的状态正在运行,但是不使用任何CPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆