From: "Borislav Petkov" <bp@alien8.de>
To: "Andrew Lutomirski" <luto@mit.edu>
Cc: "Borislav Petkov" <bp@alien8.de>,
"melwyn lobo" <linux.melwyn@gmail.com>,
"Denys Vlasenko" <vda.linux@googlemail.com>,
"Ingo Molnar" <mingo@elte.hu>,
linux-kernel@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
borislav.petkov@amd.com
Subject: Re: x86 memcpy performance
Date: Mon, 15 Aug 2011 20:49:56 +0200 (CEST) [thread overview]
Message-ID: <3175fc05afa1c2b0defd935d0fec22d5.squirrel@www.skyhub.de> (raw)
In-Reply-To: <CAObL_7ExSmbucefJ386LhK9UccVn5wKRvxHdLq0j__5bG2apwA@mail.gmail.com>
On Mon, 15 August, 2011 7:04 pm, Andrew Lutomirski wrote:
>> Well, I had a SSE memcpy which saved/restored the XMM regs on the stack.
>> This would obviate the need to muck with contexts but that could get
>> expensive wrt stack operations. The advantage is that I'm not dealing
>> with the whole FPU state but only with 16 XMM regs. I should probably
>> dust off that version again and retest.
>
> I bet it won't be a significant win. On Sandy Bridge, clts/stts takes
> 80 ns and a full state save+restore is only ~60 ns.
> Without infrastructure changes, I don't think you can avoid the clts
> and stts.
Yeah, probably.
> You might be able to get away with turning off IRQs, reading CR0 to
> check TS, pushing XMM regs, and being very certain that you don't
> accidentally generate any VEX-coded instructions.
That's ok - I'm using movaps/movups. But, the problem is that I still
need to save FPU state if the task I'm interrupting has been using FPU
instructions. So, I can't get away without saving the context in which
case I don't need to save the XMM regs anyway.
>> Or, if we want to use SSE stuff in the kernel, we might think of
>> allocating its own FPU context(s) and handle those...
>
> I'm thinking of having a stack of FPU states to parallel irq stacks
> and IST stacks.
... I'm guessing with the same nesting as hardirqs? Making FPU
instructions usable in irq contexts too.
> It gets a little hairy when code inside kernel_fpu_begin traps for a
> non-irq non-IST reason, though.
How does that happen? You're in the kernel with preemption disabled and
TS cleared, what would cause the #NM? I think that if you need to switch
context, you simply "push" the current FPU context, allocate a new one
and clts as part of the FPU context switching, no?
> Fortunately, those are rare and all of the EX_TABLE users could mark
> xmm regs as clobbered (except for copy_from_user...).
Well, copy_from_user... does a bunch of rep; movsq - if the SSE version
shows reasonable speedup there, we might need to make those work too.
> Keeping kernel_fpu_begin non-preemptable makes it less bad because the
> extra FPU state can be per-cpu and not per-task.
Yep.
> This is extra fun on 32 bit, which IIRC doesn't have IST stacks.
>
> The major speedup will come from saving state in kernel_fpu_begin but
> not restoring it until the code in entry_??.S restores registers.
But you'd need to save each kernel FPU state when nesting, no?
>>> (*) kernel_fpu_begin is a bad name. It's only safe to use integer
>>> instructions inside a kernel_fpu_begin section because MXCSR (and the
>>> 387 equivalent) could contain garbage.
>>
>> Well, do we want to use floating point instructions in the kernel?
>
> The only use I could find is in staging.
Exactly my point - I think we should do it only when it's really worth
the trouble.
--
Regards/Gruss,
Boris.
next prev parent reply other threads:[~2011-08-15 18:50 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-15 14:55 Borislav Petkov
2011-08-15 14:59 ` Andy Lutomirski
2011-08-15 15:29 ` Borislav Petkov
2011-08-15 15:36 ` Andrew Lutomirski
2011-08-15 16:12 ` Borislav Petkov
2011-08-15 17:04 ` Andrew Lutomirski
2011-08-15 18:49 ` Borislav Petkov [this message]
2011-08-15 19:11 ` Andrew Lutomirski
2011-08-15 20:05 ` Borislav Petkov
2011-08-15 20:08 ` Andrew Lutomirski
2011-08-15 16:12 ` H. Peter Anvin
2011-08-15 16:58 ` Andrew Lutomirski
2011-08-15 18:26 ` H. Peter Anvin
2011-08-15 18:35 ` Andrew Lutomirski
2011-08-15 18:52 ` H. Peter Anvin
2011-08-16 7:19 ` melwyn lobo
2011-08-16 7:43 ` Borislav Petkov
-- strict thread matches above, loose matches on Subject: below --
2011-08-12 17:59 melwyn lobo
2011-08-12 18:33 ` Andi Kleen
2011-08-12 19:52 ` Ingo Molnar
2011-08-14 9:59 ` Borislav Petkov
2011-08-14 11:13 ` Denys Vlasenko
2011-08-14 12:40 ` Borislav Petkov
2011-08-15 13:27 ` melwyn lobo
2011-08-15 13:44 ` Denys Vlasenko
2011-08-16 2:34 ` Valdis.Kletnieks
2011-08-16 12:16 ` Borislav Petkov
2011-09-01 15:15 ` Maarten Lankhorst
2011-09-01 16:18 ` Linus Torvalds
2011-09-08 8:35 ` Borislav Petkov
2011-09-08 10:58 ` Maarten Lankhorst
2011-09-09 8:14 ` Borislav Petkov
2011-09-09 10:12 ` Maarten Lankhorst
2011-09-09 11:23 ` Maarten Lankhorst
2011-09-09 13:42 ` Borislav Petkov
2011-09-09 14:39 ` Linus Torvalds
2011-09-09 15:35 ` Borislav Petkov
2011-12-05 12:20 ` melwyn lobo
2011-12-05 12:54 ` melwyn lobo
2011-12-05 14:36 ` Alan Cox
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=3175fc05afa1c2b0defd935d0fec22d5.squirrel@www.skyhub.de \
--to=bp@alien8.de \
--cc=a.p.zijlstra@chello.nl \
--cc=borislav.petkov@amd.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux.melwyn@gmail.com \
--cc=luto@mit.edu \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=vda.linux@googlemail.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
all inboxes | Powered by JetHome®