From: "Marek Behún" <kabel@kernel.org>
To: Pavel Machek <pavel@ucw.cz>
Cc: Ben Whitten <ben.whitten@gmail.com>, linux-leds@vger.kernel.org
Subject: Re: ledtrig netdev: what is the purpose of spinlock usage?
Date: Thu, 29 Oct 2020 19:13:47 +0100 [thread overview]
Message-ID: <20201029191347.6d509614@kernel.org> (raw)
In-Reply-To: <20201029174529.GA26053@duo.ucw.cz>
On Thu, 29 Oct 2020 18:45:29 +0100
Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
> > since you are the original author of netdev LED trigger, I guess this
> > question should go to you. Why are spinlocks used as locks in the
> > netdev trigger code? Is this for performance? Would it be a drastic
> > performance hit to use mutexes?
>
> Triggers can be called from interrupt context, IIRC, and many simple
> LEDs can be operated from interrupt context, too.
>
> Thus you need spinlocks...
>
> Best regards,
> Pavel
Pavel,
the set_baseline_state function in netdev trigger is guarded by a
spinlock only when reading/writing device_name attribute and in
netdev notify callback.
netdev_trig_notify can for example put the device away on
NETDEV_UNREGISTER event, and if someone was reading/writing the
device_name at the same time netdev_trig_notify is manipulating
netdevice pointer, it could break. So my guess for the lock is that it
is used because of this.
It is possible that netdev_trig_notify can be called from interrupt
context, I will have to look into this.
Anyway for the trigger_offload() method to be able to communicate with
PHYs I need the set_baseline_state function not to be called from
within spinlock. Otherwise the drivers implementing this method would
get too complicated. Would it be allright if on netdev event (link up,
link down, netdev changename, netdev unregister) the set_baseline_state
was called from a work, instead of directly from the spinlock?
I will send a patch proposing and explaining this.
Marek
next prev parent reply other threads:[~2020-10-29 18:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 6:00 ledtrig netdev: what is the purpose of spinlock usage? Marek Behún
2020-10-29 17:45 ` Pavel Machek
2020-10-29 18:13 ` Marek Behún [this message]
2020-10-29 21:32 ` Ben Whitten
2020-10-29 22:49 ` Jacek Anaszewski
2020-10-29 23:14 ` Marek Behún
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=20201029191347.6d509614@kernel.org \
--to=kabel@kernel.org \
--cc=ben.whitten@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/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).