linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer
@ 2020-11-30 12:59 Linus Walleij
  2020-11-30 12:59 ` [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function Linus Walleij
  2020-11-30 20:51 ` [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer Jonathan Cameron
  0 siblings, 2 replies; 5+ messages in thread
From: Linus Walleij @ 2020-11-30 12:59 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij

This makes use of devm_iio_triggered_buffer_setup() to
save some minor overhead.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/gyro/mpu3050-core.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 00e58060968c..0d0850945d3a 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -1203,9 +1203,10 @@ int mpu3050_common_probe(struct device *dev,
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->name = name;
 
-	ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
-					 mpu3050_trigger_handler,
-					 &mpu3050_buffer_setup_ops);
+	ret = devm_iio_triggered_buffer_setup(dev,
+					indio_dev, iio_pollfunc_store_time,
+					mpu3050_trigger_handler,
+					&mpu3050_buffer_setup_ops);
 	if (ret) {
 		dev_err(dev, "triggered buffer setup failed\n");
 		goto err_power_down;
@@ -1214,7 +1215,7 @@ int mpu3050_common_probe(struct device *dev,
 	ret = iio_device_register(indio_dev);
 	if (ret) {
 		dev_err(dev, "device register failed\n");
-		goto err_cleanup_buffer;
+		goto err_power_down;
 	}
 
 	dev_set_drvdata(dev, indio_dev);
@@ -1241,8 +1242,6 @@ int mpu3050_common_probe(struct device *dev,
 
 	return 0;
 
-err_cleanup_buffer:
-	iio_triggered_buffer_cleanup(indio_dev);
 err_power_down:
 	mpu3050_power_down(mpu3050);
 
@@ -1258,7 +1257,6 @@ int mpu3050_common_remove(struct device *dev)
 	pm_runtime_get_sync(dev);
 	pm_runtime_put_noidle(dev);
 	pm_runtime_disable(dev);
-	iio_triggered_buffer_cleanup(indio_dev);
 	if (mpu3050->irq)
 		free_irq(mpu3050->irq, mpu3050);
 	iio_device_unregister(indio_dev);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function
  2020-11-30 12:59 [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer Linus Walleij
@ 2020-11-30 12:59 ` Linus Walleij
  2020-11-30 21:07   ` Jonathan Cameron
  2020-11-30 20:51 ` [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer Jonathan Cameron
  1 sibling, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2020-11-30 12:59 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Linus Walleij

If something other than the MPU3050 itself is using this
trigger, the timestamp needs to be stored in the poll
function.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/gyro/mpu3050-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 0d0850945d3a..b892487394ea 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -457,7 +457,7 @@ static int mpu3050_write_raw(struct iio_dev *indio_dev,
 
 static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
 {
-	const struct iio_poll_func *pf = p;
+	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct mpu3050 *mpu3050 = iio_priv(indio_dev);
 	int ret;
@@ -482,6 +482,9 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
 	else
 		timestamp = iio_get_time_ns(indio_dev);
 
+	/* Someone else may be using us as trigger */
+	pf->timestamp = timestamp;
+
 	mutex_lock(&mpu3050->lock);
 
 	/* Using the hardware IRQ trigger? Check the buffer then. */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer
  2020-11-30 12:59 [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer Linus Walleij
  2020-11-30 12:59 ` [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function Linus Walleij
@ 2020-11-30 20:51 ` Jonathan Cameron
  1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2020-11-30 20:51 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Mon, 30 Nov 2020 13:59:14 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> This makes use of devm_iio_triggered_buffer_setup() to
> save some minor overhead.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Hi Linus,

I'm very fussy about mixing devm and other cleanup.  Unless everything
that happens after this point is also managed, I'm not happy to see
an individual function made managed.  It may be safe, but
if fails the 'obviously safe' test.

Something odd going on here though.  We are currently removing the
buffer before we unregister the userspace interfaces to it.
That's not a good idea.  The remove order seems reverse from
what it should be...

Jonathan

> ---
>  drivers/iio/gyro/mpu3050-core.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index 00e58060968c..0d0850945d3a 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -1203,9 +1203,10 @@ int mpu3050_common_probe(struct device *dev,
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->name = name;
>  
> -	ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
> -					 mpu3050_trigger_handler,
> -					 &mpu3050_buffer_setup_ops);
> +	ret = devm_iio_triggered_buffer_setup(dev,
> +					indio_dev, iio_pollfunc_store_time,
> +					mpu3050_trigger_handler,
> +					&mpu3050_buffer_setup_ops);
>  	if (ret) {
>  		dev_err(dev, "triggered buffer setup failed\n");
>  		goto err_power_down;
> @@ -1214,7 +1215,7 @@ int mpu3050_common_probe(struct device *dev,
>  	ret = iio_device_register(indio_dev);
>  	if (ret) {
>  		dev_err(dev, "device register failed\n");
> -		goto err_cleanup_buffer;
> +		goto err_power_down;
>  	}
>  
>  	dev_set_drvdata(dev, indio_dev);
> @@ -1241,8 +1242,6 @@ int mpu3050_common_probe(struct device *dev,
>  
>  	return 0;
>  
> -err_cleanup_buffer:
> -	iio_triggered_buffer_cleanup(indio_dev);
>  err_power_down:
>  	mpu3050_power_down(mpu3050);
>  
> @@ -1258,7 +1257,6 @@ int mpu3050_common_remove(struct device *dev)
>  	pm_runtime_get_sync(dev);
>  	pm_runtime_put_noidle(dev);
>  	pm_runtime_disable(dev);
> -	iio_triggered_buffer_cleanup(indio_dev);
>  	if (mpu3050->irq)
>  		free_irq(mpu3050->irq, mpu3050);
>  	iio_device_unregister(indio_dev);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function
  2020-11-30 12:59 ` [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function Linus Walleij
@ 2020-11-30 21:07   ` Jonathan Cameron
  2020-12-01 12:41     ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2020-11-30 21:07 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Mon, 30 Nov 2020 13:59:15 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> If something other than the MPU3050 itself is using this
> trigger, the timestamp needs to be stored in the poll
> function.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
I'm a bit confused here.

pollfuncs are per device using the trigger, so writing to the
timestamp of the one from this device, won't have an affect on
any others.

If it did, we'd still have an issue as there are no ordering
guarantees amongst different consumers of a trigger.

Jonathan

> ---
>  drivers/iio/gyro/mpu3050-core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index 0d0850945d3a..b892487394ea 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -457,7 +457,7 @@ static int mpu3050_write_raw(struct iio_dev *indio_dev,
>  
>  static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
>  {
> -	const struct iio_poll_func *pf = p;
> +	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct mpu3050 *mpu3050 = iio_priv(indio_dev);
>  	int ret;
> @@ -482,6 +482,9 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
>  	else
>  		timestamp = iio_get_time_ns(indio_dev);
>  
> +	/* Someone else may be using us as trigger */
> +	pf->timestamp = timestamp;
> +
>  	mutex_lock(&mpu3050->lock);
>  
>  	/* Using the hardware IRQ trigger? Check the buffer then. */


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function
  2020-11-30 21:07   ` Jonathan Cameron
@ 2020-12-01 12:41     ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2020-12-01 12:41 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-iio, Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler

On Mon, Nov 30, 2020 at 10:07 PM Jonathan Cameron <jic23@kernel.org> wrote:

> I'm a bit confused here.

Rightly so!

> pollfuncs are per device using the trigger, so writing to the
> timestamp of the one from this device, won't have an affect on
> any others.
>
> If it did, we'd still have an issue as there are no ordering
> guarantees amongst different consumers of a trigger.

Yeah I got it all wrong. I'm trying to find the real bug
(likely in the trigger consuming driver) and fix that instead.

What do you use when stress testing IIO stuff? I have
been using the tools from the kernel so mainly
lsiio, iio_generic_buffer and iio_event_monitor so far.

iio-sensor-proxy seems really nice, but I just haven't
figured out what kind of programs people are in turn
using that with..

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-01 12:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 12:59 [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer Linus Walleij
2020-11-30 12:59 ` [PATCH 2/2] iio: gyro: mpu3050: Store timestamp in poll function Linus Walleij
2020-11-30 21:07   ` Jonathan Cameron
2020-12-01 12:41     ` Linus Walleij
2020-11-30 20:51 ` [PATCH 1/2] iio: gyro: mpu3050: Use devm_ to set up buffer Jonathan Cameron

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).