Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2324837rwr; Fri, 21 Apr 2023 07:27:24 -0700 (PDT) X-Google-Smtp-Source: AKy350bjjje/WOWi9duCOnHV+pZhPSH+H3jbjCIgYqM3s2RfPQv3tFuWRRLJ0p7lz2J1kV6M7s8p X-Received: by 2002:a17:902:dacd:b0:1a1:956d:2281 with SMTP id q13-20020a170902dacd00b001a1956d2281mr6263689plx.3.1682087244317; Fri, 21 Apr 2023 07:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682087244; cv=none; d=google.com; s=arc-20160816; b=yq+4LIbh619Ne/lKRvUhExT9bmuN1oNrlMlgNri8n+A6Qh089xyVs0W6wlCicPPKXr lJLwAVGwv8ntEbRMPnKLusMPEn20lWnKs5YT3V5cXfJ13hf3gyEiC2xtl/NjW/qpkA95 OAtOI28/BmfTDGh+Jjp9aUbKMUqJmhTWHLqS/SjmYUdzHpbFLuyI6KKZVVdRxfZ0HII4 t027FJvWyMThYvtiXGPsDz6CDruhwSMA2q26URaS5Lgp9JsLx8iX7Ds8Lcc0swraB3S1 Om9Ev1Sxaf/yb2f3+w0teEhC4iS0JH5Puu2SsN681N5UAd18lrQ37/T7RHubrohCVHB2 /qqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=y32/TdG8kcYzN5rBv7k3EHHxOjAgmuz/MTd8pNlAXEA=; b=kX+RN2hticfTdm6QuwMuc7oEAEzn6NztPTAKDkgws0wNfiit1rwpa0XIxe/cSwdJCF oto8OoHCqp9J7+MROLaPGvDuutGhKJnKwheS8cXiqlkXG5zpJzh3DLt304aHXCuw0gI4 ecrU9QUCmcc22d6Z5wn0u4O1GYegSBNzgYC/1uYJ7NizXmUe+oSlIaiWqkdaPMYZFCws 3SlP1+Vw0x4j8NGpczIu9ZygeHimTUmoz47PM/o8iXIVpz/Bgoxi6fdup1jNqPSUirDp n7/jFJFbHm+M8DdeTCR2yPortfCJGygv7GmJoELB/uxRDI49U5tE/CCpts9VhIr5CNH0 NcWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hpKZdihT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o1-20020a17090aac0100b00240d56569eesi4591021pjq.166.2023.04.21.07.27.09; Fri, 21 Apr 2023 07:27:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hpKZdihT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232516AbjDUOTG (ORCPT + 99 others); Fri, 21 Apr 2023 10:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232526AbjDUOSw (ORCPT ); Fri, 21 Apr 2023 10:18:52 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ACBC13C11 for ; Fri, 21 Apr 2023 07:18:11 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b8f6269ad66so3064355276.1 for ; Fri, 21 Apr 2023 07:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086690; x=1684678690; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y32/TdG8kcYzN5rBv7k3EHHxOjAgmuz/MTd8pNlAXEA=; b=hpKZdihTkw8uY98Jt7btWsnsgQm4pu7ZD+gTsJEer7e7Bhi4FdnOZnlQ0Q4Yx2PbWa 7xSOTnqiOHSs/2r/I9Vlh3kHkIbqeHzKJ4pkH7SZw9v8N39RvB0BrXX6Efid57ldBfB8 YSMkcHnlJcFGMD6gLc9OUxomMd4vi8/JIq+Bsa6b4ZFxql9q24eL2t76KnEtvIInVvyo 0Yj2ocYfKjIC6LYE/0r9bZk91BJw2SK6Oza3APs+9XnCv84snwE2/sFQrhlqD3a1UUK/ 8HKf2zhrp6a+Ns1+EfDJm6Dl1cvSAoQ0zdjCb5PqEK+zL6tQfHOxqvglYP3q+F2hiop7 hr0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086690; x=1684678690; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y32/TdG8kcYzN5rBv7k3EHHxOjAgmuz/MTd8pNlAXEA=; b=LOx7WgCHOKy05/xxjY+Izok5xfH9tC5fK9Gbhzf0eL8sIaIcnNlWgZehh7QUuleHFS yciQ02IMzguNzoISJwZdXJgGgkl2QeAL1+M5VN9wwAjFtB7RvF33+gins0MYIvZU8McG NuK+FOgyjtbXmoM3K2Z7Z/UVEpYpfb93P0pxkHqsTNcjvLitRI0Auh1mdckE+HpKEI45 ceE4POSAurVxyOD1Gc3Q8KeFw7lHP1fDGL/W+QfzbRUR53VjOKz6fPEh2L5xyuOgMa6N SuIlTpSWJAdE6+kEn250rP1r9IJtLGDlOaVaqPiuW+rJggt8f1cLFD6k9RER5LPfRepX b98g== X-Gm-Message-State: AAQBX9cqrDu0FCqGyXHI6p7qFrVBwVBuNqUzagX4CsOJOYGOS/WUDlyg SgK1PKNhYf3EPfMnMpODSjOveJYuzLx+nUlfPw== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a25:d78c:0:b0:b8b:eea7:525e with SMTP id o134-20020a25d78c000000b00b8beea7525emr1763936ybg.5.1682086690780; Fri, 21 Apr 2023 07:18:10 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:23 +0200 In-Reply-To: <20230421141723.2405942-1-peternewman@google.com> Mime-Version: 1.0 References: <20230421141723.2405942-1-peternewman@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230421141723.2405942-10-peternewman@google.com> Subject: [PATCH v1 9/9] x86/resctrl: Add mount option to enable soft RMID From: Peter Newman To: Fenghua Yu , Reinette Chatre Cc: Babu Moger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Stephane Eranian , James Morse , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Peter Newman Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the 'mbm_soft_rmid' mount option to enable soft RMIDs. This requires adding a mechanism for disabling a monitoring event at mount time to prevent the llc_occupancy event from being presented to the user. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/internal.h | 3 ++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 51 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index e6ff31a4dbc4..604e3d550601 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -59,6 +59,7 @@ struct rdt_fs_context { bool enable_cdpl2; bool enable_cdpl3; bool enable_mba_mbps; + bool enable_mbm_soft_rmid; }; static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc) @@ -76,12 +77,14 @@ DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key); * @evtid: event id * @name: name of the event * @configurable: true if the event is configurable + * @enabled: true if event is disabled * @list: entry in &rdt_resource->evt_list */ struct mon_evt { enum resctrl_event_id evtid; char *name; bool configurable; + bool disabled; struct list_head list; }; diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index c10f4798156a..c2abf69c2dcf 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1013,6 +1013,8 @@ static int rdt_mon_features_show(struct kernfs_open_file *of, struct mon_evt *mevt; list_for_each_entry(mevt, &r->evt_list, list) { + if (mevt->disabled) + continue; seq_printf(seq, "%s\n", mevt->name); if (mevt->configurable) seq_printf(seq, "%s_config\n", mevt->name); @@ -2204,6 +2206,37 @@ static bool supports_mba_mbps(void) r->alloc_capable && is_mba_linear()); } +static bool supports_mbm_soft_rmid(void) +{ + return is_mbm_enabled(); +} + +int set_mbm_soft_rmid(bool mbm_soft_rmid) +{ + struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + struct mon_evt *mevt = NULL; + + /* + * is_llc_occupancy_enabled() will always return false when disabling, + * so search for the llc_occupancy event unconditionally. + */ + list_for_each_entry(mevt, &r->evt_list, list) { + if (strcmp(mevt->name, "llc_occupancy") == 0) { + mevt->disabled = mbm_soft_rmid; + break; + } + } + + rdt_mon_soft_rmid = mbm_soft_rmid; + + if (mbm_soft_rmid) + static_branch_enable_cpuslocked(&rdt_soft_rmid_enable_key); + else + static_branch_disable_cpuslocked(&rdt_soft_rmid_enable_key); + + return 0; +} + /* * Enable or disable the MBA software controller * which helps user specify bandwidth in MBps. @@ -2359,6 +2392,9 @@ static int rdt_enable_ctx(struct rdt_fs_context *ctx) if (!ret && ctx->enable_mba_mbps) ret = set_mba_sc(true); + if (!ret && ctx->enable_mbm_soft_rmid) + ret = set_mbm_soft_rmid(true); + return ret; } @@ -2534,6 +2570,8 @@ static int rdt_get_tree(struct fs_context *fc) out_mba: if (ctx->enable_mba_mbps) set_mba_sc(false); + if (ctx->enable_mbm_soft_rmid) + set_mbm_soft_rmid(false); out_cdp: cdp_disable_all(); out: @@ -2547,6 +2585,7 @@ enum rdt_param { Opt_cdp, Opt_cdpl2, Opt_mba_mbps, + Opt_mbm_soft_rmid, nr__rdt_params }; @@ -2554,6 +2593,7 @@ static const struct fs_parameter_spec rdt_fs_parameters[] = { fsparam_flag("cdp", Opt_cdp), fsparam_flag("cdpl2", Opt_cdpl2), fsparam_flag("mba_MBps", Opt_mba_mbps), + fsparam_flag("mbm_soft_rmid", Opt_mbm_soft_rmid), {} }; @@ -2579,6 +2619,11 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) return -EINVAL; ctx->enable_mba_mbps = true; return 0; + case Opt_mbm_soft_rmid: + if (!supports_mbm_soft_rmid()) + return -EINVAL; + ctx->enable_mbm_soft_rmid = true; + return 0; } return -EINVAL; @@ -2767,6 +2812,7 @@ static void rdt_kill_sb(struct super_block *sb) cpus_read_lock(); mutex_lock(&rdtgroup_mutex); + set_mbm_soft_rmid(false); set_mba_sc(false); /*Put everything back to default values. */ @@ -2861,6 +2907,8 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, priv.u.rid = r->rid; priv.u.domid = d->id; list_for_each_entry(mevt, &r->evt_list, list) { + if (mevt->disabled) + continue; priv.u.evtid = mevt->evtid; ret = mon_addfile(kn, mevt->name, priv.priv); if (ret) @@ -3517,6 +3565,9 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf) if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl)) seq_puts(seq, ",mba_MBps"); + if (static_branch_likely(&rdt_soft_rmid_enable_key)) + seq_puts(seq, ",mbm_soft_rmid"); + return 0; } -- 2.40.0.634.g4ca3ef3211-goog