Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp111817rdh; Tue, 13 Feb 2024 10:55:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+tbMlh2ZdycnphSrPYRxeIUUppWqjBgb9Uy5vSN576UbRwMqIuuaa/QlpqftYlDRiT413fi8lp23Cz+ZvdYS/sd9ZenOcYVQKJfBOcA== X-Google-Smtp-Source: AGHT+IH9vvgGlGIgTFa0Ozy5flZ7+7FAk7Znvj822ipzeDa94SfIHZ3PEJoYC0WMU1CIfKX0o/t0 X-Received: by 2002:aa7:8617:0:b0:6e0:9900:117f with SMTP id p23-20020aa78617000000b006e09900117fmr148538pfn.6.1707850506995; Tue, 13 Feb 2024 10:55:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707850506; cv=pass; d=google.com; s=arc-20160816; b=je67eROxZ8C0Y16cIrSvf2fkmVULxoiQEJWWsHvX2K6VEP3xuM3vL+R2RvLWWIrZXi rGivfjAAOPv2BgsPVPmuRFznIx1p12VDjnv0ewv2waUOXxBj/sCr4h8B2W3O6BbDawoH ZjURFks8esbMXqTTZFDB5lRDteLyNpG6NWsVH5cg6u6p5HoF0creDFDIqX+nn2BIcnJ6 OciVTkEm5rY24L9AxS3dpt4ID+daeZPRhUrNKfGAKhbhKmJKNGlTbK0jziV7D2noloGj iqJj3Dp1O/WD+6iXggzRMPov+qK0HRyI16XbhLr1AqGKZGb93TX+NiryTgfrXvvBHcad 76OA== 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; bh=yKCbwn03evTkb1pYfysjE7wPYkPceMkGFBq5p9Eo8IQ=; fh=WBLDs7r2lPItulA7ISBSzzfzupa/DWOgVqCxtTx/Vms=; b=iCfU0jlfobVNfuOXpbNFYcx1ytfU8b5XIfp5osA7FU0IkizskaTSiLki05m+2RlWyd OAT8AdDVaO0aKGN4Y1o05PAw+kcrExHe2uQiECZESpHZGh6WGWG/7G4LQiOPVKb/vNtl aQd1nQCb97e5OR8EoQtBZi1/69eslpcIW3WNjcQcEOs0jwcbzGiheDnlGuF5m9x/XlXy b+l7tr3J6mvhtuTyvveH4yBQxc/+FyNnuz7HEydyt//KzrEQNBTC2fl0jR/KNYxLxhZI n0pSYKJZaS3DmPZQZHShc5xByCwMcbkfDXwnKWSMG5dc5/kkguIeeoKpr0gisHyoUFlk Vkgw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64098-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVeSx2AG24suGLJ2TnXrp/U3j3qAbKqQNPE1cRTYSo5GmaUARaMR4QeYpf8uySLbZMVXPxB835JBbRTWANWKUmuMOinaYeMkfXpjBPKMA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e2-20020aa78c42000000b006e04eefda8bsi7034535pfd.40.2024.02.13.10.55.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:55:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64098-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-64098-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 5F3A528E178 for ; Tue, 13 Feb 2024 18:46:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B7D560B87; Tue, 13 Feb 2024 18:45:28 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 150681F5FA for ; Tue, 13 Feb 2024 18:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849927; cv=none; b=nuoYLLFLaMp1XgURrTY/L+ggPExOp/8qopx8QuvWKKFFeOWmceQKKwDwZc/NMgXRuVt1KuMobnjFF4Ga2TeZBLL4JsCyXj4cdUz9L/UUKOPX8LcTCFk72/xcVVz3/z5J6VyvLDW7950XCImSRVo+xDwe2OD1kBpsrHPX5SH2K0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849927; c=relaxed/simple; bh=6ebG69cbFczaqBbQqA7uAG5WhTVnWJljhAVqTzlCvT4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M3B0ciqvFjs//ge32fkB5CS6wS/TbZlguDiOrME+IEhPHU9R0Wnbk2Tgn8ilWHRr3wwJ+SUAbfKooc3SOys+IC+HMFCqf2n4p3OGrJ3AiKcf3b0d8GcGXvLjj5R11tBAc41KWAeG9VzbdN8Biescj3Z7JHv7IGoGGa3Ip7EVnq4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B23AE1476; Tue, 13 Feb 2024 10:46:06 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5AA3A3F766; Tue, 13 Feb 2024 10:45:22 -0800 (PST) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Babu Moger Subject: [PATCH v9 07/24] x86/resctrl: Allow RMID allocation to be scoped by CLOSID Date: Tue, 13 Feb 2024 18:44:21 +0000 Message-Id: <20240213184438.16675-8-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240213184438.16675-1-james.morse@arm.com> References: <20240213184438.16675-1-james.morse@arm.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 MPAMs RMID values are not unique unless the CLOSID is considered as well. alloc_rmid() expects the RMID to be an independent number. Pass the CLOSID in to alloc_rmid(). Use this to compare indexes when allocating. If the CLOSID is not relevant to the index, this ends up comparing the free RMID with itself, and the first free entry will be used. With MPAM the CLOSID is included in the index, so this becomes a walk of the free RMID entries, until one that matches the supplied CLOSID is found. Signed-off-by: James Morse Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- Changes since v2; * Rephrased comment in resctrl_find_free_rmid() to describe this in terms of list_entry_first() * Rephrased comment above alloc_rmid() Changes since v3: * Flipped conditions in alloc_rmid() Changes since v4: * Typo in comment Changes since v5: * Reworded two comments. Changes since v6: * Fixed a typo and some whitespace. --- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 51 +++++++++++++++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index cbba782acd0c..872ba1a34103 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -543,7 +543,7 @@ void rdtgroup_pseudo_lock_remove(struct rdtgroup *rdtgrp); struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r); int closids_supported(void); void closid_free(int closid); -int alloc_rmid(void); +int alloc_rmid(u32 closid); void free_rmid(u32 closid, u32 rmid); int rdt_get_mon_l3_config(struct rdt_resource *r); void __exit rdt_put_mon_l3_config(void); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index bc5ceef143ab..c49f2e89ef29 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -344,24 +344,49 @@ bool has_busy_rmid(struct rdt_domain *d) return find_first_bit(d->rmid_busy_llc, idx_limit) != idx_limit; } -/* - * As of now the RMIDs allocation is global. - * However we keep track of which packages the RMIDs - * are used to optimize the limbo list management. - */ -int alloc_rmid(void) +static struct rmid_entry *resctrl_find_free_rmid(u32 closid) { - struct rmid_entry *entry; - - lockdep_assert_held(&rdtgroup_mutex); + struct rmid_entry *itr; + u32 itr_idx, cmp_idx; if (list_empty(&rmid_free_lru)) - return rmid_limbo_count ? -EBUSY : -ENOSPC; + return rmid_limbo_count ? ERR_PTR(-EBUSY) : ERR_PTR(-ENOSPC); + + list_for_each_entry(itr, &rmid_free_lru, list) { + /* + * Get the index of this free RMID, and the index it would need + * to be if it were used with this CLOSID. + * If the CLOSID is irrelevant on this architecture, the two + * index values are always the same on every entry and thus the + * very first entry will be returned. + */ + itr_idx = resctrl_arch_rmid_idx_encode(itr->closid, itr->rmid); + cmp_idx = resctrl_arch_rmid_idx_encode(closid, itr->rmid); + + if (itr_idx == cmp_idx) + return itr; + } + + return ERR_PTR(-ENOSPC); +} + +/* + * For MPAM the RMID value is not unique, and has to be considered with + * the CLOSID. The (CLOSID, RMID) pair is allocated on all domains, which + * allows all domains to be managed by a single free list. + * Each domain also has a rmid_busy_llc to reduce the work of the limbo handler. + */ +int alloc_rmid(u32 closid) +{ + struct rmid_entry *entry; + + lockdep_assert_held(&rdtgroup_mutex); + + entry = resctrl_find_free_rmid(closid); + if (IS_ERR(entry)) + return PTR_ERR(entry); - entry = list_first_entry(&rmid_free_lru, - struct rmid_entry, list); list_del(&entry->list); - return entry->rmid; } diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index 65bee6f11015..d8f44113ed1f 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -777,7 +777,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp) int ret; if (rdt_mon_capable) { - ret = alloc_rmid(); + ret = alloc_rmid(rdtgrp->closid); if (ret < 0) { rdt_last_cmd_puts("Out of RMIDs\n"); return ret; diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index a7dbc0e7e559..dcffd1c4a476 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3295,7 +3295,7 @@ static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp) if (!rdt_mon_capable) return 0; - ret = alloc_rmid(); + ret = alloc_rmid(rdtgrp->closid); if (ret < 0) { rdt_last_cmd_puts("Out of RMIDs\n"); return ret; -- 2.39.2