Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2316067rwr; Fri, 21 Apr 2023 07:20:43 -0700 (PDT) X-Google-Smtp-Source: AKy350Yl+/mb+k9T5ULjJt39E2p6t5ODBQT3J4nq5sdI8wTfs+03YyVsFtItCWmJZyg2mipQp6Bl X-Received: by 2002:a05:6a00:1d8f:b0:63b:4978:a50a with SMTP id z15-20020a056a001d8f00b0063b4978a50amr5797772pfw.1.1682086842893; Fri, 21 Apr 2023 07:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086842; cv=none; d=google.com; s=arc-20160816; b=i9Kn8MOBDiD/ySnwUSY74VFNKw9RC6ie6q/p8jVyTWUQMTuk2W5DWB/9Twz3Yuoh5Z 6uaIwTwyBHHGEKVvoBdv/tZ884hEdY3YZroW72eNNo1x9UNyZD+cNbF5xc29AbIcDsz+ Ll/qUdNEJidu66dhl6yK0jt65vFXb7v1EW3YFPwYlfTpLHWb9UO2ZTuuBcLM9mmpz4oy OY+HAdlLkhW0iRFwOY/WtE5cuy/j19mzQI+IvA9YiLSKLJN5ReQlW/BtGOuMNzBr92zT WKQOTESfT7RD//ECCA29rUS84oLDUIVmv7+7/sJSrnMOc1OhkCTmwIIKBGlgzykP0lxG ZyCg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020aa79d0c000000b0063d23db693asi1086930pfp.234.2023.04.21.07.20.28; Fri, 21 Apr 2023 07:20:42 -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 S232413AbjDUOTB (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 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=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 __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); -- 2.40.0.634.g4ca3ef3211-goog