From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
To: Rob Herring <robherring2@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>,
Matt Porter <mporter@konsulko.com>,
Grant Likely <grant.likely@secretlab.ca>,
Koen Kooi <koen@dominion.thruhere.net>,
Guenter Roeck <linux@roeck-us.net>, Marek Vasut <marex@denx.de>,
Geert Uytterhoeven <geert@linux-m68k.org>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
Pantelis Antoniou <panto@antoniou-consulting.com>
Subject: [PATCH 2/3] of: Support hashtable lookups for phandles
Date: Mon, 9 May 2016 21:11:27 +0300 [thread overview]
Message-ID: <1462817488-8370-3-git-send-email-pantelis.antoniou@konsulko.com> (raw)
In-Reply-To: <1462817488-8370-1-git-send-email-pantelis.antoniou@konsulko.com>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
---
drivers/of/base.c | 35 ++++++++++++++++++++++++++++++++---
drivers/of/dynamic.c | 8 ++++++++
drivers/of/of_private.h | 31 +++++++++++++++++++++++++++++++
include/linux/of.h | 2 ++
4 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 20bbc2f..770cb95 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -27,6 +27,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/proc_fs.h>
+#include <linux/rhashtable.h>
#include "of_private.h"
@@ -41,6 +42,16 @@ static const char *of_stdout_options;
struct kset *of_kset;
+const struct rhashtable_params of_phandle_ht_params = {
+ .key_offset = offsetof(struct device_node, phandle), /* base offset */
+ .key_len = sizeof(phandle),
+ .head_offset = offsetof(struct device_node, ht_node),
+ .automatic_shrinking = true,
+};
+
+struct rhashtable of_phandle_ht;
+bool of_phandle_ht_initialized;
+
/*
* Used to protect the of_aliases, to hold off addition of nodes to sysfs.
* This mutex must be held whenever modifications are being made to the
@@ -162,6 +173,12 @@ int __of_attach_node_post(struct device_node *np)
struct property *pp;
int rc;
+ if (of_phandle_ht_available()) {
+ rc = of_phandle_ht_insert(np);
+ WARN(rc, "insert to phandle hash fail @%s\n",
+ of_node_full_name(np));
+ }
+
if (!IS_ENABLED(CONFIG_SYSFS))
return 0;
@@ -194,6 +211,13 @@ void __init of_core_init(void)
struct device_node *np;
int ret;
+ ret = rhashtable_init(&of_phandle_ht, &of_phandle_ht_params);
+ if (ret) {
+ pr_warn("devicetree: Failed to initialize hashtable\n");
+ return;
+ }
+ of_phandle_ht_initialized = 1;
+
/* Create the kset, and register existing nodes */
mutex_lock(&of_mutex);
of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj);
@@ -1073,9 +1097,14 @@ struct device_node *of_find_node_by_phandle(phandle handle)
return NULL;
raw_spin_lock_irqsave(&devtree_lock, flags);
- for_each_of_allnodes(np)
- if (np->phandle == handle)
- break;
+ /* when we're ready use the hash table */
+ if (of_phandle_ht_available() && !in_interrupt())
+ np = of_phandle_ht_lookup(handle);
+ else { /* fallback */
+ for_each_of_allnodes(np)
+ if (np->phandle == handle)
+ break;
+ }
of_node_get(np);
raw_spin_unlock_irqrestore(&devtree_lock, flags);
return np;
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index eb31a55..bdebdf5 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -11,6 +11,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/proc_fs.h>
+#include <linux/rhashtable.h>
#include "of_private.h"
@@ -44,6 +45,13 @@ EXPORT_SYMBOL(of_node_put);
void __of_detach_node_post(struct device_node *np)
{
struct property *pp;
+ int rc;
+
+ if (of_phandle_ht_available()) {
+ rc = of_phandle_ht_remove(np);
+ WARN(rc, "remove from phandle hash fail @%s\n",
+ of_node_full_name(np));
+ }
if (!IS_ENABLED(CONFIG_SYSFS))
return;
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index 10b0342..88b3b8f 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -101,4 +101,35 @@ static inline int of_overlay_init(void)
}
#endif
+extern const struct rhashtable_params of_phandle_ht_params;
+extern struct rhashtable of_phandle_ht;
+extern bool of_phandle_ht_initialized;
+
+static inline bool of_phandle_ht_available(void)
+{
+ return of_phandle_ht_initialized;
+}
+
+static inline int of_phandle_ht_insert(struct device_node *np)
+{
+ if (!np || !np->phandle)
+ return 0;
+ return rhashtable_insert_fast(&of_phandle_ht,
+ &np->ht_node, of_phandle_ht_params);
+}
+
+static inline int of_phandle_ht_remove(struct device_node *np)
+{
+ if (!np || !np->phandle)
+ return 0;
+ return rhashtable_remove_fast(&of_phandle_ht,
+ &np->ht_node, of_phandle_ht_params);
+}
+
+static inline struct device_node *of_phandle_ht_lookup(phandle handle)
+{
+ return rhashtable_lookup_fast(&of_phandle_ht,
+ &handle, of_phandle_ht_params);
+}
+
#endif /* _LINUX_OF_PRIVATE_H */
diff --git a/include/linux/of.h b/include/linux/of.h
index 582bc45..56bb62d 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -25,6 +25,7 @@
#include <linux/notifier.h>
#include <linux/property.h>
#include <linux/list.h>
+#include <linux/rhashtable.h>
#include <asm/byteorder.h>
#include <asm/errno.h>
@@ -52,6 +53,7 @@ struct device_node {
phandle phandle;
const char *full_name;
struct fwnode_handle fwnode;
+ struct rhash_head ht_node;
struct property *properties;
struct property *deadprops; /* removed properties */
--
1.7.12
next prev parent reply other threads:[~2016-05-09 18:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-09 18:11 [PATCH 0/3] of: generic infrastructure fixes Pantelis Antoniou
2016-05-09 18:11 ` [PATCH 1/3] of: rename *_node_sysfs to _node_post Pantelis Antoniou
2016-05-09 21:49 ` Rob Herring
2016-05-10 13:57 ` Pantelis Antoniou
2016-05-09 18:11 ` Pantelis Antoniou [this message]
2016-05-09 20:38 ` [PATCH 2/3] of: Support hashtable lookups for phandles Geert Uytterhoeven
2016-05-09 21:11 ` Rob Herring
2016-05-10 13:45 ` Pantelis Antoniou
2016-05-10 14:26 ` Rob Herring
2016-05-09 21:21 ` Rob Herring
2016-05-10 13:52 ` Pantelis Antoniou
2016-05-09 18:11 ` [PATCH 3/3] of: overlay: Pick up label symbols from overlays Pantelis Antoniou
2016-05-09 20:32 ` Marek Vasut
2016-05-09 21:47 ` Rob Herring
2016-05-10 13:56 ` Pantelis Antoniou
2016-05-10 14:23 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462817488-8370-3-git-send-email-pantelis.antoniou@konsulko.com \
--to=pantelis.antoniou@konsulko.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=geert@linux-m68k.org \
--cc=grant.likely@secretlab.ca \
--cc=koen@dominion.thruhere.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=marex@denx.de \
--cc=mporter@konsulko.com \
--cc=panto@antoniou-consulting.com \
--cc=robherring2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®