All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@linux-foundation.org>
To: Adrian Bunk <bunk@stusta.de>, Robert Olsson <Robert.Olsson@data.slu.se>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@elte.hu>, Josh Triplett <josh@kernel.org>,
	netdev@vger.kernel.org
Subject: [RFT] fib_trie: cleanup
Date: Thu, 26 Jul 2007 09:46:48 +0100	[thread overview]
Message-ID: <20070726094648.3b7301ae@oldman> (raw)
In-Reply-To: <20070725181557.GF3572@stusta.de>

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


--- a/net/ipv4/fib_trie.c	2007-07-26 09:22:47.000000000 +0100
+++ b/net/ipv4/fib_trie.c	2007-07-26 09:26:19.000000000 +0100
@@ -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,16 @@ 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)
+{
+	return rcu_dereference((struct tnode *) (node->parent & ~NODE_TYPE_MASK));
+}
+
+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 +449,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 +484,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 +639,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 +964,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 +1031,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 +1083,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 +1114,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 +1495,13 @@ backtrace:
 		if (chopped_off <= pn->bits) {
 			cindex &= ~(1 << (chopped_off-1));
 		} else {
-			if (NODE_PARENT(pn) == NULL)
+			struct tnode *parent = node_parent((struct node *) pn);
+			if (!parent)
 				goto failed;
 
 			/* Get Child's index */
-			cindex = tkey_extract_bits(pn->key, NODE_PARENT(pn)->pos, NODE_PARENT(pn)->bits);
-			pn = NODE_PARENT(pn);
+			cindex = tkey_extract_bits(pn->key, parent->pos, parent->bits);
+			pn = parent;
 			chopped_off = 0;
 
 #ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -1536,7 +1537,7 @@ static int trie_leaf_remove(struct trie 
 		check_tnode(tn);
 		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);
 	}
 	l = (struct leaf *) n;
 
@@ -1551,7 +1552,7 @@ static int trie_leaf_remove(struct trie 
 	t->revision++;
 	t->size--;
 
-	tp = NODE_PARENT(n);
+	tp = node_parent(n);
 	tnode_free((struct tnode *) n);
 
 	if (tp) {
@@ -1703,7 +1704,7 @@ static struct leaf *nextleaf(struct trie
 
 		p = (struct tnode*) trie;  /* Start */
 	} else
-		p = (struct tnode *) NODE_PARENT(c);
+		p = node_parent(c);
 
 	while (p) {
 		int pos, last;
@@ -1740,7 +1741,7 @@ static struct leaf *nextleaf(struct trie
 up:
 		/* No more children go up one step  */
 		c = (struct node *) p;
-		p = (struct tnode *) NODE_PARENT(p);
+		p = node_parent(c);
 	}
 	return NULL; /* Ready. Root of trie */
 }
@@ -2043,7 +2044,7 @@ rescan:
 	}
 
 	/* Current node exhausted, pop back up */
-	p = NODE_PARENT(tn);
+	p = node_parent((struct node *)tn);
 	if (p) {
 		cindex = tkey_extract_bits(tn->key, p->pos, p->bits)+1;
 		tn = p;
@@ -2317,7 +2318,7 @@ static int fib_trie_seq_show(struct seq_
 	if (v == SEQ_START_TOKEN)
 		return 0;
 
-	if (!NODE_PARENT(n)) {
+	if (!node_parent(n)) {
 		if (iter->trie == trie_local)
 			seq_puts(seq, "<local>:\n");
 		else

  reply	other threads:[~2007-07-26  8:47 UTC|newest]

Thread overview: 152+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-25 11:03 2.6.23-rc1-mm1 Andrew Morton
2007-07-25 12:25 ` 2.6.23-rc1-mm1 Cedric Le Goater
2007-07-25 17:23   ` 2.6.23-rc1-mm1 Len Brown
2007-07-25 18:58     ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-25 19:13       ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-25 20:22         ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-25 20:36           ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-25 20:36             ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-25 21:52             ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-25 21:52               ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-26  7:25               ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-26  7:25                 ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-26 17:54                 ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-26 17:54                   ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-28 14:03                   ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-28 14:03                     ` 2.6.23-rc1-mm1 Torsten Kaiser
2007-07-25 23:26       ` 2.6.23-rc1-mm1 Len Brown
2007-07-26  9:41         ` 2.6.23-rc1-mm1 Mel Gorman
2007-07-26 13:53           ` 2.6.23-rc1-mm1 Cedric Le Goater
2007-07-25 12:40 ` 2.6.23-rc1-mm1 Cedric Le Goater
2007-07-25 20:05   ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-25 12:55 ` 2.6.23-rc1-mm1 Cedric Le Goater
2007-07-25 13:48   ` 2.6.23-rc1-mm1: chipsfb_pci_suspend problem Rafael J. Wysocki
2007-07-25 20:22     ` Andrew Morton
2007-07-25 22:45       ` Pavel Machek
2007-07-25 13:36 ` [-mm patch] one e1000 driver should be enough for everyone Adrian Bunk
2007-07-25 13:48   ` Jeff Garzik
2007-07-25 13:48     ` Jeff Garzik
2007-07-25 14:46     ` Adrian Bunk
2007-07-25 15:05       ` Jeff Garzik
2007-07-25 15:05         ` Jeff Garzik
2007-07-25 15:21         ` Kok, Auke
2007-07-25 15:23           ` Jeff Garzik
2007-07-25 20:50           ` Andrew Morton
2007-07-25 20:50             ` Andrew Morton
2007-07-25 16:32 ` 2.6.23-rc1-mm1 Michal Piotrowski
2007-07-25 21:56   ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-25 16:36 ` 2.6.23-rc1-mm1 -- mostly fails to build Andy Whitcroft
2007-07-25 17:04   ` Sam Ravnborg
2007-07-25 18:06   ` 2.6.23-rc1-mm1: SCSI_SRP_ATTRS compile error Adrian Bunk
2007-07-26 10:49     ` FUJITA Tomonori
2007-07-25 22:41   ` 2.6.23-rc1-mm1 -- mostly fails to build Andy Whitcroft
2007-07-26  5:56     ` Andrew Morton
2007-07-26 17:53       ` Yinghai Lu
2007-07-25 18:15 ` 2.6.23-rc1-mm1: net/ipv4/fib_trie.c compile error Adrian Bunk
2007-07-26  8:46   ` Stephen Hemminger [this message]
2007-07-26  8:49     ` [RFT] fib_trie: cleanup David Miller
2007-07-26 10:32       ` Robert Olsson
2007-07-26  9:04     ` Andrew Morton
2007-07-26  9:15       ` Stephen Hemminger
2007-07-26 10:49       ` [RFC] fib_trie: whitespace cleanup Stephen Hemminger
2007-07-26 15:44         ` Paul E. McKenney
2007-07-27  4:56           ` Andrew Morton
2007-07-30 17:07             ` Paul E. McKenney
2007-07-26 10:43     ` [RFT] fib_trie: macro cleanup Stephen Hemminger
2007-07-26 10:54       ` Andrew Morton
2007-07-25 18:22 ` 2.6.23-rc1-mm1: reiser4 <-> lzo compile error Adrian Bunk
2007-07-25 18:44   ` Edward Shishkin
2007-07-27 12:35   ` Edward Shishkin
2007-07-27 15:11     ` Richard Purdie
2007-07-25 18:48 ` 2.6.23-rc1-mm1 Michal Piotrowski
2007-07-25 18:53   ` 2.6.23-rc1-mm1 Sam Ravnborg
2007-07-25 19:18     ` 2.6.23-rc1-mm1 H. Peter Anvin
2007-07-25 19:21       ` 2.6.23-rc1-mm1 Sam Ravnborg
2007-07-25 20:58       ` 2.6.23-rc1-mm1 Gabriel C
2007-07-25 21:05         ` 2.6.23-rc1-mm1 Gabriel C
2007-07-25 21:11           ` 2.6.23-rc1-mm1 H. Peter Anvin
2007-07-25 21:13             ` 2.6.23-rc1-mm1 Gabriel C
2007-07-25 21:18               ` 2.6.23-rc1-mm1 H. Peter Anvin
2007-07-25 21:26                 ` 2.6.23-rc1-mm1 Gabriel C
2007-07-26  0:07           ` 2.6.23-rc1-mm1 Greg KH
2007-07-26  0:28             ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-26  1:55               ` 2.6.23-rc1-mm1 Dave Young
2007-07-26  2:23                 ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-26 20:18             ` 2.6.23-rc1-mm1 Dave Hansen
2007-07-25 20:42 ` 2.6.23-rc1-mm1 - drivers/char/nozomi.c overflow in implicit constant conversion , warnings Gabriel C
2007-07-26  5:42   ` Greg KH
2007-07-25 21:01 ` 2.6.23-rc1-mm1: m32r is_init() compile error Adrian Bunk
2007-07-25 21:42   ` sukadev
2007-07-25 21:17 ` 2.6.23-rc1-mm1: git-kgdb breaks sh compilation Adrian Bunk
2007-07-26  1:45   ` Paul Mundt
2007-07-25 22:03 ` 2.6.23-rc1-mm1 - seems OK on Dell Latitude D820, except for tpm_tis Valdis.Kletnieks
2007-07-26  3:37   ` Andrew Morton
2007-07-27  4:00     ` Valdis.Kletnieks
2007-07-27 13:28       ` Valdis.Kletnieks
2007-07-27 18:07         ` Andrew Morton
2007-07-27 19:44           ` Valdis.Kletnieks
2007-07-27 22:43         ` Bjorn Helgaas
2007-07-30 18:09           ` Bjorn Helgaas
2007-07-30 23:53           ` Valdis.Kletnieks
2007-07-31 18:48             ` Valdis.Kletnieks
2007-07-31 20:01               ` Bjorn Helgaas
2007-07-31 21:31                 ` Valdis.Kletnieks
2007-07-31 23:05                   ` Bjorn Helgaas
2007-07-26  5:26 ` [-mm patch] DMA engine kconfig improvements Adrian Bunk
2007-08-04  2:15   ` Dan Williams
2007-08-10  0:43     ` Adrian Bunk
2007-08-15 23:36   ` Nelson, Shannon
2007-07-26 12:11 ` [PATCH] sparsemem: ensure we initialise the node mapping for SPARSEMEM_STATIC Andy Whitcroft
2007-07-26 12:58 ` 2.6.23-rc1-mm1 sparsemem_vmemamp fix KAMEZAWA Hiroyuki
2007-07-26 14:39   ` Andy Whitcroft
2007-07-26 14:44     ` Andy Whitcroft
2007-07-27 13:28 ` [-mm patch] xtensa console.c: remove duplicate #include Frederik Deweerdt
2007-07-28 15:44 ` NETPOLL=y , NETDEVICES=n compile error ( Re: 2.6.23-rc1-mm1 ) Gabriel C
2007-07-28 17:26   ` Andrew Morton
2007-07-28 18:42     ` Gabriel C
2007-07-31  8:32       ` Jarek Poplawski
2007-07-31 10:14         ` Gabriel C
2007-07-31 11:44           ` Jason Wessel
2007-07-31 12:47             ` Jarek Poplawski
2007-07-31 12:17           ` Jarek Poplawski
2007-07-31 15:05             ` Gabriel C
2007-08-01  9:59               ` Jarek Poplawski
2007-08-02  2:02                 ` Matt Mackall
2007-08-02  9:00                   ` Jarek Poplawski
2007-08-02 15:59                     ` Matt Mackall
2007-08-03  7:30                       ` Jarek Poplawski
2007-08-02  9:36                   ` Sam Ravnborg
2007-08-02 10:32                     ` Satyam Sharma
2007-08-02 11:40                       ` Satyam Sharma
2007-08-02 11:40                       ` Jarek Poplawski
2007-08-02 11:56                         ` Satyam Sharma
2007-08-02 12:52                           ` Jarek Poplawski
2007-08-06 11:51                     ` [PATCH] docs: note about select in kconfig-language.txt Jarek Poplawski
2007-07-28 16:36 ` DCA=n , INTEL_IOATDMA=y compile error ( Re: 2.6.23-rc1-mm1 ) Gabriel C
2007-07-28 16:47 ` sound/pci/ac97/ac97_patch.h - declared 'static' but never defined warnings " Gabriel C
2007-07-28 17:07 ` mm/sparse.c compile error " Gabriel C
2007-07-28 17:30   ` Andrew Morton
2007-07-30 12:16     ` Andy Whitcroft
2007-07-28 19:32 ` [PATCH -mm] Fix libata warnings with CONFIG_PM=n Gabriel C
2007-07-29 14:57 ` [-mm patch] make hugetlbfs_read() static Adrian Bunk
2007-07-29 14:57 ` [-mm patch] fs/ecryptfs/: make code static Adrian Bunk
2007-07-29 14:58 ` [-mm patch] make struct sdio_dev_attrs[] static Adrian Bunk
2007-07-29 19:29   ` Pierre Ossman
2007-07-29 14:58 ` [-mm patch] MTD onenand_sim.c: make struct info static Adrian Bunk
2007-07-29 14:58   ` Adrian Bunk
2007-07-29 14:58 ` [-mm patch] make scsi_host_link_pm_policy() static Adrian Bunk
2007-07-29 14:58 ` [-mm patch] USB: make dev_attr_authorized_default static Adrian Bunk
2007-07-31 19:13   ` Inaky Perez-Gonzalez
2007-07-29 14:59 ` [-mm patch] kernel/printk.c: make 2 variables static Adrian Bunk
2007-07-29 16:51   ` Randy Dunlap
2007-07-29 14:59 ` [-mm patch] export v4l2_int_device_{,un}register Adrian Bunk
2007-07-29 14:59 ` [-mm patch] kernel/pid.c: remove unused exports Adrian Bunk
2007-07-29 15:00 ` [-mm patch] security/ cleanups Adrian Bunk
2007-07-30 11:47   ` James Morris
2007-07-29 15:49 ` 2.6.23-rc1-mm1 Grant Wilson
2007-07-30  9:58   ` 2.6.23-rc1-mm1 Dave Young
2007-07-30 18:27     ` 2.6.23-rc1-mm1 Andrew Morton
2007-07-30 18:42       ` 2.6.23-rc1-mm1 Christoph Hellwig
2007-07-30 22:18         ` 2.6.23-rc1-mm1 Satyam Sharma
2007-07-31  1:21           ` 2.6.23-rc1-mm1 Dave Young
2007-08-01 15:24 ` 2.6.23-rc1-mm1 - loopback mount of files fails loop-use-unlocked_ioctl.patch Valdis.Kletnieks

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=20070726094648.3b7301ae@oldman \
    --to=shemminger@linux-foundation.org \
    --cc=Robert.Olsson@data.slu.se \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@stusta.de \
    --cc=josh@kernel.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.