Re: irqsafe_cpu_...() 64-bit operations on 32-bit platform

From: Jan Beulich
Date: Mon Jan 02 2012 - 03:58:57 EST


>>> On 23.12.11 at 16:13, Christoph Lameter <cl@xxxxxxxxx> wrote:
> On Fri, 23 Dec 2011, Jan Beulich wrote:
>
>> you introduced these for 2.6.33, but I wonder about their completeness
>
>> in the current state: On ix86, I can add, sub, xor, etc a 64-bit variable
>> this way (through the generic implementation), but there's no way to
>> read or write such a variable. While not documented explicitly, it seems
>> like the assumption is that this_cpu_{read,write}() can be used for this
>> purpose, but that's clearly wrong.
>
> Hmmm... We could add those but then you would usually not assign the
> initial values in a situation where concurrency is an issue. Typically you
> would have
> a loop over all possible cpus and then simply do a 64 bit assign to the 64
> bit values address determined via per_cpu_ptr().

You seem to assume that these would be used solely for statistical
values, but maintaining last seen values (e.g. obtained from an
underlying hypervisor) is just one other use.

> And yes reading could be an issue if you have concurrent updates ongoing.
>
> However, if you are using a loop to sum up all counters from every
> processor then you cannot use the this_cpu ops but would have to use
> something like get_64().

I understand that, but again statistics aren't my focus here.

> Reliably reading a 64 bit value on 32 bit may
> strangely require a write operation via cmpxchg8b.

Correct, but it would appear to be a read even to the compiler (only
the actual assembly implementation would have to know that it's
really a write).

Jan

--
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/