is EvtDeviceD0Exit always called for reboot?

Before I go on a bug hunt, is EvtDeviceD0Exit always called in the case of a system reboot?

Even when the device is responsible for the system drive?

Thanks

James

> Before I go on a bug hunt, is EvtDeviceD0Exit always called in the case

of a system reboot?

Even when the device is responsible for the system drive?

This driver would not exist during the initial boot process, so having it
exit D0 state could make sense. The power state of the drive would be set
in the “ROM” (EPROM, Flash,…) boot loader. There is some point in the
boot cycle where the driver again comes into play, but by that point the
boot process could make use of it. You’d have to read the Windows NT
Internals books or have one of the true experts explain the point at which
the boot support relinquishes control to the OS drivers.

Next question: why do you think this is a bug? It could simply be
undocumented behavior, and you should handle it in an appropriate fashion
no matter why it is called. Next, while it may always be called at reboot
time, it might also be called whenever the power manager wants to turn off
power hogs, such a spinning disks. Consequently, it could not be relied
upon as an indication that a reboot is about to occur.

And thus the inevitable question: what problem are you trying to solve?
joe

Thanks

James


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>

> Before I go on a bug hunt, is EvtDeviceD0Exit always called in the case
> of a system reboot?
>
> Even when the device is responsible for the system drive?
>

This driver would not exist during the initial boot process, so having it
exit D0 state could make sense. The power state of the drive would be set
in the “ROM” (EPROM, Flash,…) boot loader. There is some point in the
boot cycle where the driver again comes into play, but by that point the
boot process could make use of it. You’d have to read the Windows NT
Internals books or have one of the true experts explain the point at which
the boot support relinquishes control to the OS drivers.

Next question: why do you think this is a bug? It could simply be
undocumented behavior, and you should handle it in an appropriate fashion
no matter why it is called. Next, while it may always be called at reboot
time, it might also be called whenever the power manager wants to turn off
power hogs, such a spinning disks. Consequently, it could not be relied
upon as an indication that a reboot is about to occur.

And thus the inevitable question: what problem are you trying to solve?

Someone asked why my EvtDeviceD0Exit routine wasn’t called on system reboot / shutdown on their system. The documentation is unclear on this point so I thought I’d ask here.

Either it is always called on shutdown, and there is a bug in my driver that is blocking this somehow, and I will go hunting for it, or it is never called for the driver responsible for the system/paging device, in which case there is no bug and I’ve got no work to do aside from explaining to the asker why my driver behaves this way. Or maybe it is usually called but there are some shutdown scenarios in which it isn’t. (Pointing them to the documentation that describes this behaviour would be ideal, but apparently not possible here)

Just for completeness, I’ll rephrase the question again in case you are still baffled by it. The documentation says “If the driver has registered an EvtDeviceD0Exit callback function, the framework calls the function each time one of the driver’s devices leaves its working (D0) state”. If I was writing a unit test for my driver I would want to observe this happening in my driver when the system leaves D0 and shuts down, and a fail should be flagged if D0Exit is not called. Unless of course the documented behaviour isn’t inclusive of all possible scenarios, hence the question “is D0Exit called for the device managing the system drive on reboot (or shutdown)?”.

James

I don’t think EvtDeviceD0Exit is ever called on system reboot. I would
expect that you need to register for shutdown notification (with
IoRegisterShutdownNotification).
WdfControlDeviceInitSetShutdownNotification seems to be its equivalent
in KMDF.

Kris

