thermal: Use freezable workqueue
PATCH 1/1 thermal: Use freezable workqueue
From: Rafael J. Wysocki <[email protected]>
If thermal polling is enabled, which for example is the case for ACPI thermal zones with the _TZP object defined, the thermal driver uses delayed work items for this purpose. Unfortunately, since they are queued up using schedule_delayed_work(), the work function may be executed during system suspend or resume, which is not desirable.
To prevent that from happening, use a freezable workqueue for queuing up delayed work items in the thermal driver.
--- drivers/thermal/thermal_sys.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/thermal/thermal_sys.c +20 -2
@@ -62,6 +62,20 @@ static DEFINE_MUTEX(thermal_list_lock);static unsigned int thermal_event_seqnum; +static struct workqueue_struct *thermal_wq; + +static int __init thermal_start_workqueue (void ) +{ + thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 ); +return thermal_wq ?0 : -ENOMEM ; +} + +static inline void thermal_destroy_workqueue (void ) +{ +if (thermal_wq) +destroy_workqueue (thermal_wq); +} +static struct genl_family thermal_event_genl_family = { .id =GENL_ID_GENERATE , .name =THERMAL_GENL_FAMILY_NAME ,
@@ -611,10 +625,10 @@ static void thermal_zone_device_set_pollreturn ;if (delay >1000 ) -schedule_delayed_work (&(tz->poll_queue), +queue_delayed_work (thermal_wq, &(tz->poll_queue),round_jiffies (msecs_to_jiffies (delay)));else -schedule_delayed_work (&(tz->poll_queue), +queue_delayed_work (thermal_wq, &(tz->poll_queue),msecs_to_jiffies (delay)); }
@@ -1306,11 +1320,14 @@ static int __init thermal_init(void)int result =0 ; result =class_register (&thermal_class); +if (!result) + result =thermal_start_workqueue ();if (result) {idr_destroy (&thermal_tz_idr);idr_destroy (&thermal_cdev_idr);mutex_destroy (&thermal_idr_lock);mutex_destroy (&thermal_list_lock); +thermal_destroy_workqueue (); } result =genetlink_init ();return result;
@@ -1328,6 +1345,7 @@ static void __exit thermal_exit(void)idr_destroy (&thermal_cdev_idr);mutex_destroy (&thermal_idr_lock);mutex_destroy (&thermal_list_lock); +thermal_destroy_workqueue ();genetlink_exit (); }
Quoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If thermal polling is enabled, which for example is the case for ACPI thermal zones with the
_TZPobject defined, the thermal driver uses delayed work items for this purpose. Unfortunately, since they are queued up usingschedule_delayed_work(), the work function may be executed during system suspend or resume, which is not desirable.To prevent that from happening, use a freezable workqueue for queuing up delayed work items in the thermal driver.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/thermal_sys.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)Index:
linux-2.6/drivers/thermal/thermal_sys.c
===================================================================
drivers/thermal/thermal_sys.c static DEFINE_MUTEX(thermal_list_lock); · line 69
Quoted 8 lines
drivers/thermal/thermal_sys.c +5
-0@@ -62,6 +62,20 @@ static DEFINE_MUTEX(thermal_list_lock);static unsigned int thermal_event_seqnum; +static struct workqueue_struct *thermal_wq; + +static int __init thermal_start_workqueue (void ) +{ + thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 );
Should probably be unbound as well.
FWIW, I would not mind if we had a global freezeable workqueue already predefined. I could switch input_polldev and vmw_balloon to it and there probably could be more users...
Thanks.
Signature · 1 line
Dmitry
Quoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If thermal polling is enabled, which for example is the case for ACPI thermal zones with the
_TZPobject defined, the thermal driver uses delayed work items for this purpose. Unfortunately, since they are queued up usingschedule_delayed_work(), the work function may be executed during system suspend or resume, which is not desirable.To prevent that from happening, use a freezable workqueue for queuing up delayed work items in the thermal driver.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/thermal_sys.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)Index:
linux-2.6/drivers/thermal/thermal_sys.c
===================================================================
drivers/thermal/thermal_sys.c static DEFINE_MUTEX(thermal_list_lock); · line 69
Quoted 8 lines
drivers/thermal/thermal_sys.c +5
-0@@ -62,6 +62,20 @@ static DEFINE_MUTEX(thermal_list_lock);static unsigned int thermal_event_seqnum; +static struct workqueue_struct *thermal_wq; + +static int __init thermal_start_workqueue (void ) +{ + thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 );
Should probably be unbound as well.
FWIW, I would not mind if we had a global freezeable workqueue already predefined. I could switch input_polldev and vmw_balloon to it and there probably could be more users...
Thanks.
Signature · 1 line
Dmitry
Quoted 26 lines · Dmitry Torokhov
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If thermal polling is enabled, which for example is the case for ACPI thermal zones with the
_TZPobject defined, the thermal driver uses delayed work items for this purpose. Unfortunately, since they are queued up usingschedule_delayed_work(), the work function may be executed during system suspend or resume, which is not desirable.To prevent that from happening, use a freezable workqueue for queuing up delayed work items in the thermal driver.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/thermal_sys.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)Index:
linux-2.6/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +0
-0@@ -62,6 +62,20 @@ static DEFINE_MUTEX(thermal_list_lock);static unsigned int thermal_event_seqnum;
Quoted 7 lines
drivers/thermal/thermal_sys.c static DEFINE_MUTEX(thermal_list_lock); · line 69
Quoted 5 lines
drivers/thermal/thermal_sys.c +5
-0+static struct workqueue_struct *thermal_wq; + +static int __init thermal_start_workqueue (void ) +{ + thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 );Should probably be unbound as well.
Yup, thanks.
Quoted 3 lines
FWIW, I would not mind if we had a global freezeable workqueue already predefined. I could switch
input_polldevandvmw_balloonto it and there probably could be more users...
Hmm, OK.
Do you think we should add system_freezeable_wq to the set of predefined workqueues?
Rafael
Quoted 26 lines · Dmitry Torokhov
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If thermal polling is enabled, which for example is the case for ACPI thermal zones with the
_TZPobject defined, the thermal driver uses delayed work items for this purpose. Unfortunately, since they are queued up usingschedule_delayed_work(), the work function may be executed during system suspend or resume, which is not desirable.To prevent that from happening, use a freezable workqueue for queuing up delayed work items in the thermal driver.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/thermal_sys.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)Index:
linux-2.6/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +0
-0@@ -62,6 +62,20 @@ static DEFINE_MUTEX(thermal_list_lock);static unsigned int thermal_event_seqnum;
Quoted 7 lines
drivers/thermal/thermal_sys.c static DEFINE_MUTEX(thermal_list_lock); · line 69
Quoted 5 lines
drivers/thermal/thermal_sys.c +5
-0+static struct workqueue_struct *thermal_wq; + +static int __init thermal_start_workqueue (void ) +{ + thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 );Should probably be unbound as well.
Yup, thanks.
Quoted 3 lines
FWIW, I would not mind if we had a global freezeable workqueue already predefined. I could switch
input_polldevandvmw_balloonto it and there probably could be more users...
Hmm, OK.
Do you think we should add system_freezeable_wq to the set of predefined workqueues?
Rafael
Tejun Heo
maintainerHello, Dmitry, Rafael.
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines
drivers/thermal/thermal_sys.c static DEFINE_MUTEX(thermal_list_lock); · line 69
Quoted 1 line
drivers/thermal/thermal_sys.c +1
-0+ thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 );Should probably be unbound as well.
Yup, thanks.
Hmm.. why should it be unbound? Unbound wqs are primarily useful for very long running (system daemon type) works which may also consume considerable amount of cpu cycles.
Quoted 8 lines
Quoted 3 lines
FWIW, I would not mind if we had a global freezeable workqueue already predefined. I could switch
input_polldevandvmw_balloonto it and there probably could be more users...Hmm, OK.
Do you think we should add
system_freezeable_wqto the set of predefined workqueues?
Oh, yeah, definitely. I'll write up a patch.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerHello, Dmitry, Rafael.
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines
drivers/thermal/thermal_sys.c static DEFINE_MUTEX(thermal_list_lock); · line 69
Quoted 1 line
drivers/thermal/thermal_sys.c +1
-0+ thermal_wq =alloc_workqueue ("thermal" ,WQ_FREEZEABLE ,0 );Should probably be unbound as well.
Yup, thanks.
Hmm.. why should it be unbound? Unbound wqs are primarily useful for very long running (system daemon type) works which may also consume considerable amount of cpu cycles.
Quoted 8 lines
Quoted 3 lines
FWIW, I would not mind if we had a global freezeable workqueue already predefined. I could switch
input_polldevandvmw_balloonto it and there probably could be more users...Hmm, OK.
Do you think we should add
system_freezeable_wqto the set of predefined workqueues?
Oh, yeah, definitely. I'll write up a patch.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerPATCH 1/1 workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 1 line
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100
Add system wide freezeable workqueue.
---
Please feel free to pull from the following branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-2.6.39
Thanks.
include/linux/workqueue.h | 4 ++++ kernel/workqueue.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletions(-)
include/linux/workqueue.h +4 -0
@@ -286,11 +286,15 @@ enum {* any specific CPU, not concurrency managed, and all queued works are * executed immediately as long as max_active limit is not reached and * resources are available. +* +* system_freezeable_wq is equivalent to system_wq except that it's +* freezeable. */ extern struct workqueue_struct *system_wq;extern struct workqueue_struct *system_long_wq;extern struct workqueue_struct *system_nrt_wq;extern struct workqueue_struct *system_unbound_wq; +extern struct workqueue_struct *system_freezeable_wq;extern struct workqueue_struct * __alloc_workqueue_key(const char *name, unsigned int flags, int max_active,
kernel/workqueue.c +3 -1
@@ -3764,8 +3764,10 @@ static int __init init_workqueues(void) system_nrt_wq =alloc_workqueue ("events_nrt" ,WQ_NON_REENTRANT ,0 ); system_unbound_wq =alloc_workqueue ("events_unbound" ,WQ_UNBOUND ,WQ_UNBOUND_MAX_ACTIVE ); + system_freezeable_wq =alloc_workqueue ("events_freezeable" , +WQ_FREEZEABLE ,0 );BUG_ON (!system_wq || !system_long_wq || !system_nrt_wq || - !system_unbound_wq); + !system_unbound_wq || !system_freezeable_wq);return 0 ; }early_initcall (init_workqueues);
Signature · 1 line
1.7.1
Tejun Heo
maintainerPATCH 1/1 workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 1 line
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100
Add system wide freezeable workqueue.
---
Please feel free to pull from the following branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-2.6.39
Thanks.
include/linux/workqueue.h | 4 ++++ kernel/workqueue.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletions(-)
include/linux/workqueue.h +4 -0
@@ -286,11 +286,15 @@ enum {* any specific CPU, not concurrency managed, and all queued works are * executed immediately as long as max_active limit is not reached and * resources are available. +* +* system_freezeable_wq is equivalent to system_wq except that it's +* freezeable. */ extern struct workqueue_struct *system_wq;extern struct workqueue_struct *system_long_wq;extern struct workqueue_struct *system_nrt_wq;extern struct workqueue_struct *system_unbound_wq; +extern struct workqueue_struct *system_freezeable_wq;extern struct workqueue_struct * __alloc_workqueue_key(const char *name, unsigned int flags, int max_active,
kernel/workqueue.c +3 -1
@@ -3764,8 +3764,10 @@ static int __init init_workqueues(void) system_nrt_wq =alloc_workqueue ("events_nrt" ,WQ_NON_REENTRANT ,0 ); system_unbound_wq =alloc_workqueue ("events_unbound" ,WQ_UNBOUND ,WQ_UNBOUND_MAX_ACTIVE ); + system_freezeable_wq =alloc_workqueue ("events_freezeable" , +WQ_FREEZEABLE ,0 );BUG_ON (!system_wq || !system_long_wq || !system_nrt_wq || - !system_unbound_wq); + !system_unbound_wq || !system_freezeable_wq);return 0 ; }early_initcall (init_workqueues);
Signature · 1 line
1.7.1
Re: [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 5 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100Add system wide freezeable workqueue.
The preferred spelling is "freezable".
Alan Stern
Re: [linux-pm] [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 5 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100Add system wide freezeable workqueue.
The preferred spelling is "freezable".
Alan Stern
Tejun Heo
maintainerRe: [linux-pm] [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
Quoted 9 lines · Alan Stern
Quoted 5 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100Add system wide freezeable workqueue.
The preferred spelling is "freezable".
Hmmm... workqueue always has used freezeable (even before cmwq changes). It seems like mass renaming is in order. :-(
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerRe: [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Alan SternQuoted 9 lines · Alan Stern
Quoted 5 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100Add system wide freezeable workqueue.
The preferred spelling is "freezable".
Hmmm... workqueue always has used freezeable (even before cmwq changes). It seems like mass renaming is in order. :-(
Thanks.
Signature · 1 line
tejun
Re: [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 7 lines · Tejun Heo
Quoted 6 lines · Alan Stern
Quoted 4 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Add system wide freezeable workqueue.
The preferred spelling is "freezable".
Hmmm... workqueue always has used freezeable (even before cmwq changes). It seems like mass renaming is in order. :-(
The name of create_freezeable_workqueue was misspelled originally and then never changed. But other code and most of the comments and documentation are spelled correctly -- grep for both spellings and you'll see.
Agreed, some renaming and editing is in order.
Alan Stern
Re: [linux-pm] [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 7 lines · Tejun Heo
Quoted 6 lines · Alan Stern
Quoted 4 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Add system wide freezeable workqueue.
The preferred spelling is "freezable".
Hmmm... workqueue always has used freezeable (even before cmwq changes). It seems like mass renaming is in order. :-(
The name of create_freezeable_workqueue was misspelled originally and then never changed. But other code and most of the comments and documentation are spelled correctly -- grep for both spellings and you'll see.
Agreed, some renaming and editing is in order.
Alan Stern
Re: [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 8 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100Add system wide freezeable workqueue.
Signed-off-by Tejun Heo <[email protected]>Cc Dmitry Torokhov <[email protected]>
And if, as Alan said, it could be "freezable" that would be great.
Signature · 1 line
Dmitry
Re: [PATCH wq#for-2.6.39] workqueue: add system_freezeable_wq
In reply to Tejun HeoQuoted 8 lines · Tejun Heo
From
de62c151df9b6568c67977920267392c432f340aMon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Tue, 8 Feb 2011 10:39:03 +0100Add system wide freezeable workqueue.
Signed-off-by Tejun Heo <[email protected]>Cc Dmitry Torokhov <[email protected]>
And if, as Alan said, it could be "freezable" that would be great.
Signature · 1 line
Dmitry