Community
cancel
Showing results for 
Search instead for 
Did you mean: 
AG__Phillip
Beginner
145 Views

Determining wake up reason for MWAIT

Hello,

I'm trying to figure out how can one check what is the reason for the MWAIT to wakeup.

I know there are several reasons for MWAIT to wakeup, including a write to the monitored address (of course, and to rule out this specific reason is obvious), interrupts, faults and signals.

What I'm trying to figure out exactly is how can you know which FAULT/INTERRUPT/SIGNAL woke you up?

It is not written in the manuals or anything.

Thanks in advance.

0 Kudos
1 Reply
James_C_Intel2
Employee
145 Views

What I'm trying to figure out exactly is how can you know which FAULT/INTERRUPT/SIGNAL woke you up?

There is no way to discover this. I think the problem here is that your mental model of how mwait is used is wrong. Mwait is not a communication mechanism, it doesn't ever tell you that some condition on which you wanted to wait has occurred. Rather, it is a way of sleeping efficiently that will wake up at a time when it's likely that it's worth checking the condition. So you should think of mwait finishing as a suggestion that you should check the condition your're waiting for, not as a guarantee that the condition is true.

Therefore code using mwait looks something like this

// Wait for *target to be non-zero
static void mwaitForNonZero(uint32_t volatile * target)
{
    while (*target == 0)
    {
	_mm_monitor ((void *)target, 0, 0);
	if (*target != 0)  /* Avoid race if *target changes after the while but before the monitor */
	    break;
	_mm_mwait (0, 0);
    }
}

 

Reply