Skip to content

Commit 521348b

Browse files
rchatreIngo Molnar
authored andcommitted
x86/intel_rdt: Introduce utility to obtain CDP peer
Introduce a utility that, when provided with a RDT resource and an instance of this RDT resource (a RDT domain), would return pointers to the RDT resource and RDT domain that share the same hardware. This is specific to the CDP resources that share the same hardware. For example, if a pointer to the RDT_RESOURCE_L2DATA resource (struct rdt_resource) and a pointer to an instance of this resource (struct rdt_domain) is provided, then it will return a pointer to the RDT_RESOURCE_L2CODE resource as well as the specific instance that shares the same hardware as the provided rdt_domain. This utility is created in support of the "exclusive" resource group mode where overlap of resource allocation between resource groups need to be avoided. The overlap test need to consider not just the matching resources, but also the resources that share the same hardware. Temporarily mark it as unused in support of patch testing to avoid compile warnings until it is used. Fixes: 49f7b4e ("x86/intel_rdt: Enable setting of exclusive mode") Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Jithu Joseph <jithu.joseph@intel.com> Acked-by: Fenghua Yu <fenghua.yu@intel.com> Cc: tony.luck@intel.com Cc: gavin.hindman@intel.com Cc: dave.hansen@intel.com Cc: hpa@zytor.com Link: https://lkml.kernel.org/r/9b4bc4d59ba2e903b6a3eb17e16ef41a8e7b7c3e.1538603665.git.reinette.chatre@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent fc8eaa8 commit 521348b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

arch/x86/kernel/cpu/intel_rdt_rdtgroup.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,
960960
return 0;
961961
}
962962

963+
/**
964+
* rdt_cdp_peer_get - Retrieve CDP peer if it exists
965+
* @r: RDT resource to which RDT domain @d belongs
966+
* @d: Cache instance for which a CDP peer is requested
967+
* @r_cdp: RDT resource that shares hardware with @r (RDT resource peer)
968+
* Used to return the result.
969+
* @d_cdp: RDT domain that shares hardware with @d (RDT domain peer)
970+
* Used to return the result.
971+
*
972+
* RDT resources are managed independently and by extension the RDT domains
973+
* (RDT resource instances) are managed independently also. The Code and
974+
* Data Prioritization (CDP) RDT resources, while managed independently,
975+
* could refer to the same underlying hardware. For example,
976+
* RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache.
977+
*
978+
* When provided with an RDT resource @r and an instance of that RDT
979+
* resource @d rdt_cdp_peer_get() will return if there is a peer RDT
980+
* resource and the exact instance that shares the same hardware.
981+
*
982+
* Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists.
983+
* If a CDP peer was found, @r_cdp will point to the peer RDT resource
984+
* and @d_cdp will point to the peer RDT domain.
985+
*/
986+
static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r,
987+
struct rdt_domain *d,
988+
struct rdt_resource **r_cdp,
989+
struct rdt_domain **d_cdp)
990+
{
991+
struct rdt_resource *_r_cdp = NULL;
992+
struct rdt_domain *_d_cdp = NULL;
993+
int ret = 0;
994+
995+
switch (r->rid) {
996+
case RDT_RESOURCE_L3DATA:
997+
_r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE];
998+
break;
999+
case RDT_RESOURCE_L3CODE:
1000+
_r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA];
1001+
break;
1002+
case RDT_RESOURCE_L2DATA:
1003+
_r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE];
1004+
break;
1005+
case RDT_RESOURCE_L2CODE:
1006+
_r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA];
1007+
break;
1008+
default:
1009+
ret = -ENOENT;
1010+
goto out;
1011+
}
1012+
1013+
/*
1014+
* When a new CPU comes online and CDP is enabled then the new
1015+
* RDT domains (if any) associated with both CDP RDT resources
1016+
* are added in the same CPU online routine while the
1017+
* rdtgroup_mutex is held. It should thus not happen for one
1018+
* RDT domain to exist and be associated with its RDT CDP
1019+
* resource but there is no RDT domain associated with the
1020+
* peer RDT CDP resource. Hence the WARN.
1021+
*/
1022+
_d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
1023+
if (WARN_ON(!_d_cdp)) {
1024+
_r_cdp = NULL;
1025+
ret = -EINVAL;
1026+
}
1027+
1028+
out:
1029+
*r_cdp = _r_cdp;
1030+
*d_cdp = _d_cdp;
1031+
1032+
return ret;
1033+
}
1034+
9631035
/**
9641036
* rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other
9651037
* @r: Resource to which domain instance @d belongs.

0 commit comments

Comments
 (0)