From: Ingo Molnar <mingo@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave@sr71.net>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
X86 ML <x86@kernel.org>, Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Oleg Nesterov <oleg@redhat.com>, Borislav Petkov <bp@alien8.de>,
Rik van Riel <riel@redhat.com>,
Suresh Siddha <sbsiddha@gmail.com>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH 02/19] x86, fpu: Wrap get_xsave_addr() to make it safer
Date: Fri, 29 May 2015 20:44:56 +0200 [thread overview]
Message-ID: <20150529184455.GA27501@gmail.com> (raw)
In-Reply-To: <CALCETrU5RB_-+F0jUH+Zz599zauV47CbN6CP1WWGC+L5CuYn2w@mail.gmail.com>
* Andy Lutomirski <luto@amacapital.net> wrote:
> > It's not that simple, because the decision is not 'lazy versus eager', but
> > 'mixed lazy/eager versus eager-only':
> >
> > Even on modern machines, if a task is not using the FPU (it's doing integer
> > only work, with short sleeps just shuffling around requests, etc.) then
> > context switches get up to 5-10% faster with lazy FPU restores.
>
> That's only sort of true. I'd believe that a context switch between two lazy
> tasks is 5-10% faster than a context switch between two eager tasks. I bet that
> a context switch between a lazy task and an eager task is a whole lot slower
> than a context switch between two eager tasks because manipulating CR0.TS is
> incredibly slow on all modern CPUs AFAICT. It's even worse in a VM guest.
>
> In other words, with lazy restore, we save the XRSTOR(S) and possibly a
> subsequent XSAVEOPT/XSAVES, but the cost is a MOV to CR0 and possibly a CLTS,
> and the MOV to CR0 is much, much slower than even a worst-case XRSTOR(S). In
> the worst lazy-restore case, we also pay a full exception roundtrip, and
> everything pales in comparison. If we're a guest, then there's probably a
> handful of exits thrown in for good measure.
>
> For true integer-only tasks, I think we should instead convince glibc to add
> things like vzeroall in convenient places to force as much xstate as possible to
> the init state, thus speeding up the optimized save/restore variants.
>
> I think the fundamental issue here is that CPU designers care about xstate
> save/restore/optimize performance, but they don't care at all about TS
> performance, so TS manipulations are probably microcoded and serializing.
That's definitely true.
Btw., potentially being able to get rid of lazy restores was why I wrote the
FPU-benchmarking code, and it gives these results on reasonably recent Intel CPUs:
CR0 reads are reasonably fast:
[ 0.519287] x86/fpu: Cost of: CR0 read : 4 cycles
but we can cache that so it doesn't help us.
writes are bad:
[ 0.528643] x86/fpu: Cost of: CR0 write : 208 cycles
and we cannot cache it, so that hurts us.
and a CR0::TS fault cost is horrible:
[ 0.538042] x86/fpu: Cost of: CR0::TS fault : 1156 cycles
and this is hurting us too.
Since the first version I have extended the benchmark with a cache-cold column as
well - in the cache cold case the difference is even more striking, and in may
cases context switches are cache cold.
Interestingly, this kind of high cost of CR0 related accesses is true even on
pretty old, 10+ years old x86 CPUs, per my measurements, so it's not limited to
modern x86 microarchitectures.
So yes, it would be nice to standardize on synchronous context switching of all
CPU state.
Thanks,
Ingo
next prev parent reply other threads:[~2015-05-29 18:45 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-27 18:36 [PATCH 00/19] x86, mpx updates for 4.2 (take 8) Dave Hansen
2015-05-27 18:36 ` [PATCH 01/19] x86, mpx, xsave: Fix up bad get_xsave_addr() assumptions Dave Hansen
2015-05-27 18:36 ` [PATCH 02/19] x86, fpu: Wrap get_xsave_addr() to make it safer Dave Hansen
2015-05-28 8:41 ` Ingo Molnar
2015-05-28 14:45 ` Dave Hansen
2015-05-28 15:01 ` Ingo Molnar
2015-05-28 16:02 ` Dave Hansen
2015-05-29 18:49 ` Ingo Molnar
2015-05-28 16:24 ` Dave Hansen
2015-05-29 1:05 ` Andy Lutomirski
2015-05-29 15:31 ` Dave Hansen
2015-05-29 16:10 ` Borislav Petkov
2015-05-29 18:51 ` Ingo Molnar
2015-05-29 18:17 ` Ingo Molnar
2015-05-29 18:29 ` Andy Lutomirski
2015-05-29 18:44 ` Ingo Molnar [this message]
2015-05-29 16:47 ` Dave Hansen
2015-05-29 18:48 ` Ingo Molnar
2015-05-27 18:36 ` [PATCH 03/19] x86, mpx: Use new get_xsave_field_ptr() Dave Hansen
2015-05-27 18:36 ` [PATCH 05/19] x86, mpx: remove redundant MPX_BNDCFG_ADDR_MASK Dave Hansen
2015-05-27 18:36 ` [PATCH 04/19] x86, mpx: Cleanup: Do not pass task around when unnecessary Dave Hansen
2015-05-27 18:36 ` [PATCH 06/19] x86, mpx: Restrict mmap size check to bounds tables Dave Hansen
2015-05-27 18:36 ` [PATCH 07/19] x86, mpx: boot-time disable Dave Hansen
2015-05-27 18:36 ` [PATCH 12/19] x86: make is_64bit_mm() widely available Dave Hansen
2015-05-27 18:36 ` [PATCH 08/19] x86, mpx: trace #BR exceptions Dave Hansen
2015-05-27 18:36 ` [PATCH 11/19] x86, mpx: trace allocation of new bounds tables Dave Hansen
2015-05-27 18:36 ` [PATCH 09/19] x86, mpx: trace entry to bounds exception paths Dave Hansen
2015-05-27 18:36 ` [PATCH 10/19] x86, mpx: Trace the attempts to find bounds tables Dave Hansen
2015-05-27 18:36 ` [PATCH 14/19] x86, mpx: new directory entry to addr helper Dave Hansen
2015-05-27 18:36 ` [PATCH 13/19] x86, mpx: Add temporary variable to reduce masking Dave Hansen
2015-05-27 18:36 ` [PATCH 15/19] x86, mpx: do 32-bit-only cmpxchg for 32-bit apps Dave Hansen
2015-05-27 18:36 ` [PATCH 16/19] x86, mpx: support 32-bit binaries on 64-bit kernel Dave Hansen
2015-05-27 18:36 ` [PATCH 17/19] x86, mpx: rewrite unmap code Dave Hansen
2015-05-27 18:36 ` [PATCH 19/19] x86, mpx: allow mixed binaries again Dave Hansen
2015-05-27 18:36 ` [PATCH 18/19] x86, mpx: do not count MPX VMAs as neighbors when unmapping Dave Hansen
-- strict thread matches above, loose matches on Subject: below --
2015-06-07 18:37 [PATCH 00/19] x86, mpx updates for 4.2 (take 9) Dave Hansen
2015-06-07 18:37 ` [PATCH 02/19] x86, fpu: Wrap get_xsave_addr() to make it safer Dave Hansen
2015-05-29 22:34 [PATCH 00/19] x86, mpx updates for 4.2 (take 8) Dave Hansen
2015-05-29 22:34 ` [PATCH 02/19] x86, fpu: Wrap get_xsave_addr() to make it safer Dave Hansen
2015-05-19 6:25 [PATCH 00/19] x86, mpx updates for 4.2 (take 7) Dave Hansen
2015-05-19 6:25 ` [PATCH 02/19] x86, fpu: Wrap get_xsave_addr() to make it safer Dave Hansen
2015-05-19 8:15 ` Thomas Gleixner
2015-05-08 18:59 [PATCH 00/19] x86, mpx updates for 4.2 (take 6) Dave Hansen
2015-05-08 18:59 ` [PATCH 02/19] x86, fpu: wrap get_xsave_addr() to make it safer Dave Hansen
2015-05-18 19:38 ` Thomas Gleixner
2015-05-18 19:42 ` Thomas Gleixner
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=20150529184455.GA27501@gmail.com \
--to=mingo@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dave@sr71.net \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=riel@redhat.com \
--cc=sbsiddha@gmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@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.