You are viewing airlied

airlied
airlied
:.:..:.

May 2014
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

airlied [userpic]
hybrid graphics on Linux

So someone thought it would be a good idea to make laptops with two graphics chips in them and switch betweem them to save power.

Now other OSes support this to varying degrees, I think XP + MacOSX require a logout cycle and Vista/Win7 can dynamically switch while running, while Linux basically falls over in a heap.

So I sat down today with a Lenovo W500 which has an Intel GM45 and AMD Radeon 3650 Mobility in it, and I wrote a patch to try and get closer to the XP/MacOSX level.

The result of one days straight hacking is at:
http://people.freedesktop.org/~airlied/vgaswitcheroo/

The patch is totally focused on the Lenovo W500, other switchers will need to add stuff to this codebase.

So what works?
Boot in switchable graphics - which boots with intel and radeon turned on
KMS drivers load for radeon and intel, radeon BIOS stored in start of VRAM (driver hacked to read it)
bind to both drivers + fbs for both.
mount debugfs - cat /sys/kernel/debug/vgaswitcheroo/switch
2
0 :0000:01:00.0
1+:0000:00:02.0
shows the 02.0 (intel) device is in charge of the MUX.
goto runlevel 5, play with X under the Intel driver, goto runlevel 3 kill X
at fbcon echo "0000:01:00.0" > /sys/kernel/debug/vgaswitcheroo/switch
barely glitches console and switches
goto runlevel 5, play with X under the ATI driver, goto runlevel 3 kill X
echo "0000:00:02.0" > /sys/kernel/debug/vgaswitcheroo/switch
goto runlevel 5, play with X under intel again.
wash and repeat.

What does it do?
So far its just switching the MUX using the ACPI method and remapping all the console to the other framebuffer device,
it also reset the bits that denotes which devices is the boot vga device which X uses to pick the primary GPU. This
means X doesn't need an xorg.conf to switch. (I think all those patches are in upstream X server).

What does it not do?
It doesn't powerdown the radeon when its not in use yet. I know the ACPI call to power it off/on, and since I have
the BIOS I should be able to repost it. So I'll try adding the callbacks into the KMS driver to do this soon.
It doesn't poewrdown the intel when its not in use yet. Not sure what I can do here, since there is no ACPI method to turn
it off. I think I can just D3 the GPU, and use the normal s/r paths to bring it back. Again requires more investigation.
The whole what ACPI + methods map to what device, how the mux ids match etc will probably all need to be stored in the DMI table.
Anything not a Lenovo W500 - probably not that hard to add other Intel/AMD variants to this, add DMI and mux switching method.
nouveau isn't hooked up - this could probably be done by some interested party - the driver hooks so far aren't very hard.
No idea about ATI/ATI or NV/NV ones either.

I'm really hoping interested community people can make this actually useful to them on other hw, I won't have permanent access to the W500 to keep this all tested in the future.

Can we do dynamic switch without restarting X?
No. X needs a lot of work, a lot more than the day it took to hack the kernel.

How do we go forward?
We probably need to add gdm support to move this forward. A logout button that is "Switch GPU", that gdm kills the X server,
then hits the switch port and starts a new X server. I'll try and talk to some gdm hackers over the next few days.
I'll try and push this into a git tree against Linus current, and we can add tested patches for other machines as they go in.
Also the DMI section is only imaginary of what I think others might need, we might have to rip it all out. Also I've no idea
if there are ACPI methods to query the switchable modes etc.

Comments
blog link

This blog has some info on switchable graphics:

http://linux-hybrid-graphics.blogspot.com/

But i don't understand whole idea: who is controlling output switch - ACPI? videocard itself (one of them)? Does ATI/ATI case need some sort of crossfire setup (loading images from one card vidmem into another card vidmem over PCIe?)

Re: blog link

its different everwhere apparantly.

ACPI just talks to hardware, its most likely hardware not connected to either card, but an extra piece. But we can't know what it does, so we just call the ACPI methods. At least on this laptop the ATPX method seems to be able to do 4 things, turn ATI gpu on/off + switch output mux + something with i2c , vga detect maybe.

ATI/ATI might need crossfire I'd need someone to debug.

Re: blog link

For the Intel/ATI systems, it looks like there's always an ATPX method under the discrete GPU. Nvidia handle it through a _DSM method, regardless of whether it's Nvidia/Intel or Nvidia/Nvidia. The main thing is avoiding hardcoded paths, which requires some of the code you've currently got in the vga code to be in the gpu-specific drm instead.

Fab!

Hey well done on working on this

I imagine the X support will eventally develop into multi gpu support too

Would it be better to expose all connectors to X no matter what the card and let the kernel decide which device to use

I think with gallium the origional idea was to have one modesetting X driver and use the Xorg statetracker, is that right or have I picked things up wrongly?

Thanks again for the hard work

Mike

Re: Fab!

we don't expose connectors to X, the kernel just exposes interfaces to the X driver which exposes things.

There is not ever going to be one modesetting X driver that idea was never sane.
someone just hacked one together for a demo, the Xorg state tracker will still build per-hardware drivers.

In theory you can set X up to use both cards at once and just not see anything from the second card. I do wonder if maybe you could run the DisplayPort from the second card alongside the LVDS from the main one, that would be lols.

(Anonymous)
No good deed goes unpunished

Hybrid Graphics Comes To Linux In Crude Form (http://www.phoronix.com/scan.php?page=news_item&px=Nzk0Mw) (Phoronix)

(Anonymous)

How does Vista/7 solve this? An API for custom drivers that every OEM has to write themselves?

They ship proxy drivers which wrap the two gpu drivers afaik

(Anonymous)
switching without the hastle to the user

While I understand one would have to kill the X server on the one GPU and start an X server on the other when switching, but could one not make that more fluid an experience for the user by using xmove to persist their X windows? Just something I've read about but have no clue how it actually works.

(Anonymous)

Jon Pritchard:

I'm very interested in this as I own a T400 with Intel and AMD 3470 graphics.

I see dual-GPUs in notebooks becoming more ubiquitous and would love to see a situation where we can switch at runtime and powerdown the GPU not being used.

Thanks for your work.

(Anonymous)
What are the acpi calls to disable the radeon.

I'm having heat issues on an ATI/ATI dm3z and would like to disable the second card. I can live with any suspend issues / hacks for now.


Don't like being stuck on windows while travelling.

Re: What are the acpi calls to disable the radeon.

in theory this patch + KMS driver + echo OFF should turn if off.

you just call the ATPX method, the lenovo_acpi hack already does this.