All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: memcpy_to/fromio() is badly optimised on x86
Date: Wed, 22 Nov 2017 10:43:02 +0000	[thread overview]
Message-ID: <7d8a76ecde8b47bfacba60373c1f6f96@AcuMS.aculab.com> (raw)

I believe that it is valid to use memcpy_to/fromio() to copy
data to/from memory BARs on PCIe cards.

However on x86 they are both aliases for memcpy().

The x86 kernel has several implementations of memcpy().
The 'best' one for the current cpu is selected during boot.

For more recent Intel cpus (probably Haswell and later) the
selected implementation is just 'rep movsb' relying on
the hardware to do all its 'clever' optimisations.

These optimisations are only done for cached addresses,
for uncached ones (and definitely for PCIe ones) single
byte copies are used.
(Verified on 4.13 with a PCIe monitor (of sorts).)

With the typical large read latency of PCIe this makes
memcpy_fromio() particularly painful.

memcpy_to/fromio() should be using 'rep movsd' for
the bulk of the copy.

	David

                 reply	other threads:[~2017-11-22 10:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=7d8a76ecde8b47bfacba60373c1f6f96@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.