how does sleep work in windows kernel

so when i press Start → Shut down or sign out → Sleep , then the windows should go to sleep. But what is behind all this? Will the System BIOS be involved?
suppose this new device supports S3 power transition from D0, then its driver must have function that will be called after Sleep is pressed.
but what if Sleep is pressed, but the driver’s sleep function never get called. What would be the reason?

If the device is already in D3, the system doesn’t have to let the driver know when the system goes to sleep. The system is now rather aggressive about power management, and will try to put your device in D3 as soon as can. That way, system sleep can happen almost instantly.

Hi @Tim_Roberts , how do i know if my device is already in D3? (I suppose this D3 is the same as S3 )
actually this device is video card , so i have set a breakpoint at DxgkDdiSetPowerState this DDI function. but it never get called even after i press Sleep.

Devices have D-states. The system has an S-state. The two are rather lightly connected. When the system wants to go to S3, it will ask the devices to fall out of D0. It’s up to the device how they handle that. If a device is already not in D0, then the system doesn’t necessarily need to ask it to change. You can find out what D-state you’re in in Device Manager; it’s one of the property pages.

There are some good power management tools that allow you to force the system into certain states, like powercfg. I suppose you could use some of those to chase this down.

thank you @Tim_Roberts
Could you give litter more about this powercfg for how to use it?
i want to check if power manager sends the power command to my driver, do you think i can check this using powercfg?

have you tried a simple internet search?

https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options