Re: [RFC PATCH 04/11] x86,fpu: defer FPU restore until return to userspace

From: Oleg Nesterov
Date: Tue Jan 13 2015 - 10:54:44 EST


On 01/11, riel@xxxxxxxxxx wrote:
>
> @@ -382,6 +382,7 @@ static inline void drop_init_fpu(struct task_struct *tsk)
> else
> fxrstor_checking(&init_xstate_buf->i387);
> }
> + clear_thread_flag(TIF_LOAD_FPU);

OK, in this case tsk should be current. Still I think clear_tsk_thread_flag()
will look more consistent.

> @@ -435,24 +436,32 @@ static inline void switch_fpu_prepare(struct task_struct *old, struct task_struc
> prefetch(new->thread.fpu.state);

I am wondering if these prefetch()es in switch_fpu_prepare() make
sense after this patch.

> + } else
> + /*
> + * The new task does not want an FPU state restore,
> + * and may not even have an FPU state. However, the
> + * old task may have left TIF_LOAD_FPU set.
> + * Clear it to avoid trouble.
> + *
> + * CR0.TS is still set from a previous FPU switch
> + */
> + clear_thread_flag(TIF_LOAD_FPU);

I got lost ;) Simply can't understand what this change tries to do.

And it looks "obviously wrong"... OK, suppose that a TIF_LOAD_FPU task
schedules before it returns to user mode (and calls switch_fpu_finish).
Why should we clear its flag if the new task doesn't want FPU ?

"CR0.TS is still set" is not true if use_eager_fpu()... OTOH, .TS can
be also set even if preload == T above, when we set TIF_LOAD_FPU.

> -static inline void switch_fpu_finish(struct task_struct *new)
> +static inline void switch_fpu_finish(void)
> {
> - if (test_and_clear_thread_flag(TIF_LOAD_FPU)) {
> - __thread_fpu_begin(new);
> - if (unlikely(restore_fpu_checking(new)))
> - drop_init_fpu(new);
> - }
> + struct task_struct *tsk = current;
> +
> + __thread_fpu_begin(tsk);
> +
> + if (unlikely(restore_fpu_checking(tsk)))
> + drop_init_fpu(tsk);
> }

Again, I am totally confused. After this patch the usage of set_thread_flag()
in switch_fpu_prepare() becomes wrong (see my reply to 2/11), but it is quite
possible I misunderstood these patches.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/