Received: by 10.223.176.46 with SMTP id f43csp2594953wra; Thu, 25 Jan 2018 12:17:11 -0800 (PST) X-Google-Smtp-Source: AH8x227dKUp2n+GqL+HAmGmhCVIjDOhT5MgRMIjkdk29NLWyLX2jjBACrvKorKFWaSKVBm5obvGA X-Received: by 10.101.76.193 with SMTP id n1mr13262301pgt.194.1516911431414; Thu, 25 Jan 2018 12:17:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516911431; cv=none; d=google.com; s=arc-20160816; b=vXWez6NcC3mIcA2mGCmax1Zz/0AUES83w6FPLGGXM/YDKLq6IAphMH12bfuRcmXERN sS6t2VzmoZ12vF6SG6oidZ2cD2d2d/+IyvW54fok+N0w4GG+fHd8dVTZVCm7XNt3FpGM zkpWu3SxHvsI+Z54c18Liy27yfLxCpa6dTd20S++lcWeMA8+eXxumezuZ7+4mDXS07Dy /ubzad34KheLil61MNNgC9VGDWddJVAp/LQUOSI5OUkhBZNkbzjpwPzg+wQ9AQCe1WS0 1qmz8bdA6AMcNAY9XoCiow4Z4H9gyXKir4U91+Wz5cjyIsNcqZygqfZBNhpXwTxuI94e a+cA== 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=VCTyisCUB1or8JarSfpdnlE4vsTjYUPpGrJjA5Hu04g=; b=OWAJ/vvSb5Jtzsa5HLE/3St9bGz6UyvVp2AbiyX43rX/cFQox8JShpPkTzXv/l755a CROcZvlXUbipnpEuFLeSw4X9xnX3TGsFkChfuS/6eIL4rMGhYA7hnyn5SB7cwlyFr6kz gnneAiwNvv+7JXh1XW3zYqHnVjMUAMlojcWTnMurQvzyrNVcgVLCELEw8fmX/jwx+dV3 WAvptQSGjQYa3hn3buEL9Wj+3RtwlE4yBKDsaDA613MYifBH/meen4wvZF0lmek+V4l0 s9/wpcvoAUR3JHxFUPyijHrvlRWImjQIZ/Jy3oXre6GZQgTM31Stujb0hjY/Vp/THDFg GN5g== 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 f2-v6si2498990plt.435.2018.01.25.12.16.56; Thu, 25 Jan 2018 12:17:11 -0800 (PST) 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 S1751335AbeAYUO2 (ORCPT + 99 others); Thu, 25 Jan 2018 15:14:28 -0500 Received: from mga14.intel.com ([192.55.52.115]:52329 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751181AbeAYUO0 (ORCPT ); Thu, 25 Jan 2018 15:14:26 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 12:14:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,413,1511856000"; d="scan'208";a="169164978" Received: from otc-lr-04.jf.intel.com ([10.54.39.128]) by orsmga004.jf.intel.com with ESMTP; 25 Jan 2018 12:14:21 -0800 From: kan.liang@intel.com To: tglx@linutronix.de, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: acme@kernel.org, eranian@google.com, ak@linux.intel.com, Kan Liang Subject: [PATCH V6 1/8] perf/x86/intel/uncore: customized event_read for client IMC uncore Date: Thu, 25 Jan 2018 12:13:41 -0800 Message-Id: <1516911228-5293-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 custom event_init() function hardcode their index to 'UNCORE_PMC_IDX_FIXED' and 'UNCORE_PMC_IDX_FIXED + 1'. To support the 'UNCORE_PMC_IDX_FIXED + 1' case, the generic uncore_perf_event_update is obscurely hacked. The code quality issue will bring problem when new counter index is introduced into generic code. For example, free running counter index. Introduce customized event_read function for client IMC uncore. The customized function is exactly copied from previous generic uncore_pmu_event_read. The 'UNCORE_PMC_IDX_FIXED + 1' case will be isolated for client IMC uncore only. Reviewed-by: Thomas Gleixner Signed-off-by: Kan Liang --- Change since V5: - Add reviewed-by 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