Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3137454iog; Mon, 27 Jun 2022 09:54:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t+gpyQlfSIixvjftNxxXOw+gHiKsvliH5QPJOagKC+ghuoKNF0KLiQdtVtUNw8jq33/gbi X-Received: by 2002:a50:fe83:0:b0:437:9c60:12f3 with SMTP id d3-20020a50fe83000000b004379c6012f3mr4769301edt.120.1656348850792; Mon, 27 Jun 2022 09:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656348850; cv=none; d=google.com; s=arc-20160816; b=iP/OLsoUzx89QoDv7b3EYUpc9Cr8m2FXod73yCFZtT3jHIEZ6nCTyD2zkcvsUx6ic+ mh8DbLf/WCHcQVScW9JaZwaQwPosVJskXc4mTnM+t46087VQxBz0EJJkTiXpISi7HNol uppyUYDdgrgWVoC+ahcM/5LJ7QuvoB14JPTnYTbwPMqk61LPV2tfmvYmEmbdndptBC31 RvzAme7K96tWSdfqRrcjz1KOmRhW4M958K+A8OF5IYjmaplXWkPgK/tjMHFaESjt4FWD 8Q7wgWOFFHgDGsWZrdAdDj0Y/qP8I62ljyBHYbuyBfXFJ3+EdKj853dBI/UXaorA2PPP /1xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8E9SDpTeiLq7w3szKdWR9qYMYRPQ921T9Qh/bECCHGA=; b=l2RWhi4wAOu1uJNJsw/Rz++shyeRqq4iLDElPLUeo+RGH0wic2xXGbSHB7JZDmzoTj F4keRTzpvJVBMYcsTdt/b23CcSrhoqs5OPkI+FTCHelBH7KIzTIEEXQPNzk8FKAG7Hlf seY9M3BHsMyQbjZCyM4sNY5LNLfPrCkPt064VUR2dQC3mceI92jCJO+A/DFlQwH2+rmH GgPJI3P/eOabkaptTWVaRD27R4mnjzErwsaL2j/BaWQVCF6iucpbu2FXRUJeW23bV4O9 7ew68bykSgC8S/+PE6TwAvxbmrUD7WCkA2WRFBU24EUNWoFGbOIQ4ONduqRr+DKEK8nH T0rg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020a1709064a1100b00722f72e1c15si12567621eju.428.2022.06.27.09.53.44; Mon, 27 Jun 2022 09:54:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238701AbiF0QvX (ORCPT + 99 others); Mon, 27 Jun 2022 12:51:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239429AbiF0QvM (ORCPT ); Mon, 27 Jun 2022 12:51:12 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 047DF12090 for ; Mon, 27 Jun 2022 09:51:07 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E18AD175A; Mon, 27 Jun 2022 09:51:07 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E53FD3F792; Mon, 27 Jun 2022 09:51:05 -0700 (PDT) From: Sudeep Holla To: linux-kernel@vger.kernel.org Cc: Sudeep Holla , Greg Kroah-Hartman , Atish Patra , Atish Patra , Vincent Guittot , Dietmar Eggemann , Qing Wang , Rob Herring , "Rafael J . Wysocki" , Ionela Voinescu , Pierre Gondois , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Gavin Shan Subject: [PATCH v5 05/19] cacheinfo: Add support to check if last level cache(LLC) is valid or shared Date: Mon, 27 Jun 2022 17:50:33 +0100 Message-Id: <20220627165047.336669-6-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627165047.336669-1-sudeep.holla@arm.com> References: <20220627165047.336669-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 It is useful to have helper to check if the given two CPUs share last level cache. We can do that check by comparing fw_token or by comparing the cache ID. Currently we check just for fw_token as the cache ID is optional. This helper can be used to build the llc_sibling during arch specific topology parsing and feeding information to the sched_domains. This also helps to get rid of llc_id in the CPU topology as it is sort of duplicate information. Also add helper to check if the llc information in cacheinfo is valid or not. Link: https://lore.kernel.org/r/20220621192034.3332546-6-sudeep.holla@arm.com Tested-by: Ionela Voinescu Reviewed-by: Gavin Shan Signed-off-by: Sudeep Holla --- drivers/base/cacheinfo.c | 26 ++++++++++++++++++++++++++ include/linux/cacheinfo.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 2cea9201f31c..fdc1baa342f1 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -47,6 +47,32 @@ static inline bool cache_leaves_are_shared(struct cacheinfo *this_leaf, return sib_leaf->fw_token == this_leaf->fw_token; } +bool last_level_cache_is_valid(unsigned int cpu) +{ + struct cacheinfo *llc; + + if (!cache_leaves(cpu)) + return false; + + llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); + + return !!llc->fw_token; +} + +bool last_level_cache_is_shared(unsigned int cpu_x, unsigned int cpu_y) +{ + struct cacheinfo *llc_x, *llc_y; + + if (!last_level_cache_is_valid(cpu_x) || + !last_level_cache_is_valid(cpu_y)) + return false; + + llc_x = per_cpu_cacheinfo_idx(cpu_x, cache_leaves(cpu_x) - 1); + llc_y = per_cpu_cacheinfo_idx(cpu_y, cache_leaves(cpu_y) - 1); + + return cache_leaves_are_shared(llc_x, llc_y); +} + #ifdef CONFIG_OF /* OF properties to query for a given cache type */ struct cache_type_info { diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 4ff37cb763ae..7e429bc5c1a4 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -82,6 +82,8 @@ struct cpu_cacheinfo *get_cpu_cacheinfo(unsigned int cpu); int init_cache_level(unsigned int cpu); int populate_cache_leaves(unsigned int cpu); int cache_setup_acpi(unsigned int cpu); +bool last_level_cache_is_valid(unsigned int cpu); +bool last_level_cache_is_shared(unsigned int cpu_x, unsigned int cpu_y); #ifndef CONFIG_ACPI_PPTT /* * acpi_find_last_cache_level is only called on ACPI enabled -- 2.36.1