[RFC PATCH 07/13] arm64: percpu: Implement preemptible read/write ops

David Laight david.laight.linux at gmail.com
Tue Jul 28 14:47:55 PDT 2026


On Tue, 28 Jul 2026 13:38:53 +0100
Mark Rutland <mark.rutland at arm.com> wrote:

> Use the PCPU GPR infrastructure to implement preemptible this_cpu_read()
> and this_cpu_write().
...
>  #define this_cpu_write_1(pcp, val)	\
> -	_pcp_protect(__percpu_write_8, pcp, (unsigned long)val)
> +	_pcp_wrap(__percpu_write_8, pcp, (unsigned long)val)

Not new, but does that end up sign extending 'val' which is likely
to be more expensive than zero extending it?
Using '(val) + 0u + 0ul' might generate better code in some cases.

Just noticed it should be (unsigned long)(val) as well.
Otherwise this_cpu_write_n(pcp, -7 / 4) isn't going to DTRT.

	David

>  #define this_cpu_write_2(pcp, val)	\
> -	_pcp_protect(__percpu_write_16, pcp, (unsigned long)val)
> +	_pcp_wrap(__percpu_write_16, pcp, (unsigned long)val)
>  #define this_cpu_write_4(pcp, val)	\
> -	_pcp_protect(__percpu_write_32, pcp, (unsigned long)val)
> +	_pcp_wrap(__percpu_write_32, pcp, (unsigned long)val)
>  #define this_cpu_write_8(pcp, val)	\
> -	_pcp_protect(__percpu_write_64, pcp, (unsigned long)val)
> +	_pcp_wrap(__percpu_write_64, pcp, (unsigned long)val)
>  
>  #define this_cpu_add_1(pcp, val)	\
>  	_pcp_protect(__percpu_add_case_8, pcp, val)




More information about the linux-arm-kernel mailing list