public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* perf_mmap__write_tail() and control dependencies
@ 2015-07-24 15:29 Paul E. McKenney
  2015-07-24 15:33 ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Paul E. McKenney @ 2015-07-24 15:29 UTC (permalink / raw)
  To: peterz; +Cc: will.deacon, linux-kernel, linux-arch, paulus, rostedt

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: perf_mmap__write_tail() and control dependencies
  2015-07-24 15:29 perf_mmap__write_tail() and control dependencies Paul E. McKenney
@ 2015-07-24 15:33 ` Peter Zijlstra
  2015-07-24 15:35   ` Peter Zijlstra
  2015-07-24 15:36   ` Will Deacon
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Zijlstra @ 2015-07-24 15:33 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: will.deacon, linux-kernel, linux-arch, paulus, rostedt

On Fri, Jul 24, 2015 at 08:29:05AM -0700, Paul E. McKenney wrote:
> 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?

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: perf_mmap__write_tail() and control dependencies
  2015-07-24 15:33 ` Peter Zijlstra
@ 2015-07-24 15:35   ` Peter Zijlstra
  2015-07-24 15:36   ` Will Deacon
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2015-07-24 15:35 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: will.deacon, linux-kernel, linux-arch, paulus, rostedt

On Fri, Jul 24, 2015 at 05:33:16PM +0200, Peter Zijlstra wrote:
> On Fri, Jul 24, 2015 at 08:29:05AM -0700, Paul E. McKenney wrote:
> > 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?
> 
> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: perf_mmap__write_tail() and control dependencies
  2015-07-24 15:33 ` Peter Zijlstra
  2015-07-24 15:35   ` Peter Zijlstra
@ 2015-07-24 15:36   ` Will Deacon
  2015-07-24 15:49     ` Paul E. McKenney
  1 sibling, 1 reply; 5+ messages in thread
From: Will Deacon @ 2015-07-24 15:36 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Paul E. McKenney, linux-kernel@vger.kernel.org,
	linux-arch@vger.kernel.org, paulus@samba.org, rostedt@goodmis.org

On Fri, Jul 24, 2015 at 04:33:16PM +0100, Peter Zijlstra wrote:
> On Fri, Jul 24, 2015 at 08:29:05AM -0700, Paul E. McKenney wrote:
> > 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?
> 
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: perf_mmap__write_tail() and control dependencies
  2015-07-24 15:36   ` Will Deacon
@ 2015-07-24 15:49     ` Paul E. McKenney
  0 siblings, 0 replies; 5+ messages in thread
From: Paul E. McKenney @ 2015-07-24 15:49 UTC (permalink / raw)
  To: Will Deacon
  Cc: Peter Zijlstra, linux-kernel@vger.kernel.org,
	linux-arch@vger.kernel.org, paulus@samba.org, rostedt@goodmis.org

On Fri, Jul 24, 2015 at 04:36:20PM +0100, Will Deacon wrote:
> On Fri, Jul 24, 2015 at 04:33:16PM +0100, Peter Zijlstra wrote:
> > On Fri, Jul 24, 2015 at 08:29:05AM -0700, Paul E. McKenney wrote:
> > > 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?
> > 
> > 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-24 15:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-24 15:29 perf_mmap__write_tail() and control dependencies Paul E. McKenney
2015-07-24 15:33 ` Peter Zijlstra
2015-07-24 15:35   ` Peter Zijlstra
2015-07-24 15:36   ` Will Deacon
2015-07-24 15:49     ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox