Skip to contentSkip to conversation

perf_mmap__write_tail() and control dependencies

DISCUSSION Paul E. McKenney 3 participants 5 messages Jul 24, 2015 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

Hello, Peter,

The ring-buffer code uses control dependencies, and the shiny new READ_ONCE_CTRL() is now in mainline. I was idly curious about whether the write side could use smp_store_release(), and I found this:

static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)

{
	struct perf_event_mmap_page *pc = md->base;

	/*
	 * ensure all reads are done before we write the tail out.
	 */
	mb();
	pc->data_tail = tail;
}

I see mb() rather than smp_mb(). Did I find the correct code for the write side? If so, why mb() rather than smp_mb()? To serialize against MMIO interactions with hardware counters or some such?

Thanx, Paul

#1 lore raw
Quoted 17 lines · Paul E. McKenney

Hello, Peter,

The ring-buffer code uses control dependencies, and the shiny new READ_ONCE_CTRL() is now in mainline. I was idly curious about whether the write side could use smp_store_release(), and I found this:

static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)

{
	struct perf_event_mmap_page *pc = md->base;

	/*
	 * ensure all reads are done before we write the tail out.
	 */
	mb();
	pc->data_tail = tail;
}
Quoted 3 lines

I see mb() rather than smp_mb(). Did I find the correct code for the write side? If so, why mb() rather than smp_mb()? To serialize against MMIO interactions with hardware counters or some such?

This is userspace, it doesn't patch itself depending on if its run on an SMP machine or not.

#2 lore raw
Quoted 18 lines · Peter Zijlstra
Quoted 17 lines · Paul E. McKenney

Hello, Peter,

The ring-buffer code uses control dependencies, and the shiny new READ_ONCE_CTRL() is now in mainline. I was idly curious about whether the write side could use smp_store_release(), and I found this:

static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)

{
	struct perf_event_mmap_page *pc = md->base;

	/*
	 * ensure all reads are done before we write the tail out.
	 */
	mb();
	pc->data_tail = tail;
}
Quoted 6 lines
Quoted 3 lines

I see mb() rather than smp_mb(). Did I find the correct code for the write side? If so, why mb() rather than smp_mb()? To serialize against MMIO interactions with hardware counters or some such?

This is userspace, it doesn't patch itself depending on if its run on an SMP machine or not.

Furthremore, reading the buffer is a much less frequent occurrence than writing entries to it. So its less performance critical.

#3 lore raw
In reply to Peter Zijlstra
Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Paul E. McKenney

The ring-buffer code uses control dependencies, and the shiny new READ_ONCE_CTRL() is now in mainline. I was idly curious about whether the write side could use smp_store_release(), and I found this:

static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)

{
	struct perf_event_mmap_page *pc = md->base;

	/*
	 * ensure all reads are done before we write the tail out.
	 */
	mb();
	pc->data_tail = tail;
}
Quoted 6 lines
Quoted 3 lines

I see mb() rather than smp_mb(). Did I find the correct code for the write side? If so, why mb() rather than smp_mb()? To serialize against MMIO interactions with hardware counters or some such?

This is userspace, it doesn't patch itself depending on if its run on an SMP machine or not.

Yup, and that's why mb() expands to dmb instead of dsb in tools/arch/arm64/include/asm/barrier.h (I see there's an XXX: comment there asking about the difference).

Will

#4 lore raw
Quoted 21 lines · Will Deacon
Quoted 20 lines · Peter Zijlstra
Quoted 18 lines · Paul E. McKenney

The ring-buffer code uses control dependencies, and the shiny new READ_ONCE_CTRL() is now in mainline. I was idly curious about whether the write side could use smp_store_release(), and I found this:

static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)

{
	struct perf_event_mmap_page *pc = md->base;

	/*
	 * ensure all reads are done before we write the tail out.
	 */
	mb();
	pc->data_tail = tail;
}

I see mb() rather than smp_mb(). Did I find the correct code for the write side? If so, why mb() rather than smp_mb()? To serialize against MMIO interactions with hardware counters or some such?

Quoted 6 lines
Quoted 2 lines

This is userspace, it doesn't patch itself depending on if its run on an SMP machine or not.

Yup, and that's why mb() expands to dmb instead of dsb in tools/arch/arm64/include/asm/barrier.h (I see there's an XXX: comment there asking about the difference).

Thank you both! I will therefore refrain from attempting to restrict READ_ONCE_CTRL() to pairing with smp_store_release(). ;-)

Thanx, Paul