2010-04-09 12:56:23

by Jiri Kosina

[permalink] [raw]
Subject: [PATCH] lis3lv02d: provide means to disable polled input interface

lis3lv02d driver creates emulated joystick interface for events reported
by the sensor.
Because of HW, this has to be implemented as polled input device, with
20Hz frequency.

This is reported to create 20% CPU usage increase (and proportionaly higher
power consumption) just for the ipolldevd kernel thread (which is used
to read the sensor).

As most users probably only use the freefall functionality of the driver
and not the joystick interface, provide means for disabling the registration
of joystick device altogether via module parameter.
(I'd rather make it default to 0, but this will break backwards compatibility).

Signed-off-by: Jiri Kosina <[email protected]>

---
drivers/hwmon/lis3lv02d.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index b2f2277..bfbc02c 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -41,6 +41,9 @@

/* joystick device poll interval in milliseconds */
#define MDPS_POLL_INTERVAL 50
+static int enable_joystick = 1;
+module_param_named(joystick, enable_joystick, int, 0400);
+MODULE_PARM_DESC(joystick, "Enable joystick emulation (0 = disable, 1 = enable). Default: 1");
/*
* The sensor can also generate interrupts (DRDY) but it's pretty pointless
* because they are generated even if the data do not change. So it's better
@@ -434,14 +437,13 @@ EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);

void lis3lv02d_joystick_disable(void)
{
- if (!lis3_dev.idev)
- return;
-
if (lis3_dev.irq)
misc_deregister(&lis3lv02d_misc_device);
- input_unregister_polled_device(lis3_dev.idev);
- input_free_polled_device(lis3_dev.idev);
- lis3_dev.idev = NULL;
+ if (lis3_dev.idev) {
+ input_unregister_polled_device(lis3_dev.idev);
+ input_free_polled_device(lis3_dev.idev);
+ lis3_dev.idev = NULL;
+ }
}
EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);

@@ -559,7 +561,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
lis3lv02d_add_fs(dev);
lis3lv02d_poweron(dev);

- if (lis3lv02d_joystick_enable())
+ if (enable_joystick && lis3lv02d_joystick_enable())
printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n");

/* passing in platform specific data is purely optional and only


2010-04-09 13:29:58

by Éric Piel

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

On 09/04/10 14:56, Jiri Kosina wrote:
> lis3lv02d driver creates emulated joystick interface for events reported
> by the sensor.
> Because of HW, this has to be implemented as polled input device, with
> 20Hz frequency.
>
> This is reported to create 20% CPU usage increase (and proportionaly higher
> power consumption) just for the ipolldevd kernel thread (which is used
> to read the sensor).
>
> As most users probably only use the freefall functionality of the driver
> and not the joystick interface, provide means for disabling the registration
> of joystick device altogether via module parameter.
> (I'd rather make it default to 0, but this will break backwards compatibility).
Are you saying there is a 20% CPU usage even when the joystick interface
is not open? This should not happen (and this is not happening on my
laptop). The polling should happen only when a userspace app opens the
joystick interface (like running neverball).

So I'd tend to think it's more due to a misconfiguration of the system
(like xserver using the joystick interface as a pointer device) or it's
a bug in the way we set up the polling. Could you investigate and let me
know?

Cheers,
Eric

2010-04-09 13:33:09

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

On Fri, 9 Apr 2010, ?ric Piel wrote:

> > This is reported to create 20% CPU usage increase (and proportionaly higher
> > power consumption) just for the ipolldevd kernel thread (which is used
> > to read the sensor).
> >
> > As most users probably only use the freefall functionality of the driver
> > and not the joystick interface, provide means for disabling the registration
> > of joystick device altogether via module parameter.
> > (I'd rather make it default to 0, but this will break backwards compatibility).
> Are you saying there is a 20% CPU usage even when the joystick interface
> is not open? This should not happen (and this is not happening on my
> laptop). The polling should happen only when a userspace app opens the
> joystick interface (like running neverball).
>
> So I'd tend to think it's more due to a misconfiguration of the system
> (like xserver using the joystick interface as a pointer device) or it's
> a bug in the way we set up the polling. Could you investigate and let me
> know?

Marcin originally reported this to me.

Marcin, could you please check 'lsof' output to see whether the joystick
interface has been open by some application?

Thanks,

--
Jiri Kosina
SUSE Labs, Novell Inc.

2010-04-09 18:11:15

by Jean Delvare

[permalink] [raw]
Subject: Re: [lm-sensors] [PATCH] lis3lv02d: provide means to disable polled input interface

On Fri, 9 Apr 2010 15:32:59 +0200 (CEST), Jiri Kosina wrote:
> On Fri, 9 Apr 2010, Éric Piel wrote:
>
> > > This is reported to create 20% CPU usage increase (and proportionaly higher
> > > power consumption) just for the ipolldevd kernel thread (which is used
> > > to read the sensor).
> > >
> > > As most users probably only use the freefall functionality of the driver
> > > and not the joystick interface, provide means for disabling the registration
> > > of joystick device altogether via module parameter.
> > > (I'd rather make it default to 0, but this will break backwards compatibility).
> > Are you saying there is a 20% CPU usage even when the joystick interface
> > is not open? This should not happen (and this is not happening on my
> > laptop). The polling should happen only when a userspace app opens the
> > joystick interface (like running neverball).
> >
> > So I'd tend to think it's more due to a misconfiguration of the system
> > (like xserver using the joystick interface as a pointer device) or it's
> > a bug in the way we set up the polling. Could you investigate and let me
> > know?
>
> Marcin originally reported this to me.
>
> Marcin, could you please check 'lsof' output to see whether the joystick
> interface has been open by some application?

I would randomly blame hal. It keeps my IR remote control device opened
all the time and I have no idea why.

--
Jean Delvare

2010-04-09 21:41:54

by Frans Pop

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

?ric Piel wrote:
> Are you saying there is a 20% CPU usage even when the joystick interface
> is not open? This should not happen (and this is not happening on my
> laptop).

I've also never seen this problem on my HP 2510p.

2010-04-16 11:41:55

by Marcin Derlukiewicz

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

Dnia 09-04-2010 o 15:32:59 Jiri Kosina <[email protected]> napisał(a):

> On Fri, 9 Apr 2010, Éric Piel wrote:
>
>> > This is reported to create 20% CPU usage increase (and proportionaly
>> higher
>> > power consumption) just for the ipolldevd kernel thread (which is used
>> > to read the sensor).
>> >
>> > As most users probably only use the freefall functionality of the
>> driver
>> > and not the joystick interface, provide means for disabling the
>> registration
>> > of joystick device altogether via module parameter.
>> > (I'd rather make it default to 0, but this will break backwards
>> compatibility).
>> Are you saying there is a 20% CPU usage even when the joystick interface
>> is not open? This should not happen (and this is not happening on my
>> laptop). The polling should happen only when a userspace app opens the
>> joystick interface (like running neverball).
>>
>> So I'd tend to think it's more due to a misconfiguration of the system
>> (like xserver using the joystick interface as a pointer device) or it's
>> a bug in the way we set up the polling. Could you investigate and let me
>> know?
>
> Marcin originally reported this to me.
>
> Marcin, could you please check 'lsof' output to see whether the joystick
> interface has been open by some application?
>
> Thanks,
>

sorry for the delay, had a crunch time

here is the link for this lsof:
https://bugzilla.novell.com/attachment.cgi?id=354953


Best regards,
Marcin.

2010-04-16 12:01:38

by Samu Onkalo

[permalink] [raw]
Subject: RE: [PATCH] lis3lv02d: provide means to disable polled input interface



>-----Original Message-----
>From: ext Marcin Derlukiewicz [mailto:[email protected]]
>Sent: 16 April, 2010 14:42
>To: Jiri Kosina; Éric Piel
>Cc: Andrew Morton; Onkalo Samu.P (Nokia-D/Tampere); Pavel Machek; lm-
>[email protected]; [email protected]
>Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input
>interface
>
>Dnia 09-04-2010 o 15:32:59 Jiri Kosina <[email protected]> napisał(a):
>
>> On Fri, 9 Apr 2010, Éric Piel wrote:
>>
>>> > This is reported to create 20% CPU usage increase (and
>proportionaly
>>> higher
>>> > power consumption) just for the ipolldevd kernel thread (which is
>used
>>> > to read the sensor).
>>> >
>>> > As most users probably only use the freefall functionality of the
>>> driver
>>> > and not the joystick interface, provide means for disabling the
>>> registration
>>> > of joystick device altogether via module parameter.
>>> > (I'd rather make it default to 0, but this will break backwards
>>> compatibility).
>>> Are you saying there is a 20% CPU usage even when the joystick
>interface
>>> is not open? This should not happen (and this is not happening on my
>>> laptop). The polling should happen only when a userspace app opens
>the
>>> joystick interface (like running neverball).
>>>
>>> So I'd tend to think it's more due to a misconfiguration of the
>system
>>> (like xserver using the joystick interface as a pointer device) or
>it's
>>> a bug in the way we set up the polling. Could you investigate and let
>me
>>> know?
>>
>> Marcin originally reported this to me.
>>
>> Marcin, could you please check 'lsof' output to see whether the
>joystick
>> interface has been open by some application?
>>
>> Thanks,
>>
>
>sorry for the delay, had a crunch time
>
>here is the link for this lsof:
>https://bugzilla.novell.com/attachment.cgi?id=354953
>

Could you check what is the polling period of the device.
something like:
cat /sys/devices/platform/lis3lv02d/input/input9/poll

it is current polling period in milliseconds. 0 disables polling.

-Samu

????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2010-04-16 12:06:50

by Éric Piel

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

On 16/04/10 13:41, Marcin Derlukiewicz wrote:
:
> sorry for the delay, had a crunch time
>
> here is the link for this lsof:
> https://bugzilla.novell.com/attachment.cgi?id=354953
So apparently, it's opened by mplayer. Indeed, by default mplayer always
opens the first joystick device, because some people like to control a
movie with a joystick.

I don't think much can be done from the kernel point of view. Maybe
there are even people who enjoy controlling their movies by moving their
laptop! Here, my ~/.mplayer/config looks like:
[default]
input=js-dev=/dev/input/js8

You could also put a udev rule to change the name of this joystick to
something like js1.

All I could think of in the kernel side to improve this situation would
be to give more information about joystick devices, and define a subtype
"accelerometer", which mplayer could avoid selecting by default. I don't
know enough the input interface to know if this already exists...

See you,
Eric

2010-04-16 12:13:27

by Marcin Derlukiewicz

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

Dnia 16-04-2010 o 14:00:15 <[email protected]> napisał(a):

>
>
>> -----Original Message-----
>> From: ext Marcin Derlukiewicz [mailto:[email protected]]
>> Sent: 16 April, 2010 14:42
>> To: Jiri Kosina; Éric Piel
>> Cc: Andrew Morton; Onkalo Samu.P (Nokia-D/Tampere); Pavel Machek; lm-
>> [email protected]; [email protected]
>> Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input
>> interface
>>
>> Dnia 09-04-2010 o 15:32:59 Jiri Kosina <[email protected]> napisał(a):
>>
>>> On Fri, 9 Apr 2010, Éric Piel wrote:
>>>
>>>> > This is reported to create 20% CPU usage increase (and
>> proportionaly
>>>> higher
>>>> > power consumption) just for the ipolldevd kernel thread (which is
>> used
>>>> > to read the sensor).
>>>> >
>>>> > As most users probably only use the freefall functionality of the
>>>> driver
>>>> > and not the joystick interface, provide means for disabling the
>>>> registration
>>>> > of joystick device altogether via module parameter.
>>>> > (I'd rather make it default to 0, but this will break backwards
>>>> compatibility).
>>>> Are you saying there is a 20% CPU usage even when the joystick
>> interface
>>>> is not open? This should not happen (and this is not happening on my
>>>> laptop). The polling should happen only when a userspace app opens
>> the
>>>> joystick interface (like running neverball).
>>>>
>>>> So I'd tend to think it's more due to a misconfiguration of the
>> system
>>>> (like xserver using the joystick interface as a pointer device) or
>> it's
>>>> a bug in the way we set up the polling. Could you investigate and let
>> me
>>>> know?
>>>
>>> Marcin originally reported this to me.
>>>
>>> Marcin, could you please check 'lsof' output to see whether the
>> joystick
>>> interface has been open by some application?
>>>
>>> Thanks,
>>>
>>
>> sorry for the delay, had a crunch time
>>
>> here is the link for this lsof:
>> https://bugzilla.novell.com/attachment.cgi?id=354953
>>
>
> Could you check what is the polling period of the device.
> something like:
> cat /sys/devices/platform/lis3lv02d/input/input9/poll
>
> it is current polling period in milliseconds. 0 disables polling.
>
> -Samu
>

I think that on my system this is /sys/devices/platform/lis3lv02d/rate
but i may be wrong. Anyway it contains 40 as a number.

Marcin.

2010-04-16 13:56:51

by Éric Piel

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

On 16/04/10 14:13, Marcin Derlukiewicz wrote:
> Dnia 16-04-2010 o 14:00:15 <[email protected]> napisał(a):
>
:
>>
>> Could you check what is the polling period of the device.
>> something like:
>> cat /sys/devices/platform/lis3lv02d/input/input9/poll
>>
>> it is current polling period in milliseconds. 0 disables polling.
>>
>> -Samu
>>
>
> I think that on my system this is /sys/devices/platform/lis3lv02d/rate
> but i may be wrong. Anyway it contains 40 as a number.
This file is something else. Isn't there any file like
/sys/devices/platform/lis3lv02d/input/input*/poll ?

Maybe your kernel is too old to have this functionality (I don't know
when it was introduced). Samu is right, here to disable the joystick, I
can indeed do a:
echo 0 > /sys/devices/platform/lis3lv02d/input/input*/poll

Eric

2010-04-16 14:27:01

by Marcin Derlukiewicz

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

Dnia 16-04-2010 o 15:56:43 Éric Piel <[email protected]>
napisał(a):

> On 16/04/10 14:13, Marcin Derlukiewicz wrote:
>> Dnia 16-04-2010 o 14:00:15 <[email protected]> napisał(a):
>>
> :
>>>
>>> Could you check what is the polling period of the device.
>>> something like:
>>> cat /sys/devices/platform/lis3lv02d/input/input9/poll
>>>
>>> it is current polling period in milliseconds. 0 disables polling.
>>>
>>> -Samu
>>>
>>
>> I think that on my system this is /sys/devices/platform/lis3lv02d/rate
>> but i may be wrong. Anyway it contains 40 as a number.
> This file is something else. Isn't there any file like
> /sys/devices/platform/lis3lv02d/input/input*/poll ?
>
> Maybe your kernel is too old to have this functionality (I don't know
> when it was introduced). Samu is right, here to disable the joystick, I
> can indeed do a:
> echo 0 > /sys/devices/platform/lis3lv02d/input/input*/poll
>
> Eric

nope, should i paste you list?
my kernel is 2.6.31.12

2010-04-16 14:30:34

by Éric Piel

[permalink] [raw]
Subject: Re: [PATCH] lis3lv02d: provide means to disable polled input interface

On 16/04/10 16:26, Marcin Derlukiewicz wrote:
> Dnia 16-04-2010 o 15:56:43 Éric Piel <[email protected]>
> napisał(a):
:
>>
>> Maybe your kernel is too old to have this functionality (I don't know
>> when it was introduced). Samu is right, here to disable the joystick, I
>> can indeed do a:
>> echo 0 > /sys/devices/platform/lis3lv02d/input/input*/poll
:
> nope, should i paste you list?
> my kernel is 2.6.31.12
It's not necessary. For your kernel, I'd recommend the trick with the
mplayer configuration file. And as Samu explained, on newer kernels the
ability to disable totally the polling is already there.

Eric