[PATCH i-g-t 2/3] lib/xe_spin: Fix xe_spin_wait_started()

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Wed Jul 31 06:06:52 UTC 2024


On Tue, Jul 30, 2024 at 08:35:03PM -0700, Lucas De Marchi wrote:
> Use READ_ONCE() to guarantee we are actually reading the memory written
> by the GPU and compiler can't optimize it away.
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
> ---
>  lib/xe/xe_spin.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/xe/xe_spin.c b/lib/xe/xe_spin.c
> index 3adacc3a8..43a7a43c2 100644
> --- a/lib/xe/xe_spin.c
> +++ b/lib/xe/xe_spin.c
> @@ -166,7 +166,7 @@ void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts)
>   */
>  bool xe_spin_started(struct xe_spin *spin)
>  {
> -	return spin->start != 0;
> +	return READ_ONCE(spin->start) != 0;
>  }
>  
>  /**
> -- 
> 2.43.0
> 

Hmm, function is exported and would expect compiler will always
read the memory before return. This is part of .so and I don't
think this will be inlined to the caller. Where do you observe
gpu memory write is not reflected to the cpu?

--
Zbigniew



More information about the igt-dev mailing list