Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1850233imm; Sat, 6 Oct 2018 11:52:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV62lI2oIMuef9U4Be0XcjC7dzFOV23A47TAm9XuKHwvbWMl+NXKyFyBq6r1ecW/0lvneMWOR X-Received: by 2002:a62:d046:: with SMTP id p67-v6mr18269323pfg.147.1538851940091; Sat, 06 Oct 2018 11:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538851940; cv=none; d=google.com; s=arc-20160816; b=FmP+nAGJIQYdI+VhpK/NWS9+ZCMSiZ2g/tp78s72nb1coo8zJmQ5uVweMqwZr+9kwA c7prmhJeJf+rutkQptls7CamPpltD7IKpDIkkDMqcySEbIcssS8VNDOkV5L4QtphoAgj U0IC5qJa5/uZ10dJ0praNEbEy0208i6BdNNTAPmUxevfuxzZfr55YZ/Hdy0OnEDwS2nL BvE19d7tE2GSt/ZF6eJb4PX6EbydjQXD5aPwMHHGcL2lxXHnYHu937AcMbfEmfmINc2E g0W82nH2Xdxi8ySXhCSpdUlXKlyVxHTvXvBm0aj9Qg46t5EEch6Hrf2qpuhVyC704JGw FatQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=F/xrCrfLbS8MRDYI0XaPw8YU8xdQczYLzTGTQVjs2rU=; b=vQ2AjW2TGnXZ2pelXpMz39lV5Y5XBzCLg/VLBVoLgOKonCFA9fSMdTtwWrN+C63dKe /hBUXP0pB/gKG2yO1lDF5PP2Eckx3E1EwzYZEih/ioQwk6Qyg4m1IPkaObIHekRm6ngU a5lrQRUyjl5WkTTmynAdsFZxMJGp9K+tL/0XNxBwvF+dKM1nJbYu6a2mXj4OMP170NTU OZ38bQRqcF8Wqt6jt+3uDF2ljkywO9kPV47o/ODD+xBpHYMEKnsQl7sR974KXDIW2PSb BUczEarsOaLsRLC8pllrxD7UdDmEckXtsBva3vIotc+pZWO7jBCpx4Vb57OJdyJ/F9zi mZBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3-v6si11591406pgg.266.2018.10.06.11.52.04; Sat, 06 Oct 2018 11:52:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbeJGB4W (ORCPT + 99 others); Sat, 6 Oct 2018 21:56:22 -0400 Received: from terminus.zytor.com ([198.137.202.136]:53421 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726285AbeJGB4W (ORCPT ); Sat, 6 Oct 2018 21:56:22 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w96IpqHQ3647627 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 6 Oct 2018 11:51:52 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w96Ipq4M3647624; Sat, 6 Oct 2018 11:51:52 -0700 Date: Sat, 6 Oct 2018 11:51:52 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Reinette Chatre Message-ID: Cc: tglx@linutronix.de, jithu.joseph@intel.com, fenghua.yu@intel.com, reinette.chatre@intel.com, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com Reply-To: mingo@kernel.org, jithu.joseph@intel.com, reinette.chatre@intel.com, fenghua.yu@intel.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org In-Reply-To: <9b4bc4d59ba2e903b6a3eb17e16ef41a8e7b7c3e.1538603665.git.reinette.chatre@intel.com> References: <9b4bc4d59ba2e903b6a3eb17e16ef41a8e7b7c3e.1538603665.git.reinette.chatre@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cache] x86/intel_rdt: Introduce utility to obtain CDP peer Git-Commit-ID: fa9032bca042b50f0ba7d80e53025cecbd5ad0f3 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: fa9032bca042b50f0ba7d80e53025cecbd5ad0f3 Gitweb: https://git.kernel.org/tip/fa9032bca042b50f0ba7d80e53025cecbd5ad0f3 Author: Reinette Chatre AuthorDate: Wed, 3 Oct 2018 15:17:01 -0700 Committer: Thomas Gleixner CommitDate: Sat, 6 Oct 2018 20:46:26 +0200 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: 49f7b4efa110 ("x86/intel_rdt: Enable setting of exclusive mode") Signed-off-by: Reinette Chatre Signed-off-by: Thomas Gleixner Tested-by: Jithu Joseph Acked-by: Fenghua Yu 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 --- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c index 56a6b2388c61..7fc2f86bb13a 100644 --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c @@ -960,6 +960,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of, return 0; } +/** + * rdt_cdp_peer_get - Retrieve CDP peer if it exists + * @r: RDT resource to which RDT domain @d belongs + * @d: Cache instance for which a CDP peer is requested + * @r_cdp: RDT resource that shares hardware with @r (RDT resource peer) + * Used to return the result. + * @d_cdp: RDT domain that shares hardware with @d (RDT domain peer) + * Used to return the result. + * + * RDT resources are managed independently and by extension the RDT domains + * (RDT resource instances) are managed independently also. The Code and + * Data Prioritization (CDP) RDT resources, while managed independently, + * could refer to the same underlying hardware. For example, + * RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache. + * + * When provided with an RDT resource @r and an instance of that RDT + * resource @d rdt_cdp_peer_get() will return if there is a peer RDT + * resource and the exact instance that shares the same hardware. + * + * Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists. + * If a CDP peer was found, @r_cdp will point to the peer RDT resource + * and @d_cdp will point to the peer RDT domain. + */ +static int __attribute__((unused)) rdt_cdp_peer_get(struct rdt_resource *r, + struct rdt_domain *d, + struct rdt_resource **r_cdp, + struct rdt_domain **d_cdp) +{ + struct rdt_resource *_r_cdp = NULL; + struct rdt_domain *_d_cdp = NULL; + int ret = 0; + + switch (r->rid) { + case RDT_RESOURCE_L3DATA: + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE]; + break; + case RDT_RESOURCE_L3CODE: + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA]; + break; + case RDT_RESOURCE_L2DATA: + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE]; + break; + case RDT_RESOURCE_L2CODE: + _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA]; + break; + default: + ret = -ENOENT; + goto out; + } + + /* + * When a new CPU comes online and CDP is enabled then the new + * RDT domains (if any) associated with both CDP RDT resources + * are added in the same CPU online routine while the + * rdtgroup_mutex is held. It should thus not happen for one + * RDT domain to exist and be associated with its RDT CDP + * resource but there is no RDT domain associated with the + * peer RDT CDP resource. Hence the WARN. + */ + _d_cdp = rdt_find_domain(_r_cdp, d->id, NULL); + if (WARN_ON(!_d_cdp)) { + _r_cdp = NULL; + ret = -EINVAL; + } + +out: + *r_cdp = _r_cdp; + *d_cdp = _d_cdp; + + return ret; +} + /** * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other * @r: Resource to which domain instance @d belongs.