From: Ingo Molnar <mingo@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>, Fenghua Yu <fenghua.yu@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 054/208] x86/fpu: Get rid of PF_USED_MATH usage, convert it to fpu->fpstate_active
Date: Wed, 6 May 2015 05:24:11 +0200 [thread overview]
Message-ID: <20150506032411.GA11779@gmail.com> (raw)
In-Reply-To: <CALCETrW0MrwgzXtL0=FJ8skcvr+wUSdHE7RDnei-Ng1YXLaU8Q@mail.gmail.com>
* Andy Lutomirski <luto@amacapital.net> wrote:
> > diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h
> > index efb520dcf38e..f6317d9aa808 100644
> > --- a/arch/x86/include/asm/fpu/types.h
> > +++ b/arch/x86/include/asm/fpu/types.h
> > @@ -137,6 +137,12 @@ struct fpu {
> > * deal with bursty apps that only use the FPU for a short time:
> > */
> > unsigned char counter;
> > + /*
> > + * This flag indicates whether this context is fpstate_active: if the task is
> > + * not running then we can restore from this context, if the task
> > + * is running then we should save into this context.
> > + */
> > + unsigned char fpstate_active;
>
> I don't understand. What does it mean if !fpstate_active?
Yeah, so this was just the 'simple' migration patch from PF_USED_FPU
to ->fpstate_active.
At the end of the series those fields get more love and a more
detailed explanation:
/*
* @fpstate_active:
*
* This flag indicates whether this context is active: if the task
* is not running then we can restore from this context, if the task
* is running then we should save into this context.
*/
unsigned char fpstate_active;
and its interaction with fpregs_active is explained as well:
/*
* @fpregs_active:
*
* This flag determines whether a given context is actively
* loaded into the FPU's registers and that those registers
* represent the task's current FPU state.
*
* Note the interaction with fpstate_active:
*
* # task does not use the FPU:
* fpstate_active == 0
*
* # task uses the FPU and regs are active:
* fpstate_active == 1 && fpregs_active == 1
*
* # the regs are inactive but still match fpstate:
* fpstate_active == 1 && fpregs_active == 0 && fpregs_owner == fpu
*
* The third state is what we use for the lazy restore optimization
* on lazy-switching CPUs.
*/
unsigned char fpregs_active;
Basically the 'fpstate' is the in-memory FPU state, and if it's
active, it means it can be copied to (saved to) and copied from
(restored from). Whether this fpstate is the currently representative
FPU state depends on the other state flag(s), as described.
Maybe I should have broken out the fourth state as well:
* # the fpstate holds all of a task's FPU state:
* fpstate_active == 1 && fpregs_active == 0 && fpregs_owner != fpu
?
active/inactive was one idiom that I felt worked pretty well - but I
considered others as well:
- dirty/clean (didn't work so well and too MM-ish)
- valid/invalid (likewise)
- used/unused (yuck)
Note:
There's a fifth valid state as well, but I did not want
to complicate the description even more: kernel_user_begin()/end()
users create this state with its own private in_kernel_fpu flag, in
that they use FPU registers but don't touch these (user-)flags.
kernel_user_begin()/end() is atomic and (beyond zapping pending lazy
restore state in fpu_fpregs_owner_ctx) it restores the FPU to the
previous state so it's pretty orthogonal as far as the other states
are concerned.
Note2:
I also considered renaming kernel_fpu_begin()/end() to the new
nomenclature, but it has a good name and I did not want too much
churn with a well-established API, which also mirrors
user_fpu_begin() conceptually. I also couldn't find a better name:
maybe fpu__kernel_save()/restore(), but that felt a bit strained.
Does this make things clearer? I can work on it some more if I got it
wrong or if the text is confusing somewhere, this is crucial IMHO.
Instead of binary states we could also unify them into a single state
variable - didn't find any really convincing naming concept for that
though, mostly because I think those states are fundamentally
separate, just interrelated.
Thanks,
Ingo
next prev parent reply other threads:[~2015-05-06 3:24 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 16:23 [PATCH 000/208] big x86 FPU code rewrite Ingo Molnar
2015-05-05 16:23 ` [PATCH 001/208] x86/fpu: Rename unlazy_fpu() to fpu__save() Ingo Molnar
2015-05-05 16:23 ` [PATCH 002/208] x86/fpu: Add comments to fpu__save() and restrict its export Ingo Molnar
2015-05-05 16:23 ` [PATCH 003/208] x86/fpu: Add debugging check to fpu__save() Ingo Molnar
2015-05-05 16:23 ` [PATCH 004/208] x86/fpu: Rename fpu_detect() to fpu__detect() Ingo Molnar
2015-05-05 16:23 ` [PATCH 005/208] x86/fpu: Remove stale init_fpu() prototype Ingo Molnar
2015-05-05 16:23 ` [PATCH 006/208] x86/fpu: Split an fpstate_alloc_init() function out of init_fpu() Ingo Molnar
2015-05-05 16:23 ` [PATCH 007/208] x86/fpu: Make init_fpu() static Ingo Molnar
2015-05-05 16:23 ` [PATCH 008/208] x86/fpu: Rename init_fpu() to fpu__unlazy_stopped() and add debugging check Ingo Molnar
2015-05-05 16:23 ` [PATCH 009/208] x86/fpu: Optimize fpu__unlazy_stopped() Ingo Molnar
2015-05-05 16:23 ` [PATCH 010/208] x86/fpu: Simplify fpu__unlazy_stopped() Ingo Molnar
2015-05-05 16:23 ` [PATCH 011/208] x86/fpu: Remove fpu_allocated() Ingo Molnar
2015-05-05 16:23 ` [PATCH 012/208] x86/fpu: Move fpu_alloc() out of line Ingo Molnar
2015-05-05 16:23 ` [PATCH 013/208] x86/fpu: Rename fpu_alloc() to fpstate_alloc() Ingo Molnar
2015-05-05 16:23 ` [PATCH 014/208] x86/fpu: Rename fpu_free() to fpstate_free() Ingo Molnar
2015-05-05 16:23 ` [PATCH 015/208] x86/fpu: Rename fpu_finit() to fpstate_init() Ingo Molnar
2015-05-05 16:23 ` [PATCH 016/208] x86/fpu: Rename fpu_init() to fpu__cpu_init() Ingo Molnar
2015-05-05 16:23 ` [PATCH 017/208] x86/fpu: Rename init_thread_xstate() to fpstate_xstate_init_size() Ingo Molnar
2015-05-05 16:23 ` [PATCH 018/208] x86/fpu: Move thread_info::fpu_counter into thread_info::fpu.counter Ingo Molnar
2015-05-05 16:23 ` [PATCH 019/208] x86/fpu: Improve the comment for the fpu::counter field Ingo Molnar
2015-05-05 16:24 ` [PATCH 020/208] x86/fpu: Move FPU data structures to asm/fpu_types.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 021/208] x86/fpu: Clean up asm/fpu/types.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 022/208] x86/fpu: Move i387.c and xsave.c to arch/x86/kernel/fpu/ Ingo Molnar
2015-05-05 16:24 ` [PATCH 023/208] x86/fpu: Fix header file dependencies of fpu-internal.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 024/208] x86/fpu: Split out the boot time FPU init code into fpu/init.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 025/208] x86/fpu: Remove unnecessary includes from core.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 026/208] x86/fpu: Move the no_387 handling and FPU detection code into init.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 027/208] x86/fpu: Remove the free_thread_xstate() complication Ingo Molnar
2015-05-05 16:24 ` [PATCH 028/208] x86/fpu: Factor out fpu__flush_thread() from flush_thread() Ingo Molnar
2015-05-05 16:24 ` [PATCH 029/208] x86/fpu: Move math_state_restore() to fpu/core.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 030/208] x86/fpu: Rename math_state_restore() to fpu__restore() Ingo Molnar
2015-05-05 16:24 ` [PATCH 031/208] x86/fpu: Factor out the FPU bug detection code into fpu__init_check_bugs() Ingo Molnar
2015-05-05 16:24 ` [PATCH 032/208] x86/fpu: Simplify the xsave_state*() methods Ingo Molnar
2015-05-05 16:24 ` [PATCH 033/208] x86/fpu: Remove fpu_xsave() Ingo Molnar
2015-05-05 16:24 ` [PATCH 034/208] x86/fpu: Move task_xstate_cachep handling to core.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 035/208] x86/fpu: Factor out fpu__copy() Ingo Molnar
2015-05-05 16:24 ` [PATCH 036/208] x86/fpu: Uninline fpstate_free() and move it next to the allocation function Ingo Molnar
2015-05-05 16:24 ` [PATCH 037/208] x86/fpu: Make task_xstate_cachep static Ingo Molnar
2015-05-05 16:24 ` [PATCH 038/208] x86/fpu: Make kernel_fpu_disable/enable() static Ingo Molnar
2015-05-05 16:24 ` [PATCH 039/208] x86/fpu: Add debug check to kernel_fpu_disable() Ingo Molnar
2015-05-05 16:24 ` [PATCH 040/208] x86/fpu: Add kernel_fpu_disabled() Ingo Molnar
2015-05-05 16:24 ` [PATCH 041/208] x86/fpu: Remove __save_init_fpu() Ingo Molnar
2015-05-05 16:24 ` [PATCH 042/208] x86/fpu: Move fpu_copy() to fpu/core.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 043/208] x86/fpu: Add debugging check to fpu_copy() Ingo Molnar
2015-05-05 16:24 ` [PATCH 044/208] x86/fpu: Print out whether we are doing lazy/eager FPU context switches Ingo Molnar
2015-05-05 16:24 ` [PATCH 045/208] x86/fpu: Eliminate the __thread_has_fpu() wrapper Ingo Molnar
2015-05-05 16:24 ` [PATCH 046/208] x86/fpu: Change __thread_clear_has_fpu() to 'struct fpu' parameter Ingo Molnar
2015-05-05 16:24 ` [PATCH 047/208] x86/fpu: Move 'PER_CPU(fpu_owner_task)' to fpu/core.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 048/208] x86/fpu: Change fpu_owner_task to fpu_fpregs_owner_ctx Ingo Molnar
2015-05-05 16:24 ` [PATCH 049/208] x86/fpu: Remove 'struct task_struct' usage from __thread_set_has_fpu() Ingo Molnar
2015-05-05 16:24 ` [PATCH 050/208] x86/fpu: Remove 'struct task_struct' usage from __thread_fpu_end() Ingo Molnar
2015-05-05 16:24 ` [PATCH 051/208] x86/fpu: Remove 'struct task_struct' usage from __thread_fpu_begin() Ingo Molnar
2015-05-05 16:24 ` [PATCH 052/208] x86/fpu: Open code PF_USED_MATH usages Ingo Molnar
2015-05-05 16:24 ` [PATCH 053/208] x86/fpu: Document fpu__unlazy_stopped() Ingo Molnar
2015-05-05 16:24 ` [PATCH 054/208] x86/fpu: Get rid of PF_USED_MATH usage, convert it to fpu->fpstate_active Ingo Molnar
2015-05-06 0:51 ` Andy Lutomirski
2015-05-06 3:24 ` Ingo Molnar [this message]
2015-05-05 16:24 ` [PATCH 055/208] x86/fpu: Remove 'struct task_struct' usage from drop_fpu() Ingo Molnar
2015-05-05 16:24 ` [PATCH 056/208] x86/fpu: Remove task_disable_lazy_fpu_restore() Ingo Molnar
2015-05-05 16:24 ` [PATCH 057/208] x86/fpu: Use 'struct fpu' in fpu_lazy_restore() Ingo Molnar
2015-05-05 16:24 ` [PATCH 058/208] x86/fpu: Use 'struct fpu' in restore_fpu_checking() Ingo Molnar
2015-05-05 16:24 ` [PATCH 059/208] x86/fpu: Use 'struct fpu' in fpu_reset_state() Ingo Molnar
2015-05-05 16:24 ` [PATCH 060/208] x86/fpu: Use 'struct fpu' in switch_fpu_prepare() Ingo Molnar
2015-05-05 16:24 ` [PATCH 061/208] x86/fpu: Use 'struct fpu' in switch_fpu_finish() Ingo Molnar
2015-05-05 16:24 ` [PATCH 062/208] x86/fpu: Move __save_fpu() into fpu/core.c Ingo Molnar
2015-05-05 16:24 ` [PATCH 063/208] x86/fpu: Use 'struct fpu' in __fpu_save() Ingo Molnar
2015-05-05 16:24 ` [PATCH 064/208] x86/fpu: Use 'struct fpu' in fpu__save() Ingo Molnar
2015-05-05 16:24 ` [PATCH 065/208] x86/fpu: Use 'struct fpu' in fpu_copy() Ingo Molnar
2015-05-05 16:24 ` [PATCH 066/208] x86/fpu: Use 'struct fpu' in fpu__copy() Ingo Molnar
2015-05-05 16:24 ` [PATCH 067/208] x86/fpu: Use 'struct fpu' in fpstate_alloc_init() Ingo Molnar
2015-05-05 16:24 ` [PATCH 068/208] x86/fpu: Use 'struct fpu' in fpu__unlazy_stopped() Ingo Molnar
2015-05-05 16:24 ` [PATCH 069/208] x86/fpu: Rename fpu__flush_thread() to fpu__clear() Ingo Molnar
2015-05-05 16:24 ` [PATCH 070/208] x86/fpu: Clean up fpu__clear() a bit Ingo Molnar
2015-05-05 16:24 ` [PATCH 071/208] x86/fpu: Rename i387.h to fpu/api.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 072/208] x86/fpu: Move xsave.h to fpu/xsave.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 073/208] x86/fpu: Rename fpu-internal.h to fpu/internal.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 074/208] x86/fpu: Move MXCSR_DEFAULT " Ingo Molnar
2015-05-05 16:24 ` [PATCH 075/208] x86/fpu: Remove xsave_init() __init obfuscation Ingo Molnar
2015-05-05 16:24 ` [PATCH 076/208] x86/fpu: Remove assembly guard from asm/fpu/api.h Ingo Molnar
2015-05-05 16:24 ` [PATCH 077/208] x86/fpu: Improve FPU detection kernel messages Ingo Molnar
2015-05-05 16:24 ` [PATCH 078/208] x86/fpu: Print supported xstate features in human readable way Ingo Molnar
2015-05-05 16:24 ` [PATCH 079/208] x86/fpu: Rename 'pcntxt_mask' to 'xfeatures_mask' Ingo Molnar
2015-05-05 17:14 ` [PATCH 000/208] big x86 FPU code rewrite Linus Torvalds
2015-05-05 17:50 ` Ingo Molnar
2015-07-17 23:52 ` Andy Lutomirski
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=20150506032411.GA11779@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox