Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3051458pxj; Mon, 14 Jun 2021 13:13:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwur41pWak7kbv3e46NhDMR4oTl8rI88g5WaD1H0JjKms61NYtJfGwvqY1yC3XYNwVkjs6i X-Received: by 2002:a17:907:7b8b:: with SMTP id ne11mr7497981ejc.177.1623701609366; Mon, 14 Jun 2021 13:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623701609; cv=none; d=google.com; s=arc-20160816; b=P66c58TzRfxR1aQIWDC2CdsWX8rcpKGtkKxOi42w1I/E4braWb8zyV5emMn44TUXgu O6YJKQEbxztuAMT/MXqRDADlIkQj3jZjWT03X7DfS2bQ9QDC+ftvyyVheZE3jri7XRj1 +u3lAODlYtMLQQm+1amMV+5vhIvpiwO7UgmSR+dg86Kx5mUBF+8HPtpxiJTgXCxHG2Xo HArGVTbl7yndrN7V0GArHUGSgRHtXi2b1IvrU9HsUOB9PPWJ47xjCpiDzPXLlalc8leR 7CPzI9ymi74Nt1y54k3o0TCzNIE/eAc7goOxAA2BV5HvUStpKfuw/LKFJOPs3NcmZ07p dGBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=w02MVmDeXf9KXEv1TpWHePBwpZoyON0SCwjqJk2MRrQ=; b=OnlOK4s/Ml20eF0TGUB5b/3jwVbqsaEpissjc6BjiEjVHLAiVV332wXm+I/F5NczdG sarzG1e9lgJonrOislry1nYR5Alfu+1n0+DU9DLWLryEn+y8TZAAj00k27NVFr6b7ECb H0IhCcT6oMOTn+LYk2rGxYisOFBWI6nQMNAqW7BJpcR393cPG5jEZljQrnfHFJHSuEPE +S5LvJ2IkkNGvKb4Zw7tG4V2poOJoBLXWxkR5bzV4GTIi16ylwmlB2At9hvpr6RAy0Y+ dcBC3WGUgII3zDuIOVpi3KSRCax8aisTXzlM5WooyRNqlTMlAK/rkvy9qWxL8BQ9w5uC aE1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo3si12405946edb.589.2021.06.14.13.13.06; Mon, 14 Jun 2021 13:13:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235470AbhFNUMt (ORCPT + 99 others); Mon, 14 Jun 2021 16:12:49 -0400 Received: from foss.arm.com ([217.140.110.172]:45810 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235365AbhFNUMn (ORCPT ); Mon, 14 Jun 2021 16:12:43 -0400 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 F18CD11D4; Mon, 14 Jun 2021 13:10:39 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 240303F694; Mon, 14 Jun 2021 13:10:38 -0700 (PDT) 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, Jamie Iles , D Scott Phillips OS , lcherian@marvell.com Subject: [PATCH v4 16/24] x86/resctrl: Add a helper to read/set the CDP configuration Date: Mon, 14 Jun 2021 20:09:33 +0000 Message-Id: <20210614200941.12383-17-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210614200941.12383-1-james.morse@arm.com> References: <20210614200941.12383-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whether CDP is enabled for a hardware resource like the L3 cache can be found by inspecting the alloc_enabled flags of the L3CODE/L3DATA struct rdt_hw_resources, even if they aren't in use. Once these resources are merged, the flags can't be compared. Whether CDP is enabled needs tracking explicitly. If another architecture is emulating CDP the behaviour may not be per-resource. Add cdp_capable and cdp_enabled to struct rdt_hw_resource and add resctrl_arch_set_cdp_enabled() to let resctrl enable or disable CDP on a resource. resctrl_arch_get_cdp_enabled() lets it read the current state. Reviewed-by: Jamie Iles Signed-off-by: James Morse --- Changes since v3: * Fixed a spelling mistake. Changes since v2: * Merged rdt_domain_reconfigure_cdp() changes here. * Shuffled commit message, Changes since v1: * Added prototype for resctrl_arch_set_cdp_enabled() * s/Currently/Previously/ * rdt_get_cdp_config() accesses the array directly as most of the code here disappears once the resources are merged. It isn't practical for MPAM to hide the CDP emulation by applying the same 'L3' configuration to the two closid that are in use, as this would then consume two monitors, which are likely to be in short supply. --- arch/x86/kernel/cpu/resctrl/core.c | 4 ++ arch/x86/kernel/cpu/resctrl/internal.h | 13 +++- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 75 +++++++++++++---------- 4 files changed, 62 insertions(+), 34 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index be974517ba0d..a2cbd2832d73 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -374,6 +374,10 @@ static void rdt_get_cdp_config(int level, int type) * "cdp" during resctrl file system mount time. */ r->alloc_enabled = false; + rdt_resources_all[level].cdp_enabled = false; + rdt_resources_all[type].cdp_enabled = false; + rdt_resources_all[level].cdp_capable = true; + rdt_resources_all[type].cdp_capable = true; } static void rdt_get_cdp_l3_config(void) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 44f2b8f7b5d7..af230135ad7c 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -375,6 +375,8 @@ struct rdt_parse_data { * @msr_update: Function pointer to update QOS MSRs * @mon_scale: cqm counter * mon_scale = occupancy in bytes * @mbm_width: Monitor width, to detect and correct for overflow. + * @cdp_enabled: CDP state of this resource + * @cdp_capable: Is the CDP feature available on this resource * * Members of this structure are either private to the architecture * e.g. mbm_width, or accessed via helpers that provide abstraction. e.g. @@ -389,6 +391,8 @@ struct rdt_hw_resource { struct rdt_resource *r); unsigned int mon_scale; unsigned int mbm_width; + bool cdp_enabled; + bool cdp_capable; }; static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r) @@ -409,7 +413,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); extern struct dentry *debugfs_resctrl; -enum { +enum resctrl_res_level { RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA, RDT_RESOURCE_L3CODE, @@ -430,6 +434,13 @@ static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res) return &hw_res->resctrl; } +static inline bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l) +{ + return rdt_resources_all[l].cdp_enabled; +} + +int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable); + /* * To return the common struct rdt_resource, which is contained in struct * rdt_hw_resource, walk the resctrl member of struct rdt_hw_resource. diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index 2f99210a9d69..f322f5c78a41 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -684,8 +684,8 @@ int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp) * resource, the portion of cache used by it should be made * unavailable to all future allocations from both resources. */ - if (rdt_resources_all[RDT_RESOURCE_L3DATA].resctrl.alloc_enabled || - rdt_resources_all[RDT_RESOURCE_L2DATA].resctrl.alloc_enabled) { + if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3) || + resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2)) { rdt_last_cmd_puts("CDP enabled\n"); return -EINVAL; } diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 57e4d793f576..6b01902ac037 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1933,14 +1933,16 @@ static int set_cache_qos_cfg(int level, bool enable) /* Restore the qos cfg state when a domain comes online */ void rdt_domain_reconfigure_cdp(struct rdt_resource *r) { - if (!r->alloc_capable) + struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); + + if (!hw_res->cdp_capable) return; if (r == &rdt_resources_all[RDT_RESOURCE_L2DATA].resctrl) - l2_qos_cfg_update(&r->alloc_enabled); + l2_qos_cfg_update(&hw_res->cdp_enabled); if (r == &rdt_resources_all[RDT_RESOURCE_L3DATA].resctrl) - l3_qos_cfg_update(&r->alloc_enabled); + l3_qos_cfg_update(&hw_res->cdp_enabled); } /* @@ -1984,51 +1986,62 @@ static int cdp_enable(int level, int data_type, int code_type) r_l->alloc_enabled = false; r_ldata->alloc_enabled = true; r_lcode->alloc_enabled = true; + rdt_resources_all[level].cdp_enabled = true; + rdt_resources_all[data_type].cdp_enabled = true; + rdt_resources_all[code_type].cdp_enabled = true; } return ret; } -static int cdpl3_enable(void) -{ - return cdp_enable(RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA, - RDT_RESOURCE_L3CODE); -} - -static int cdpl2_enable(void) -{ - return cdp_enable(RDT_RESOURCE_L2, RDT_RESOURCE_L2DATA, - RDT_RESOURCE_L2CODE); -} - static void cdp_disable(int level, int data_type, int code_type) { - struct rdt_resource *r = &rdt_resources_all[level].resctrl; + struct rdt_hw_resource *r_hw = &rdt_resources_all[level]; + struct rdt_resource *r = &r_hw->resctrl; r->alloc_enabled = r->alloc_capable; - if (rdt_resources_all[data_type].resctrl.alloc_enabled) { + if (r_hw->cdp_enabled) { rdt_resources_all[data_type].resctrl.alloc_enabled = false; rdt_resources_all[code_type].resctrl.alloc_enabled = false; set_cache_qos_cfg(level, false); + r_hw->cdp_enabled = false; + rdt_resources_all[data_type].cdp_enabled = false; + rdt_resources_all[code_type].cdp_enabled = false; } } -static void cdpl3_disable(void) +int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable) { - cdp_disable(RDT_RESOURCE_L3, RDT_RESOURCE_L3DATA, RDT_RESOURCE_L3CODE); -} + struct rdt_hw_resource *hw_res = &rdt_resources_all[l]; + enum resctrl_res_level code_type, data_type; -static void cdpl2_disable(void) -{ - cdp_disable(RDT_RESOURCE_L2, RDT_RESOURCE_L2DATA, RDT_RESOURCE_L2CODE); + if (!hw_res->cdp_capable) + return -EINVAL; + + if (l == RDT_RESOURCE_L3) { + code_type = RDT_RESOURCE_L3CODE; + data_type = RDT_RESOURCE_L3DATA; + } else if (l == RDT_RESOURCE_L2) { + code_type = RDT_RESOURCE_L2CODE; + data_type = RDT_RESOURCE_L2DATA; + } else { + return -EINVAL; + } + + if (enable) + return cdp_enable(l, data_type, code_type); + + cdp_disable(l, data_type, code_type); + + return 0; } static void cdp_disable_all(void) { - if (rdt_resources_all[RDT_RESOURCE_L3DATA].resctrl.alloc_enabled) - cdpl3_disable(); - if (rdt_resources_all[RDT_RESOURCE_L2DATA].resctrl.alloc_enabled) - cdpl2_disable(); + if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3)) + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false); + if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2)) + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false); } /* @@ -2106,10 +2119,10 @@ static int rdt_enable_ctx(struct rdt_fs_context *ctx) int ret = 0; if (ctx->enable_cdpl2) - ret = cdpl2_enable(); + ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, true); if (!ret && ctx->enable_cdpl3) - ret = cdpl3_enable(); + ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, true); if (!ret && ctx->enable_mba_mbps) ret = set_mba_sc(true); @@ -3208,10 +3221,10 @@ static int rdtgroup_rmdir(struct kernfs_node *kn) static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf) { - if (rdt_resources_all[RDT_RESOURCE_L3DATA].resctrl.alloc_enabled) + if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3)) seq_puts(seq, ",cdp"); - if (rdt_resources_all[RDT_RESOURCE_L2DATA].resctrl.alloc_enabled) + if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2)) seq_puts(seq, ",cdpl2"); if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].resctrl)) -- 2.30.2