On Thu, Jan 23, 2014 at 10:35 AM, James Harper
wrote:
>>
>> > Before I go on a bug hunt, is EvtDeviceD0Exit always called in the case
>> > of a system reboot?
>> >
>> > Even when the device is responsible for the system drive?
>> >
>>
>> This driver would not exist during the initial boot process, so having it
>> exit D0 state could make sense. The power state of the drive would be set
>> in the “ROM” (EPROM, Flash,…) boot loader. There is some point in the
>> boot cycle where the driver again comes into play, but by that point the
>> boot process could make use of it. You’d have to read the Windows NT
>> Internals books or have one of the true experts explain the point at which
>> the boot support relinquishes control to the OS drivers.
>>
>> Next question: why do you think this is a bug? It could simply be
>> undocumented behavior, and you should handle it in an appropriate fashion
>> no matter why it is called. Next, while it may always be called at reboot
>> time, it might also be called whenever the power manager wants to turn off
>> power hogs, such a spinning disks. Consequently, it could not be relied
>> upon as an indication that a reboot is about to occur.
>>
>> And thus the inevitable question: what problem are you trying to solve?
>
> Someone asked why my EvtDeviceD0Exit routine wasn’t called on system reboot / shutdown on their system. The documentation is unclear on this point so I thought I’d ask here.
>
> Either it is always called on shutdown, and there is a bug in my driver that is blocking this somehow, and I will go hunting for it, or it is never called for the driver responsible for the system/paging device, in which case there is no bug and I’ve got no work to do aside from explaining to the asker why my driver behaves this way. Or maybe it is usually called but there are some shutdown scenarios in which it isn’t. (Pointing them to the documentation that describes this behaviour would be ideal, but apparently not possible here)
>
> Just for completeness, I’ll rephrase the question again in case you are still baffled by it. The documentation says “If the driver has registered an EvtDeviceD0Exit callback function, the framework calls the function each time one of the driver’s devices leaves its working (D0) state”. If I was writing a unit test for my driver I would want to observe this happening in my driver when the system leaves D0 and shuts down, and a fail should be flagged if D0Exit is not called. Unless of course the documented behaviour isn’t inclusive of all possible scenarios, hence the question “is D0Exit called for the device managing the system drive on reboot (or shutdown)?”.
>
> James
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Kris

Sort of an odd question,still, given that storage miniports aren’t
framework drivers. They do see a shutdown event that might be analogous to
EvtDoExit.

Mark Roddy

On Thu, Jan 23, 2014 at 5:35 AM, James Harper > wrote:

> >
> > > Before I go on a bug hunt, is EvtDeviceD0Exit always called in the
> case
> > > of a system reboot?
> > >
> > > Even when the device is responsible for the system drive?
> > >
> >
> > This driver would not exist during the initial boot process, so having it
> > exit D0 state could make sense. The power state of the drive would be
> set
> > in the “ROM” (EPROM, Flash,…) boot loader. There is some point in the
> > boot cycle where the driver again comes into play, but by that point the
> > boot process could make use of it. You’d have to read the Windows NT
> > Internals books or have one of the true experts explain the point at
> which
> > the boot support relinquishes control to the OS drivers.
> >
> > Next question: why do you think this is a bug? It could simply be
> > undocumented behavior, and you should handle it in an appropriate fashion
> > no matter why it is called. Next, while it may always be called at
> reboot
> > time, it might also be called whenever the power manager wants to turn
> off
> > power hogs, such a spinning disks. Consequently, it could not be relied
> > upon as an indication that a reboot is about to occur.
> >
> > And thus the inevitable question: what problem are you trying to solve?
>
> Someone asked why my EvtDeviceD0Exit routine wasn’t called on system
> reboot / shutdown on their system. The documentation is unclear on this
> point so I thought I’d ask here.
>
> Either it is always called on shutdown, and there is a bug in my driver
> that is blocking this somehow, and I will go hunting for it, or it is never
> called for the driver responsible for the system/paging device, in which
> case there is no bug and I’ve got no work to do aside from explaining to
> the asker why my driver behaves this way. Or maybe it is usually called but
> there are some shutdown scenarios in which it isn’t. (Pointing them to the
> documentation that describes this behaviour would be ideal, but apparently
> not possible here)
>
> Just for completeness, I’ll rephrase the question again in case you are
> still baffled by it. The documentation says “If the driver has registered
> an EvtDeviceD0Exit callback function, the framework calls the function each
> time one of the driver’s devices leaves its working (D0) state”. If I was
> writing a unit test for my driver I would want to observe this happening in
> my driver when the system leaves D0 and shuts down, and a fail should be
> flagged if D0Exit is not called. Unless of course the documented behaviour
> isn’t inclusive of all possible scenarios, hence the question “is D0Exit
> called for the device managing the system drive on reboot (or shutdown)?”.
>
> James
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

