Received: by 10.192.165.148 with SMTP id m20csp261592imm; Thu, 3 May 2018 19:43:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq2JNdxKpG+pxoSY2qfB80j2vadlHBjTtFSiT9Xf509UgHd5fv1n0wsOuN5ygHA5P4O6L0L X-Received: by 2002:a17:902:6045:: with SMTP id a5-v6mr25889750plt.138.1525401780484; Thu, 03 May 2018 19:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525401780; cv=none; d=google.com; s=arc-20160816; b=vG2Q2Mew6jrCr53R8/fjPAR0ZRrwKv81pBT7DJnC/APyeJAcJxXHpuD0mnldiKU9Uj 2iY+LBeCCH09WMzAoP2ktVA+mMiEgjs/myrykYVTYec1tQkR7NB5JurY8feMwb7PfQbp rWlOenNdhDXB87Gy4SZgLw6HvkIRTeQ0J3kna/8XWmkPNNLokcgW6G90i3AKrBEc//NY 6NH7Qt141g9UrNPsVNFM4nIlKXRzhYNGva6UUbsL8H/XkwSvc4sQNp2SWx57nRjJfuEQ dBinxRbsAm/g2dUF0MSELKbF8yqjiJ7KSETKYiq7r/xLMkMlmcQYYr7Gy9DSdmXyRaEt bNwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=aVeH0FamxhDroAqJL0hXHg0UaQByxiX/IaZy6owksj0=; b=Xlv+V90g7wi8S9aNSO/hoCPthd7SV7vY8qMLwyMOX4HdVAc+u3VOMXBcaAeyewswok fkKZD3rYO4QAc+zDUJVdHygyt+j8TeBKISJZ00brsPxAdNzdIPKe/+H389VdAxW79l3E xmyyvmu+KSdhYkvxQA8Ky9GDjOgqqXT/UsqIuIC8sAiLyP/sSsSv8tu7hlRL6HR+G5yN 7+nlizkT5RRD/v4GMyWW2S/n7nuVWln7sk7+c1oOYpyIc4sQUyClGYw02tJ2r/AV+I9w ciAFnmiAOCAnkH/tykbt8LtFvwRJ9lEyCyJ35N8F01h1jMLOInu1tk6rde45oB8vSZCJ mw2w== 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 v29-v6si13129415pgo.483.2018.05.03.19.42.46; Thu, 03 May 2018 19:43:00 -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 S1751291AbeEDCl1 (ORCPT + 99 others); Thu, 3 May 2018 22:41:27 -0400 Received: from mga11.intel.com ([192.55.52.93]:18418 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751214AbeEDCl0 (ORCPT ); Thu, 3 May 2018 22:41:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 19:41:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,360,1520924400"; d="scan'208";a="221513521" Received: from otc-lr-04.jf.intel.com ([10.54.39.15]) by orsmga005.jf.intel.com with ESMTP; 03 May 2018 19:41:26 -0700 From: kan.liang@intel.com To: peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: acme@kernel.org, eranian@google.com, ak@linux.intel.com, Kan Liang Subject: [RESEND PATCH V7 1/8] perf/x86/intel/uncore: Customized event_read() for client IMC uncore Date: Thu, 3 May 2018 11:25:06 -0700 Message-Id: <1525371913-10597-1-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang 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. Reviewed-by: Thomas Gleixner Signed-off-by: Kan Liang --- Changes since V6 - Refine changelog 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 aee5e84..df53521 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 = { -- 2.7.4