Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp554716imm; Thu, 31 May 2018 05:32:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL/CHr0NwhiLnakgZk9oTSIHSPw9qW2YKmFXDq7KQszfJX6tJllTxSCT1BF4ancPwS0lGK6 X-Received: by 2002:a63:8f0d:: with SMTP id n13-v6mr5528853pgd.109.1527769950291; Thu, 31 May 2018 05:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527769950; cv=none; d=google.com; s=arc-20160816; b=dVOT/A7F15b2CO24Q4AN4Yb1psz94as2CuTcMQLxHLsLcVIHLWxPZCK53jHKRjwji/ g4Q4D0eYTRQ9NfmF8YyUXs5D+93i3Ni3J0MATsOBgdxyuMxVcdDBvyE8QIv3YdN0VBkn pamWls+rZDQHpsqLY0QkZYDVyXhGS4rMYWlud8cDcBquvxO2xDaNE1BwvrVfXtjykwkQ mbRLd2kJOyuTJfaCsSgbvGeYxAFPaMqsyEKDZdsdAxjkFJgdMcC3ctCu7Sd0bEWPqRnt yAbcQPl2EGRMflx6BXMt4M2Rvih/3y/Hma4pPWdbFrCEPh7BH6+tMcW01SvKy6zCaHPB SRWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=y1xxFNUYU9SQHJI89uO65D7S3kagltZAY2PB+Clq8CY=; b=LWlFywA0Z1SHnTQKnRwH3+Yd7z5UuGWzeqPTHLiiaZ5OI7sJIdvB16rH4KeH23D1nf OBm2lymtTZ+PNanBdHcQ8GYF2PDtEjj6mCErCclBS+cBe5uc5aUBwkHZmqDa6tdOqrp6 DeRGjEFNo/KpoVBfhiTUJ9Q/jHMeuEWT9R27TL7zRBDfsO5NzMu7zu09loUZuRHBOrPL jx0mNxybmoW35G9lUMe+Mks5HIufJqRT2jTYXBrjbMiA53TzAhYzDEGu6FOyBgmNm1Yb unX3X1uETOaKxgr4A3yqa6ls1tgRVpmO8146W7EzUW9B3d1c/ve3ofpjhuXoXNCdJstF Wz9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18-v6si37088247plo.285.2018.05.31.05.32.15; Thu, 31 May 2018 05:32:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755072AbeEaMaY (ORCPT + 99 others); Thu, 31 May 2018 08:30:24 -0400 Received: from terminus.zytor.com ([198.137.202.136]:36061 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754197AbeEaMaX (ORCPT ); Thu, 31 May 2018 08:30:23 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w4VCU3e33562873 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 31 May 2018 05:30:04 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w4VCU3j53562870; Thu, 31 May 2018 05:30:03 -0700 Date: Thu, 31 May 2018 05:30:03 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kan Liang Message-ID: Cc: kan.liang@intel.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de Reply-To: tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, kan.liang@intel.com In-Reply-To: <1525371913-10597-1-git-send-email-kan.liang@intel.com> References: <1525371913-10597-1-git-send-email-kan.liang@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf/x86/intel/uncore: Introduce customized event_read() for client IMC uncore Git-Commit-ID: 2da331465f44f9618abe8837d1a68405d550b66e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_48_96 autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 2da331465f44f9618abe8837d1a68405d550b66e Gitweb: https://git.kernel.org/tip/2da331465f44f9618abe8837d1a68405d550b66e Author: Kan Liang AuthorDate: Thu, 3 May 2018 11:25:06 -0700 Committer: Ingo Molnar CommitDate: Thu, 31 May 2018 12:36:27 +0200 perf/x86/intel/uncore: Introduce customized event_read() for client IMC uncore There are two free-running counters for client IMC uncore. The customized event_init() function hard codes their index to 'UNCORE_PMC_IDX_FIXED' and 'UNCORE_PMC_IDX_FIXED + 1'. To support the index 'UNCORE_PMC_IDX_FIXED + 1', the generic uncore_perf_event_update is obscurely hacked. The code quality issue will bring problems when a new counter index is introduced into the generic code, for example, a new index for free-running counter. Introducing a customized event_read() function for client IMC uncore. The customized function is copied from previous generic uncore_pmu_event_read(). The index 'UNCORE_PMC_IDX_FIXED + 1' will be isolated for client IMC uncore only. Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Cc: Linus Torvalds Cc: Peter Zijlstra Cc: acme@kernel.org Cc: eranian@google.com Link: http://lkml.kernel.org/r/1525371913-10597-1-git-send-email-kan.liang@intel.com Signed-off-by: Ingo Molnar --- arch/x86/events/intel/uncore_snb.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c index aee5e8496be4..df535215d18b 100644 --- a/arch/x86/events/intel/uncore_snb.c +++ b/arch/x86/events/intel/uncore_snb.c @@ -450,6 +450,35 @@ static void snb_uncore_imc_event_start(struct perf_event *event, int flags) uncore_pmu_start_hrtimer(box); } +static void snb_uncore_imc_event_read(struct perf_event *event) +{ + struct intel_uncore_box *box = uncore_event_to_box(event); + u64 prev_count, new_count, delta; + int shift; + + /* + * There are two free running counters in IMC. + * The index for the second one is hardcoded to + * UNCORE_PMC_IDX_FIXED + 1. + */ + if (event->hw.idx >= UNCORE_PMC_IDX_FIXED) + shift = 64 - uncore_fixed_ctr_bits(box); + else + shift = 64 - uncore_perf_ctr_bits(box); + + /* the hrtimer might modify the previous event value */ +again: + prev_count = local64_read(&event->hw.prev_count); + new_count = uncore_read_counter(box, event); + if (local64_xchg(&event->hw.prev_count, new_count) != prev_count) + goto again; + + delta = (new_count << shift) - (prev_count << shift); + delta >>= shift; + + local64_add(delta, &event->count); +} + static void snb_uncore_imc_event_stop(struct perf_event *event, int flags) { struct intel_uncore_box *box = uncore_event_to_box(event); @@ -472,7 +501,7 @@ static void snb_uncore_imc_event_stop(struct perf_event *event, int flags) * Drain the remaining delta count out of a event * that we are disabling: */ - uncore_perf_event_update(box, event); + snb_uncore_imc_event_read(event); hwc->state |= PERF_HES_UPTODATE; } } @@ -534,7 +563,7 @@ static struct pmu snb_uncore_imc_pmu = { .del = snb_uncore_imc_event_del, .start = snb_uncore_imc_event_start, .stop = snb_uncore_imc_event_stop, - .read = uncore_pmu_event_read, + .read = snb_uncore_imc_event_read, }; static struct intel_uncore_ops snb_uncore_imc_ops = {