Received: by 10.192.165.148 with SMTP id m20csp772407imm; Fri, 20 Apr 2018 15:43:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/oXaGoxA3iwAwlzCiQVITkn1y5T/uuN2obFy7fCxXb5VLXRKMu1jYntB9swCNC1meM+DTf X-Received: by 10.99.167.4 with SMTP id d4mr2429073pgf.324.1524264234645; Fri, 20 Apr 2018 15:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524264234; cv=none; d=google.com; s=arc-20160816; b=vNCHax2vrurdVBh3yQOj6rqQK5age3MSngkZfuq8FcJzVCgMe1aL8bLVKw/qv0l4oZ ARayNxLppQ57JMTB7JFZmaXUvS9MGU6vuY6S5M20/QPzo9Zigu6FVSSuO1LL9zaWPI79 ogb2k341sxlzwkizQKX1HA8npF8SUEWEJPhW0PDTW1/e/9abFRtzRUokEttqhZkBWRZ3 7+QYq0UL+R1420KhXwongIo/CW7DlUI/WFdpD6RWlrVHZD0RUwHv6Kz3pi/RO3ZABPTT 1Rb4yGbfNrsNPHmGaz1hqsnOGhCJy2FX+AJLV039pakAZshcfU+O+ZytrhPXA3DPLLWq /dYg== 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:message-id:date :subject:cc:to:from:arc-authentication-results; bh=l3FUxRuSG3V/HBlrMZ0DxY5PX7+DMkJRlP43RB2WF60=; b=pS1Aqy0xwp8Bjf82kp71HHKORGVo6Y0uXsbRdi7o57Fnsv8YnC3iikIvOBzaGlq1gy 2F9ZsQKcu9afv9lW9T73IHCPUTRwwHizM/dzTXi9IvIyViProwsmxnELKx4gV8ywWLfW z6z/HdDINXnE3mxQEFkLRnbSx322ZRhjWjqqcWtIAEwJnbH/b0UC2ph+eAisdEWxfBqS /lBwNFayqvfoFdSJdWPDLt0Vh/WqhBItSpGP4IajxhVqEPLqSGRw4H85cYGrnmZZWTFf b1Aq1IxF9o4ZDYVbfxH0cv0ljcHvj08u6VmcyBAmy83N5I4cOMZADqhve6l9PdKgNT2T Rv3g== 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 y86si6040633pfa.243.2018.04.20.15.43.17; Fri, 20 Apr 2018 15:43:54 -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 S1753199AbeDTWjk (ORCPT + 99 others); Fri, 20 Apr 2018 18:39:40 -0400 Received: from mga01.intel.com ([192.55.52.88]:60384 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752924AbeDTWjK (ORCPT ); Fri, 20 Apr 2018 18:39:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Apr 2018 15:39:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,303,1520924400"; d="scan'208";a="34982644" Received: from vshiva-udesk.sc.intel.com ([10.3.52.52]) by orsmga007.jf.intel.com with ESMTP; 20 Apr 2018 15:39:09 -0700 From: Vikas Shivappa To: vikas.shivappa@intel.com, tony.luck@intel.com, ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org, tglx@linutronix.de, hpa@zytor.com Cc: linux-kernel@vger.kernel.org, ak@linux.intel.com, vikas.shivappa@linux.intel.com Subject: [PATCH 5/6] x86/intel_rdt/mba_sc: Prepare for feedback loop Date: Fri, 20 Apr 2018 15:36:20 -0700 Message-Id: <1524263781-14267-6-git-send-email-vikas.shivappa@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524263781-14267-1-git-send-email-vikas.shivappa@linux.intel.com> References: <1524263781-14267-1-git-send-email-vikas.shivappa@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparatory patch for the mba feedback loop. We add support to measure the "bandwidth in MBps" and the "delta bandwidth". We measure it reading the MBM IA32_QM_CTR MSRs and calculating the amount of "bytes" moved. There is no user interface for this and will only be used by the feedback loop patch. Signed-off-by: Vikas Shivappa --- arch/x86/kernel/cpu/intel_rdt.h | 10 ++++++++ arch/x86/kernel/cpu/intel_rdt_monitor.c | 45 ++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h index 91cc310..66a0ba3 100644 --- a/arch/x86/kernel/cpu/intel_rdt.h +++ b/arch/x86/kernel/cpu/intel_rdt.h @@ -180,10 +180,20 @@ struct rftype { * struct mbm_state - status for each MBM counter in each domain * @chunks: Total data moved (multiply by rdt_group.mon_scale to get bytes) * @prev_msr Value of IA32_QM_CTR for this RMID last time we read it + * @chunks_bw Total local data moved. Used for bandwidth calculation + * @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting + * @prev_bw The most recent bandwidth in MBps + * @delta_bw Difference between the current and previous bandwidth + * @delta_comp Indicates whether to compute the delta_bw */ struct mbm_state { u64 chunks; u64 prev_msr; + u64 chunks_bw; + u64 prev_bw_msr; + u32 prev_bw; + u32 delta_bw; + bool delta_comp; }; /** diff --git a/arch/x86/kernel/cpu/intel_rdt_monitor.c b/arch/x86/kernel/cpu/intel_rdt_monitor.c index 681450e..32c9e55 100644 --- a/arch/x86/kernel/cpu/intel_rdt_monitor.c +++ b/arch/x86/kernel/cpu/intel_rdt_monitor.c @@ -225,10 +225,18 @@ void free_rmid(u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } +static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr) +{ + u64 shift = 64 - MBM_CNTR_WIDTH, chunks; + + chunks = (cur_msr << shift) - (prev_msr << shift); + return chunks >>= shift; +} + static int __mon_event_count(u32 rmid, struct rmid_read *rr) { - u64 chunks, shift, tval; struct mbm_state *m; + u64 chunks, tval; tval = __rmid_read(rmid, rr->evtid); if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) { @@ -254,14 +262,12 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr) } if (rr->first) { - m->prev_msr = tval; - m->chunks = 0; + memset(m, 0, sizeof(struct mbm_state)); + m->prev_bw_msr = m->prev_msr = tval; return 0; } - shift = 64 - MBM_CNTR_WIDTH; - chunks = (tval << shift) - (m->prev_msr << shift); - chunks >>= shift; + chunks = mbm_overflow_count(m->prev_msr, tval); m->chunks += chunks; m->prev_msr = tval; @@ -270,6 +276,33 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr) } /* + * Supporting function to calculate the memory bandwidth + * and delta bandwidth in MBps. + */ +static void mbm_bw_count(u32 rmid, struct rmid_read *rr) +{ + struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3]; + struct mbm_state *m = &rr->d->mbm_local[rmid]; + u64 tval, cur_bw, chunks; + + tval = __rmid_read(rmid, rr->evtid); + if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) { + return; + } + + chunks = mbm_overflow_count(m->prev_bw_msr, tval); + m->chunks_bw += chunks; + m->chunks = m->chunks_bw; + cur_bw = (chunks * r->mon_scale) >> 20; + + if (m->delta_comp) + m->delta_bw = abs(cur_bw - m->prev_bw); + m->delta_comp = false; + m->prev_bw = cur_bw; + m->prev_bw_msr = tval; +} + +/* * This is called via IPI to read the CQM/MBM counters * on a domain. */ -- 1.9.1