Matthew Garrett: Linux backlight control
Backlight control is one of those things that you'd think would be simple, but ha ha this is computing so of course it's an utter disaster and everything is a huge mess. There's three main classes of backlight control in the x86 world, all of which have drawbacks:- ACPI specifies a mechanism for backlight control, and the majority of modern machines implement it. It has the advantage that the brightness query interface is generally aware of anything else in the system which may have changed the brightness, so it's unlikely to get out of sync with reality if the platform tries to do something odd like change the backlight itself in response to an ambient light sensor or some other event. The main drawback is that there's typically a fairly small number of available backlight values, usually somewhere between 8 and 20.
- A platform-specific mechanism. This used to be more popular before the ACPI backlight interface took off, but some machines still require it. The idea here is that there's some sort of platform-specific way of requesting a backlight change, ranging from a vendor-specific ACPI method through to triggering system management calls by magic register writes. These methods usually (but not always) keep in sync with other firmware changes, but rarely provide any more brightness steps than the standard ACPI interface.
- Many mobile GPUs have backlight control registers built in. These usually give you a range of several thousand possible values, but using them will almost certainly leave you out of sync with reality if the firmware touches them at all. To make things worse, the firmware control of the backlight may occur after the gpu - so you could end up with two different controls that both need to be full in order to get maximum brightness. The worst case scenario is that the firmware gets confused by the values not being what it programmed and you end up with a hung machine.
Right now, if there's an ACPI backlight interface then that's usually the only thing we'll show you. We can do that because we can identify if there's an ACPI backlight interface when we parse the ACPI tables at the start of booting, and that information can be registered before we start setting up any other backlights. The problem comes when we have no ACPI backlight interface. We don't have any idea whether there's a platform mechanism until a platform driver loads, which could be at any time. As a result, we've been reluctant to expose GPU-level backlight control because doing so would often give you two separate backlight controls and no indication as to which should be used. Userspace doesn't really have a way to make that decision either, so everyone ends up unhappy.
This is especially problematic with some machines which provide no ACPI or known platform control (or, in the case of some Samsungs, only provide platform control if you have a special Linux BIOS that Samsung won't give you) but can control the backlight via the gpu. Right now you get nothing, because giving you something would potentially break other systems and the needs of the many etc. Sorry! But this is obviously problematic in the long term, especially because multi-GPU machines tend to have multiple ACPI backlight interfaces, so I've been working on a better approach.
When a backlight device is registered, it appears under /sys/class/backlight. If it's an ACPI device it has a symlink pointing to some random ACPI device. If it's a platform device it's pointing at something like "dell-laptop" which is approximately unhelpful when it comes to figuring out what it controls. If it's a GPU-level device then it probably points at the PCI device, which is helpful except in the case where you have multiple backlight controls on a single GPU. So, by and large, you have no good way to identify which backlight control is preferable unless you keep a huge list of all possible backlights along with some scoring.
The first thing I've added to improve this is a "type" attribute. This tells you whether a given backlight is firmware-level (like ACPI), platform-level (like the various laptop drivers) or performs raw register writes (like a GPU driver). That lets userspace decide which interface is preferable. It'll typically be the ACPI interface, because that's the most likely to keep synchronisation and so avoid bizarre brightness bugs. The next thing has been to start fixing up the parent links. There's nothing we can do for the platform level devices, but the ACPI drivers could at least point at PCI devices rather than into ACPI space. That means that multi-GPU systems can now identify which interface to use based on the currently active GPU. Finally, I've started pointing the GPU-level backlight controls at the specific output rather than merely at the PCI device. This probably makes little difference for laptops as such, but once we start exposing backlight control for monitors that support ddcci it'll make things much easier as we'll know which backlight control corresponds to which monitor.
I've then written a small library that accepts information about the output and picks the "best" backlight for the device. It's obviously based on a pile of heuristics and there's a couple of bits of API that I suspect need to be nailed down yet, but it means that this code only needs to be written once. It's then simple to glue this into X drivers, which means that they can expose a "Backlight" xrandr property on each relevant display. That means that backlight control is then handled at the session level with the X server acting as the privileged agent, which simplifies a bunch of things and means we can finally let hal die entirely. Long-term this means we'll have unified backlight control for all of your displays, which is a wonderful thing.
Summary: We kind of suck right now, but there's a reasonably clear path to getting better.
This took a bit of searching, so it's here for reference. I'm sure it'll catch out people who upgrade from Lenny to Squeeze as the initial presentation can be deeply mysterious and frustrating.
PS This post also gives me a chance to comment
on a so called
A long time ago, when I was first introduced to email, I was using the
Mail program from Unix. I quickly converted to Elm, then Mutt, which
were both better in terms of interface. Then I found out about Gnus,
and I wouldn't dream of letting it go now. However, Gnus has started
showing its age several times, and several times have I needed to
upgrade the way I was using it: first because I needed to sort and
split email, then because I took the sorting out of Gnus and into
Procmail for more advanced filtering (including spam filtering), then
because I switched to storing the emails on an IMAP server so I could
read them remotely from several computers. My setup as of a few days
ago was functional, but since I have grown over time to splitting
emails into several hundred folders, checking for new messages was
becoming more and more boring.
So it's time to jump in with all the cool kids and switch to a modern
solution: still Gnus of course, but with Dovecot, OfflineIMAP for
synchronisation, and let's add email searches into the mix while we're
at it. My web searches didn't turn up a simple step-by-step HOWTO,
but I assembled bits from different places, and here's my attempt at
documenting my new setup.
Goals
GSoC 2010 is over for some time and I should write some summary how students
projects ended up. The very short summary is that all five students were
successful and their work got merged. Follows description of the project in no
particular order.
Thanks to Martynas Mickevicius you can now get charts out of various parts of
phpMyAdmin. They are used on server status pages or you can get query results in
form of several charts. It seems to work pretty well at least what I've tried
so far.
Ankit Gupta was working on Visual Query Builder for phpMyAdmin. Unfortunately
this is only project which is not yet merged to master branch, mostly because
some UI things were not yet finished. But hopefully it will be merged soon.
Adnan Mughal was converting our schema export feature from PDF to support
multiple formats. You can now get the schema as SVG, DIA or even Visio
formats, some of them will require a little bit of tuning still, because the
scaling is not perfect.
Ninad Pundalik did a lot of work on AJAXifying phpMyAdmin. His changes touched
quite a lot of places and there are still some rough edges (as you can see in our
bug tracker), but this is definitely welcome improvement and I hope it will
get stable soon.
Piotr Przybylski basically continued in his effort two years ago when he had
reimplemented setup script and now he had focused on user configuration. It
can be stored in session, browser local storage (HTML 5 feature) or in
separate table in phpMyAdmin configuration storage (that's new name for
pmadb). This is something what people were requesting for very long time and
I'm happy we can finally bring this feature.
And last but not least is Lorikeet Lee, who spend lot of time on tuning user
interface of phpMyAdmin. The most visible changes are on export and import
pages, which now should be less scaring for new users, but there are other
changes in lot of other places, for example the main page.
Generally it was a great summer and I hope we will be so successful also next
year.
PS: You can try all these features on
Italian
Like
End of the second day in the off-grid house. Three things strike me about
being here: quiet, rhythm, and awareness.
In the city, I am constantly annoyed by noise. Here, there's a empty,
echoing feeling to the quiet. It's not lack of noise exactly -- I can hear
cicadas and birds right now -- but it's still quiet. At first I wanted to
fill it, but now I can feel my hearing instead expanding outward. Catching
a faint engine noise, or a dog barking in the distance.
Here there's a rhythm to the day driven by the sun. Get up, connect the
batteries to the solar panels. (Only necessary because the charge
controller is broken.) Check and record the battery levels, make sure the
panels are producing well. Think about adjusting them at solar noon. Check
the cooler to see how the ice is holding out. Do weekly chores: Refilling
the kerosine lanterns and replacing the rock salt used to control the
humidity, which is the downside to a earth-sheltered house that stays 70
degrees cool on a 90 degree day. In the evening, watch the sun go down,
disconnect the solar panels, record battery levels, and light lanterns.
That's the shape of the day.
Besides being aware of distant sounds and time time of day, being here
brings to the fore awareness of consumables. Until I get a fridge sorted
out, I have a cooler full of ice that I have to monitor. There's propane
for the stove, and kerosine for the lanterns. And of course always the state
of the batteries. So far, the first battery bank seems likely to last longer
than the ice. I'll know better tomorrow.
Unfortunatly I burned out the 5v power suppzly I was using to run my NSLU2
in a wiring mishap, so I have to run that on an inverter for now, and the
batteries, though not low, can barely power both the inverter and my
laptop. This has made staying online tricky. But I'm finding dialup
psurpisingly tolerable, and it helps to generally slow down, too. Despite
all the above, I got about as much real work done today as I normally
would.
A few days ago I talked about
After a bit of work, I got the sheeva plug working the way I wanted it to. First of all, I grabbed a spare 1G USB flash disk I had laying around and installed Debian squeeze to it by following tbm s instructions here:
The
I started to give 
After