如何在Windows中获取上下文切换的通知(7)

发布于 2024-10-15 15:28:56 字数 382 浏览 7 评论 0原文

对于某些 RTOS,当内核切换到线程或什至切换出线程时,会调用一些事件,甚至调用调用函数。在 pSOS 中,它被称为 TaskSwitchCallout。在此,我们将使用代码来增加计数器,从而我们知道线程占用了多少 CPU 时间。在 Qnx 中,您可以订阅内核切换到任务时发生的事件并执行相同的计数器增量。

Windows 中有类似的吗?通常,在 Windows 下,我们无法确定线程上下文相对于系统中运行的其他线程(阅读:托管代码)何时被切入或切出。

请不要问我为什么要这样做,我无法谈论它。不过我可以说 Windows perfmon 中的上下文切换计数器是不够的。但我认为 perfmon 中的上下文切换计数器必须从某个地方获取它的信息......我试图在每个线程的基础上访问该信息。

谢谢!!

For some RTOS's, there is some event, or even a callout function that is called when the kernel is switching into, or even switching out of a thread. In pSOS it was called the TaskSwitchCallout. In this we would have code to increment counters whereby we knew how much CPU time a thread was taking. In Qnx, you can subscribe to an event that occurs when the kernel has switched in a task and perform the same counter increment.

Is there an equivalent in Windows? Often under Windows we cannot determine when exactly a thread context has been switched in or out of relative to other threads running in the system (read:managed code).

Please don't ask why I'm trying to do this, I can't talk about it. However I can say that the context switch counter in Windows perfmon is not sufficient. But I figure that the context switch counter in perfmon must get it's information from somewhere... I'm trying to access that somewhere on a per thread basis.

Thanks!!

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

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

发布评论

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

评论(1

冰火雁神 2024-10-22 15:28:56

Windows 不会通知线程上下文切换。

如果您需要计时信息,请使用 GetThreadTimesQueryThreadCycleTime,或其中之一性能计数器。

或者,您可以使用 Windows 7 用户模式调度程序,以便您负责上下文切换:用户态调度

Windows does not notify threads of context switches.

If you want timing information, use GetThreadTimes or QueryThreadCycleTime, or one of the performance counters.

Alternatively, you could make use of the Windows 7 User-mode scheduler, so you are in charge of the context switches: User-mode scheduling

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