From: Jonathan Cameron <jic23@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Mathias Duckeck <m.duckeck@kunbus.de>,
Phil Elwell <phil@raspberrypi.org>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 2/3] iio: dac: Add Texas Instruments 8/10/12-bit 2/4-channel DAC driver
Date: Thu, 26 Oct 2017 16:35:48 +0100 [thread overview]
Message-ID: <20171026163548.0e59fa6c@archlinux> (raw)
In-Reply-To: <20171022094854.GA30715@wunner.de>
On Sun, 22 Oct 2017 11:48:54 +0200
Lukas Wunner <lukas@wunner.de> wrote:
> On Sat, Oct 21, 2017 at 08:33:08PM +0100, Jonathan Cameron wrote:
> > On Tue, 17 Oct 2017 12:42:00 +0200 Lukas Wunner <lukas@wunner.de> wrote:
> > > +struct ti_dac_chip {
> > > + struct mutex lock;
> > > + struct regulator *vref;
> > > + struct spi_message mesg;
> > > + struct spi_transfer xfer;
> > > + u8 buf[2] ____cacheline_aligned;
> >
> > I missed this the first time. The whole point of the fun
> > of ____cacheline_aligned is to ensure nothing shares a
> > cacheline with the buffer used for DMA. We take care
> > when allocating these private structures that this
> > will be true, but it relies on nothing that might be
> > changed during dma being after the buffer.
> >
> > Simple reordering fix so I'll do it whilst applying.
>
> TBH I was a bit confused about how to achieve proper cacheline
> alignment. My limited understanding of the slab allocator is
> that it neither guarantees that an allocation begins on a cacheline
> nor that no another allocation immediately starts after it.
>
> However taking a closer look at iio_device_alloc() I realize now
> that it implicitly takes care of both by inserting the necessary
> padding. Neat. I was already wondering why the IIO subsystem
> takes this somewhat unusual approach to allocate the private struct
> behind struct iio_dev, instead of letting the driver embed it
> within its private struct and use container_of() to yield the
> private struct corresponding to a struct iio_dev, as most other
> subsystems do. But that explains it.
Kind of - if we didn't play that game, the drivers could do it
themselves in their private structures.
Back when we got started with IIO it was actually a pretty
even split in kernel subsystems between those who did the embedding
one way around and those that went the other way around - there
are advantages to both approaches but it doesn't really matter.
Honestly an early reviewer (can't remember who) said do it this
way (before that we were separately allocating both) and I never
thought about it at the time ;)
I now wonder if we made the right choice sometimes - particularly
as it makes drivers embedding both IIO and other interfaces a bit
messy. I always planned to put in the various
initializers to handle the embedding in the private structure case
correctly, but haven't gotten around to it yet :) Should be easy
enough to do I think... From a review point of view though it
is nice to keep all drivers looking roughly the same so perhaps
introducing another option would be a bad idea...
Malloc calls are always guaranteed to be cacheline aligned (though
largely through implementation than I think an explicit rule - though
they are guaranteed to be safe for DMA as long as the whole memory
space is accessible for DMA - so this enforces cacheline alignment
rather indirectly).
A lot of drivers rely on this for dma buffers though so it won't
change without a 'lot' of work. Much nicer than in userspace
where you have to go through the dance of alloc_aligned to
guarantee anything at all...
Jonathan
>
> Thanks,
>
> Lukas
prev parent reply other threads:[~2017-10-26 15:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 10:42 [PATCH v2 0/3] Texas Instruments 8/10/12-bit 2/4-channel DAC driver Lukas Wunner
2017-10-17 10:42 ` [PATCH v2 1/3] dt-bindings: iio: dac: ti-dac082s085: Document new driver Lukas Wunner
2017-10-21 19:27 ` Jonathan Cameron
2017-10-17 10:42 ` [PATCH v2 3/3] iio: dac: ti-dac082s085: Read chip spec from device table Lukas Wunner
2017-10-21 19:38 ` Jonathan Cameron
2017-10-17 10:42 ` [PATCH v2 2/3] iio: dac: Add Texas Instruments 8/10/12-bit 2/4-channel DAC driver Lukas Wunner
2017-10-21 19:33 ` Jonathan Cameron
2017-10-22 9:48 ` Lukas Wunner
2017-10-26 15:35 ` Jonathan Cameron [this message]
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=20171026163548.0e59fa6c@archlinux \
--to=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=m.duckeck@kunbus.de \
--cc=phil@raspberrypi.org \
--cc=pmeerw@pmeerw.net \
/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).