Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2313890rwr; Fri, 21 Apr 2023 07:19:14 -0700 (PDT) X-Google-Smtp-Source: AKy350ZkD8FCFvgC8FO/itZqT6A0jMGJUuXYqLzY45XfJTbT8H0zo7IY192Qjb/rXw3TARmUsG1q X-Received: by 2002:a17:902:e852:b0:1a9:4b42:a5a2 with SMTP id t18-20020a170902e85200b001a94b42a5a2mr2126037plg.0.1682086754255; Fri, 21 Apr 2023 07:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086754; cv=none; d=google.com; s=arc-20160816; b=Uo5TTmuxm3cRcHc2vv+pmnjZYnL4ZLPkPxh/2jfGIq2r3sI8VVyE28UmSecRaqrpjK /EVfxNOt9UGuDnKvqyg51fSgzyCLEczKGfCsKTYue3hwSp+COX1vKNnFOUw5c+7gL8sA 3EM88g3LkxfYSAdj41Vn7bSqmSt8ojb3lmpF3Ezf/fTRZKeDO4//gkPqiErIU+nBkGKw Qim7n7tXlyK1QkQFV1HdMzl/mE7XM+4IN7ZtWx8Oe8p/sBdUt8FSFG+kIwSZDKXzfaSy VJQlHUZPw8Gw6KadYvP+1WM2hjd1M6CKLB1mOQeYEp94dU5VcyO9PXfqZHN1j6EdCFhL V6Uw== 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=+n+j8heP4pCjXZYyBacJTBZB3NL6fBggzFdjHd9oRv0=; b=voCEl0U6mRZn0U/fzgEJh01Dk2y6lLC2QixHQ0TyX2mq4Tx1ruDEzund2AME21PbUD Spp7CcMTa6gwOGLZPeE1+aCngfVcLwvWeocvAc8uXEi/7mkTFhwvyPrzfYELbmOt0Xle 8F/1TDJZhBMAPa0g+tEyXpyqrT8fBvUXijZAGQDr7J6+G+seLDeb+R30VNni/MNia22G dmTXIN8HgEyxT+EMIVxNUeP8aPLADw2ROx2mjY8oCPP/ewbE8ClkcOAd7ovjL8ncwVvU W0dIXhsHuW220dvR83TBy9P/PyhgyvE1DvsiLU6NRebyGkf1RE+sM4u1/r1NJJkA5NkT 0NCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=1J+xPZGW; 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 c7-20020a170903234700b001a52dd0195csi4779892plh.549.2023.04.21.07.19.02; Fri, 21 Apr 2023 07:19:14 -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=1J+xPZGW; 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 S231317AbjDUOSR (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229962AbjDUOR6 (ORCPT ); Fri, 21 Apr 2023 10:17:58 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE7E8E50 for ; Fri, 21 Apr 2023 07:17:56 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54f88a34bd6so23283717b3.2 for ; Fri, 21 Apr 2023 07:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086676; x=1684678676; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+n+j8heP4pCjXZYyBacJTBZB3NL6fBggzFdjHd9oRv0=; b=1J+xPZGWBNzha1s2A0zh1bYQja2oWHpvpOCxFHuTZtFUWKMmSQnBfxHBH0Zcm44kZA mPOZ/Fht1Aftwl9AJ1rKtC59A4jvXdb1ZYW8T2qD/3ZYsP8HOjEF5aK/sPWCyvfddAGs YZVHhrnd9w2mxWucAZPFAtJnP9MSj3lmKy/TSOAxNQS4f3hIn2T2k8w1STVe4BtZELVX pJkgxjkF5hE3w133duRa8aLyLmZJq1iOL967XYQ/GUbKLPXFkKw4b9ahEO8C0ZO6zECt izmMTaC7MHs6J71osGTiOvAsndQZ1oFYtSarJD7aSOdBEp0EuGUc3FUDwpkI1pL1x4Bm A4Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086676; x=1684678676; 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=+n+j8heP4pCjXZYyBacJTBZB3NL6fBggzFdjHd9oRv0=; b=lbhX6jxSMRBrM5xU/6LJ/QxLxLfDH7B1sF+Vh0haf3x9kUi0OFEJ2RhCiCCgNhAVjF RAGIpj09qCxyQ0+uW0Viq+K4mcYeH4ZX1Ehp0+soqJ+jmgp6aamkL46j9NptlYLopUhu VYYSh0LgxmxnY4r6XEkGUvnVWU288BwRDckkBpvzeI6qOp9NQzuQojL5pH6Awj2C//gy v/EVTiNAt6OIxt/HoiWAQgHbdebM3CI68HaFUvYfr07Irfa88ieZWkWKiKo6Yl0VEHXW 5/ih1Ti+WR9E1xY2QG456MHjhKfu9NsSMCIrCPxS1JCBv0G6LqNvPLN8JoVvQidHSR9u iGhA== X-Gm-Message-State: AAQBX9c2+mnIX+4ltbhse4brVeLw5G6FsU2TNQBcgH1HN2Gllpt48h9t ihXnCgQBgDp1WzBbJnC410vIVt+Jmyuc6R0K8g== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a0d:ec48:0:b0:54f:ae82:3f92 with SMTP id r8-20020a0dec48000000b0054fae823f92mr1328767ywn.2.1682086675839; Fri, 21 Apr 2023 07:17:55 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:18 +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-5-peternewman@google.com> Subject: [PATCH v1 4/9] x86/resctrl: Flush MBM event counts on soft RMID change 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 To implement soft RMIDs, context switch must detect when the current soft RMID is changing and if so, flush the CPU's MBM event counts to the outgoing soft RMID. To avoid impacting context switch performance in the non-soft RMID case, protect the new logic with a static branch. Co-developed-by: Stephane Eranian Signed-off-by: Stephane Eranian Signed-off-by: Peter Newman --- arch/x86/include/asm/resctrl.h | 27 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index e7acf118d770..50d05e883dbb 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -36,6 +36,9 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); DECLARE_STATIC_KEY_FALSE(rdt_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key); +DECLARE_STATIC_KEY_FALSE(rdt_soft_rmid_enable_key); + +void resctrl_mbm_flush_cpu(void); /* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR @@ -75,9 +78,31 @@ static inline void __resctrl_sched_in(struct task_struct *tsk) } if (closid != state->cur_closid || rmid != state->cur_rmid) { + if (static_branch_likely(&rdt_soft_rmid_enable_key)) { + /* + * Flush current event counts to outgoing soft rmid + * when it changes. + */ + if (rmid != state->cur_rmid) + resctrl_mbm_flush_cpu(); + + /* + * rmid never changes in this mode, so skip wrmsr if the + * closid is not changing. + */ + if (closid != state->cur_closid) + wrmsr(MSR_IA32_PQR_ASSOC, state->hw_rmid, + closid); + } else { + wrmsr(MSR_IA32_PQR_ASSOC, rmid, closid); + } + + /* + * Record new closid/rmid last so soft rmid case can detect + * changes. + */ state->cur_closid = closid; state->cur_rmid = rmid; - wrmsr(MSR_IA32_PQR_ASSOC, rmid, closid); } } diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 6ad33f355861..c10f4798156a 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -35,6 +35,7 @@ DEFINE_STATIC_KEY_FALSE(rdt_enable_key); DEFINE_STATIC_KEY_FALSE(rdt_mon_enable_key); DEFINE_STATIC_KEY_FALSE(rdt_alloc_enable_key); +DEFINE_STATIC_KEY_FALSE(rdt_soft_rmid_enable_key); static struct kernfs_root *rdt_root; struct rdtgroup rdtgroup_default; LIST_HEAD(rdt_all_groups); -- 2.40.0.634.g4ca3ef3211-goog