Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp27898rdb; Mon, 22 Jan 2024 10:48:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKFHxhiwNYoht/rZy/+/05o19JBwNBPcMy/yM5Y8PdXgVQoghQUAqR0L8EHVLzyZau6YVt X-Received: by 2002:a05:6a20:3941:b0:19b:1d39:a567 with SMTP id r1-20020a056a20394100b0019b1d39a567mr2144051pzg.47.1705949309721; Mon, 22 Jan 2024 10:48:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705949309; cv=pass; d=google.com; s=arc-20160816; b=VD07AXcF1B+jT4FNXUHHDAVilFS6j6cW4aF4A6h++4ZD1G+8fzi/ilTsH41oRaeh2O utwrCgKoR0eEgbzfXf+u53vHVWFtzT4CsQ9trdjAfFT1B+tE0xz/5ne04VT6cpe2kItI sT67wvd1W9fB3kYMtXPyuAYT1vm0WocZ4TnjXcYZ0SfBenrEBYgh2tnZDzvEmCfZc+yl /FmEvytR+qFHKulb/bvZ7W4uraLVGu512pYDy7d4XHAqUaHcgEFCFbqQ/vX4+oygXgvW uvpRJCmKcvUw0bpABCrVFiMr6fANOT7SoevMHaaYXX9yXc9k3Yx3aRMzDd4X6jtBKseY gMcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mduEbg0+6pWbfhLQwhBko/+Koox4VJoFdyU+S5ObwsE=; fh=wabzPehvY+8ExyHdPkZ7+34uni000AYzU46+1cAt/gI=; b=f8ryoNyvCkQRXiaoggFRM2/sVDD3a67iaQZKBFaHvXBkZ/or8SDs6zVzFN7VKAP3jB XZP9rNnOeeod/S1Iud6mW2Xd+GLBWnycy9NEBhz9FK9PrsmbBCzj/PsMaglA+ZreFvuO /NES9oX1mmXBPGMa+xl90gz8I0hC9EYoDczt6LYMKs3semcA1oKjbO7UzS6ATjmqAikH gXYgaSU5Q1RUnDWrkWVVktVnrhyGDmBvMymP36NZfEkh0ScP3E1+dmeqTZ3bkpyZ3G5U S4PxRmxwqlLV2iDGpAm6Mnmtc4xojsAJ6C+LogJvCTszTXJmWJhfKX8Uv/rsuVShJshW CKWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WY8oGVYB; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-33910-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l3-20020a17090a150300b0028dbbeaa18dsi8412126pja.120.2024.01.22.10.48.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 10:48:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33910-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WY8oGVYB; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-33910-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C9948294040 for ; Mon, 22 Jan 2024 18:36:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F73D55C21; Mon, 22 Jan 2024 18:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WY8oGVYB" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 90CBB56470 for ; Mon, 22 Jan 2024 18:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705946898; cv=none; b=St+qCzVe7iLYyQ8suw3WfTMIXxd9H/GOOAiSpaXlzOHAnu0xVebK2KFDKknb/vsVHSBZFKm0k+gFsOH55R0IlA8IXwDc1+Sfu0UAL+XXh7UhTA+J7AZjIP4RyL9DiPMrBjWI7wQUOpY0zg6tJNx1QXSgLk1XT36TzY+QYBwjA7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705946898; c=relaxed/simple; bh=VOl/tWnPHQoqS1cXUmh7wGTtB6as1Bks3zWGadAFdtU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iLzuTh4eeVbUtW9fFkCKVVJPUbp7K/Smk48ZVH0O+NH+ZJaF2ID9KXXhUbXtHrhq7bmB+rDZua6ulf9jpfw5eNSqQhPSJLGcx7aI7JMpf5x/SiFumCqcNyLCdKbEcetpO0qj2TeJm7c14rnJiI4gdJfPmqr3ac0QtrKMucrQq+4= 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=WY8oGVYB; arc=none smtp.client-ip=198.175.65.10 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705946897; x=1737482897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VOl/tWnPHQoqS1cXUmh7wGTtB6as1Bks3zWGadAFdtU=; b=WY8oGVYBiSNoFG32ea1l8RFCkpwFJzb2EGy4jXXcaRuhZRDKVkJugGPW 1o/E9RPVBOkRBeF1qLgtoyTfIfKvB4FKyaLQ1PUUujShI+aYBGZtasCCN ZA5+YJzNclZITDoP2r9msFYtw4AwrG07jrFiCt0F7XfBa5zfjlmDpXkcz rV1xZqKAS25AnRVe00KceGlIqWT+3a7he3UYqcUVM9yMPjgQJKdzPOdDH pQ+A2DgbSYM9xTxkYuniIdA37JnOZHNT2NXa+UwVur/CzO4giOjTk4VuH 5vKnNQ3uYPBKKR1S6eWl9RWBP0jvZvW2pWMNwOkRXAjS+fh184JmPDGZP g==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="14627538" X-IronPort-AV: E=Sophos;i="6.05,211,1701158400"; d="scan'208";a="14627538" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 10:08:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,211,1701158400"; d="scan'208";a="1375980" Received: from agluck-desk3.sc.intel.com ([172.25.222.74]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 10:08:14 -0800 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Peter Newman , x86@kernel.org Cc: James Morse , Jamie Iles , Babu Moger , Xiaochen Shen , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v3] x86/resctrl: Implement new mba_MBps throttling heuristic Date: Mon, 22 Jan 2024 10:08:07 -0800 Message-ID: <20240122180807.70518-1-tony.luck@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118214213.59596-1-tony.luck@intel.com> References: <20240118214213.59596-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: 8bit The mba_MBps feedback loop increases throttling when a group is using more bandwidth than the target set by the user in the schemata file, and decreases throttling when below target. To avoid possibly stepping throttling up and down on every poll a flag "delta_comp" is set whenever throttling is changed to indicate that the actual change in bandwidth should be recorded on the next poll in "delta_bw". Throttling is only reduced if the current bandwidth plus delta_bw is below the user target. This algorithm works well if the workload has steady bandwidth needs. But it can go badly wrong if the workload moves to a different phase just as the throttling level changed. E.g. if the workload becomes essentially idle right as throttling level is increased, the value calculated for delta_bw will be more or less the old bandwidth level. If the workload then resumes, Linux may never reduce throttling because current bandwidth plus delta_bw is above the target set by the user. Implement a simpler heuristic by assuming that in the worst case the currently measured bandwidth is being controlled by the current level of throttling. Compute how much it may increase if throttling is relaxed to the next higher level. If that is still below the user target, then it is ok to reduce the amount of throttling. Fixes: ba0f26d8529c ("x86/intel_rdt/mba_sc: Prepare for feedback loop") Reported-by: Xiaochen Shen Signed-off-by: Tony Luck Tested-by: Xiaochen Shen Reviewed-by: Reinette Chatre --- v2->v3 changes: Reinette noticed a reverse fir tree breakage in update_mba_bw() arch/x86/kernel/cpu/resctrl/internal.h | 4 --- arch/x86/kernel/cpu/resctrl/monitor.c | 42 ++++++-------------------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index a4f1aa15f0a2..71bbd2245cc7 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -296,14 +296,10 @@ struct rftype { * struct mbm_state - status for each MBM counter in each domain * @prev_bw_bytes: Previous bytes value read for bandwidth calculation * @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 prev_bw_bytes; u32 prev_bw; - u32 delta_bw; - bool delta_comp; }; /** diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index f136ac046851..6c2d4e97e5f1 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -440,9 +440,6 @@ static void mbm_bw_count(u32 rmid, struct rmid_read *rr) cur_bw = bytes / SZ_1M; - if (m->delta_comp) - m->delta_bw = abs(cur_bw - m->prev_bw); - m->delta_comp = false; m->prev_bw = cur_bw; } @@ -520,11 +517,11 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) { u32 closid, rmid, cur_msr_val, new_msr_val; struct mbm_state *pmbm_data, *cmbm_data; - u32 cur_bw, delta_bw, user_bw; struct rdt_resource *r_mba; struct rdt_domain *dom_mba; struct list_head *head; struct rdtgroup *entry; + u32 cur_bw, user_bw; if (!is_mbm_local_enabled()) return; @@ -543,7 +540,6 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) cur_bw = pmbm_data->prev_bw; user_bw = dom_mba->mbps_val[closid]; - delta_bw = pmbm_data->delta_bw; /* MBA resource doesn't support CDP */ cur_msr_val = resctrl_arch_get_config(r_mba, dom_mba, closid, CDP_NONE); @@ -555,49 +551,31 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) list_for_each_entry(entry, head, mon.crdtgrp_list) { cmbm_data = &dom_mbm->mbm_local[entry->mon.rmid]; cur_bw += cmbm_data->prev_bw; - delta_bw += cmbm_data->delta_bw; } /* * Scale up/down the bandwidth linearly for the ctrl group. The * bandwidth step is the bandwidth granularity specified by the * hardware. - * - * The delta_bw is used when increasing the bandwidth so that we - * dont alternately increase and decrease the control values - * continuously. - * - * For ex: consider cur_bw = 90MBps, user_bw = 100MBps and if - * bandwidth step is 20MBps(> user_bw - cur_bw), we would keep - * switching between 90 and 110 continuously if we only check - * cur_bw < user_bw. + * Always increase throttling if current bandwidth is above the + * target set by user. + * But avoid thrashing up and down on every poll by checking + * whether a decrease in throttling is likely to push the group + * back over target. E.g. if currently throttling to 30% of bandwidth + * on a system with 10% granularity steps, check whether moving to + * 40% would go past the limit by multiplying current bandwidth by + * "(30 + 10) / 30". */ if (cur_msr_val > r_mba->membw.min_bw && user_bw < cur_bw) { new_msr_val = cur_msr_val - r_mba->membw.bw_gran; } else if (cur_msr_val < MAX_MBA_BW && - (user_bw > (cur_bw + delta_bw))) { + (user_bw > (cur_bw * (cur_msr_val + r_mba->membw.min_bw) / cur_msr_val))) { new_msr_val = cur_msr_val + r_mba->membw.bw_gran; } else { return; } resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val); - - /* - * Delta values are updated dynamically package wise for each - * rdtgrp every time the throttle MSR changes value. - * - * This is because (1)the increase in bandwidth is not perfectly - * linear and only "approximately" linear even when the hardware - * says it is linear.(2)Also since MBA is a core specific - * mechanism, the delta values vary based on number of cores used - * by the rdtgrp. - */ - pmbm_data->delta_comp = true; - list_for_each_entry(entry, head, mon.crdtgrp_list) { - cmbm_data = &dom_mbm->mbm_local[entry->mon.rmid]; - cmbm_data->delta_comp = true; - } } static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid) base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d -- 2.43.0