Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp272010ioo; Thu, 26 May 2022 03:23:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy21uCgdvaCd0olljj2PH+rbPaYMwmMPfTbBYrZBO8bbBe42rib30Pzubc69h348hPoM36B X-Received: by 2002:a05:6a00:2918:b0:512:e4b5:60fb with SMTP id cg24-20020a056a00291800b00512e4b560fbmr38406203pfb.50.1653560596809; Thu, 26 May 2022 03:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653560596; cv=none; d=google.com; s=arc-20160816; b=mqRHp9TPfIN4WvclBrTmzSCZtPrYGmXtb7HK8I48sd1Id0v9/q9Eu9lFbW5e7ZOfr4 S38L7wHisEmxEf869ddAzf9wwKLDVhMhlxrJWWwA9I2DCSVFJDUm2hwoDh3dVgvdMHb6 CHHrupC1BnB6O5jGs40Li6+5AHWtboavYbOL9mats61kFk5Kle5lh5O0fWW3imtwtVFH 7QdgOiHk6UspvexnLgvFW/tya/EObBMp11hGo+aJOyoS5Iji3PrIJ2YcuX4zaFODLXhZ 23Ks+tDI3OwUcdFHtq2THka/J3PVtA3S9hOFDyM/Dlys3PYE8kkOEPYwcgxD08v9YT1P uMGQ== 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=8zFtkDd3+9pwSEugztLtlGyqQCGgy9wKKWLBsbNnYTE=; b=bOFJFSnHSxr1WqE9OhJqXOKQ5Q3LI6Fz2B/YT359bzA+4jKEHpsifzsFwRZlAmDjxq 4cO8tEL7vn0MI3HE3ZSp54lhqRbPgByvFwfBMls4Sl+LKQUj+ITPlHlN64H5+5xBKzqR WKNBeVj18Q9Mxu8BbpblYkAiw8+ytMhquKGiAJ7zD2X7v4I5AvVn5/G8kwaY0wHvnCiR 5K8bbJcrd5DKcen/rB6xdWMpS0uBNPzHSsLkj1qimS4mANmXMA/0wwT3yVIqsmyycmha LgOLaTwO3/n4ZSfg8nX71gcj1Znyu7+4eC5kiglDhCIwLQEAU4Kv9ncJVzrKuyL4wUFl 6YNQ== 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 y13-20020a056a00180d00b00518422cb775si1684318pfa.15.2022.05.26.03.23.03; Thu, 26 May 2022 03:23: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; 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 S240219AbiEYIPA (ORCPT + 99 others); Wed, 25 May 2022 04:15:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236715AbiEYIOl (ORCPT ); Wed, 25 May 2022 04:14:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB93E81998 for ; Wed, 25 May 2022 01:14:40 -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 7CC4423A; Wed, 25 May 2022 01:14:40 -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 85AE33F73D; Wed, 25 May 2022 01:14:38 -0700 (PDT) From: Sudeep Holla To: linux-kernel@vger.kernel.org Cc: Sudeep Holla , Atish Patra , Atish Patra , Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Qing Wang , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, Rob Herring Subject: [PATCH v3 04/16] cacheinfo: Add support to check if last level cache(LLC) is valid or shared Date: Wed, 25 May 2022 09:14:04 +0100 Message-Id: <20220525081416.3306043-5-sudeep.holla@arm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525081416.3306043-4-sudeep.holla@arm.com> References: <20220525081416.3306043-1-sudeep.holla@arm.com> <20220525081416.3306043-2-sudeep.holla@arm.com> <20220525081416.3306043-3-sudeep.holla@arm.com> <20220525081416.3306043-4-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_PASS,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. 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 417e1ebf5525..ed74db18468f 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