[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231005091713.jgx5h2ss4oybdxq7@pengutronix.de>
Date: Thu, 5 Oct 2023 11:17:13 +0200
From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To: Sean Young <sean@...s.org>
Cc: linux-arm-kernel@...ts.infradead.org, linux-pwm@...r.kernel.org,
Ivaylo Dimitrov <ivo.g.dimitrov.75@...il.com>,
Maxime Coquelin <mcoquelin.stm32@...il.com>,
Daire McNamara <daire.mcnamara@...rochip.com>,
Shawn Guo <shawnguo@...nel.org>,
Sascha Hauer <s.hauer@...gutronix.de>,
Alexandre Torgue <alexandre.torgue@...s.st.com>,
Vladimir Zapolskiy <vz@...ia.com>,
Conor Dooley <conor.dooley@...rochip.com>,
Thierry Reding <thierry.reding@...il.com>,
Palmer Dabbelt <palmer@...belt.com>,
NXP Linux Team <linux-imx@....com>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
Paul Walmsley <paul.walmsley@...ive.com>,
linux-riscv@...ts.infradead.org,
Fabio Estevam <festevam@...il.com>,
linux-stm32@...md-mailman.stormreply.com,
linux-kernel@...r.kernel.org,
Fabrice Gasnier <fabrice.gasnier@...s.st.com>
Subject: Re: [PATCH 1/2] pwm: make it possible to apply pwm changes in atomic
context
Hello Sean,
On Thu, Oct 05, 2023 at 09:30:32AM +0100, Sean Young wrote:
> On Wed, Oct 04, 2023 at 11:59:20AM +0200, Uwe Kleine-König wrote:
> > On Sun, Oct 01, 2023 at 11:40:29AM +0100, Sean Young wrote:
> > > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> > > index dc66e3405bf5..d9679ae5b2be 100644
> > > --- a/drivers/pwm/core.c
> > > +++ b/drivers/pwm/core.c
> > > @@ -505,7 +505,7 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
> > > * is a bad idea. So make it explicit that calling this function might
> > > * sleep.
> > > */
> > > - might_sleep();
> > > + might_sleep_if(pwm_can_sleep(pwm));
> > >
> > > if (!pwm || !state || !state->period ||
> > > state->duty_cycle > state->period)
> >
> > I'd like to have a mechanism to catch drivers that missed to set
> > .can_sleep. The best idea I currently have for that is to disable
> > preemption if IS_ENABLED(CONFIG_PWM_DEBUG) && !pwm_can_sleep(pwm) while
> > .apply() is running.
>
> If we have pwm_apply_state_atomic(), then CONFIG_DEBUG_ATOMIC_SLEEP will
> catch them, but only in that code path of course.
>
> How about using non_block_start() and non_block_end() if can_sleep is
> not set?
TIL, looks like it was created for that task.
> > > diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c
> > > index b7c6045c5d08..b8b9392844e9 100644
> > > --- a/drivers/pwm/pwm-fsl-ftm.c
> > > +++ b/drivers/pwm/pwm-fsl-ftm.c
> > > @@ -405,6 +405,7 @@ static int fsl_pwm_probe(struct platform_device *pdev)
> > >
> > > fpc->soc = of_device_get_match_data(&pdev->dev);
> > > fpc->chip.dev = &pdev->dev;
> > > + fpc->chip.can_sleep = true;
> >
> > Also I wonder if the distinction between atomic and sleeping
> > pwm_state_apply() should be more explicit. For GPIOs you have a sleeping
> > variant gpiod_set_value_cansleep() that allows to immediately determine
> > the intended context in the caller. This would allow that programming
> > a PWM stays a preemption point (if possible/desired) even if the
> > underlying hardware/driver is atomic. To not have to touch all consumer
> > drivers, maybe the pair for pwm should better be
> >
> > pwm_apply_state()
> > pwm_apply_state_atomic()
>
> Do we need pwm_config_atomic(), pwm_enable_atomic(), and pwm_disable_atomic()
> too? These are just convenience functions, so we can probably do without them.
I'd like to get rid of these, so for now I'd keep them as is.
> > instead of a "cansleep" suffix for the sleeping variant? Or maybe it's
> > better to accept touching all consumer drivers to get semantics similar
> > to gpio? I couldn't decide quickly what I really like better here, so
> > that's your chance to comment and influence the outcome :-)
>
> If you expect to have more parameters for pwm_apply_state() then a flags
> argument makes sense.
Actually I don't want more parameters -- at least for this use case. I
could imagine another parameter for something like apply-immediately vs.
complete-current-period, but that's another topic.
> TBH I like the pwm_apply_state_atomic() option.
ok.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists