有什么方法可以显示线程切换吗?

发布于 2024-11-27 07:44:55 字数 73 浏览 2 评论 0原文

请问有没有什么办法或者工具可以展示线程切换的过程,即可以知道在任何特定的时间,CPU被哪个线程占用了,以及上下文切换的时间成本,谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回眸一笑 2024-12-04 07:44:55

SystemTap 对于这种事情很有用。有一个固定示例 sched_switch.stp

但它不测量切换所用的时间。这看起来很棘手,至少有几个原因。首先,您必须为入口和出口决定合适的探针来测量增量,但我现在没有找到任何东西。 (在相关进程中进入/退出内核可能是一个不错的近似值?虽然我现在还没有看到,但可能有一些东西。)其次,如果您想知道在多大程度上值得避免上下文切换,那么它如果您不考虑更频繁地切换任务而导致的额外 CPU 缓存未命中,那么这将是一幅不完整的图景,而这些是随后发生的。我认为获得答案的唯一好方法可能是实验。特别是,您可以尝试调整调度参数(请参阅 cfs-tuning .pdf)来查看更频繁的上下文切换如何影响程序的速度。

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.

暮光沉寂 2024-12-04 07:44:55

如果您已将 ftrace 编译到内核中,则可以使用 sched_switch 跟踪器来输出进程唤醒和上下文切换的跟踪。如果您的任务是 RT 调度的,您还可以使用唤醒跟踪器来了解任务唤醒和调度之间的最大延迟。有关详细信息,请参阅 Documentation/trace/ftrace.txt

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文