summaryrefslogtreecommitdiffstats
path: root/runtime/transport
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/transport')
-rw-r--r--runtime/transport/ChangeLog13
-rw-r--r--runtime/transport/control.c209
-rw-r--r--runtime/transport/procfs.c288
-rw-r--r--runtime/transport/symbols.c185
-rw-r--r--runtime/transport/transport.c33
-rw-r--r--runtime/transport/transport_msgs.h23
6 files changed, 358 insertions, 393 deletions
diff --git a/runtime/transport/ChangeLog b/runtime/transport/ChangeLog
index 764e3579..c3837f86 100644
--- a/runtime/transport/ChangeLog
+++ b/runtime/transport/ChangeLog
@@ -1,3 +1,16 @@
+2008-02-27 Martin Hunt <hunt@redhat.com>
+
+ * symbols.c: Use rwlocks. Use new dbug macros. Handle
+ unwind info if present.
+
+ * transport.c: Include mempool.c. Update dbug and kbug calls
+ to new macros.
+ * transport_msgs.h (_stp_command_name): Add
+ struct containing message names for debugging.
+
+ * control.c, procfs.c: Use new dbug macros. Use
+ new mempool functions.
+
2008-01-28 Martin Hunt <hunt@redhat.com>
* control.c, procfs.c, symbols.c: Use DEFINE_SPINLOCK
diff --git a/runtime/transport/control.c b/runtime/transport/control.c
index 0bf99fc8..6a5b272d 100644
--- a/runtime/transport/control.c
+++ b/runtime/transport/control.c
@@ -12,15 +12,13 @@
#define STP_DEFAULT_BUFFERS 50
static int _stp_current_buffers = STP_DEFAULT_BUFFERS;
+static _stp_mempool_t *_stp_pool_q;
static struct list_head _stp_ctl_ready_q;
static struct list_head _stp_sym_ready_q;
-static struct list_head _stp_pool_q;
-DEFINE_SPINLOCK(_stp_pool_lock);
DEFINE_SPINLOCK(_stp_ctl_ready_lock);
DEFINE_SPINLOCK(_stp_sym_ready_lock);
-static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t _stp_sym_write_cmd(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
static int saved_type = 0;
int type;
@@ -28,7 +26,7 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
if (count < sizeof(int32_t))
return 0;
- /* Allow sending of packet type followed by data in the next packet.*/
+ /* Allow sending of packet type followed by data in the next packet. */
if (count == sizeof(int32_t)) {
if (get_user(saved_type, (int __user *)buf))
return -EFAULT;
@@ -42,11 +40,14 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
count -= sizeof(int);
buf += sizeof(int);
}
-
- kbug ("count:%d type:%d\n", (int)count, type);
+
+#if DEBUG_TRANSPORT > 0
+ if (type < STP_MAX_CMD)
+ _dbug("Got %s. len=%d\n", _stp_command_name[type], (int)count);
+#endif
switch (type) {
- case STP_SYMBOLS:
+ case STP_SYMBOLS:
count = _stp_do_symbols(buf, count);
break;
case STP_MODULE:
@@ -54,21 +55,20 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
count = _stp_do_module(buf, count);
else {
/* count == 1 indicates end of initial modules list */
- _stp_ctl_send(STP_TRANSPORT, NULL, 0);
+ _stp_ctl_send(STP_TRANSPORT, NULL, 0);
}
break;
case STP_EXIT:
_stp_exit_flag = 1;
break;
default:
- errk ("invalid symbol command type %d\n", type);
+ errk("invalid symbol command type %d\n", type);
return -EINVAL;
}
return count;
}
-static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t _stp_ctl_write_cmd(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int type;
static int started = 0;
@@ -79,7 +79,10 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
if (get_user(type, (int __user *)buf))
return -EFAULT;
- kbug ("count:%d type:%d\n", (int)count, type);
+#if DEBUG_TRANSPORT > 0
+ if (type < STP_MAX_CMD)
+ _dbug("Got %s. len=%d\n", _stp_command_name[type], (int)count);
+#endif
count -= sizeof(int);
buf += sizeof(int);
@@ -90,9 +93,9 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
struct _stp_msg_start st;
if (count < sizeof(st))
return 0;
- if (copy_from_user (&st, buf, sizeof(st)))
+ if (copy_from_user(&st, buf, sizeof(st)))
return -EFAULT;
- _stp_handle_start (&st);
+ _stp_handle_start(&st);
started = 1;
}
break;
@@ -107,11 +110,11 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
#endif
case STP_READY:
/* request symbolic information */
- _stp_ask_for_symbols();
+ _stp_ask_for_symbols();
break;
-
+
default:
- errk ("invalid command type %d\n", type);
+ errk("invalid command type %d\n", type);
return -EINVAL;
}
@@ -130,55 +133,55 @@ struct _stp_buffer {
static DECLARE_WAIT_QUEUE_HEAD(_stp_ctl_wq);
static DECLARE_WAIT_QUEUE_HEAD(_stp_sym_wq);
-#ifdef DEBUG
-static void _stp_ctl_write_dbug (int type, void *data, int len)
+#if DEBUG_TRANSPORT > 0
+static void _stp_ctl_write_dbug(int type, void *data, int len)
{
char buf[64];
switch (type) {
case STP_START:
- printk("_stp_ctl_write: sending STP_START\n");
+ _dbug("sending STP_START\n");
break;
case STP_EXIT:
- printk("_stp_ctl_write: sending STP_EXIT\n");
+ _dbug("sending STP_EXIT\n");
break;
case STP_OOB_DATA:
- snprintf(buf, sizeof(buf), "%s", (char *)data);
- printk("_stp_ctl_write: sending %d bytes of STP_OOB_DATA: %s\n", len, buf);
+ snprintf(buf, sizeof(buf), "%s", (char *)data);
+ _dbug("sending %d bytes of STP_OOB_DATA: %s\n", len, buf);
break;
case STP_SYSTEM:
- snprintf(buf, sizeof(buf), "%s", (char *)data);
- printk("_stp_ctl_write: sending STP_SYSTEM: %s\n", buf);
+ snprintf(buf, sizeof(buf), "%s", (char *)data);
+ _dbug("sending STP_SYSTEM: %s\n", buf);
break;
case STP_TRANSPORT:
- printk("_stp_ctl_write: sending STP_TRANSPORT\n");
+ _dbug("sending STP_TRANSPORT\n");
break;
default:
- printk("_stp_ctl_write: ERROR: unknown message type: %d\n", type);
+ _dbug("ERROR: unknown message type: %d\n", type);
break;
}
}
-static void _stp_sym_write_dbug (int type, void *data, int len)
+static void _stp_sym_write_dbug(int type, void *data, int len)
{
switch (type) {
case STP_SYMBOLS:
- printk("_stp_sym_write: sending STP_SYMBOLS\n");
+ _dbug("sending STP_SYMBOLS\n");
break;
case STP_MODULE:
- printk("_stp_sym_write: sending STP_MODULE\n");
+ _dbug("sending STP_MODULE\n");
break;
default:
- printk("_stp_sym_write: ERROR: unknown message type: %d\n", type);
+ _dbug("ERROR: unknown message type: %d\n", type);
break;
}
}
#endif
-static int _stp_ctl_write (int type, void *data, unsigned len)
+static int _stp_ctl_write(int type, void *data, unsigned len)
{
struct _stp_buffer *bptr;
unsigned long flags;
- unsigned numtrylock;
-#ifdef DEBUG
+
+#if DEBUG_TRANSPORT > 0
_stp_ctl_write_dbug(type, data, len);
#endif
@@ -186,47 +189,29 @@ static int _stp_ctl_write (int type, void *data, unsigned len)
if (unlikely(len > STP_CTL_BUFFER_SIZE))
return 0;
- numtrylock = 0;
- while (!spin_trylock_irqsave (&_stp_pool_lock, flags) && (++numtrylock < MAXTRYLOCK))
- ndelay (TRYLOCKDELAY);
- if (unlikely (numtrylock >= MAXTRYLOCK))
- return 0;
-
- if (unlikely(list_empty(&_stp_pool_q))) {
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
- dbug("_stp_pool_q empty\n");
+ /* get a buffer from the free pool */
+ bptr = _stp_mempool_alloc(_stp_pool_q);
+ if (unlikely(bptr == NULL))
return -1;
- }
-
- /* get the next buffer from the pool */
- bptr = (struct _stp_buffer *)_stp_pool_q.next;
- list_del_init(&bptr->list);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
bptr->type = type;
memcpy(bptr->buf, data, len);
bptr->len = len;
-
- /* put it on the pool of ready buffers */
- numtrylock = 0;
- while (!spin_trylock_irqsave (&_stp_ctl_ready_lock, flags) && (++numtrylock < MAXTRYLOCK))
- ndelay (TRYLOCKDELAY);
-
- if (unlikely (numtrylock >= MAXTRYLOCK))
- return 0;
+ /* put it on the pool of ready buffers */
+ spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
list_add_tail(&bptr->list, &_stp_ctl_ready_q);
spin_unlock_irqrestore(&_stp_ctl_ready_lock, flags);
return len;
}
-static int _stp_sym_write (int type, void *data, unsigned len)
+static int _stp_sym_write(int type, void *data, unsigned len)
{
struct _stp_buffer *bptr;
unsigned long flags;
-#ifdef DEBUG
+#if DEBUG_TRANSPORT > 0
_stp_sym_write_dbug(type, data, len);
#endif
@@ -234,24 +219,17 @@ static int _stp_sym_write (int type, void *data, unsigned len)
if (unlikely(len > STP_CTL_BUFFER_SIZE))
return 0;
- spin_lock_irqsave (&_stp_pool_lock, flags);
- if (unlikely(list_empty(&_stp_pool_q))) {
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
- dbug("_stp_pool_q empty\n");
+ /* get a buffer from the free pool */
+ bptr = _stp_mempool_alloc(_stp_pool_q);
+ if (unlikely(bptr == NULL))
return -1;
- }
-
- /* get the next buffer from the pool */
- bptr = (struct _stp_buffer *)_stp_pool_q.next;
- list_del_init(&bptr->list);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
bptr->type = type;
memcpy(bptr->buf, data, len);
bptr->len = len;
-
+
/* put it on the pool of ready buffers */
- spin_lock_irqsave (&_stp_sym_ready_lock, flags);
+ spin_lock_irqsave(&_stp_sym_ready_lock, flags);
list_add_tail(&bptr->list, &_stp_sym_ready_q);
spin_unlock_irqrestore(&_stp_sym_ready_lock, flags);
@@ -262,25 +240,24 @@ static int _stp_sym_write (int type, void *data, unsigned len)
}
/* send commands with timeout and retry */
-static int _stp_ctl_send (int type, void *data, int len)
+static int _stp_ctl_send(int type, void *data, int len)
{
int err, trylimit = 50;
- kbug("ctl_send: type=%d len=%d\n", type, len);
+ kbug(DEBUG_TRANSPORT, "ctl_send: type=%d len=%d\n", type, len);
if (unlikely(type == STP_SYMBOLS || type == STP_MODULE)) {
while ((err = _stp_sym_write(type, data, len)) < 0 && trylimit--)
- msleep (5);
+ msleep(5);
} else {
while ((err = _stp_ctl_write(type, data, len)) < 0 && trylimit--)
- msleep (5);
+ msleep(5);
if (err > 0)
wake_up_interruptible(&_stp_ctl_wq);
}
- kbug("returning %d\n", err);
+ kbug(DEBUG_TRANSPORT, "returning %d\n", err);
return err;
}
-static ssize_t
-_stp_sym_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t _stp_sym_read_cmd(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
struct _stp_buffer *bptr;
int len;
@@ -296,7 +273,7 @@ _stp_sym_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
return -ERESTARTSYS;
spin_lock_irqsave(&_stp_sym_ready_lock, flags);
}
-
+
/* get the next buffer off the ready list */
bptr = (struct _stp_buffer *)_stp_sym_ready_q.next;
list_del_init(&bptr->list);
@@ -314,15 +291,12 @@ _stp_sym_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
}
/* put it on the pool of free buffers */
- spin_lock_irqsave(&_stp_pool_lock, flags);
- list_add_tail(&bptr->list, &_stp_pool_q);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
+ _stp_mempool_free(bptr);
return len;
}
-static ssize_t
-_stp_ctl_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t _stp_ctl_read_cmd(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
struct _stp_buffer *bptr;
int len;
@@ -338,7 +312,7 @@ _stp_ctl_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
return -ERESTARTSYS;
spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
}
-
+
/* get the next buffer off the ready list */
bptr = (struct _stp_buffer *)_stp_ctl_ready_q.next;
list_del_init(&bptr->list);
@@ -356,15 +330,13 @@ _stp_ctl_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
}
/* put it on the pool of free buffers */
- spin_lock_irqsave(&_stp_pool_lock, flags);
- list_add_tail(&bptr->list, &_stp_pool_q);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
+ _stp_mempool_free(bptr);
return len;
}
static int _stp_sym_opens = 0;
-static int _stp_sym_open_cmd (struct inode *inode, struct file *file)
+static int _stp_sym_open_cmd(struct inode *inode, struct file *file)
{
/* only allow one reader */
if (_stp_sym_opens)
@@ -374,14 +346,14 @@ static int _stp_sym_open_cmd (struct inode *inode, struct file *file)
return 0;
}
-static int _stp_sym_close_cmd (struct inode *inode, struct file *file)
+static int _stp_sym_close_cmd(struct inode *inode, struct file *file)
{
if (_stp_sym_opens)
_stp_sym_opens--;
return 0;
}
-static int _stp_ctl_open_cmd (struct inode *inode, struct file *file)
+static int _stp_ctl_open_cmd(struct inode *inode, struct file *file)
{
if (_stp_attached)
return -1;
@@ -390,7 +362,7 @@ static int _stp_ctl_open_cmd (struct inode *inode, struct file *file)
return 0;
}
-static int _stp_ctl_close_cmd (struct inode *inode, struct file *file)
+static int _stp_ctl_close_cmd(struct inode *inode, struct file *file)
{
if (_stp_attached)
_stp_detach();
@@ -416,12 +388,12 @@ static struct file_operations _stp_sym_fops_cmd = {
static struct dentry *_stp_cmd_file = NULL;
static struct dentry *_stp_sym_file = NULL;
-static int _stp_register_ctl_channel (void)
+static int _stp_register_ctl_channel(void)
{
int i;
struct list_head *p, *tmp;
char buf[32];
-
+
if (_stp_utt == NULL) {
errk("_expected _stp_utt to be set.\n");
return -1;
@@ -429,21 +401,16 @@ static int _stp_register_ctl_channel (void)
INIT_LIST_HEAD(&_stp_ctl_ready_q);
INIT_LIST_HEAD(&_stp_sym_ready_q);
- INIT_LIST_HEAD(&_stp_pool_q);
/* allocate buffers */
- for (i = 0; i < STP_DEFAULT_BUFFERS; i++) {
- p = (struct list_head *)_stp_kmalloc(sizeof(struct _stp_buffer));
- // printk("allocated buffer at %lx\n", (long)p);
- if (!p)
- goto err0;
- _stp_allocated_net_memory += sizeof(struct _stp_buffer);
- list_add (p, &_stp_pool_q);
- }
+ _stp_pool_q = _stp_mempool_init(sizeof(struct _stp_buffer), STP_DEFAULT_BUFFERS);
+ if (unlikely(_stp_pool_q == NULL))
+ goto err0;
+ _stp_allocated_net_memory += sizeof(struct _stp_buffer) * STP_DEFAULT_BUFFERS;
/* create [debugfs]/systemtap/module_name/.cmd */
_stp_cmd_file = debugfs_create_file(".cmd", 0600, _stp_utt->dir, NULL, &_stp_ctl_fops_cmd);
- if (_stp_cmd_file == NULL)
+ if (_stp_cmd_file == NULL)
goto err0;
_stp_cmd_file->d_inode->i_uid = _stp_uid;
_stp_cmd_file->d_inode->i_gid = _stp_gid;
@@ -455,35 +422,29 @@ static int _stp_register_ctl_channel (void)
return 0;
err0:
- if (_stp_cmd_file) debugfs_remove(_stp_cmd_file);
-
- list_for_each_safe(p, tmp, &_stp_pool_q) {
- list_del(p);
- _stp_kfree(p);
- }
- errk ("Error creating systemtap debugfs entries.\n");
+ if (_stp_cmd_file)
+ debugfs_remove(_stp_cmd_file);
+ _stp_mempool_destroy(_stp_pool_q);
+ errk("Error creating systemtap debugfs entries.\n");
return -1;
}
-
-static void _stp_unregister_ctl_channel (void)
+static void _stp_unregister_ctl_channel(void)
{
struct list_head *p, *tmp;
- if (_stp_sym_file) debugfs_remove(_stp_sym_file);
- if (_stp_cmd_file) debugfs_remove(_stp_cmd_file);
+ if (_stp_sym_file)
+ debugfs_remove(_stp_sym_file);
+ if (_stp_cmd_file)
+ debugfs_remove(_stp_cmd_file);
- /* free memory pools */
- list_for_each_safe(p, tmp, &_stp_pool_q) {
- list_del(p);
- _stp_kfree(p);
- }
+ /* Return memory to pool and free it. */
list_for_each_safe(p, tmp, &_stp_sym_ready_q) {
list_del(p);
- _stp_kfree(p);
+ _stp_mempool_free(p);
}
list_for_each_safe(p, tmp, &_stp_ctl_ready_q) {
list_del(p);
- _stp_kfree(p);
+ _stp_mempool_free(p);
}
+ _stp_mempool_destroy(_stp_pool_q);
}
-
diff --git a/runtime/transport/procfs.c b/runtime/transport/procfs.c
index 33f6db33..2afea1c9 100644
--- a/runtime/transport/procfs.c
+++ b/runtime/transport/procfs.c
@@ -12,18 +12,16 @@
#define STP_DEFAULT_BUFFERS 256
static int _stp_current_buffers = STP_DEFAULT_BUFFERS;
+static _stp_mempool_t *_stp_pool_q;
static struct list_head _stp_ctl_ready_q;
static struct list_head _stp_sym_ready_q;
-static struct list_head _stp_pool_q;
-DEFINE_SPINLOCK(_stp_pool_lock);
DEFINE_SPINLOCK(_stp_ctl_ready_lock);
DEFINE_SPINLOCK(_stp_sym_ready_lock);
#ifdef STP_BULKMODE
extern int _stp_relay_flushing;
/* handle the per-cpu subbuf info read for relayfs */
-static ssize_t
-_stp_proc_read (struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t _stp_proc_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
int num;
struct _stp_buf_info out;
@@ -46,8 +44,7 @@ _stp_proc_read (struct file *file, char __user *buf, size_t count, loff_t *ppos)
}
/* handle the per-cpu subbuf info write for relayfs */
-static ssize_t _stp_proc_write (struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t _stp_proc_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
struct _stp_consumed_info info;
int cpu = *(int *)(PDE(file->f_dentry->d_inode)->data);
@@ -65,8 +62,7 @@ static struct file_operations _stp_proc_fops = {
};
#endif /* STP_BULKMODE */
-static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t _stp_sym_write_cmd(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
static int saved_type = 0;
int type;
@@ -74,7 +70,7 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
if (count < sizeof(int32_t))
return 0;
- /* Allow sending of packet type followed by data in the next packet.*/
+ /* Allow sending of packet type followed by data in the next packet. */
if (count == sizeof(int32_t)) {
if (get_user(saved_type, (int __user *)buf))
return -EFAULT;
@@ -88,11 +84,14 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
count -= sizeof(int);
buf += sizeof(int);
}
-
- // kbug ("count:%d type:%d\n", (int)count, type);
+
+#if DEBUG_TRANSPORT > 0
+ if (type < STP_MAX_CMD)
+ _dbug("Got %s. len=%d\n", _stp_command_name[type], (int)count);
+#endif
switch (type) {
- case STP_SYMBOLS:
+ case STP_SYMBOLS:
count = _stp_do_symbols(buf, count);
break;
case STP_MODULE:
@@ -100,19 +99,19 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
count = _stp_do_module(buf, count);
else {
/* count == 1 indicates end of initial modules list */
- _stp_ctl_send(STP_TRANSPORT, NULL, 0);
+ _stp_ctl_send(STP_TRANSPORT, NULL, 0);
}
break;
default:
- errk ("invalid symbol command type %d\n", type);
+ errk("invalid symbol command type %d\n", type);
return -EINVAL;
}
return count;
}
-static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
+
+static ssize_t _stp_ctl_write_cmd(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int type;
static int started = 0;
@@ -123,7 +122,10 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
if (get_user(type, (int __user *)buf))
return -EFAULT;
- // kbug ("count:%d type:%d\n", count, type);
+#if DEBUG_TRANSPORT > 0
+ if (type < STP_MAX_CMD)
+ _dbug("Got %s. len=%d\n", _stp_command_name[type], (int)count);
+#endif
count -= sizeof(int);
buf += sizeof(int);
@@ -134,9 +136,9 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
struct _stp_msg_start st;
if (count < sizeof(st))
return 0;
- if (copy_from_user (&st, buf, sizeof(st)))
+ if (copy_from_user(&st, buf, sizeof(st)))
return -EFAULT;
- _stp_handle_start (&st);
+ _stp_handle_start(&st);
started = 1;
}
break;
@@ -145,10 +147,10 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
break;
case STP_READY:
/* request symbolic information */
- _stp_ask_for_symbols();
+ _stp_ask_for_symbols();
break;
default:
- errk ("invalid command type %d\n", type);
+ errk("invalid command type %d\n", type);
return -EINVAL;
}
@@ -165,76 +167,66 @@ struct _stp_buffer {
static DECLARE_WAIT_QUEUE_HEAD(_stp_ctl_wq);
static DECLARE_WAIT_QUEUE_HEAD(_stp_sym_wq);
-#ifdef DEBUG
-static void _stp_ctl_write_dbug (int type, void *data, int len)
+#if DEBUG_TRANSPORT > 0
+static void _stp_ctl_write_dbug(int type, void *data, int len)
{
char buf[64];
switch (type) {
- case STP_REALTIME_DATA:
- break;
case STP_START:
- printk("_stp_ctl_write: sending STP_START\n");
+ _dbug("sending STP_START\n");
break;
case STP_EXIT:
- printk("_stp_ctl_write: sending STP_EXIT\n");
+ _dbug("sending STP_EXIT\n");
break;
case STP_OOB_DATA:
- snprintf(buf, sizeof(buf), "%s", (char *)data);
- printk("_stp_ctl_write: sending %d bytes of STP_OOB_DATA: %s\n", len, buf);
+ snprintf(buf, sizeof(buf), "%s", (char *)data);
+ _dbug("sending %d bytes of STP_OOB_DATA: %s\n", len, buf);
break;
case STP_SYSTEM:
- snprintf(buf, sizeof(buf), "%s", (char *)data);
- printk("_stp_ctl_write: sending STP_SYSTEM: %s\n", buf);
+ snprintf(buf, sizeof(buf), "%s", (char *)data);
+ _dbug("sending STP_SYSTEM: %s\n", buf);
break;
case STP_TRANSPORT:
- printk("_stp_ctl_write: sending STP_TRANSPORT\n");
+ _dbug("sending STP_TRANSPORT\n");
break;
default:
- printk("_stp_ctl_write: ERROR: unknown message type: %d\n", type);
+ _dbug("ERROR: unknown message type: %d\n", type);
break;
}
}
-static void _stp_sym_write_dbug (int type, void *data, int len)
+static void _stp_sym_write_dbug(int type, void *data, int len)
{
switch (type) {
case STP_SYMBOLS:
- printk("_stp_sym_write: sending STP_SYMBOLS\n");
+ _dbug("sending STP_SYMBOLS\n");
break;
case STP_MODULE:
- printk("_stp_sym_write: sending STP_MODULE\n");
+ _dbug("sending STP_MODULE\n");
break;
default:
- printk("_stp_sym_write: ERROR: unknown message type: %d\n", type);
+ _dbug("ERROR: unknown message type: %d\n", type);
break;
}
}
#endif
-static int _stp_ctl_write (int type, void *data, int len)
+static int _stp_ctl_write(int type, void *data, int len)
{
struct _stp_buffer *bptr;
unsigned long flags;
- unsigned numtrylock;
-#ifdef DEBUG
+#if DEBUG_TRANSPORT > 0
_stp_ctl_write_dbug(type, data, len);
#endif
#define WRITE_AGG
#ifdef WRITE_AGG
- numtrylock = 0;
- while (!spin_trylock_irqsave (&_stp_ctl_ready_lock, flags) && (++numtrylock < MAXTRYLOCK))
- ndelay (TRYLOCKDELAY);
- if (unlikely (numtrylock >= MAXTRYLOCK))
- return 0;
-
+ spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
if (!list_empty(&_stp_ctl_ready_q)) {
bptr = (struct _stp_buffer *)_stp_ctl_ready_q.prev;
- if (bptr->len + len <= STP_BUFFER_SIZE
- && type == STP_REALTIME_DATA
- && bptr->type == STP_REALTIME_DATA) {
- memcpy (bptr->buf + bptr->len, data, len);
+ if (bptr->len + len <= STP_BUFFER_SIZE && type == STP_REALTIME_DATA && bptr->type == STP_REALTIME_DATA) {
+ memcpy(bptr->buf + bptr->len, data, len);
bptr->len += len;
spin_unlock_irqrestore(&_stp_ctl_ready_lock, flags);
return len;
@@ -247,47 +239,29 @@ static int _stp_ctl_write (int type, void *data, int len)
if (unlikely(len > STP_BUFFER_SIZE))
return 0;
- numtrylock = 0;
- while (!spin_trylock_irqsave (&_stp_pool_lock, flags) && (++numtrylock < MAXTRYLOCK))
- ndelay (TRYLOCKDELAY);
- if (unlikely (numtrylock >= MAXTRYLOCK))
- return 0;
-
- if (unlikely(list_empty(&_stp_pool_q))) {
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
- dbug("_stp_pool_q empty\n");
+ /* get a buffer from the free pool */
+ bptr = _stp_mempool_alloc(_stp_pool_q);
+ if (unlikely(bptr == NULL))
return -1;
- }
-
- /* get the next buffer from the pool */
- bptr = (struct _stp_buffer *)_stp_pool_q.next;
- list_del_init(&bptr->list);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
bptr->type = type;
- memcpy (bptr->buf, data, len);
+ memcpy(bptr->buf, data, len);
bptr->len = len;
-
- /* put it on the pool of ready buffers */
- numtrylock = 0;
- while (!spin_trylock_irqsave (&_stp_ctl_ready_lock, flags) && (++numtrylock < MAXTRYLOCK))
- ndelay (TRYLOCKDELAY);
-
- if (unlikely (numtrylock >= MAXTRYLOCK))
- return 0;
+ /* put it on the pool of ready buffers */
+ spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
list_add_tail(&bptr->list, &_stp_ctl_ready_q);
spin_unlock_irqrestore(&_stp_ctl_ready_lock, flags);
return len;
}
-static int _stp_sym_write (int type, void *data, unsigned len)
+static int _stp_sym_write(int type, void *data, unsigned len)
{
struct _stp_buffer *bptr;
unsigned long flags;
-#ifdef DEBUG
+#if DEBUG_TRANSPORT > 0
_stp_sym_write_dbug(type, data, len);
#endif
@@ -295,24 +269,17 @@ static int _stp_sym_write (int type, void *data, unsigned len)
if (unlikely(len > STP_BUFFER_SIZE))
return 0;
- spin_lock_irqsave (&_stp_pool_lock, flags);
- if (unlikely(list_empty(&_stp_pool_q))) {
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
- dbug("_stp_pool_q empty\n");
+ /* get a buffer from the free pool */
+ bptr = _stp_mempool_alloc(_stp_pool_q);
+ if (unlikely(bptr == NULL))
return -1;
- }
-
- /* get the next buffer from the pool */
- bptr = (struct _stp_buffer *)_stp_pool_q.next;
- list_del_init(&bptr->list);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
bptr->type = type;
memcpy(bptr->buf, data, len);
bptr->len = len;
/* put it on the pool of ready buffers */
- spin_lock_irqsave (&_stp_sym_ready_lock, flags);
+ spin_lock_irqsave(&_stp_sym_ready_lock, flags);
list_add_tail(&bptr->list, &_stp_sym_ready_q);
spin_unlock_irqrestore(&_stp_sym_ready_lock, flags);
@@ -323,23 +290,24 @@ static int _stp_sym_write (int type, void *data, unsigned len)
}
/* send commands with timeout and retry */
-static int _stp_ctl_send (int type, void *data, int len)
+static int _stp_ctl_send(int type, void *data, int len)
{
int err, trylimit = 50;
+ kbug(DEBUG_TRANSPORT, "ctl_send: type=%d len=%d\n", type, len);
if (unlikely(type == STP_SYMBOLS || type == STP_MODULE)) {
while ((err = _stp_sym_write(type, data, len)) < 0 && trylimit--)
- msleep (5);
+ msleep(5);
} else {
while ((err = _stp_ctl_write(type, data, len)) < 0 && trylimit--)
- msleep (5);
+ msleep(5);
if (err > 0)
wake_up_interruptible(&_stp_ctl_wq);
}
+ kbug(DEBUG_TRANSPORT, "returning %d\n", err);
return err;
}
-static ssize_t
-_stp_sym_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t _stp_sym_read_cmd(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
struct _stp_buffer *bptr;
int len;
@@ -355,7 +323,7 @@ _stp_sym_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
return -ERESTARTSYS;
spin_lock_irqsave(&_stp_sym_ready_lock, flags);
}
-
+
/* get the next buffer off the ready list */
bptr = (struct _stp_buffer *)_stp_sym_ready_q.next;
list_del_init(&bptr->list);
@@ -373,15 +341,12 @@ _stp_sym_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
}
/* put it on the pool of free buffers */
- spin_lock_irqsave(&_stp_pool_lock, flags);
- list_add_tail(&bptr->list, &_stp_pool_q);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
+ _stp_mempool_free(bptr);
return len;
}
-static ssize_t
-_stp_ctl_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t _stp_ctl_read_cmd(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
struct _stp_buffer *bptr;
int len;
@@ -397,7 +362,7 @@ _stp_ctl_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
return -ERESTARTSYS;
spin_lock_irqsave(&_stp_ctl_ready_lock, flags);
}
-
+
/* get the next buffer off the ready list */
bptr = (struct _stp_buffer *)_stp_ctl_ready_q.next;
list_del_init(&bptr->list);
@@ -415,15 +380,13 @@ _stp_ctl_read_cmd (struct file *file, char __user *buf, size_t count, loff_t *pp
}
/* put it on the pool of free buffers */
- spin_lock_irqsave(&_stp_pool_lock, flags);
- list_add_tail(&bptr->list, &_stp_pool_q);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
+ _stp_mempool_free(bptr);
return len;
}
static int _stp_sym_opens = 0;
-static int _stp_sym_open_cmd (struct inode *inode, struct file *file)
+static int _stp_sym_open_cmd(struct inode *inode, struct file *file)
{
/* only allow one reader */
if (_stp_sym_opens)
@@ -433,14 +396,14 @@ static int _stp_sym_open_cmd (struct inode *inode, struct file *file)
return 0;
}
-static int _stp_sym_close_cmd (struct inode *inode, struct file *file)
+static int _stp_sym_close_cmd(struct inode *inode, struct file *file)
{
if (_stp_sym_opens)
_stp_sym_opens--;
return 0;
}
-static int _stp_ctl_open_cmd (struct inode *inode, struct file *file)
+static int _stp_ctl_open_cmd(struct inode *inode, struct file *file)
{
if (_stp_attached)
return -1;
@@ -449,7 +412,7 @@ static int _stp_ctl_open_cmd (struct inode *inode, struct file *file)
return 0;
}
-static int _stp_ctl_close_cmd (struct inode *inode, struct file *file)
+static int _stp_ctl_close_cmd(struct inode *inode, struct file *file)
{
if (_stp_attached)
_stp_detach();
@@ -482,46 +445,14 @@ static int my_proc_match(int len, const char *name, struct proc_dir_entry *de)
/* set the number of buffers to use to 'num' */
static int _stp_set_buffers(int num)
{
- int i;
- struct list_head *p;
- unsigned long flags;
-
- //printk("stp_set_buffers %d\n", num);
-
- if (num == 0 || num == _stp_current_buffers)
- return _stp_current_buffers;
-
- if (num > _stp_current_buffers) {
- for (i = 0; i < num - _stp_current_buffers; i++) {
- p = (struct list_head *)_stp_kmalloc(sizeof(struct _stp_buffer));
- if (!p) {
- _stp_current_buffers += i;
- goto err;
- }
- _stp_allocated_net_memory += sizeof(struct _stp_buffer);
- spin_lock_irqsave(&_stp_pool_lock, flags);
- list_add (p, &_stp_pool_q);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
- }
- } else {
- for (i = 0; i < _stp_current_buffers - num; i++) {
- spin_lock_irqsave(&_stp_pool_lock, flags);
- p = _stp_pool_q.next;
- list_del(p);
- spin_unlock_irqrestore(&_stp_pool_lock, flags);
- _stp_kfree(p);
- }
- }
- _stp_current_buffers = num;
-err:
- return _stp_current_buffers;
+ kbug(DEBUG_TRANSPORT, "stp_set_buffers %d\n", num);
+ return _stp_mempool_resize(_stp_pool_q, num);
}
-static int _stp_ctl_read_bufsize (char *page, char **start, off_t off,
- int count, int *eof, void *data)
+static int _stp_ctl_read_bufsize(char *page, char **start, off_t off, int count, int *eof, void *data)
{
int len = sprintf(page, "%d,%d\n", _stp_nsubbufs, _stp_subbuf_size);
- if (len <= off+count)
+ if (len <= off + count)
*eof = 1;
*start = page + off;
len -= off;
@@ -532,7 +463,7 @@ static int _stp_ctl_read_bufsize (char *page, char **start, off_t off,
return len;
}
-static int _stp_register_ctl_channel (void)
+static int _stp_register_ctl_channel(void)
{
int i;
const char *dirname = "systemtap";
@@ -546,17 +477,12 @@ static int _stp_register_ctl_channel (void)
INIT_LIST_HEAD(&_stp_ctl_ready_q);
INIT_LIST_HEAD(&_stp_sym_ready_q);
- INIT_LIST_HEAD(&_stp_pool_q);
/* allocate buffers */
- for (i = 0; i < STP_DEFAULT_BUFFERS; i++) {
- p = (struct list_head *)_stp_kmalloc(sizeof(struct _stp_buffer));
- // printk("allocated buffer at %lx\n", (long)p);
- if (!p)
- goto err0;
- _stp_allocated_net_memory += sizeof(struct _stp_buffer);
- list_add (p, &_stp_pool_q);
- }
+ _stp_pool_q = _stp_mempool_init(sizeof(struct _stp_buffer), STP_DEFAULT_BUFFERS);
+ if (unlikely(_stp_pool_q == NULL))
+ goto err0;
+ _stp_allocated_net_memory += sizeof(struct _stp_buffer) * STP_DEFAULT_BUFFERS;
if (!_stp_mkdir_proc_module())
goto err0;
@@ -565,15 +491,15 @@ static int _stp_register_ctl_channel (void)
/* now for each cpu "n", create /proc/systemtap/module_name/n */
for_each_cpu(i) {
sprintf(buf, "%d", i);
- de = create_proc_entry (buf, 0600, _stp_proc_root);
- if (de == NULL)
+ de = create_proc_entry(buf, 0600, _stp_proc_root);
+ if (de == NULL)
goto err1;
de->uid = _stp_uid;
de->gid = _stp_gid;
de->proc_fops = &_stp_proc_fops;
de->data = _stp_kmalloc(sizeof(int));
if (de->data == NULL) {
- remove_proc_entry (buf, _stp_proc_root);
+ remove_proc_entry(buf, _stp_proc_root);
goto err1;
}
*(int *)de->data = i;
@@ -582,48 +508,44 @@ static int _stp_register_ctl_channel (void)
#endif /* STP_BULKMODE */
/* create /proc/systemtap/module_name/.cmd */
- de = create_proc_entry (".cmd", 0600, _stp_proc_root);
- if (de == NULL)
+ de = create_proc_entry(".cmd", 0600, _stp_proc_root);
+ if (de == NULL)
goto err1;
de->uid = _stp_uid;
de->gid = _stp_gid;
de->proc_fops = &_stp_proc_fops_cmd;
/* create /proc/systemtap/module_name/.symbols */
- de = create_proc_entry (".symbols", 0600, _stp_proc_root);
- if (de == NULL)
+ de = create_proc_entry(".symbols", 0600, _stp_proc_root);
+ if (de == NULL)
goto err2;
de->proc_fops = &_stp_sym_fops_cmd;
return 0;
err2:
- remove_proc_entry (".cmd", _stp_proc_root);
+ remove_proc_entry(".cmd", _stp_proc_root);
err1:
#ifdef STP_BULKMODE
for (de = _stp_proc_root->subdir; de; de = de->next)
- _stp_kfree (de->data);
+ _stp_kfree(de->data);
for_each_cpu(j) {
if (j == i)
break;
sprintf(buf, "%d", j);
- remove_proc_entry (buf, _stp_proc_root);
-
+ remove_proc_entry(buf, _stp_proc_root);
+
}
- if (bs) remove_proc_entry ("bufsize", _stp_proc_root);
+ if (bs)
+ remove_proc_entry("bufsize", _stp_proc_root);
#endif /* STP_BULKMODE */
_stp_rmdir_proc_module();
err0:
- list_for_each_safe(p, tmp, &_stp_pool_q) {
- list_del(p);
- _stp_kfree(p);
- }
-
- errk ("Error creating systemtap /proc entries.\n");
+ _stp_mempool_destroy(_stp_pool_q);
+ errk("Error creating systemtap /proc entries.\n");
return -1;
}
-
-static void _stp_unregister_ctl_channel (void)
+static void _stp_unregister_ctl_channel(void)
{
struct list_head *p, *tmp;
char buf[32];
@@ -632,31 +554,27 @@ static void _stp_unregister_ctl_channel (void)
struct proc_dir_entry *de;
kbug("unregistering procfs\n");
for (de = _stp_proc_root->subdir; de; de = de->next)
- _stp_kfree (de->data);
+ _stp_kfree(de->data);
for_each_cpu(i) {
sprintf(buf, "%d", i);
- remove_proc_entry (buf, _stp_proc_root);
+ remove_proc_entry(buf, _stp_proc_root);
}
- remove_proc_entry ("bufsize", _stp_proc_root);
+ remove_proc_entry("bufsize", _stp_proc_root);
#endif /* STP_BULKMODE */
- remove_proc_entry (".symbols", _stp_proc_root);
- remove_proc_entry (".cmd", _stp_proc_root);
+ remove_proc_entry(".symbols", _stp_proc_root);
+ remove_proc_entry(".cmd", _stp_proc_root);
_stp_rmdir_proc_module();
- /* free memory pools */
- list_for_each_safe(p, tmp, &_stp_pool_q) {
- list_del(p);
- _stp_kfree(p);
- }
+ /* Return memory to pool and free it. */
list_for_each_safe(p, tmp, &_stp_sym_ready_q) {
list_del(p);
- _stp_kfree(p);
+ _stp_mempool_free(p);
}
list_for_each_safe(p, tmp, &_stp_ctl_ready_q) {
list_del(p);
- _stp_kfree(p);
+ _stp_mempool_free(p);
}
+ _stp_mempool_destroy(_stp_pool_q);
}
-
diff --git a/runtime/transport/symbols.c b/runtime/transport/symbols.c
index e740dde8..8c453a55 100644
--- a/runtime/transport/symbols.c
+++ b/runtime/transport/symbols.c
@@ -16,16 +16,6 @@
#define _SYMBOLS_C_
#include "../sym.h"
-DEFINE_SPINLOCK(_stp_module_lock);
-#define STP_TRYLOCK_MODULES ({ \
- int numtrylock = 0; \
- while (!spin_trylock_irqsave (&_stp_module_lock, flags) && (++numtrylock < MAXTRYLOCK)) \
- ndelay (TRYLOCKDELAY); \
- (numtrylock >= MAXTRYLOCK); \
- })
-#define STP_LOCK_MODULES spin_lock_irqsave(&_stp_module_lock, flags)
-#define STP_UNLOCK_MODULES spin_unlock_irqrestore(&_stp_module_lock, flags)
-
static char *_stp_symbol_data = NULL;
static int _stp_symbol_state = 0;
static char *_stp_module_data = NULL;
@@ -63,7 +53,7 @@ static unsigned _stp_get_sym_sizes(struct module *m, unsigned *dsize)
}
/* allocate space for a module and symbols */
-static struct _stp_module * _stp_alloc_module(unsigned num, unsigned datasize)
+static struct _stp_module * _stp_alloc_module(unsigned num, unsigned datasize, unsigned unwindsize)
{
struct _stp_module *mod = (struct _stp_module *)_stp_kzalloc(sizeof(struct _stp_module));
if (mod == NULL)
@@ -85,6 +75,14 @@ static struct _stp_module * _stp_alloc_module(unsigned num, unsigned datasize)
mod->allocated |= 2;
}
+ mod->unwind_data = _stp_kmalloc(unwindsize);
+ if (mod->unwind_data == NULL) {
+ mod->unwind_data = _stp_vmalloc(unwindsize);
+ if (mod->unwind_data == NULL)
+ goto bad;
+ mod->allocated |= 4;
+ }
+
mod->num_symbols = num;
return mod;
@@ -97,19 +95,40 @@ bad:
_stp_kfree(mod->symbols);
mod->symbols = NULL;
}
+ if (mod->symbol_data) {
+ if (mod->allocated & 2)
+ _stp_vfree(mod->symbol_data);
+ else
+ _stp_kfree(mod->symbol_data);
+ mod->symbol_data = NULL;
+ }
+ _stp_kfree(mod);
+ if (mod->symbols) {
+ if (mod->allocated & 1)
+ _stp_vfree(mod->symbols);
+ else
+ _stp_kfree(mod->symbols);
+ mod->symbols = NULL;
+ }
_stp_kfree(mod);
}
return NULL;
}
-static struct _stp_module * _stp_alloc_module_from_module (struct module *m)
+static struct _stp_module * _stp_alloc_module_from_module (struct module *m, uint32_t unwind_len)
{
unsigned datasize, num = _stp_get_sym_sizes(m, &datasize);
- return _stp_alloc_module(num, datasize);
+ return _stp_alloc_module(num, datasize, unwind_len);
}
static void _stp_free_module(struct _stp_module *mod)
{
+ /* The module write lock is held. Any prior readers of this */
+ /* module's data will have read locks and need to finish before */
+ /* the memory is freed. */
+ write_lock(&mod->lock);
+ write_unlock(&mod->lock); /* there will be no more readers */
+
/* free symbol memory */
if (mod->symbols) {
if (mod->allocated & 1)
@@ -126,21 +145,30 @@ static void _stp_free_module(struct _stp_module *mod)
mod->symbol_data = NULL;
}
+ if (mod->unwind_data) {
+ if (mod->allocated & 4)
+ _stp_vfree(mod->unwind_data);
+ else
+ _stp_kfree(mod->unwind_data);
+ mod->unwind_data = NULL;
+
+ }
if (mod->sections) {
_stp_kfree(mod->sections);
mod->sections = NULL;
}
+
/* free module memory */
_stp_kfree(mod);
}
/* Delete a module and free its memory. */
-/* The lock should already be held before calling this. */
+/* The module lock should already be held before calling this. */
static void _stp_del_module(struct _stp_module *mod)
{
int i, num;
- // kbug("deleting %s\n", mod->name);
+ // kbug(DEBUG_SYMBOLS, "deleting %s\n", mod->name);
/* signal relocation code to clear its cache */
_stp_module_relocate((char *)-1, NULL, 0);
@@ -185,7 +213,7 @@ static unsigned long _stp_kallsyms_lookup_name(const char *name);
static int _stp_do_symbols(const char __user *buf, int count)
{
struct _stp_symbol *s;
- unsigned datasize, num;
+ unsigned datasize, num, unwindsize;
int i;
switch (_stp_symbol_state) {
@@ -198,23 +226,26 @@ static int _stp_do_symbols(const char __user *buf, int count)
return -EFAULT;
if (get_user(datasize, (unsigned __user *)(buf+4)))
return -EFAULT;
- //kbug("num=%d datasize=%d\n", num, datasize);
+ if (get_user(unwindsize, (unsigned __user *)(buf+8)))
+ return -EFAULT;
+ dbug(DEBUG_UNWIND, "num=%d datasize=%d unwindsize=%d\n", num, datasize, unwindsize);
- _stp_modules[0] = _stp_alloc_module(num, datasize);
+ _stp_modules[0] = _stp_alloc_module(num, datasize, unwindsize);
if (_stp_modules[0] == NULL) {
errk("cannot allocate memory\n");
return -EFAULT;
}
+ rwlock_init(&_stp_modules[0]->lock);
_stp_symbol_state = 1;
break;
case 1:
- //kbug("got stap_symbols, count=%d\n", count);
+ dbug(DEBUG_SYMBOLS, "got stap_symbols, count=%d\n", count);
if (copy_from_user ((char *)_stp_modules[0]->symbols, buf, count))
return -EFAULT;
_stp_symbol_state = 2;
break;
case 2:
- //kbug("got symbol data, count=%d buf=%p\n", count, buf);
+ dbug(DEBUG_SYMBOLS, "got symbol data, count=%d buf=%p\n", count, buf);
if (copy_from_user (_stp_modules[0]->symbol_data, buf, count))
return -EFAULT;
_stp_num_modules = 1;
@@ -227,8 +258,19 @@ static int _stp_do_symbols(const char __user *buf, int count)
/* NB: this mapping is used by kernel/_stext pseudo-relocations. */
_stp_modules[0]->text = _stp_kallsyms_lookup_name("_stext");
_stp_modules[0]->data = _stp_kallsyms_lookup_name("_etext");
+ _stp_modules[0]->text_size = _stp_modules[0]->data - _stp_modules[0]->text;
_stp_modules_by_addr[0] = _stp_modules[0];
- //kbug("done with symbol data\n");
+ dbug(DEBUG_SYMBOLS, "Got kernel symbols. text=%p len=%u\n",
+ (int64_t)_stp_modules[0]->text, _stp_modules[0]->text_size);
+ break;
+ case 3:
+ dbug(DEBUG_UNWIND, "got unwind data, count=%d\n", count);
+ _stp_symbol_state = 4;
+ if (copy_from_user (_stp_modules[0]->unwind_data, buf, count)) {
+ _dbug("cfu failed\n");
+ return -EFAULT;
+ }
+ _stp_modules[0]->unwind_data_len = count;
break;
default:
errk("unexpected symbol data of size %d.\n", count);
@@ -266,10 +308,8 @@ static void u32_swap(void *a, void *b, int size)
static void generic_swap(void *a, void *b, int size)
{
- char t;
-
do {
- t = *(char *)a;
+ char t = *(char *)a;
*(char *)a++ = *(char *)b;
*(char *)b++ = t;
} while (--size > 0);
@@ -328,7 +368,7 @@ void _stp_sort(void *base, size_t num, size_t size,
}
/* Create a new _stp_module and load the symbols */
-static struct _stp_module *_stp_load_module_symbols (struct _stp_module *imod)
+static struct _stp_module *_stp_load_module_symbols (struct _stp_module *imod, uint32_t unwind_len)
{
unsigned i, num=0;
struct module *m = (struct module *)imod->module;
@@ -336,12 +376,12 @@ static struct _stp_module *_stp_load_module_symbols (struct _stp_module *imod)
char *dataptr;
if (m == NULL) {
- kbug("imod->module is NULL\n");
+ kbug(DEBUG_SYMBOLS, "imod->module is NULL\n");
return NULL;
}
if (try_module_get(m)) {
- mod = _stp_alloc_module_from_module(m);
+ mod = _stp_alloc_module_from_module(m, unwind_len);
if (mod == NULL) {
module_put(m);
errk("failed to allocate memory for module.\n");
@@ -354,6 +394,8 @@ static struct _stp_module *_stp_load_module_symbols (struct _stp_module *imod)
mod->data = imod->data;
mod->num_sections = imod->num_sections;
mod->sections = imod->sections;
+ mod->text_size = m->core_text_size;
+ rwlock_init(&mod->lock);
/* now copy all the symbols we are interested in */
dataptr = mod->symbol_data;
@@ -375,24 +417,32 @@ static struct _stp_module *_stp_load_module_symbols (struct _stp_module *imod)
return mod;
}
-/* Do we already have this module? */
-static int _stp_module_exists(struct _stp_module *mod)
+/* Remove any old module info from our database */
+static void _stp_module_exists_delete (struct _stp_module *mod)
{
- int i, res;
- unsigned long flags;
- // kbug("exists? %s\n", mod->name);
- STP_LOCK_MODULES;
- for (i = 1; i < _stp_num_modules; i++) {
- res = strcmp(_stp_modules[i]->name, mod->name);
- if (res > 0)
+ int i, num;
+
+ /* remove any old modules with the same name */
+ for (num = 1; num < _stp_num_modules; num++) {
+ if (strcmp(_stp_modules[num]->name, mod->name) == 0) {
+ dbug(DEBUG_SYMBOLS, "found existing module with name %s. Deleting.\n", mod->name);
+ _stp_del_module(_stp_modules[num]);
break;
- if (res == 0 && _stp_modules[i]->module == mod->module) {
- STP_UNLOCK_MODULES;
- return 1;
}
}
- STP_UNLOCK_MODULES;
- return 0;
+
+ /* remove modules with overlapping addresses */
+ for (num = 1; num < _stp_num_modules; num++) {
+ if (mod->text + mod->text_size < _stp_modules_by_addr[num]->text)
+ continue;
+ if (mod->text < _stp_modules_by_addr[num]->text
+ + _stp_modules_by_addr[num]->text_size) {
+ dbug(DEBUG_SYMBOLS, "New module %s overlaps with old module %s. Deleting old.\n",
+ mod->name, _stp_modules_by_addr[num]->name);
+ _stp_del_module(_stp_modules_by_addr[num]);
+ }
+ }
+
}
static int _stp_ins_module(struct _stp_module *mod)
@@ -400,9 +450,11 @@ static int _stp_ins_module(struct _stp_module *mod)
int i, num, res, ret = 0;
unsigned long flags;
- // kbug("insert %s\n", mod->name);
+ // kbug(DEBUG_SYMBOLS, "insert %s\n", mod->name);
- STP_LOCK_MODULES;
+ STP_WLOCK_MODULES;
+
+ _stp_module_exists_delete(mod);
/* check for overflow */
if (_stp_num_modules == STP_MAX_MODULES) {
@@ -412,32 +464,25 @@ static int _stp_ins_module(struct _stp_module *mod)
}
/* insert alphabetically in _stp_modules[] */
- for (num = 1; num < _stp_num_modules; num++) {
- res = strcmp(_stp_modules[num]->name, mod->name);
- if (res < 0)
- continue;
- if (res > 0)
+ for (num = 1; num < _stp_num_modules; num++)
+ if (strcmp(_stp_modules[num]->name, mod->name) > 0)
break;
- _stp_del_module(_stp_modules[num]);
- break;
- }
for (i = _stp_num_modules; i > num; i--)
_stp_modules[i] = _stp_modules[i-1];
_stp_modules[num] = mod;
/* insert by text address in _stp_modules_by_addr[] */
- for (num = 1; num < _stp_num_modules; num++) {
- if (_stp_modules_by_addr[num]->text > mod->text)
+ for (num = 1; num < _stp_num_modules; num++)
+ if (mod->text < _stp_modules_by_addr[num]->text)
break;
- }
for (i = _stp_num_modules; i > num; i--)
_stp_modules_by_addr[i] = _stp_modules_by_addr[i-1];
_stp_modules_by_addr[num] = mod;
-
+
_stp_num_modules++;
done:
- STP_UNLOCK_MODULES;
+ STP_WUNLOCK_MODULES;
return ret;
}
@@ -456,13 +501,13 @@ static int _stp_do_module(const char __user *buf, int count)
if (copy_from_user ((char *)&tmpmod, buf, sizeof(tmpmod)))
return -EFAULT;
- section_len = count - sizeof(tmpmod);
+ section_len = count - sizeof(tmpmod) - tmpmod.unwind_len;
if (section_len <= 0) {
errk("section_len = %d\n", section_len);
return -EFAULT;
}
- kbug("Got module %s, count=%d section_len=%d\n",
- tmpmod.name, count, section_len);
+ dbug(DEBUG_SYMBOLS, "Got module %s, count=%d section_len=%d unwind_len=%d\n",
+ tmpmod.name, count, section_len, tmpmod.unwind_len);
strcpy(mod.name, tmpmod.name);
mod.module = tmpmod.module;
@@ -470,9 +515,6 @@ static int _stp_do_module(const char __user *buf, int count)
mod.data = tmpmod.data;
mod.num_sections = tmpmod.num_sections;
- if (_stp_module_exists(&mod))
- return count;
-
/* copy in section data */
mod.sections = _stp_kmalloc(section_len);
if (mod.sections == NULL) {
@@ -489,18 +531,27 @@ static int _stp_do_module(const char __user *buf, int count)
+ (long)((long)mod.sections + mod.num_sections * sizeof(struct _stp_symbol)));
}
- #ifdef DEBUG_SYMBOLS
+ #if 0
for (i = 0; i < mod.num_sections; i++)
- printk("section %d (stored at %p): %s %lx\n", i, &mod.sections[i], mod.sections[i].symbol, mod.sections[i].addr);
+ _dbug("section %d (stored at %p): %s %lx\n", i, &mod.sections[i], mod.sections[i].symbol, mod.sections[i].addr);
#endif
/* load symbols from tmpmod.module to mod */
- m = _stp_load_module_symbols(&mod);
+ m = _stp_load_module_symbols(&mod, tmpmod.unwind_len);
if (m == NULL) {
_stp_kfree(mod.sections);
return 0;
}
+ dbug(DEBUG_SYMBOLS, "module %s loaded. Text=%p text_size=%u\n", m->name, (int64_t)m->text, m->text_size);
+ /* finally copy unwind info */
+ if (copy_from_user (m->unwind_data, buf+sizeof(tmpmod)+section_len, tmpmod.unwind_len)) {
+ _stp_free_module(m);
+ _stp_kfree(mod.sections);
+ return -EFAULT;
+ }
+ m->unwind_data_len = tmpmod.unwind_len;
+
if (_stp_ins_module(m) < 0) {
_stp_free_module(m);
return -ENOMEM;
@@ -513,20 +564,18 @@ static int _stp_ctl_send (int type, void *data, int len);
static int _stp_module_load_notify(struct notifier_block * self, unsigned long val, void * data)
{
-#ifdef CONFIG_MODULES
struct module *mod = (struct module *)data;
struct _stp_module rmod;
switch (val) {
case MODULE_STATE_COMING:
- dbug("module %s loaded\n", mod->name);
+ dbug(DEBUG_SYMBOLS, "module %s load notify\n", mod->name);
strlcpy(rmod.name, mod->name, STP_MODULE_NAME_LEN);
_stp_ctl_send(STP_MODULE, &rmod, sizeof(struct _stp_module));
break;
default:
errk("module loaded? val=%ld\n", val);
}
-#endif
return 0;
}
diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c
index 6b90ee64..8335e44b 100644
--- a/runtime/transport/transport.c
+++ b/runtime/transport/transport.c
@@ -18,6 +18,7 @@
#include <linux/namei.h>
#include "transport.h"
#include "time.c"
+#include "../mempool.c"
#include "symbols.c"
#include "../procfs.c"
@@ -76,7 +77,7 @@ static void _stp_ask_for_symbols(void)
if (sent_symbols == 0) {
/* ask for symbols and modules */
- kbug("AFS\n");
+ kbug(DEBUG_SYMBOLS|DEBUG_TRANSPORT, "AFS\n");
req.endian = 0x1234;
req.ptr_size = sizeof(char *);
@@ -94,7 +95,7 @@ static void _stp_ask_for_symbols(void)
void _stp_handle_start (struct _stp_msg_start *st)
{
- kbug ("stp_handle_start\n");
+ kbug (DEBUG_TRANSPORT, "stp_handle_start\n");
if (register_module_notifier(&_stp_module_load_nb))
errk("failed to load module notifier\n");
@@ -116,7 +117,7 @@ void _stp_handle_start (struct _stp_msg_start *st)
/* when someone does /sbin/rmmod on a loaded systemtap module. */
static void _stp_cleanup_and_exit (int dont_rmmod)
{
- kbug("cleanup_and_exit (%d)\n", dont_rmmod);
+ kbug(DEBUG_TRANSPORT, "cleanup_and_exit (%d)\n", dont_rmmod);
if (!_stp_exit_called) {
int failures;
@@ -127,23 +128,23 @@ static void _stp_cleanup_and_exit (int dont_rmmod)
_stp_exit_called = 1;
if (_stp_probes_started) {
- kbug("calling probe_exit\n");
+ kbug(DEBUG_TRANSPORT, "calling probe_exit\n");
/* tell the stap-generated code to unload its probes, etc */
probe_exit();
- kbug("done with probe_exit\n");
+ kbug(DEBUG_TRANSPORT, "done with probe_exit\n");
}
failures = atomic_read(&_stp_transport_failures);
if (failures)
_stp_warn ("There were %d transport failures.\n", failures);
- kbug("************** calling startstop 0 *************\n");
+ kbug(DEBUG_TRANSPORT, "************** calling startstop 0 *************\n");
if (_stp_utt) utt_trace_startstop(_stp_utt, 0, &utt_seq);
- kbug("ctl_send STP_EXIT\n");
+ kbug(DEBUG_TRANSPORT, "ctl_send STP_EXIT\n");
/* tell staprun to exit (if it is still there) */
_stp_ctl_send(STP_EXIT, &dont_rmmod, sizeof(int));
- kbug("done with ctl_send STP_EXIT\n");
+ kbug(DEBUG_TRANSPORT, "done with ctl_send STP_EXIT\n");
}
}
@@ -152,7 +153,7 @@ static void _stp_cleanup_and_exit (int dont_rmmod)
*/
static void _stp_detach(void)
{
- kbug("detach\n");
+ kbug(DEBUG_TRANSPORT, "detach\n");
_stp_attached = 0;
_stp_pid = 0;
@@ -168,7 +169,7 @@ static void _stp_detach(void)
*/
static void _stp_attach(void)
{
- kbug("attach\n");
+ kbug(DEBUG_TRANSPORT, "attach\n");
_stp_attached = 1;
_stp_pid = current->pid;
utt_set_overwrite(0);
@@ -210,7 +211,7 @@ static void _stp_work_queue (void *data)
*/
void _stp_transport_close()
{
- kbug("%d: ************** transport_close *************\n", current->pid);
+ kbug(DEBUG_TRANSPORT, "%d: ************** transport_close *************\n", current->pid);
_stp_cleanup_and_exit(1);
destroy_workqueue(_stp_wq);
_stp_unregister_ctl_channel();
@@ -219,7 +220,7 @@ void _stp_transport_close()
_stp_kill_time();
_stp_print_cleanup(); /* free print buffers */
_stp_mem_debug_done();
- kbug("---- CLOSED ----\n");
+ kbug(DEBUG_TRANSPORT, "---- CLOSED ----\n");
}
@@ -248,7 +249,7 @@ int _stp_transport_init(void)
{
int ret;
- kbug("transport_init\n");
+ kbug(DEBUG_TRANSPORT, "transport_init\n");
_stp_init_pid = current->pid;
_stp_uid = current->uid;
_stp_gid = current->gid;
@@ -263,7 +264,7 @@ int _stp_transport_init(void)
unsigned size = _stp_bufsize * 1024 * 1024;
_stp_subbuf_size = ((size >> 2) + 1) * 65536;
_stp_nsubbufs = size / _stp_subbuf_size;
- kbug("Using %d subbufs of size %d\n", _stp_nsubbufs, _stp_subbuf_size);
+ kbug(DEBUG_TRANSPORT, "Using %d subbufs of size %d\n", _stp_nsubbufs, _stp_subbuf_size);
}
/* initialize timer code */
@@ -388,12 +389,12 @@ static struct dentry *_stp_get_root_dir(const char *name) {
_stp_lock_inode(sb->s_root->d_inode);
root = lookup_one_len(name, sb->s_root, strlen(name));
_stp_unlock_inode(sb->s_root->d_inode);
- kbug("root=%p\n", root);
+ kbug(DEBUG_TRANSPORT, "root=%p\n", root);
if (!IS_ERR(root))
dput(root);
else {
root = NULL;
- kbug("Could not create or find transport directory.\n");
+ kbug(DEBUG_TRANSPORT, "Could not create or find transport directory.\n");
}
}
_stp_unlock_debugfs();
diff --git a/runtime/transport/transport_msgs.h b/runtime/transport/transport_msgs.h
index b2187cd5..55de2d4a 100644
--- a/runtime/transport/transport_msgs.h
+++ b/runtime/transport/transport_msgs.h
@@ -36,7 +36,30 @@ enum
STP_SUBBUFS_CONSUMED,
STP_REALTIME_DATA,
#endif
+
+ STP_MAX_CMD
+};
+
+#ifdef DEBUG_TRANSPORT
+static const char *_stp_command_name[] = {
+ "STP_START",
+ "STP_EXIT",
+ "STP_OOB_DATA",
+ "STP_SYSTEM",
+ "STP_SYMBOLS",
+ "STP_MODULE",
+ "STP_TRANSPORT",
+ "STP_CONNECT",
+ "STP_DISCONNECT",
+ "STP_BULK",
+ "STP_READY",
+#ifdef STP_OLD_TRANSPORT
+ "STP_BUF_INFO",
+ "STP_SUBBUFS_CONSUMED",
+ "STP_REALTIME_DATA",
+#endif
};
+#endif /* DEBUG_TRANSPORT */
/* control channel messages */