Re: [PATCH] [5/20] x86: Introduce nsec_barrier()



On Thursday 03 January 2008 11:47:54 Ingo Molnar wrote:

* Andi Kleen <ak@xxxxxxx> wrote:

nsec_barrier() is a new barrier primitive that stops RDTSC speculation
to avoid races with timer interrupts on other CPUs.

Add it to all architectures. Except for x86 it is a nop right now. I
only tested x86, but it's a very simple change.

On x86 it expands either to LFENCE (for Intel CPUs) or MFENCE (for AMD
CPUs) which stops RDTSC on all currently known microarchitectures that
implement SSE. On CPUs without SSE there is generally no RDTSC
speculation.

i've picked up your rdtsc patches into x86.git but have simplified it:
there's no nsec_barrier() anymore - rdtsc() is always synchronous.
MFENCE/LFENCE is fast enough. Open-coding such barriers almost always
leads to needless trouble. Please check the next x86.git tree.

That's most likely wrong unless you added two barriers -- the barriers
are strictly need to be before and after RDTSC.

I still think having the open barrier is the better approach here.

It's also useful for performance measurements because it allows
a cheap way to measure a specific region with RDTSC

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



Relevant Pages

  • Re: [PATCH] [5/20] x86: Introduce nsec_barrier() II
    ... to avoid races with timer interrupts on other CPUs. ... Except for x86 it is a nop right now. ... On CPUs without SSE there is generally no RDTSC ... That's most likely wrong unless you added two barriers -- the barriers ...
    (Linux-Kernel)
  • Re: High resolution timer.
    ... It should run on Windows and Linux so there is no Win32 API. ... The first thing to use is RDTSC. ... What about multiple CPUs. ...
    (comp.lang.asm.x86)
  • Re: QueryPerformanceFrequency
    ... While rdtsc is one possible implementation, on some CPUs/systems the QPC needs to be implemented in a more complex manner ... I would definitely not recommend using rdtsc directly - it was quite a common practice in game programming to do this a few years back, and games which did it are experiencing serious compatibility issues recently. ... Alex Blekhman napsal: ...
    (microsoft.public.vc.language)
  • Re: [PATCH] [5/20] x86: Introduce nsec_barrier()
    ... to avoid races with timer interrupts on other CPUs. ... only tested x86, but it's a very simple change. ... On CPUs without SSE there is generally no RDTSC ...
    (Linux-Kernel)
  • Re: gettimeofday resolution seriously degraded in test9
    ... > modifies the gettimeofdayand the POSIX clock routines to ... > use rdtsc when available, a lot of problems will go away. ... sure most other modern cpus do too. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)