linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier.adi@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Oskar Schirmer" <os@emlix.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Daniel Glöckner" <dg@emlix.com>,
	"Oliver Schneidewind" <osw@emlix.com>,
	"Johannes Weiner" <jw@emlix.com>
Subject: Re: [PATCH v3] ad7877: keep dma rx buffers in seperate cache lines
Date: Tue, 11 May 2010 02:23:34 -0400	[thread overview]
Message-ID: <AANLkTiktu7N5IXknkkJ9D5L4z5plhuGvD45IVqJm9zG1@mail.gmail.com> (raw)
In-Reply-To: <20100511062110.GB9644@core.coreip.homeip.net>

On Tue, May 11, 2010 at 02:21, Dmitry Torokhov wrote:
> On Tue, May 11, 2010 at 02:11:41AM -0400, Mike Frysinger wrote:
>> On Tue, May 11, 2010 at 02:05, Dmitry Torokhov wrote:
>> > On Mon, May 10, 2010 at 02:22:25PM -0700, Andrew Morton wrote:
>> >> On Mon, 10 May 2010 12:42:34 +0200 Oskar Schirmer wrote:
>> >> > With dma based spi transmission, data corruption
>> >> > is observed occasionally. With dma buffers located
>> >> > right next to msg and xfer fields, cache lines
>> >> > correctly flushed in preparation for dma usage
>> >> > may be polluted again when writing to fields
>> >> > in the same cache line.
>> >> >
>> >> > Make sure cache fields used with dma do not
>> >> > share cache lines with fields changed during
>> >> > dma handling. As both fields are part of a
>> >> > struct that is allocated via kzalloc, thus
>> >> > cache aligned, moving the fields to the 1st
>> >> > position and insert padding for alignment
>> >> > does the job.
>> >>
>> >> This sounds odd.  Doesn't it imply that some code somewhere is missing
>> >> some DMA synchronisation actions?
>> >>
>> >> >
>> >> > v2: add a comment to explain why alignment is needed
>> >> >
>> >> > v3: fix the typo in comment and layout (- to end of line)
>> >> >
>> >> > diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
>> >> > index 885354c..9ebb1b4 100644
>> >> > --- a/drivers/input/touchscreen/ad7877.c
>> >> > +++ b/drivers/input/touchscreen/ad7877.c
>> >> > @@ -153,15 +153,29 @@ enum {
>> >> >   */
>> >> >
>> >> >  struct ser_req {
>> >> > +   u16                     sample;
>> >> > +   /*
>> >> > +    * DMA (thus cache coherency maintenance) requires the
>> >> > +    * transfer buffers to live in their own cache lines.
>> >> > +    */
>> >> > +   char                    __padalign[L1_CACHE_BYTES - sizeof(u16)];
>> >>
>> >> It would be better to use __cacheline_aligned, rather than open-coding
>> >> things in this manner.
>> >>
>> >
>> > OK, then I have the following which I will apply unless someone shouts.
>> >
>> > --
>> > Dmitry
>> >
>> > Input: ad7877 - keep dma rx buffers in seperate cache lines
>> >
>> > From: Oskar Schirmer <os@emlix.com>
>> >
>> > With dma based spi transmission, data corruption is observed
>> > occasionally. With dma buffers located right next to msg and
>> > xfer fields, cache lines correctly flushed in preparation for
>> > dma usage may be polluted again when writing to fields in the
>> > same cache line.
>> >
>> > Make sure cache fields used with dma do not share cache lines
>> > with fields changed during dma handling. As both fields are part
>> > of a struct that is allocated via kzalloc, thus cache aligned,
>> > moving the fields to the 1st position and insert padding for
>> > alignment does the job.
>> >
>> > Signed-off-by: Oskar Schirmer <os@emlix.com>
>> > Signed-off-by: Daniel Glöckner <dg@emlix.com>
>> > Signed-off-by: Oliver Schneidewind <osw@emlix.com>
>> > Signed-off-by: Johannes Weiner <jw@emlix.com>
>> > Acked-by: Mike Frysinger <vapier@gentoo.org>
>> > [dtor@mail.ru - changed to use ___cacheline_aligned at suggestion
>> >  of akpm]
>> > Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
>> > ---
>> >
>> >  drivers/input/touchscreen/ad7877.c |   15 ++++++++++++---
>> >  1 files changed, 12 insertions(+), 3 deletions(-)
>> >
>> >
>> > diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
>> > index e019d53..0d2d7e5 100644
>> > --- a/drivers/input/touchscreen/ad7877.c
>> > +++ b/drivers/input/touchscreen/ad7877.c
>> > @@ -156,9 +156,14 @@ struct ser_req {
>> >        u16                     reset;
>> >        u16                     ref_on;
>> >        u16                     command;
>> > -       u16                     sample;
>> >        struct spi_message      msg;
>> >        struct spi_transfer     xfer[6];
>> > +
>> > +       /*
>> > +        * DMA (thus cache coherency maintenance) requires the
>> > +        * transfer buffers to live in their own cache lines.
>> > +        */
>> > +       u16 sample ____cacheline_aligned;
>> >  };
>> >
>> >  struct ad7877 {
>> > @@ -182,8 +187,6 @@ struct ad7877 {
>> >        u8                      averaging;
>> >        u8                      pen_down_acc_interval;
>> >
>> > -       u16                     conversion_data[AD7877_NR_SENSE];
>> > -
>> >        struct spi_transfer     xfer[AD7877_NR_SENSE + 2];
>> >        struct spi_message      msg;
>> >
>> > @@ -195,6 +198,12 @@ struct ad7877 {
>> >        spinlock_t              lock;
>> >        struct timer_list       timer;          /* P: lock */
>> >        unsigned                pending:1;      /* P: lock */
>> > +
>> > +       /*
>> > +        * DMA (thus cache coherency maintenance) requires the
>> > +        * transfer buffers to live in their own cache lines.
>> > +        */
>> > +       u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned;
>> >  };
>>
>> i'm not sure this is correct.  the cached_aligned attribute makes sure
>> it starts on a cache boundary, but it doesnt make sure it pads out to
>> one.  so it might work more of the time, but i dont think it's
>> guaranteed.
>
> The buffers are moved to the end of the structure - there is nothing
> else there.

what guarantee exactly do you have for that statement ?
-mike

  reply	other threads:[~2010-05-11  6:23 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-06 10:37 [PATCH] ad7877: fix spi word size to 16 bit Oskar Schirmer
2010-05-06 10:37 ` [PATCH] ad7877: keep dma rx buffers in seperate cache lines Oskar Schirmer
2010-05-06 18:46   ` Mike Frysinger
2010-05-07 10:15     ` Oskar Schirmer
2010-05-07 18:28       ` Mike Frysinger
2010-05-08 22:32         ` Johannes Weiner
2010-05-09  4:45           ` Mike Frysinger
2010-05-09  8:50             ` Oskar Schirmer
2010-05-07 12:07     ` Johannes Weiner
2010-05-10 10:34   ` [PATCH v2] " Oskar Schirmer
2010-05-10 10:42     ` [PATCH v3] " Oskar Schirmer
2010-05-10 16:39       ` Mike Frysinger
2010-05-10 20:54         ` Dmitry Torokhov
2010-05-10 21:22       ` Andrew Morton
2010-05-10 21:27         ` Mike Frysinger
2010-05-11  6:05         ` Dmitry Torokhov
2010-05-11  6:11           ` Mike Frysinger
2010-05-11  3:20             ` Andrew Morton
2010-05-11  6:21             ` Dmitry Torokhov
2010-05-11  6:23               ` Mike Frysinger [this message]
2010-05-11  6:33                 ` Dmitry Torokhov
2010-05-11  6:37                   ` Mike Frysinger
2010-05-11  6:42                   ` Pekka Enberg
2010-05-11 13:57                     ` Christoph Lameter
2010-05-11 16:52                     ` Dmitry Torokhov
2010-05-11 17:31                       ` Mike Frysinger
2010-05-11 18:59                       ` Pekka Enberg
2010-05-11 20:03                     ` Mike Frysinger
2010-05-11 20:07                       ` Matt Mackall
2010-05-11 20:10                         ` Mike Frysinger
2010-05-11 20:21                           ` Christoph Lameter
2010-05-11 20:34                             ` Mike Frysinger
2010-05-11 20:38                               ` Pekka Enberg
2010-05-11 20:43                                 ` Mike Frysinger
2010-05-11 20:47                                   ` Pekka Enberg
2010-05-13  6:21                                     ` Paul Mundt
2010-05-11 20:46                               ` Christoph Lameter
2010-05-11 20:54                                 ` Mike Frysinger
2010-05-11 21:01                                   ` Pekka Enberg
2010-05-11 21:11                                     ` Mike Frysinger
2010-05-12  1:58                                     ` FUJITA Tomonori
     [not found]                                   ` <20100511214836.GH1726@emlix.com>
2010-05-11 21:53                                     ` Dmitry Torokhov
2010-05-11 22:39                                       ` Mike Frysinger
2010-05-12  2:07                                         ` [LKML] " Marc Gauthier
2010-05-12  3:03                                           ` Nick Piggin
2010-05-12  3:23                                             ` FUJITA Tomonori
2010-05-12  4:35                                               ` Mike Frysinger
2010-05-12  5:28                                                 ` FUJITA Tomonori
2010-05-12 14:37                                                   ` Mike Frysinger
2010-05-12 18:11                                                     ` Dmitry Torokhov
2010-05-12 18:28                                                       ` Mike Frysinger
2010-05-12 10:36                                                 ` Johannes Weiner
2010-05-12 12:35                                                 ` Marc Gauthier
2010-05-12 14:36                                                   ` Mike Frysinger
2010-05-19 12:48                                             ` David Woodhouse
2010-05-19 13:07                                               ` Nick Piggin
2010-05-19 13:17                                                 ` David Woodhouse
2010-05-19 13:36                                                   ` Nick Piggin
2010-05-19 13:44                                                     ` Johannes Weiner
2010-05-19 13:52                                                       ` Nick Piggin
2010-05-19 14:38                                                         ` FUJITA Tomonori
2010-05-19 14:58                                                           ` David Woodhouse
2010-05-20  4:42                                                             ` FUJITA Tomonori
2010-05-19 16:37                                                           ` Dmitry Torokhov
2010-05-19 15:00                                                         ` Johannes Weiner
2010-05-17  6:12                                         ` Michal Simek
2010-05-19 13:00                                   ` David Woodhouse
2010-05-11 22:37                               ` Alan Cox
2010-05-11 20:22                           ` Pekka Enberg
2010-05-11 14:12           ` Oskar Schirmer
2010-05-06 11:18 ` [PATCH] ad7877: fix spi word size to 16 bit Hennerich, Michael
2010-05-06 18:26 ` Mike Frysinger
2010-05-07  9:41   ` Daniel Glöckner
2010-05-07 18:23     ` Mike Frysinger
2010-05-13  7:53       ` Dmitry Torokhov
2010-05-15 18:15         ` Oskar Schirmer
2010-05-16 19:25           ` Mike Frysinger
2010-05-17  7:29             ` Oskar Schirmer
2010-05-17  8:14               ` Hennerich, Michael
2010-05-17  8:41                 ` Oskar Schirmer
2010-05-17 23:49               ` Mike Frysinger
2010-05-18  0:18                 ` H Hartley Sweeten
2010-05-18  8:32                   ` Oskar Schirmer
2010-05-18  9:37                 ` Daniel Glöckner
2010-05-18  8:34 ` [PATCH v2] " Oskar Schirmer

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=AANLkTiktu7N5IXknkkJ9D5L4z5plhuGvD45IVqJm9zG1@mail.gmail.com \
    --to=vapier.adi@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=akpm@linux-foundation.org \
    --cc=dg@emlix.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jw@emlix.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=os@emlix.com \
    --cc=osw@emlix.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).