EvtDeviceD0Exit is called on reboot. All devices see an Sx irp and then map that to a Dx state. Drivers in the hiber path do not power down iirc

d

Bent from my phone


From: Krzysztof Uchronskimailto:xxxxx
Sent: ?1/?23/?2014 4:52 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] is EvtDeviceD0Exit always called for reboot?

I don’t think EvtDeviceD0Exit is ever called on system reboot. I would
expect that you need to register for shutdown notification (with
IoRegisterShutdownNotification).
WdfControlDeviceInitSetShutdownNotification seems to be its equivalent
in KMDF.

Kris

On Thu, Jan 23, 2014 at 10:35 AM, James Harper
wrote:
>>
>> > Before I go on a bug hunt, is EvtDeviceD0Exit always called in the case
>> > of a system reboot?
>> >
>> > Even when the device is responsible for the system drive?
>> >
>>
>> This driver would not exist during the initial boot process, so having it
>> exit D0 state could make sense. The power state of the drive would be set
>> in the “ROM” (EPROM, Flash,…) boot loader. There is some point in the
>> boot cycle where the driver again comes into play, but by that point the
>> boot process could make use of it. You’d have to read the Windows NT
>> Internals books or have one of the true experts explain the point at which
>> the boot support relinquishes control to the OS drivers.
>>
>> Next question: why do you think this is a bug? It could simply be
>> undocumented behavior, and you should handle it in an appropriate fashion
>> no matter why it is called. Next, while it may always be called at reboot
>> time, it might also be called whenever the power manager wants to turn off
>> power hogs, such a spinning disks. Consequently, it could not be relied
>> upon as an indication that a reboot is about to occur.
>>
>> And thus the inevitable question: what problem are you trying to solve?
>
> Someone asked why my EvtDeviceD0Exit routine wasn’t called on system reboot / shutdown on their system. The documentation is unclear on this point so I thought I’d ask here.
>
> Either it is always called on shutdown, and there is a bug in my driver that is blocking this somehow, and I will go hunting for it, or it is never called for the driver responsible for the system/paging device, in which case there is no bug and I’ve got no work to do aside from explaining to the asker why my driver behaves this way. Or maybe it is usually called but there are some shutdown scenarios in which it isn’t. (Pointing them to the documentation that describes this behaviour would be ideal, but apparently not possible here)
>
> Just for completeness, I’ll rephrase the question again in case you are still baffled by it. The documentation says “If the driver has registered an EvtDeviceD0Exit callback function, the framework calls the function each time one of the driver’s devices leaves its working (D0) state”. If I was writing a unit test for my driver I would want to observe this happening in my driver when the system leaves D0 and shuts down, and a fail should be flagged if D0Exit is not called. Unless of course the documented behaviour isn’t inclusive of all possible scenarios, hence the question “is D0Exit called for the device managing the system drive on reboot (or shutdown)?”.
>
> James
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Kris


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Let me elaborate on Doron?s response. EvtDeviceD0Exit is called whenever the device should be powered off, either because the device stack received a Dx (where x != 0) IRP (that it may have sent itself) or because the driver is being unloaded, or because the machine is rebooting.

In the case that the driver is unloading or the machine is rebooting, you?ll see WdfPowerDeviceD3Final as the target state, as a hint for drivers which want to treat these cases differently. (Most drivers shouldn?t discriminate between these values.) Unfortunately, Doron and I made a mistake when we wrote this code, or at least I think it?s a mistake in hindsight. WdfPowerDeviceD3Final is also used when the driver is stopping for rebalance. Sorry.

There may be a little confusion here when James asks about ?shutdown and reboot.? With Windows 8, client machines that can hibernate will do so as part of shutting down, after the user is logged off. Hibernation is special here, particularly for the storage stacks and their parents and grandparents. You really don?t want the device turned off. So no Dx IRP is sent. This will mean that in the general client shutdown case, you won?t see EvtDeviceD0Exit in the storage stacks, if I recall correctly.

