Race condition when entering Deep sleep mode

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Race condition when entering Deep sleep mode

572 Views
gennadiykiryukh
Contributor III

What is the process for handling race conditions when an interrupt is generated right before the system goes to deep sleep mode under Linux?

For example, I have a GPIO rising edge interrupt enabled that my program waits on using epoll_wait() system call. My program determines that no pending action exists and goes to deep sleep by writing "mem" to /sys/power/state. While in deep sleep, a rising edge occurs on a pin that triggers an interrupt. This wakes up the system and my program resumes. At that point, epoll_wait() returns with an event indicating that an interrupt occurred. I set a flag in the program indicating that there is a pending action that prevents the system from going to sleep until the action is complete.

However, if an interrupt occurs at the beginning of writing "mem" to /sys/power/state, there appear to be no mechanism in place to prevent the system from going to sleep. An interrupt might be handled by the kernel driver right before "mem" is written, but after handling the interrupt the system will still go to sleep without giving user space program a chance to react to the interrupt.

How should this condition be handled?

Labels (2)
0 Kudos
1 Reply

505 Views
igorpadykov
NXP Employee
NXP Employee

Hi Gennadiy

may be useful to look at ERR007265 CCM: When improper low-power sequence is used

in i.MX6DQ Errata document

https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf

and implementation of nxp low power drivers described in Linux Manual in

Linux L4.14.78_1.0.0 Documentation

low power drivers

mach-imx\arm\arch - linux-imx - i.MX Linux kernel 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos