Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-05-14 Thread Tejun Heo
>From cee22a15052faa817e3ec8985a28154d3fabc7aa Mon Sep 17 00:00:00 2001
From: Viresh Kumar 
Date: Mon, 8 Apr 2013 16:45:40 +0530
Subject: workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented 
workqueues

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores (Idle from
scheduler's perspective. Which may or may not be physically idle) just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

tj: Updated config description and comments.  Renamed
CONFIG_WQ_POWER_EFFICIENT to CONFIG_WQ_POWER_EFFICIENT_DEFAULT.

Signed-off-by: Viresh Kumar 
Reviewed-by: Amit Kucheria 
Signed-off-by: Tejun Heo 
---
 Documentation/kernel-parameters.txt | 15 +++
 include/linux/workqueue.h   | 27 +++
 kernel/power/Kconfig| 20 
 kernel/workqueue.c  | 13 +
 4 files changed, 75 insertions(+)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index c3bfacb..37dfd72 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3320,6 +3320,21 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
that this also can be controlled per-workqueue for
workqueues visible under /sys/bus/workqueue/.
 
+   workqueue.power_efficient
+   Per-cpu workqueues are generally preferred because
+   they show better performance thanks to cache
+   locality; unfortunately, per-cpu workqueues tend to
+   be more power hungry than unbound workqueues.
+
+   Enabling this makes the per-cpu workqueues which
+   were observed to contribute significantly to power
+   consumption unbound, leading to measurably lower
+   power usage at the cost of small performance
+   overhead.
+
+   The default value of this parameter is determined by
+   the config option CONFIG_WQ_POWER_EFFICIENT_DEFAULT.
+
x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
default x2apic cluster mode on platforms
supporting x2apic.
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 623488f..fc0136b 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -303,6 +303,33 @@ enum {
WQ_CPU_INTENSIVE= 1 << 5, /* cpu instensive workqueue */
WQ_SYSFS= 1 << 6, /* visible in sysfs, see 
wq_sysfs_register() */
 
+   /*
+* Per-cpu workqueues are generally preferred because they tend to
+* show better performance thanks to cache locality.  Per-cpu
+* workqueues exclude the scheduler from choosing the CPU to
+* execute the worker threads, which has an unfortunate side effect
+* of increasing power consumption.
+*
+* The scheduler considers a CPU idle if it doesn't have any task
+* to execute and tries to keep idle cores idle to conserve power;
+* however, for example, a per-cpu work item scheduled from an
+* interrupt handler on an idle CPU will force the scheduler to
+* excute the work item on that CPU breaking the idleness, which in
+* turn may lead to more scheduling choices which are sub-optimal
+* in terms of power consumption.
+*
+* Workqueues marked with WQ_POWER_EFFICIENT are per-cpu by default
+* but become unbound if workqueue.power_efficient kernel param is
+* specified.  Per-cpu workqueues which are identified to
+* contribute significantly to power-consumption are identified and
+* marked with this flag and enabling the power_efficient mode
+* leads to noticeable power saving at the cost of small
+* performance disadvantage.
+*
+* http://thread.gmane.org/gmane.linux.kernel/1480396
+*/
+   WQ_POWER_EFFICIENT  = 1 << 7,
+
__WQ_DRAINING   = 1 << 16, /* internal: workqueue is draining */
__WQ_ORDERED= 1 << 17, /* internal: workqueue is ordered */
 
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 5dfdc9e..4645596 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-05-14 Thread Tejun Heo
From cee22a15052faa817e3ec8985a28154d3fabc7aa Mon Sep 17 00:00:00 2001
From: Viresh Kumar viresh.ku...@linaro.org
Date: Mon, 8 Apr 2013 16:45:40 +0530
Subject: workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented 
workqueues

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores (Idle from
scheduler's perspective. Which may or may not be physically idle) just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

tj: Updated config description and comments.  Renamed
CONFIG_WQ_POWER_EFFICIENT to CONFIG_WQ_POWER_EFFICIENT_DEFAULT.

Signed-off-by: Viresh Kumar viresh.ku...@linaro.org
Reviewed-by: Amit Kucheria amit.kuche...@linaro.org
Signed-off-by: Tejun Heo t...@kernel.org
---
 Documentation/kernel-parameters.txt | 15 +++
 include/linux/workqueue.h   | 27 +++
 kernel/power/Kconfig| 20 
 kernel/workqueue.c  | 13 +
 4 files changed, 75 insertions(+)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index c3bfacb..37dfd72 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3320,6 +3320,21 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
that this also can be controlled per-workqueue for
workqueues visible under /sys/bus/workqueue/.
 
+   workqueue.power_efficient
+   Per-cpu workqueues are generally preferred because
+   they show better performance thanks to cache
+   locality; unfortunately, per-cpu workqueues tend to
+   be more power hungry than unbound workqueues.
+
+   Enabling this makes the per-cpu workqueues which
+   were observed to contribute significantly to power
+   consumption unbound, leading to measurably lower
+   power usage at the cost of small performance
+   overhead.
+
+   The default value of this parameter is determined by
+   the config option CONFIG_WQ_POWER_EFFICIENT_DEFAULT.
+
x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
default x2apic cluster mode on platforms
supporting x2apic.
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 623488f..fc0136b 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -303,6 +303,33 @@ enum {
WQ_CPU_INTENSIVE= 1  5, /* cpu instensive workqueue */
WQ_SYSFS= 1  6, /* visible in sysfs, see 
wq_sysfs_register() */
 
+   /*
+* Per-cpu workqueues are generally preferred because they tend to
+* show better performance thanks to cache locality.  Per-cpu
+* workqueues exclude the scheduler from choosing the CPU to
+* execute the worker threads, which has an unfortunate side effect
+* of increasing power consumption.
+*
+* The scheduler considers a CPU idle if it doesn't have any task
+* to execute and tries to keep idle cores idle to conserve power;
+* however, for example, a per-cpu work item scheduled from an
+* interrupt handler on an idle CPU will force the scheduler to
+* excute the work item on that CPU breaking the idleness, which in
+* turn may lead to more scheduling choices which are sub-optimal
+* in terms of power consumption.
+*
+* Workqueues marked with WQ_POWER_EFFICIENT are per-cpu by default
+* but become unbound if workqueue.power_efficient kernel param is
+* specified.  Per-cpu workqueues which are identified to
+* contribute significantly to power-consumption are identified and
+* marked with this flag and enabling the power_efficient mode
+* leads to noticeable power saving at the cost of small
+* performance disadvantage.
+*
+* http://thread.gmane.org/gmane.linux.kernel/1480396
+*/
+   WQ_POWER_EFFICIENT  = 1  7,
+
__WQ_DRAINING   = 1  16, /* internal: workqueue is draining */
__WQ_ORDERED= 1  17, /* internal: workqueue is ordered */
 
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-05-13 Thread Viresh Kumar
On 27 April 2013 00:41, Tejun Heo  wrote:
>
> It's already too late for the upcoming merge window, but things
> generally look good to me and I'll apply the patchset once wq/for-3.11
> opens.  One nitpick tho.
>
> On Thu, Apr 25, 2013 at 09:13:44AM +0530, Viresh Kumar wrote:
>> + workqueue.power_efficient
>> + Workqueues can be performance or power-oriented.
>> + Currently, most workqueues are bound to the CPU they
>
>per-cpu would be better
>
>> + were created on. This gives good performance (due to
>> + cache effects) at the cost of potentially waking up
>> + otherwise idle cores just to process some work. To save
>> + power, we can allow the work to be rescheduled on a 
>> core
>> + that is already awake.
>
> The above description is confusing to me.  As have been discussed
> multiple times before, per-cpu workqueue in itself doesn't wake up the
> CPU physically.  The timer may but per-cpu workqueue doesn't.  It was
> confusing when this patchset was first posted and the above phrasing
> is still confusing.  What the patchset tries to do is preventing the
> scheduler from perceiving the CPU as active due to the activated
> worker thread pinned to that CPU, right?  The knob doesn't really do
> anything about waking up the processor in itself.  It just avoids
> feeding the scheduler with noisy activation events and allows it to
> allocate work item execution according to the scheduler's view of CPU
> active/idleness.  As the scheduler has longer / larger scope of
> overall CPU activities and means to regulate them, this leads to more
> power-efficient allocation of work item executions, right?  It'd be
> really great if the descriptions and the comment above the flag makes
> this abundantly clear because it's not something too apparent.

Sorry for the long delay for such a small change. I went on long leaves..

I have added following to make things more clear at places:
(Idle from scheduler's perspective. Which may or may not be physically idle)..

Let me know if it is still unclear..

And this is the new patch: (Attached it too for applying cleanly)

-x---x---

From: Viresh Kumar 
Date: Mon, 8 Apr 2013 16:45:40 +0530
Subject: [PATCH V5 resent 1/5] workqueues: Introduce new flag
WQ_POWER_EFFICIENT for power oriented workqueues

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores (Idle from
scheduler's perspective. Which may or may not be physically idle) just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

Signed-off-by: Viresh Kumar 
Reviewed-by: Amit Kucheria 
---
 Documentation/kernel-parameters.txt | 18 ++
 include/linux/workqueue.h   |  3 +++
 kernel/power/Kconfig| 21 +
 kernel/workqueue.c  | 11 +++
 4 files changed, 53 insertions(+)

diff --git a/Documentation/kernel-parameters.txt
b/Documentation/kernel-parameters.txt
index c3bfacb..9a991b6 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3320,6 +3320,24 @@ bytes respectively. Such letter suffixes can
also be entirely omitted.
that this also can be controlled per-workqueue for
workqueues visible under /sys/bus/workqueue/.

+   workqueue.power_efficient
+   Workqueues can be performance or power-oriented.
+   Currently, most workqueues are bound to the CPU they
+   were created on. This gives good performance (due to
+   cache effects) at the cost of potentially waking up
+   otherwise idle cores (Idle from scheduler's perspective.
+   Which may or may not be physically idle) just to process
+   some work. To save power, we can allow the work to be
+   rescheduled on a core that is already awake.
+
+   Workqueues created with the WQ_UNBOUND flag will allow
+   some power savings.  However, we don't change the
+   default behaviour of the system.  To enable power-saving
+   behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-05-13 Thread Viresh Kumar
On 27 April 2013 00:41, Tejun Heo t...@kernel.org wrote:

 It's already too late for the upcoming merge window, but things
 generally look good to me and I'll apply the patchset once wq/for-3.11
 opens.  One nitpick tho.

 On Thu, Apr 25, 2013 at 09:13:44AM +0530, Viresh Kumar wrote:
 + workqueue.power_efficient
 + Workqueues can be performance or power-oriented.
 + Currently, most workqueues are bound to the CPU they

per-cpu would be better

 + were created on. This gives good performance (due to
 + cache effects) at the cost of potentially waking up
 + otherwise idle cores just to process some work. To save
 + power, we can allow the work to be rescheduled on a 
 core
 + that is already awake.

 The above description is confusing to me.  As have been discussed
 multiple times before, per-cpu workqueue in itself doesn't wake up the
 CPU physically.  The timer may but per-cpu workqueue doesn't.  It was
 confusing when this patchset was first posted and the above phrasing
 is still confusing.  What the patchset tries to do is preventing the
 scheduler from perceiving the CPU as active due to the activated
 worker thread pinned to that CPU, right?  The knob doesn't really do
 anything about waking up the processor in itself.  It just avoids
 feeding the scheduler with noisy activation events and allows it to
 allocate work item execution according to the scheduler's view of CPU
 active/idleness.  As the scheduler has longer / larger scope of
 overall CPU activities and means to regulate them, this leads to more
 power-efficient allocation of work item executions, right?  It'd be
 really great if the descriptions and the comment above the flag makes
 this abundantly clear because it's not something too apparent.

Sorry for the long delay for such a small change. I went on long leaves..

I have added following to make things more clear at places:
(Idle from scheduler's perspective. Which may or may not be physically idle)..

Let me know if it is still unclear..

And this is the new patch: (Attached it too for applying cleanly)

-x---x---

From: Viresh Kumar viresh.ku...@linaro.org
Date: Mon, 8 Apr 2013 16:45:40 +0530
Subject: [PATCH V5 resent 1/5] workqueues: Introduce new flag
WQ_POWER_EFFICIENT for power oriented workqueues

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores (Idle from
scheduler's perspective. Which may or may not be physically idle) just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

Signed-off-by: Viresh Kumar viresh.ku...@linaro.org
Reviewed-by: Amit Kucheria amit.kuche...@linaro.org
---
 Documentation/kernel-parameters.txt | 18 ++
 include/linux/workqueue.h   |  3 +++
 kernel/power/Kconfig| 21 +
 kernel/workqueue.c  | 11 +++
 4 files changed, 53 insertions(+)

diff --git a/Documentation/kernel-parameters.txt
b/Documentation/kernel-parameters.txt
index c3bfacb..9a991b6 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3320,6 +3320,24 @@ bytes respectively. Such letter suffixes can
also be entirely omitted.
that this also can be controlled per-workqueue for
workqueues visible under /sys/bus/workqueue/.

+   workqueue.power_efficient
+   Workqueues can be performance or power-oriented.
+   Currently, most workqueues are bound to the CPU they
+   were created on. This gives good performance (due to
+   cache effects) at the cost of potentially waking up
+   otherwise idle cores (Idle from scheduler's perspective.
+   Which may or may not be physically idle) just to process
+   some work. To save power, we can allow the work to be
+   rescheduled on a core that is already awake.
+
+   Workqueues created with the WQ_UNBOUND flag will allow
+   some power savings.  However, we don't change the
+   default behaviour of the system.  To enable power-saving
+   behaviour, a 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-29 Thread Viresh Kumar
On 29 April 2013 21:49, Tejun Heo  wrote:
> On Mon, Apr 29, 2013 at 12:06:28PM +0530, Viresh Kumar wrote:
> Yeap, !WQ_UNBOUND workqueues == per-cpu workqueues.

Sigh!! You were talking about thread per cpu here... Sorry for missing
it earlier :(

>> At this time local cpu may be busy or idle (Atleast according to scheduler).
>> We don't want a idle cpu (From schedulers perspective) to be used for
>> running this work's handler due to two reasons.
>> - idle cpu may be in WFI or deeper idle states and so we can avoid waking
>>   it up.
>
> I have no idea what WFI is but the physical CPU is already awake at
> that time.  It can't be idle - it's running queue_work().  It could be
> running in lower freq tho, which each code piece doesn't really have
> much control over.

Stupid point. WFI: Wait for interrupt (low power mode of cpu).

>> - We will make idle cpu look busy and so other kernel stuff may be scheduled
>>   on it now. But we could have kept it idle for a long time.
>
> Hmmm... yeah, about the same thing I wrote, it's not really about not
> waking up the CPU right now physically but avoiding forcing the
> scheduler scheduling a pinned task on an otherwise quiescent CPU.
> This effectively allows the scheduler to migrate such work items
> towards a CPU which the scheduler considers to be better (in power or
> whatever) leading to noticeable powersave.

Correct.

>> And what timer are you talking about? I am not talking about deffered work 
>> only,
>> but normal work too.
>
> Deferred work item == timer + work item.

Ya, i knew that :)

>> I might have wrongly phrased some part of my patch (maybe used workqueue
>> instead of work), will fix that up.
>
> I think it'd be necessary to distinguish the physical CPU being idle
> and the scheduler considers it to be idle (no task to schedule on it)
> and explain how increasing the latter can lead to powersave.  As it's
> currently written, it seemingly, to me anyway, suggests that the
> proposed change somehow avoids waking up actually idle CPU, which
> isn't the case as queue_work() *always* schedules on the local CPU.
> The local CPU can't be idle by definition.

Yes you are correct. I will fix it.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-29 Thread Tejun Heo
Hello,

On Mon, Apr 29, 2013 at 12:06:28PM +0530, Viresh Kumar wrote:
> Whatever you wrote above confused me even more :)

Heh heh, confumageddon

> This is what i had in my mind until now. Its not about per-cpu workqueue.
> 
> Lets take example of system_wq. It doesn't have WQ_UNBOUND flag set.
> Now if we call queue_work_on() with cpu x and sytem_wq, then work
> will execute on cpu x. If we call queue_work() then it will queue the work
> on local cpu.

Yeap, !WQ_UNBOUND workqueues == per-cpu workqueues.

> At this time local cpu may be busy or idle (Atleast according to scheduler).
> We don't want a idle cpu (From schedulers perspective) to be used for
> running this work's handler due to two reasons.
> - idle cpu may be in WFI or deeper idle states and so we can avoid waking
>   it up.

I have no idea what WFI is but the physical CPU is already awake at
that time.  It can't be idle - it's running queue_work().  It could be
running in lower freq tho, which each code piece doesn't really have
much control over.

> - We will make idle cpu look busy and so other kernel stuff may be scheduled
>   on it now. But we could have kept it idle for a long time.

Hmmm... yeah, about the same thing I wrote, it's not really about not
waking up the CPU right now physically but avoiding forcing the
scheduler scheduling a pinned task on an otherwise quiescent CPU.
This effectively allows the scheduler to migrate such work items
towards a CPU which the scheduler considers to be better (in power or
whatever) leading to noticeable powersave.

> And what timer are you talking about? I am not talking about deffered work 
> only,
> but normal work too.

Deferred work item == timer + work item.

> I might have wrongly phrased some part of my patch (maybe used workqueue
> instead of work), will fix that up.

I think it'd be necessary to distinguish the physical CPU being idle
and the scheduler considers it to be idle (no task to schedule on it)
and explain how increasing the latter can lead to powersave.  As it's
currently written, it seemingly, to me anyway, suggests that the
proposed change somehow avoids waking up actually idle CPU, which
isn't the case as queue_work() *always* schedules on the local CPU.
The local CPU can't be idle by definition.

Thanks.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-29 Thread Viresh Kumar
Hey Tejun,

On 27 April 2013 00:41, Tejun Heo  wrote:
> Hey, Viresh.
>
> It's already too late for the upcoming merge window, but things
> generally look good to me and I'll apply the patchset once wq/for-3.11
> opens.  One nitpick tho.

Obviously. I understand this and agree with you on it. It should go in 3.11 now.

> On Thu, Apr 25, 2013 at 09:13:44AM +0530, Viresh Kumar wrote:
>> + workqueue.power_efficient
>> + Workqueues can be performance or power-oriented.
>> + Currently, most workqueues are bound to the CPU they
>
>per-cpu would be better
>
>> + were created on. This gives good performance (due to
>> + cache effects) at the cost of potentially waking up
>> + otherwise idle cores just to process some work. To save
>> + power, we can allow the work to be rescheduled on a 
>> core
>> + that is already awake.
>
> The above description is confusing to me.  As have been discussed
> multiple times before, per-cpu workqueue in itself doesn't wake up the
> CPU physically.  The timer may but per-cpu workqueue doesn't.  It was
> confusing when this patchset was first posted and the above phrasing
> is still confusing.  What the patchset tries to do is preventing the
> scheduler from perceiving the CPU as active due to the activated
> worker thread pinned to that CPU, right?  The knob doesn't really do
> anything about waking up the processor in itself.  It just avoids
> feeding the scheduler with noisy activation events and allows it to
> allocate work item execution according to the scheduler's view of CPU
> active/idleness.  As the scheduler has longer / larger scope of
> overall CPU activities and means to regulate them, this leads to more
> power-efficient allocation of work item executions, right?  It'd be
> really great if the descriptions and the comment above the flag makes
> this abundantly clear because it's not something too apparent.

Whatever you wrote above confused me even more :)
This is what i had in my mind until now. Its not about per-cpu workqueue.

Lets take example of system_wq. It doesn't have WQ_UNBOUND flag set.
Now if we call queue_work_on() with cpu x and sytem_wq, then work
will execute on cpu x. If we call queue_work() then it will queue the work
on local cpu.

At this time local cpu may be busy or idle (Atleast according to scheduler).
We don't want a idle cpu (From schedulers perspective) to be used for
running this work's handler due to two reasons.
- idle cpu may be in WFI or deeper idle states and so we can avoid waking
  it up.
- We will make idle cpu look busy and so other kernel stuff may be scheduled
  on it now. But we could have kept it idle for a long time.

And what timer are you talking about? I am not talking about deffered work only,
but normal work too.

I might have wrongly phrased some part of my patch (maybe used workqueue
instead of work), will fix that up.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-29 Thread Viresh Kumar
Hey Tejun,

On 27 April 2013 00:41, Tejun Heo t...@kernel.org wrote:
 Hey, Viresh.

 It's already too late for the upcoming merge window, but things
 generally look good to me and I'll apply the patchset once wq/for-3.11
 opens.  One nitpick tho.

Obviously. I understand this and agree with you on it. It should go in 3.11 now.

 On Thu, Apr 25, 2013 at 09:13:44AM +0530, Viresh Kumar wrote:
 + workqueue.power_efficient
 + Workqueues can be performance or power-oriented.
 + Currently, most workqueues are bound to the CPU they

per-cpu would be better

 + were created on. This gives good performance (due to
 + cache effects) at the cost of potentially waking up
 + otherwise idle cores just to process some work. To save
 + power, we can allow the work to be rescheduled on a 
 core
 + that is already awake.

 The above description is confusing to me.  As have been discussed
 multiple times before, per-cpu workqueue in itself doesn't wake up the
 CPU physically.  The timer may but per-cpu workqueue doesn't.  It was
 confusing when this patchset was first posted and the above phrasing
 is still confusing.  What the patchset tries to do is preventing the
 scheduler from perceiving the CPU as active due to the activated
 worker thread pinned to that CPU, right?  The knob doesn't really do
 anything about waking up the processor in itself.  It just avoids
 feeding the scheduler with noisy activation events and allows it to
 allocate work item execution according to the scheduler's view of CPU
 active/idleness.  As the scheduler has longer / larger scope of
 overall CPU activities and means to regulate them, this leads to more
 power-efficient allocation of work item executions, right?  It'd be
 really great if the descriptions and the comment above the flag makes
 this abundantly clear because it's not something too apparent.

Whatever you wrote above confused me even more :)
This is what i had in my mind until now. Its not about per-cpu workqueue.

Lets take example of system_wq. It doesn't have WQ_UNBOUND flag set.
Now if we call queue_work_on() with cpu x and sytem_wq, then work
will execute on cpu x. If we call queue_work() then it will queue the work
on local cpu.

At this time local cpu may be busy or idle (Atleast according to scheduler).
We don't want a idle cpu (From schedulers perspective) to be used for
running this work's handler due to two reasons.
- idle cpu may be in WFI or deeper idle states and so we can avoid waking
  it up.
- We will make idle cpu look busy and so other kernel stuff may be scheduled
  on it now. But we could have kept it idle for a long time.

And what timer are you talking about? I am not talking about deffered work only,
but normal work too.

I might have wrongly phrased some part of my patch (maybe used workqueue
instead of work), will fix that up.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-29 Thread Tejun Heo
Hello,

On Mon, Apr 29, 2013 at 12:06:28PM +0530, Viresh Kumar wrote:
 Whatever you wrote above confused me even more :)

Heh heh, confumageddon

 This is what i had in my mind until now. Its not about per-cpu workqueue.
 
 Lets take example of system_wq. It doesn't have WQ_UNBOUND flag set.
 Now if we call queue_work_on() with cpu x and sytem_wq, then work
 will execute on cpu x. If we call queue_work() then it will queue the work
 on local cpu.

Yeap, !WQ_UNBOUND workqueues == per-cpu workqueues.

 At this time local cpu may be busy or idle (Atleast according to scheduler).
 We don't want a idle cpu (From schedulers perspective) to be used for
 running this work's handler due to two reasons.
 - idle cpu may be in WFI or deeper idle states and so we can avoid waking
   it up.

I have no idea what WFI is but the physical CPU is already awake at
that time.  It can't be idle - it's running queue_work().  It could be
running in lower freq tho, which each code piece doesn't really have
much control over.

 - We will make idle cpu look busy and so other kernel stuff may be scheduled
   on it now. But we could have kept it idle for a long time.

Hmmm... yeah, about the same thing I wrote, it's not really about not
waking up the CPU right now physically but avoiding forcing the
scheduler scheduling a pinned task on an otherwise quiescent CPU.
This effectively allows the scheduler to migrate such work items
towards a CPU which the scheduler considers to be better (in power or
whatever) leading to noticeable powersave.

 And what timer are you talking about? I am not talking about deffered work 
 only,
 but normal work too.

Deferred work item == timer + work item.

 I might have wrongly phrased some part of my patch (maybe used workqueue
 instead of work), will fix that up.

I think it'd be necessary to distinguish the physical CPU being idle
and the scheduler considers it to be idle (no task to schedule on it)
and explain how increasing the latter can lead to powersave.  As it's
currently written, it seemingly, to me anyway, suggests that the
proposed change somehow avoids waking up actually idle CPU, which
isn't the case as queue_work() *always* schedules on the local CPU.
The local CPU can't be idle by definition.

Thanks.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-29 Thread Viresh Kumar
On 29 April 2013 21:49, Tejun Heo t...@kernel.org wrote:
 On Mon, Apr 29, 2013 at 12:06:28PM +0530, Viresh Kumar wrote:
 Yeap, !WQ_UNBOUND workqueues == per-cpu workqueues.

Sigh!! You were talking about thread per cpu here... Sorry for missing
it earlier :(

 At this time local cpu may be busy or idle (Atleast according to scheduler).
 We don't want a idle cpu (From schedulers perspective) to be used for
 running this work's handler due to two reasons.
 - idle cpu may be in WFI or deeper idle states and so we can avoid waking
   it up.

 I have no idea what WFI is but the physical CPU is already awake at
 that time.  It can't be idle - it's running queue_work().  It could be
 running in lower freq tho, which each code piece doesn't really have
 much control over.

Stupid point. WFI: Wait for interrupt (low power mode of cpu).

 - We will make idle cpu look busy and so other kernel stuff may be scheduled
   on it now. But we could have kept it idle for a long time.

 Hmmm... yeah, about the same thing I wrote, it's not really about not
 waking up the CPU right now physically but avoiding forcing the
 scheduler scheduling a pinned task on an otherwise quiescent CPU.
 This effectively allows the scheduler to migrate such work items
 towards a CPU which the scheduler considers to be better (in power or
 whatever) leading to noticeable powersave.

Correct.

 And what timer are you talking about? I am not talking about deffered work 
 only,
 but normal work too.

 Deferred work item == timer + work item.

Ya, i knew that :)

 I might have wrongly phrased some part of my patch (maybe used workqueue
 instead of work), will fix that up.

 I think it'd be necessary to distinguish the physical CPU being idle
 and the scheduler considers it to be idle (no task to schedule on it)
 and explain how increasing the latter can lead to powersave.  As it's
 currently written, it seemingly, to me anyway, suggests that the
 proposed change somehow avoids waking up actually idle CPU, which
 isn't the case as queue_work() *always* schedules on the local CPU.
 The local CPU can't be idle by definition.

Yes you are correct. I will fix it.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-26 Thread Tejun Heo
Hey, Viresh.

It's already too late for the upcoming merge window, but things
generally look good to me and I'll apply the patchset once wq/for-3.11
opens.  One nitpick tho.

On Thu, Apr 25, 2013 at 09:13:44AM +0530, Viresh Kumar wrote:
> + workqueue.power_efficient
> + Workqueues can be performance or power-oriented.
> + Currently, most workqueues are bound to the CPU they
   
   per-cpu would be better

> + were created on. This gives good performance (due to
> + cache effects) at the cost of potentially waking up
> + otherwise idle cores just to process some work. To save
> + power, we can allow the work to be rescheduled on a core
> + that is already awake.

The above description is confusing to me.  As have been discussed
multiple times before, per-cpu workqueue in itself doesn't wake up the
CPU physically.  The timer may but per-cpu workqueue doesn't.  It was
confusing when this patchset was first posted and the above phrasing
is still confusing.  What the patchset tries to do is preventing the
scheduler from perceiving the CPU as active due to the activated
worker thread pinned to that CPU, right?  The knob doesn't really do
anything about waking up the processor in itself.  It just avoids
feeding the scheduler with noisy activation events and allows it to
allocate work item execution according to the scheduler's view of CPU
active/idleness.  As the scheduler has longer / larger scope of
overall CPU activities and means to regulate them, this leads to more
power-efficient allocation of work item executions, right?  It'd be
really great if the descriptions and the comment above the flag makes
this abundantly clear because it's not something too apparent.

Thanks.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-26 Thread Tejun Heo
Hey, Viresh.

It's already too late for the upcoming merge window, but things
generally look good to me and I'll apply the patchset once wq/for-3.11
opens.  One nitpick tho.

On Thu, Apr 25, 2013 at 09:13:44AM +0530, Viresh Kumar wrote:
 + workqueue.power_efficient
 + Workqueues can be performance or power-oriented.
 + Currently, most workqueues are bound to the CPU they
   
   per-cpu would be better

 + were created on. This gives good performance (due to
 + cache effects) at the cost of potentially waking up
 + otherwise idle cores just to process some work. To save
 + power, we can allow the work to be rescheduled on a core
 + that is already awake.

The above description is confusing to me.  As have been discussed
multiple times before, per-cpu workqueue in itself doesn't wake up the
CPU physically.  The timer may but per-cpu workqueue doesn't.  It was
confusing when this patchset was first posted and the above phrasing
is still confusing.  What the patchset tries to do is preventing the
scheduler from perceiving the CPU as active due to the activated
worker thread pinned to that CPU, right?  The knob doesn't really do
anything about waking up the processor in itself.  It just avoids
feeding the scheduler with noisy activation events and allows it to
allocate work item execution according to the scheduler's view of CPU
active/idleness.  As the scheduler has longer / larger scope of
overall CPU activities and means to regulate them, this leads to more
power-efficient allocation of work item executions, right?  It'd be
really great if the descriptions and the comment above the flag makes
this abundantly clear because it's not something too apparent.

Thanks.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-25 Thread Viresh Kumar
On 25 April 2013 16:43, Amit Kucheria  wrote:
> On Thu, Apr 25, 2013 at 9:13 AM, Viresh Kumar  wrote:
>> On 25 April 2013 09:00, Amit Kucheria  wrote:
>>> Yes. That was my intention - preventing a prompt on existing defconfigs and
>>> there by maintaining current behavior.
>>
>> Hmm... Following is the version after fixing all problems you reported.
>> @Tejun: I have attached it too as gmail's copy-paste may break it. Please
>> consider applying this series if it looks fine to you.
>>
>>
>> ---xx-
>>
>> From: Viresh Kumar 
>> Date: Mon, 8 Apr 2013 16:45:40 +0530
>> Subject: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for
>>  power oriented workqueues
>>
>> Workqueues can be performance or power-oriented. Currently, most workqueues 
>> are
>> bound to the CPU they were created on. This gives good performance (due to 
>> cache
>> effects) at the cost of potentially waking up otherwise idle cores just to
>> process some work. To save power, we can allow the work to be rescheduled on 
>> a
>> core that is already awake.
>>
>> Workqueues created with the WQ_UNBOUND flag will allow some power savings.
>> However, we don't change the default behaviour of the system.  To enable
>> power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs 
>> to
>> be turned on. This option can also be overridden by the
>> workqueue.power_efficient boot parameter.
>>
>> Signed-off-by: Viresh Kumar 
>
> For the series, you can add my:
>
> Reviewed-by: Amit Kucheria 

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-25 Thread Amit Kucheria
On Thu, Apr 25, 2013 at 9:13 AM, Viresh Kumar  wrote:
> On 25 April 2013 09:00, Amit Kucheria  wrote:
>> Yes. That was my intention - preventing a prompt on existing defconfigs and
>> there by maintaining current behavior.
>
> Hmm... Following is the version after fixing all problems you reported.
> @Tejun: I have attached it too as gmail's copy-paste may break it. Please
> consider applying this series if it looks fine to you.
>
>
> ---xx-
>
> From: Viresh Kumar 
> Date: Mon, 8 Apr 2013 16:45:40 +0530
> Subject: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for
>  power oriented workqueues
>
> Workqueues can be performance or power-oriented. Currently, most workqueues 
> are
> bound to the CPU they were created on. This gives good performance (due to 
> cache
> effects) at the cost of potentially waking up otherwise idle cores just to
> process some work. To save power, we can allow the work to be rescheduled on a
> core that is already awake.
>
> Workqueues created with the WQ_UNBOUND flag will allow some power savings.
> However, we don't change the default behaviour of the system.  To enable
> power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
> be turned on. This option can also be overridden by the
> workqueue.power_efficient boot parameter.
>
> Signed-off-by: Viresh Kumar 

For the series, you can add my:

Reviewed-by: Amit Kucheria 

> ---
>  Documentation/kernel-parameters.txt | 17 +
>  include/linux/workqueue.h   |  3 +++
>  kernel/power/Kconfig| 19 +++
>  kernel/workqueue.c  | 11 +++
>  4 files changed, 50 insertions(+)
>
> diff --git a/Documentation/kernel-parameters.txt
> b/Documentation/kernel-parameters.txt
> index c4fa000..22edc83 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -3312,6 +3312,23 @@ bytes respectively. Such letter suffixes can
> also be entirely omitted.
> that this also can be controlled per-workqueue for
> workqueues visible under /sys/bus/workqueue/.
>
> +   workqueue.power_efficient
> +   Workqueues can be performance or power-oriented.
> +   Currently, most workqueues are bound to the CPU they
> +   were created on. This gives good performance (due to
> +   cache effects) at the cost of potentially waking up
> +   otherwise idle cores just to process some work. To 
> save
> +   power, we can allow the work to be rescheduled on a 
> core
> +   that is already awake.
> +
> +   Workqueues created with the WQ_UNBOUND flag will allow
> +   some power savings.  However, we don't change the
> +   default behaviour of the system.  To enable 
> power-saving
> +   behaviour, a new config option 
> CONFIG_WQ_POWER_EFFICIENT
> +   needs to be turned on. This option can also be
> +   overridden by the workqueue.power_efficient boot
> +   parameter.
> +
> x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
> default x2apic cluster mode on platforms
> supporting x2apic.
> diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
> index 623488f..83fa570 100644
> --- a/include/linux/workqueue.h
> +++ b/include/linux/workqueue.h
> @@ -302,6 +302,9 @@ enum {
> WQ_HIGHPRI  = 1 << 4, /* high priority */
> WQ_CPU_INTENSIVE= 1 << 5, /* cpu instensive workqueue */
> WQ_SYSFS= 1 << 6, /* visible in sysfs, see 
> wq_sysfs_register() */
> +   WQ_POWER_EFFICIENT  = 1 << 7, /* WQ_UNBOUND, for power
> +  * saving, if wq_power_efficient is
> +  * enabled. Unused otherwise. */
>
> __WQ_DRAINING   = 1 << 16, /* internal: workqueue is draining 
> */
> __WQ_ORDERED= 1 << 17, /* internal: workqueue is ordered 
> */
> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index 5dfdc9e..018f039 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -263,6 +263,25 @@ config PM_GENERIC_DOMAINS
> bool
> depends on PM
>
> +config WQ_POWER_EFFICIENT
> +   bool "Workqueue allocated as UNBOUND (by default) for power 
> efficiency"
> +   depends on PM
> +   default n
> +   help
> + Workqueues can be performance or power-oriented. Currently, most
> + workqueues are bound to the CPU they were created on. This gives 
> good
> + performance (due to cache effects) at the cost of potentially waking
> + up otherwise idle cores just 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-25 Thread Amit Kucheria
On Thu, Apr 25, 2013 at 9:13 AM, Viresh Kumar viresh.ku...@linaro.org wrote:
 On 25 April 2013 09:00, Amit Kucheria amit.kuche...@linaro.org wrote:
 Yes. That was my intention - preventing a prompt on existing defconfigs and
 there by maintaining current behavior.

 Hmm... Following is the version after fixing all problems you reported.
 @Tejun: I have attached it too as gmail's copy-paste may break it. Please
 consider applying this series if it looks fine to you.


 ---xx-

 From: Viresh Kumar viresh.ku...@linaro.org
 Date: Mon, 8 Apr 2013 16:45:40 +0530
 Subject: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for
  power oriented workqueues

 Workqueues can be performance or power-oriented. Currently, most workqueues 
 are
 bound to the CPU they were created on. This gives good performance (due to 
 cache
 effects) at the cost of potentially waking up otherwise idle cores just to
 process some work. To save power, we can allow the work to be rescheduled on a
 core that is already awake.

 Workqueues created with the WQ_UNBOUND flag will allow some power savings.
 However, we don't change the default behaviour of the system.  To enable
 power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
 be turned on. This option can also be overridden by the
 workqueue.power_efficient boot parameter.

 Signed-off-by: Viresh Kumar viresh.ku...@linaro.org

For the series, you can add my:

Reviewed-by: Amit Kucheria amit.kuche...@linaro.org

 ---
  Documentation/kernel-parameters.txt | 17 +
  include/linux/workqueue.h   |  3 +++
  kernel/power/Kconfig| 19 +++
  kernel/workqueue.c  | 11 +++
  4 files changed, 50 insertions(+)

 diff --git a/Documentation/kernel-parameters.txt
 b/Documentation/kernel-parameters.txt
 index c4fa000..22edc83 100644
 --- a/Documentation/kernel-parameters.txt
 +++ b/Documentation/kernel-parameters.txt
 @@ -3312,6 +3312,23 @@ bytes respectively. Such letter suffixes can
 also be entirely omitted.
 that this also can be controlled per-workqueue for
 workqueues visible under /sys/bus/workqueue/.

 +   workqueue.power_efficient
 +   Workqueues can be performance or power-oriented.
 +   Currently, most workqueues are bound to the CPU they
 +   were created on. This gives good performance (due to
 +   cache effects) at the cost of potentially waking up
 +   otherwise idle cores just to process some work. To 
 save
 +   power, we can allow the work to be rescheduled on a 
 core
 +   that is already awake.
 +
 +   Workqueues created with the WQ_UNBOUND flag will allow
 +   some power savings.  However, we don't change the
 +   default behaviour of the system.  To enable 
 power-saving
 +   behaviour, a new config option 
 CONFIG_WQ_POWER_EFFICIENT
 +   needs to be turned on. This option can also be
 +   overridden by the workqueue.power_efficient boot
 +   parameter.
 +
 x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
 default x2apic cluster mode on platforms
 supporting x2apic.
 diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
 index 623488f..83fa570 100644
 --- a/include/linux/workqueue.h
 +++ b/include/linux/workqueue.h
 @@ -302,6 +302,9 @@ enum {
 WQ_HIGHPRI  = 1  4, /* high priority */
 WQ_CPU_INTENSIVE= 1  5, /* cpu instensive workqueue */
 WQ_SYSFS= 1  6, /* visible in sysfs, see 
 wq_sysfs_register() */
 +   WQ_POWER_EFFICIENT  = 1  7, /* WQ_UNBOUND, for power
 +  * saving, if wq_power_efficient is
 +  * enabled. Unused otherwise. */

 __WQ_DRAINING   = 1  16, /* internal: workqueue is draining 
 */
 __WQ_ORDERED= 1  17, /* internal: workqueue is ordered 
 */
 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
 index 5dfdc9e..018f039 100644
 --- a/kernel/power/Kconfig
 +++ b/kernel/power/Kconfig
 @@ -263,6 +263,25 @@ config PM_GENERIC_DOMAINS
 bool
 depends on PM

 +config WQ_POWER_EFFICIENT
 +   bool Workqueue allocated as UNBOUND (by default) for power 
 efficiency
 +   depends on PM
 +   default n
 +   help
 + Workqueues can be performance or power-oriented. Currently, most
 + workqueues are bound to the CPU they were created on. This gives 
 good
 + performance (due to cache effects) at the cost of potentially waking
 + up otherwise idle cores just to 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-25 Thread Viresh Kumar
On 25 April 2013 16:43, Amit Kucheria amit.kuche...@linaro.org wrote:
 On Thu, Apr 25, 2013 at 9:13 AM, Viresh Kumar viresh.ku...@linaro.org wrote:
 On 25 April 2013 09:00, Amit Kucheria amit.kuche...@linaro.org wrote:
 Yes. That was my intention - preventing a prompt on existing defconfigs and
 there by maintaining current behavior.

 Hmm... Following is the version after fixing all problems you reported.
 @Tejun: I have attached it too as gmail's copy-paste may break it. Please
 consider applying this series if it looks fine to you.


 ---xx-

 From: Viresh Kumar viresh.ku...@linaro.org
 Date: Mon, 8 Apr 2013 16:45:40 +0530
 Subject: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for
  power oriented workqueues

 Workqueues can be performance or power-oriented. Currently, most workqueues 
 are
 bound to the CPU they were created on. This gives good performance (due to 
 cache
 effects) at the cost of potentially waking up otherwise idle cores just to
 process some work. To save power, we can allow the work to be rescheduled on 
 a
 core that is already awake.

 Workqueues created with the WQ_UNBOUND flag will allow some power savings.
 However, we don't change the default behaviour of the system.  To enable
 power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs 
 to
 be turned on. This option can also be overridden by the
 workqueue.power_efficient boot parameter.

 Signed-off-by: Viresh Kumar viresh.ku...@linaro.org

 For the series, you can add my:

 Reviewed-by: Amit Kucheria amit.kuche...@linaro.org

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Viresh Kumar
On 25 April 2013 09:00, Amit Kucheria  wrote:
> Yes. That was my intention - preventing a prompt on existing defconfigs and
> there by maintaining current behavior.

Hmm... Following is the version after fixing all problems you reported.
@Tejun: I have attached it too as gmail's copy-paste may break it. Please
consider applying this series if it looks fine to you.


---xx-

From: Viresh Kumar 
Date: Mon, 8 Apr 2013 16:45:40 +0530
Subject: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for
 power oriented workqueues

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

Signed-off-by: Viresh Kumar 
---
 Documentation/kernel-parameters.txt | 17 +
 include/linux/workqueue.h   |  3 +++
 kernel/power/Kconfig| 19 +++
 kernel/workqueue.c  | 11 +++
 4 files changed, 50 insertions(+)

diff --git a/Documentation/kernel-parameters.txt
b/Documentation/kernel-parameters.txt
index c4fa000..22edc83 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3312,6 +3312,23 @@ bytes respectively. Such letter suffixes can
also be entirely omitted.
that this also can be controlled per-workqueue for
workqueues visible under /sys/bus/workqueue/.

+   workqueue.power_efficient
+   Workqueues can be performance or power-oriented.
+   Currently, most workqueues are bound to the CPU they
+   were created on. This gives good performance (due to
+   cache effects) at the cost of potentially waking up
+   otherwise idle cores just to process some work. To save
+   power, we can allow the work to be rescheduled on a core
+   that is already awake.
+
+   Workqueues created with the WQ_UNBOUND flag will allow
+   some power savings.  However, we don't change the
+   default behaviour of the system.  To enable power-saving
+   behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT
+   needs to be turned on. This option can also be
+   overridden by the workqueue.power_efficient boot
+   parameter.
+
x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
default x2apic cluster mode on platforms
supporting x2apic.
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 623488f..83fa570 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -302,6 +302,9 @@ enum {
WQ_HIGHPRI  = 1 << 4, /* high priority */
WQ_CPU_INTENSIVE= 1 << 5, /* cpu instensive workqueue */
WQ_SYSFS= 1 << 6, /* visible in sysfs, see 
wq_sysfs_register() */
+   WQ_POWER_EFFICIENT  = 1 << 7, /* WQ_UNBOUND, for power
+  * saving, if wq_power_efficient is
+  * enabled. Unused otherwise. */

__WQ_DRAINING   = 1 << 16, /* internal: workqueue is draining */
__WQ_ORDERED= 1 << 17, /* internal: workqueue is ordered */
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 5dfdc9e..018f039 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -263,6 +263,25 @@ config PM_GENERIC_DOMAINS
bool
depends on PM

+config WQ_POWER_EFFICIENT
+   bool "Workqueue allocated as UNBOUND (by default) for power efficiency"
+   depends on PM
+   default n
+   help
+ Workqueues can be performance or power-oriented. Currently, most
+ workqueues are bound to the CPU they were created on. This gives good
+ performance (due to cache effects) at the cost of potentially waking
+ up otherwise idle cores just to process some work. To save power, we
+ can allow the work to be rescheduled on a core that is already awake.
+
+ Workqueues created with the WQ_UNBOUND flag will allow some power
+ savings.  However, we don't change the default behaviour of the
+ system.  To enable power-saving behaviour, a new 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Tejun Heo
On Wed, Apr 24, 2013 at 05:57:09PM +0530, Viresh Kumar wrote:
> If this line is not present i believe it is 'default n' only. So, i skipped 
> it.

I think the difference is that when you configure the option for the
first time - ie. building kernel with .config used for an older kernel
- that it prompts for selection, thus annoying the big penguin.  You
probably want the explicit 'N'.

Thanks.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Viresh Kumar
On 24 April 2013 17:50, Amit Kucheria  wrote:
> On Wed, Apr 24, 2013 at 5:12 PM, Viresh Kumar  wrote:
>> +config WQ_POWER_EFFICIENT
>> +   bool "Workqueue allocated as UNBOUND (by default) for power 
>> efficiency"
>> +   depends on PM
>
> default n

If this line is not present i believe it is 'default n' only. So, i skipped it.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Amit Kucheria
On Wed, Apr 24, 2013 at 5:12 PM, Viresh Kumar  wrote:
> Workqueues can be performance or power oriented. For performance we may want 
> to
> keep them running on a single cpu, so that it remains cache hot. For power we
> can give scheduler the liberty to choose target cpu for running work handler.

Consider the following rewording:

Workqueues can be performance or power-oriented. Currently, most
workqueues are bound to the CPU they were created on. This gives good
performance (due to cache effects) at the cost of potentially waking
up otherwise idle cores just to process some work. To save power, we
can allow the work to be rescheduled on a core that is already awake.

> Later one (Power oriented WQ) can be achieved if the workqueue is allocated 
> with
> WQ_UNBOUND flag. Enabling CONFIG_WQ_POWER_EFFICIENT will set
> 'wq_power_efficient' to 'true'. Setting 'power_efficient' boot param will
> override value of 'wq_power_efficient' variable. When 'wq_power_efficient' is
> set to 'true', we will convert WQ_POWER_EFFICIENT flag to WQ_UNBOUND on wq
> allocation. And so scheduler will have the liberty to choose where to run this
> work.

Consider the following rewording which is easier to understand IMO:

Workqueues created with the WQ_UNBOUND flag will allow some power
savings. However, we don't change the default behaviour of the system.
To enable power-saving behaviour, a new config option
CONFIG_WQ_POWER_EFFICIENT needs to be turned on. This option can also
be overridden by the workqueue.power_efficient boot parameter.



> Signed-off-by: Viresh Kumar 
> ---
>  Documentation/kernel-parameters.txt | 17 +
>  include/linux/workqueue.h   |  3 +++
>  kernel/power/Kconfig| 19 +++
>  kernel/workqueue.c  | 11 +++
>  4 files changed, 50 insertions(+)
>
> diff --git a/Documentation/kernel-parameters.txt 
> b/Documentation/kernel-parameters.txt
> index c4fa000..a9040fa 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -3312,6 +3312,23 @@ bytes respectively. Such letter suffixes can also be 
> entirely omitted.
> that this also can be controlled per-workqueue for
> workqueues visible under /sys/bus/workqueue/.
>
> +   workqueue.power_efficient
> +   Workqueues can be performance or power oriented. For
> +   performance we may want to keep them running on a 
> single
> +   cpu, so that it remains cache hot. For power we can 
> give
> +   scheduler the liberty to choose target cpu for running
> +   work handler.
> +
> +   Later one (Power oriented WQ) can be achieved if the
> +   workqueue is allocated with WQ_UNBOUND flag. Enabling
> +   CONFIG_WQ_POWER_EFFICIENT will set 
> 'wq_power_efficient'
> +   to 'true'. Setting 'power_efficient' boot param will
> +   override value of 'wq_power_efficient' variable. When
> +   'wq_power_efficient' is set to 'true', we will convert
> +   WQ_POWER_EFFICIENT flag to WQ_UNBOUND on wq 
> allocation.
> +   And so scheduler will have the liberty to choose where
> +   to run this work.
> +

Rewrite as above.

> x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
> default x2apic cluster mode on platforms
> supporting x2apic.
> diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
> index 623488f..83fa570 100644
> --- a/include/linux/workqueue.h
> +++ b/include/linux/workqueue.h
> @@ -302,6 +302,9 @@ enum {
> WQ_HIGHPRI  = 1 << 4, /* high priority */
> WQ_CPU_INTENSIVE= 1 << 5, /* cpu instensive workqueue */
> WQ_SYSFS= 1 << 6, /* visible in sysfs, see 
> wq_sysfs_register() */
> +   WQ_POWER_EFFICIENT  = 1 << 7, /* WQ_UNBOUND, for power
> +  * saving, if wq_power_efficient is
> +  * enabled. Unused otherwise. */
>
> __WQ_DRAINING   = 1 << 16, /* internal: workqueue is draining 
> */
> __WQ_ORDERED= 1 << 17, /* internal: workqueue is ordered 
> */
> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index 5dfdc9e..e1e9c8b 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -263,6 +263,25 @@ config PM_GENERIC_DOMAINS
> bool
> depends on PM
>
> +config WQ_POWER_EFFICIENT
> +   bool "Workqueue allocated as UNBOUND (by default) for power 
> efficiency"
> +   depends on PM

default n

> +   help
> + Workqueues can be performance or power oriented. For performance we
> + may want to keep them running on a 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Amit Kucheria
On Wed, Apr 24, 2013 at 5:12 PM, Viresh Kumar viresh.ku...@linaro.org wrote:
 Workqueues can be performance or power oriented. For performance we may want 
 to
 keep them running on a single cpu, so that it remains cache hot. For power we
 can give scheduler the liberty to choose target cpu for running work handler.

Consider the following rewording:

Workqueues can be performance or power-oriented. Currently, most
workqueues are bound to the CPU they were created on. This gives good
performance (due to cache effects) at the cost of potentially waking
up otherwise idle cores just to process some work. To save power, we
can allow the work to be rescheduled on a core that is already awake.

 Later one (Power oriented WQ) can be achieved if the workqueue is allocated 
 with
 WQ_UNBOUND flag. Enabling CONFIG_WQ_POWER_EFFICIENT will set
 'wq_power_efficient' to 'true'. Setting 'power_efficient' boot param will
 override value of 'wq_power_efficient' variable. When 'wq_power_efficient' is
 set to 'true', we will convert WQ_POWER_EFFICIENT flag to WQ_UNBOUND on wq
 allocation. And so scheduler will have the liberty to choose where to run this
 work.

Consider the following rewording which is easier to understand IMO:

Workqueues created with the WQ_UNBOUND flag will allow some power
savings. However, we don't change the default behaviour of the system.
To enable power-saving behaviour, a new config option
CONFIG_WQ_POWER_EFFICIENT needs to be turned on. This option can also
be overridden by the workqueue.power_efficient boot parameter.



 Signed-off-by: Viresh Kumar viresh.ku...@linaro.org
 ---
  Documentation/kernel-parameters.txt | 17 +
  include/linux/workqueue.h   |  3 +++
  kernel/power/Kconfig| 19 +++
  kernel/workqueue.c  | 11 +++
  4 files changed, 50 insertions(+)

 diff --git a/Documentation/kernel-parameters.txt 
 b/Documentation/kernel-parameters.txt
 index c4fa000..a9040fa 100644
 --- a/Documentation/kernel-parameters.txt
 +++ b/Documentation/kernel-parameters.txt
 @@ -3312,6 +3312,23 @@ bytes respectively. Such letter suffixes can also be 
 entirely omitted.
 that this also can be controlled per-workqueue for
 workqueues visible under /sys/bus/workqueue/.

 +   workqueue.power_efficient
 +   Workqueues can be performance or power oriented. For
 +   performance we may want to keep them running on a 
 single
 +   cpu, so that it remains cache hot. For power we can 
 give
 +   scheduler the liberty to choose target cpu for running
 +   work handler.
 +
 +   Later one (Power oriented WQ) can be achieved if the
 +   workqueue is allocated with WQ_UNBOUND flag. Enabling
 +   CONFIG_WQ_POWER_EFFICIENT will set 
 'wq_power_efficient'
 +   to 'true'. Setting 'power_efficient' boot param will
 +   override value of 'wq_power_efficient' variable. When
 +   'wq_power_efficient' is set to 'true', we will convert
 +   WQ_POWER_EFFICIENT flag to WQ_UNBOUND on wq 
 allocation.
 +   And so scheduler will have the liberty to choose where
 +   to run this work.
 +

Rewrite as above.

 x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
 default x2apic cluster mode on platforms
 supporting x2apic.
 diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
 index 623488f..83fa570 100644
 --- a/include/linux/workqueue.h
 +++ b/include/linux/workqueue.h
 @@ -302,6 +302,9 @@ enum {
 WQ_HIGHPRI  = 1  4, /* high priority */
 WQ_CPU_INTENSIVE= 1  5, /* cpu instensive workqueue */
 WQ_SYSFS= 1  6, /* visible in sysfs, see 
 wq_sysfs_register() */
 +   WQ_POWER_EFFICIENT  = 1  7, /* WQ_UNBOUND, for power
 +  * saving, if wq_power_efficient is
 +  * enabled. Unused otherwise. */

 __WQ_DRAINING   = 1  16, /* internal: workqueue is draining 
 */
 __WQ_ORDERED= 1  17, /* internal: workqueue is ordered 
 */
 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
 index 5dfdc9e..e1e9c8b 100644
 --- a/kernel/power/Kconfig
 +++ b/kernel/power/Kconfig
 @@ -263,6 +263,25 @@ config PM_GENERIC_DOMAINS
 bool
 depends on PM

 +config WQ_POWER_EFFICIENT
 +   bool Workqueue allocated as UNBOUND (by default) for power 
 efficiency
 +   depends on PM

default n

 +   help
 + Workqueues can be performance or power oriented. For performance we
 + may want to keep them running on a single cpu, so that it remains
 + cache hot. For 

Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Viresh Kumar
On 24 April 2013 17:50, Amit Kucheria amit.kuche...@linaro.org wrote:
 On Wed, Apr 24, 2013 at 5:12 PM, Viresh Kumar viresh.ku...@linaro.org wrote:
 +config WQ_POWER_EFFICIENT
 +   bool Workqueue allocated as UNBOUND (by default) for power 
 efficiency
 +   depends on PM

 default n

If this line is not present i believe it is 'default n' only. So, i skipped it.

All others comments accepted.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Tejun Heo
On Wed, Apr 24, 2013 at 05:57:09PM +0530, Viresh Kumar wrote:
 If this line is not present i believe it is 'default n' only. So, i skipped 
 it.

I think the difference is that when you configure the option for the
first time - ie. building kernel with .config used for an older kernel
- that it prompts for selection, thus annoying the big penguin.  You
probably want the explicit 'N'.

Thanks.

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


Re: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

2013-04-24 Thread Viresh Kumar
On 25 April 2013 09:00, Amit Kucheria amit.kuche...@linaro.org wrote:
 Yes. That was my intention - preventing a prompt on existing defconfigs and
 there by maintaining current behavior.

Hmm... Following is the version after fixing all problems you reported.
@Tejun: I have attached it too as gmail's copy-paste may break it. Please
consider applying this series if it looks fine to you.


---xx-

From: Viresh Kumar viresh.ku...@linaro.org
Date: Mon, 8 Apr 2013 16:45:40 +0530
Subject: [PATCH V5 1/5] workqueues: Introduce new flag WQ_POWER_EFFICIENT for
 power oriented workqueues

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

Signed-off-by: Viresh Kumar viresh.ku...@linaro.org
---
 Documentation/kernel-parameters.txt | 17 +
 include/linux/workqueue.h   |  3 +++
 kernel/power/Kconfig| 19 +++
 kernel/workqueue.c  | 11 +++
 4 files changed, 50 insertions(+)

diff --git a/Documentation/kernel-parameters.txt
b/Documentation/kernel-parameters.txt
index c4fa000..22edc83 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3312,6 +3312,23 @@ bytes respectively. Such letter suffixes can
also be entirely omitted.
that this also can be controlled per-workqueue for
workqueues visible under /sys/bus/workqueue/.

+   workqueue.power_efficient
+   Workqueues can be performance or power-oriented.
+   Currently, most workqueues are bound to the CPU they
+   were created on. This gives good performance (due to
+   cache effects) at the cost of potentially waking up
+   otherwise idle cores just to process some work. To save
+   power, we can allow the work to be rescheduled on a core
+   that is already awake.
+
+   Workqueues created with the WQ_UNBOUND flag will allow
+   some power savings.  However, we don't change the
+   default behaviour of the system.  To enable power-saving
+   behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT
+   needs to be turned on. This option can also be
+   overridden by the workqueue.power_efficient boot
+   parameter.
+
x2apic_phys [X86-64,APIC] Use x2apic physical mode instead of
default x2apic cluster mode on platforms
supporting x2apic.
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 623488f..83fa570 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -302,6 +302,9 @@ enum {
WQ_HIGHPRI  = 1  4, /* high priority */
WQ_CPU_INTENSIVE= 1  5, /* cpu instensive workqueue */
WQ_SYSFS= 1  6, /* visible in sysfs, see 
wq_sysfs_register() */
+   WQ_POWER_EFFICIENT  = 1  7, /* WQ_UNBOUND, for power
+  * saving, if wq_power_efficient is
+  * enabled. Unused otherwise. */

__WQ_DRAINING   = 1  16, /* internal: workqueue is draining */
__WQ_ORDERED= 1  17, /* internal: workqueue is ordered */
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 5dfdc9e..018f039 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -263,6 +263,25 @@ config PM_GENERIC_DOMAINS
bool
depends on PM

+config WQ_POWER_EFFICIENT
+   bool Workqueue allocated as UNBOUND (by default) for power efficiency
+   depends on PM
+   default n
+   help
+ Workqueues can be performance or power-oriented. Currently, most
+ workqueues are bound to the CPU they were created on. This gives good
+ performance (due to cache effects) at the cost of potentially waking
+ up otherwise idle cores just to process some work. To save power, we
+ can allow the work to be rescheduled on a core that is already awake.
+
+ Workqueues created with the WQ_UNBOUND flag will allow some power
+ savings.  However, we don't change the default behaviour of the
+