Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5539378imm; Sat, 19 May 2018 04:26:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo7DrJ1dTHQfU6y2PWv3425lzKYd/cHdJrgigNdNTAV72NtrY8t56v3PxEf9x5B1D02Alzr X-Received: by 2002:a63:6c4:: with SMTP id 187-v6mr5144668pgg.435.1526729163525; Sat, 19 May 2018 04:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526729163; cv=none; d=google.com; s=arc-20160816; b=YQ2+GRA0/8VY5k/eF48TVaEBIaceKsj02bSVzo50+Q2QN7ZxeDW6/Lz43GnElIT3yK IQFcnIp/X5CJXEFqLTGPqE2bapHPOqxsEiT0q3/RiCTxS3suRtiZgZ0so/xJaiAAgUA7 ei+qATyzqdvjAufVeOxaqbuIbjErJFADvH/Y7cvu1xc+kxpQlT0HPcp2eyqagewfxzO5 luAlRxeXO1gA00lhBFdnW3z9uh4wEQnbbKbR45KbEKNceGF+BgbAgbmCOd9a5kegQ0Xr 4TqBK2lOnLRCKIaxVruG+QTcCVRrnlAEn/udEsOti6Zv5VuZh/q0mqzuEvaTRcVeAz8R RC6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=BSQIuMaBRCmScYpUNpBl5X2ulVVW4XshF+hTWOEQzY8=; b=zWKILIpTShwtaGGNbUpWqurhCkWSaoqq012oalx1iNGa0ZmQTiwrpaTk4V8zX7XcZ/ SGVyuos8vuEwpWi9i6OqwOHgc7j55Hpba10IHfKiFKeYnwCTbDMSXaFJ1hNb2x0/ltki uLs4qWbewFntCPVDdA5nzpy/f6SXBOsUrBjSRHQPaED9igcuMZoVZGx9Naa5nWIZRZvF Pv8uRdQsjb7/xHSG6ljMoTGfB1hZEi4kRIZHl4zK+VQNGno5crShoOXsY+nFtrZEb5PX TcDmkKxWwxpG+OTPBM6lp3qE5SpBm7v6vPcg6PlpkCZ1mq1d/Vaqgo84+WTDyQstb5+J axbg== 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 y40-v6si9514491pla.470.2018.05.19.04.25.49; Sat, 19 May 2018 04:26:03 -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 S1752526AbeESLXv (ORCPT + 99 others); Sat, 19 May 2018 07:23:51 -0400 Received: from terminus.zytor.com ([198.137.202.136]:60025 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752191AbeESLXu (ORCPT ); Sat, 19 May 2018 07:23:50 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w4JBNjCG2794941 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 19 May 2018 04:23:45 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w4JBNjTR2794938; Sat, 19 May 2018 04:23:45 -0700 Date: Sat, 19 May 2018 04:23:45 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Vikas Shivappa Message-ID: Cc: mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, vikas.shivappa@linux.intel.com Reply-To: tglx@linutronix.de, linux-kernel@vger.kernel.org, vikas.shivappa@linux.intel.com, mingo@kernel.org, hpa@zytor.com In-Reply-To: <1524263781-14267-6-git-send-email-vikas.shivappa@linux.intel.com> References: <1524263781-14267-6-git-send-email-vikas.shivappa@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cache] x86/intel_rdt/mba_sc: Prepare for feedback loop Git-Commit-ID: ba0f26d8529c2dfc9aa6d9e8a338180737f8c1be X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ba0f26d8529c2dfc9aa6d9e8a338180737f8c1be Gitweb: https://git.kernel.org/tip/ba0f26d8529c2dfc9aa6d9e8a338180737f8c1be Author: Vikas Shivappa AuthorDate: Fri, 20 Apr 2018 15:36:20 -0700 Committer: Thomas Gleixner CommitDate: Sat, 19 May 2018 13:16:44 +0200 x86/intel_rdt/mba_sc: Prepare for feedback loop This is a preparatory patch for the mba feedback loop. Add support to measure the "bandwidth in MBps" and the "delta bandwidth". Measure it by reading the MBM IA32_QM_CTR MSRs and calculating the amount of "bytes" moved. There is no user space interface for this and will only be used by the feedback loop patch. Signed-off-by: Vikas Shivappa Signed-off-by: Thomas Gleixner Cc: ravi.v.shankar@intel.com Cc: tony.luck@intel.com Cc: fenghua.yu@intel.com Cc: vikas.shivappa@intel.com Cc: ak@linux.intel.com Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/1524263781-14267-6-git-send-email-vikas.shivappa@linux.intel.com --- arch/x86/kernel/cpu/intel_rdt.h | 10 ++++++++ arch/x86/kernel/cpu/intel_rdt_monitor.c | 44 ++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h index 91cc31087e8a..66a0ba37a8a3 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 681450eee428..7690402c42b7 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; @@ -269,6 +275,32 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr) return 0; } +/* + * 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.