Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2316065rwr; Fri, 21 Apr 2023 07:20:43 -0700 (PDT) X-Google-Smtp-Source: AKy350bY6FZ873n4wTS/eXrN8cY8/yMqIHErRpCJLBx+x+dZYyBqJkWbFh7M68fTwMzK2mD/P7jg X-Received: by 2002:a17:903:22ce:b0:19a:a815:2877 with SMTP id y14-20020a17090322ce00b0019aa8152877mr6555151plg.6.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=aoqBohz0lNwYDMUp9E11cpmbDSE8JUqGbu/EevwxvUnFbwk4zKsfy0Osu4Xu1V0ZE1 YW0Kdeyz9f7qn6HpK/o4KgaBFB61ZHi2a8YBYG8jjCAPAiAVCw1DbBdBpOmzClXMKCxt Mj+ox+Qo8MAHZTXs0Ehx58XNu1VwBg8osFWLDHZ16Hl7IH/J+f7b+gc/vfX4Lk3yn2Ar UaCYc31uxyw5HrRfM5YGvbYsKEhnwZI7jaw07TW5CAdtPDvzzgb9rL6btWaGRBPsJTuf 5JPIkmXzv36cgilUK2ChlDsyrzDDt1H5x5kjzPbYglGHIkViSPAf56KVly/EUwEdCYUM /DNQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gd17-20020a17090b0fd100b002308ac7a1b0si4704520pjb.117.2023.04.21.07.20.30; 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=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 S232509AbjDUOTE (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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To implement soft RMIDs, 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) -- 2.40.0.634.g4ca3ef3211-goog