Skip to content

Commit 2e1ac88

Browse files
Alexander Duyckdavem330
authored andcommitted
fib_trie: Rename tnode_child_length to child_length
We are now checking the length of a key_vector instead of a tnode so it makes sense to probably just rename this to child_length since it would probably even be applicable to a leaf. Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 754baf8 commit 2e1ac88

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

net/ipv4/fib_trie.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ typedef unsigned int t_key;
9292
#define IS_TNODE(n) ((n)->bits)
9393
#define IS_LEAF(n) (!(n)->bits)
9494

95-
#define get_index(_key, _kv) (((_key) ^ (_kv)->key) >> (_kv)->pos)
96-
9795
struct key_vector {
9896
struct rcu_head rcu;
9997

@@ -177,11 +175,18 @@ static inline void node_set_parent(struct key_vector *n, struct key_vector *tp)
177175
/* This provides us with the number of children in this node, in the case of a
178176
* leaf this will return 0 meaning none of the children are accessible.
179177
*/
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)
181179
{
182180
return (1ul << tn->bits) & ~(1ul);
183181
}
184182

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+
185190
static inline struct fib_table *trie_get_table(struct trie *t)
186191
{
187192
unsigned long *tb_data = (unsigned long *)t;
@@ -374,7 +379,7 @@ static void put_child(struct key_vector *tn, unsigned long i,
374379
struct key_vector *chi = get_child(tn, i);
375380
int isfull, wasfull;
376381

377-
BUG_ON(i >= tnode_child_length(tn));
382+
BUG_ON(i >= child_length(tn));
378383

379384
/* update emptyChildren, overflow into fullChildren */
380385
if (n == NULL && chi != NULL)
@@ -402,7 +407,7 @@ static void update_children(struct key_vector *tn)
402407
unsigned long i;
403408

404409
/* update all of the child parent pointers */
405-
for (i = tnode_child_length(tn); i;) {
410+
for (i = child_length(tn); i;) {
406411
struct key_vector *inode = get_child(tn, --i);
407412

408413
if (!inode)
@@ -480,7 +485,7 @@ static struct key_vector __rcu **replace(struct trie *t,
480485
cptr = tp ? tp->tnode : t->tnode;
481486

482487
/* resize children now that oldtnode is freed */
483-
for (i = tnode_child_length(tn); i;) {
488+
for (i = child_length(tn); i;) {
484489
struct key_vector *inode = get_child(tn, --i);
485490

486491
/* resize child node */
@@ -512,7 +517,7 @@ static struct key_vector __rcu **inflate(struct trie *t,
512517
* point to existing tnodes and the links between our allocated
513518
* nodes.
514519
*/
515-
for (i = tnode_child_length(oldtnode), m = 1u << tn->pos; i;) {
520+
for (i = child_length(oldtnode), m = 1u << tn->pos; i;) {
516521
struct key_vector *inode = get_child(oldtnode, --i);
517522
struct key_vector *node0, *node1;
518523
unsigned long j, k;
@@ -562,7 +567,7 @@ static struct key_vector __rcu **inflate(struct trie *t,
562567
tnode_free_append(tn, node0);
563568

564569
/* 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;) {
566571
put_child(node1, --j, get_child(inode, --k));
567572
put_child(node0, j, get_child(inode, j));
568573
put_child(node1, --j, get_child(inode, --k));
@@ -607,7 +612,7 @@ static struct key_vector __rcu **halve(struct trie *t,
607612
* point to existing tnodes and the links between our allocated
608613
* nodes.
609614
*/
610-
for (i = tnode_child_length(oldtnode); i;) {
615+
for (i = child_length(oldtnode); i;) {
611616
struct key_vector *node1 = get_child(oldtnode, --i);
612617
struct key_vector *node0 = get_child(oldtnode, --i);
613618
struct key_vector *inode;
@@ -648,7 +653,7 @@ static void collapse(struct trie *t, struct key_vector *oldtnode)
648653
unsigned long i;
649654

650655
/* 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;)
652657
n = get_child(oldtnode, --i);
653658

654659
/* compress one level */
@@ -670,7 +675,7 @@ static unsigned char update_suffix(struct key_vector *tn)
670675
* why we start with a stride of 2 since a stride of 1 would
671676
* represent the nodes with suffix length equal to tn->pos
672677
*/
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) {
674679
struct key_vector *n = get_child(tn, i);
675680

676681
if (!n || (n->slen <= slen))
@@ -703,12 +708,12 @@ static unsigned char update_suffix(struct key_vector *tn)
703708
*
704709
* 'high' in this instance is the variable 'inflate_threshold'. It
705710
* 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
707712
* child array will be doubled by inflate()) and multiplying
708713
* the left-hand side by 100 (to handle the percentage thing) we
709714
* multiply the left-hand side by 50.
710715
*
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)
712717
* - tn->empty_children is of course the number of non-null children
713718
* in the current node. tn->full_children is the number of "full"
714719
* 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)
718723
* A clearer way to write this would be:
719724
*
720725
* 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 -
722727
* tn->full_children;
723728
*
724-
* new_child_length = tnode_child_length(tn) * 2;
729+
* new_child_length = child_length(tn) * 2;
725730
*
726731
* new_fill_factor = 100 * (not_to_be_doubled + 2*to_be_doubled) /
727732
* new_child_length;
@@ -738,23 +743,23 @@ static unsigned char update_suffix(struct key_vector *tn)
738743
* inflate_threshold * new_child_length
739744
*
740745
* 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 +
742747
* tn->full_children) >= inflate_threshold * new_child_length
743748
*
744749
* expand new_child_length:
745-
* 100 * (tnode_child_length(tn) - tn->empty_children +
750+
* 100 * (child_length(tn) - tn->empty_children +
746751
* tn->full_children) >=
747-
* inflate_threshold * tnode_child_length(tn) * 2
752+
* inflate_threshold * child_length(tn) * 2
748753
*
749754
* shorten again:
750-
* 50 * (tn->full_children + tnode_child_length(tn) -
755+
* 50 * (tn->full_children + child_length(tn) -
751756
* tn->empty_children) >= inflate_threshold *
752-
* tnode_child_length(tn)
757+
* child_length(tn)
753758
*
754759
*/
755760
static inline bool should_inflate(struct key_vector *tp, struct key_vector *tn)
756761
{
757-
unsigned long used = tnode_child_length(tn);
762+
unsigned long used = child_length(tn);
758763
unsigned long threshold = used;
759764

760765
/* Keep root node larger */
@@ -769,7 +774,7 @@ static inline bool should_inflate(struct key_vector *tp, struct key_vector *tn)
769774

770775
static inline bool should_halve(struct key_vector *tp, struct key_vector *tn)
771776
{
772-
unsigned long used = tnode_child_length(tn);
777+
unsigned long used = child_length(tn);
773778
unsigned long threshold = used;
774779

775780
/* Keep root node larger */
@@ -783,7 +788,7 @@ static inline bool should_halve(struct key_vector *tp, struct key_vector *tn)
783788

784789
static inline bool should_collapse(struct key_vector *tn)
785790
{
786-
unsigned long used = tnode_child_length(tn);
791+
unsigned long used = child_length(tn);
787792

788793
used -= tn->empty_children;
789794

@@ -1874,7 +1879,7 @@ static struct key_vector *fib_trie_get_next(struct fib_trie_iter *iter)
18741879
pr_debug("get_next iter={node=%p index=%d depth=%d}\n",
18751880
iter->tnode, iter->index, iter->depth);
18761881
rescan:
1877-
while (cindex < tnode_child_length(tn)) {
1882+
while (cindex < child_length(tn)) {
18781883
struct key_vector *n = get_child_rcu(tn, cindex);
18791884

18801885
if (n) {

0 commit comments

Comments
 (0)