mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Jaeger <email@christophjaeger.info>
To: shigekatsu.tateno@atmel.com, gregkh@linuxfoundation.org
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	Christoph Jaeger <email@christophjaeger.info>
Subject: [PATCH 09/10 v2] staging: ozwpan: Use slab cache for oz_tx_frame allocation
Date: Fri,  8 Aug 2014 08:01:09 +0200	[thread overview]
Message-ID: <1407477669-329-1-git-send-email-email@christophjaeger.info> (raw)
In-Reply-To: <1407156896-3246-10-git-send-email-email@christophjaeger.info>

Use a slab cache rather than rolling our own free list.

Signed-off-by: Christoph Jaeger <email@christophjaeger.info>
---
v2: Don't use likely()/unlikely().

 drivers/staging/ozwpan/ozpd.c    | 41 ++++++----------------------------------
 drivers/staging/ozwpan/ozpd.h    |  3 +--
 drivers/staging/ozwpan/ozproto.c |  8 ++++++++
 drivers/staging/ozwpan/ozproto.h |  1 +
 4 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c
index c6fddb8..e849d8a 100644
--- a/drivers/staging/ozwpan/ozpd.c
+++ b/drivers/staging/ozwpan/ozpd.c
@@ -21,8 +21,6 @@
 #include <linux/uaccess.h>
 #include <net/psnap.h>
 
-#define OZ_MAX_TX_POOL_SIZE	6
-
 static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd);
 static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f);
 static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f);
@@ -177,13 +175,6 @@ static void oz_pd_free(struct work_struct *work)
 		e = e->next;
 		kfree(fwell);
 	}
-	/* Deallocate all frames in tx pool.
-	 */
-	while (pd->tx_pool) {
-		e = pd->tx_pool;
-		pd->tx_pool = e->next;
-		kfree(container_of(e, struct oz_tx_frame, link));
-	}
 	if (pd->net_dev)
 		dev_put(pd->net_dev);
 	kfree(pd);
@@ -333,17 +324,9 @@ int oz_pd_sleep(struct oz_pd *pd)
  */
 static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd)
 {
-	struct oz_tx_frame *f = NULL;
+	struct oz_tx_frame *f;
 
-	spin_lock_bh(&pd->tx_frame_lock);
-	if (pd->tx_pool) {
-		f = container_of(pd->tx_pool, struct oz_tx_frame, link);
-		pd->tx_pool = pd->tx_pool->next;
-		pd->tx_pool_count--;
-	}
-	spin_unlock_bh(&pd->tx_frame_lock);
-	if (f == NULL)
-		f = kmalloc(sizeof(struct oz_tx_frame), GFP_ATOMIC);
+	f = kmem_cache_alloc(oz_tx_frame_cache, GFP_ATOMIC);
 	if (f) {
 		f->total_size = sizeof(struct oz_hdr);
 		INIT_LIST_HEAD(&f->link);
@@ -359,13 +342,9 @@ static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f)
 {
 	pd->nb_queued_isoc_frames--;
 	list_del_init(&f->link);
-	if (pd->tx_pool_count < OZ_MAX_TX_POOL_SIZE) {
-		f->link.next = pd->tx_pool;
-		pd->tx_pool = &f->link;
-		pd->tx_pool_count++;
-	} else {
-		kfree(f);
-	}
+
+	kmem_cache_free(oz_tx_frame_cache, f);
+
 	oz_dbg(TX_FRAMES, "Releasing ISOC Frame isoc_nb= %d\n",
 	       pd->nb_queued_isoc_frames);
 }
@@ -375,15 +354,7 @@ static void oz_tx_isoc_free(struct oz_pd *pd, struct oz_tx_frame *f)
  */
 static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f)
 {
-	spin_lock_bh(&pd->tx_frame_lock);
-	if (pd->tx_pool_count < OZ_MAX_TX_POOL_SIZE) {
-		f->link.next = pd->tx_pool;
-		pd->tx_pool = &f->link;
-		pd->tx_pool_count++;
-		f = NULL;
-	}
-	spin_unlock_bh(&pd->tx_frame_lock);
-	kfree(f);
+	kmem_cache_free(oz_tx_frame_cache, f);
 }
 
 /*
diff --git a/drivers/staging/ozwpan/ozpd.h b/drivers/staging/ozwpan/ozpd.h
index 43a26ea..212fab0 100644
--- a/drivers/staging/ozwpan/ozpd.h
+++ b/drivers/staging/ozwpan/ozpd.h
@@ -90,8 +90,6 @@ struct oz_pd {
 	unsigned	max_stream_buffering;
 	int		nb_queued_frames;
 	int		nb_queued_isoc_frames;
-	struct list_head *tx_pool;
-	int		tx_pool_count;
 	spinlock_t	tx_frame_lock;
 	struct list_head *last_sent_frame;
 	struct list_head tx_queue;
@@ -131,5 +129,6 @@ void oz_apps_init(void);
 void oz_apps_term(void);
 
 extern struct kmem_cache *oz_elt_info_cache;
+extern struct kmem_cache *oz_tx_frame_cache;
 
 #endif /* Sentry */
diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
index b592e96..db6ef99 100644
--- a/drivers/staging/ozwpan/ozproto.c
+++ b/drivers/staging/ozwpan/ozproto.c
@@ -53,6 +53,7 @@ static u16 g_apps = 0x1;
 static int g_processing_rx;
 
 struct kmem_cache *oz_elt_info_cache;
+struct kmem_cache *oz_tx_frame_cache;
 
 /*
  * Context: softirq-serialized
@@ -483,6 +484,7 @@ void oz_protocol_term(void)
 	spin_unlock_bh(&g_polling_lock);
 	oz_dbg(ON, "Protocol stopped\n");
 
+	kmem_cache_destroy(oz_tx_frame_cache);
 	kmem_cache_destroy(oz_elt_info_cache);
 }
 
@@ -771,6 +773,12 @@ int oz_protocol_init(char *devs)
 	if (!oz_elt_info_cache)
 		return -ENOMEM;
 
+	oz_tx_frame_cache = KMEM_CACHE(oz_tx_frame, 0);
+	if (!oz_tx_frame_cache) {
+		kmem_cache_destroy(oz_elt_info_cache);
+		return -ENOMEM;
+	}
+
 	skb_queue_head_init(&g_rx_queue);
 	if (devs[0] == '*') {
 		oz_binding_add(NULL);
diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h
index b0f7459..73cc69b 100644
--- a/drivers/staging/ozwpan/ozproto.h
+++ b/drivers/staging/ozwpan/ozproto.h
@@ -66,5 +66,6 @@ int oz_get_pd_status_list(char *pd_list, int max_count);
 int oz_get_binding_list(char *buf, int max_if);
 
 extern struct kmem_cache *oz_elt_info_cache;
+extern struct kmem_cache *oz_tx_frame_cache;
 
 #endif /* _OZPROTO_H */
-- 
1.9.1


  reply	other threads:[~2014-08-08  6:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04 12:54 [PATCH 00/10] staging: Clean up ozwpan driver Christoph Jaeger
2014-08-04 12:54 ` [PATCH 01/10] staging: ozwpan: Add module parameter description Christoph Jaeger
2014-08-04 12:54 ` [PATCH 02/10] staging: ozwpan: Fix typo in typedef Christoph Jaeger
2014-08-10  4:42   ` Greg KH
2014-08-04 12:54 ` [PATCH 03/10] staging: ozwpan: Remove unused OZ_MAX_TIMER_POOL_SIZE Christoph Jaeger
2014-08-04 12:54 ` [PATCH 04/10] staging: ozwpan: Remove redundant initialization Christoph Jaeger
2014-08-04 12:54 ` [PATCH 05/10] staging: ozwpan: Remove dead code Christoph Jaeger
2014-08-04 12:54 ` [PATCH 06/10] staging: ozwpan: Simplify app interface Christoph Jaeger
2014-08-05 11:13   ` Dan Carpenter
2014-08-04 12:54 ` [PATCH 07/10] staging: ozwpan: Use slab cache for oz_urb_link allocation Christoph Jaeger
2014-08-05 11:18   ` Dan Carpenter
2014-08-08  5:59   ` [PATCH 07/10 v2] " Christoph Jaeger
2014-08-04 12:54 ` [PATCH 08/10] staging: ozwpan: Use slab cache for oz_elt_info allocation Christoph Jaeger
2014-08-08  6:00   ` [PATCH 08/10 v2] " Christoph Jaeger
2014-08-04 12:54 ` [PATCH 09/10] staging: ozwpan: Use slab cache for oz_tx_frame allocation Christoph Jaeger
2014-08-08  6:01   ` Christoph Jaeger [this message]
2014-08-04 12:54 ` [PATCH 10/10] staging: ozwpan: Use list helpers Christoph Jaeger

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=1407477669-329-1-git-send-email-email@christophjaeger.info \
    --to=email@christophjaeger.info \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shigekatsu.tateno@atmel.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 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®