From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752113AbdKVKmp convert rfc822-to-8bit (ORCPT ); Wed, 22 Nov 2017 05:42:45 -0500 Received: from smtp-out4.electric.net ([192.162.216.182]:51784 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751863AbdKVKmn (ORCPT ); Wed, 22 Nov 2017 05:42:43 -0500 From: David Laight To: "'linux-kernel@vger.kernel.org'" Subject: memcpy_to/fromio() is badly optimised on x86 Thread-Topic: memcpy_to/fromio() is badly optimised on x86 Thread-Index: AdNjfqv6ERXM246CQJmsvkXiwMV7tQ== Date: Wed, 22 Nov 2017 10:43:02 +0000 Message-ID: <7d8a76ecde8b47bfacba60373c1f6f96@AcuMS.aculab.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Outbound-IP: 156.67.243.126 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuMS.aculab.com X-TLS: TLSv1.2:ECDHE-RSA-AES256-SHA384:256 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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