FreeBSD/sys/dev/hyperv/vmbus/hv_ring_buffer.c
/*
 * When we write to the ring buffer, check if the host needs to
 * be signaled. Here is the details of this protocol:
 *
 *	1. The host guarantees that while it is draining the
 *	   ring buffer, it will set the interrupt_mask to
 *	   indicate it does not need to be interrupted when
 *	   new data is placed.
 *
 *	2. The host guarantees that it will completely drain
 *	   the ring buffer before exiting the read loop. Further,
 *	   once the ring buffer is empty, it will clear the
 *	   interrupt_mask and re-check to see if new data has
 *	   arrived.
 */
When we write to the ring buffer, check if the host needs to
be signaled. Here is the details of this protocol.

1. The host guarantees that while it is draining the
ring buffer, it will set the interrupt_mask to
indicate it does not need to be interrupted when
new data is placed.

2. The host guarantees that it will completely drain
the ring buffer before exiting the read loop. Further,
once the ring buffer is empty, it will clear the
interrupt_mask and re-check to see if new data has
arrived.
When we write to the ring buffer check if the host needs to be signaled . Here is the details of this protocol . 1 . The host guarantees that while it is draining the ring buffer it will set the interrupt_mask to indicate it does not need to be interrupted when new data is placed . 2 . The host guarantees that it will completely drain the ring buffer before exiting the read loop . Further once the ring buffer is empty it will clear the interrupt_mask and re - check to see if new data has arrived .
static boolean_t
hv_ring_buffer_needsig_on_write(
	uint32_t			old_write_location,
	hv_vmbus_ring_buffer_info*	rbi)
{
	mb();
	if (rbi->ring_buffer->interrupt_mask)
		return (FALSE);
	rmb();
	if (old_write_location == rbi->ring_buffer->read_index)
		return (TRUE);
	return (FALSE);
}
static boolean_t hv_ring_buffer_needsig_on_write ( uint32_t old_write_location , hv_vmbus_ring_buffer_info * rbi ) { mb ( ) ; if ( rbi -> ring_buffer -> interrupt_mask ) return ( FALSE ) ; rmb ( ) ; if ( old_write_location == rbi -> ring_buffer -> read_index ) return ( TRUE ) ; return ( FALSE ) ; }
When we write to the ring buffer, check if the host needs to
 be signaled.
When we write to the ring buffer check if the host needs to be signaled .
/* Read memory barrier */ /*
	 * This is the only case we need to signal when the
	 * ring transitions from being empty to non-empty.
	 */