Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

freezer: convert freezable helpers to freezer_do_not_count()

Freezing tasks will wake up almost every userspace task from
where it is blocking and force it to run until it hits a
call to try_to_sleep(), generally on the exit path from the syscall
it is blocking in. On resume each task will run again, usually
restarting the syscall and running until it hits the same
blocking call as it was originally blocked in.

Convert the existing wait_event_freezable* wrappers to use
freezer_do_not_count(). Combined with a previous patch,
these tasks will not run during suspend or resume unless they wake
up for another reason, in which case they will run until they hit
the try_to_freeze() in freezer_count(), and then continue processing
the wakeup after tasks are thawed.

This results in a small change in behavior, previously a race
between freezing and a normal wakeup would be won by the wakeup,
now the task will freeze and then handle the wakeup after thawing.

Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Colin Cross <ccross@android.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Colin Cross and committed by
Rafael J. Wysocki
b0123586 613f5d13

+7 -15
+7 -15
include/linux/freezer.h
··· 228 228 #define wait_event_freezable(wq, condition) \ 229 229 ({ \ 230 230 int __retval; \ 231 - for (;;) { \ 232 - __retval = wait_event_interruptible(wq, \ 233 - (condition) || freezing(current)); \ 234 - if (__retval || (condition)) \ 235 - break; \ 236 - try_to_freeze(); \ 237 - } \ 231 + freezer_do_not_count(); \ 232 + __retval = wait_event_interruptible(wq, (condition)); \ 233 + freezer_count(); \ 238 234 __retval; \ 239 235 }) 240 236 241 237 #define wait_event_freezable_timeout(wq, condition, timeout) \ 242 238 ({ \ 243 239 long __retval = timeout; \ 244 - for (;;) { \ 245 - __retval = wait_event_interruptible_timeout(wq, \ 246 - (condition) || freezing(current), \ 247 - __retval); \ 248 - if (__retval <= 0 || (condition)) \ 249 - break; \ 250 - try_to_freeze(); \ 251 - } \ 240 + freezer_do_not_count(); \ 241 + __retval = wait_event_interruptible_timeout(wq, (condition), \ 242 + __retval); \ 243 + freezer_count(); \ 252 244 __retval; \ 253 245 }) 254 246