[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250421140342.4097c0c4@jic23-huawei>
Date: Mon, 21 Apr 2025 14:03:42 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: David Lechner <dlechner@...libre.com>, Nuno Sá
<nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>, Lars-Peter Clausen
<lars@...afoo.de>, Michael Hennerich <Michael.Hennerich@...log.com>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 0/4] iio: introduce IIO_DECLARE_BUFFER_WITH_TS
On Sun, 20 Apr 2025 07:36:18 +0300
Andy Shevchenko <andy.shevchenko@...il.com> wrote:
> On Sat, Apr 19, 2025 at 1:59 AM David Lechner <dlechner@...libre.com> wrote:
> >
> > Creating a buffer of the proper size and correct alignment for use with
> > iio_push_to_buffers_with_ts() is commonly used and not easy to get
> > right (as seen by a number of recent fixes on the mailing list).
> >
> > In general, we prefer to use this pattern for creating such buffers:
> >
> > struct {
> > u16 data[2];
> > aligned_s64 timestamp;
> > } buffer;
> >
> > However, there are many cases where a driver may have a large number of
> > channels that can be optionally enabled or disabled in a scan or the
> > driver might support a range of chips that have different numbers of
> > channels or different storage sizes for the data. In these cases, the
> > timestamp may not always be at the same place relative to the data. We
> > just allocate a buffer large enough for the largest possible case and
> > don't care exactly where the timestamp ends up in the buffer.
> >
> > For these cases, we propose to introduce a new macro to make it easier
> > it easier for both the authors to get it right and for readers of the
> > code to not have to do all of the math to verify that it is correct.
> >
> > I have just included a few examples of drivers that can make use of this
> > new macro, but there are dozens more.
>
> I'm going to answer here as the summary of my view to this series and
> macro after your replies.
>
> So, first of all, the macro embeds alignment which is used only once
> in practice and the alignment used in most of the cases is DMA one.
It think that's because this is only converting a few examples. There
are more of these to come (9 of the ones that David first converted
to structures then realized this was a better fit for starters!).
A lot might still be aligned for DMA but I'd expect to see more of
the cases that don't need that either because they are i2c only or
because data shuffling means the DMA hits a different buffer and we
unscramble it into this one.
> Having two alignments in a row seems a bit weird to me. Second one, if
> we drop alignment, it means each of the users will need it. That
> significantly increases the line size and with high probability will
> require two LoCs to occupy. And third, based on the examples, the
> macro doesn't help much if we don't convert drivers to properly handle
> what they are using instead of plain u8 in all of the cases. Yes, it
> might require quite an invasive change to a driver, but this is how I
> see it should go.
Agreed for almost all cases that a conversion to the right type
is good to have - preferably as a precursor. There is that one case in
here where it depends on the specific part though which will remain
in a messier form.
>
> That said, it feels like this series took a half road.
>
> I leave it to Jonothan, but I don't like it to be merged in this form.
>
Whilst there are no current platforms where IIO_DMA_MINALIGN is < 8
in theory it might be in future.
The other way around, IIO_DMA_MINALIGN is large on some architectures
so could result in considerable additional padding and should only
be used where it is needed. Also that alignment is useless on the
stack as it does nothing about data after the buffer. Hence there
isn't really a general solution with one or the other :(
So I like the idea in general as a way to make things a little better
but agree it is still somewhat ugly.
Maybe we could add...
IIO_DECLARE_BUFFER_WITH_TS_FOR_DMA()
Might be worth it?
Jonathan
Powered by blists - more mailing lists