From nobody Thu Dec 18 01:38:46 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A2DE1FFC5E; Fri, 6 Dec 2024 16:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733502718; cv=none; b=DaOkZ9oGYM4YHl+gp3CRoZ0AWiriFxNF0X13m4BLLjQ3QWNa5bMcs3CGkO2GPSetvMNa5zLsrb5qpcjxz6Qrn1EaIVO+v2edQjN9s75RU33moQcuVdFNx0tMCm1NpEKkjZmor622Qe0t24y4AF1bNpOIh8Poh+v+ub+8OoxDPuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733502718; c=relaxed/simple; bh=JG3z7yTbByVBYHLz+pJgSPAGR9jxx7TOcdejCgHSi+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qPPfgXNol/LTRBDMmNIjsCULLFKqauU+hDcEge8+P71tOabcSX+pxX1/S03Gnmx8psZ4X9RI4DeT8xTg9IC9jSQcEcmwC9vt0GAr8G6UElViib0YcoB+FtEu/LTRUrzx7l2Q56JckPaj4Hxh2egG8M0gMb57/fPwElCApGcBH9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fC3E3IRI; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fC3E3IRI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733502717; x=1765038717; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JG3z7yTbByVBYHLz+pJgSPAGR9jxx7TOcdejCgHSi+k=; b=fC3E3IRIwNMoaLg7cxk38moOBXQRb9lZ9ufFWKw0VvJpSlbrHecBfv7l zNYQ3n6hOGX+PwHyj5eLUjG/ytxKLI1EI/h8C5nsibiPZs7gGLuYJPeyZ UM85WxtQXOFxSHBArjXok7UO5P7oPApfZfl5w/S0PJJFy6I+qjsGuyIFZ v3bWYIJV5WeND82UCsMiecer6ppwiyujBRF+ilBSDv4yKiwV3rRUL0kS9 wQAsn9v1tk/UfKSFySjkdZBEUJZJNZmeWEAHaWzWvwOKdgw6/Z6h0EhTp jfAriIg+NMpaj8J3dHSX7qYmjSHcoNXzFAS784XBHzMC3NnvYINW7mYgk w==; X-CSE-ConnectionGUID: frn+yE4bQL2d1qimxZJKVA== X-CSE-MsgGUID: P3hvlKmTSXmjDVxO0GuiKg== X-IronPort-AV: E=McAfee;i="6700,10204,11278"; a="44470405" X-IronPort-AV: E=Sophos;i="6.12,213,1728975600"; d="scan'208";a="44470405" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2024 08:31:54 -0800 X-CSE-ConnectionGUID: nN6+PwVaT+CR0f3E5h3fXw== X-CSE-MsgGUID: b6p8EBjlSq6JCv+AsXuGrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,213,1728975600"; d="scan'208";a="95258517" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2024 08:31:54 -0800 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Peter Newman , Jonathan Corbet , x86@kernel.org Cc: James Morse , Jamie Iles , Babu Moger , Randy Dunlap , "Shaopeng Tan (Fujitsu)" , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v11 4/8] x86/resctrl: Compute memory bandwidth for all supported events Date: Fri, 6 Dec 2024 08:31:44 -0800 Message-ID: <20241206163148.83828-5-tony.luck@intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241206163148.83828-1-tony.luck@intel.com> References: <20241206163148.83828-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switching between local and total memory bandwidth events as the input to the mba_sc feedback loop would be cumbersome and take effect slowly in the current implementation as the bandwidth is only known after two consecutive readings of the same event. Compute the bandwidth for all supported events. This doesn't add significant overhead and will make changing which event is used simple. Suggested-by: Reinette Chatre Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- arch/x86/kernel/cpu/resctrl/monitor.c | 72 ++++++++++++--------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index adb18f088979..94a1d9780461 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -663,9 +663,12 @@ static int __mon_event_count(u32 closid, u32 rmid, str= uct rmid_read *rr) */ static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr) { - u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); - struct mbm_state *m =3D &rr->d->mbm_local[idx]; u64 cur_bw, bytes, cur_bytes; + struct mbm_state *m; + + m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); + if (WARN_ON_ONCE(!m)) + return; =20 cur_bytes =3D rr->val; bytes =3D cur_bytes - m->prev_bw_bytes; @@ -815,54 +818,45 @@ static void update_mba_bw(struct rdtgroup *rgrp, stru= ct rdt_mon_domain *dom_mbm) resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val); } =20 -static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, - u32 closid, u32 rmid) +static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_do= main *d, + u32 closid, u32 rmid, enum resctrl_event_id evtid) { struct rmid_read rr =3D {0}; =20 rr.r =3D r; rr.d =3D d; + rr.evtid =3D evtid; + rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); + if (IS_ERR(rr.arch_mon_ctx)) { + pr_warn_ratelimited("Failed to allocate monitor context: %ld", + PTR_ERR(rr.arch_mon_ctx)); + return; + } + + __mon_event_count(closid, rmid, &rr); =20 /* - * This is protected from concurrent reads from user - * as both the user and we hold the global mutex. + * If the software controller is enabled, compute the + * bandwidth for this event id. */ - if (is_mbm_total_enabled()) { - rr.evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID; - rr.val =3D 0; - rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); - if (IS_ERR(rr.arch_mon_ctx)) { - pr_warn_ratelimited("Failed to allocate monitor context: %ld", - PTR_ERR(rr.arch_mon_ctx)); - return; - } + if (is_mba_sc(NULL)) + mbm_bw_count(closid, rmid, &rr); =20 - __mon_event_count(closid, rmid, &rr); - - resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); - } - if (is_mbm_local_enabled()) { - rr.evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID; - rr.val =3D 0; - rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); - if (IS_ERR(rr.arch_mon_ctx)) { - pr_warn_ratelimited("Failed to allocate monitor context: %ld", - PTR_ERR(rr.arch_mon_ctx)); - return; - } - - __mon_event_count(closid, rmid, &rr); + resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); +} =20 - /* - * Call the MBA software controller only for the - * control groups and when user has enabled - * the software controller explicitly. - */ - if (is_mba_sc(NULL)) - mbm_bw_count(closid, rmid, &rr); +static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, + u32 closid, u32 rmid) +{ + /* + * This is protected from concurrent reads from user as both + * the user and overflow handler hold the global mutex. + */ + if (is_mbm_total_enabled()) + mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID); =20 - resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); - } + if (is_mbm_local_enabled()) + mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID); } =20 /* --=20 2.47.0