From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754186AbbE1TQL (ORCPT ); Thu, 28 May 2015 15:16:11 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:43222 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752130AbbE1TQI convert rfc822-to-8bit (ORCPT ); Thu, 28 May 2015 15:16:08 -0400 Message-ID: <1432840551.11346.8.camel@twins> Subject: Re: [patch] inherited events not signalling parent on overflow From: Peter Zijlstra To: Vince Weaver Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, eranian@google.com, Paul Mackerras , Arnaldo Carvalho de Melo Date: Thu, 28 May 2015 21:15:51 +0200 In-Reply-To: References: Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2015-05-28 at 15:06 -0400, Vince Weaver wrote: > We're trying to get self-monitoring multi-threaded sampling working in > PAPI. Fun times. > > Is this even possible? > > Ideally in your parent thread you could perf_event_open() with > inherit set. Then your program (say an OpenMP program) would do its thing > and all of the samples would get written back to the parent thread's > mmap() buffer. > > But this won't work as mmap'ing an inherited event is explicitly > disasllowed in events.c due to "performance reasons". > > Which is believable, it's just there's not really a good alternative that > doesn't involve having to somehow manually instrument every single > possible thread. What could maybe work -- I'd have to check the code -- is open a per-task-per-cpu counter for every cpu. Those we could inherit -- if we currently allow it I'm not sure of. The 'problem' is having multiple CPUs write into the same buffer, that's bad for performance because cacheline contention and the requirement for using atomic operations. Using per-task-per-cpu events side steps that. Of course, then you get to deal with nr_cpus buffers. > on a related note, I turned up the following issue when working on this > issue. I don't know if this is the proper fix but it makes my simple test > case behave as expected. > > > > If we inherit events, we inherit the signal state but not the fasync > state, so overflows in inherited children will never trigger the signal > handler. > > Signed-off-by: Vince Weaver > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 1a3bf48..7df4cf5 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -8626,6 +8630,8 @@ inherit_event(struct perf_event *parent_event, > child_event->overflow_handler_context > = parent_event->overflow_handler_context; > > + child_event->fasync = parent_event->fasync; > + > /* > * Precalculate sample_data sizes > */ Sounds right; but I've forgotten everything there is to forget about fasync. I'll go dig through those details again.