* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 16:24 ` Linus Torvalds
@ 2014-07-14 16:59 ` Linus Torvalds
2014-07-14 20:45 ` Bjørn Mork
2014-07-14 18:01 ` Rafael J. Wysocki
2014-07-15 7:00 ` Hans de Goede
2 siblings, 1 reply; 13+ messages in thread
From: Linus Torvalds @ 2014-07-14 16:59 UTC (permalink / raw)
To: Hans de Goede
Cc: Bjørn Mork, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
[-- Attachment #1: Type: text/plain, Size: 1772 bytes --]
On Mon, Jul 14, 2014 at 9:24 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Bjørn, what's your setup? Is this perhaps solvable some other way?
For example, I wonder if we could fix the "dual brightness change"
problem automatically by making a new option for
'brightness_switch_enabled'.
Currently, there are two cases:
- enabled: do the actual brightness change _and_ send the input
report keycode for a brightness change
- disabled: just send the keycode, excpecting the desktop software to
handle it.
and maybe we could have a new case (and make *that* the default):
- delayed: send the keycode, and set up a delayed timer (say, one
tenth of a second) to do the actual brightness change. And if a
brightness change from user mode comes in during that delay, we cancel
the kernel-induced pending change.
Something like the very hacky attached patch that is COMPLETELY UNTESTED.
My point being that I think we can get this right *without* some
stupid "user has to specify the behavior of their desktop application
and ACPI implementation" crap. Especially since it's entirely possible
that there are different behaviors for the same machine (ie the user
session may act differently from the login screen, which will act
differently from the text virtual terminal).
I really don't expect my patch to work as-is, it is really meant more
as an illustration of an approach that might work. There may well be
many other complications (ie how does this interact with the whole
"use_native_backlight" thing and user space possibly accessing *other*
backlight controls). But I have the feeling that this should be
solvable without breaking old setups or causing problems on newer
ones.
Linus
[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 3393 bytes --]
drivers/acpi/video.c | 42 ++++++++++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 071c1dfb93f3..9c4afface8e7 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -68,8 +68,8 @@ MODULE_AUTHOR("Bruno Ducrot");
MODULE_DESCRIPTION("ACPI Video Driver");
MODULE_LICENSE("GPL");
-static bool brightness_switch_enabled;
-module_param(brightness_switch_enabled, bool, 0644);
+static int brightness_switch_enabled = -1;
+module_param(brightness_switch_enabled, int, 0644);
/*
* By default, we don't allow duplicate ACPI video bus devices
@@ -270,11 +270,21 @@ static int acpi_video_get_brightness(struct backlight_device *bd)
return 0;
}
+static u32 acpi_brightness_event;
+static struct acpi_video_device *acpi_brightness_device;
+static void acpi_video_set_brighness_delayed(struct work_struct *work)
+{
+ acpi_video_switch_brightness(acpi_brightness_device, acpi_brightness_event);
+}
+
+static DECLARE_DELAYED_WORK(acpi_brightness_work, acpi_video_set_brighness_delayed);
+
static int acpi_video_set_brightness(struct backlight_device *bd)
{
int request_level = bd->props.brightness + 2;
struct acpi_video_device *vd = bl_get_data(bd);
+ cancel_delayed_work(&acpi_brightness_work);
return acpi_video_device_lcd_set_level(vd,
vd->brightness->levels[request_level]);
}
@@ -1601,6 +1611,19 @@ static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
return;
}
+static void brightness_switch_event(struct acpi_video_device *video_device, u32 event)
+{
+ if (!brightness_switch_enabled)
+ return;
+ if (brightness_switch_enabled > 0) {
+ acpi_video_switch_brightness(video_device, event);
+ return;
+ }
+ acpi_brightness_device = video_device;
+ acpi_brightness_event = event;
+ schedule_delayed_work(&acpi_brightness_work, HZ/10);
+}
+
static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
{
struct acpi_video_device *video_device = data;
@@ -1618,28 +1641,23 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
switch (event) {
case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
- if (brightness_switch_enabled)
- acpi_video_switch_brightness(video_device, event);
+ brightness_switch_event(video_device, event);
keycode = KEY_BRIGHTNESS_CYCLE;
break;
case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
- if (brightness_switch_enabled)
- acpi_video_switch_brightness(video_device, event);
+ brightness_switch_event(video_device, event);
keycode = KEY_BRIGHTNESSUP;
break;
case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
- if (brightness_switch_enabled)
- acpi_video_switch_brightness(video_device, event);
+ brightness_switch_event(video_device, event);
keycode = KEY_BRIGHTNESSDOWN;
break;
case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */
- if (brightness_switch_enabled)
- acpi_video_switch_brightness(video_device, event);
+ brightness_switch_event(video_device, event);
keycode = KEY_BRIGHTNESS_ZERO;
break;
case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
- if (brightness_switch_enabled)
- acpi_video_switch_brightness(video_device, event);
+ brightness_switch_event(video_device, event);
keycode = KEY_DISPLAY_OFF;
break;
default:
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 16:59 ` Linus Torvalds
@ 2014-07-14 20:45 ` Bjørn Mork
2014-07-14 20:49 ` Linus Torvalds
0 siblings, 1 reply; 13+ messages in thread
From: Bjørn Mork @ 2014-07-14 20:45 UTC (permalink / raw)
To: Linus Torvalds
Cc: Hans de Goede, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Mon, Jul 14, 2014 at 9:24 AM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
>>
>> Bjørn, what's your setup? Is this perhaps solvable some other way?
Just to answer that: I don't use any particular desktop environment. I
have acpid running to take care of the most basic power management
stuff. My X session is simply WindowMaker (sic) running directly from
lightdm. No session management or fancy policy daemons. So I don't have
any daemon which would react on the brightness key codes.
Now, it's not that I would mind adding a daemon to handle stuff like
brightness control. I reported this as a bug because I was a bit
surprised by the existing behaviour breaking like that, and I thought
that other users might be as surprised as me. Some maybe even without
the ability to track down the change and the setting that would restore
the old behaviour.
> For example, I wonder if we could fix the "dual brightness change"
> problem automatically by making a new option for
> 'brightness_switch_enabled'.
>
> Currently, there are two cases:
>
> - enabled: do the actual brightness change _and_ send the input
> report keycode for a brightness change
>
> - disabled: just send the keycode, excpecting the desktop software to
> handle it.
>
> and maybe we could have a new case (and make *that* the default):
>
> - delayed: send the keycode, and set up a delayed timer (say, one
> tenth of a second) to do the actual brightness change. And if a
> brightness change from user mode comes in during that delay, we cancel
> the kernel-induced pending change.
That sounds like a good solution to me FWIW.
Bjørn
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 20:45 ` Bjørn Mork
@ 2014-07-14 20:49 ` Linus Torvalds
2014-07-14 21:46 ` Bjørn Mork
0 siblings, 1 reply; 13+ messages in thread
From: Linus Torvalds @ 2014-07-14 20:49 UTC (permalink / raw)
To: Bjørn Mork
Cc: Hans de Goede, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
On Mon, Jul 14, 2014 at 1:45 PM, Bjørn Mork <bjorn@mork.no> wrote:
>> brightness change from user mode comes in during that delay, we cancel
>> the kernel-induced pending change.
>
> That sounds like a good solution to me FWIW.
Try the patch. It *might* work. I'm not saying it will, but it seemed
to at least compile for me.
Linus
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 20:49 ` Linus Torvalds
@ 2014-07-14 21:46 ` Bjørn Mork
2014-07-14 22:19 ` Linus Torvalds
0 siblings, 1 reply; 13+ messages in thread
From: Bjørn Mork @ 2014-07-14 21:46 UTC (permalink / raw)
To: Linus Torvalds
Cc: Hans de Goede, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Mon, Jul 14, 2014 at 1:45 PM, Bjørn Mork <bjorn@mork.no> wrote:
>>> brightness change from user mode comes in during that delay, we cancel
>>> the kernel-induced pending change.
>>
>> That sounds like a good solution to me FWIW.
>
> Try the patch. It *might* work. I'm not saying it will, but it seemed
> to at least compile for me.
Yes, the patch works as advertised for me. Thanks.
But this will break existing configs:
> --- a/drivers/acpi/video.c
> +++ b/drivers/acpi/video.c
> @@ -68,8 +68,8 @@ MODULE_AUTHOR("Bruno Ducrot");
> MODULE_DESCRIPTION("ACPI Video Driver");
> MODULE_LICENSE("GPL");
>
> -static bool brightness_switch_enabled;
> -module_param(brightness_switch_enabled, bool, 0644);
> +static int brightness_switch_enabled = -1;
> +module_param(brightness_switch_enabled, int, 0644);
>
> /*
> * By default, we don't allow duplicate ACPI video bus devices
Any setup using e.g "options video brightness_switch_enabled=Y" will
barf on this, won't they?
Bjørn
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 21:46 ` Bjørn Mork
@ 2014-07-14 22:19 ` Linus Torvalds
0 siblings, 0 replies; 13+ messages in thread
From: Linus Torvalds @ 2014-07-14 22:19 UTC (permalink / raw)
To: Bjørn Mork
Cc: Hans de Goede, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
On Mon, Jul 14, 2014 at 2:46 PM, Bjørn Mork <bjorn@mork.no> wrote:
>
> Yes, the patch works as advertised for me. Thanks.
Ok, so it should probably be tested by people who see the "move by
two" problem too.
> But this will break existing configs:
>
> Any setup using e.g "options video brightness_switch_enabled=Y" will
> barf on this, won't they?
Hmm. Probably. That said, that kind of breakage I think we might want
to live with, especially if it actually ends up causing them to test
the new default (which might just work for them).
But regardless, let's make sure that patch (or something _like_ it)
works for people who saw the reverse problem for you. Then the exact
syntax of whatever module parameter (if any) can be a separate
discussion.
Anyway, for 3.16 I think we should just do what we used to do (ie the
revert that Rafael apparently already has queued up), so this isn't
necessarily critical.
Linus
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 16:24 ` Linus Torvalds
2014-07-14 16:59 ` Linus Torvalds
@ 2014-07-14 18:01 ` Rafael J. Wysocki
2014-07-15 7:00 ` Hans de Goede
2 siblings, 0 replies; 13+ messages in thread
From: Rafael J. Wysocki @ 2014-07-14 18:01 UTC (permalink / raw)
To: Linus Torvalds
Cc: Hans de Goede, Bjørn Mork, Linux Kernel Mailing List,
Linux ACPI, Rafael J. Wysocki
On Monday, July 14, 2014 09:24:16 AM Linus Torvalds wrote:
> On Mon, Jul 14, 2014 at 6:14 AM, Hans de Goede <hdegoede@redhat.com> wrote:
> >
> > This *not* a regression, it is an intended behavior change [..]
>
> That counts as a regression.
>
> If things used to work, and they don't work, it's a regression. If
> it's intentional, that just makes it worse.
>
> > Yes this may break existing configurations for some users, most likely
> > users running some custom setup, who thus should be able to fix things
> > by adding one more customization to there setup.
>
> .. and apparently this whole paragraph is completely bogus. It *does*
> break things, and for normal people. That's what the bug report is all
> about. So don't waffle about it.
>
> Bjørn, what's your setup? Is this perhaps solvable some other way?
>
> > TL;DR: This change really is for the better and is here to stay.
>
> Wrong. We don't break existing setups, and your attitude needs fixing.
>
> Rafael, please get it reverted, or I will have to revert it.
I've queued up a revert already. I'll include it into my next pull
request later this week.
Rafael
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-14 16:24 ` Linus Torvalds
2014-07-14 16:59 ` Linus Torvalds
2014-07-14 18:01 ` Rafael J. Wysocki
@ 2014-07-15 7:00 ` Hans de Goede
2014-07-15 7:33 ` Bjørn Mork
2014-07-15 10:59 ` Hans de Goede
2 siblings, 2 replies; 13+ messages in thread
From: Hans de Goede @ 2014-07-15 7:00 UTC (permalink / raw)
To: Linus Torvalds
Cc: Bjørn Mork, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
Hi,
On 07/14/2014 06:24 PM, Linus Torvalds wrote:
> On Mon, Jul 14, 2014 at 6:14 AM, Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> This *not* a regression, it is an intended behavior change [..]
>
> That counts as a regression.
>
> If things used to work, and they don't work, it's a regression. If
> it's intentional, that just makes it worse.
The problem is that our previous default behavior turns out to be
wrong for many users.
So as answered later in the thread Bjørn is using a custom setup with
acpid and WindowMaker. So in order to keep his exotic (and very simple
to fix) setup working we are keeping thing broken on what are probably
a 100 thousand Linux installs or more.
>
>> Yes this may break existing configurations for some users, most likely
>> users running some custom setup, who thus should be able to fix things
>> by adding one more customization to there setup.
>
> .. and apparently this whole paragraph is completely bogus. It *does*
> break things, and for normal people.
It breaks things on exotic setups, running a non standard desktop
environment or no desktop environment at all. Note that this is
about laptops most people will be using one of gnome / kde / unity /
xfce on a desktop, and for all of these the old default behavior is
bad.
> That's what the bug report is all about. So don't waffle about it.
>
> Bjørn, what's your setup?
> Is this perhaps solvable some other way?
I see that further down the thread you've send a patch to fix
this by waiting sometime for userspace to react and if it does
not then do the change in the kernel as it used to be.
FWIW I don't think this is a good idea. This is inherently racy, so
we will still sometimes see the backlight taking 2 steps leading to
hard to debug problems.
It has made me think about doing something to keep both setups
like Bjørn's working, and get rid of the 2 steps problem. I think
adding an auto setting for brightness_switch_enabled and making that
the default is a good idea. But instead of using a timeout, I suggest
to make -1 / auto behave the same as 1 / on until userspace sets the
brightness. Once userspace has written to the brightness attribute
we start interpreting auto as 0 / off.
Rafael would you be willing to take a patch doing this ?
>> TL;DR: This change really is for the better and is here to stay.
>
> Wrong. We don't break existing setups, and your attitude needs fixing.
>
> Rafael, please get it reverted, or I will have to revert it. We have
> *long* had a rule that we don't break things "in order to improve
> things for others", and quite frankly, power management and ACPI in
> particular was exactly *why* that rule was introduced, because the
> whole "one step back, two steps forward" model does not work.
>
> The problem needs to be solved some other way, and developers need to
> f*cking stop with the "we can break peoples setups" mentality./
>
> Hans, seriously. You have the wrong mental model. Fix it.
Linus, normally I agree 101% with your no regressions policy. but I'm
also a big fan of the it just works philosophy. The problem here is
that when this switch got introduced a long time ago it got (in hindsight)
the wrong default. In order to make things just work it needs to get
fixed, but maybe we can come up with a solution to both have our cake
and eat it.
Regards,
Hans
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-15 7:00 ` Hans de Goede
@ 2014-07-15 7:33 ` Bjørn Mork
2014-07-15 10:59 ` Hans de Goede
1 sibling, 0 replies; 13+ messages in thread
From: Bjørn Mork @ 2014-07-15 7:33 UTC (permalink / raw)
To: Hans de Goede
Cc: Linus Torvalds, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
Hans de Goede <hdegoede@redhat.com> writes:
> It breaks things on exotic setups,
I find your attitude extremely arrogant. If you want to run a
non-exotic setup then you should definitely not consider Linux for your
desktop system...
I am trying to help you sort out a bug in code you have written, before
it hits a release. I do not really expect to receive a beer for this,
but maybe a little less of the "yes, I know there is a bug and I don't
give a damn" attitude.
Yes, I can of course fix *my* system, making your reported bug count go
from 1 to 0. Does that help you in any way? How does that make your
projected number of affected users change?
Bjørn
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BISECTED 3.16-rc REGREGRESSION] backlight control stopped working
2014-07-15 7:00 ` Hans de Goede
2014-07-15 7:33 ` Bjørn Mork
@ 2014-07-15 10:59 ` Hans de Goede
1 sibling, 0 replies; 13+ messages in thread
From: Hans de Goede @ 2014-07-15 10:59 UTC (permalink / raw)
To: Linus Torvalds
Cc: Bjørn Mork, Linux Kernel Mailing List, Linux ACPI,
Rafael J. Wysocki
Hi,
> On 07/14/2014 06:24 PM, Linus Torvalds wrote:
> Hans, seriously. You have the wrong mental model. Fix it.
> On 07/15/2014 Bjørn Mork wrote:
> I find your attitude extremely arrogant. If you want to run a
> non-exotic setup then you should definitely not consider Linux for your
> desktop system...
After stepping away from the keyboard and thinking about this for
a while I looked in the mirror and I saw someone who liked like
one of those developers who keeps taking away features to streamline
the user experience, and who does not care about your use-case because
it is not mainstream.
I've butted head with those kind of developers several times and
I really don't want to become like one of them. So you two are
right, and I apologize for my behavior.
So now lets go and fix this in way so that we can both have our
cake and eat it :)
On 07/15/2014 09:00 AM, Hans de Goede wrote:
<snip>
> I see that further down the thread you've send a patch to fix
> this by waiting sometime for userspace to react and if it does
> not then do the change in the kernel as it used to be.
>
> FWIW I don't think this is a good idea. This is inherently racy, so
> we will still sometimes see the backlight taking 2 steps leading to
> hard to debug problems.
>
> It has made me think about doing something to keep both setups
> like Bjørn's working, and get rid of the 2 steps problem. I think
> adding an auto setting for brightness_switch_enabled and making that
> the default is a good idea. But instead of using a timeout, I suggest
> to make -1 / auto behave the same as 1 / on until userspace sets the
> brightness. Once userspace has written to the brightness attribute
> we start interpreting auto as 0 / off.
Thinking more about this I can still think of several use cases which
will break with this change. So I believe that Linus' suggestion for
fixing this is probably the best solution and we will just have to
live with the race (if we hit the race we will behave as before and
take 2 steps).
After testing several laptops I've found one which exhibits the
2 step problem. For the record to reproduce this you need a laptop
with non intel gfx, as the xf86-video-intel driver caches the backlight
setting, and thus userspace does not see the kernel made changes
when it applies its own changes, so the backlight still gets stepped
twice, but the second step (done by userspace) just repeats the change
already done by the kernel.
Testing Linus' patch on that laptop unfortunately shows that it
does not fix the problem (while setting brightness_switch_enabled=0
does). I've already tried raising the delay to 250ms to no avail,
so I'm going to need to do some debugging on this. Besides that
the patch should be modified to not use globals as theoretically
there can be more then 1 acpi backlight device. Assuming I can get
the patch working (it should work in theory), I'll send a fixed
and cleaned-up version to Rafael for 3.17 .
Regards,
Hans
^ permalink raw reply [flat|nested] 13+ messages in thread