linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: "David Lechner" <dlechner@baylibre.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Eugen Hristev" <eugen.hristev@linaro.org>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Claudiu Beznea" <claudiu.beznea@tuxon.dev>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v5 6/7] iio: accel: sca3300: use IIO_DECLARE_BUFFER_WITH_TS
Date: Wed, 07 May 2025 07:37:50 +0100	[thread overview]
Message-ID: <b986f420280ae64b77c9534b856f3537bd5b29ed.camel@gmail.com> (raw)
In-Reply-To: <20250505-iio-introduce-iio_declare_buffer_with_ts-v5-6-814b72b1cae3@baylibre.com>

On Mon, 2025-05-05 at 11:31 -0500, David Lechner wrote:
> Use IIO_DECLARE_BUFFER_WITH_TS() to declare the buffer that gets used
> with iio_push_to_buffers_with_ts(). This makes the code a bit easier to
> read and understand.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> This is an alternative to [1]. Also, this serves as a test to see if we
> can get a rule of thumb to decide how much is too much to put on the
> stack vs. needing to put the buffer in a static struct. SCA3300_SCAN_MAX
> is 7, so this add a bit over 64 bytes to the stack, make the stack now
> roughly double what it was before.

IMHO, I think that for this buffer size, having it on the stack is very reasonable.

> 
> [1]:
> https://lore.kernel.org/linux-iio/20250418-iio-prefer-aligned_s64-timestamp-v1-1-4c6080710516@baylibre.com/
> ---
>  drivers/iio/accel/sca3300.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/iio/accel/sca3300.c b/drivers/iio/accel/sca3300.c
> index
> 1132bbaba75bcca525fac2f3e19f63546380fd4f..67416a406e2f43e4e417210410904d44c93111d2
> 100644
> --- a/drivers/iio/accel/sca3300.c
> +++ b/drivers/iio/accel/sca3300.c
> @@ -58,15 +58,6 @@ enum sca3300_scan_indexes {
>  	SCA3300_SCAN_MAX
>  };
>  
> -/*
> - * Buffer size max case:
> - * Three accel channels, two bytes per channel.
> - * Temperature channel, two bytes.
> - * Three incli channels, two bytes per channel.
> - * Timestamp channel, eight bytes.
> - */
> -#define SCA3300_MAX_BUFFER_SIZE (ALIGN(sizeof(s16) * SCA3300_SCAN_MAX,
> sizeof(s64)) + sizeof(s64))
> -
>  #define SCA3300_ACCEL_CHANNEL(index, reg, axis) {			\
>  	.type = IIO_ACCEL,						\
>  	.address = reg,							\
> @@ -193,9 +184,6 @@ struct sca3300_chip_info {
>   * @spi: SPI device structure
>   * @lock: Data buffer lock
>   * @chip: Sensor chip specific information
> - * @buffer: Triggered buffer:
> - *          -SCA3300: 4 channel 16-bit data + 64-bit timestamp
> - *          -SCL3300: 7 channel 16-bit data + 64-bit timestamp
>   * @txbuf: Transmit buffer
>   * @rxbuf: Receive buffer
>   */
> @@ -203,7 +191,6 @@ struct sca3300_data {
>  	struct spi_device *spi;
>  	struct mutex lock;
>  	const struct sca3300_chip_info *chip;
> -	u8 buffer[SCA3300_MAX_BUFFER_SIZE] __aligned(sizeof(s64));
>  	u8 txbuf[4] __aligned(IIO_DMA_MINALIGN);
>  	u8 rxbuf[4];
>  };
> @@ -492,7 +479,7 @@ static irqreturn_t sca3300_trigger_handler(int irq, void *p)
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct sca3300_data *data = iio_priv(indio_dev);
>  	int bit, ret, val, i = 0;
> -	s16 *channels = (s16 *)data->buffer;
> +	IIO_DECLARE_BUFFER_WITH_TS(s16, channels, SCA3300_SCAN_MAX);

On top of what you mentioned I like this change. The pattern you're removing is the
typical one for getting into unaligned accesses.

>  
>  	iio_for_each_active_channel(indio_dev, bit) {
>  		ret = sca3300_read_reg(data, indio_dev->channels[bit].address,
> &val);
> @@ -505,8 +492,7 @@ static irqreturn_t sca3300_trigger_handler(int irq, void *p)
>  		channels[i++] = val;
>  	}
>  
> -	iio_push_to_buffers_with_ts(indio_dev, data->buffer,
> -				    sizeof(data->buffer),
> +	iio_push_to_buffers_with_ts(indio_dev, channels, sizeof(channels),
>  				    iio_get_time_ns(indio_dev));
>  out:
>  	iio_trigger_notify_done(indio_dev->trig);
> 



  reply	other threads:[~2025-05-07  9:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 16:31 [PATCH v5 0/7] iio: introduce IIO_DECLARE_BUFFER_WITH_TS David Lechner
2025-05-05 16:31 ` [PATCH v5 1/7] iio: make IIO_DMA_MINALIGN minimum of 8 bytes David Lechner
2025-05-07 20:02   ` Jonathan Cameron
2025-05-08 21:39   ` David Laight
2025-05-08 21:44     ` David Lechner
2025-05-05 16:31 ` [PATCH v5 2/7] iio: introduce IIO_DECLARE_BUFFER_WITH_TS macros David Lechner
2025-05-05 16:31 ` [PATCH v5 3/7] iio: adc: ad4695: use IIO_DECLARE_DMA_BUFFER_WITH_TS David Lechner
2025-05-05 16:31 ` [PATCH v5 4/7] iio: adc: ad4695: rename AD4695_MAX_VIN_CHANNELS David Lechner
2025-05-05 16:31 ` [PATCH v5 5/7] iio: adc: ad7380: use IIO_DECLARE_DMA_BUFFER_WITH_TS David Lechner
2025-05-05 16:31 ` [PATCH v5 6/7] iio: accel: sca3300: use IIO_DECLARE_BUFFER_WITH_TS David Lechner
2025-05-07  6:37   ` Nuno Sá [this message]
2025-05-05 16:31 ` [PATCH v5 7/7] iio: adc: at91-sama5d2: " David Lechner
2025-05-05 16:47 ` [PATCH v5 0/7] iio: introduce IIO_DECLARE_BUFFER_WITH_TS Jonathan Cameron
2025-05-07  6:39 ` Nuno Sá
2025-05-07 19:54   ` Jonathan Cameron

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=b986f420280ae64b77c9534b856f3537bd5b29ed.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy@kernel.org \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=dlechner@baylibre.com \
    --cc=eugen.hristev@linaro.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=nuno.sa@analog.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).