James, of course, is primarily concerned with Windows running in VMs. It?s not clear to me whether his VMs hibernate, in which case shutdown will go through the general reboot path. It?s also no clear whether he?s looking at server VMs, which will always go down the reboot path as part of shutdown.

Jake Oshins
(former WDF guy)
Windows Kernel Team

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, January 23, 2014 6:47 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] is EvtDeviceD0Exit always called for reboot?

EvtDeviceD0Exit is called on reboot. All devices see an Sx irp and then map that to a Dx state. Drivers in the hiber path do not power down iirc

d

Bent from my phone


From: Krzysztof Uchronskimailto:xxxxx
Sent: ?1/?23/?2014 4:52 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] is EvtDeviceD0Exit always called for reboot?
I don’t think EvtDeviceD0Exit is ever called on system reboot. I would
expect that you need to register for shutdown notification (with
IoRegisterShutdownNotification).
WdfControlDeviceInitSetShutdownNotification seems to be its equivalent
in KMDF.

Kris

On Thu, Jan 23, 2014 at 10:35 AM, James Harper
> wrote:
>>
>> > Before I go on a bug hunt, is EvtDeviceD0Exit always called in the case
>> > of a system reboot?
>> >
>> > Even when the device is responsible for the system drive?
>> >
>>
>> This driver would not exist during the initial boot process, so having it
>> exit D0 state could make sense. The power state of the drive would be set
>> in the “ROM” (EPROM, Flash,…) boot loader. There is some point in the
>> boot cycle where the driver again comes into play, but by that point the
>> boot process could make use of it. You’d have to read the Windows NT
>> Internals books or have one of the true experts explain the point at which
>> the boot support relinquishes control to the OS drivers.
>>
>> Next question: why do you think this is a bug? It could simply be
>> undocumented behavior, and you should handle it in an appropriate fashion
>> no matter why it is called. Next, while it may always be called at reboot
>> time, it might also be called whenever the power manager wants to turn off
>> power hogs, such a spinning disks. Consequently, it could not be relied
>> upon as an indication that a reboot is about to occur.
>>
>> And thus the inevitable question: what problem are you trying to solve?
>
> Someone asked why my EvtDeviceD0Exit routine wasn’t called on system reboot / shutdown on their system. The documentation is unclear on this point so I thought I’d ask here.
>
> Either it is always called on shutdown, and there is a bug in my driver that is blocking this somehow, and I will go hunting for it, or it is never called for the driver responsible for the system/paging device, in which case there is no bug and I’ve got no work to do aside from explaining to the asker why my driver behaves this way. Or maybe it is usually called but there are some shutdown scenarios in which it isn’t. (Pointing them to the documentation that describes this behaviour would be ideal, but apparently not possible here)
>
> Just for completeness, I’ll rephrase the question again in case you are still baffled by it. The documentation says “If the driver has registered an EvtDeviceD0Exit callback function, the framework calls the function each time one of the driver’s devices leaves its working (D0) state”. If I was writing a unit test for my driver I would want to observe this happening in my driver when the system leaves D0 and shuts down, and a fail should be flagged if D0Exit is not called. Unless of course the documented behaviour isn’t inclusive of all possible scenarios, hence the question “is D0Exit called for the device managing the system drive on reboot (or shutdown)?”.
>
> James
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Kris


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

>

Sort of an odd question,still, given that storage miniports aren’t framework
drivers. They do see a shutdown event that might be analogous to EvtDoExit.

The bus driver that enumerates the storport/scsiport device can be a framework driver though.

James

Ah - that explains it.

Mark Roddy

On Thu, Jan 23, 2014 at 3:55 PM, James Harper > wrote:

> >
> > Sort of an odd question,still, given that storage miniports aren’t
> framework
> > drivers. They do see a shutdown event that might be analogous to
> EvtDoExit.
> >
>
> The bus driver that enumerates the storport/scsiport device can be a
> framework driver though.
>
> James
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>