[RFC PATCH 2.6.17-mm1 1/3] ieee1394: reduce size of hpsb_host by 252 bytes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Struct hpsb_host contains struct hpsb_tlabel_pool 63 times, therefore
each word that can be shaved off of hpsb_tlabel_pool is a win.

Since hpsb_tlabel_pool.next is accessed twice as often as .allocations,
.next is put into the lower part of the word.  The value of .allocations
rolls over after about 67 million now but we don't care.

Signed-off-by: Stefan Richter <[email protected]>
---
 drivers/ieee1394/ieee1394_transactions.c |   22 ++++++++++++----------
 drivers/ieee1394/ieee1394_types.h        |    9 +++++++--
 2 files changed, 19 insertions(+), 12 deletions(-)

Index: linux/drivers/ieee1394/ieee1394_types.h
===================================================================
--- linux.orig/drivers/ieee1394/ieee1394_types.h	2006-04-24 22:20:24.000000000 +0200
+++ linux/drivers/ieee1394/ieee1394_types.h	2006-06-24 09:52:37.000000000 +0200
@@ -17,8 +17,13 @@
 struct hpsb_tlabel_pool {
 	DECLARE_BITMAP(pool, 64);
 	spinlock_t lock;
-	u8 next;
-	u32 allocations;
+#ifdef __BIG_ENDIAN_BITFIELD
+	u32 allocations	:26 __attribute__((packed));
+	u32 next	:6  __attribute__((packed));
+#else
+	u32 next	:6  __attribute__((packed));
+	u32 allocations	:26 __attribute__((packed));
+#endif
 	struct semaphore count;
 };
 
Index: linux/drivers/ieee1394/ieee1394_transactions.c
===================================================================
--- linux.orig/drivers/ieee1394/ieee1394_transactions.c	2006-06-23 19:10:30.000000000 +0200
+++ linux/drivers/ieee1394/ieee1394_transactions.c	2006-06-24 09:24:00.000000000 +0200
@@ -136,7 +136,7 @@ int hpsb_get_tlabel(struct hpsb_packet *
 {
 	unsigned long flags;
 	struct hpsb_tlabel_pool *tp;
-	int n = NODEID_TO_NODE(packet->node_id);
+	int tlabel, n = NODEID_TO_NODE(packet->node_id);
 
 	if (unlikely(n == ALL_NODES))
 		return 0;
@@ -151,15 +151,17 @@ int hpsb_get_tlabel(struct hpsb_packet *
 
 	spin_lock_irqsave(&tp->lock, flags);
 
-	packet->tlabel = find_next_zero_bit(tp->pool, 64, tp->next);
-	if (packet->tlabel > 63)
-		packet->tlabel = find_first_zero_bit(tp->pool, 64);
-	tp->next = (packet->tlabel + 1) % 64;
+	tlabel = find_next_zero_bit(tp->pool, 64, tp->next);
+	if (tlabel > 63)
+		tlabel = find_first_zero_bit(tp->pool, 64);
+	/* tp->next is 6 bits wide, thus rolls over from 63 to 0 */
+	tp->next = (tlabel + 1);
 	/* Should _never_ happen */
-	BUG_ON(test_and_set_bit(packet->tlabel, tp->pool));
+	BUG_ON(test_and_set_bit(tlabel, tp->pool));
 	tp->allocations++;
-	spin_unlock_irqrestore(&tp->lock, flags);
 
+	spin_unlock_irqrestore(&tp->lock, flags);
+	packet->tlabel = tlabel;
 	return 0;
 }
 
@@ -178,16 +180,16 @@ void hpsb_free_tlabel(struct hpsb_packet
 {
 	unsigned long flags;
 	struct hpsb_tlabel_pool *tp;
-	int n = NODEID_TO_NODE(packet->node_id);
+	int tlabel = packet->tlabel, n = NODEID_TO_NODE(packet->node_id);
 
 	if (unlikely(n == ALL_NODES))
 		return;
 	tp = &packet->host->tpool[n];
 
-	BUG_ON(packet->tlabel > 63 || packet->tlabel < 0);
+	BUG_ON(tlabel > 63 || tlabel < 0);
 
 	spin_lock_irqsave(&tp->lock, flags);
-	BUG_ON(!test_and_clear_bit(packet->tlabel, tp->pool));
+	BUG_ON(!test_and_clear_bit(tlabel, tp->pool));
 	spin_unlock_irqrestore(&tp->lock, flags);
 
 	up(&tp->count);


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux