开发者

Any approach to show threads switch?

all, Is there any approach or tools to show the process of thread switch, that is, I can know at any specific time, the CPU is taken by which t开发者_JAVA技巧hread, as well as the time context switch costs, thanks


SystemTap is useful for this kind of thing. There's a canned example sched_switch.stp for this.

It doesn't measure the elapsed time of the switch, though. That seems tricky for at least a couple reasons. First, you'd have to decide an appropriate probe for the entry and exit to measure a delta, and I'm not finding anything right now. (Entering/exiting kernel within the relevant processes might be a decent approximation? There's probably something for that though I don't see it right now.) Second, if you're asking to know to what extent it's worth avoiding context switches, it'd be an incomplete picture if you didn't consider extra CPU cache misses from switching tasks more often, and those come afterward. I think the only good way to get an answer may be experimentally. In particular, you might try tweaking scheduling parameters (see cfs-tuning.pdf) to see how more frequent context switches affect your program's speed.


If you have ftrace compiled into your kernel, you can use the sched_switch tracer to output a trace of process wakeups and context switches. If your tasks are RT scheduled, you can also use the wakeup tracer to get an idea of the maximum latency between a task's wakeup and scheduling. see Documentation/trace/ftrace.txt for more information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