mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2.6.17-mm1 1/3] ieee1394: reduce size of hpsb_host by 252 bytes
Date: Sat, 24 Jun 2006 11:32:09 +0200 (CEST)	[thread overview]
Message-ID: <tkrat.9c73406a85ae9ce4@s5r6.in-berlin.de> (raw)
In-Reply-To: <tkrat.df6845846c72176e@s5r6.in-berlin.de>

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 <stefanr@s5r6.in-berlin.de>
---
 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);



       reply	other threads:[~2006-06-24  9:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <449BEBFB.60302@s5r6.in-berlin.de>
     [not found] ` <200606230904.k5N94Al3005245@shell0.pdx.osdl.net>
     [not found]   ` <30866.1151072338@warthog.cambridge.redhat.com>
     [not found]     ` <tkrat.df6845846c72176e@s5r6.in-berlin.de>
2006-06-24  9:32       ` Stefan Richter [this message]
2006-06-24  9:33         ` [RFC PATCH 2.6.17-mm1 2/3] ieee1394: coarser locking for tlabel allocation Stefan Richter
2006-06-24  9:35           ` [RFC PATCH 2.6.17-mm1 3/3] ieee1394: nodemgr: read tlabel attributes atomically Stefan Richter
2006-06-24 17:32             ` [RFC PATCH 2.6.17-mm1 4/3] ieee1394: convert ieee1394_transactions from semaphores to waitqueue Stefan Richter
2006-06-24 17:45               ` Stefan Richter
2006-06-24 18:12                 ` Arjan van de Ven
2006-06-24 20:28                   ` Stefan Richter
2006-06-24 20:56                     ` Stefan Richter
2006-06-25 19:37                   ` [RFC PATCH 2.6.17-mm1 5/3] ieee1394: raw1394: remove redundant counting semaphore Stefan Richter
2006-06-25 19:54                     ` Stefan Richter
2006-06-25 17:27               ` [RFC PATCH 2.6.17-mm1 4/3] ieee1394: convert ieee1394_transactions from semaphores to waitqueue Stefan Richter

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=tkrat.9c73406a85ae9ce4@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®