@@ -92,8 +92,6 @@ typedef unsigned int t_key;
92
92
#define IS_TNODE (n ) ((n)->bits)
93
93
#define IS_LEAF (n ) (!(n)->bits)
94
94
95
- #define get_index (_key , _kv ) (((_key) ^ (_kv)->key) >> (_kv)->pos)
96
-
97
95
struct key_vector {
98
96
struct rcu_head rcu ;
99
97
@@ -177,11 +175,18 @@ static inline void node_set_parent(struct key_vector *n, struct key_vector *tp)
177
175
/* This provides us with the number of children in this node, in the case of a
178
176
* leaf this will return 0 meaning none of the children are accessible.
179
177
*/
180
- static inline unsigned long tnode_child_length (const struct key_vector * tn )
178
+ static inline unsigned long child_length (const struct key_vector * tn )
181
179
{
182
180
return (1ul << tn -> bits ) & ~(1ul );
183
181
}
184
182
183
+ static inline unsigned long get_index (t_key key , struct key_vector * kv )
184
+ {
185
+ unsigned long index = key ^ kv -> key ;
186
+
187
+ return index >> kv -> pos ;
188
+ }
189
+
185
190
static inline struct fib_table * trie_get_table (struct trie * t )
186
191
{
187
192
unsigned long * tb_data = (unsigned long * )t ;
@@ -374,7 +379,7 @@ static void put_child(struct key_vector *tn, unsigned long i,
374
379
struct key_vector * chi = get_child (tn , i );
375
380
int isfull , wasfull ;
376
381
377
- BUG_ON (i >= tnode_child_length (tn ));
382
+ BUG_ON (i >= child_length (tn ));
378
383
379
384
/* update emptyChildren, overflow into fullChildren */
380
385
if (n == NULL && chi != NULL )
@@ -402,7 +407,7 @@ static void update_children(struct key_vector *tn)
402
407
unsigned long i ;
403
408
404
409
/* update all of the child parent pointers */
405
- for (i = tnode_child_length (tn ); i ;) {
410
+ for (i = child_length (tn ); i ;) {
406
411
struct key_vector * inode = get_child (tn , -- i );
407
412
408
413
if (!inode )
@@ -480,7 +485,7 @@ static struct key_vector __rcu **replace(struct trie *t,
480
485
cptr = tp ? tp -> tnode : t -> tnode ;
481
486
482
487
/* resize children now that oldtnode is freed */
483
- for (i = tnode_child_length (tn ); i ;) {
488
+ for (i = child_length (tn ); i ;) {
484
489
struct key_vector * inode = get_child (tn , -- i );
485
490
486
491
/* resize child node */
@@ -512,7 +517,7 @@ static struct key_vector __rcu **inflate(struct trie *t,
512
517
* point to existing tnodes and the links between our allocated
513
518
* nodes.
514
519
*/
515
- for (i = tnode_child_length (oldtnode ), m = 1u << tn -> pos ; i ;) {
520
+ for (i = child_length (oldtnode ), m = 1u << tn -> pos ; i ;) {
516
521
struct key_vector * inode = get_child (oldtnode , -- i );
517
522
struct key_vector * node0 , * node1 ;
518
523
unsigned long j , k ;
@@ -562,7 +567,7 @@ static struct key_vector __rcu **inflate(struct trie *t,
562
567
tnode_free_append (tn , node0 );
563
568
564
569
/* populate child pointers in new nodes */
565
- for (k = tnode_child_length (inode ), j = k / 2 ; j ;) {
570
+ for (k = child_length (inode ), j = k / 2 ; j ;) {
566
571
put_child (node1 , -- j , get_child (inode , -- k ));
567
572
put_child (node0 , j , get_child (inode , j ));
568
573
put_child (node1 , -- j , get_child (inode , -- k ));
@@ -607,7 +612,7 @@ static struct key_vector __rcu **halve(struct trie *t,
607
612
* point to existing tnodes and the links between our allocated
608
613
* nodes.
609
614
*/
610
- for (i = tnode_child_length (oldtnode ); i ;) {
615
+ for (i = child_length (oldtnode ); i ;) {
611
616
struct key_vector * node1 = get_child (oldtnode , -- i );
612
617
struct key_vector * node0 = get_child (oldtnode , -- i );
613
618
struct key_vector * inode ;
@@ -648,7 +653,7 @@ static void collapse(struct trie *t, struct key_vector *oldtnode)
648
653
unsigned long i ;
649
654
650
655
/* scan the tnode looking for that one child that might still exist */
651
- for (n = NULL , i = tnode_child_length (oldtnode ); !n && i ;)
656
+ for (n = NULL , i = child_length (oldtnode ); !n && i ;)
652
657
n = get_child (oldtnode , -- i );
653
658
654
659
/* compress one level */
@@ -670,7 +675,7 @@ static unsigned char update_suffix(struct key_vector *tn)
670
675
* why we start with a stride of 2 since a stride of 1 would
671
676
* represent the nodes with suffix length equal to tn->pos
672
677
*/
673
- for (i = 0 , stride = 0x2ul ; i < tnode_child_length (tn ); i += stride ) {
678
+ for (i = 0 , stride = 0x2ul ; i < child_length (tn ); i += stride ) {
674
679
struct key_vector * n = get_child (tn , i );
675
680
676
681
if (!n || (n -> slen <= slen ))
@@ -703,12 +708,12 @@ static unsigned char update_suffix(struct key_vector *tn)
703
708
*
704
709
* 'high' in this instance is the variable 'inflate_threshold'. It
705
710
* is expressed as a percentage, so we multiply it with
706
- * tnode_child_length () and instead of multiplying by 2 (since the
711
+ * child_length () and instead of multiplying by 2 (since the
707
712
* child array will be doubled by inflate()) and multiplying
708
713
* the left-hand side by 100 (to handle the percentage thing) we
709
714
* multiply the left-hand side by 50.
710
715
*
711
- * The left-hand side may look a bit weird: tnode_child_length (tn)
716
+ * The left-hand side may look a bit weird: child_length (tn)
712
717
* - tn->empty_children is of course the number of non-null children
713
718
* in the current node. tn->full_children is the number of "full"
714
719
* children, that is non-null tnodes with a skip value of 0.
@@ -718,10 +723,10 @@ static unsigned char update_suffix(struct key_vector *tn)
718
723
* A clearer way to write this would be:
719
724
*
720
725
* to_be_doubled = tn->full_children;
721
- * not_to_be_doubled = tnode_child_length (tn) - tn->empty_children -
726
+ * not_to_be_doubled = child_length (tn) - tn->empty_children -
722
727
* tn->full_children;
723
728
*
724
- * new_child_length = tnode_child_length (tn) * 2;
729
+ * new_child_length = child_length (tn) * 2;
725
730
*
726
731
* new_fill_factor = 100 * (not_to_be_doubled + 2*to_be_doubled) /
727
732
* new_child_length;
@@ -738,23 +743,23 @@ static unsigned char update_suffix(struct key_vector *tn)
738
743
* inflate_threshold * new_child_length
739
744
*
740
745
* expand not_to_be_doubled and to_be_doubled, and shorten:
741
- * 100 * (tnode_child_length (tn) - tn->empty_children +
746
+ * 100 * (child_length (tn) - tn->empty_children +
742
747
* tn->full_children) >= inflate_threshold * new_child_length
743
748
*
744
749
* expand new_child_length:
745
- * 100 * (tnode_child_length (tn) - tn->empty_children +
750
+ * 100 * (child_length (tn) - tn->empty_children +
746
751
* tn->full_children) >=
747
- * inflate_threshold * tnode_child_length (tn) * 2
752
+ * inflate_threshold * child_length (tn) * 2
748
753
*
749
754
* shorten again:
750
- * 50 * (tn->full_children + tnode_child_length (tn) -
755
+ * 50 * (tn->full_children + child_length (tn) -
751
756
* tn->empty_children) >= inflate_threshold *
752
- * tnode_child_length (tn)
757
+ * child_length (tn)
753
758
*
754
759
*/
755
760
static inline bool should_inflate (struct key_vector * tp , struct key_vector * tn )
756
761
{
757
- unsigned long used = tnode_child_length (tn );
762
+ unsigned long used = child_length (tn );
758
763
unsigned long threshold = used ;
759
764
760
765
/* Keep root node larger */
@@ -769,7 +774,7 @@ static inline bool should_inflate(struct key_vector *tp, struct key_vector *tn)
769
774
770
775
static inline bool should_halve (struct key_vector * tp , struct key_vector * tn )
771
776
{
772
- unsigned long used = tnode_child_length (tn );
777
+ unsigned long used = child_length (tn );
773
778
unsigned long threshold = used ;
774
779
775
780
/* Keep root node larger */
@@ -783,7 +788,7 @@ static inline bool should_halve(struct key_vector *tp, struct key_vector *tn)
783
788
784
789
static inline bool should_collapse (struct key_vector * tn )
785
790
{
786
- unsigned long used = tnode_child_length (tn );
791
+ unsigned long used = child_length (tn );
787
792
788
793
used -= tn -> empty_children ;
789
794
@@ -1874,7 +1879,7 @@ static struct key_vector *fib_trie_get_next(struct fib_trie_iter *iter)
1874
1879
pr_debug ("get_next iter={node=%p index=%d depth=%d}\n" ,
1875
1880
iter -> tnode , iter -> index , iter -> depth );
1876
1881
rescan :
1877
- while (cindex < tnode_child_length (tn )) {
1882
+ while (cindex < child_length (tn )) {
1878
1883
struct key_vector * n = get_child_rcu (tn , cindex );
1879
1884
1880
1885
if (n ) {
0 commit comments