Re: [PATCH] 2.5.1-pre5: per-cpu areas

Andi Kleen (ak@suse.de)
Thu, 14 Mar 2002 19:51:22 +0100


On Thu, Mar 14, 2002 at 10:04:05AM -0800, David Mosberger wrote:
> How about the following proposal:
>
> - taking the address of this_cpu(var) is never allowed (can be
> enforced with RELOC_HIDE())
>
> - taking the address of per_cpu(var, n) is always legal and
> will return a pointer which will access CPU n's version of
> the variable, no matter what CPU dereferences the pointer
>
> Andi, I think this would take care of the x86-64 problem as well, right?

Yes, it would.

It would be a bit more overhead for taking the address than a
this_cpu_address(), because one would need to fetch the CPU number first
and do the arithmetic and the array reference instead of fetching the
address directly. But I agree that per_cpu() has much cleaner semantics than
this_cpu_address() for addresses, so it is worth it.

When one considers preemptive kernels where you can lose your CPU anytime
then it makes even more sense. But then this_cpu is only safe there when
you turn off preemption or hold some lock or run in interrupt context.
Outside such regions per_cpu() seems to be safer.

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