If the pwm can sleep defer actions to it using a worker.
A similar approach was used in leds-pwm (c971ff185)
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.5-rc1 and 4.1.
Unmodified applicable to
* 4.5-rc4
* 4.4.1 (stable)
* 4.3.5 (stable)
* 4.1.18 (longterm)
Modified applicable to
* 3.18.27 (longterm)
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 62 +++++++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 18 deletions(-)
On Wed, Feb 17, 2016 at 02:19:26PM +0100, Manfred Schlaegl wrote:
quoted hunk
If the pwm can sleep defer actions to it using a worker.
A similar approach was used in leds-pwm (c971ff185)
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.5-rc1 and 4.1.
Unmodified applicable to
* 4.5-rc4
* 4.4.1 (stable)
* 4.3.5 (stable)
* 4.1.18 (longterm)
Modified applicable to
* 3.18.27 (longterm)
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 62 +++++++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 18 deletions(-)
On Wed, Feb 17, 2016 at 02:19:26PM +0100, Manfred Schlaegl wrote:
quoted
If the pwm can sleep defer actions to it using a worker.
A similar approach was used in leds-pwm (c971ff185)
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.5-rc1 and 4.1.
Unmodified applicable to
* 4.5-rc4
* 4.4.1 (stable)
* 4.3.5 (stable)
* 4.1.18 (longterm)
Modified applicable to
* 3.18.27 (longterm)
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 62 +++++++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 18 deletions(-)
I wonder if it is not better to always schedule work, regardless of
whether PWM may sleep or not.
Thanks.
In my opinion there is no real strong argument to do it this or that way.
I decided to do it this way because of following weaker arguments:
1. If pwm can not sleep the behavior stays exactly the same as before
2. The introduced conditions do not really add much complexity to the code
3. It was successfully done the same way in leds-pwm
Best regards,
Manfred
On Mon, Feb 22, 2016 at 11:46:39AM -0800, Dmitry Torokhov wrote:
On Wed, Feb 17, 2016 at 02:19:26PM +0100, Manfred Schlaegl wrote:
quoted
If the pwm can sleep defer actions to it using a worker.
A similar approach was used in leds-pwm (c971ff185)
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.5-rc1 and 4.1.
Unmodified applicable to
* 4.5-rc4
* 4.4.1 (stable)
* 4.3.5 (stable)
* 4.1.18 (longterm)
Modified applicable to
* 3.18.27 (longterm)
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 62 +++++++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 18 deletions(-)
I wonder if it is not better to always schedule work, regardless of
whether PWM may sleep or not.
I agree with Dmitry. Users of the PWM API should always assume that
calls to the PWM API might sleep. Conditionalizing on pwm_can_sleep()
isn't a good idea, since that function is scheduled to be removed. In
fact it's been returning true unconditionally since v4.5, so the fast
path is dead code anyway.
Thierry
I agree with Dmitry. Users of the PWM API should always assume that
calls to the PWM API might sleep. Conditionalizing on pwm_can_sleep()
isn't a good idea, since that function is scheduled to be removed. In
fact it's been returning true unconditionally since v4.5, so the fast
path is dead code anyway.
In this case, the decision is clear ;-)
I'll rework and send the new patch in the next days.
best regards,
manfred
Pwm config may sleep so defer it using a worker.
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0 and 4.1.24.
Unmodified applicable to
* 4.6 (stable)
* 4.5.4 (stable)
* 4.4.10 (longterm)
* 4.1.24 (longterm)
Modified applicable to
* 3.18.33 (longterm)
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 54 +++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 18 deletions(-)
On Wed, May 18, 2016 at 05:16:49PM +0200, Manfred Schlaegl wrote:
Pwm config may sleep so defer it using a worker.
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0 and 4.1.24.
Unmodified applicable to
* 4.6 (stable)
* 4.5.4 (stable)
* 4.4.10 (longterm)
* 4.1.24 (longterm)
Modified applicable to
* 3.18.33 (longterm)
What does this all mean? Have you read
Documentation/stable_kernel_rules.txt for how to mark things for stable
inclusion?
thanks,
greg k-h
On Wed, May 18, 2016 at 05:16:49PM +0200, Manfred Schlaegl wrote:
quoted
Pwm config may sleep so defer it using a worker.
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0 and 4.1.24.
Unmodified applicable to
* 4.6 (stable)
* 4.5.4 (stable)
* 4.4.10 (longterm)
* 4.1.24 (longterm)
Modified applicable to
* 3.18.33 (longterm)
What does this all mean? Have you read
Documentation/stable_kernel_rules.txt for how to mark things for stable
inclusion?
thanks,
greg k-h
Sorry, I'm afraid I missed that. Thanks for the clarification. I will respect that in the future.
Should I resend the patch with a cleaned up message (without "Unmodified applicable to" and "Modified applicable to" stuff)?
Is the rest of message (formally) ok?
thanks,
manfred
This is racy, request to play may come in after cancel_work_sync()
returns but before we unregistered input device. I think you want the
version below.
--
Dmitry
Input: pwm-beeper - fix 'scheduling while atomic'
From: Manfred Schlaegl <redacted>
Pwm config may sleep so defer it using a worker.
Trigger:
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0 and 4.1.24.
Signed-off-by: Manfred Schlaegl <redacted>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/misc/pwm-beeper.c | 70 +++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 21 deletions(-)
This is racy, request to play may come in after cancel_work_sync()
returns but before we unregistered input device. I think you want the
version below.
Hi Dmitry,
yes you are right. Thank you for your feedback.
I also see that point, but I think it would be a simpler change just
to cancel the worker after unregistering the device (to reorder
cancel_work_sync and input_unregister_device).
Patch will follow shortly.
What do you think?
Sincerely,
Manfred
Pwm config may sleep so defer it using a worker.
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0 and 4.1.24.
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 54 +++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 18 deletions(-)
This is racy, request to play may come in after cancel_work_sync()
returns but before we unregistered input device. I think you want the
version below.
Hi Dmitry,
yes you are right. Thank you for your feedback.
I also see that point, but I think it would be a simpler change just
to cancel the worker after unregistering the device (to reorder
cancel_work_sync and input_unregister_device).
That is an option, but I wanter to have close() because I also want to
convert the driver to used devm for allocating resources, and then we'd
need close() anyway so that we can get rid of remove() method.
Thanks.
--
Dmitry
This is racy, request to play may come in after cancel_work_sync()
returns but before we unregistered input device. I think you want the
version below.
Hi Dmitry,
yes you are right. Thank you for your feedback.
I also see that point, but I think it would be a simpler change just
to cancel the worker after unregistering the device (to reorder
cancel_work_sync and input_unregister_device).
That is an option, but I wanter to have close() because I also want to
convert the driver to used devm for allocating resources, and then we'd
need close() anyway so that we can get rid of remove() method.
Thanks.
Ok. Thanks for clarification.
I will send a patch with the modifications you suggested before.
The following patch will also have some slight modifications in line numbers to make it apply after
cfae56f18 (input: misc: pwm-beeper: Explicitly apply PWM config extracted from pwm_args).
best regards,
Manfred
Ok. Thanks for clarification.
I will send a patch with the modifications you suggested before.
The following patch will also have some slight modifications in line numbers to make it apply after
cfae56f18 (input: misc: pwm-beeper: Explicitly apply PWM config extracted from pwm_args).
best regards,
Manfred
While testing the patch I found another problem.
calling
pwm_config(beeper->pwm, period / 2, period) with periode=0 leads to
[ 199.964836] Division by zero in kernel.
[ 199.964875] CPU: 0 PID: 277 Comm: kworker/0:1 Not tainted 4.6.0-general-1-11011-g928f0cf #24
[ 199.964887] Hardware name: Freescale i.MX53 (Device Tree Support)
[ 199.964925] Workqueue: events pwm_beeper_work
[ 199.964937] Backtrace:
[ 199.964970] [<c010a73c>] (dump_backtrace) from [<c010a920>] (show_stack+0x18/0x1c)
[ 199.964980] r6:00000000 r5:ce9fed9c r4:00000000 r3:00000000
[ 199.965018] [<c010a908>] (show_stack) from [<c031ca78>] (dump_stack+0x20/0x28)
[ 199.965037] [<c031ca58>] (dump_stack) from [<c010a888>] (__div0+0x18/0x20)
[ 199.965053] [<c010a870>] (__div0) from [<c031b86c>] (Ldiv0+0x8/0x14)
[ 199.965080] [<c034bbec>] (imx_pwm_config_v2) from [<c034bfb8>] (imx_pwm_config+0x68/0x88)
[ 199.965088] r9:00000000 r8:ceabf2c0 r7:00000000 r6:00000000 r5:ceabf440 r4:ce9fed9c
[ 199.965121] [<c034bf50>] (imx_pwm_config) from [<c034b288>] (pwm_apply_state+0xfc/0x188)
[ 199.965129] r9:00000000 r8:cedd9a00 r7:00000000 r6:ceabf2e0 r5:ce9f7ec0 r4:ceabf2c0
[ 199.965164] [<c034b18c>] (pwm_apply_state) from [<c0475b28>] (__pwm_beeper_set+0x60/0xd8)
[ 199.965172] r7:00000000 r6:ceabf2c0 r5:00000000 r4:cea92e80
[ 199.965200] [<c0475ac8>] (__pwm_beeper_set) from [<c0475bb4>] (pwm_beeper_work+0x14/0x18)
[ 199.965209] r7:ce9da998 r6:c0908a80 r5:cea92e88 r4:ce9da980
[ 199.965240] [<c0475ba0>] (pwm_beeper_work) from [<c01315c8>] (process_one_work+0x1f4/0x334)
[ 199.965255] [<c01313d4>] (process_one_work) from [<c0131dc4>] (worker_thread+0x330/0x4ac)
[ 199.965264] r10:00000000 r9:00000008 r8:c0908a94 r7:ce9da998 r6:c0908a80 r5:c0908a80
[ 199.965289] r4:ce9da980
[ 199.965311] [<c0131a94>] (worker_thread) from [<c0136308>] (kthread+0xe4/0xf8)
[ 199.965319] r10:00000000 r9:00000000 r8:00000000 r7:c0131a94 r6:ce9da980 r5:00000000
[ 199.965342] r4:cea7d900 r3:ce9f6000
[ 199.965364] [<c0136224>] (kthread) from [<c01073b8>] (ret_from_fork+0x14/0x3c)
[ 199.965372] r7:00000000 r6:00000000 r5:c0136224 r4:cea7d900
I modified the patch, so that pwm_config is called only with periode >0
- pwm_config(beeper->pwm, period / 2, period);
-
- if (period == 0)
- pwm_disable(beeper->pwm);
- else
+ if (period) {
+ pwm_config(beeper->pwm, period / 2, period);
pwm_enable(beeper->pwm);
+ } else
+ pwm_disable(beeper->pwm);
I will send the corrected patch shortly.
Best regards,
Manfred
Pwm config may sleep so defer it using a worker.
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0.
Signed-off-by: Manfred Schlaegl <redacted>
---
drivers/input/misc/pwm-beeper.c | 69 ++++++++++++++++++++++++++++-------------
1 file changed, 48 insertions(+), 21 deletions(-)
On Fri, May 27, 2016 at 11:14:27AM +0200, Manfred Schlaegl wrote:
Pwm config may sleep so defer it using a worker.
On a Freescale i.MX53 based board we ran into "BUG: scheduling while
atomic" because input_inject_event locks interrupts, but
imx_pwm_config_v2 sleeps.
Tested on Freescale i.MX53 SoC with 4.6.0.
Signed-off-by: Manfred Schlaegl <redacted>