January 3rd, 2006

The world's slowest RET instruction

Occasionally, somebody will ask

I’m debugging a hang, and I see that many threads are stuck at a RET instruction. When I try to trace one instruction from that thread, the trace breakpoint never fires. It’s as if the RET instruction itself is wedged! I’ve found the world’s slowest RET instruction.

(A common variation on this theme is that the thread in question is consuming 100% CPU… on a RET instruction?) Because what you see in that RET instruction is a thread that is executing in kernel mode. The kernel parked the user-mode side of the thread at a RET instruction, poised to execute once the kernel-mode side has returned. Which it hasn’t yet. In order to see what is really going on with that thread, you have to drop into the kernel debugger. You might be able to make some educated guesses (also known as “invoke psychic powers”) based on what you can still see on the user-mode side. For example, the RET could be returning back to a WaitForSingleObject call, which tells you that whatever this thread is waiting for hasn’t happened yet.

[While Raymond was on vacation, the autopilot stopped working due to a power outage. This entry has been backdated.]

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.