locked
How to make sure a driver is dead, C++ RRS feed

  • Question

  • I'm just wondering if there is a way when calling DeactivateDevice to block and wait for the driver to fully unload. We switched to a transactional filesystem and now its taking a bit to long to unload the driver.
    Thursday, November 10, 2011 8:42 PM

Answers

  • I'm not sure I understand your question anyway these are some thougts: when you call DeactivateDevice the device manager performs several actions to remove the device from its bookkeeping structures and, at the end, it calls the driver XXX_Deinit (possibly also XXX_PreDeinit). These operations are synchronous so when DeactivateDevice returns this means that the driver XXX_Deinit has also returned so 'the driver has been unloaded'. The latest can or cannot be actually true depending on the driver itself: for example you may still have threads around if the XXX_Deinit function does not clean up things.
    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    Monday, November 14, 2011 7:55 AM

All replies

  • I'm not sure I understand your question anyway these are some thougts: when you call DeactivateDevice the device manager performs several actions to remove the device from its bookkeeping structures and, at the end, it calls the driver XXX_Deinit (possibly also XXX_PreDeinit). These operations are synchronous so when DeactivateDevice returns this means that the driver XXX_Deinit has also returned so 'the driver has been unloaded'. The latest can or cannot be actually true depending on the driver itself: for example you may still have threads around if the XXX_Deinit function does not clean up things.
    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    Monday, November 14, 2011 7:55 AM
  • Ok now I'm confused, something is lingering on from one of our drivers after we call DeactivateDevice. Its our micron nand chip's on die EDC feature. Basically we deactive the DSK driver and when we try to read/write we'll have two modes of ECC on and fail.

     

    What we are seeing is that the Deinit isn't finished before our program starts to use the nand device. 

    Monday, November 14, 2011 2:59 PM
  • The first solution is not really recommended, but if your system is closed and you can guarantee that a customer will never be able to create their own functions to write to the DSK device, you can try the following:

    You could use a mutex (or critical section) so that before your thread calls DeactivateDevice(), it grabs hold of the mutex (or enters the critical section) and releases it when DeactivateDevice returns something. This mutex (critical section) object can be used to block the threads that write data to your DSK device.

    You could also try playing with thread priorities to prioritize the process of unloading the driver (device manager) over the thread which writes to the DSK device, this is a lot safer, but may have adverse affects in other parts of your project.

    Monday, November 14, 2011 10:44 PM
  • It is a closed system, all it does is scan things and this is how we update the OS/APP since they are part of the nk.nb0 that gets written to a raw data partition. So we have to kind of shut the driver off to stop nand usage and write the new OS and then shut down / restart. I'll try the named mutex seems easy enough to implement.
    Tuesday, November 15, 2011 2:21 AM