Commit 3bbd038f authored by Ben Collins's avatar Ben Collins

IEEE1394(r1168): Add on a mempool for packet allocation, in addition to the kmem_cache.

parent 713d8db7
......@@ -31,6 +31,7 @@
#include <linux/moduleparam.h>
#include <linux/bitops.h>
#include <linux/kdev_t.h>
#include <linux/mempool.h>
#include <asm/byteorder.h>
#include <asm/semaphore.h>
......@@ -56,6 +57,7 @@ MODULE_PARM_DESC(disable_nodemgr, "Disable nodemgr functionality.");
MODULE_LICENSE("GPL");
static kmem_cache_t *hpsb_packet_cache;
static mempool_t *hpsb_packet_mempool;
/* Some globals used */
const char *hpsb_speedto_str[] = { "S100", "S200", "S400", "S800", "S1600", "S3200" };
......@@ -92,7 +94,7 @@ static void queue_packet_complete(struct hpsb_packet *packet);
void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
void (*routine)(void *), void *data)
{
BUG_ON(packet->complete_routine != NULL);
WARN_ON(packet->complete_routine != NULL);
packet->complete_routine = routine;
packet->complete_data = data;
return;
......@@ -123,14 +125,15 @@ struct hpsb_packet *hpsb_alloc_packet(size_t data_size)
struct hpsb_packet *packet = NULL;
void *data = NULL;
packet = kmem_cache_alloc(hpsb_packet_cache, GFP_ATOMIC);
packet = mempool_alloc(hpsb_packet_mempool, GFP_ATOMIC);
if (packet == NULL)
return NULL;
if (data_size) {
data_size = (data_size + 3) & ~3;
data = kmalloc(data_size + 8, GFP_ATOMIC);
if (data == NULL) {
kmem_cache_free(hpsb_packet_cache, packet);
mempool_free(packet, hpsb_packet_mempool);
return NULL;
}
......@@ -152,7 +155,7 @@ void hpsb_free_packet(struct hpsb_packet *packet)
{
if (packet && atomic_dec_and_test(&packet->refcnt)) {
kfree(packet->data);
kmem_cache_free(hpsb_packet_cache, packet);
mempool_free(packet, hpsb_packet_mempool);
}
}
......@@ -1065,7 +1068,14 @@ static int __init ieee1394_init(void)
devfs_mk_dir("ieee1394");
hpsb_packet_cache = kmem_cache_create("hpsb_packet", sizeof(struct hpsb_packet),
0, 0, hpsb_packet_ctor, NULL);
0, SLAB_HWCACHE_ALIGN, hpsb_packet_ctor, NULL);
/* Our memory pool keeps 32 packets allocated at all times. The
* default callbacks use the hpsb_packet_cache for the allocation,
* and the hpsb_packet_ctor call back makes sure that the packets
* are setup properly. Smooooth. */
hpsb_packet_mempool = mempool_create(32, mempool_alloc_slab,
mempool_free_slab,
hpsb_packet_cache);
bus_register(&ieee1394_bus_type);
for (i = 0; fw_bus_attrs[i]; i++)
......@@ -1102,6 +1112,7 @@ static void __exit ieee1394_cleanup(void)
wait_for_completion(&khpsbpkt_complete);
}
mempool_destroy(hpsb_packet_mempool);
kmem_cache_destroy(hpsb_packet_cache);
unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment