Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137487145
D50750.id156704.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
8 KB
Referenced Files
None
Subscribers
None
D50750.id156704.diff
View Options
Index: sys/kern/subr_pctrie.c
===================================================================
--- sys/kern/subr_pctrie.c
+++ sys/kern/subr_pctrie.c
@@ -170,7 +170,7 @@
static __inline smr_pctnode_t *
pctrie_child(struct pctrie *ptree, struct pctrie_node *node, uint64_t index)
{
- return (node == NULL ? pctrie_root(ptree) :
+ return (node == PCTRIE_NULL ? pctrie_root(ptree) :
&node->pn_child[pctrie_slot(node, index)]);
}
@@ -290,11 +290,11 @@
* will never be used.
*/
node = pctrie_root_load(ptree, NULL, PCTRIE_LOCKED);
- parent = NULL;
+ parent = PCTRIE_NULL;
for (;;) {
if (pctrie_isleaf(node)) {
if (node == PCTRIE_NULL) {
- if (parent == NULL)
+ if (parent == PCTRIE_NULL)
pctrie_node_store(pctrie_root(ptree),
pctrie_toleaf(val), PCTRIE_LOCKED);
else
@@ -323,7 +323,8 @@
* now, and will point to to the new branching node later.
*/
*parent_out = parent;
- return ((parent == NULL) ? pctrie_root(ptree): &parent->pn_child[slot]);
+ return ((parent == PCTRIE_NULL) ? pctrie_root(ptree):
+ &parent->pn_child[slot]);
}
/*
@@ -489,29 +490,28 @@
struct pctrie_node *parent;
int slot;
+ parent = node;
+ if (pctrie_isleaf(parent))
+ node = pctrie_root_load(ptree, smr, access);
+
/*
* Climb the search path to find the lowest node from which to start the
* search for a value matching 'index'.
*/
- while (node != NULL) {
- KASSERT(access == PCTRIE_SMR || !powerof2(node->pn_popmap),
+ while (!pctrie_isleaf(parent)) {
+ KASSERT(access == PCTRIE_SMR || !powerof2(parent->pn_popmap),
("%s: freed node in iter path", __func__));
+ node = parent;
if (!pctrie_keybarr(node, index, &slot))
break;
- node = pctrie_parent(node);
- }
-
- if (node == NULL) {
- parent = NULL;
- node = pctrie_root_load(ptree, smr, access);
- } else {
- parent = node;
- node = pctrie_node_load(&node->pn_child[slot], smr, access);
+ parent = pctrie_parent(node);
}
/* Seek a node that matches index. */
while (!pctrie_isleaf(node) && !pctrie_keybarr(node, index, &slot)) {
parent = node;
+ KASSERT(access == PCTRIE_SMR || !powerof2(parent->pn_popmap),
+ ("%s: freed node in iter path", __func__));
node = pctrie_node_load(&node->pn_child[slot], smr, access);
}
*parent_out = parent;
@@ -547,7 +547,7 @@
node = _pctrie_lookup_node(it->ptree, it->node, *val, &it->node,
NULL, PCTRIE_LOCKED);
if (node == PCTRIE_NULL) {
- if (it->node == NULL)
+ if (it->node == PCTRIE_NULL)
pctrie_node_store(pctrie_root(it->ptree),
pctrie_toleaf(val), PCTRIE_LOCKED);
else
@@ -627,7 +627,7 @@
break;
value[i++] = val;
base = (index + i) % PCTRIE_COUNT;
- if (base == 0 || parent == NULL || parent->pn_clev != 0)
+ if (base == 0 || parent == PCTRIE_NULL || parent->pn_clev != 0)
continue;
/*
@@ -682,8 +682,8 @@
pctrie_lookup_range(struct pctrie *ptree, uint64_t index,
uint64_t *value[], int count)
{
- return (_pctrie_lookup_range(ptree, NULL, index, value, count, NULL,
- NULL, PCTRIE_LOCKED));
+ return (_pctrie_lookup_range(ptree, PCTRIE_NULL, index, value, count,
+ NULL, NULL, PCTRIE_LOCKED));
}
/*
@@ -700,8 +700,8 @@
int res;
smr_enter(smr);
- res = _pctrie_lookup_range(ptree, NULL, index, value, count, NULL,
- smr, PCTRIE_SMR);
+ res = _pctrie_lookup_range(ptree, PCTRIE_NULL, index, value, count,
+ NULL, smr, PCTRIE_SMR);
smr_exit(smr);
return (res);
}
@@ -741,14 +741,15 @@
*/
if (node == PCTRIE_NULL || *pctrie_toval(node) < index) {
/* Climb the path to find a node with a descendant > index. */
- for (node = parent; node != NULL; node = pctrie_parent(node)) {
+ for (node = parent; node != PCTRIE_NULL;
+ node = pctrie_parent(node)) {
slot = pctrie_slot(node, index) + 1;
if ((node->pn_popmap >> slot) != 0)
break;
}
- if (node == NULL) {
+ if (node == PCTRIE_NULL) {
if (parent_out != NULL)
- *parent_out = NULL;
+ *parent_out = PCTRIE_NULL;
return (NULL);
}
@@ -778,7 +779,7 @@
uint64_t *
pctrie_lookup_ge(struct pctrie *ptree, uint64_t index)
{
- return (_pctrie_lookup_ge(ptree, NULL, index, NULL, 0));
+ return (_pctrie_lookup_ge(ptree, PCTRIE_NULL, index, NULL, 0));
}
/*
@@ -835,14 +836,15 @@
*/
if (node == PCTRIE_NULL || *pctrie_toval(node) > index) {
/* Climb the path to find a node with a descendant < index. */
- for (node = parent; node != NULL; node = pctrie_parent(node)) {
+ for (node = parent; node != PCTRIE_NULL;
+ node = pctrie_parent(node)) {
slot = pctrie_slot(node, index);
if ((node->pn_popmap & ((1 << slot) - 1)) != 0)
break;
}
- if (node == NULL) {
+ if (node == PCTRIE_NULL) {
if (parent_out != NULL)
- *parent_out = NULL;
+ *parent_out = PCTRIE_NULL;
return (NULL);
}
@@ -873,7 +875,7 @@
uint64_t *
pctrie_lookup_le(struct pctrie *ptree, uint64_t index)
{
- return (_pctrie_lookup_le(ptree, NULL, index, NULL, 0));
+ return (_pctrie_lookup_le(ptree, PCTRIE_NULL, index, NULL, 0));
}
uint64_t *
@@ -932,7 +934,7 @@
*freenode = NULL;
parentp = pctrie_child(ptree, node, index);
- if (node == NULL) {
+ if (node == PCTRIE_NULL) {
pctrie_node_store(parentp, PCTRIE_NULL, PCTRIE_LOCKED);
return;
}
@@ -971,7 +973,7 @@
uint64_t *m;
int slot;
- node = NULL;
+ node = PCTRIE_NULL;
child = pctrie_root_load(ptree, NULL, PCTRIE_LOCKED);
while (!pctrie_isleaf(child)) {
node = child;
@@ -1056,7 +1058,7 @@
pctrie_reclaim_resume_compound(struct pctrie_node **pnode,
pctrie_cb_t callback, int keyoff, void *arg)
{
- if (*pnode == NULL)
+ if (*pnode == PCTRIE_NULL)
return (NULL);
/* Climb one level up the trie. */
return (pctrie_reclaim_prune(pnode, pctrie_parent(*pnode), callback,
@@ -1081,7 +1083,8 @@
return (NULL);
}
*pnode = node;
- return (pctrie_reclaim_prune(pnode, NULL, callback, keyoff, arg));
+ return (pctrie_reclaim_prune(pnode, PCTRIE_NULL, callback, keyoff,
+ arg));
}
struct pctrie_node *
@@ -1126,11 +1129,11 @@
leaf = pctrie_toleaf(newval);
index = *newval;
node = pctrie_root_load(ptree, NULL, PCTRIE_LOCKED);
- parent = NULL;
+ parent = PCTRIE_NULL;
for (;;) {
if (pctrie_isleaf(node)) {
if ((m = pctrie_toval(node)) != NULL && *m == index) {
- if (parent == NULL)
+ if (parent == PCTRIE_NULL)
pctrie_node_store(pctrie_root(ptree),
leaf, PCTRIE_LOCKED);
else
Index: sys/sys/pctrie.h
===================================================================
--- sys/sys/pctrie.h
+++ sys/sys/pctrie.h
@@ -34,41 +34,6 @@
#include <sys/_pctrie.h>
#include <sys/_smr.h>
-struct pctrie_iter {
- struct pctrie *ptree;
- struct pctrie_node *node;
- uint64_t index;
- uint64_t limit;
-};
-
-static __inline void
-pctrie_iter_reset(struct pctrie_iter *it)
-{
- it->node = NULL;
-}
-
-static __inline bool
-pctrie_iter_is_reset(struct pctrie_iter *it)
-{
- return (it->node == NULL);
-}
-
-static __inline void
-pctrie_iter_init(struct pctrie_iter *it, struct pctrie *ptree)
-{
- it->ptree = ptree;
- it->node = NULL;
- it->limit = 0;
-}
-
-static __inline void
-pctrie_iter_limit_init(struct pctrie_iter *it, struct pctrie *ptree,
- uint64_t limit)
-{
- pctrie_iter_init(it, ptree);
- it->limit = limit;
-}
-
#ifdef _KERNEL
typedef void (*pctrie_cb_t)(void *ptr, void *arg);
@@ -464,6 +429,41 @@
return (ptree->pt_root == PCTRIE_NULL);
}
+struct pctrie_iter {
+ struct pctrie *ptree;
+ struct pctrie_node *node;
+ uint64_t index;
+ uint64_t limit;
+};
+
+static __inline void
+pctrie_iter_reset(struct pctrie_iter *it)
+{
+ it->node = PCTRIE_NULL;
+}
+
+static __inline bool
+pctrie_iter_is_reset(struct pctrie_iter *it)
+{
+ return (it->node == PCTRIE_NULL);
+}
+
+static __inline void
+pctrie_iter_init(struct pctrie_iter *it, struct pctrie *ptree)
+{
+ it->ptree = ptree;
+ pctrie_iter_reset(it);
+ it->limit = 0;
+}
+
+static __inline void
+pctrie_iter_limit_init(struct pctrie_iter *it, struct pctrie *ptree,
+ uint64_t limit)
+{
+ pctrie_iter_init(it, ptree);
+ it->limit = limit;
+}
+
/* Set of all flag bits stored in node pointers. */
#define PCTRIE_FLAGS (PCTRIE_ISLEAF)
/* Minimum align parameter for uma_zcreate. */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 24, 10:14 PM (11 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26077399
Default Alt Text
D50750.id156704.diff (8 KB)
Attached To
Mode
D50750: pctrie: simplify lookup_node
Attached
Detach File
Event Timeline
Log In to Comment