Message ID | 20240130105236.3097126-2-dawei.li@shingroup.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-44434-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1131161dyb; Tue, 30 Jan 2024 02:55:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGi1eaE0Aj9Z89RabkB1u0QfqAPu3MNDITG8zhoQLb+Lg0c61dlTMI2q4dCjKnS/87OPx5v X-Received: by 2002:a17:906:19ce:b0:a36:bc3:3c8e with SMTP id h14-20020a17090619ce00b00a360bc33c8emr1512828ejd.50.1706612122907; Tue, 30 Jan 2024 02:55:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706612122; cv=pass; d=google.com; s=arc-20160816; b=VsbXpTpmpnp5jB62D0YIwr6MX9VzCZRlRWX5ktfhsSQXKah8iN0REaJdMn/eqfcu9q VkMPPvQvMqAADvgI5rbSdawCkPoi8bsrdtRe3CEB2xqNZyy0uBS/k2G6iTAO95vQDZ3R wgG7Lu7RtuS3xe/e05wb1ogP53CwJONrfQV5fYJx/Bol+UcvFusOTNA/LPqgxVPfA2VJ PajDM8r8wzpJssUaZZdfcHU2/MiWqN4VWmEqFBk1wF2JOw+KK687Vg8jMAwnEUgvWPFx RtNLLvyrfEmafveI0ualm32siAdJYS4FDzFb1PHYWatAUl4Pwb909VFsoaOdunNZWChM ayhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=eGCL7YR5rDNUQxE40LfXBuu86bUIykwWLpFp0I7fwIE=; fh=X4ESHG3nBm8IJ4pKa0sPg1PGVIKA3uDXwAnDzgNaeZw=; b=KSHMj7zZwywiIuq7j9M2IdIWsVQ9vJu2UNsWFKqx/StMEP5BUzvXzcMyxQrD314Hw8 TSCiUM2AyiqjMyx9JIsaMFhWrNMzGi8s9LFW+ySC5zchC4eVyhxUbo97kc3J+y47AeCj RVov1mDjb69Mjq62rH82rW5Y3PBDSscIpm/eT9lueAtF325OnkWvV9IktzaAhhcwHmdK 85Tld3MGPWHsN7/mdwkCXvHrLIQvFMGerRUFP/y83TAcC89u2ArdzFMHN9zFrbMDZL9E cJO5jQ4MUCzksp24k/ROwJK5MSBllrbfBhe1b36tRQPfYGPhe9DIJwRrg92HYCBfpLsb 3/rg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-44434-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44434-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dt16-20020a170906b79000b00a3600b03138si909616ejb.1003.2024.01.30.02.55.22 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:55:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44434-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-44434-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44434-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4D89E1F24E23 for <ouuuleilei@gmail.com>; Tue, 30 Jan 2024 10:55:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6747967A0C; Tue, 30 Jan 2024 10:53:59 +0000 (UTC) Received: from bg5.exmail.qq.com (bg5.exmail.qq.com [43.154.197.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81D90679E1; Tue, 30 Jan 2024 10:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=43.154.197.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706612037; cv=none; b=mNuKkwycJ1VE4esOG4nCrwQGiQacv6BTyDP1Fo5cswrQWFPvTzEe/JO2zhbItj1VsWU4qxiBNApXrQ1zSY+8lOz8w/vXwlxWhfqtHBev7nj/FqQ6yqZysPLe7e25sAJxUZlDuIRg3sl8iVNbaDbLXieCxLUcYtztrIbD0vxDIhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706612037; c=relaxed/simple; bh=RIK1GTg4s+rzbcaZXHK3u636sXfCOEHmIpjFNKQH/dY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JiibWpJB82JXnNVVBzE/dcC4xrIMvHi9ZARa4AR8wfUXiylIPyVcjysWqsPEYSPluO+6v4CCAmPPjN2YGVG4HjNLWra3FiHL7cYH2gRKOBszanoNqSX0IN0iZE7zZWEtpr7hx952Y3vCUsTJCFmXs5Xs3lqaQzQMd+NZuIr4RcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=43.154.197.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtp67t1706612008t5pdrgw5 X-QQ-Originating-IP: McRnbfgIa0ScS2LSD6966zLm+LhiBWrKFLqPBn+AjPs= Received: from localhost ( [183.209.108.228]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 30 Jan 2024 18:53:27 +0800 (CST) X-QQ-SSF: 01400000000000504000000A0000000 X-QQ-FEAT: hbRRqFkQ5Km9KMEaVsJ8Yg3S2qaluHN41rFJKLGwpIe8Lc2o6QRSVAfxL3TFV ul80InEbhhCPqguTFs9hhU18gu/OibUWzEo+mLfpAt1x+Er0r/aUmVgQYEt/YOrBHMiv7Tw UkOhG1giJz8R3tkYqA+j9M30/jdcNbUFctEmlY0fISL6aBq7LqspOEXTRIlHen/OAhMGJm4 9ALwTwZ6CIBntsfSB5rgrVpkOA6R4sG83H4AbzNomaffUewLBEx+9ZSHfyCAjavjkSY7iiO Rn38RTa1e4XSw/2li8q0MrE34SdHN5LeyuVl0iAB3CJYBqkuCHZRQMQ/tKynlLrhetrB1ut J8zGe2kLEw13E9G6STJ2QGRSdPG7/+n6O1uCiGLMnNNj+YZyXOir++MBdunvTQliHsvT7ki DDNM/GpLbiQ= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 14637609362048520855 From: Dawei Li <dawei.li@shingroup.cn> To: robh+dt@kernel.org, frowand.list@gmail.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, set_pte_at@outlook.com, Dawei Li <dawei.li@shingroup.cn> Subject: [PATCH 1/2] of: Introduce __of_phandle_update_cache Date: Tue, 30 Jan 2024 18:52:35 +0800 Message-Id: <20240130105236.3097126-2-dawei.li@shingroup.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240130105236.3097126-1-dawei.li@shingroup.cn> References: <20240130105236.3097126-1-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-1 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789512513523425331 X-GMAIL-MSGID: 1789512513523425331 |
Series |
Update phandle cache on device node attach
|
|
Commit Message
Dawei Li
Jan. 30, 2024, 10:52 a.m. UTC
For system with CONFIG_OF_DYNAMIC=y, device nodes can be inserted/removed
dynamically from device tree. Meanwhile phandle_cache is created for fast
lookup from phandle to device node.
For node detach, phandle cache of removed node is invalidated to maintain
the mapping up to date, but the counterpart operation on node attach is
not implemented yet.
Thus, implement the cache updating operation on node attach.
Signed-off-by: Dawei Li <dawei.li@shingroup.cn>
---
drivers/of/base.c | 16 ++++++++++++++++
drivers/of/of_private.h | 1 +
2 files changed, 17 insertions(+)
Comments
On Tue, Jan 30, 2024 at 06:52:35PM +0800, Dawei Li wrote: > For system with CONFIG_OF_DYNAMIC=y, device nodes can be inserted/removed > dynamically from device tree. Meanwhile phandle_cache is created for fast > lookup from phandle to device node. Why do we need it to be fast? What's the usecase (upstream dynamic DT usecases are limited) and what's the performance difference? We'll already cache the new phandle on the first lookup. Plus with only 128 entries you are likely evicting an entry. > For node detach, phandle cache of removed node is invalidated to maintain > the mapping up to date, but the counterpart operation on node attach is > not implemented yet. > > Thus, implement the cache updating operation on node attach. Except this patch does not do that. The next patch does. > > Signed-off-by: Dawei Li <dawei.li@shingroup.cn> > --- > drivers/of/base.c | 16 ++++++++++++++++ > drivers/of/of_private.h | 1 + > 2 files changed, 17 insertions(+) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index b0ad8fc06e80..8b7da27835eb 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -163,6 +163,22 @@ void __of_phandle_cache_inv_entry(phandle handle) > phandle_cache[handle_hash] = NULL; > } > > +void __of_phandle_update_cache(struct device_node *np, bool lock) > +{ > + u32 hash; > + > + if (lock) > + lockdep_assert_held(&devtree_lock); I don't think this is a good use of a function parameter. > + > + if (unlikely(!np || !np->phandle)) > + return; > + > + hash = of_phandle_cache_hash(np->phandle); > + > + if (!phandle_cache[hash]) > + phandle_cache[hash] = np; Okay, so you don't evict existing entries. I'm not sure what makes more sense. I would imagine old entries are less likely to be accessed than new phandles for just added nodes given DT is kind of parse it all once (e.g. at boot time). Again, need to understand your usecase and performance differences. Rob
Hi Rob, Thanks for reviewing, On Wed, Jan 31, 2024 at 03:29:38PM -0600, Rob Herring wrote: > On Tue, Jan 30, 2024 at 06:52:35PM +0800, Dawei Li wrote: > > For system with CONFIG_OF_DYNAMIC=y, device nodes can be inserted/removed > > dynamically from device tree. Meanwhile phandle_cache is created for fast > > lookup from phandle to device node. > > Why do we need it to be fast? What's the usecase (upstream dynamic DT > usecases are limited) and what's the performance difference? We'll > already cache the new phandle on the first lookup. Plus with only 128 > entries you are likely evicting an entry. I read the history changelog and get that a _lot_ of lookup has been taken before of_core_init(), so the update of cache in lookup operation mean a lot to performance improvement. > > > For node detach, phandle cache of removed node is invalidated to maintain > > the mapping up to date, but the counterpart operation on node attach is > > not implemented yet. > > > > Thus, implement the cache updating operation on node attach. > > Except this patch does not do that. The next patch does. Agreed. > > > > > Signed-off-by: Dawei Li <dawei.li@shingroup.cn> > > --- > > drivers/of/base.c | 16 ++++++++++++++++ > > drivers/of/of_private.h | 1 + > > 2 files changed, 17 insertions(+) > > > > diff --git a/drivers/of/base.c b/drivers/of/base.c > > index b0ad8fc06e80..8b7da27835eb 100644 > > --- a/drivers/of/base.c > > +++ b/drivers/of/base.c > > @@ -163,6 +163,22 @@ void __of_phandle_cache_inv_entry(phandle handle) > > phandle_cache[handle_hash] = NULL; > > } > > > > +void __of_phandle_update_cache(struct device_node *np, bool lock) > > +{ > > + u32 hash; > > + > > + if (lock) > > + lockdep_assert_held(&devtree_lock); > > I don't think this is a good use of a function parameter. Yep, assertion under condition is odd. > > > + > > + if (unlikely(!np || !np->phandle)) > > + return; > > + > > + hash = of_phandle_cache_hash(np->phandle); > > + > > + if (!phandle_cache[hash]) > > + phandle_cache[hash] = np; > > Okay, so you don't evict existing entries. I'm not sure what makes more Yes, the updating policy of dynamic nodes is exactly same with static nodes (the ones in of_core_init()), no eviction/invalidation on _existing_ cache involved. > sense. I would imagine old entries are less likely to be accessed than Well, I don't think we are gonna implement a full-fledged cache replacing algorithm such as LRU. > new phandles for just added nodes given DT is kind of parse it all once > (e.g. at boot time). Again, need to understand your usecase and > performance differences. It's kinda awkward that no such usecases/stats are available for now. My motivation is simple as that: As long as detached nodes are supposed to be removed from cache entries, the newly inserted nodes should be added to cache entries, it is more balanced and symmetric. And I am sorry if it breaks/undermines current design. Thanks, Dawei > > Rob >
On Thu, Feb 1, 2024 at 4:01 AM Dawei Li <dawei.li@shingroup.cn> wrote: > > Hi Rob, > > Thanks for reviewing, > > On Wed, Jan 31, 2024 at 03:29:38PM -0600, Rob Herring wrote: > > On Tue, Jan 30, 2024 at 06:52:35PM +0800, Dawei Li wrote: > > > For system with CONFIG_OF_DYNAMIC=y, device nodes can be inserted/removed > > > dynamically from device tree. Meanwhile phandle_cache is created for fast > > > lookup from phandle to device node. > > > > Why do we need it to be fast? What's the usecase (upstream dynamic DT > > usecases are limited) and what's the performance difference? We'll > > already cache the new phandle on the first lookup. Plus with only 128 > > entries you are likely evicting an entry. > > I read the history changelog and get that a _lot_ of lookup has been > taken before of_core_init(), so the update of cache in lookup operation > mean a lot to performance improvement. Yes, and there was compelling data on the performance difference to justify the added complexity. > > > For node detach, phandle cache of removed node is invalidated to maintain > > > the mapping up to date, but the counterpart operation on node attach is > > > not implemented yet. > > > > > > Thus, implement the cache updating operation on node attach. > > > > Except this patch does not do that. The next patch does. > > Agreed. > > > > > > > > > Signed-off-by: Dawei Li <dawei.li@shingroup.cn> > > > --- > > > drivers/of/base.c | 16 ++++++++++++++++ > > > drivers/of/of_private.h | 1 + > > > 2 files changed, 17 insertions(+) > > > > > > diff --git a/drivers/of/base.c b/drivers/of/base.c > > > index b0ad8fc06e80..8b7da27835eb 100644 > > > --- a/drivers/of/base.c > > > +++ b/drivers/of/base.c > > > @@ -163,6 +163,22 @@ void __of_phandle_cache_inv_entry(phandle handle) > > > phandle_cache[handle_hash] = NULL; > > > } > > > > > > +void __of_phandle_update_cache(struct device_node *np, bool lock) > > > +{ > > > + u32 hash; > > > + > > > + if (lock) > > > + lockdep_assert_held(&devtree_lock); > > > > I don't think this is a good use of a function parameter. > > Yep, assertion under condition is odd. > > > > > > + > > > + if (unlikely(!np || !np->phandle)) > > > + return; > > > + > > > + hash = of_phandle_cache_hash(np->phandle); > > > + > > > + if (!phandle_cache[hash]) > > > + phandle_cache[hash] = np; > > > > Okay, so you don't evict existing entries. I'm not sure what makes more > > Yes, the updating policy of dynamic nodes is exactly same with static nodes > (the ones in of_core_init()), no eviction/invalidation on _existing_ cache > involved. > > > sense. I would imagine old entries are less likely to be accessed than > > Well, I don't think we are gonna implement a full-fledged cache replacing > algorithm such as LRU. > > > new phandles for just added nodes given DT is kind of parse it all once > > (e.g. at boot time). Again, need to understand your usecase and > > performance differences. > > It's kinda awkward that no such usecases/stats are available for now. > > My motivation is simple as that: > As long as detached nodes are supposed to be removed from cache entries, > the newly inserted nodes should be added to cache entries, it is more > balanced and symmetric. The difference is that no entry for attach works fine while accessing a detached node that may have been freed would be a problem. Rob
diff --git a/drivers/of/base.c b/drivers/of/base.c index b0ad8fc06e80..8b7da27835eb 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -163,6 +163,22 @@ void __of_phandle_cache_inv_entry(phandle handle) phandle_cache[handle_hash] = NULL; } +void __of_phandle_update_cache(struct device_node *np, bool lock) +{ + u32 hash; + + if (lock) + lockdep_assert_held(&devtree_lock); + + if (unlikely(!np || !np->phandle)) + return; + + hash = of_phandle_cache_hash(np->phandle); + + if (!phandle_cache[hash]) + phandle_cache[hash] = np; +} + void __init of_core_init(void) { struct device_node *np; diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index f38397c7b582..89559aad8ccb 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -94,6 +94,7 @@ int of_resolve_phandles(struct device_node *tree); #endif void __of_phandle_cache_inv_entry(phandle handle); +void __of_phandle_update_cache(struct device_node *np, bool lock); #if defined(CONFIG_OF_OVERLAY) void of_overlay_mutex_lock(void);