From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755444AbcECHrE (ORCPT ); Tue, 3 May 2016 03:47:04 -0400 Received: from merlin.infradead.org ([205.233.59.134]:51906 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750819AbcECHrA (ORCPT ); Tue, 3 May 2016 03:47:00 -0400 Date: Tue, 3 May 2016 09:46:50 +0200 From: Peter Zijlstra To: Vikas Shivappa Cc: Vikas Shivappa , tony.luck@intel.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, h.peter.anvin@intel.com Subject: Re: [PATCH 2/4] perf/x86/mbm: Store bytes counted for mbm during recycle Message-ID: <20160503074650.GF3430@twins.programming.kicks-ass.net> References: <1461371241-4258-1-git-send-email-vikas.shivappa@linux.intel.com> <1461371241-4258-3-git-send-email-vikas.shivappa@linux.intel.com> <20160425091311.GE3430@twins.programming.kicks-ass.net> <20160425200222.GM3448@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 25, 2016 at 02:12:09PM -0700, Vikas Shivappa wrote: > >start: > > prev_count = read_hw_counter(); > > I am assuming this means we keep the prev_count when event is initialized. > This is done in the mbm_init which calls update_sample with first parameter > set to true.. No, when pmu::start() is called. > >read: > > do { > > prev = prev_count; > > cur_val = read_hw_counter(); > > delta = cur_val - prev; > > } while (local_cmpxchg(&prev_count, prev, cur_val) != prev); > > count += delta; And this you do on pmu::{stop,read}() > the update_sample does the work to compute the delta and add the delta to > total_bytes.. it has all the code except for the while loop. No, no, no, you add rc_count and st_count and generally make a huge mess of things. The above needs none of that. Because the above only cares about deltas against the hw counter (as per prev_count). Therefore count can be an absolute value that carries all your history as per rc_count, and you don't need st_count because per prev_count you don't care about the absolute value of the hw counter.