[svn-commits] sruffell: branch linux/sruffell/dahdi-linux-cmdqueue r6112 - /linux/team/sruf...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Mar 11 09:49:24 CDT 2009
Author: sruffell
Date: Wed Mar 11 09:49:20 2009
New Revision: 6112
URL: http://svn.digium.com/svn-view/dahdi?view=rev&rev=6112
Log:
Using kmem_cache instead of free list. Causes an error when unloading that I'm
still working on.
Modified:
linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c
linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h
Modified: linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c
URL: http://svn.digium.com/svn-view/dahdi/linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c?view=diff&rev=6112&r1=6111&r2=6112
==============================================================================
--- linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c (original)
+++ linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c Wed Mar 11 09:49:20 2009
@@ -85,24 +85,18 @@
static struct command * get_free_cmd(struct t1 *wc)
{
- struct command *cmd = NULL;
- unsigned long flags;
- spin_lock_irqsave(&wc->cmd_list_lock, flags);
- if (!list_empty(&wc->free_cmds)) {
- cmd = list_entry(wc->free_cmds.next, struct command, node);
- list_del_init(&cmd->node);
+ struct command *cmd;
+ cmd = kmem_cache_alloc(wc->cmd_cache, GFP_ATOMIC);
+ if (cmd) {
memset(cmd, 0, sizeof(*cmd));
- }
- spin_unlock_irqrestore(&wc->cmd_list_lock, flags);
+ INIT_LIST_HEAD(&cmd->node);
+ }
return cmd;
}
static void free_cmd(struct t1 *wc, struct command *cmd)
{
- unsigned long flags;
- spin_lock_irqsave(&wc->cmd_list_lock, flags);
- list_move(&cmd->node, &wc->free_cmds);
- spin_unlock_irqrestore(&wc->cmd_list_lock, flags);
+ kmem_cache_free(wc->cmd_cache, cmd);
}
static struct command * get_pending_cmd(struct t1 *wc)
@@ -135,6 +129,7 @@
list_splice_init(&wc->active_cmds, &wc->pending_cmds);
spin_unlock_irqrestore(&wc->cmd_list_lock, flags);
}
+
static void cmd_dequeue(struct t1 *wc, volatile unsigned char *writechunk, int eframe, int slot)
{
struct command *curcmd=NULL;
@@ -195,7 +190,8 @@
if (cmd->flags & (__CMD_WR | __CMD_LEDS)) {
/* Nobody is waiting on writes...so let's just
* free them here. */
- list_move(&cmd->node, &wc->free_cmds);
+ list_del(&cmd->node);
+ free_cmd(wc, cmd);
} else {
cmd->data |= readchunk[CMD_BYTE(cmd->cs_slot, 2, IS_VPM)];
list_del_init(&cmd->node);
@@ -208,9 +204,10 @@
static inline int t1_setreg_full(struct t1 *wc, int addr, int val, int vpm_num)
{
struct command *cmd;
- might_sleep();
- while (!(cmd = get_free_cmd(wc))) {
- msleep(1);
+ cmd = get_free_cmd(wc);
+ if (!cmd) {
+ WARN_ON(1);
+ return -ENOMEM;
}
cmd->address = addr;
cmd->data = val;
@@ -235,9 +232,9 @@
might_sleep();
- while (!(cmd = get_free_cmd(wc)))
- msleep(1);
-
+ cmd = get_free_cmd(wc);
+ if (!cmd)
+ return -ENOMEM;
cmd->address = addr;
cmd->data = 0x00;
cmd->flags = __CMD_RD;
@@ -263,10 +260,9 @@
leds = (~leds) & 0x0E; /* invert the LED bits (3 downto 1)*/
- while (!(cmd = get_free_cmd(wc))) {
- msleep(10);
- }
-
+ cmd = get_free_cmd(wc);
+ if (!cmd)
+ return;
cmd->flags |= __CMD_LEDS;
cmd->address = leds;
submit_cmd(wc, cmd);
@@ -314,11 +310,24 @@
static void t1_release(struct t1 *wc)
{
unsigned int x;
+ unsigned long flags;
+ struct command *cmd;
+ LIST_HEAD(list);
dahdi_unregister(&wc->span);
for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++) {
kfree(wc->chans[x]);
}
+ spin_lock_irqsave(&wc->cmd_list_lock, flags);
+ list_move_tail(&wc->active_cmds, &list);
+ list_move_tail(&wc->pending_cmds, &list);
+ spin_unlock_irqrestore(&wc->cmd_list_lock, flags);
+ while (!list_empty(&list)) {
+ cmd = list_entry(list.next, struct command, node);
+ list_del(&cmd->node);
+ free_cmd(wc, cmd);
+ }
+ kmem_cache_destroy(wc->cmd_cache);
kfree(wc);
printk(KERN_INFO "Freed a Wildcard TE12xP\n");
}
@@ -1353,11 +1362,18 @@
spin_lock_init(&wc->cmd_list_lock);
INIT_LIST_HEAD(&wc->active_cmds);
INIT_LIST_HEAD(&wc->pending_cmds);
- INIT_LIST_HEAD(&wc->free_cmds);
- for (x = 0; x < MAX_COMMANDS; ++x) {
- INIT_LIST_HEAD(&wc->cmds[x].node);
- free_cmd(wc, &wc->cmds[x]);
- }
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
+ wc->cmd_cache = kmem_cache_create(THIS_MODULE->name, sizeof(struct command), 0,
+#if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 22)
+ SLAB_HWCACHE_ALIGN | SLAB_STORE_USER, NULL, NULL);
+#else
+ SLAB_HWCACHE_ALIGN, NULL, NULL);
+#endif
+#else
+ wc->cmd_cache = kmem_cache_create(THIS_MODULE->name, sizeof(struct command), 0,
+ SLAB_HWCACHE_ALIGN, NULL);
+#endif
wc->variety = d->name;
wc->txident = 1;
Modified: linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h
URL: http://svn.digium.com/svn-view/dahdi/linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h?view=diff&rev=6112&r1=6111&r2=6112
==============================================================================
--- linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h (original)
+++ linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h Wed Mar 11 09:49:20 2009
@@ -135,13 +135,15 @@
unsigned long dtmfmask;
unsigned long dtmfmutemask;
#endif
- /* Preallocted memory for the commands. TODO remove this. */
- struct command cmds[MAX_COMMANDS];
-
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
+ kmem_cache_t *cmd_cache;
+#else
+ struct kmem_cache *cmd_cache;
+#endif
spinlock_t cmd_list_lock;
struct list_head pending_cmds;
struct list_head active_cmds;
- struct list_head free_cmds;
struct timer_list timer;
struct work_struct timer_work;
};
More information about the svn-commits
mailing list