All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain
@ 2012-04-28 20:45 Alexander Tarasikov
  2012-04-28 20:45 ` [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops Alexander Tarasikov
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Tarasikov @ 2012-04-28 20:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: airlied


Hello! Many modern laptops featuring hybrid graphics show a huge raise in
power drain after a suspend/resume cycle which is caused by the discrete
adapter ignoring ACPI-issued power off call after a resume.

This behaviour (increase in power consumption) has been observed on several
machines by many users. This machines include Thinkpad X220, HP Elitebook and
Sony VAIO series, so this may apply to all laptops.

One of the workarounds is to do an ON/OFF cycle via switcheroo from userland
on each resume but this causes confusion in the VGA BIOS which thinks the card
is already ON and that leads to the GPU lockup and system slowdown for a minute
or so. This kind of behaviour is absolutely unacceptable.

I propose this patch as a workaround. It creates a new module parameter
(vga_switcheroo.resume_powercut). When it is set to 1, on resume the driver
will iterate over the list of registered cards and disable all inactive cards
ignoring their power state in switcheroo struct (ON/OFF).

I have tested this on my laptop (which is Sony VAIO SA3S9R with i5, HM67,
HD3000 and Radeon 6630M).
Without this patch, the idle power consumption is 7-9W. After a suspend/resume
cycle that jumps to 15-19W. With the patch, the consumption is always below
10W after numerous suspend/resume cycles.

I agree that the implementation may be far from clean, therefore I have
not enabled the parameter by default. I am welcome to any suggestions on
improving the implementation but I think that it would not hurt to include
it as-is so that users can test it and report their impressions/bugs. Please
review the patch and forward it to downstream projects if you are involved in
any that may be interested (i.e., ubuntu kernel team).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops
  2012-04-28 20:45 [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain Alexander Tarasikov
@ 2012-04-28 20:45 ` Alexander Tarasikov
  2012-04-28 21:10   ` Alan Cox
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Tarasikov @ 2012-04-28 20:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: airlied, Alexander Tarasikov

	Many laptop computers with switchable graphics that have an ATI
	Radeon graphics card ignore ACPI state for the discrete VGA
	and enable it on resume in spite of it being disabled by
	vga_switcheroo.

	That causes an extra power drain of around 10-15W and overheating after
	a suspend-resume cycle. A userspace-based workaround involving
	enabling and disabling the discrete card via debugfs has a major
	drawback - it causes long (around one minute) lockups because VGA BIOS
	is confused by the enable request.

	This patch adds an experimental module parameter that causes
	vga_switcheroo to disable all inactive VGA cards after a resume
	to save power and avoid lockups/GPU freezes. This has been tested
	on a Sony VAIO laptop with Intel HD3000 and Ati Radeon 6630M GPU.

Signed-off-by: Alexander Tarasikov <alexander.tarasikov@gmail.com>
---
 drivers/gpu/vga/vga_switcheroo.c |   71 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index 58434e8..21b8e2c 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -490,3 +490,74 @@ err:
 }
 EXPORT_SYMBOL(vga_switcheroo_process_delayed_switch);
 
+#ifdef CONFIG_PM_SLEEP
+#include <linux/suspend.h>
+
+static int resume_powercut;
+module_param_named(resume_powercut, resume_powercut, int, 0400);
+MODULE_PARM_DESC(resume_powercut,
+	"Forcibly disable power to inactive VGA cards on resume."
+	" This is a workaround for laptops with ATI Radeon cards"
+	" which ignore ACPI state and cause extra 10W of power consumption");
+
+static int vga_switcheroo_notify(struct notifier_block *nb,
+	unsigned long mode, void *_unused)
+{
+	int i;
+
+	switch (mode) {
+	case PM_POST_HIBERNATION:
+	case PM_POST_SUSPEND:
+		break;
+	default:
+		return 0;
+	}
+
+	mutex_lock(&vgasr_mutex);
+
+	if (!vgasr_priv.active) {
+		pr_info("vga_witcheroo: not active, ignoring notification\n");
+		goto out;
+	}
+
+	pr_debug("vga_switcheroo: disabling unused VGAs\n");
+	for (i = 0; i < VGA_SWITCHEROO_MAX_CLIENTS; i++) {
+		if (vgasr_priv.clients[i].active)
+			continue;
+		pr_info("vga_switcheroo: disabling VGA %d at resume\n", i);
+		vga_switchoff(&vgasr_priv.clients[i]);
+	}
+
+out:
+	mutex_unlock(&vgasr_mutex);
+
+	return 0;
+}
+
+static struct notifier_block vga_switcheroo_notifier_block = {
+	.notifier_call = vga_switcheroo_notify,
+};
+
+static int __init vga_switcheroo_pm_hack_init(void)
+{
+	int ret;
+
+	if (!resume_powercut)
+		return 0;
+
+	ret = register_pm_notifier(&vga_switcheroo_notifier_block);
+	if (ret)
+		pr_err("%s: failed to register pm notifier\n", __func__);
+
+	return ret;
+}
+
+static void __exit vga_switcheroo_pm_hack_exit(void)
+{
+	if (resume_powercut)
+		unregister_pm_notifier(&vga_switcheroo_notifier_block);
+}
+
+late_initcall(vga_switcheroo_pm_hack_init);
+module_exit(vga_switcheroo_pm_hack_exit);
+#endif
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops
  2012-04-28 20:45 ` [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops Alexander Tarasikov
@ 2012-04-28 21:10   ` Alan Cox
  2012-04-28 22:17     ` Alexander Tarasikov
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2012-04-28 21:10 UTC (permalink / raw)
  To: Alexander Tarasikov; +Cc: linux-kernel, airlied

> 	This patch adds an experimental module parameter that causes
> 	vga_switcheroo to disable all inactive VGA cards after a resume
> 	to save power and avoid lockups/GPU freezes. This has been tested
> 	on a Sony VAIO laptop with Intel HD3000 and Ati Radeon 6630M GPU.

The module parameter is probably the wrong long term option. Do you know
if the problem is general or specific to some laptops. If it's the latter
then it might also be worth implementing a DMI and/or PCI detection
routine to match the laptops you know are afflicted and automatically
enabled it.

Alan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops
  2012-04-28 21:10   ` Alan Cox
@ 2012-04-28 22:17     ` Alexander Tarasikov
  2012-05-06 17:36       ` Uwe Bonnes
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Tarasikov @ 2012-04-28 22:17 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel, airlied

2012/4/29 Alan Cox <alan@lxorguk.ukuu.org.uk>:
> The module parameter is probably the wrong long term option. Do you know
> if the problem is general or specific to some laptops. If it's the latter
> then it might also be worth implementing a DMI and/or PCI detection
> routine to match the laptops you know are afflicted and automatically
> enabled it.
> Alan

I agree that module parameter is not a good idea, but I have seen a
lot of reports
of the problem and no patches were proposed, so I tried to do what I could. It
could be a good temporary solution until we make sure it does not break
any configurations. I am unsure how muxless/muxed cards may differ in
behaviour.

I suspect that the problem is specific to all laptops with
intel+radeon combination.
So far I have found these reports of radeon eating battery

[2010] Acer TravelMate Timeline 8371
[2012] Hp Envy 14 https://bugs.launchpad.net/ubuntu/+source/linux/+bug/909337
[2012] Thinkpad T400 https://bbs.archlinux.org/viewtopic.php?id=133329
[2012] Sony Vaio SE15 (VPCSE1v9E)
http://blog.ejbca.org/2012/02/ubuntu-gnulinux-1204-precise-on-sony.html

The current solution involves doing an ON-OFF cycle and radeon hangs
on echoing ON to switcheroo for a minute. This if, of course, very
annoying and is not ready for daily usage.
I and other users get the messages like

[drm:atom_op_jump] *ERROR* atombios stuck in loop for more than 1sec aborting
[drm:atom_execute_table_locked] *ERROR* atombios stuck executing CAE2
(len 62, WS 0, PS 0) @ 0xCAFE

A possible solution might be to simply remove the "if
(vgasr_priv.clients[i].pwr_state == VGA_SWITCHEROO_ON)"
check. However, that would still mean some userland app will have to echo "OFF"
on each resume. I find this behaviour unacceptable because I believe power
management must be done by kernel and things that are likely to cause hardware
damage (i.e., overheating) must be kept off userland. Overall, the
drivers only do this enable-disable stuff
during probe/remove, but when suspending, we're handing the control
over to the proprietary BIOS/bootloader
and the hardware is left in the undeterminate state. It might be a
good idea to force power reinit on suspend/resume.

Therefore I think we should get people having problems (and those not
having problems) to test the patch
to see if it fixes power drain and does not break other machines
(i.e., whether we can enable aggressive
powersaving for everyone). Maybe it's better to notify downstream
(ubuntu, fedora) but I guess everyone
reads LKML.

-- 
Regards, Alexander

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops
  2012-04-28 22:17     ` Alexander Tarasikov
@ 2012-05-06 17:36       ` Uwe Bonnes
  2012-07-03  1:55         ` Valery Pipin
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Bonnes @ 2012-05-06 17:36 UTC (permalink / raw)
  To: linux-kernel

Alexander Tarasikov <alexander.tarasikov@gmail.com> wrote:
> 2012/4/29 Alan Cox <alan@lxorguk.ukuu.org.uk>:
> > The module parameter is probably the wrong long term option. Do you know
> > if the problem is general or specific to some laptops. If it's the latter
> > then it might also be worth implementing a DMI and/or PCI detection
> > routine to match the laptops you know are afflicted and automatically
> > enabled it.
> > Alan

> I agree that module parameter is not a good idea, but I have seen a
> lot of reports of the problem and no patches were proposed, 
> so I tried to do what I could. It
> could be a good temporary solution until we make sure it does not break
> any configurations. I am unsure how muxless/muxed cards may differ in
> behaviour.

> I suspect that the problem is specific to all laptops with
> intel+radeon combination.

Intel+Nvidia combination seems to be affected too!

> So far I have found these reports of radeon eating battery

> [2010] Acer TravelMate Timeline 8371
> [2012] Hp Envy 14 https://bugs.launchpad.net/ubuntu/+source/linux/+bug/909337
> [2012] Thinkpad T400 https://bbs.archlinux.org/viewtopic.php?id=133329
> [2012] Sony Vaio SE15 (VPCSE1v9E)
> http://blog.ejbca.org/2012/02/ubuntu-gnulinux-1204-precise-on-sony.html

I can confirm the problem with an intel+nvidia combination, on a Thinkpad T520:
> lspci |grep -i VGA
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core \
Processor Family Integrated Graphics Controller (rev 09)
01:00.0 VGA compatible controller: nVidia Corporation GF119 [Quadro NVS 4200M] (rev ff)

I suspend with "DIS"cret graphics off. Resuming comes up with about 5 Watt
more power drain compared before suspend. Switching "DIS" needs another 5
Watt. Switching "DIS" off again brings me back to the power drain level
before suspend.

I vote for Alexander proposal!

Bye

-- 
Uwe Bonnes                bon@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops
  2012-05-06 17:36       ` Uwe Bonnes
@ 2012-07-03  1:55         ` Valery Pipin
  0 siblings, 0 replies; 6+ messages in thread
From: Valery Pipin @ 2012-07-03  1:55 UTC (permalink / raw)
  To: linux-kernel

I vote  for this patch. It solves my problems with suspend/hibernate/resume on
ENVY 14 1210NR that has itegrated card by Intel and discrete  from AMD(redwood).
Using on Mageia 2 kernel 3.4.2

Valery





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-07-03  2:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-28 20:45 [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain Alexander Tarasikov
2012-04-28 20:45 ` [PATCH] drivers:gpu:vga_switcheroo: Work around dramatic power drain in laptops Alexander Tarasikov
2012-04-28 21:10   ` Alan Cox
2012-04-28 22:17     ` Alexander Tarasikov
2012-05-06 17:36       ` Uwe Bonnes
2012-07-03  1:55         ` Valery Pipin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.