public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Sean Young <sean@mess.org>
Cc: linux-media@vger.kernel.org,
	"Ivaylo Dimitrov" <ivo.g.dimitrov.75@gmail.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] pwm: make it possible to apply pwm changes in atomic context
Date: Fri, 13 Oct 2023 17:34:34 +0200	[thread overview]
Message-ID: <ZSljioc2OfPfxVeB@orome.fritz.box> (raw)
In-Reply-To: <ZSlbFukZKGNpR5PM@gofer.mess.org>

[-- Attachment #1: Type: text/plain, Size: 3729 bytes --]

On Fri, Oct 13, 2023 at 03:58:30PM +0100, Sean Young wrote:
> On Fri, Oct 13, 2023 at 01:51:40PM +0200, Thierry Reding wrote:
> > On Fri, Oct 13, 2023 at 11:46:14AM +0100, Sean Young wrote:
> > [...]
> > > diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> > > index d2f9f690a9c1..93f166ab03c1 100644
> > > --- a/include/linux/pwm.h
> > > +++ b/include/linux/pwm.h
> > > @@ -267,6 +267,7 @@ struct pwm_capture {
> > >   * @get_state: get the current PWM state. This function is only
> > >   *	       called once per PWM device when the PWM chip is
> > >   *	       registered.
> > > + * @atomic: can the driver execute pwm_apply_state in atomic context
> > >   * @owner: helps prevent removal of modules exporting active PWMs
> > >   */
> > >  struct pwm_ops {
> > > @@ -278,6 +279,7 @@ struct pwm_ops {
> > >  		     const struct pwm_state *state);
> > >  	int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
> > >  			 struct pwm_state *state);
> > > +	bool atomic;
> > >  	struct module *owner;
> > >  };
> > 
> > As I mentioned earlier, this really belongs in struct pwm_chip rather
> > than struct pwm_ops. I know that Uwe said this is unlikely to happen,
> > and that may be true, but at the same time it's not like I'm asking
> > much. Whether you put this in struct pwm_ops or struct pwm_chip is
> > about the same amount of code, and putting it into pwm_chip is much
> > more flexible, so it's really a no-brainer.
> 
> Happy to change this of course. I changed it and then changed it back after
> Uwe's comment, I'll fix this in the next version.
> 
> One tiny advantage is that pwm_ops is static const while pwm_chip is
> allocated per-pwm, so will need instructions for setting the value. Having
> said that, the difference is tiny, it's a single bool.

Yeah, it's typically a single assignment, so from a code point of view
it should be pretty much the same. I suppose from an instruction level
point of view, yes, this might add a teeny-tiny bit of overhead.

On the other hand it lets us do interesting things like initialize
chip->atomic = !regmap_might_sleep() for those drivers that use regmap
and then not worry about it any longer.

Given that, I'm also wondering if we should try to keep the terminology
a bit more consistent. "Atomic" is somewhat overloaded because ->apply()
and ->get_state() are part of the "atomic" PWM API (in the sense that
applying changes are done as a single, atomic operation, rather than in
the sense of "non-sleeping" operation).

So pwm_apply_state_atomic() is then doubly atomic, which is a bit weird.
On the other hand it's a bit tedious to convert all existing users to
pwm_apply_state_might_sleep().

Perhaps as a compromise we can add pwm_apply_state_might_sleep() and
make pwm_apply_state() a (deprecated) alias for that, so that existing
drivers can be converted one by one.

Eventually we would then end up with both pwm_apply_state_might_sleep()
and pwm_apply_state_atomic(), which has the nice side-effect of these
being unambiguous.

That doesn't get rid of the ambiguity of that _atomic() suffix, but I
can probably live with that one. It's used for this same meaning in
other contexts and if we add a _might_sleep() variant it becomes clearer
how the two are different.

Anyway, the bottom line is that I'd prefer the "atomic" field to be
renamed "might_sleep". It'd also be nice to add the new _might_sleep()
variant since you're already changing all of this anyway. No need to
mass-convert all the drivers to the _might_sleep() variant yet, though,
since we can have a transitional alias for that.

Of course feel free to give it a shot if you feel like it.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-10-13 15:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1697193646.git.sean@mess.org>
2023-10-13 10:46 ` [PATCH v2 1/3] pwm: make it possible to apply pwm changes in atomic context Sean Young
2023-10-13 11:51   ` Thierry Reding
2023-10-13 14:58     ` Sean Young
2023-10-13 15:34       ` Thierry Reding [this message]
2023-10-13 18:04         ` Uwe Kleine-König
2023-10-14  8:31           ` Sean Young
2023-10-13 10:46 ` [PATCH v2 2/3] pwm: bcm2835: allow pwm driver to be used " Sean Young
2023-10-13 11:04   ` Stefan Wahren
2023-10-13 11:13     ` Alexander Stein
2023-10-13 11:44       ` Stefan Wahren
2023-10-13 17:51       ` Uwe Kleine-König
2023-10-14  6:51         ` Ivaylo Dimitrov
2023-10-14  8:47           ` Uwe Kleine-König
2023-10-13 10:46 ` [PATCH v2 3/3] media: pwm-ir-tx: trigger edges from hrtimer interrupt context Sean Young
2023-10-15  6:31   ` Ivaylo Dimitrov
2023-10-15 21:25     ` Sean Young

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=ZSljioc2OfPfxVeB@orome.fritz.box \
    --to=thierry.reding@gmail.com \
    --cc=ivo.g.dimitrov.75@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=sean@mess.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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