Received: by 10.223.176.46 with SMTP id f43csp2569532wra; Thu, 25 Jan 2018 11:55:45 -0800 (PST) X-Google-Smtp-Source: AH8x227vGa1zo80D9DRmpj07Eu/mB/ZvIVxsRXsXXIZE9Nj+XgYqDrpK1Q7u7fTH7/CGU366uhpg X-Received: by 10.98.137.75 with SMTP id v72mr17171541pfd.189.1516910145639; Thu, 25 Jan 2018 11:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516910145; cv=none; d=google.com; s=arc-20160816; b=lHbj/jey2P6EDlu7riWcDkdqRBfMvJ5++L7ycFmAhI80ws2eSlXdexJTOTYRbthMIG Xn/02YPTqjDbZSkynjIMMmbpd4jjgBRZabmtKod+uULBHoKozsVf8sb9y9Wa1e0IDv7d nuXFVrupcbobRRk45gRiZRLaYIIKpX+x++YI/k2QZ4W0DBjD7hJpRoZ9/yVyz2XAhZCX SfzLL1jPpIiG2lnbCAwskbewYfBAfNQQx8FntGmLW6ll1Ab7KcbwLbtu5vYHcyscQ548 FL1Og68beYAKMVXfUX22h96ID2fzuCNBpZ1/DiXfKD/8KT5V9fb3FneeUeUAxdZ0A8L/ XA6w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=JnmFYCkiIdM4kOGvUUUbP+zjmEMNx5pYpVWUAIvK93I=; b=j+SgNUnGgsUvBTMDAmKUtdYenDcxen+YGFrkIgqA9NZa2bpKltnTjgR0t7brHfVHaI wOoaM0exuZT28ujFiEkr12hJq37+6gbWvsjo4PCFgQNVNTXVNa/XzzdkzANT1hgMqUcx KChRy3JbYrscho+vI2O6wXcEa+4/lFooQcgp4NBnrjnaN/EmjBUv2D8b/GjCyBm/9gAE DfMkAy/D7eysvLzzyX4b/W+PP5ZhQQ96xoRifi971iVUdj7Yp3hgcNgnFPda4+7QfX2Z +QRkmtPG2HJxwgiHtEkC2/kRj1ndIR6uGFkvypI8MxpwDJtKS3GlTQam6Ozu5eUo4GXV XFsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hTxWd5Re; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e192si1946490pgc.547.2018.01.25.11.55.30; Thu, 25 Jan 2018 11:55:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hTxWd5Re; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751345AbeAYTyu (ORCPT + 99 others); Thu, 25 Jan 2018 14:54:50 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34470 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191AbeAYTys (ORCPT ); Thu, 25 Jan 2018 14:54:48 -0500 Received: by mail-pg0-f68.google.com with SMTP id r19so5733323pgn.1; Thu, 25 Jan 2018 11:54:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=JnmFYCkiIdM4kOGvUUUbP+zjmEMNx5pYpVWUAIvK93I=; b=hTxWd5ReiqWXrSM05E1BEFzRnBW2KZP4VQSE7+0jSJhIB4Ah0X/nWh14xtNd10jZtd 6yUjct3xrQSWigUt3RHC3UYVVjFYvxMkztIzBI0WAV/54SWkTqX5x/5THh0/tyCWz2Kp obckxG53wmQQTfgekmKFsqkVpbpmPT4b1qNS/OrrcgDb5SUhIRhzqa9ttFD4vTmVMZlR iPwMJLz/o5vMB16iHs/UZnyUHGk3Ria6ZKHzvvCgZrbhEVT6i0/nnATqK5H4wu9BDUiF Qx+w+z2+iGfv9DOK+dzWOaj/RqgPKPwCW6qMAUdMDVZ/NkH371xLwh+4aZrQykiHUFf7 6E9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JnmFYCkiIdM4kOGvUUUbP+zjmEMNx5pYpVWUAIvK93I=; b=ugeym5NNi7pywbYj/GpiyTEugP4VyhzxNyJhw5Ve2WoaxkjZjAPbYWaBNyV9UIlsQA bQZWW4oau9hkipu959FJk+2n3uwgGtXLF82ebXgv/aEjKMqGFGXR1FuTRmQEbWWjp0E8 p1Vb3suqdHZzbuUctlPCoozu/vmVCYSKczJuTRt25DHyOhAoCt+NZndHcoQD27yjNOI1 iozpj93sDk2ugBCdDH4Omc6B5QachuW4HwFssKDhNgM3SrCIJoalPciMTa99BXq3wPi1 IauMCBfs/1pLxbnVp7WvL+kYdS3saF2tPMJwe51nRllaG2lxzQ52Xsugo+Xws1G1OigL J4/A== X-Gm-Message-State: AKwxytepMHijh/cf/tPN3UkDWGOJwqdWqjC5B/+Y/3sVh0Au9tCCqJo5 tmhpbYNzzn2B7N543QEqEgy9ukX1 X-Received: by 10.101.96.44 with SMTP id p12mr13542173pgu.390.1516910088080; Thu, 25 Jan 2018 11:54:48 -0800 (PST) Received: from [192.168.1.70] (c-73-93-215-6.hsd1.ca.comcast.net. [73.93.215.6]) by smtp.gmail.com with ESMTPSA id j1sm13288941pff.94.2018.01.25.11.54.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 11:54:47 -0800 (PST) Subject: Re: [PATCH] of: use hash based search in of_find_node_by_phandle To: Chintan Pandya , robh+dt@kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org References: <1516875247-19599-1-git-send-email-cpandya@codeaurora.org> From: Frank Rowand Message-ID: <5a7793df-725e-608d-778b-cb81fde0cc64@gmail.com> Date: Thu, 25 Jan 2018 11:54:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1516875247-19599-1-git-send-email-cpandya@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/25/18 02:14, Chintan Pandya wrote: > of_find_node_by_phandle() takes a lot of time finding > right node when your intended device is too right-side > in the fdt. Reason is, we search each device serially > from the fdt, starting from left-most to right-most. Please give me a pointer to the code that is doing this search. -Frank > > Implement, device-phandle relation in hash-table so > that look up can be faster. > > Change-Id: I4a2bc7eff6de142e4f91a7bf474893a45e61c128 > Signed-off-by: Chintan Pandya > --- > drivers/of/base.c | 9 +++++++-- > drivers/of/fdt.c | 18 ++++++++++++++++++ > include/linux/of.h | 6 ++++++ > 3 files changed, 31 insertions(+), 2 deletions(-) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index a0bccb5..3e06316 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1099,10 +1100,14 @@ struct device_node *of_find_node_by_phandle(phandle handle) > if (!handle) > return NULL; > > - raw_spin_lock_irqsave(&devtree_lock, flags); > - for_each_of_allnodes(np) > + spin_lock(&dt_hash_spinlock); > + hash_for_each_possible(dt_hash_table, np, hash, handle) > if (np->phandle == handle) > break; > + > + spin_unlock(&dt_hash_spinlock); > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > of_node_get(np); > raw_spin_unlock_irqrestore(&devtree_lock, flags); > return np; > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index c0914fb..f0e78a7 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -31,6 +31,10 @@ > #include /* for COMMAND_LINE_SIZE */ > #include > > +static bool dt_hash_needs_init = true; > +DECLARE_HASHTABLE(dt_hash_table, DT_HASH_BITS); > +DEFINE_SPINLOCK(dt_hash_spinlock); > + > /* > * of_fdt_limit_memory - limit the number of regions in the /memory node > * @limit: maximum entries > @@ -227,6 +231,20 @@ static void populate_properties(const void *blob, > pprev = &pp->next; > } > > + /* > + * In 'dryrun = true' cases, np is some non-NULL junk. So, protect > + * against those cases. > + */ > + if (!dryrun && np->phandle) { > + spin_lock(&dt_hash_spinlock); > + if (dt_hash_needs_init) { > + dt_hash_needs_init = false; > + hash_init(dt_hash_table); > + } > + hash_add(dt_hash_table, &np->hash, np->phandle); > + spin_unlock(&dt_hash_spinlock); > + } > + > /* With version 0x10 we may not have the name property, > * recreate it here from the unit name if absent > */ > diff --git a/include/linux/of.h b/include/linux/of.h > index 299aeb1..5b3f4f1 100644 > --- a/include/linux/of.h > +++ b/include/linux/of.h > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -61,6 +62,7 @@ struct device_node { > struct kobject kobj; > unsigned long _flags; > void *data; > + struct hlist_node hash; > #if defined(CONFIG_SPARC) > const char *path_component_name; > unsigned int unique_id; > @@ -68,6 +70,10 @@ struct device_node { > #endif > }; > > +#define DT_HASH_BITS 6 > +extern DECLARE_HASHTABLE(dt_hash_table, DT_HASH_BITS); > +extern spinlock_t dt_hash_spinlock; > + > #define MAX_PHANDLE_ARGS 16 > struct of_phandle_args { > struct device_node *np; >