Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2657904imm; Thu, 16 Aug 2018 13:18:11 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwRxsrf5nTZWdKVEA+gYesiZsHuw+vEREMjih3wSjKVz7QeQStc0qS4YwfzikHD8D+45CJO X-Received: by 2002:a63:af14:: with SMTP id w20-v6mr31105741pge.47.1534450691583; Thu, 16 Aug 2018 13:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534450691; cv=none; d=google.com; s=arc-20160816; b=sCmX2llaA2pPKxDL8ByDeQqmIypsdvwbgRTHC5o1dMz7R19hX9wa7kEXyOxOoFWSkN IYD5fib/gXeMdajbwLT8K4juGcwZK4EsZR48lwjs9WMWt3W61scg00GcesqDd8/+iUVt InI5bl5ByRg/CCZ56M6DwScu7Li9hvJCoJhgbDt4QrLGySzD85oSD8vzv9rpVAwkQ810 L+O60yqhf0kL171oi6BWt9BAWlTjp/Mjjnx8gN8yb7/2cg1qSPwOdZvVnTB5bOMp2yl4 FSKAQImeR4E5iNKevh2NsXdrkBaorFntQ9ML0kilu3tmPAuYUYay8a1jz/7/G5Nsbaap RtnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xBmuUhxLVzwijt4XzlMBCHgNM0zKH3HW0VOFR6KALDg=; b=Lg/BbskKwpFLmDVZp/pfq1HniDuOEsnlhlfmff+oc2YidY/Kn3HrIvDgGnAcGzNpmz A70wC8G1nce7HhXasxtfFn8vUohsRNnbJ+ybQzXKcke1qJAFVE5VyepDzNqvoLQThOOT D7vcVu37YblVAl51dpYvpSg6ktI6JC6yYSoR58Ba3OYKJJU357NBtOBNu+Q/ywRPG8N1 cLpLdFu8itteCoDgsHU6uLdDBllyCAS/F8nkk8MHB5yrzd3pU7LmusWa9EN3pdgWN8kx T8sAwW3vxB/aAQ1my/zNnqDiJYUhL3brN4MgwgTAkc70J3HsV7tAkaP3sL84NaVF/Stn /HuA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s15-v6si216394pgr.269.2018.08.16.13.17.56; Thu, 16 Aug 2018 13:18:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726185AbeHPXRF (ORCPT + 99 others); Thu, 16 Aug 2018 19:17:05 -0400 Received: from mga17.intel.com ([192.55.52.151]:43390 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726108AbeHPXRE (ORCPT ); Thu, 16 Aug 2018 19:17:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Aug 2018 13:16:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,248,1531810800"; d="scan'208";a="225248288" Received: from rchatre-s.jf.intel.com ([10.54.70.76]) by orsmga004.jf.intel.com with ESMTP; 16 Aug 2018 13:16:34 -0700 From: Reinette Chatre To: tglx@linutronix.de, fenghua.yu@intel.com, tony.luck@intel.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, vikas.shivappa@linux.intel.com Cc: gavin.hindman@intel.com, jithu.joseph@intel.com, dave.hansen@intel.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, Reinette Chatre Subject: [PATCH V2 4/6] x86/intel_rdt: Add helper to obtain performance counter index Date: Thu, 16 Aug 2018 13:16:07 -0700 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In support of the most accurate measurements rdpmcl() is used instead of the more elaborate perf_event_read_local(). rdpmcl() requires the index of the performance counter used so a helper is introduced to determine the index used by a provided performance event. The index used by a performance event may change when interrupts are enabled. A check is added to ensure that the index is only accessed with interrupts disabled. Even with this check the use of this counter needs to be done with care to ensure it is queried and used within the same disabled interrupts section. Signed-off-by: Reinette Chatre --- arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c index ab93079e9e5b..20b76024701d 100644 --- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c +++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c @@ -942,6 +942,27 @@ static struct perf_event_attr __attribute__((unused)) perf_hit_attr = { .exclude_user = 1, }; +/** + * x86_perf_rdpmc_ctr_get - Return PMC counter used for event + * @event: the perf_event to which the PMC counter was assigned + * + * The counter assigned to this performance event may change if interrupts + * are enabled. This counter should thus never be used while interrupts are + * enabled. Before this function is used to obtain the assigned counter the + * event could be checked for validity using, for example, + * perf_event_read_local(), within the same interrupt disabled section in + * which this counter is planned to be used. + * + * Return: The index of the performance monitoring counter assigned to + * @perf_event, -1 if event is not valid. + */ +static inline int x86_perf_rdpmc_ctr_get(struct perf_event *event) +{ + lockdep_assert_irqs_disabled(); + + return IS_ERR_OR_NULL(event) ? -1 : event->hw.event_base_rdpmc; +} + static int measure_cycles_perf_fn(void *_plr) { unsigned long long l3_hits = 0, l3_miss = 0; -- 2.17.0