Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2060878ybz; Thu, 30 Apr 2020 10:09:38 -0700 (PDT) X-Google-Smtp-Source: APiQypL5CEKO7WvTJKWhmMVMf4D8qosPbbuKYEAMy1QExaPMPltTwP3tK8l9kTUIO6nMOHm+XS7q X-Received: by 2002:a17:906:6a02:: with SMTP id o2mr3586363ejr.223.1588266578492; Thu, 30 Apr 2020 10:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588266578; cv=none; d=google.com; s=arc-20160816; b=0Qg3jBwO6J5qIwaeqML6zQSMoLMH+3xnt8+PDkS7HGQy9inSvj1PUUCHzzQheIlLG1 5X1lKCNUOqoE9dB1z3qRzoakk9MB8jjy/g9CITCnfT4q7uEsHGck7HHaNLsZzUUsMSCc PXN89/AQXFHfDXj+dlLBgHtB1oeN2Q8b4I0E+3wcR+JGU1SKXoGZI/m2F6bQfcRGgjBp hpxDLeIyYe9Lc4YyQKM62FYh4mU9eDC2t/1yoDelQOLuJi/07YAAYhzx/v0zzGFFnuzl 8uj4w8DDGoLXi3GKwvI9S+S4JGhbsYPPklIthvTrfpnHWcV7Uo3e9QFd+tlBahu8J8bL zv9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=a6BF81lYcBpiC5cQUsipenVghvEeifJ1Ywa/CeghVvI=; b=Ag5F4NwJ4wWAHtlHeiD+7TbkOIQfoG1kbGR0r60l6GxNs+hGoCGaJVMvMD8FoslRgT dxuFdr6WsZkNfxZ9bOLYQ5Zb4uW82Nn4fjctuReYw2C5csSwL3hCxRQXfdv3YKOtty0i OOrtBixNgHaFLjRZWBJF+GloZd2GpgJKmZf68XaTUIvDXBiTH7CrQPk2LrqXje6Ztd68 ii0FjFzCATM72oIKP8JHEPXnlnTTvLu8ity55LIM+5Pe1wkysbiBZ3RCQzYNRDPbmHL/ bbT+LRD6IffoA1Qa+4G3nRBPH9GsZTqXCfhKFNHTEortW0fVW1nDeVssC/BfYHSB4o4o AmGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si141893eju.166.2020.04.30.10.09.14; Thu, 30 Apr 2020 10:09:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727896AbgD3REm (ORCPT + 99 others); Thu, 30 Apr 2020 13:04:42 -0400 Received: from foss.arm.com ([217.140.110.172]:59262 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726440AbgD3REk (ORCPT ); Thu, 30 Apr 2020 13:04:40 -0400 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 C355B1045; Thu, 30 Apr 2020 10:04:39 -0700 (PDT) Received: from melchizedek.cambridge.arm.com (melchizedek.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 748003F73D; Thu, 30 Apr 2020 10:04:38 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse Subject: [PATCH v2 10/10] cacheinfo: Move resctrl's get_cache_id() to the cacheinfo header file Date: Thu, 30 Apr 2020 18:04:00 +0100 Message-Id: <20200430170400.21501-11-james.morse@arm.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20200430170400.21501-1-james.morse@arm.com> References: <20200430170400.21501-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org resctrl/core.c defines get_cache_id() for use in its cpu-hotplug callbacks. This gets the id attribute of the cache at the corresponding level of a cpu. Later rework means this private function needs to be shared. Move it to the header file. The name conflicts with a different definition in intel_cacheinfo.c, name it get_cpu_cacheinfo_id() to show its relation with get_cpu_cacheinfo(). Now this is visible on other architectures, check the id attribute has actually been set. Signed-off-by: James Morse --- arch/x86/kernel/cpu/resctrl/core.c | 17 ++--------------- include/linux/cacheinfo.h | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 00c88f42742c..f6458cefcac3 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -350,19 +350,6 @@ static void rdt_get_cdp_l2_config(void) rdt_get_cdp_config(RDT_RESOURCE_L2, RDT_RESOURCE_L2CODE); } -static int get_cache_id(int cpu, int level) -{ - struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); - int i; - - for (i = 0; i < ci->num_leaves; i++) { - if (ci->info_list[i].level == level) - return ci->info_list[i].id; - } - - return -1; -} - static void mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r) { @@ -560,7 +547,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d) */ static void domain_add_cpu(int cpu, struct rdt_resource *r) { - int id = get_cache_id(cpu, r->cache_level); + int id = get_cpu_cacheinfo_id(cpu, r->cache_level); struct list_head *add_pos = NULL; struct rdt_domain *d; @@ -606,7 +593,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) static void domain_remove_cpu(int cpu, struct rdt_resource *r) { - int id = get_cache_id(cpu, r->cache_level); + int id = get_cpu_cacheinfo_id(cpu, r->cache_level); struct rdt_domain *d; d = rdt_find_domain(r, id, NULL); diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 46b92cd61d0c..4f72b47973c3 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -3,6 +3,7 @@ #define _LINUX_CACHEINFO_H #include +#include #include #include @@ -119,4 +120,24 @@ int acpi_find_last_cache_level(unsigned int cpu); const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf); +/* + * Get the id of the cache associated with @cpu at level @level. + * cpuhp lock must be held. + */ +static inline int get_cpu_cacheinfo_id(int cpu, int level) +{ + struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); + int i; + + for (i = 0; i < ci->num_leaves; i++) { + if (ci->info_list[i].level == level) { + if (ci->info_list[i].attributes & CACHE_ID) + return ci->info_list[i].id; + return -1; + } + } + + return -1; +} + #endif /* _LINUX_CACHEINFO_H */ -- 2.26.1