From: Jonathan Cameron <jic23@kernel.org>
To: Vasileios Amoiridis <vassilisamir@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
lars@metafoo.de, ang.iglesiasg@gmail.com,
mazziesaccount@gmail.com, ak@it-klinger.de,
petre.rodan@subdimension.ro, phil@raspberrypi.com,
579lpy@gmail.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: pressure: Add triggered buffer support for BMP280 driver
Date: Sat, 9 Mar 2024 18:19:42 +0000 [thread overview]
Message-ID: <20240309181942.5a60c3a7@jic23-huawei> (raw)
In-Reply-To: <20240304200547.GA10314@vamoiridPC>
On Mon, 4 Mar 2024 21:05:47 +0100
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:
> On Mon, Mar 04, 2024 at 09:18:27PM +0200, Andy Shevchenko wrote:
> > On Mon, Mar 04, 2024 at 08:08:38PM +0100, Vasileios Amoiridis wrote:
> > > On Mon, Mar 04, 2024 at 01:52:05PM +0200, Andy Shevchenko wrote:
> > > > On Sun, Mar 03, 2024 at 05:53:00PM +0100, Vasileios Amoiridis wrote:
> >
> > ...
> >
> > > > > + struct {
> > > > > + s32 temperature;
> > > > > + u32 pressure;
> > > > > + u32 humidity;
> > > >
> > > > > + s64 timestamp;
> > > >
> > > > Shouldn't this be aligned properly?
> > >
> > > I saw that in some drivers it was added and in some it was not. What is the
> > > difference of aligning just the timestamp of the kernel?
> >
> > You can count yourself. With provided structure as above there is a high
> > probability of misaligned timeout field. The latter has to be aligned on
> > 8 bytes.
> >
>
> I was unaware, but now I am not. Thank you very much for the feedback.
Fun bit of C is that you aren't actually aligning just the timestamp.
A C structure is aligned to the alignment of the maximum element within it.
So by specifying that timestamp is aligned to 8 bytes, you also force the
alignment of the whole structure to 8 bytes.
When you see the outer buffer aligned as well (typically the potentially larger
__aligned (IIO_DMA_MINALIGN)) that's for a different reason. Used on a trailing
element of a structure via iio_priv() that ensures there is nothing else in the
cacheline (maximum one in the system) on systems where this matters due to non
coherent DMA. Still need the __aligned(8) on the timestamp though as otherwise
the internal padding may be wrong (like here).
On some architectures small buffers are always bounced - if that were true on
all of them we could get rid of the complexity of IIO_DMA_MINALIGN.
Alignment is so much fun - particularly with x86_32 which does 8 byte values aligned
to 4 bytes. We had a massive set of patches fixing subtle issues around that a
few years ago.
Jonathan
> > > > > + } iio_buffer;
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
> >
> >
next prev parent reply other threads:[~2024-03-09 18:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 16:52 [PATCH 0/4] Series to add triggered buffer support to BMP280 driver Vasileios Amoiridis
2024-03-03 16:52 ` [PATCH 1/4] iio: pressure: BMP280 core driver headers sorting Vasileios Amoiridis
2024-03-04 11:36 ` Andy Shevchenko
2024-03-09 18:09 ` Jonathan Cameron
2024-03-03 16:52 ` [PATCH 2/4] iio: pressure: Add scale value for channels Vasileios Amoiridis
2024-03-04 11:42 ` Andy Shevchenko
2024-03-09 18:28 ` Jonathan Cameron
2024-03-03 16:52 ` [PATCH 3/4] iio: pressure: Add timestamp and scan_masks for BMP280 driver Vasileios Amoiridis
2024-03-04 11:47 ` Andy Shevchenko
2024-03-04 18:50 ` Vasileios Amoiridis
2024-03-04 19:07 ` Andy Shevchenko
2024-03-09 18:12 ` Jonathan Cameron
2024-03-03 16:53 ` [PATCH 4/4] iio: pressure: Add triggered buffer support " Vasileios Amoiridis
2024-03-04 11:52 ` Andy Shevchenko
2024-03-04 19:08 ` Vasileios Amoiridis
2024-03-04 19:18 ` Andy Shevchenko
2024-03-04 20:05 ` Vasileios Amoiridis
2024-03-09 18:19 ` Jonathan Cameron [this message]
2024-03-09 18:32 ` 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=20240309181942.5a60c3a7@jic23-huawei \
--to=jic23@kernel.org \
--cc=579lpy@gmail.com \
--cc=ak@it-klinger.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ang.iglesiasg@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=petre.rodan@subdimension.ro \
--cc=phil@raspberrypi.com \
--cc=vassilisamir@gmail.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