From patchwork Fri Apr 21 14:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1110157vqo; Fri, 21 Apr 2023 07:28:42 -0700 (PDT) X-Google-Smtp-Source: AKy350b+YSK8J7c390Zr2d9MDlFQAO5qG0kpupIyNCJJSKfuQW+d2ePHJPToGK69TKeCyxDjO3kI X-Received: by 2002:a17:90b:4a87:b0:23f:9448:89c2 with SMTP id lp7-20020a17090b4a8700b0023f944889c2mr5644657pjb.7.1682087322736; Fri, 21 Apr 2023 07:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682087322; cv=none; d=google.com; s=arc-20160816; b=GvZK6oS9da/F/3a7kP0Z3PKAqzOE0LAH1lmWh4CA/hKJ1ayHqzGAsqN3Y8f0vy4YHk 24t3rgj8JKPWLrsXO10W2CKZDXGnarjsyAmZdAIAKKWsSGC23qis0lfFIToCSSiW7wOk U5TXYlowVzdbifCrVwstdBKGVCl8//FYv8I5kzTplcv873R+9XpmDQ9qUwVfPXaAFL+m hCa5C85pwHy60yF4kdEYwhud8+FIE5Fzc1kSDKyGepI+JisZMtm4Gznw7MZ9FcXxEu5O FYQCsflrdHvNcN3jjY5U8gCg829wJ0pyF5+f+E7BRSgMOQjI59fEzZX2YzrIKNF1jQPP o/fQ== 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=K9ehmzwOW4Qc9gQvpwM/ZZofEU4OqXe1UUgzo44mFis=; b=M7uyNL9VP+bWfEJDDNYkIB7cXupKANySVnigd46bQ2jJMayoyrDIGesfyF6mcAk7jE vhJfFLRepBZ1LPvm6KrOkHkwbgFbg3DYlZ/DcKd1r6bAvFg3sea1/ZUCl+HC4rgBTvq3 h9AobpIrUfnCxYcV3x8elV+aGT66X1a5V2e3Ou8IvPz/2/QinFwSCTQfv8mzI1bXwqk1 x0+4UMuOYL6/AYsc1mUcEcNE8XWTGn79G6UX+y4V70vvbkSaQhkm87i2tmFkM3er+hMW s8/pmenxJrKDS4iX2VB0SGavhsbeytFz1YDd5llh+jAKIQmZC7Ple1mMYe9d3MzTDUba qkMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="jQ/EfbEl"; 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 o1-20020a17090aac0100b00240d56569eesi4591021pjq.166.2023.04.21.07.28.25; Fri, 21 Apr 2023 07:28: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="jQ/EfbEl"; 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 S231923AbjDUOSA (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232389AbjDUORt (ORCPT ); Fri, 21 Apr 2023 10:17:49 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8654493DE for ; Fri, 21 Apr 2023 07:17:47 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54f87c0a000so27619907b3.3 for ; Fri, 21 Apr 2023 07:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086666; x=1684678666; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=K9ehmzwOW4Qc9gQvpwM/ZZofEU4OqXe1UUgzo44mFis=; b=jQ/EfbElWOoD7Q5RcZ9PEMa2xeB33n91soMxfAboXtG9IdbuenydvfqGJRJs173o0i vupY0UegJS39vUDZPWg//Oym1AxFL0seSvyqJuJ2iCaBeWL8/gw7JMqp4PQ7JqaqcVXN iNIK16Y8y4rXoL54RmLqFH1ccS7vUP4c6UAmjsYbFOzVDuRQ9s7pTGXMPN+J00WMZlh/ dkBxnZoW2ygD8DRNK6Rn+6P0ltnrb6sIgfoNbyE0Ov4dTaBIn6WtKU0bQDqeRL8gbvhA /vwQxur+PunJsSaBWZDh+8oiYEaDyLaOgE7fzoSNYbg7eGhEH2OnC/ShEbI1U1+eZhx8 QppA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086666; x=1684678666; 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=K9ehmzwOW4Qc9gQvpwM/ZZofEU4OqXe1UUgzo44mFis=; b=WJfYWDaXt/0BzL6RJS/DtX7Cdq7lJjeXuMOJaYxUfNpEyQDdPuNNa8fE8QqUbafqW7 jAvhqrCYjo9nlWzIF3+PjThZFUz9Y+I90wyJ4W7+s9H2e2A4JfWPRCEpfuc1yt908MgZ plCetMcUhG1KU1QLbe+7yVmDNcX14lg6ha5gQFjZM+2tsjMFNK7DG1+J4FCy0Z2vnYvM j3DUSYjBXHovYNl1IMjlD3iaFx58B989hgU/U9UfbGRThDRQ1m9M9J0TIhEZ8cfovksj 9a6lZH5f07xfpdwZY2GWoklGU1SxtYLt0cg0s1YKMNN17omcMK++bUe3UAot384MsAdN VSFg== X-Gm-Message-State: AAQBX9eSwlOCasS39irAykfitlmpTflJjhODQUY5APN44iu4HddXmWpi CR+u76FZ9f/auf3Ow6u45BOboSFhNJe+uVf7Pg== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a81:b725:0:b0:555:f33e:e346 with SMTP id v37-20020a81b725000000b00555f33ee346mr1484199ywh.6.1682086666823; Fri, 21 Apr 2023 07:17:46 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:15 +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-2-peternewman@google.com> Subject: [PATCH v1 1/9] selftests/resctrl: Verify all RMIDs count together 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?1763796396793021848?= X-GMAIL-MSGID: =?utf-8?q?1763796396793021848?= AMD CPUs in particular implement fewer monitors than RMIDs, so add a test case to see if a large number of monitoring groups can be measured together. Signed-off-by: Peter Newman --- tools/testing/selftests/resctrl/test_rmids.sh | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 tools/testing/selftests/resctrl/test_rmids.sh diff --git a/tools/testing/selftests/resctrl/test_rmids.sh b/tools/testing/selftests/resctrl/test_rmids.sh new file mode 100755 index 000000000000..475e69c0217e --- /dev/null +++ b/tools/testing/selftests/resctrl/test_rmids.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +cd /sys/fs/resctrl + +grep -q mbm_total_bytes info/L3_MON/mon_features || { + echo "MBM required" + exit 4 +} + +which perf > /dev/null || { + echo "perf tool required" + exit 4 +} + +num_rmids=$(cat info/L3_MON/num_rmids) + +count=0 + +result=0 + +# use as many RMIDs as possible, up to the number of RMIDs +for i in `seq $num_rmids`; do + mkdir mon_groups/_test_m$((count+1)) 2> /dev/null || break + if [[ -d mon_groups/_test_m$((count+1))/mon_data ]]; then + count=$((count+1)) + else + break; + fi +done + +echo "Created $count monitoring groups." + +if [[ $count -eq 0 ]]; then + echo "need monitoring groups to continue." + exit 4 +fi + +declare -a bytes_array + +unavailable=0 +unavailable0=0 + +for i in `seq $count`; do + bytes_array[$i]=$(cat mon_groups/_test_m${i}/mon_data/mon_L3_00/mbm_total_bytes) + + if [[ "${bytes_array[$i]}" = "Unavailable" ]]; then + unavailable0=$((unavailable0 + 1)) + fi +done + +for i in `seq $count`; do + echo $$ > mon_groups/_test_m${i}/tasks + taskset 0x1 perf bench mem memcpy -s 100MB -f default > /dev/null +done +echo $$ > tasks + +# zero non-integer values +declare -i bytes bytes0 + +success_count=0 + +for i in `seq $count`; do + raw_bytes=$(cat mon_groups/_test_m${i}/mon_data/mon_L3_00/mbm_total_bytes) + raw_bytes0=${bytes_array[$i]} + + # coerce the value to an integer for math + bytes=$raw_bytes + bytes0=$raw_bytes0 + + echo -n "g${i}: mbm_total_bytes: $raw_bytes0 -> $raw_bytes" + + if [[ "$raw_bytes" = "Unavailable" ]]; then + unavailable=$((unavailable + 1)) + fi + + if [[ $bytes -gt $bytes0 ]]; then + success_count=$((success_count+1)) + echo "" + else + echo " (FAIL)" + result=1 + fi +done + +first=$((count-unavailable0)) +second=$((count-unavailable)) +echo "$count groups, $first returned counts in first pass, $second in second" +echo "successfully measured bandwidth from ${success_count}/${count} groups" + +rmdir mon_groups/_test_m* + +exit $result From patchwork Fri Apr 21 14:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1109086vqo; Fri, 21 Apr 2023 07:27:05 -0700 (PDT) X-Google-Smtp-Source: AKy350Yni9tt40suahmhQEcy9de58bgWHoTgPfXvaIRRGS7zzqAzqw/Ev8ds54nWWpdwMmBpkYPD X-Received: by 2002:a05:6a20:3d90:b0:ee:2f91:206b with SMTP id s16-20020a056a203d9000b000ee2f91206bmr8207041pzi.1.1682087225504; Fri, 21 Apr 2023 07:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682087225; cv=none; d=google.com; s=arc-20160816; b=UxEV4uKcomvxTWEAldmJhX/pF0efJLeBXWHZwlalIJdIV9IskCfWJLsHpXptQFjCDi vPRjbykemrDnh3ho6KBxapdnY8dIoUlPopehg+IcNfL8iNA+RTBNrJxW0OynN8izQdNd qg+wNlPN0KiLqbILS5p0/tWPv3YVt6PsTYSHx+OBLdLlI6xpUwjPHHkmvGYA+V+JHJ39 eHAqnHUHnKh9fSKD/kIcr8G/Gqwlra8xBTu+fu/MG3tq8o/2ZS/lF9//IKVW8iMXDpy7 zSxYz4mDopFKjdLizCngcK29xYiF5rIxGWOBQL4ND3Ntn82vFOeK0dNwZCqnfdnzIkCY LZJg== 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=9ZdT0+yxI631GXfw7STY7XxcZTuaYlRecO3uXqz7sRs=; b=EcgVdKTJSiJ71S5oRPt1OmiVnrRJNnutWknE0K2vO+/13LAWnVNJzDavneXZb2sT7J hv1FE12d1zJqJ1ELcnTafZwPK4pho714LW2SfN/EyX/qBuWsrcFmlp8+2NY3EWilmqno mPpSv0Yt4h+Dgma8WmOqw5CH08C+Ke8N5IsPcSw5SRaSGdOjbHmKp/MTynZWNNAIFqL1 WWgXzyN7G1RN65qI1kZure1AeLISZpjP6P9oPvZWQAeV2ZdR+5NyQ2NZUYaURZIrDpQd mA8siUiQxgzv7M3oQDsrGvLrbC7K4cYtVO2tniYu4qrlfeHkGA+rVuQ3f3DckCCS3Z2z XPKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Y2+bxGSH; 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 d9-20020aa797a9000000b0063b59a25a0asi4546930pfq.134.2023.04.21.07.26.53; Fri, 21 Apr 2023 07:27:05 -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=Y2+bxGSH; 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 S231926AbjDUOSE (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232434AbjDUORv (ORCPT ); Fri, 21 Apr 2023 10:17:51 -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 E9ABB93DE for ; Fri, 21 Apr 2023 07:17:49 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b8f566ea5e6so6393390276.0 for ; Fri, 21 Apr 2023 07:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086669; x=1684678669; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9ZdT0+yxI631GXfw7STY7XxcZTuaYlRecO3uXqz7sRs=; b=Y2+bxGSHDI0cOeuV61GwDsFnnX9uAq9WV4Qgojc5LTOAuEP7C/2lbNBzZCmr9EdXh7 T9jJFsDqzueATZPhTVjNwdJ4MFL89AyXFBgYcElt1FG2xsfcm9t/jgq2PV+yLwMb7P37 sBDmeAm7DfdmrMZ0bI/85s0NTFkKfCr8eZPBFv7mbUVMz/4yNLvDgNiI8lS/+WydrCT9 0xlrKDptRLKB0mb733akzzr1zKgHEJXS5NUA2IWaMU05W6pdg6KhkQHmIygs+G8eC3bI FtBXepDYkaHIXGahLzv8DVUcjVfhwk/8CZCRLk9Ay5NK+v9x3qPgWv2q/rUiCbhfuZUt 3gxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086669; x=1684678669; 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=9ZdT0+yxI631GXfw7STY7XxcZTuaYlRecO3uXqz7sRs=; b=QXy6wKZ1be6rbgOXygU6xTBFC6AKkTAEbXSOHA3XzQGkF0/R5AYoD4jkH66qidSfPv +zX/jdqLyJe+0Wj6wHZw45PM9qZb1kvVtQhEmsxqOv79YFtRA4pqH+ZSdVhsSN1xUdiQ +KRFo/2D2keTeoICYmZkfpJKxrau5RZzofOdTXKVuZzyuKN5UTAoRrxVc/p7DwJpXFdX OA4gG+uD6pk0zKKZP3GwBHjh9pcEaa6tlBLgM9FK2vXQLtr+FPTJdpm7kyvdIsV3ocT4 ONZactPWHUbdsbSIAXdDXnBlOeO2Z9LkProA0OCcC+BEf0OQyW5Cmt/7o3Q0zs2V82Qi CRaw== X-Gm-Message-State: AAQBX9eFQ9T+RiR0vzOKjue9rog1Hiu07aGAAJnJwsSLRk39o2gXK0m9 hy9gcCJNDCwpL5gmBOr5UCHf39P/XYE06X+a1A== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a05:690c:c8c:b0:54f:e2ca:3085 with SMTP id cm12-20020a05690c0c8c00b0054fe2ca3085mr1849543ywb.1.1682086669711; Fri, 21 Apr 2023 07:17:49 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:16 +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-3-peternewman@google.com> Subject: [PATCH v1 2/9] x86/resctrl: Hold a spinlock in __rmid_read() on AMD 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?1763796294576809718?= X-GMAIL-MSGID: =?utf-8?q?1763796294576809718?= From: Stephane Eranian In AMD PQoS Versions 1.0 and 2.0, IA32_QM_EVTSEL MSR is shared by all processors in a QOS domain. So there's a chance it can read a different event when two processors are reading the counter concurrently. Add a spinlock to prevent this race. Co-developed-by: Peter Newman Signed-off-by: Peter Newman Signed-off-by: Stephane Eranian --- arch/x86/kernel/cpu/resctrl/core.c | 41 ++++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/internal.h | 5 ++++ arch/x86/kernel/cpu/resctrl/monitor.c | 14 +++++++-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 030d3b409768..47b1c37a81f8 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -25,6 +25,8 @@ #include #include "internal.h" +DEFINE_STATIC_KEY_FALSE(rmid_read_locked); + /* Mutex to protect rdtgroup access. */ DEFINE_MUTEX(rdtgroup_mutex); @@ -529,6 +531,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d->id = id; cpumask_set_cpu(cpu, &d->cpu_mask); + raw_spin_lock_init(&hw_dom->evtsel_lock); + rdt_domain_reconfigure_cdp(r); if (r->alloc_capable && domain_setup_ctrlval(r, d)) { @@ -829,6 +833,41 @@ static __init bool get_rdt_mon_resources(void) return !rdt_get_mon_l3_config(r); } +static __init bool amd_shared_qm_evtsel(void) +{ + /* + * From AMD64 Technology Platform Quality of Service Extensions, + * Revision 1.03: + * + * "For PQoS Version 1.0 and 2.0, as identified by Family/Model, the + * QM_EVTSEL register is shared by all the processors in a QOS domain." + * + * Check the inclusive Family/Model ranges for PQoS Extension versions + * 1.0 and 2.0 from the PQoS Extension Versions table. + */ + if (boot_cpu_data.x86 == 0x17) + /* V1.0 */ + return boot_cpu_data.x86_model >= 0x30 && + boot_cpu_data.x86_model <= 0x9f; + + if (boot_cpu_data.x86 == 0x19) + /* V2.0 */ + return (boot_cpu_data.x86_model <= 0xf) || + ((boot_cpu_data.x86_model >= 0x20) && + (boot_cpu_data.x86_model <= 0x5f)); + + return false; +} + +static __init void __check_quirks_amd(void) +{ + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL) || + rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { + if (amd_shared_qm_evtsel()) + static_branch_enable(&rmid_read_locked); + } +} + static __init void __check_quirks_intel(void) { switch (boot_cpu_data.x86_model) { @@ -852,6 +891,8 @@ static __init void check_quirks(void) { if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) __check_quirks_intel(); + else if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) + __check_quirks_amd(); } static __init bool get_rdt_resources(void) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 85ceaf9a31ac..02a062558c67 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -325,6 +325,7 @@ struct arch_mbm_state { * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) * @arch_mbm_total: arch private state for MBM total bandwidth * @arch_mbm_local: arch private state for MBM local bandwidth + * @lock: serializes counter reads when QM_EVTSEL MSR is shared per-domain * * Members of this structure are accessed via helpers that provide abstraction. */ @@ -333,6 +334,7 @@ struct rdt_hw_domain { u32 *ctrl_val; struct arch_mbm_state *arch_mbm_total; struct arch_mbm_state *arch_mbm_local; + raw_spinlock_t evtsel_lock; }; static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r) @@ -428,6 +430,9 @@ extern struct rdt_hw_resource rdt_resources_all[]; extern struct rdtgroup rdtgroup_default; DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); +/* Serialization required in resctrl_arch_rmid_read(). */ +DECLARE_STATIC_KEY_FALSE(rmid_read_locked); + extern struct dentry *debugfs_resctrl; enum resctrl_res_level { diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 20952419be75..2de8397f91cd 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -146,10 +146,15 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid) return entry; } -static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) +static int __rmid_read(struct rdt_hw_domain *hw_dom, u32 rmid, + enum resctrl_event_id eventid, u64 *val) { + unsigned long flags; u64 msr_val; + if (static_branch_likely(&rmid_read_locked)) + raw_spin_lock_irqsave(&hw_dom->evtsel_lock, flags); + /* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits @@ -161,6 +166,9 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid); rdmsrl(MSR_IA32_QM_CTR, msr_val); + if (static_branch_likely(&rmid_read_locked)) + raw_spin_unlock_irqrestore(&hw_dom->evtsel_lock, flags); + if (msr_val & RMID_VAL_ERROR) return -EIO; if (msr_val & RMID_VAL_UNAVAIL) @@ -200,7 +208,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, memset(am, 0, sizeof(*am)); /* Record any initial, non-zero count value. */ - __rmid_read(rmid, eventid, &am->prev_msr); + __rmid_read(hw_dom, rmid, eventid, &am->prev_msr); } } @@ -241,7 +249,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask)) return -EINVAL; - ret = __rmid_read(rmid, eventid, &msr_val); + ret = __rmid_read(hw_dom, rmid, eventid, &msr_val); if (ret) return ret; From patchwork Fri Apr 21 14:17:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1103871vqo; Fri, 21 Apr 2023 07:19:17 -0700 (PDT) X-Google-Smtp-Source: AKy350Ydsb934z4Is/ekD9oCE7b3o7j5lwn/RTXB2Cq8Nmvj6ILCnziPDirFNRseFuhANYip1Zhb X-Received: by 2002:a17:902:d483:b0:1a6:961e:fd0b with SMTP id c3-20020a170902d48300b001a6961efd0bmr5905536plg.4.1682086756768; Fri, 21 Apr 2023 07:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086756; cv=none; d=google.com; s=arc-20160816; b=lgyyuGHonBzXF6XdB/h+SHoJLDSZl04YdxFT9WEWRylOVr8xkEeixDUqnouVrVnnnh cHMYYNBKHy3L15DsPURhp8kC85KP7TYZsrZI9KkhTaA0L2TM4nc03Pj5pCndHVfZZZvf 0fEFbroS00UgtMk95TsnuNbkqTG0bUBG+VUlVC83nVyF5a+MFhhZqzJox9jwXXIP0Xop CE4KvMSSc95qcsve+55he8LMkzxEuD5xEsMEcJcOyoN51zhsXHoUInko9XAgiQA79Gua xVxCh+Y35Rf4Gzsr58rkCB23UCLZYoSkBJ93y0IYgei3EFFf79nGfPmKayOrzmcxLUBX xVVg== 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=BuRpJ8asAkuXVj/aByE26xnYMHbcW3VWyH6v7oH/F3A=; b=R/Z6pfQ/ODtQJubMn47ddRmu0n/+y874iSZrvGOWonDQ/ojCLvYssACEl0u0tMhjUz w10AI22ir3x2QIVrJwNRdZ03g4mPGgfTluw1R9/Od3mY8uhHQX+lQYbA5spAx2rbVJJV etWIDeyAjF5e28QDlLTrQyrIAbTYwnTsySBo68u0h8WZ0UAGNpnTj3wXkcoBUNu3Fw+c ELaif3PGYK/BgzjWj2xURTTquvA0Rt/hZSJ5jNxVBNLqVZpmGLpzGjKAsOJ2pYEpuvcv SncfOtIa3ZSaR89MCur5vl7BnA7JRnJGKdyPih0xhnh9n/XIv4CAzW3ITsbLMe5zufnH Nk/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="YF6mH/8C"; 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 y12-20020a1709029b8c00b0019a59c52fd3si4100673plp.508.2023.04.21.07.19.03; Fri, 21 Apr 2023 07:19:16 -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="YF6mH/8C"; 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 S232402AbjDUOSI (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232438AbjDUORz (ORCPT ); Fri, 21 Apr 2023 10:17:55 -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 98EE319B2 for ; Fri, 21 Apr 2023 07:17:53 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b8f324b3ef8so1213739276.0 for ; Fri, 21 Apr 2023 07:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086673; x=1684678673; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BuRpJ8asAkuXVj/aByE26xnYMHbcW3VWyH6v7oH/F3A=; b=YF6mH/8C6d2LEICnoqqT4IlypJNJI7h7vMGL3vmU8nm89xmj7nFwuuIi0Wugm9WY7S LZT7Lgv38D5hvS66vh1juZA/85ZJAPR2JWb6rtiB3SRpL/EO75XCQVejewfggFNY6tFf RzHFp1/kP+25z9AnutEzY4IoniQvEzo16VK7X+sycwpCy3UwwvKbnqksNfF1U7vt2PHV bSJAcLXepaAKacebZQY18LDeX7Zs7xw1hB+gldk/e7vBIaWUaSVtYUz6W4roqTjhSZJG HMyd3SE7sDxYTWk7s5ZqTodFH5yuHwd0x1uf+1epjoOsNQcwdzTFPBgd9pwdMOellgcs H4CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086673; x=1684678673; 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=BuRpJ8asAkuXVj/aByE26xnYMHbcW3VWyH6v7oH/F3A=; b=iFOcfmGSLyhJIXWJjbRcYlgx4wmHpkKJhU9qVGmlM/zy1r+wtGPbE0SZRYIiN3a2Hd mUXjElc4vo6tA/8zR6FSswDsrLZ/1AtDG40w3lI7qhmiByvaHLSwEbQyuXC3Z5InNfQR 5ep9BbwAdCuSbVMF5QG/TNb1YjBLpVUUfFnQDJi2IY6Sq10As+WnzoNlj2SWhTvv7K5Q JXk3MjTigxpjElYpg1jyPLtPleL5alsvDnBV9uOyHGk2G8NDunItyrBCisUa5mRA/fMP yDLF0TqmMdtDZIGDyKfLUOoJuLtSSOz7oJhz+6dUmcLQbSwCgeYlCaovO6Bf8RryGILl gnmQ== X-Gm-Message-State: AAQBX9c2DEDScsHRxbf3P3blup5XMPiTdeDZVUlD3TtGlkvtl4/XDH45 JheupI9wNyyiZeL3gAwMUE5nPLpcaTED0G8/Lw== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a0d:ec49:0:b0:552:b607:634b with SMTP id r9-20020a0dec49000000b00552b607634bmr1395087ywn.4.1682086672863; Fri, 21 Apr 2023 07:17:52 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:17 +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-4-peternewman@google.com> Subject: [PATCH v1 3/9] x86/resctrl: Add resctrl_mbm_flush_cpu() to collect CPUs' MBM events 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?1763795802845559372?= X-GMAIL-MSGID: =?utf-8?q?1763795802845559372?= AMD implementations so far are only guaranteed to provide MBM event counts for RMIDs which are currently assigned in CPUs' PQR_ASSOC MSRs. Hardware can reallocate the counter resources for all other RMIDs' which are not currently assigned to those which are, zeroing the event counts of the unassigned RMIDs. In practice, this makes it impossible to simultaneously calculate the memory bandwidth speed of all RMIDs on a busy system where all RMIDs are in use. Over a multiple-second measurement window, the RMID would need to remain assigned in all of the L3 cache domains where it has been assigned for the duration of the measurement, otherwise portions of the final count will be zero. In general, it is not possible to bound the number of RMIDs which will be assigned in an L3 domain over any interval of time. To provide reliable MBM counts on such systems, introduce "soft" RMIDs: when enabled, each CPU is permanently assigned a hardware RMID whose event counts are flushed to the current soft RMID during context switches which result in a change in soft RMID as well as whenever userspace requests the current event count for a domain. Implement resctrl_mbm_flush_cpu(), which collects a domain's current MBM event counts into its current software RMID. The delta for each CPU is determined by tracking the previous event counts in per-CPU data. The software byte counts reside in the arch-independent mbm_state structures. Co-developed-by: Stephane Eranian Signed-off-by: Stephane Eranian Signed-off-by: Peter Newman --- arch/x86/include/asm/resctrl.h | 2 + arch/x86/kernel/cpu/resctrl/internal.h | 10 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 78 ++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 255a78d9d906..e7acf118d770 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -13,6 +13,7 @@ * @cur_closid: The cached Class Of Service ID * @default_rmid: The user assigned Resource Monitoring ID * @default_closid: The user assigned cached Class Of Service ID + * @hw_rmid: The permanently-assigned RMID when soft RMIDs are in use * * The upper 32 bits of MSR_IA32_PQR_ASSOC contain closid and the * lower 10 bits rmid. The update to MSR_IA32_PQR_ASSOC always @@ -27,6 +28,7 @@ struct resctrl_pqr_state { u32 cur_closid; u32 default_rmid; u32 default_closid; + u32 hw_rmid; }; DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 02a062558c67..256eee05d447 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -298,12 +298,14 @@ struct rftype { * @prev_bw: The most recent bandwidth in MBps * @delta_bw: Difference between the current and previous bandwidth * @delta_comp: Indicates whether to compute the delta_bw + * @soft_rmid_bytes: Recent bandwidth count in bytes when using soft RMIDs */ struct mbm_state { - u64 prev_bw_bytes; - u32 prev_bw; - u32 delta_bw; - bool delta_comp; + u64 prev_bw_bytes; + u32 prev_bw; + u32 delta_bw; + bool delta_comp; + atomic64_t soft_rmid_bytes; }; /** diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 2de8397f91cd..3671100d3cc7 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -404,6 +404,84 @@ static struct mbm_state *get_mbm_state(struct rdt_domain *d, u32 rmid, } } +struct mbm_soft_counter { + u64 prev_bytes; + bool initialized; +}; + +struct mbm_flush_state { + struct mbm_soft_counter local; + struct mbm_soft_counter total; +}; + +DEFINE_PER_CPU(struct mbm_flush_state, flush_state); + +/* + * flushes the value of the cpu_rmid to the current soft rmid + */ +static void __mbm_flush(int evtid, struct rdt_resource *r, struct rdt_domain *d) +{ + struct mbm_flush_state *state = this_cpu_ptr(&flush_state); + u32 soft_rmid = this_cpu_ptr(&pqr_state)->cur_rmid; + u32 hw_rmid = this_cpu_ptr(&pqr_state)->hw_rmid; + struct mbm_soft_counter *counter; + struct mbm_state *m; + u64 val; + + /* cache occupancy events are disabled in this mode */ + WARN_ON(!is_mbm_event(evtid)); + + if (evtid == QOS_L3_MBM_LOCAL_EVENT_ID) { + counter = &state->local; + } else { + WARN_ON(evtid != QOS_L3_MBM_TOTAL_EVENT_ID); + counter = &state->total; + } + + /* + * Propagate the value read from the hw_rmid assigned to the current CPU + * into the "soft" rmid associated with the current task or CPU. + */ + m = get_mbm_state(d, soft_rmid, evtid); + if (!m) + return; + + if (resctrl_arch_rmid_read(r, d, hw_rmid, evtid, &val)) + return; + + /* Count bandwidth after the first successful counter read. */ + if (counter->initialized) { + /* Assume that mbm_update() will prevent double-overflows. */ + if (val != counter->prev_bytes) + atomic64_add(val - counter->prev_bytes, + &m->soft_rmid_bytes); + } else { + counter->initialized = true; + } + + counter->prev_bytes = val; +} + +/* + * Called from context switch code __resctrl_sched_in() when the current soft + * RMID is changing or before reporting event counts to user space. + */ +void resctrl_mbm_flush_cpu(void) +{ + struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + int cpu = smp_processor_id(); + struct rdt_domain *d; + + d = get_domain_from_cpu(cpu, r); + if (!d) + return; + + if (is_mbm_local_enabled()) + __mbm_flush(QOS_L3_MBM_LOCAL_EVENT_ID, r, d); + if (is_mbm_total_enabled()) + __mbm_flush(QOS_L3_MBM_TOTAL_EVENT_ID, r, d); +} + static int __mon_event_count(u32 rmid, struct rmid_read *rr) { struct mbm_state *m; 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); From patchwork Fri Apr 21 14:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1104037vqo; Fri, 21 Apr 2023 07:19:31 -0700 (PDT) X-Google-Smtp-Source: AKy350aTNTg7Zkl7Mlfrg8IPlXxv2oF1NJX2kzSetxLstlrvv4E8Ov8RDOw460MxYVrGW1gfh+al X-Received: by 2002:a17:902:c408:b0:1a8:ac3:47b4 with SMTP id k8-20020a170902c40800b001a80ac347b4mr7223077plk.20.1682086771672; Fri, 21 Apr 2023 07:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086771; cv=none; d=google.com; s=arc-20160816; b=u/y1NGJMnPu/q9KpCuploT7ObdASxamjP0BKE0/4ZUiu/EsKfm2sjMBatURJltldWS IHwiyVegwiyNAgWGBsOEUT17daqXaia450qAw3GJOdTOUZnCvbkuXcLXw5mmEsVZuj6j 82gxYqWHuadjS4PnNLCqH56BDWU6rvKosnMjKu88C7mNI+hrbIyPfaFhckPz2yiQozls vgFEGi6p2PV7395qfNp98Q+J/cDeMMElsU2NECAoStMG6peTshXsjqxZ7wfw+VX+y3PY +gV4o2ekIBsgMyM+1v50hpNePk6AdH1aoX6pQ3Y7LASXtnI3uH3KABCjYlU2BhkOdQ1L ZzbA== 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=pHZMVL6RAnw5G7UfUNTFa5CzwFEHRn1u+l8+oLzhKx4=; b=QOcDv6oLc8GEQ9BQ8aD58loPB2vHapJLcq23WIRobgu1BA8K+C3OJoOP5EuTXvsgDA MkkUn0IDu0i0LTNr/WwbZvQS53vR/7c6hmVtSvCHkWXyfLjXSF4JIWQtjrYgxZUrEUlf RMi2z8vE1h/oWEDUj7H85SAzFJrLlTPMBOUJ4a9ctxfYSrliLVb15+iJmz4+J8RAMDMJ 5fxQM8sokRMeZek3ri+9jtlPlTAlmRkoTml9ulFBhVwtSaPQPzgNMlpvNaBYlIWOgO4l GkK/69PhbZgZxUXpWyYMD7J/AF9zk0Rcnfa0i2jjuw+YJWTvG/SkFZIvCGyfmbidEQFJ K+NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=MfKd7cn5; 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 m12-20020a170902d18c00b0019aa3505620si4037825plb.284.2023.04.21.07.19.17; Fri, 21 Apr 2023 07:19:31 -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=MfKd7cn5; 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 S231667AbjDUOSX (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232248AbjDUOSB (ORCPT ); Fri, 21 Apr 2023 10:18:01 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C523012C9C for ; Fri, 21 Apr 2023 07:17:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b98ef5b557fso1821614276.2 for ; Fri, 21 Apr 2023 07:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086679; x=1684678679; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pHZMVL6RAnw5G7UfUNTFa5CzwFEHRn1u+l8+oLzhKx4=; b=MfKd7cn5Uub1nNM2RiV3ISktGqpLP5EyFHMUPTILCfI1qopVg8PNxzIa5VZ+WVXZcx YZQQ69rym1OqIQnu263AjZ26mfrN9dRc/O+yt9qJlZr0OQWY7+sFU45p712eZ73X/pq+ 4Nuhsixxps7DcDhS8ICV53xkgX4iMhzzYLMYV6mG4O4qavIN7UXl1yLnU6UYwzdbAfEJ XNoVRfO8lEMNDiQ7idtMdbVoXBEUHQvqduc/A77nuADM4Lw/KkA2p6bc2WIgZsi3U3N/ trNTBvt2RGd59HStffaZOaFrM5q5/qYO3yTC7XGOJfGCsPSLoeWY96CWcfKm4Xj9mPLG QXQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086679; x=1684678679; 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=pHZMVL6RAnw5G7UfUNTFa5CzwFEHRn1u+l8+oLzhKx4=; b=WG7eALEQKF6SLx/ZrIdyfuA+tAipUWPXX/1tQhEjdNttEulfZBQDDMvQLnhTeRsmns UvLfI9Om67+Z01AdoxnhHxdGl64u21ZPL32AqDW1rePDh97OR4sLWxav12Mlipq82xNu jcxv+rRwEcddbJUUA2GRqhmWYE/fbycJbOQfT+FvtC946OdvC2wxkYmqMXKZhhZZQ9/h 8TZZutdVU3Qogzo+Bph4qDi7V8HAQTnvZWzHAyn5PBDq4ndMjTLNWPJTP+Ou9FFiGOFK O7IcwYAFz3PwZC6UFIrOGjvVOgzNS8Fpvfmh+sdzQWtwXsAb3cI3vupbzd6/UWRnDS+T zmGA== X-Gm-Message-State: AAQBX9c1twgwXiy/Px/UdHL0JdNC1nSt+vS+/nS8jlSBGGLKV+5RZUrE dKEhJe5myFnazbWfrJcKuYb2fz1RUlL7EtHxsw== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a81:ae68:0:b0:533:8f19:4576 with SMTP id g40-20020a81ae68000000b005338f194576mr1440134ywk.0.1682086679114; Fri, 21 Apr 2023 07:17:59 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:19 +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-6-peternewman@google.com> Subject: [PATCH v1 5/9] x86/resctrl: Call mon_event_count() directly for soft RMIDs 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?1763795818275612897?= X-GMAIL-MSGID: =?utf-8?q?1763795818275612897?= There is no point in using IPIs to call mon_event_count() when it is only reading software counters from memory. When RMIDs are soft, mon_event_read() just calls mon_event_count() directly. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 9 ++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c index b44c487727d4..b2ed25a08f6f 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -534,7 +534,14 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val = 0; rr->first = first; - smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1); + if (rdt_mon_soft_rmid) + /* + * Soft RMID counters reside in memory, so they can be read from + * anywhere. + */ + mon_event_count(rr); + else + smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1); } int rdtgroup_mondata_show(struct seq_file *m, void *arg) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 256eee05d447..e6ff31a4dbc4 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -115,6 +115,7 @@ struct rmid_read { extern bool rdt_alloc_capable; extern bool rdt_mon_capable; +extern bool rdt_mon_soft_rmid; extern unsigned int rdt_mon_features; extern struct list_head resctrl_schema_all; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 3671100d3cc7..bb857eefa3b0 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -57,6 +57,11 @@ static struct rmid_entry *rmid_ptrs; */ bool rdt_mon_capable; +/* + * Global boolean to indicate when RMIDs are implemented in software. + */ +bool rdt_mon_soft_rmid; + /* * Global to indicate which monitoring events are enabled. */ From patchwork Fri Apr 21 14:17:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1109578vqo; Fri, 21 Apr 2023 07:27:49 -0700 (PDT) X-Google-Smtp-Source: AKy350azfEj1hci3kpRNq15B2A2y5fs/BMVZphQhtmuJsHfVT/u41lGx1ednzSpLsTj5WzfBpNGw X-Received: by 2002:a17:903:234a:b0:1a6:413c:4a47 with SMTP id c10-20020a170903234a00b001a6413c4a47mr7639835plh.1.1682087268722; Fri, 21 Apr 2023 07:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682087268; cv=none; d=google.com; s=arc-20160816; b=DyoOXVkSAO73+MAdufL3pAsEejzj4yOweoXaaDuElNyLUXzpc+NTmXWWR9S3mwrEMp ByTzJ5rLGl4B0C/8h1uHjI4hiyD1/Ho6uPewxl9Slze9/eLrVgMnjZZJ7X1he3YhTxFN 6Xid9yR0Z4EH+jk3H8FbdMdwyrRaBbV7bu9n3nz82OVGLnyOKNXREEFo4+PvKYwh1msY /alqYISPt8mif39aja9Sivw3KCo7s9tN56+PLpyhUN7YltXTm5uyTJ+rY3GfIW5/oCAh H8OFbEb4AG7lLCPxiVr0+NG/eqoa8bbg+e12G9r+fN8lwV93iji2/zJmIZCnewU68+5X ZTog== 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=eG+d82X49QK4SbPD8xART0pPpkKrWLwG04cl9OQ+l3E=; b=zra4S4CsnCNFkH8kn6YTWtKVwa44MoJtpkzSWePnmC9hck254XOk1sGbWv9u9a495F thmdpd6BAMN8I7BbXCt7j2bRJdJEjf7RjqVOJy2FdSXBQXY0Lp/0nI1rFvREeyCNiCq1 VAYUMH/8YiJx1lXum6Okxg0uGxgLP+dvxVTYd3Q0NWAFdtU8NDwEpdkJUpVEeC4JEHXI A1RQKhLE3h1JzXJterLHcyGpNfjwAiJSGG1zpiTR3jhYCv2jHFH5OX7MdoS21XnB1fef 7JKS8gpiVmRwRTTFKVa6K1aURQRvmQGxrOmvvwri9avlqhYKOW1joAtZN9KihwLaj63n 97aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Wd+O3j54; 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 z16-20020a170902ccd000b001a677821130si4565061ple.13.2023.04.21.07.27.36; Fri, 21 Apr 2023 07:27:48 -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=Wd+O3j54; 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 S232434AbjDUOSt (ORCPT + 99 others); Fri, 21 Apr 2023 10:18:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbjDUOSD (ORCPT ); Fri, 21 Apr 2023 10:18:03 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BADA012C99 for ; Fri, 21 Apr 2023 07:18:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9229dd8c62so1210683276.0 for ; Fri, 21 Apr 2023 07:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086682; x=1684678682; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eG+d82X49QK4SbPD8xART0pPpkKrWLwG04cl9OQ+l3E=; b=Wd+O3j54Skqqn0pDaOa4Mjhf66LdJYTTj9EXOkDn/rwzAbg0BNewxKMK2fmMK8iG98 PicL46080hpLDBhfW/fTzkNo0EtVBh5MW6t23IZuu1RN6M338Hjbb0qD9I7z5KZ1n6QO t1cYVANMd85R44HbBJnjZausS2fw39/88Myh/hUlRcAU44GrbT8jfDhuYCOrhyj4MRYK WjHWGraOdx84TsWCjTu5s9cG6f4hnFQ/BeIhldOpzYVeBs4+iwLMdNanU9uFoitxwZAs 4OJ9cE65XStC7x334oAqiaoPQt5KUOL7kSzkZ3ntdiTUox5Fmt7osx4w5LeXwpEmOJoP U8Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086682; x=1684678682; 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=eG+d82X49QK4SbPD8xART0pPpkKrWLwG04cl9OQ+l3E=; b=goMaArQ54uftf7wReJaPPCCRXb/SbNbBPrFJpRr5vQw6bOu5aQ54ikq0z9ENjUaKGn 6JQixTrRyusHGoSpQRDWphow4I9h8mRCuCpzP7bULppNMfWBBcRZ1Xe9TFzeS9a8UPkp 0sqLqae/lkj1EiwG8atCjDKgPZUeoQT8Z+lrAGkjIRa7UkARrewmInuv83TCniAkBjvl XZYTWIuHf7HWWx1rKmQv9Z+Is9QAeFbT0pM29sIH5BtudXbdZ+x71WcarFfq6Iu56jgR LK5XabO7Urmspv42q09NG4yMZqsA1bCWS4vb5M7AJE3MDUL7xEXUOMk+1thYvSTOU/Ce anTg== X-Gm-Message-State: AAQBX9cdRqPUG6aGayfC0Km0nbbhpIgIgV1l7czEPF6E+f2ftna7WNV0 WYu7gRTfgF0qcNVcjB8TkLowZRxNX1UXt101PQ== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a25:cc93:0:b0:b92:570c:57a1 with SMTP id l141-20020a25cc93000000b00b92570c57a1mr1764698ybf.2.1682086682008; Fri, 21 Apr 2023 07:18:02 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:20 +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-7-peternewman@google.com> Subject: [PATCH v1 6/9] x86/resctrl: Create soft RMID version of __mon_event_count() 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?1763796339852862523?= X-GMAIL-MSGID: =?utf-8?q?1763796339852862523?= When RMIDs are soft, __mon_event_count() only needs to report the current byte count in memory and should not touch the hardware RMIDs. Create a parallel version for the soft RMID configuration and update __mon_event_count() to choose between it and the original depending on whether the soft RMID static key is enabled. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/monitor.c | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index bb857eefa3b0..3d54a634471a 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -487,7 +487,30 @@ void resctrl_mbm_flush_cpu(void) __mbm_flush(QOS_L3_MBM_TOTAL_EVENT_ID, r, d); } -static int __mon_event_count(u32 rmid, struct rmid_read *rr) +static int __mon_event_count_soft_rmid(u32 rmid, struct rmid_read *rr) +{ + struct mbm_state *m; + + WARN_ON(!is_mbm_event(rr->evtid)); + m = get_mbm_state(rr->d, rmid, rr->evtid); + if (!m) + /* implies !is_mbm_event(...) */ + return -1; + + rr->val += atomic64_read(&m->soft_rmid_bytes); + + if (rr->first) { + /* + * Discard any bandwidth resulting from the initial HW counter + * reads. + */ + atomic64_set(&m->soft_rmid_bytes, 0); + } + + return 0; +} + +static int __mon_event_count_default(u32 rmid, struct rmid_read *rr) { struct mbm_state *m; u64 tval = 0; @@ -509,6 +532,14 @@ static int __mon_event_count(u32 rmid, struct rmid_read *rr) return 0; } +static int __mon_event_count(u32 rmid, struct rmid_read *rr) +{ + if (rdt_mon_soft_rmid) + return __mon_event_count_soft_rmid(rmid, rr); + else + return __mon_event_count_default(rmid, rr); +} + /* * mbm_bw_count() - Update bw count from values previously read by * __mon_event_count(). From patchwork Fri Apr 21 14:17:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1105370vqo; Fri, 21 Apr 2023 07:21:26 -0700 (PDT) X-Google-Smtp-Source: AKy350bSXtRH11ZmNIN0QfKcFZUMWH/RbnkoLQnORKAVokGcoF13yHIsEUQW5ZLoaVxSLH7en5fF X-Received: by 2002:a17:903:188:b0:1a9:2a9e:30a8 with SMTP id z8-20020a170903018800b001a92a9e30a8mr8215490plg.9.1682086885715; Fri, 21 Apr 2023 07:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682086885; cv=none; d=google.com; s=arc-20160816; b=Imv/jcE+dkQjGlrBR5IyAEjvSLkEt8YqH6LOtZHQcEOdZbpHkJAWKqTuhXh7bpyF2/ i8vL+t3eA4FY04RUNDI0sIR2R/rb27r0O18fY8G0Te6rmeayvjNlZn7eRf76rWQehLrG s3mnHWdeQavM58eqbXVPNHJ3DHQEDs7TBFWsvW2RQhCqj8FieWtlJSFc0grNKZh8GV7Y nuU7yyFbfOySNCY+XWt6vhPE3nqkp16tHd61I+v7DgAqSkgqJrEwZ+cgNsyzEb003h7o Qlq4rVufPXHaxtmQezKqMTrAVAcfV5Jmk8EeY/cftmbTs/x2vYI7gOgitJeR+8sfewBC WslQ== 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=W6639SD0H0EtLqB4ey0Z/SCfQQd2BwEFoKtAHXawttg=; b=1GwG51ZJywIK3TXSRQj/5CZgwIsp2GsACOAI8czw2JAep9CQZdL3GwmGoiAHXstPyO w/wiNc1hy/qBQRdQJhYVTo0dFf3Fg1/OlJ+PAV9/49bclVdnn0OBcwcJtqaABBYAzV3C 2g84TicOMesDCczbP8im42ak35IGBBZaV8ALgo2cUZH7UjEOd9j0yfqo2Cd/4uSZJgTN WkiyJ4SiWehWtVtElzbGEarcBWqTMai1mEPZJtlE+NdeSaadsksJYZ1U3ldrqo1dyDcu HGagR71xEnvT5sq2YFCrorGHjtjuO9M2hl8pxcjRUM/BxHiO19BLBaibK6r6tCq5Vd5+ eoiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=F99tHTPd; 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 f15-20020a170902684f00b001a24efa45bfsi4284702pln.81.2023.04.21.07.21.12; Fri, 21 Apr 2023 07:21:25 -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=F99tHTPd; 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 S232511AbjDUOTE (ORCPT + 99 others); Fri, 21 Apr 2023 10:19:04 -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 S232400AbjDUOSI (ORCPT ); Fri, 21 Apr 2023 10:18:08 -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 3B2B413C0B for ; Fri, 21 Apr 2023 07:18:05 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54f855ecb9cso23424457b3.0 for ; Fri, 21 Apr 2023 07:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682086685; x=1684678685; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=W6639SD0H0EtLqB4ey0Z/SCfQQd2BwEFoKtAHXawttg=; b=F99tHTPdoQ7C9Ix3lhzgS+44QzUBAXokIJ7FiF1lJ2iBIJ3DQYl/MLze6AckhIXvdc Hn1QgxpX5Y0KkD6eTmkiklywcUgCl65/mQAQ80srV+i65MYkbmqxNV6Wuv9hhHPEJgYj hj+Bvt+Bxx/5LGd0tPAx/FTKSotEpkvZ8kjx5jYAVY0+ZyZBlSdJuheD1Xo4AwSjku6L dt04yxCX5IT74kYysO2NmG5vOOht4o5PPfR6VATD2lZ3ZJXCc50kxU8yoAvhAHZBevKb 84pRmjxRdUbiYE/VJLBlphZEamluppZApe1XIXNcNQGXa6KhQTOAtfRelsZKUhgS7kOl u/dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682086685; x=1684678685; 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=W6639SD0H0EtLqB4ey0Z/SCfQQd2BwEFoKtAHXawttg=; b=c+LP5NPfcppbn3UNioXDM1axzdkS5eBWOOXAkp8WLK5fsF0vMwFo/fvEqnEf4su+nB RdyMcobBcbmxBC9BLjJqGt6oYbx5hOxCJEJhYv+YuRDoqzLZDfSY473JLqqStfydXdKG SvlBJmqfuTXRBsDH1IwGL625V6vhV9IHBJGyfQGg6AGsnswHu+THh9ydGKIo+nWxQwM9 SShkAdQbF2S1Vnt8iurhld+whY55a51yOOXs7ggT3i5zlJZmPO0tdQvKr1hIVEZfFV3U QmSIgSIHGyd7SnPjCc3ibkrcdC/AM2bmhF9Yk3sdfkNPMH4gVUAnoe0+Ck76ZwbIfjYb ruLg== X-Gm-Message-State: AAQBX9fZgTLcS1tpykYcKFe3w9bZGWi8YmSSAP9zINkUjn6UxgT9vPAz Ua28HditBgjkPzjJ6UID09vEQnUvG9RZD1Fgaw== X-Received: from peternewman0.zrh.corp.google.com ([2a00:79e0:9d:6:c801:daa2:428c:d3fc]) (user=peternewman job=sendgmr) by 2002:a81:b149:0:b0:54f:bb37:4a1c with SMTP id p70-20020a81b149000000b0054fbb374a1cmr1291578ywh.8.1682086684958; Fri, 21 Apr 2023 07:18:04 -0700 (PDT) Date: Fri, 21 Apr 2023 16:17:21 +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-8-peternewman@google.com> Subject: [PATCH v1 7/9] x86/resctrl: Assign HW RMIDs to CPUs for 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 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?1763795938220975388?= X-GMAIL-MSGID: =?utf-8?q?1763795938220975388?= To implement soft RMIDs, each CPU needs a HW RMID that is unique within its L3 cache domain. This is the minimum number of RMIDs needed to monitor all CPUs. This is accomplished by determining the rank of each CPU's mask bit within its L3 shared_cpu_mask in resctrl_online_cpu(). Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/core.c | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 47b1c37a81f8..b0d873231b1e 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -596,6 +596,38 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } } +/* Assign each CPU an RMID that is unique within its cache domain. */ +static u32 determine_hw_rmid_for_cpu(int cpu) +{ + struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); + struct cacheinfo *l3ci = NULL; + u32 rmid; + int i; + + /* Locate the cacheinfo for this CPU's L3 cache. */ + for (i = 0; i < ci->num_leaves; i++) { + if (ci->info_list[i].level == 3 && + (ci->info_list[i].attributes & CACHE_ID)) { + l3ci = &ci->info_list[i]; + break; + } + } + WARN_ON(!l3ci); + + if (!l3ci) + return 0; + + /* Use the position of cpu in its shared_cpu_mask as its RMID. */ + rmid = 0; + for_each_cpu(i, &l3ci->shared_cpu_map) { + if (i == cpu) + break; + rmid++; + } + + return rmid; +} + static void clear_closid_rmid(int cpu) { struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state); @@ -604,7 +636,12 @@ static void clear_closid_rmid(int cpu) state->default_rmid = 0; state->cur_closid = 0; state->cur_rmid = 0; - wrmsr(MSR_IA32_PQR_ASSOC, 0, 0); + state->hw_rmid = 0; + + if (static_branch_likely(&rdt_soft_rmid_enable_key)) + state->hw_rmid = determine_hw_rmid_for_cpu(cpu); + + wrmsr(MSR_IA32_PQR_ASSOC, state->hw_rmid, 0); } static int resctrl_online_cpu(unsigned int cpu) 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); From patchwork Fri Apr 21 14:17:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Newman X-Patchwork-Id: 86347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1108718vqo; Fri, 21 Apr 2023 07:26:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bMkgMYgRJXBIPrD31fa/Vqq/IF5zmcaaFzC3IJPTJmuavk4pb+pL7jTbgYY5CpWU+j7vso X-Received: by 2002:a05:6a20:8e0f:b0:ef:7d7b:4332 with SMTP id y15-20020a056a208e0f00b000ef7d7b4332mr6806306pzj.22.1682087191176; Fri, 21 Apr 2023 07:26:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682087191; cv=none; d=google.com; s=arc-20160816; b=i3trJvuWuV/xVKuapoNY4f9A6QAtcpYL1WgXCTS2T9v5JZmmULr5Fnj4XYZi5AZWs4 Z8HCA3IZCNvAblFdj239EZifjoEpYtRaAqCCyh+qamwzK3UG89HPqX+vd2aEsswKXHQT WO7hpOmRIANfH8MbXQn6mnYJjJ00D1rHhVptlHQQrlbJjOjBLh2VmVyn1p8npF0vnJX3 ylzSBoKG0ZgK+gM7Yp34eYkKAeweheDVlel5MlYrD3W1J994oAFClRvfdLx+GQgIYmZX 6J14fnBAezktwyQH8s00fJ5T9bcgbj4cDtiA9qJ/nF3LOqlx7dj2OtSxffchjdUqiNja HLBg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020aa797a9000000b0063b59a25a0asi4546930pfq.134.2023.04.21.07.26.19; Fri, 21 Apr 2023 07:26:31 -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 S232519AbjDUOTH (ORCPT + 99 others); Fri, 21 Apr 2023 10:19:07 -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 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?1763796258518806413?= X-GMAIL-MSGID: =?utf-8?q?1763796258518806413?= 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; }