From: Pavel Machek <pavel@ucw.cz>
To: Baolin Wang <baolin.wang@linaro.org>
Cc: "Geert Uytterhoeven" <geert@linux-m68k.org>,
"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
rteysseyre@gmail.com,
"Björn Andersson" <bjorn.andersson@linaro.org>,
"Mark Brown" <broonie@kernel.org>,
"Linux LED Subsystem" <linux-leds@vger.kernel.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v14 1/2] leds: core: Introduce LED pattern trigger
Date: Fri, 9 Nov 2018 09:13:58 +0100 [thread overview]
Message-ID: <20181109081358.GD12450@amd> (raw)
In-Reply-To: <CAMz4kuKZ5z-v_j5Fhu=QzwY-=U6SBy4uSWoT8G8U83Z2qBRLxA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4180 bytes --]
On Wed 2018-11-07 11:23:52, Baolin Wang wrote:
> Hi Geert,
>
> On 6 November 2018 at 23:57, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > Hi Baolin,
> >
> > On Tue, Oct 2, 2018 at 6:39 PM Baolin Wang <baolin.wang@linaro.org> wrote:
> >> This patch adds one new led trigger that LED device can configure
> >> the software or hardware pattern and trigger it.
> >>
> >> Consumers can write 'pattern' file to enable the software pattern
> >> which alters the brightness for the specified duration with one
> >> software timer.
> >>
> >> Moreover consumers can write 'hw_pattern' file to enable the hardware
> >> pattern for some LED controllers which can autonomously control
> >> brightness over time, according to some preprogrammed hardware
> >> patterns.
> >>
> >> Signed-off-by: Raphael Teysseyre <rteysseyre@gmail.com>
> >> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> >
> >> --- /dev/null
> >> +++ b/drivers/leds/trigger/ledtrig-pattern.c
> >> @@ -0,0 +1,431 @@
> >
> >> +static void pattern_trig_timer_function(struct timer_list *t)
> >> +{
> >> + struct pattern_trig_data *data = from_timer(data, t, timer);
> >> +
> >> + mutex_lock(&data->lock);
> >
> > Timer functions run in interrupt context, hence if CONFIG_DEBUG_ATOMIC_SLEEP=y:
> >
> > BUG: sleeping function called from invalid context at kernel/locking/mutex.c:254
> > in_atomic(): 1, irqs_disabled(): 0, pid: 0, name: swapper/1
> > CPU: 1 PID: 0 Comm: swapper/1 Not tainted
> > 4.20.0-rc1-koelsch-00841-ga338c8181013c1a9 #171
> > Hardware name: Generic R-Car Gen2 (Flattened Device Tree)
> > [<c020f19c>] (unwind_backtrace) from [<c020aecc>] (show_stack+0x10/0x14)
> > [<c020aecc>] (show_stack) from [<c07affb8>] (dump_stack+0x7c/0x9c)
> > [<c07affb8>] (dump_stack) from [<c02417d4>] (___might_sleep+0xf4/0x158)
> > [<c02417d4>] (___might_sleep) from [<c07c92c4>] (mutex_lock+0x18/0x60)
> > [<c07c92c4>] (mutex_lock) from [<c067b28c>]
> > (pattern_trig_timer_function+0x1c/0x11c)
> > [<c067b28c>] (pattern_trig_timer_function) from [<c027f6fc>]
> > (call_timer_fn+0x1c/0x90)
> > [<c027f6fc>] (call_timer_fn) from [<c027f944>] (expire_timers+0x94/0xa4)
> > [<c027f944>] (expire_timers) from [<c027fc98>] (run_timer_softirq+0x108/0x15c)
> > [<c027fc98>] (run_timer_softirq) from [<c02021cc>] (__do_softirq+0x1d4/0x258)
> > [<c02021cc>] (__do_softirq) from [<c0224d24>] (irq_exit+0x64/0xc4)
> > [<c0224d24>] (irq_exit) from [<c0268dd0>] (__handle_domain_irq+0x80/0xb4)
> > [<c0268dd0>] (__handle_domain_irq) from [<c045e1b0>] (gic_handle_irq+0x58/0x90)
> > [<c045e1b0>] (gic_handle_irq) from [<c02019f8>] (__irq_svc+0x58/0x74)
> > Exception stack(0xeb483f60 to 0xeb483fa8)
> > 3f60: 00000000 00000000 eb9afaa0 c0217e80 00000000 ffffe000 00000000 c0e06408
> > 3f80: 00000002 c0e0647c c0c6a5f0 00000000 c0e04900 eb483fb0 c0207ea8 c0207e98
> > 3fa0: 60020013 ffffffff
> > [<c02019f8>] (__irq_svc) from [<c0207e98>] (arch_cpu_idle+0x1c/0x38)
> > [<c0207e98>] (arch_cpu_idle) from [<c0247ca8>] (do_idle+0x138/0x268)
> > [<c0247ca8>] (do_idle) from [<c0248050>] (cpu_startup_entry+0x18/0x1c)
> > [<c0248050>] (cpu_startup_entry) from [<402022ec>] (0x402022ec)
> >
> > Either this should use a spinlock instead of a mutex, or the timer
> > function should kick a workqueue to do the real work.
> >
>
> Ah, sorry I missed this. Good catch.
>
> After more thinking, the easy fix is that I think we can remove the
> mutex lock in pattern_trig_timer_function(). Since the mutex lock is
> used to protect the pattern trigger data, but before changing new
> pattern trigger data (pattern values or repeat value) by users, we
> always cancel the timer firstly to clear previous patterns'
> performance. That means there is no race in
> pattern_trig_timer_function(), so we can drop the mutex lock in
> pattern_trig_timer_function() to avoid this issue.
>
> I will send one patch to fix this issue. Thanks.
That's kind of interesting, but yes, it should work.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
prev parent reply other threads:[~2018-11-09 8:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-02 15:43 [PATCH v14 1/2] leds: core: Introduce LED pattern trigger Baolin Wang
2018-10-02 15:43 ` [PATCH v14 2/2] leds: sc27xx: Add pattern_set/clear interfaces for LED controller Baolin Wang
2018-10-02 20:25 ` [PATCH v14 1/2] leds: core: Introduce LED pattern trigger Jacek Anaszewski
2018-10-03 1:21 ` Baolin Wang
2018-10-04 20:00 ` Jacek Anaszewski
2018-10-09 12:01 ` Baolin Wang
2018-10-09 18:37 ` Jacek Anaszewski
2018-10-10 2:14 ` Baolin Wang
2018-10-10 16:00 ` Pavel Machek
2018-10-11 2:05 ` Baolin Wang
2018-10-10 20:43 ` Jacek Anaszewski
2018-10-11 3:06 ` Baolin Wang
2018-11-06 15:57 ` Geert Uytterhoeven
2018-11-07 3:23 ` Baolin Wang
2018-11-09 8:13 ` Pavel Machek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181109081358.GD12450@amd \
--to=pavel@ucw.cz \
--cc=baolin.wang@linaro.org \
--cc=bjorn.andersson@linaro.org \
--cc=broonie@kernel.org \
--cc=geert@linux-m68k.org \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=rteysseyre@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).