Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752160AbdHDO0W (ORCPT ); Fri, 4 Aug 2017 10:26:22 -0400 Received: from mga02.intel.com ([134.134.136.20]:10219 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751304AbdHDO0U (ORCPT ); Fri, 4 Aug 2017 10:26:20 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,321,1498546800"; d="scan'208";a="1000237273" Subject: Re: [PATCH v6 2/3]: perf/core: use context tstamp_data for skipped events on mux interrupt To: Peter Zijlstra 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 References: <96c7776f-1f17-a39e-23e9-658596216d6b@linux.intel.com> <20170803150052.za2vofyqfgarukdr@hirez.programming.kicks-ass.net> <20170804123534.bcej4vblurz3stqb@hirez.programming.kicks-ass.net> <20170804125102.vrukamkpcnxvgkd5@hirez.programming.kicks-ass.net> From: Alexey Budankov Organization: Intel Corp. Message-ID: Date: Fri, 4 Aug 2017 17:25:55 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170804125102.vrukamkpcnxvgkd5@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1647 Lines: 74 On 04.08.2017 15:51, Peter Zijlstra wrote: > On Fri, Aug 04, 2017 at 02:35:34PM +0200, Peter Zijlstra wrote: >> Something like: >> >> __update_state_and_time(event, new_state) >> { >> u64 delta, now = perf_event_time(event); >> int old_state = event->state; >> >> event->tstamp = now; >> event->state = new_state; >> >> delta = now - event->tstamp; > Obv should go above the tstamp assignment > >> switch (state) { >> case STATE_ACTIVE: >> WARN_ON_ONCE(old_state != STATE_INACTIVE); >> event->total_time_enabled += delta; >> break; >> >> case STATE_INACTIVE: >> switch (old_state) { >> case STATE_OFF: >> /* ignore the OFF -> INACTIVE period */ >> break; >> >> case STATE_ACTIVE: >> event->total_time_enabled += delta; >> event->total_time_running += delta; >> break; >> >> default: >> WARN_ONCE(); >> } >> break; >> >> case STATE_OFF: >> WARN_ON_ONCE(old_state != STATE_INACTIVE) >> event->total_time_enabled += delta; >> break; >> } >> } > > So that's a straight fwd state machine that deals with: > > OFF <-> INACTIVE <-> ACTIVE > > but I think something like: > > __update_state_and_time(event, new_state) > { > u64 delta, new = perf_event_time(event); > int old_state = event->state; > > delta = now - event->tstamp; > event->tstamp = now; > event->state = new_state; > > if (old_state == STATE_OFF) > return; > > event->total_time_enabled += delta; > > if (old_state == STATE_ACTIVE) > event->total_time_running += delta; > } > > is equivalent and generates smaller code.. but again, double check (also > it doesn't validate the state transitions). Accepted. >