[patch 12/28] fib_trie: cleanup

2007-08-10 Thread akpm
From: Stephen Hemminger [EMAIL PROTECTED]

Try this out:
 * replace macro's with inlines
 * get rid of places doing multiple evaluations of NODE_PARENT

[EMAIL PROTECTED]: rcu_dereference wants an lval]
Cc: David S. Miller [EMAIL PROTECTED]
Cc: Paul E. McKenney [EMAIL PROTECTED]
Signed-off-by: Andrew Morton [EMAIL PROTECTED]
---

 net/ipv4/fib_trie.c |   68 ++
 1 files changed, 36 insertions(+), 32 deletions(-)

diff -puN net/ipv4/fib_trie.c~fib_trie-cleanup net/ipv4/fib_trie.c
--- a/net/ipv4/fib_trie.c~fib_trie-cleanup
+++ a/net/ipv4/fib_trie.c
@@ -93,15 +93,8 @@ typedef unsigned int t_key;
 #define T_TNODE 0
 #define T_LEAF  1
 #define NODE_TYPE_MASK 0x1UL
-#define NODE_PARENT(node) \
-   ((struct tnode *)rcu_dereference(((node)-parent  ~NODE_TYPE_MASK)))
-
 #define NODE_TYPE(node) ((node)-parent  NODE_TYPE_MASK)
 
-#define NODE_SET_PARENT(node, ptr) \
-   rcu_assign_pointer((node)-parent,  \
-  ((unsigned long)(ptr)) | NODE_TYPE(node))
-
 #define IS_TNODE(n) (!(n-parent  T_LEAF))
 #define IS_LEAF(n) (n-parent  T_LEAF)
 
@@ -174,6 +167,19 @@ static void tnode_free(struct tnode *tn)
 static struct kmem_cache *fn_alias_kmem __read_mostly;
 static struct trie *trie_local = NULL, *trie_main = NULL;
 
+static inline struct tnode *node_parent(struct node *node)
+{
+   struct tnode *ret;
+
+   ret = (struct tnode *)(node-parent  ~NODE_TYPE_MASK);
+   return rcu_dereference(ret);
+}
+
+static inline void node_set_parent(struct node *node, struct tnode *ptr)
+{
+   rcu_assign_pointer(node-parent,
+  (unsigned long)ptr | NODE_TYPE(node));
+}
 
 /* rcu_read_lock needs to be hold by caller from readside */
 
@@ -446,7 +452,7 @@ static void tnode_put_child_reorg(struct
tn-full_children++;
 
if (n)
-   NODE_SET_PARENT(n, tn);
+   node_set_parent(n, tn);
 
rcu_assign_pointer(tn-child[i], n);
 }
@@ -481,7 +487,7 @@ static struct node *resize(struct trie *
continue;
 
/* compress one level */
-   NODE_SET_PARENT(n, NULL);
+   node_set_parent(n, NULL);
tnode_free(tn);
return n;
}
@@ -636,7 +642,7 @@ static struct node *resize(struct trie *
 
/* compress one level */
 
-   NODE_SET_PARENT(n, NULL);
+   node_set_parent(n, NULL);
tnode_free(tn);
return n;
}
@@ -961,24 +967,21 @@ fib_find_node(struct trie *t, u32 key)
 static struct node *trie_rebalance(struct trie *t, struct tnode *tn)
 {
int wasfull;
-   t_key cindex, key;
-   struct tnode *tp = NULL;
-
-   key = tn-key;
+   t_key cindex, key = tn-key;
+   struct tnode *tp;
 
-   while (tn != NULL  NODE_PARENT(tn) != NULL) {
-
-   tp = NODE_PARENT(tn);
+   while (tn != NULL  (tp = node_parent((struct node *)tn)) != NULL) {
cindex = tkey_extract_bits(key, tp-pos, tp-bits);
wasfull = tnode_full(tp, tnode_get_child(tp, cindex));
tn = (struct tnode *) resize (t, (struct tnode *)tn);
tnode_put_child_reorg((struct tnode *)tp, cindex,(struct 
node*)tn, wasfull);
 
-   if (!NODE_PARENT(tn))
+   tp = node_parent((struct node *) tn);
+   if (!tp)
break;
-
-   tn = NODE_PARENT(tn);
+   tn = tp;
}
+
/* Handle last (top) tnode */
if (IS_TNODE(tn))
tn = (struct tnode*) resize(t, (struct tnode *)tn);
@@ -1031,7 +1034,7 @@ fib_insert_node(struct trie *t, int *err
pos = tn-pos + tn-bits;
n = tnode_get_child(tn, tkey_extract_bits(key, tn-pos, 
tn-bits));
 
-   BUG_ON(n  NODE_PARENT(n) != tn);
+   BUG_ON(n  node_parent(n) != tn);
} else
break;
}
@@ -1083,7 +1086,7 @@ fib_insert_node(struct trie *t, int *err
if (t-trie  n == NULL) {
/* Case 2: n is NULL, and will just insert a new leaf */
 
-   NODE_SET_PARENT(l, tp);
+   node_set_parent((struct node *)l, tp);
 
cindex = tkey_extract_bits(key, tp-pos, tp-bits);
put_child(t, (struct tnode *)tp, cindex, (struct node *)l);
@@ -1114,7 +1117,7 @@ fib_insert_node(struct trie *t, int *err
goto err;
}
 
-   NODE_SET_PARENT(tn, tp);
+   node_set_parent((struct node *)tn, tp);
 
missbit = tkey_extract_bits(key, newpos, 1);
put_child(t, tn, missbit, (struct node *)l);
@@ -1495,12 +1498,13 @@ backtrace:
if (chopped_off = pn-bits) 

Re: [patch 12/28] fib_trie: cleanup

2007-08-10 Thread David Miller
From: [EMAIL PROTECTED]
Date: Fri, 10 Aug 2007 14:11:56 -0700

 From: Stephen Hemminger [EMAIL PROTECTED]
 
 Try this out:
  * replace macro's with inlines
  * get rid of places doing multiple evaluations of NODE_PARENT
 
 [EMAIL PROTECTED]: rcu_dereference wants an lval]
 Cc: David S. Miller [EMAIL PROTECTED]
 Cc: Paul E. McKenney [EMAIL PROTECTED]
 Signed-off-by: Andrew Morton [EMAIL PROTECTED]

Applied to net-2.6.24, thanks!
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html