Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752540AbdFLKgg (ORCPT ); Mon, 12 Jun 2017 06:36:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37586 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751604AbdFLKgf (ORCPT ); Mon, 12 Jun 2017 06:36:35 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 387FCC04B320 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jolsa@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 387FCC04B320 Date: Mon, 12 Jun 2017 12:36:31 +0200 From: Jiri Olsa To: kan.liang@intel.com Cc: peterz@infradead.org, mingo@redhat.com, eranian@google.com, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, acme@redhat.com, torvalds@linux-foundation.org, tglx@linutronix.de, vincent.weaver@maine.edu, ak@linux.intel.com Subject: Re: [PATCH V2 1/2] perf/x86/intel: enable CPU ref_cycles for GP counter Message-ID: <20170612103631.GA6099@krava> References: <1497029283-3332-1-git-send-email-kan.liang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1497029283-3332-1-git-send-email-kan.liang@intel.com> User-Agent: Mutt/1.8.0 (2017-02-23) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 12 Jun 2017 10:36:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1969 Lines: 45 On Fri, Jun 09, 2017 at 10:28:02AM -0700, kan.liang@intel.com wrote: SNIP > + /* > + * Correct the count number if applying ref_cycles replacement. > + * There is a constant ratio between ref_cycles (event A) and > + * ref_cycles replacement (event B). The delta result is from event B. > + * To get accurate event A count, the real delta result must be > + * multiplied with the constant ratio. > + * > + * It is handled differently for sampling and counting. > + * - Fixed period Sampling: The period is already adjusted in > + * scheduling for event B. The period_left is the remaining period > + * for event B. Don't need to modify period_left. > + * It's enough to only adjust event->count here. > + * > + * - Fixed freq Sampling: The adaptive frequency algorithm needs > + * the last_period and event counts for event A to estimate the next > + * period for event A. So the period_left is the remaining period > + * for event A. It needs to multiply the result with the ratio. > + * However, the period_left is also used to reload the event counter > + * for event B in x86_perf_event_set_period. It has to be adjusted to > + * event B's remaining period there. > + * > + * - Counting: It's enough to only adjust event->count for perf stat. > + * > + * - RDPMC: User can also read the counter directly by rdpmc/mmap. > + * Users have to handle the adjustment themselves. > + * For kernel, it only needs to guarantee that the offset is correct. > + * In x86's arch_perf_update_userpage, the offset will be corrected > + * if event B is used. > + */ > + adjust_delta = delta; > + if (hwc->flags & PERF_X86_EVENT_REF_CYCLES_REP) { > + adjust_delta = delta * x86_pmu.ref_cycles_factor; > + > + if (is_sampling_event(event) && event->attr.freq) > + local64_sub(adjust_delta, &hwc->period_left); > + else > + local64_sub(delta, &hwc->period_left); shouldn't you use adjust_delta in here also ^^^ ? jirka