From patchwork Mon Aug 19 22:07:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 13769038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E267FC3DA4A for ; Mon, 19 Aug 2024 22:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=bAWPpH98uB1OTCvvhWjODEhWm2A9dY5cc7zY2QcbBew=; b=tgs593mAQXSEg26uXELxA1ImhF QP0TtVq53nAKwb/gGBTxUNyJGhm3xxs8AZ0ZTi7J+LBP2C1Ic1XWUM2AYlbh0+xvGTxqDAGwU8P40 ftr5MEu8f/Yi4Upjn2zvVlVB3zi330lshXBxfsbimaFBuu/riEyyoo+J3USGhptCcLHWpNFfIV4ek i/Mrc8EOp/6Q0MIW7aeruPyHKUpljdtNEzIdpiG2KXHtjtSlvuvLsF0ALKMScQL5fa2svh2l5jsGJ 4yW3jKJcFTHwczUrOLvr1GGd4fDKdh7DXEDQBC90o+8LEXRBwPuvfPbW8uYHxKKptE47Aw8YdcHN3 ShJmZibw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgAZ0-000000034Me-3M3z; Mon, 19 Aug 2024 22:09:22 +0000 Received: from mail-dm3nam02on20600.outbound.protection.outlook.com ([2a01:111:f403:2405::600] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgAYJ-000000034Ds-1ySK for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 22:08:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kCEcKQaNfzFZMX8dyCzBH6YdoYPbckX3GOp3QMBHMYdorsjeIGFENIHzEsrxUPMc8MCJciDQpdUHntR8d7vvzZfsWUPyGY+JOozWBvCVba20uIsBPO4i7eiH4EBV0H6Wijz75VoYczzsjcCAf+bFCS3s3wLeBHlRPTkfbc9HjYGtE76hwjz0FnP2lJLwjW72aM4gv5FjAcnwyMw/oZfuAUDiPkzBQIABtnIrFUAAoz7A2mEuU38+k1jDgKrg2R3PA8KZQp/9+NtP+tvrToJ3WkxwI7x9wbMmCikv8/UBcIDStJu+tyqQw6jhRJ9pT1gkPR2Jk1Gp24PhEnrZza5Yzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bAWPpH98uB1OTCvvhWjODEhWm2A9dY5cc7zY2QcbBew=; b=cMw6L/ooSYq4w8lB00YRAN7/xtEjpDGpEZQKCR0IFuwSEerdmtdzAqUuRCaOJ3H1R2K/FKRO/FUEJ2PHuOVF1jn1ICQ8RIDFQz3wAmeJoVSubZEUMjxIbLmlLgKirBv9M7aKJ5bbVeZ+4RdOwHDOQBrqVyGvRWTj9Qt53X5lyRNruBp4Mu1SZQOW84eBfFcNF34EA7MvSBLeTrdgL8hBQ62DLZ+etYMbbpf5r0S7feplJvpzQczqRz01vJ6pJ5OR3uLj1TnA6gqF1LLLY2ek3yJnPrQyogzDpWfymownvWSGnLHF/rMGEfLf8cb0Rr9ZXdQDTH2cQUNZE1Jlz719DQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bAWPpH98uB1OTCvvhWjODEhWm2A9dY5cc7zY2QcbBew=; b=aui03HRMWDpgcQjSkzW01NKZ1H6/NLixB5ob0040Gg+0FDGu1dc9kUkA0EUPLDZOqjSKHuYTb7fYLfsZjhr12mjJg5gjmNqhouVuF56bPdbxgK370HZt3suoHUKzkh3KgpUKAPGEih5q13h3IaxgcLStuHnTc8HWLUNtF8jqM0csT+ZaN1trn9jEzdRG5w6adbKbMmQAkHOZyomY2KeH0+9oopUiuj8vpCSBt4R49JNgzwgI6UrH8bknY+eEUZVDNQS2j7XHG++COwAZ6c0mj+As20yCXZBRPyDMd8gK/+g49frDo1dmU8uMKkVAh76pL8r3wGVQfJdNyLX9z4h46A== Received: from SJ0PR13CA0222.namprd13.prod.outlook.com (2603:10b6:a03:2c1::17) by SN7PR12MB6984.namprd12.prod.outlook.com (2603:10b6:806:260::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Mon, 19 Aug 2024 22:08:26 +0000 Received: from SJ1PEPF0000231D.namprd03.prod.outlook.com (2603:10b6:a03:2c1:cafe::65) by SJ0PR13CA0222.outlook.office365.com (2603:10b6:a03:2c1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.13 via Frontend Transport; Mon, 19 Aug 2024 22:08:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ1PEPF0000231D.mail.protection.outlook.com (10.167.242.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Mon, 19 Aug 2024 22:08:26 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 19 Aug 2024 15:08:07 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 19 Aug 2024 15:08:07 -0700 Received: from SDONTHINENI-DESKTOP.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 19 Aug 2024 15:08:06 -0700 From: Shanker Donthineni To: James Morse CC: Catalin Marinas , Shanker Donthineni , Rohit Mathew , , , , Vikram Sethi Subject: [PATCH] arm_mpam: resctrl: Update only requested configuration Date: Mon, 19 Aug 2024 17:07:52 -0500 Message-ID: <20240819220752.201815-1-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF0000231D:EE_|SN7PR12MB6984:EE_ X-MS-Office365-Filtering-Correlation-Id: d557f863-a273-4687-4eaf-08dcc09b7325 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: G8Uk1baU+nkh+UCr9HBGOnviPEutCfBo0VJdbLYW7yQjyrE6akFI/ZSMOKYu971KkJZLL0AHXdzSwtb3Qk9pAMU7d0z9DE22fUqgVEAqUBl4XYQuMKj8k/ohQgOuInjNVlGDhynxn0x+HJ9/lmqcnH+cc35RGlnkgzZvEoUtge0w25aoSU1z8m3WFzqgTT6lhikHaTSyrConrJgmQdUiu+qGkgW8qtSRdcywTCexaBlZTGOIhTfpzAVk5CW6i86QxFW6kj1D4RTGmBLDgttYFT/qhZMS4kptmZYVoUWT6KkNTbgpJ53tC454MA1ZE29fJZeB3PPhg0NWmAJDxa5TZWV1WSZdV7x97f7dQ5LRWSMl7LCI9JpjYxUvKZ1YE83yjAd3jRRbVat/uVKU0D5LHKRlF4zgUoTXNneJq5JJ2i2QoOkcmsSv1LqYLIgt/UErrjQ17zSbgujWHJnQ86Uat0wABRB8rDaMJ6VXz2SgKMUvhMLGbQDPS3/sZiS2Jne2hp5BZhdTs0VAMuB9j79JbzQrf1q7b0jgs9xXKob9qIhQxfGpB/N8TSuvYZI5+ewViQyD4XA/VM9h3cOQN+6sYBGRRNhR5GHjkHfomLXCC8bTUR1iu2HoWdicMXp7/J10G4DCey6gjiVTjCO5EMJVhUth3xG5Mv0acF1NIiOqp7Z5nlAGwQI8BWlgMrQcquHU5TK7mWmiVHi1/FdHysKzeVPUvLQpiUsv9KnXOYg0aO8N05KmDO6qnqR74jIVESe+Gvuefsnf9+oOqEmdiow+q8nRptwMP/bU86se+TF6ME77242+2EogKUmvDoeQfgJUqmgoicdu5Tyo2aZJ3qyEN18e80KFhU6pZn64wedAFYohAN5m3J4iDxldrnxywhK+7sBulzSsJEiDQhKuxBykNWKELxe+HolOMyebKJq4l1X01P8xXC1D4aoXJJocV8ijXWS+R5dWsYn0sOEBRX50ELDWymI9+oBF7gcfieXYMZ8yKl4omfKn/DGDx2rMawjvpI9Nbb9fnYW5XUIoFrw1ttO7P5g0xy9f1h15BIz6F3NS+ehYM5qonK4VeX/IDsu3IawDCrDGzBMqRD7jAK2tHPJm1Vgc5BmHJQU9TiBrY1yWk1W2yOrg4z/6kLSHsQCKSF7cUuartsyjg9c7tZ4HjWgbklto6mSUSzL9QR249bfJMgchB84k6Zu6syoE+zHfXHTLYiMd8Z3+dn1yEJTQ2JtOoOp2EtwDWcXbdZeLOxr2Gimh0cOqZ9nNNne/s6jTi1RlJeLukdpoSGAGXZhvvbAe/jNr6ck9u9+HyGgFpnyvCDEmXHq1Bm+F4LT5af4aKtKR/vjfSBQoqrwX+eCYCCvzt9bXqdXSRlSz5LJlnaDN7zcg63jediY++a6Duu4u6BsVKgYUhET3zjDBg7RvNnhxbpvkACLngCaL1vsgHGapcYvJGVPqjFeswkIdh9Sv X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2024 22:08:26.2806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d557f863-a273-4687-4eaf-08dcc09b7325 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF0000231D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6984 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_150839_554448_6A90BF21 X-CRM114-Status: GOOD ( 13.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The resctrl has helper functions for updating CPOR and MBW configuration updates. While the existing resctrl_arch_update_one() effectively updates the specified configuration as intended, it inadvertently overrides other configurations with default values. Example bandwdith value is not applied: root# cat /sys/fs/resctrl/schemata MB:1=100 L3:1=fff root# echo -e "L3:1=fff\nMB:1=50" > /sys/fs/resctrl/schemata root# cat /sys/fs/resctrl/schemata MB:1=100 L3:1=fff Fix the potential loss of accuracy during the conversion of MBW_MAX from percentage to fixed-point representation, and vice versa. The updated functions provide fixed-point values that closely align with the values specified in the MPAM specification, Table 9-3 for Fraction Widths And Hex Representation. Before this fix: root# echo -e "MB:1=1" > /sys/fs/resctrl/schemata root# cat /sys/fs/resctrl/schemata MB:1=000 L3:1=fff root# echo -e "MB:1=2" > /sys/fs/resctrl/schemata root# cat /sys/fs/resctrl/schemata MB:1=001 L3:1=fff root# echo -e "MB:1=3" > /sys/fs/resctrl/schemata root@pset# cat /sys/fs/resctrl/schemata MB:1=001 L3:1=fff With this patch: root# echo -e "MB:1=1" > /sys/fs/resctrl/schemata root# cat /sys/fs/resctrl/schemata MB:1=001 L3:1=fff root# echo -e "MB:1=2" > /sys/fs/resctrl/schemata root# cat /sys/fs/resctrl/schemata MB:1=002 L3:1=fff root# echo -e "MB:1=3" > /sys/fs/resctrl/schemata root@pset# cat /sys/fs/resctrl/schemata MB:1=003 L3:1=fff Signed-off-by: Shanker Donthineni --- drivers/platform/arm64/mpam/mpam_resctrl.c | 49 ++++------------------ 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index 258a39e90f2e..f4da24cad600 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -574,23 +574,7 @@ static u32 mbw_pbm_to_percent(const unsigned long mbw_pbm, struct mpam_props *cp static u32 mbw_max_to_percent(u16 mbw_max, struct mpam_props *cprops) { - int bit; - u8 num_bits = 0; - u32 divisor = 2, value = 0; - - for (bit = 16; bit > (16 - cprops->bwa_wd); bit--) { - if (mbw_max & BIT(bit - 1)) { - num_bits++; - value += MAX_MBA_BW / divisor; - } - divisor <<= 1; - } - - /* Lest user-space get confused... */ - if (num_bits == cprops->bwa_wd) - return 100; - - return value; + return DIV_ROUND_CLOSEST((mbw_max + 1) * 100, 65536); } static u32 percent_to_mbw_pbm(u8 pc, struct mpam_props *cprops) @@ -605,31 +589,7 @@ static u32 percent_to_mbw_pbm(u8 pc, struct mpam_props *cprops) static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops) { - u8 bit; - u32 divisor = 2, value = 0, milli_pc; - - /* - * To ensure 100% sets all the bits, we need to the contribution - * of bits worth less than 1%. Scale everything up by 1000. - */ - milli_pc = pc * 1000; - - for (bit = 16; bit > (16 - cprops->bwa_wd); bit--) { - if (milli_pc >= MAX_MBA_BW * 1000 / divisor) { - milli_pc -= MAX_MBA_BW * 1000 / divisor; - value |= BIT(bit - 1); - } - divisor <<= 1; - - if (!milli_pc) - break; - } - - /* Mask out unimplemented bits */ - if (cprops->bwa_wd <= 16) - value &= GENMASK(15, 16 - cprops->bwa_wd); - - return value; + return (((pc * 65536) / 100) - 1); } /* Find the L3 component that holds this CPU */ @@ -1167,6 +1127,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, if (!r->alloc_capable || partid >= resctrl_arch_get_num_closid(r)) return -EINVAL; + /* Update with requested configuration only */ + cfg = dom->comp->cfg[partid]; + switch (r->rid) { case RDT_RESOURCE_L2: case RDT_RESOURCE_L3: @@ -1182,6 +1145,8 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, } else if (mpam_has_feature(mpam_feat_mbw_max, cprops)) { cfg.mbw_max = percent_to_mbw_max(cfg_val, cprops); mpam_set_feature(mpam_feat_mbw_max, &cfg); + /* Resctrl doesn't support MBW_MIN yet, use default value */ + mpam_clear_feature(mpam_feat_mbw_min, &cfg.features); break; } fallthrough;