Any approach to show threads switch?

為{幸葍}努か 提交于 2019-12-23 18:52:10

问题


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 thread, as well as the time context switch costs, thanks


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6906690/any-approach-to-show-threads-switch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!