1 Star2 Stars3 Stars4 Stars5 Stars (还没有评分)

DTrace tricks and tips (10) –如何判断CPU当前运行的是不是Idle线程

最近在看sched provider相关内容,搜索到一篇古老的帖子。帖子大意就是用“sched:::on-cpu”和“sched:::off-cpu”统计的线程运行时间和期望的不一样,原因是把Idle线程的运行时间计算进去了,需要过滤掉。在Solaris上过滤Idle线程的方法:

/curthread->t_pri != -1/

不同操作系统过滤Idle线程的方法如下(摘自DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD (Oracle Solaris Series),需要注意这些条件有可能在当前的操作系统上已经改变了,请以当前操作系统为准):

OS Predicate Reference
Solaris /curthread->t_pri != -1/ thread_init() in usr/src/uts/common/disp/thread.c
Mac OS X /!(curthread->state & 0x80)/ TH_IDLE in osfmk/kern/thread.h
FreeBSD /!(curthread->td_flags & 0x20)/ TDF_IDLETD in /usr/src/sys/sys/proc.h

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.