A virtual device can use the Call_When_Task_Switched service to install a callback function that the VMM calls whenever the processor switches from one task to another. The callback remains in effect until it is removed by calling the Cancel_Call_When_Task_Switched service.
Similarly, a virtual device can use the Call_When_Thread_Switched service to install a callback function that the VMM calls whenever the processor switches from one thread to another. It can remove the callback function by calling the Cancel_Call_When_Thread_Switched service.
Thread-switch and task-switch callbacks are called extremely frequently and should be written for maximum speed.
See also Call_When_Task_Switched, Call_When_Thread_Switched, Cancel_Call_When_Task_Switched, Cancel_Call_When_Thread_Switched