Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753556AbdIDMI4 (ORCPT ); Mon, 4 Sep 2017 08:08:56 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:42081 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753480AbdIDMIz (ORCPT ); Mon, 4 Sep 2017 08:08:55 -0400 Date: Mon, 4 Sep 2017 14:08:43 +0200 From: Peter Zijlstra To: Alexey Budankov Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Andi Kleen , Kan Liang , Dmitri Prokhorov , Valery Cherepennikov , Mark Rutland , Stephane Eranian , David Carrillo-Cisneros , linux-kernel , Vince Weaver , Thomas Gleixner Subject: Re: [RFC][PATCH] perf: Rewrite enabled/running timekeeping Message-ID: <20170904120843.oazlv73phoxoinlj@hirez.programming.kicks-ass.net> References: <96c7776f-1f17-a39e-23e9-658596216d6b@linux.intel.com> <20170803150052.za2vofyqfgarukdr@hirez.programming.kicks-ass.net> <20170822204743.GR32112@worktop.programming.kicks-ass.net> <2a426aa2-42c8-e839-1cec-aa3971651f3e@linux.intel.com> <20170831171837.njnc6r6elsvkl7lt@hirez.programming.kicks-ass.net> <46f72a3f-f18b-0227-3d78-fb23c8a6e18e@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46f72a3f-f18b-0227-3d78-fb23c8a6e18e@linux.intel.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2357 Lines: 56 On Mon, Sep 04, 2017 at 01:46:45PM +0300, Alexey Budankov wrote: > > So the below completely rewrites timekeeping (and probably breaks > > world) but does away with the need to touch events that don't get > > scheduled. > > We still need and do iterate thru all events at some points e.g. on context switches. Why do we _need_ to? On ctx switch we should stop iteration for a PMU once we fail to schedule an event, same as for rotation. > > The basic idea is really simple, we have a single timestamp and > > depending on the state we update enabled/running. This obviously only > > requires updates when we change state and when we need up-to-date > > timestamps (read). > > I would prefer to have this rework in a FSM similar to that below, > so state transition and the corresponding tstamp, total_time_enabled > and total_time_running manipulation logic would be consolidated in > one place and adjacent lines of code. > > From the table below event->state FSM is not as simple as it may seem > on the first sight so in order to avoid regressions after rework we > better keep that in mind and explicitly implement allowed and disallowed > state transitions. Maybe if we introduce something like CONFIG_PERF_DEBUG, but I fear that for normal operation that's all fairly horrible overhead. > A I O E X D U > > A Te+,Tr+ Te+,Tr+ Te+,Tr+ Te+,Tr+ Te+,Tr+ Te+,Tr+ --- > ts ts ts ts ts ts > > I Te+,ts Te+,ts Te+,ts Te+,ts Te+,ts Te+,ts --- > > O Te=0,Tr=0, Te=0,Tr=0, Te=0,Tr=0 Te=0,Tr=0 Te=0,Tr=0 Te=0,Tr=0 --- > ts ts ts ts ts ts > > E Te=0,Tr=0, Te=0,Tr=0, Te=0,Tr=0 Te=0,Tr=0 Te=0,Tr=0 Te=0,Tr=0 --- > ts ts ts ts ts ts > > X --- --- --- --- --- --- --- > > D --- --- --- --- --- --- --- > > U --- Te=0,Tr=0 Te=0,Tr=0 --- --- --- --- > ts ts > > LEGEND: > > U - allocation, A - ACTIVE, I - INACTIVE, O - OFF, > E - ERROR, X - EXIT, D - DEAD, Not sure we care about the different <0 values, they're all effectively OFF.