Skip to content

Commit e42837b

Browse files
rjwysockiLinus Torvalds
authored andcommitted
freezer: introduce freezer-friendly waiting macros
Introduce freezer-friendly wrappers around wait_event_interruptible() and wait_event_interruptible_timeout(), originally defined in <linux/wait.h>, to be used in freezable kernel threads. Make some of the freezable kernel threads use them. This is necessary for the freezer to stop sending signals to kernel threads, which is implemented in the next patch. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Pavel Machek <pavel@ucw.cz> Cc: Nigel Cunningham <nigel@nigel.suspend2.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2e13189 commit e42837b

7 files changed

Lines changed: 45 additions & 13 deletions

File tree

‎drivers/input/gameport/gameport.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,8 @@ static int gameport_thread(void *nothing)
448448
set_freezable();
449449
do {
450450
gameport_handle_event();
451-
wait_event_interruptible(gameport_wait,
451+
wait_event_freezable(gameport_wait,
452452
kthread_should_stop() || !list_empty(&gameport_event_list));
453-
try_to_freeze();
454453
} while (!kthread_should_stop());
455454

456455
printk(KERN_DEBUG "gameport: kgameportd exiting\n");

‎drivers/input/serio/serio.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,8 @@ static int serio_thread(void *nothing)
387387
set_freezable();
388388
do {
389389
serio_handle_event();
390-
wait_event_interruptible(serio_wait,
390+
wait_event_freezable(serio_wait,
391391
kthread_should_stop() || !list_empty(&serio_event_list));
392-
try_to_freeze();
393392
} while (!kthread_should_stop());
394393

395394
printk(KERN_DEBUG "serio: kseriod exiting\n");

‎drivers/input/touchscreen/ucb1400_ts.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,9 @@ static int ucb1400_ts_thread(void *_ucb)
333333
timeout = msecs_to_jiffies(10);
334334
}
335335

336-
wait_event_interruptible_timeout(ucb->ts_wait,
336+
wait_event_freezable_timeout(ucb->ts_wait,
337337
ucb->irq_pending || ucb->ts_restart || kthread_should_stop(),
338338
timeout);
339-
try_to_freeze();
340339
}
341340

342341
/* Send the "pen off" if we are stopping with the pen still active */

‎drivers/media/dvb/dvb-core/dvb_frontend.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ static int dvb_frontend_thread(void *data)
527527
up(&fepriv->sem); /* is locked when we enter the thread... */
528528
restart:
529529
timeout = wait_event_interruptible_timeout(fepriv->wait_queue,
530-
dvb_frontend_should_wakeup(fe) || kthread_should_stop(),
530+
dvb_frontend_should_wakeup(fe) || kthread_should_stop()
531+
|| freezing(current),
531532
fepriv->delay);
532533

533534
if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {

‎drivers/usb/core/hub.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,10 +2870,9 @@ static int hub_thread(void *__unused)
28702870
set_freezable();
28712871
do {
28722872
hub_events();
2873-
wait_event_interruptible(khubd_wait,
2873+
wait_event_freezable(khubd_wait,
28742874
!list_empty(&hub_event_list) ||
28752875
kthread_should_stop());
2876-
try_to_freeze();
28772876
} while (!kthread_should_stop() || !list_empty(&hub_event_list));
28782877

28792878
pr_debug("%s: khubd exiting\n", usbcore_name);

‎drivers/usb/storage/usb.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,9 @@ static int usb_stor_scan_thread(void * __us)
907907
if (delay_use > 0) {
908908
printk(KERN_DEBUG "usb-storage: waiting for device "
909909
"to settle before scanning\n");
910-
retry:
911-
wait_event_interruptible_timeout(us->delay_wait,
910+
wait_event_freezable_timeout(us->delay_wait,
912911
test_bit(US_FLIDX_DISCONNECTING, &us->flags),
913912
delay_use * HZ);
914-
if (try_to_freeze())
915-
goto retry;
916913
}
917914

918915
/* If the device is still connected, perform the scanning */

‎include/linux/freezer.h‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define FREEZER_H_INCLUDED
55

66
#include <linux/sched.h>
7+
#include <linux/wait.h>
78

89
#ifdef CONFIG_PM_SLEEP
910
/*
@@ -126,6 +127,36 @@ static inline void set_freezable(void)
126127
current->flags &= ~PF_NOFREEZE;
127128
}
128129

130+
/*
131+
* Freezer-friendly wrappers around wait_event_interruptible() and
132+
* wait_event_interruptible_timeout(), originally defined in <linux/wait.h>
133+
*/
134+
135+
#define wait_event_freezable(wq, condition) \
136+
({ \
137+
int __retval; \
138+
do { \
139+
__retval = wait_event_interruptible(wq, \
140+
(condition) || freezing(current)); \
141+
if (__retval && !freezing(current)) \
142+
break; \
143+
else if (!(condition)) \
144+
__retval = -ERESTARTSYS; \
145+
} while (try_to_freeze()); \
146+
__retval; \
147+
})
148+
149+
150+
#define wait_event_freezable_timeout(wq, condition, timeout) \
151+
({ \
152+
long __retval = timeout; \
153+
do { \
154+
__retval = wait_event_interruptible_timeout(wq, \
155+
(condition) || freezing(current), \
156+
__retval); \
157+
} while (try_to_freeze()); \
158+
__retval; \
159+
})
129160
#else /* !CONFIG_PM_SLEEP */
130161
static inline int frozen(struct task_struct *p) { return 0; }
131162
static inline int freezing(struct task_struct *p) { return 0; }
@@ -143,6 +174,13 @@ static inline void freezer_do_not_count(void) {}
143174
static inline void freezer_count(void) {}
144175
static inline int freezer_should_skip(struct task_struct *p) { return 0; }
145176
static inline void set_freezable(void) {}
177+
178+
#define wait_event_freezable(wq, condition) \
179+
wait_event_interruptible(wq, condition)
180+
181+
#define wait_event_freezable_timeout(wq, condition, timeout) \
182+
wait_event_interruptible_timeout(wq, condition, timeout)
183+
146184
#endif /* !CONFIG_PM_SLEEP */
147185

148186
#endif /* FREEZER_H_INCLUDED */

0 commit comments

Comments
 (0)