From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759880AbdKPPYE (ORCPT ); Thu, 16 Nov 2017 10:24:04 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52572 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759056AbdKPPXz (ORCPT ); Thu, 16 Nov 2017 10:23:55 -0500 Cc: gregkh@linuxfoundation.org, Sudeep Holla , linux-kernel@vger.kernel.org Subject: Re: [PATCH] drivers: base: cacheinfo: support DT overrides for cache type To: Tan Xiaojun References: <1510837089-5951-1-git-send-email-tanxiaojun@huawei.com> From: Sudeep Holla Organization: ARM Message-ID: Date: Thu, 16 Nov 2017 15:23:52 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1510837089-5951-1-git-send-email-tanxiaojun@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/11/17 12:58, Tan Xiaojun wrote: > Since commit dfea747d2aba ("drivers: base: cacheinfo: support DT > overrides for cache properties"), we can set the correct cacheinfo > via DT. But the cache type can't be set in the same way. > > I found this may be a problem in recent tests. I tested L3 cache > node setting in DT in Hisilicon D03/D05 board. And I got cacheinfo > via sysfs below: I assume L3 is outer non-architected system cache. > > $ cat /sys/devices/system/cpu/cpu*/cache/index3/ > allocation_policy level power/ > shared_cpu_map uevent write_policy > coherency_line_size number_of_sets shared_cpu_list > size ways_of_associativity > > This is incomplete, no type file to display type info. Because L3 > cache is uncore, we can't get correct type info from system > register, and will get a default type "CACHE_TYPE_NOCACHE". Then > use "lscpu" will print an error like below: > > $ lscpu > lscpu: cannot open /sys/devices/system/cpu/cpu0/cache/index3/type: > No such file or directory > > So I think maybe we can set correct cache type via DT too. > > Signed-off-by: Tan Xiaojun > --- > drivers/base/cacheinfo.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c > index eb3af27..3e650dc 100644 > --- a/drivers/base/cacheinfo.c > +++ b/drivers/base/cacheinfo.c > @@ -122,6 +122,15 @@ static inline int get_cacheinfo_idx(enum cache_type type) > return type; > } > > +static void cache_type(struct cacheinfo *this_leaf) > +{ > + const __be32 *cache_type; > + > + cache_type = of_get_property(this_leaf->of_node, "type", NULL); NACK for this: 1. We don't have any DT binding for the "type" 2. Even if we had, we will never have such a binding that magical returns the enum used in Linux implementation. That's not how DT bindings are designed. Please refer ePAPR or Devicetree Specification Release 0.1 from devicetree.org, we have cache-unified boolean for type. Let me know if the below patch works for you, I will submit it preferably with your tested-by. Regards, Sudeep -->8 diff --git i/drivers/base/cacheinfo.c w/drivers/base/cacheinfo.c index eb3af2739537..07532d83be0b 100644 --- i/drivers/base/cacheinfo.c +++ w/drivers/base/cacheinfo.c @@ -186,6 +186,11 @@ static void cache_associativity(struct cacheinfo *this_leaf) this_leaf->ways_of_associativity = (size / nr_sets) / line_size; } +static bool cache_node_is_unified(struct cacheinfo *this_leaf) +{ + return of_property_read_bool(this_leaf->of_node, "cache-unified"); +} + static void cache_of_override_properties(unsigned int cpu) { int index; @@ -194,6 +199,14 @@ static void cache_of_override_properties(unsigned int cpu) for (index = 0; index < cache_leaves(cpu); index++) { this_leaf = this_cpu_ci->info_list + index; + /* + * init_cache_level must setup the cache level correctly + * overriding the architecturally specified levels, so + * if type is NONE at this stage, it should be unified + */ + if (this_leaf->type == CACHE_TYPE_NOCACHE && + cache_node_is_unified(this_leaf)) + this_leaf->type = CACHE_TYPE_UNIFIED; cache_size(this_leaf); cache_get_line_size(this_leaf); cache_nr_sets(this_leaf);