From: Ingo Molnar <mingo@kernel•org>
To: Pavel Machek <pavel@ucw•cz>
Cc: Thomas Gleixner <tglx@linutronix•de>,
David Laight <David.Laight@ACULAB•COM>,
'Rahul Lakkireddy' <rahul.lakkireddy@chelsio•com>,
"x86@kernel•org" <x86@kernel•org>,
"linux-kernel@vger•kernel.org" <linux-kernel@vger•kernel.org>,
"netdev@vger•kernel.org" <netdev@vger•kernel.org>,
"mingo@redhat•com" <mingo@redhat•com>,
"hpa@zytor•com" <hpa@zytor•com>,
"davem@davemloft•net" <davem@davemloft•net>,
"akpm@linux-foundation•org" <akpm@linux-foundation•org>,
"torvalds@linux-foundation•org" <torvalds@linux-foundation•org>,
"ganeshgr@chelsio•com" <ganeshgr@chelsio•com>,
"nirranjan@chelsio•com" <nirranjan@chelsio•com>,
"indranil@chelsio•com" <indranil@chelsio•com>,
Andy Lutomirski <luto@kernel•org>,
Peter Zijlstra <a.p.zijlstra@chello•nl>,
Fenghua Yu <fenghua.yu@intel•com
Subject: Re: [RFC PATCH 0/3] kernel: add support for 256-bit IO access
Date: Tue, 3 Apr 2018 12:36:55 +0200 [thread overview]
Message-ID: <20180403103655.oa235p3h65twf4ct@gmail.com> (raw)
In-Reply-To: <20180403084932.GA3926@amd>
* Pavel Machek <pavel@ucw•cz> wrote:
> > > > Yeah, so generic memcpy() replacement is only feasible I think if the most
> > > > optimistic implementation is actually correct:
> > > >
> > > > - if no preempt disable()/enable() is required
> > > >
> > > > - if direct access to the AVX[2] registers does not disturb legacy FPU state in
> > > > any fashion
> > > >
> > > > - if direct access to the AVX[2] registers cannot raise weird exceptions or have
> > > > weird behavior if the FPU control word is modified to non-standard values by
> > > > untrusted user-space
> > > >
> > > > If we have to touch the FPU tag or control words then it's probably only good for
> > > > a specialized API.
> > >
> > > I did not mean to have a general memcpy replacement. Rather something like
> > > magic_memcpy() which falls back to memcpy when AVX is not usable or the
> > > length does not justify the AVX stuff at all.
> >
> > OK, fair enough.
> >
> > Note that a generic version might still be worth trying out, if and only if it's
> > safe to access those vector registers directly: modern x86 CPUs will do their
> > non-constant memcpy()s via the common memcpy_erms() function - which could in
> > theory be an easy common point to be (cpufeatures-) patched to an AVX2 variant, if
> > size (and alignment, perhaps) is a multiple of 32 bytes or so.
>
> How is AVX2 supposed to help the memcpy speed?
>
> If the copy is small, constant overhead will dominate, and I don't
> think AVX2 is going to be win there.
There are several advantages:
1)
"REP; MOVS" (also called ERMS) has a significant constant "setup cost".
In the scheme I suggested (and if it's possible) then single-register AVX2 access
on the other hand has a setup cost on the "few cycles" order of magnitude.
2)
AVX2 have various non-temporary load and store behavioral variants - while "REP;
MOVS" doesn't (or rather, any such caching optimizations, to the extent they
exist, are hidden in the microcode).
> If the copy is big, well, the copy loop will likely run out of L1 and maybe even
> out of L2, and at that point speed of the loop does not matter because memory is
> slow...?
In many cases "memory" will be something very fast, such as another level of
cache. Also, on NUMA "memory" can also be something locally wired to the CPU -
again accessible at ridiculous bandwidths.
Nevertheless ERMS is probably wins for the regular bulk memcpy by a few percentage
points, so I don't think AVX2 is a win in the generic large-memcpy case, as long
as continued caching of both the loads and the stores is beneficial.
Thanks,
Ingo
next prev parent reply other threads:[~2018-04-03 10:36 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-19 14:20 [RFC PATCH 0/3] kernel: add support for 256-bit IO access Rahul Lakkireddy
2018-03-19 14:20 ` [RFC PATCH 1/3] include/linux: add 256-bit IO accessors Rahul Lakkireddy
2018-03-19 14:20 ` [RFC PATCH 2/3] x86/io: implement 256-bit IO read and write Rahul Lakkireddy
2018-03-19 14:43 ` Thomas Gleixner
2018-03-20 13:32 ` Rahul Lakkireddy
2018-03-20 13:44 ` Andy Shevchenko
2018-03-21 12:27 ` Rahul Lakkireddy
2018-03-20 14:40 ` David Laight
2018-03-21 12:28 ` Rahul Lakkireddy
2018-03-20 14:42 ` Alexander Duyck
2018-03-21 12:28 ` Rahul Lakkireddy
2018-03-22 1:26 ` Linus Torvalds
2018-03-22 10:48 ` David Laight
2018-03-22 17:16 ` Linus Torvalds
2018-03-19 14:20 ` [RFC PATCH 3/3] cxgb4: read on-chip memory 256-bits at a time Rahul Lakkireddy
2018-03-19 14:53 ` [RFC PATCH 0/3] kernel: add support for 256-bit IO access David Laight
2018-03-19 15:05 ` Thomas Gleixner
2018-03-19 15:19 ` David Laight
2018-03-19 15:37 ` Thomas Gleixner
2018-03-19 15:53 ` David Laight
2018-03-19 16:29 ` Linus Torvalds
2018-03-20 8:26 ` Ingo Molnar
2018-03-20 8:38 ` Thomas Gleixner
2018-03-20 9:08 ` Ingo Molnar
2018-03-20 9:41 ` Thomas Gleixner
2018-03-20 9:59 ` David Laight
2018-03-20 10:54 ` Ingo Molnar
2018-03-20 13:30 ` David Laight
2018-04-03 8:49 ` Pavel Machek
2018-04-03 10:36 ` Ingo Molnar [this message]
2018-03-20 14:57 ` Andy Lutomirski
2018-03-20 15:10 ` David Laight
2018-03-21 0:39 ` Andy Lutomirski
2018-03-20 18:01 ` Linus Torvalds
2018-03-21 6:32 ` Ingo Molnar
2018-03-21 15:45 ` Andy Lutomirski
2018-03-22 9:36 ` Ingo Molnar
2018-03-21 7:46 ` Ingo Molnar
2018-03-21 18:15 ` Linus Torvalds
2018-03-22 9:33 ` Ingo Molnar
2018-03-22 17:40 ` Alexei Starovoitov
2018-03-22 17:44 ` Andy Lutomirski
2018-03-22 10:35 ` David Laight
2018-03-22 12:48 ` David Laight
2018-03-22 17:07 ` Linus Torvalds
2018-03-19 15:27 ` Christoph Hellwig
2018-03-20 13:45 ` Rahul Lakkireddy
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=20180403103655.oa235p3h65twf4ct@gmail.com \
--to=mingo@kernel$(echo .)org \
--cc=David.Laight@ACULAB$(echo .)COM \
--cc=a.p.zijlstra@chello$(echo .)nl \
--cc=akpm@linux-foundation$(echo .)org \
--cc=davem@davemloft$(echo .)net \
--cc=fenghua.yu@intel$(echo .)com \
--cc=ganeshgr@chelsio$(echo .)com \
--cc=hpa@zytor$(echo .)com \
--cc=indranil@chelsio$(echo .)com \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=luto@kernel$(echo .)org \
--cc=mingo@redhat$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=nirranjan@chelsio$(echo .)com \
--cc=pavel@ucw$(echo .)cz \
--cc=rahul.lakkireddy@chelsio$(echo .)com \
--cc=tglx@linutronix$(echo .)de \
--cc=torvalds@linux-foundation$(echo .)org \
--cc=x86@kernel$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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