Received: by 2002:ac0:de83:0:0:0:0:0 with SMTP id b3csp1463504imk; Mon, 4 Jul 2022 03:42:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vew6Y8SJSYRL/0j4zJ3kuMJVGiAJ3nENNUu8HWIvASGUpb3kVhCjJm7MRvQATHDLvyjXZu X-Received: by 2002:a05:6a00:3488:b0:528:3c8b:7b3a with SMTP id cp8-20020a056a00348800b005283c8b7b3amr15948001pfb.57.1656931340880; Mon, 04 Jul 2022 03:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656931340; cv=none; d=google.com; s=arc-20160816; b=0EVMvucyTmj50e62KWrYISpQOVNr/syNxvCQ4rH9QxJNoktUq7KMpzakjh0/TmQNui 0T1kC0UnZXgsLEdzAsZUrugeLtgCvPNp115T4izTzKS9NKJxMe+k8Osbb7DVXf+0jPaK AYhWpCOWCIH7+WfKKS6daVybrfByEEJrtMx3KhLj+IvM/uFKNga4qY/Sj++raBFjcs+B JfrVuGNMxYW+O2EXRl+FSqQ+g9bii8I7fSN1W+wDnisGHmckI/r7vNAcuuj+raXJZhY0 xP2mXooeYY6Mdn6MTB+evJdbxVzJ/8Sh7U0+L1Ck3/Zwu/UT/vlqBRb9oBn6rW2z6xv9 bEcg== 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=OWdxnRG648EEBUYYQTJ1+sXGSlzgPwn4MeoQ+x915uk=; b=FyGqBFDeJwjS0dO7l1WtFcpTl9QeETj+h3CoSeiLhy8TuR+yulEuMua3KEEq90aA7i n4ixSJ0ahkUxDqk1YofHUAmZENIdlC2I0G2DfEOB3C/IBWdzKNEnjLfFf4QAgmTpYssT owthA/scwAVglAUH53n0MdnKQ10FuKIPNcJXSssilGmszCUhyYG8WCNLoesQsf7NIL/A gGeNc960RCqjeSnUuHM9Ted1xV3Rdj4mfUNIanIRKtvTRLug8i1B0so3zwmg61QkPOVq h201jygQ0qhK6fUOeqG2FbG+BFShtudb3TO97VS2YRzAlA1DlEl274senWSelE4piB9P wzjg== 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 w70-20020a638249000000b003fe26a2db63si37958329pgd.401.2022.07.04.03.42.09; Mon, 04 Jul 2022 03:42:20 -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 S234361AbiGDKRP (ORCPT + 99 others); Mon, 4 Jul 2022 06:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232768AbiGDKQ0 (ORCPT ); Mon, 4 Jul 2022 06:16:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDA2EDF74 for ; Mon, 4 Jul 2022 03:16:25 -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 E7499D6E; Mon, 4 Jul 2022 03:16:25 -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 BCDA23F792; Mon, 4 Jul 2022 03:16:23 -0700 (PDT) From: Sudeep Holla To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Cc: Sudeep Holla , conor.dooley@microchip.com, valentina.fernandezalanis@microchip.com, 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 v6 05/21] cacheinfo: Add support to check if last level cache(LLC) is valid or shared Date: Mon, 4 Jul 2022 11:15:49 +0100 Message-Id: <20220704101605.1318280-6-sudeep.holla@arm.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220704101605.1318280-1-sudeep.holla@arm.com> References: <20220704101605.1318280-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. 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.37.0