RE: [PATCH 3/9] net: xfrm: use this_cpu_ptr per-cpu helper

From: David Laight
Date: Thu Nov 01 2012 - 08:16:30 EST


> this_cpu_read
> |-----_this_cpu_generic_read
>
> #define _this_cpu_generic_read(pcp) \
> ({ typeof(pcp) ret__; \
> preempt_disable(); \
> ret__ = *this_cpu_ptr(&(pcp)); \
> preempt_enable(); \
> ret__; \
> })
>
>
> this_cpu_read operations locate per-cpu variable with preemption safeï not
> disable interrupts. why is it atomic vs interrupts?

Hmmm... what effect do those preemt_dis/enable() actually have?
Since a pre-empt can happen either side of them, the value
the caller sees can be for the wrong cpu anyway.

The only time I could see them being necessary is if
*this_cpu_ptr() itself needs mutex protection in order to
function correctly - and that is likely to be port specific.
On i386/amd64 where (I guess) it is an access offset by fs/gs
this isn't necessary and just wastes cpu cycles.

If the caller cares which cpu the value comes from (eg to
increment a counter) then the caller would need to disable
pre-emption across the whole operation.

David

èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—