Re: [linux-pm] wait_for_completion_interruptible does not wait !!

From: Suresh Rajashekara
Date: Sun Jun 27 2010 - 00:08:43 EST


On Sun, Jun 20, 2010 at 8:52 AM, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> What happens if the variable is completed while nobody is waiting for
> it?  The next time somebody tries to wait, won't the wait terminate
> immediately?
>

Haven't tested it but will reply with the answer once I get a chance to test it.


>> I tried wait_for_completion instead, but now the kernel refuses to suspend.
>>
>> I have tried wait queues and mutexs with no success.
>>
>> Could anyone please point me how I can resolve this issue? Is there
>> any construct which can block inside the kernel during suspend/resume?
>
> Yes: The freezer.
>
>> Can there be a blocking call active while we suspend?
>
> Yes, in theory.  In practice it's not a good idea, since the call
> wouldn't be able to distinguish between an actual signal and the onset
> of a suspend.  You might end up with a call that ignores all signals
> and hence cannot be interrupted.
>

Just for the information of others on the list, here is what we did to
solve this issue, we designed a freezer-friendly wrapper around
wait_for_completion_interruptible()

<SNIP>
#define wait_for_completion_freezable(ptr_completion) \
({ \
int __retval; \
do { \
__retval = wait_for_completion_interruptible( \
ptr_completion); \
if (__retval && !freezing(current)) \
break; \
} while (try_to_freeze()); \
__retval; \
})

</SNIP>

Thanks
Suresh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/