From patchwork Fri Apr 21 14:17:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1105764vqo; Fri, 21 Apr 2023 07:22:02 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgUCkYuihQUJeMM4dUJju49OjgLABzJli7BUupELC5H/QSbaQbBl14107XYlx9WMK9jVXy X-Received: by 2002:a17:90a:ea8e:b0:23d:29c7:916f with SMTP id h14-20020a17090aea8e00b0023d29c7916fmr5271835pjz.32.1682086922437; Fri, 21 Apr 2023 07:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086922; cv=none; d=google.com; s=arc-20160816; b=bOz2xCytu5A65VieanstjfZF6zjK0nECMO/8naOGMJniupmFTcyH/Kc725ncg4XDAe rD1G/oTQCsydi8ukC4FKkqu4TCSoZ8NjaxSs0IuDsA/49mRvf3tqWGcn/1uXSgKPX0ap 31Lnjs2k9daAuM43PfRttD/2/SSekwg9GS/W8/ogoK+uEJqf+ITMzD+Ulb3giTckfZCZ wt+LX/002GArYPk+uCfSxdBJDNy4BUERmsyrMj80YDw28MKQEYtbPAqaK9WtKs8G3MwL ZY8s+d6DX6skejksTiGhETY92Fy0e+lS5jSR1tKkv6ZpquIJoKZBmrvcjbEFNJC49pI1 TTSg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v24-20020a63f218000000b0051b313bdebesi2086924pgh.1.2023.04.21.07.21.49; Fri, 21 Apr 2023 07:22:02 -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 S232229AbjDUOSR (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763795976802486906?= X-GMAIL-MSGID: =?utf-8?q?1763795976802486906?= 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);