Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1926468rdb; Wed, 31 Jan 2024 13:31:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV4KNGXe6GbF2RGN4ARXSuzvrdn6WNlahDFMzmKoUwFwCKwgerP3BdKQW2Qcbt+xHLFikL X-Received: by 2002:a05:6a20:7484:b0:19e:3c4e:f7a8 with SMTP id p4-20020a056a20748400b0019e3c4ef7a8mr927675pzd.11.1706736673803; Wed, 31 Jan 2024 13:31:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706736673; cv=pass; d=google.com; s=arc-20160816; b=MDJwFZpHno5xFguH3fuqobD1VAtn/U5WmuCEzhEFcHiu/Gx5Cb8L4MnO+6/DLwomZt A6JbffD0IoawVUSNODFt79lPAoFfduD7aHkRFHNcO8dosQ3cSvXTPiNbaYJlIWz/K5uI 25eDO9dpAToS7y06npnuy7dlaM6UAIouagPd2/FeMFCrvfoCRGmCIaeCgeOJDMuPrkDh K02t0OFJyAGkAkWyH90qdBCG75bnnxdcl1GVkct5HTaMrewLUsZvUmCGz5sxvuQtn+87 HwSa3eRHSPK8MsfjvctFvLlLjWa+nYSrE9/4E2sSjAebIsIaHvkeie3UqYG/niZgOBmF WuvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nlNYY5bt/V8GMwbheJhuhNzStiVRf6ADInltjWQNrSc=; fh=z+rzDf4uzz7WArYPz2uxfOR+I//HA+yaE73d7bp/tC0=; b=rr5Rfj8pcr6SWmbtCIYKMZ7ObANGPb/jsJRkAeDTN2SG0RVN0x/8uo3PXlxBuw+TAc YawPbSBmEnaVHJIe6wS5LrWUzOGlxjsYYENANjMe2ekUWZ8RU3Z/C1ElpLaC5r9gsX06 oftZbg/QuMU5NMHkEBiLpoxYgLcdFLwSM3/zGofa6rNbaf3w1B8nraqqIpzBqVmEmiTy BHpaEpxA1HZbnzdz4TAwQf+Je89mHVNGLkklM0ierPPy8Dq2qhPsy6ErC6QuwAHawuaA srsgXgAFPwpJS5c8M+NjqOAzqvMssUBifghFud6JnbCQzkx80sI+Sx2E7vqYhFFDSZ8n zBmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rneGBcjK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47170-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; AJvYcCXD4IvouHWFtgznKaml0twVK0z2uX/PC4O8hh0LyOVsh/aNxIGkVB+g/zdEsX5bspWSH8P4nH1smZbdKQT66iohWK9jABjMoAaVApS3ZA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w19-20020a056a0014d300b006db9cce8e2fsi10749586pfu.280.2024.01.31.13.31.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 13:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47170-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=rneGBcjK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47170-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 7784E2861FA for ; Wed, 31 Jan 2024 21:31:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 714903A1C1; Wed, 31 Jan 2024 21:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rneGBcjK" 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 85CA23985A; Wed, 31 Jan 2024 21:29:41 +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=1706736581; cv=none; b=Z6P9TWqYSDLJV912bt+7zA6qlyXLqdbDsQ8eVeCFL8HT0vjjDVQofqLRPZkhktfvaHhjG/JxOxxvbItQ/Tu3cgJjPrko3aqy9WbVA6qxuKeAu5zTwljnaDgp4Kt3mrhX7I+6AH/qqew9Cu083qwL0S8MSKb71dEFvzlE3gG+Vi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706736581; c=relaxed/simple; bh=+ZV2cN1u7YTwLufo+MSlE1shle2HFWJbJPm0fQ1GzBo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iA1ElnyWmf++RnnI/cpraMm0tamJltxZKeFQ9zcwtbieMvxx8RfnovUmPguexFhZ+GDo1jjuIDqFdnUTEdFWPws79NrtRuZb7j9h8GjigiQIKcEUj3nXJ3x5VBzr4XeKatUyADwoWa6vb7alqHIwKVc9fShSmi9mAq+brug5AxM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rneGBcjK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C95A7C433C7; Wed, 31 Jan 2024 21:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706736581; bh=+ZV2cN1u7YTwLufo+MSlE1shle2HFWJbJPm0fQ1GzBo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rneGBcjKDAVaVzQgBrzml07UEUx3wI24DIog/I3aLVvBTFmCTfTrjD/cetBRVfgzf Vzk1WrWXmRQCz09lsQcmHfQsTZ5qpkevKuibFLdZwLy/EUzxaIFWdA68qlaVOZbue7 Bnh39eCNZVII4QGvOuCfoN7iGXhsML2STxSss9VHuIISep+1VvBwmKGghFA/dmVBUi yNTbFP2gPkLmsv/KwPdu+KHfqlbYEaJ+aTHCaeqodO9tkMuRHf9xOkYKG6s8evD7js UbH3M4WOEh8wM0lfWIQjnq+CGgZNoBGnTIzgtEx/O2pO0LcdtxmTic2rvsLzpO7+MZ tRih2Alw/HRTQ== Date: Wed, 31 Jan 2024 15:29:38 -0600 From: Rob Herring To: Dawei Li Cc: frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, set_pte_at@outlook.com Subject: Re: [PATCH 1/2] of: Introduce __of_phandle_update_cache Message-ID: <20240131212938.GB2303754-robh@kernel.org> References: <20240130105236.3097126-1-dawei.li@shingroup.cn> <20240130105236.3097126-2-dawei.li@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240130105236.3097126-2-dawei.li@shingroup.cn> 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 > --- > 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