Received: by 10.213.65.68 with SMTP id h4csp368939imn; Tue, 20 Mar 2018 05:37:06 -0700 (PDT) X-Google-Smtp-Source: AG47ELsnz/OycnLis/aod+25lQtiscA/zJawyNFi44W04J1gXh+E25B1kwQVKwxt9iGbl8HxYSTk X-Received: by 2002:a17:902:c6b:: with SMTP id 98-v6mr16244508pls.267.1521549426054; Tue, 20 Mar 2018 05:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521549426; cv=none; d=google.com; s=arc-20160816; b=Lpq9QtD8OCcPxBIwelxWMK4822+0U9GOBB6dlrfqJkaYSr+PlJJWxwjgj/POYQdTBC Bpqq1XIPcBCWmYHIP/F3DYbO4VVI9WAdoEdhdfwT0ZT70GJPwOZ0bXVY5bKIdcZwsJ7+ eivK3bvGw2qoo+HYUUdSzCDzU9X6zcQvdjo4lIo9PXBo6VCYu1li3aN+0ULaYgQ5JO94 pMWb1wIAwHKJcPPCrseSC3kV/Waf1/cK/QExDauTScD9Qjx0v53hM9zs+zW5RxxaPk00 NruUYdl0A4ofeak8+lWOoat8Sf6Qi89x+ypE9vXXef1dNSQk/Zjug4On7N4dL3ZPQz1Q o+LA== 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=3VnHmOuAccYLa5odYD5EH6uu0bgTFl/m36mzyb1VMHg=; b=f2qbMTO7ktAPO/HIFRw3PGwHCY1D/ktl58dBTYPj3fTBZrNiq5DRaAN0kyXOngIi7t /oNXRiGAoFuojTaV+1Z5gIzHroVQgjl1EMs9pUr4LZIt25HalQRq9Lej2CJV/c9PWz/V 2KwoiZVnBm/PH3+NatmG0uG0jaOzI5ToAgKxqScpbBlGbbzS56UgUKnM2VAB925WVSvX tryjAy/L9d3stbyRI5dOCDO4031XNuPnlqqjClviCVRE4MlPlcQZJAR5ZiN1PG6vYtiR 7RwI6DFLq6l41yfV+vMEvJi0hMzFqdLsW52GqeVi9g2feDD32uxhmBhNIqB9fZRI+ND9 tVHw== 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 u25si1256233pfm.164.2018.03.20.05.36.50; Tue, 20 Mar 2018 05:37:06 -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 S1753378AbeCTMfK (ORCPT + 99 others); Tue, 20 Mar 2018 08:35:10 -0400 Received: from mga18.intel.com ([134.134.136.126]:3060 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753176AbeCTMdU (ORCPT ); Tue, 20 Mar 2018 08:33:20 -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 orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2018 05:33:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,335,1517904000"; d="scan'208";a="209781478" Received: from otc-lr-04.jf.intel.com ([10.54.39.128]) by orsmga005.jf.intel.com with ESMTP; 20 Mar 2018 05:33:19 -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: [PATCH V7 1/8] perf/x86/intel/uncore: Customized event_read for client IMC uncore Date: Tue, 20 Mar 2018 05:32:38 -0700 Message-Id: <1521549165-6216-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 --- No changes since V6. 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