Received: by 10.223.164.221 with SMTP id h29csp2586673wrb; Thu, 2 Nov 2017 13:35:06 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R8Zo0QaW3kFv2YBZAsD7BgnI7hAM4S+tff4bXzx9e8euZLjf5nIWsosPsrTv6YGclZ1kSH X-Received: by 10.84.176.131 with SMTP id v3mr4512067plb.208.1509654906703; Thu, 02 Nov 2017 13:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509654906; cv=none; d=google.com; s=arc-20160816; b=Eh8Nbgqg9xbr7whHp/iRrZl3QkMbAwjPkz+8WBqYMTLJu6xkN1iNAH53sWAsr+OAdQ e82KM/L9LQueKWoq/zPdbz7Z2a9ug5isOXioPdg07k6CQkJcFaHuCoh0pgzWVLFAVSXU D0cwG5BNlobOiHpPO3IzVpl/auIJ5mAHHZS8GxzIv7QjfhqBGNWgWZYBXMZgb5+vfIxq pGcLWOmEnJpnRshvVufbWVbQUYkSJ7OkLnrQS2uI3drFIk2ovAoZYHkiywwBAUQ2yT6+ tz653/Vag025sE1yL1EV3hndkALmKVhA7LVOEyz3iS6W5QATEc+UQGN5HmUONW8Q4GW5 j4Wg== 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=YkPMdEP6pIZUinxQ1H2X0mGx060qnIO4k5MTIZvUsPw=; b=G4UOb0aD5B0SXq0MUyk/tLjQkhbqKykiOoqejos4DD1bniYebeXLTdmHphLlSaOgMp WTwYuNrfIMdvoW7gIeJ6ZO9gRxC44lzxNV1oAe6VHVX63LGdoOauCvCRq/x+v4n/CeEe zuS5DbJuLc+341z7cVX7H9DEpvZ8krbBR08Elestj3fvL8lBTCruEruXyk7qZrdqIpXW mRmH57YEOwKzIZ6x5jqJ7pcynXRJb0uWWs68NN2lmMvST9bwA/NkGqrRjhbOJgscpbsN 7aig30AxJnNLHiNwg+GU2LEjz0RaXWfWSRY/J2s2cJdt6btzC6DnIKS7ZEIBaXu8eOwZ 1+cQ== 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 q1si3040436plb.368.2017.11.02.13.34.53; Thu, 02 Nov 2017 13:35: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 S964856AbdKBUaY (ORCPT + 99 others); Thu, 2 Nov 2017 16:30:24 -0400 Received: from mga11.intel.com ([192.55.52.93]:31294 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932241AbdKBUaX (ORCPT ); Thu, 2 Nov 2017 16:30:23 -0400 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Nov 2017 13:30:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,335,1505804400"; d="scan'208";a="145287036" Received: from otc-lr-04.jf.intel.com ([10.54.39.138]) by orsmga004.jf.intel.com with ESMTP; 02 Nov 2017 13:30:22 -0700 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 V4 1/8] perf/x86/intel/uncore: customized event_read for client IMC uncore Date: Thu, 2 Nov 2017 13:29:46 -0700 Message-Id: <1509654593-4446-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. Signed-off-by: Kan Liang --- Change since V3: - Use the customized read function to replace uncore_perf_event_update. - Move generic code change to patch 3/8. 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 db1127c..b6d0d72 100644 --- a/arch/x86/events/intel/uncore_snb.c +++ b/arch/x86/events/intel/uncore_snb.c @@ -449,6 +449,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); @@ -471,7 +500,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; } } @@ -533,7 +562,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 From 1586482404683928336@xxx Mon Dec 11 10:18:42 +0000 2017 X-GM-THRID: 1586482404683928336 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread