Skip to contentSkip to conversation

small skbuff.[ch] tweaks

PATCH In review Mitchell Blank Jr 2 participants 5 messages Sep 2, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 small skbuff.[ch] tweaks

This patch:
o Makes a couple inline functions in <linux/skbuff.h> take const arguments as appropriate
o Obvious unlikely()/likely()/BUG_ON() conversions

Patch is versus 2.6.0-test4.

-Mitch

include/linux/skbuff.h +3 -3
@@ -306,7 +306,7 @@
  *
  *	Returns true if the queue is empty, false otherwise.
  */
-static inline int skb_queue_empty(struct sk_buff_head *list)
+static inline int skb_queue_empty(const struct sk_buff_head *list)
 {
 	return list->next == (struct sk_buff *)list;
 }
@@ -475,7 +475,7 @@
  *
  *	Return the length of an &sk_buff queue.
  */
-static inline __u32 skb_queue_len(struct sk_buff_head *list_)
+static inline __u32 skb_queue_len(const struct sk_buff_head *list_)
 {
 	return list_->qlen;
 }
@@ -1050,7 +1050,7 @@
 					      int gfp_mask)
 {
 	struct sk_buff *skb = alloc_skb(length + 16, gfp_mask);
-	if (skb)
+	if (likely(skb))
 		skb_reserve(skb, 16);
 	return skb;
 }
net/core/skbuff.c +35 -45

242 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · On Tue, 2 Sep 2003 01:16:25 -0700 Mitchell Blank Jr <[email protected]> wrote:
net/core/skbuff.c +0 -0
@@ -129,14 +129,17 @@
 	/* Get the HEAD */
 	skb = kmem_cache_alloc(skbuff_head_cache,
 			       gfp_mask & ~__GFP_DMA);

net/core/skbuff.c line 138

Quoted 10 lines
net/core/skbuff.c +2 -3
-	if (!skb)
+	if (unlikely(!skb))
 		goto out;
 
 	/* Get the DATA. Size must match skb_add_mtu(). */
 	size = SKB_DATA_ALIGN(size);
 	data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
-	if (!data)
-		goto nodata;
+	if (unlikely(!data)) {

Both unlikely(!ptr) and likely(ptr) are not needed because gcc assumes this by default

-Andi

#3 lore raw
In reply to Mitchell Blank Jr
Quoted 5 lines · Mitchell Blank Jr
Quoted 2 lines · Andi Kleen

Both unlikely(!ptr) and likely(ptr) are not needed because gcc assumes this by default

Is there any disadvantage to stating it explicitly?

It makes the code much uglier.

-Andi

#2 lore raw
In reply to Andi Kleen
Quoted 2 lines · Andi Kleen

Both unlikely(!ptr) and likely(ptr) are not needed because gcc assumes this by default

Is there any disadvantage to stating it explicitly?

-Mitch

#4 lore raw
In reply to Andi Kleen
Quoted 6 lines · Andi Kleen
Quoted 4 lines
Quoted 2 lines

Both unlikely(!ptr) and likely(ptr) are not needed because gcc assumes this by default

Is there any disadvantage to stating it explicitly?

It makes the code much uglier.

Well I guess it's a matter of taste then. Personally I like unlikely()/ likely() a lot, even from just a readability standpoint. I think it provides a nice hint to the structure of code while reading it ("ok, we're just handling an error case here, the meat of the code is below") If anything they help comment the code.

I certainly think they're preferable to "this is an unlikely error condition but we shouldn't mark it as such because of some gcc trivia lets us save a few characters of typing"

However if the consensus is that those unlikely()'s should be removed I'll be happy to spin a new patch with those removed.

-Mitch