none
Device Driver Clarifications RRS feed

  • Question

  • Hi all

    I have Three Questions or clarifications

    Q1) Regarding Driver code execution:

    Is it true that the Device Driver code is executed in an arbitrary thread context, if so does the OS perform a context switch with the current executing thread and what happens if the DPC routine is lengthy and the thread times out, will it again execute the Driver code next time the kernel thread is scheduled and  until it is done with an DPC routine.


    Q2) PAGE_CODE()

    The Driver Code could be executed in an  arbitrary thread context and if that thread happens to run at a higher IRQL level
    Hence the macro PAGE_CODE() will ensure that the section of the deriver code is not executed at a higher IRQL level. is my understanding correct ?

    Q3) also at what instance does the OS elevate the thread to Higher IRQL level?

    if anyone can clarify these questions

    regards

    Rekha


    • Edited by Rekha_KP Thursday, November 8, 2012 1:09 PM
    Thursday, November 8, 2012 1:03 PM

Answers

  • Hi all

    I have Three Questions or clarifications

    Q1) Regarding Driver code execution:

    Is it true that the Device Driver code is executed in an arbitrary thread context

    Yes, some driver code may run in arbitrary thread context.

    if so does the OS perform a context switch with the current executing thread

    No, the scheduler in this situation will be locked and won't switch to other thread.

    and what happens if the DPC routine is lengthy and the thread times out

    Threads do not time out. Windows can detect when a DPC runs for too long time. Then the kernel may bugcheck :-(

    will it again execute the Driver code next time the kernel thread is scheduled and  until it is done with an DPC routine.

    No.

    Q2) PAGE_CODE()

    The Driver Code could be executed in an  arbitrary thread context and if that thread happens to run at a higher IRQL level
    Hence the macro PAGE_CODE() will ensure that the section of the deriver code is not executed at a higher IRQL level. is my understanding correct ?

    No. You must ensure that paged code runs at correct IRQL.

    Q3) also at what instance does the OS elevate the thread to Higher IRQL level?

    For example, when the thread acquires a spinlock.

    Regards,
    --pa

    Thursday, November 8, 2012 1:34 PM

All replies

  • to clarify "youmust ensure that paged code runs at correct IRQL", it means you must use the right locks and mark the appropriate code as paged. you CANNOT lower irql if you were not the one raising IRQL.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, November 8, 2012 4:09 PM
  • Thanks Pavel and Doron

    appreciate your help!!!

    regards

    Rekha

    Thursday, November 8, 2012 5:02 PM
  • "what happens if the DPC routine is lengthy and the thread times out"

    You should not make your DPC routines lengthy.  For more information about IRQL, you can take a look at http://msdn.microsoft.com/en-us/windows/hardware/gg487402.aspx.  DPCs are run at DISPATCH_LEVEL.  Per that document:
    While the processor operates at this level, one thread cannot pre-empt another; only a hardware interrupt can interrupt the running thread. To maximize overall system throughput, driver code that runs at DISPATCH_LEVEL should perform only the minimum amount of required processing.

    Thursday, November 8, 2012 6:57 PM
  • >The Driver Code could be executed in an  arbitrary thread context and if that thread happens to run at a higher IRQL level

    If you are running in an arbitrary thread context you must be executing a DPC or ISR, that means you know for sure that you are running at elevated IRQL.

    //Daniel
    Friday, November 9, 2012 1:36 AM