Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp445225rdb; Thu, 1 Feb 2024 13:11:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaRnBSCvP/gxoZYQTVIuNfrz7b5dRnR9tLAsyXqMOApU0IOJZ0X/7jlNORHKCQNHNe3yhi X-Received: by 2002:a05:6a21:151b:b0:19c:a632:e176 with SMTP id nq27-20020a056a21151b00b0019ca632e176mr83817pzb.11.1706821862880; Thu, 01 Feb 2024 13:11:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706821862; cv=pass; d=google.com; s=arc-20160816; b=TpCKEbeaiwTctDciLDs2N87iRItr32LkLijlGpBd5OY26fkhWFSjQp3PyRIFjIreKc qJn3zxoUqsiOqjQmiv4RbzGCGFT1/Jysc8AJtis0wqOd1VCnrrxPwtvHK22y5FPMbmMG nAzoKEOSQwrMx8zwOJ2ZVGGvebJZYI699R2yw4bK4slChsmyRZirGyZw036cxeRdxRH+ y3ovjhC054Je/53ceMAtn5hYTPWw6kZrWftWXa+xqlz1de2irpU66pYwkGyfAvhweodE 37iRZX8wVnCL0lXbYlJg34k0fP5vl8h4KL4Pcqm3JhnIsymSMCKqgqpEE5VnS/RT9tSQ 49/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=qH5gPo6GpSginb5T5EeYJXxIoo0x4+PqjX93YfIGBzI=; fh=3+dadpCHRkAMJlI/OIIvDKBQRQmKgPWHCNAVQWcqBuM=; b=QObFgl0I5s+3k0To15rtvyaDa6tNF1Qzicc8uMrdXKqmExGrMl0vqRMMHKYwYEmwqu VWAk4KNeIgwGzTpAz+e3tRPlfVewunFRb96Ok0LxO1NWD5+PL8v9Wc2jmp7tdb/CQhs8 7OfGOrdppV7ltOsIMjKc1ZMZOAzpMg191pW8CRqUqegL6xJqybgiZlPl8To9h3A4iNuB x2wNQF0NsUj1MOklvJRFm11gW5kcD99PSu/XOi/4gFbv+luKiUfJtFN0qPguvltOt4yY DoMHF7r6iGnW0v6X4DkfSB24Pt0LMJpWnelGEuYOPgsnLKATjPFOKPQvCG2ic4Wv/MiU yzvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bn0Kx9Wy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-48861-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48861-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUkvR9K74JfTjxz8tWHtU1tVrZe5NeIr0KmvVciKBbJRdRnMTO4yzvDK4EQB2SB8fWG8juzsDxXfun1t3ZyDtZTOUfu7B4B0OSpKHpdZw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x16-20020aa79a50000000b006d9a4e6ce19si269625pfj.159.2024.02.01.13.11.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 13:11:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48861-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bn0Kx9Wy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-48861-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48861-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5F925285E40 for ; Thu, 1 Feb 2024 21:11:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25133405FE; Thu, 1 Feb 2024 21:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bn0Kx9Wy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 402FA39AE1; Thu, 1 Feb 2024 21:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706821768; cv=none; b=jZrUo7iK7J1S5zVtwisM7gBag0d4s4s6Cn87i/UkoQAB2r4WG7RDhfcFuISJYe9j2JA2fTbVdbK6A1v9JsS0/aBpjRRPNLH9ApgOboSy76oxSdMkc81UqsvPsO+IphPrgZC+swhuGD9w2IbWtBjXD9223xVD0uGck280H+De0Gw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706821768; c=relaxed/simple; bh=6v01RU+zLBfMH3ycqivUxPJyd9tsVfriHpIcjMGbkes=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=QG24YDyc7uIWDgX65NpZH0OkRpOJUMFnylAL7YLr0XyFri1rbr0zE1aW8GCDdWTcXIYW3K5iRnArX7xdBsWB6CU8CTbNFUzhHGWoEMb93w2XMsXuz+6fjFE4sIApFILohe8rqIIiEj50nAx5McyRUECtE2AXe4hPRSwln8XHugM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bn0Kx9Wy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3994C43390; Thu, 1 Feb 2024 21:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706821767; bh=6v01RU+zLBfMH3ycqivUxPJyd9tsVfriHpIcjMGbkes=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Bn0Kx9WybaQsW2pRh0Btwv1/jeZ9YrtkMLOy6D5HjMROH6mqJVGRuzWEkekfQt79H szsqxSalbLFCLrIMbRzgdWINX8HtTO6iySGW5iDstwAMfsP8x5RQJkFtaWt48nIZpR cp5sVZbAt0/wmSmAL4AjES7fV5+LhBCp2E3SqxF0g9aSTKtzNAmbPCHv0FPFcjvlHd kdre5oOfR9jsPfz9SmN/9TNbIsEqEcee2U78ZOLJOIAdYG+IfmG30H2Q16gmYRmgQV CZUjS9z8GsDB70D548p52Q3fGmsOw1uZ1MOl/aXm6gwzGBTBGA5aKXYW7DXuXUlcsi RTXv55zbNJCYw== Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-510322d5363so2184835e87.1; Thu, 01 Feb 2024 13:09:27 -0800 (PST) X-Gm-Message-State: AOJu0Yw+oIAqPPuCZopbuQyYPyTHkoRlakKS+43mqLiRwfqnSkwtRthL qzwP39waWHmT/ttGBPsK4bVs0tYUdD+QLJHApsJXzzuIowVr1JjeUMU0gaO2CjD084WilVc5MdN EnEAmu0JUE8lNHNpr4RVqgIelOQ== X-Received: by 2002:a05:6512:3b0:b0:511:21e4:5a69 with SMTP id v16-20020a05651203b000b0051121e45a69mr2724946lfp.40.1706821765984; Thu, 01 Feb 2024 13:09:25 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240130105236.3097126-1-dawei.li@shingroup.cn> <20240130105236.3097126-2-dawei.li@shingroup.cn> <20240131212938.GB2303754-robh@kernel.org> In-Reply-To: From: Rob Herring Date: Thu, 1 Feb 2024 15:09:13 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] of: Introduce __of_phandle_update_cache To: Dawei Li Cc: frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, set_pte_at@outlook.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 4:01=E2=80=AFAM Dawei Li wro= te: > > 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=3Dy, device nodes can be inserted/r= emoved > > > 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 main= tain > > > 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 > > > --- > > > 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] =3D 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 =3D of_phandle_cache_hash(np->phandle); > > > + > > > + if (!phandle_cache[hash]) > > > + phandle_cache[hash] =3D 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 nod= es > (the ones in of_core_init()), no eviction/invalidation on _existing_ cach= e > 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