Re: [PATCH v2 15/17] x86: Add rdtsc_ordered() and use it in trivial call sites
From: Andy Lutomirski
Date: Sat Jun 13 2015 - 14:25:49 EST
On Sat, Jun 13, 2015 at 2:02 AM, Borislav Petkov <bp@xxxxxxx> wrote:
> On Fri, Jun 12, 2015 at 04:44:55PM -0700, Andy Lutomirski wrote:
>> barrier_before_rdtsc(); rdtsc_unordered() is an unnecessary mouthful and
>> requires more thought than should be necessary. Add an rdtsc_ordered()
>> helper and replace the trivial call sites with it.
>>
>> This should not change generated code.
>>
>> Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx>
>> ---
>
> ...
>
>> diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
>> index a47fb11af5f5..22d69d2d1f0d 100644
>> --- a/arch/x86/include/asm/msr.h
>> +++ b/arch/x86/include/asm/msr.h
>> @@ -148,6 +148,20 @@ static __always_inline void barrier_before_rdtsc(void)
>> "lfence", X86_FEATURE_LFENCE_RDTSC);
>> }
>>
>> +/**
>> + * rdtsc_ordered() - read the current TSC in program order
>> + *
>> + * rdtsc_ordered() returns the result of RDTSC as a 64-bit integer.
>> + * It is ordered like a load to a global in-memory counter. It should
>> + * be impossible to observe non-monotonic rdtsc_unordered() behavior
>> + * across multiple CPUs as long as the TSC is synced.
>> + */
>> +static __always_inline unsigned long long rdtsc_ordered(void)
>> +{
>> + barrier_before_rdtsc();
>> + return rdtsc_unordered();
>> +}
>> +
>
> I don't see the final tree state with all those applied (too lazy to
> apply them) but why not simply kill barrier_before_rdtsc() and inline
> the alternative into rdtsc_ordered()?
>
> I mean, I don't see usage for it somewhere else...
There's the awful, awful code in kvmclock. I'll fix that as part of
v3 and get rid of barrier_before_rdtsc().
--Andy
--
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/