From patchwork Fri Apr 21 14:17:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1105765vqo; Fri, 21 Apr 2023 07:22:02 -0700 (PDT) X-Google-Smtp-Source: AKy350a82z8anfkcDyytFw0gPSnXptIZFxbRHtLc5pEzvgyC79/OeEhKiWegu9HQnU/c1JyhOvvL X-Received: by 2002:a17:903:110f:b0:1a6:dba5:2e3b with SMTP id n15-20020a170903110f00b001a6dba52e3bmr6565946plh.29.1682086922638; 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=gkhO0w23mqBz25vodg4bj0mm6Pt7GrAJoBtxYsxQi45rNfGFenXMTpQN/G7wylNJ7Z ObvEXNcsYpmg8uTaCv4tMHonPEg28bwtuU+30py1TsCiMrnZFkmtsu7HkQh3yhjXEHRC IgXVDrHLfI9roOfGtmbF0QYTgHMVuy7guq2sboK2Vo7gZCwN1qAVLvs9Sw7MpM75FMfp hOuMR4ZsKGpgajuqbUs9Iy3tWC4eUBKDdte7GS9sMIrO9VLDdTRlnymafaQRS7brtRfh g6iyJo9q55v8bZ0VnnVO21cdhNl4gSjKxYRuWKIOOhMp85ejxkEA+ZkW3Zr6RN7DtSY4 bsyQ== 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=4R40htVFkZdRKo0vr5qbbFiTdJ0ln75dPc18Ex1B+xs=; b=oec0BZeVMGa0Iaxgw2GrC/Zcy4yIXOB8aJSiITh3bED1SQJm076w5gDnlILTMOi4Hw TFTUW0ej9+iWitEpVSjGLSUMe9uK3ihyZeAbuLyAmqmFVGcXSxhFMDcxbMzoTEJbfEhQ e8kEGcTLUlila+bWNR5+O9CmC4Zu/+q3JFtq7CJSOr6q0nE81mldU+KKk5azOvOwOJ3J W972EVqDYL4tkETZlGwPPA4JgxL+IH7zdSDBhR63l9NHdGmCr4caAnEH0TyFZ+Ws2kNx ZhPvD1TvSjO+5nwDxFwZc77dxn0LjLybHFkaXCr36sFxhkxyzyAqYxeL1CN2B7hUmYvv mj3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=C5BMyCvl; 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 i10-20020a17090332ca00b001a6b273fef3si4717488plr.442.2023.04.21.07.21.48; 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=C5BMyCvl; 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 S232438AbjDUOTB (ORCPT + 99 others); Fri, 21 Apr 2023 10:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232508AbjDUOSu (ORCPT ); Fri, 21 Apr 2023 10:18:50 -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 01E8E13C33 for ; Fri, 21 Apr 2023 07:18:08 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b8f52c2da49so2925455276.3 for ; Fri, 21 Apr 2023 07:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086688; x=1684678688; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4R40htVFkZdRKo0vr5qbbFiTdJ0ln75dPc18Ex1B+xs=; b=C5BMyCvlSu+eRzBuquykI60dxIq34oqxyOw42+ATs4ZC1qIFL9f0A1m6cTj1Jn86Bc 44vRd37/KN9LFP3+Vgd6I3Tk6cDxaeV8xTNfWw+0kITVFdf4LaajI4M8GClIsJGdlrVo ZXBYbKbAqjawn9c6qHTuBylMX2eEVIDSk0Hh2f96PyUpJcGQfEmbP1iNKvAkagqwNwAZ fBeCOT5hlALd9f2omWh3ORkodnLziGqV4RS8XBrfYg7P9BwfF/wp99EnLYDYtUg6u7Q2 xLGNagHO1uKYyrOjiHAOyGA9bxx8PXRaYcRCp6RHq+hedzzLAVlekMwLMyDxa8FSee+d Xn8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086688; x=1684678688; 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=4R40htVFkZdRKo0vr5qbbFiTdJ0ln75dPc18Ex1B+xs=; b=WbasDNy0lw5FI+BiHQMJndivEXzXnMCCpJO0zRvd4uruP/Zr63Qt3GJCz8h7deCMgh OEzy2NAyBfyUGVLI8GQEnqyXPtcGh3L82slnmi5iN+JH0YkCsMwNv9C8R8S+mPP32R9I 8x4UxkIfoG5IKDXAQKEnuaAI9DUK0bEmuVVk8E8833YKCNxBAsPL16aRQs2C2xwCXYWS LOpMrUPcNWySdV4IVfg3yCTGAOa1xea0aUAPsSjJLS25CqL8ai8Ykg4kw1d7ztwnR79L 5AjvIIJflqWgJOECwI8taEs+l55Kx9WlmuivopWat8/4+Tp6RjVu/kyDKdwJbXjvTOuF JMiQ== X-Gm-Message-State: AAQBX9e+fnd0FQJCid0T3uj2gV3QJ6aMijFjbFItSu+rN6fihYvh9t+g tbMCCwVZncYdn/Z2HBbTmhHu1veLDaaOlE1OGQ== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a25:d1d0:0:b0:b98:6352:be19 with SMTP id i199-20020a25d1d0000000b00b986352be19mr1290128ybg.9.1682086687990; Fri, 21 Apr 2023 07:18:07 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:22 +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-9-peternewman@google.com> Subject: [PATCH v1 8/9] x86/resctrl: Use mbm_update() to push soft RMID counts 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=unavailable 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?1763795976630249026?= X-GMAIL-MSGID: =?utf-8?q?1763795976630249026?= __mon_event_count() only reads the current software count and does not cause CPUs in the domain to flush. For mbm_update() to be effective in preventing overflow in hardware counters with soft RMIDs, it needs to flush the domain CPUs so that all of the HW RMIDs are read. When RMIDs are soft, mbm_update() is intended to push bandwidth counts to the software counters rather than pulling the counts from hardware when userspace reads event counts, as this is a lot more efficient when the number of HW RMIDs is fixed. When RMIDs are soft, mbm_update() only calls mbm_flush_cpu_handler() on each CPU in the domain rather than reading all RMIDs. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/monitor.c | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 3d54a634471a..9575cb79b8ee 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -487,6 +487,11 @@ void resctrl_mbm_flush_cpu(void) __mbm_flush(QOS_L3_MBM_TOTAL_EVENT_ID, r, d); } +static void mbm_flush_cpu_handler(void *p) +{ + resctrl_mbm_flush_cpu(); +} + static int __mon_event_count_soft_rmid(u32 rmid, struct rmid_read *rr) { struct mbm_state *m; @@ -806,12 +811,27 @@ void mbm_handle_overflow(struct work_struct *work) r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; d = container_of(work, struct rdt_domain, mbm_over.work); + if (rdt_mon_soft_rmid) { + /* + * HW RMIDs are permanently assigned to CPUs, so only a per-CPU + * flush is needed. + */ + on_each_cpu_mask(&d->cpu_mask, mbm_flush_cpu_handler, NULL, + false); + } + list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { - mbm_update(r, d, prgrp->mon.rmid); + /* + * mbm_update() on every RMID would result in excessive IPIs + * when RMIDs are soft. + */ + if (!rdt_mon_soft_rmid) { + mbm_update(r, d, prgrp->mon.rmid); - head = &prgrp->mon.crdtgrp_list; - list_for_each_entry(crgrp, head, mon.crdtgrp_list) - mbm_update(r, d, crgrp->mon.rmid); + head = &prgrp->mon.crdtgrp_list; + list_for_each_entry(crgrp, head, mon.crdtgrp_list) + mbm_update(r, d, crgrp->mon.rmid); + } if (is_mba_sc(NULL)) update_mba_bw(prgrp, d);