Blktrace - introducing trace_dump() to log output
A message that is not in the archive (sent off-list or not yet received): [email protected]
RFC PATCH 1/5 Blktrace - introducing trace_dump() to log output
This patch replaces the memcpy in the output functions to use trace_dump() function. This renders several other operations done in blktrace.c such as setup/tear-down/read operation definitions redundant.
This patch also introduces instances of a few structures required to use trace_dump() function in struct blk_trace.
--- block/blktrace.c | 32 +++++++++++++++++++++++++++----- include/linux/blktrace_api.h | 3 +++ 2 files changed, 30 insertions(+), 5 deletions(-)
block/blktrace.c +27 -5
@@ -25,6 +25,7 @@#include <linux/time.h> #include <asm/uaccess.h> +#define BLKTRACE_ROOT_DIR "block"static unsigned int blktrace_seq__read_mostly =1 ;/*
@@ -35,7 +36,7 @@ static void trace_note(struct blk_trace {struct blk_io_trace *t; - t =relay_reserve (bt->rchan,sizeof (*t) + len); + t =kzalloc (sizeof (*t),GFP_KERNEL );if (t) {const int cpu =smp_processor_id ();
@@ -46,7 +47,8 @@ static void trace_note(struct blk_trace t->pid = pid; t->cpu = cpu; t->pdu_len = len; -memcpy ((void *) t +sizeof (*t), data, len); +trace_dump (bt->tpk, t,sizeof (*t)); +trace_dump (bt->tpk, data, len); } }
@@ -151,7 +153,7 @@ void __blk_add_trace(struct blk_trace *bif (unlikely (tsk->btrace_seq != blktrace_seq))trace_note_tsk (bt, tsk); - t =relay_reserve (bt->rchan,sizeof (*t) + pdu_len); + t =kzalloc (sizeof (*t),GFP_KERNEL );if (t) { cpu =smp_processor_id (); sequence =per_cpu_ptr (bt->sequence, cpu);
@@ -168,8 +170,9 @@ void __blk_add_trace(struct blk_trace *b t->error = error; t->pdu_len = pdu_len; +trace_dump (bt->tpk, t,sizeof (*t));if (pdu_len) -memcpy ((void *) t +sizeof (*t), pdu_data, pdu_len); +trace_dump (bt->tpk, pdu_data, pdu_len); }local_irq_restore (flags);
@@ -206,7 +209,7 @@ static struct dentry *blk_create_tree(comutex_lock (&blk_tree_mutex);if (!blk_tree_root) { - blk_tree_root =debugfs_create_dir ("block" ,NULL ); + blk_tree_root =debugfs_create_dir ("block_old" ,NULL );if (!blk_tree_root) goto err; created =1 ;
@@ -232,6 +235,11 @@ static void blk_trace_cleanup(struct blkdebugfs_remove (bt->dropped_file);blk_remove_tree (bt->dir);free_percpu (bt->sequence); +trace_cleanup (bt->tpk->ti); + +kfree (bt->tpk->parent_dir); +kfree (bt->tpk->dir); +kfree (bt->tpk);kfree (bt); }
@@ -342,6 +350,16 @@ int do_blk_trace_setup(struct request_quif (!bt) goto err; + bt->tpk =kzalloc (sizeof (*(bt->tpk)),GFP_KERNEL ); +if (!bt->tpk) + goto err; + bt->tpk->parent_dir =kstrdup (BLKTRACE_ROOT_DIR ,GFP_KERNEL ); +if (!bt->tpk->parent_dir) + goto parent_dir_err; + bt->tpk->dir =kstrdup (name,GFP_KERNEL ); +if (!bt->tpk->dir) + goto dir_err; + bt->sequence = alloc_percpu(unsigned long);if (!bt->sequence) goto err;
@@ -385,6 +403,10 @@ int do_blk_trace_setup(struct request_qu }return 0 ; +dir_err: +kfree (bt->tpk->parent_dir); +parent_dir_err: +kfree (bt->tpk); err:if (dir)blk_remove_tree (dir);
include/linux/blktrace_api.h +3 -0
@@ -3,6 +3,7 @@#include <linux/blkdev.h> #include <linux/relay.h> +#include <linux/trace.h> /* * Trace categories
@@ -127,6 +128,8 @@ struct blk_trace {struct dentry *dir;struct dentry *dropped_file;atomic_t dropped; +struct trace_info *ti; +struct trace_printk_data *tpk; };/*
RFC PATCH 2/5 Blktrace - Remove the 'dropped' file from blktrace.c
In reply to a message not in the archiveRemove the 'dropped' file and the setup/removal/access operations surrounding it. The use of trace_dump() has rendered this file redundant, as 'trace' infrastructure makes this file available already.
--- block/blktrace.c | 33 --------------------------------- include/linux/blktrace_api.h | 2 -- 2 files changed, 35 deletions(-)
block/blktrace.c +0 -33
@@ -232,7 +232,6 @@ err:static void blk_trace_cleanup (struct blk_trace *bt) {relay_close (bt->rchan); -debugfs_remove (bt->dropped_file);blk_remove_tree (bt->dir);free_percpu (bt->sequence);trace_cleanup (bt->tpk->ti);
@@ -259,30 +258,6 @@ int blk_trace_remove(struct request_queu }EXPORT_SYMBOL_GPL (blk_trace_remove); -static int blk_dropped_open (struct inode *inode,struct file *filp) -{ - filp->private_data = inode->i_private; - -return 0 ; -} - -static ssize_t blk_dropped_read (struct file *filp,char __user *buffer, -size_t count,loff_t *ppos) -{ -struct blk_trace *bt = filp->private_data; -char buf[16 ]; - -snprintf (buf,sizeof (buf),"%u\n" ,atomic_read (&bt->dropped)); - -return simple_read_from_buffer (buffer, count, ppos, buf,strlen (buf)); -} - -static const struct file_operations blk_dropped_fops = { - .owner =THIS_MODULE , - .open = blk_dropped_open, - .read = blk_dropped_read, -}; -/* * Keep track of how many times we encountered a full subbuffer, to aid * the user space app in telling how many lost events there were.
@@ -296,7 +271,6 @@ static int blk_subbuf_start_callback(strreturn 1 ; bt = buf->chan->private_data; -atomic_inc (&bt->dropped);return 0 ; }
@@ -371,13 +345,8 @@ int do_blk_trace_setup(struct request_qu bt->dir = dir; bt->dev = dev; -atomic_set (&bt->dropped,0 ); ret = -EIO ; - bt->dropped_file =debugfs_create_file ("dropped" ,0444 , dir, bt, &blk_dropped_fops); -if (!bt->dropped_file) - goto err; - bt->rchan =relay_open ("trace" , dir, buts->buf_size, buts->buf_nr, &blk_relay_callbacks, bt);if (!bt->rchan)
@@ -411,8 +380,6 @@ err:if (dir)blk_remove_tree (dir);if (bt) { -if (bt->dropped_file) -debugfs_remove (bt->dropped_file);free_percpu (bt->sequence);if (bt->rchan)relay_close (bt->rchan);
include/linux/blktrace_api.h +0 -2
@@ -126,8 +126,6 @@ struct blk_trace {u32 pid;u32 dev;struct dentry *dir; -struct dentry *dropped_file; -atomic_t dropped;struct trace_info *ti;struct trace_printk_data *tpk; };
RFC PATCH 3/5 Blktrace - Remove the "block" directory operations from blktrace.c
In reply to a message not in the archiveThis patch removes the code associated with the creation/removal/access operations associated with the "block" directory. Please note that the "block" di
rectory had been renamed "block_old" in the previous patch for testing. This change is however temporary, since all code relevant to directory operations are removed through this patch.
--- block/blktrace.c | 57 ------------------------------------------- include/linux/blktrace_api.h | 1 2 files changed, 58 deletions(-)
block/blktrace.c +0 -57
@@ -180,59 +180,9 @@ void __blk_add_trace(struct blk_trace *bEXPORT_SYMBOL_GPL (__blk_add_trace); -static struct dentry *blk_tree_root; -static DEFINE_MUTEX (blk_tree_mutex); -static unsigned int root_users; - -static inline void blk_remove_root (void ) -{ -if (blk_tree_root) { -debugfs_remove (blk_tree_root); - blk_tree_root =NULL ; - } -} - -static void blk_remove_tree (struct dentry *dir) -{ -mutex_lock (&blk_tree_mutex); -debugfs_remove (dir); -if (--root_users ==0 ) -blk_remove_root (); -mutex_unlock (&blk_tree_mutex); -} - -static struct dentry *blk_create_tree (const char *blk_name) -{ -struct dentry *dir =NULL ; -int created =0 ; - -mutex_lock (&blk_tree_mutex); - -if (!blk_tree_root) { - blk_tree_root =debugfs_create_dir ("block_old" ,NULL ); -if (!blk_tree_root) - goto err; - created =1 ; - } - - dir =debugfs_create_dir (blk_name, blk_tree_root); -if (dir) - root_users++; -else { -/* Delete root only if we created it */ -if (created) -blk_remove_root (); - } - -err: -mutex_unlock (&blk_tree_mutex); -return dir; -} -static void blk_trace_cleanup (struct blk_trace *bt) {relay_close (bt->rchan); -blk_remove_tree (bt->dir);free_percpu (bt->sequence);trace_cleanup (bt->tpk->ti);
@@ -339,11 +289,6 @@ int do_blk_trace_setup(struct request_qu goto err; ret = -ENOENT ; - dir =blk_create_tree (buts->name); -if (!dir) - goto err; - - bt->dir = dir; bt->dev = dev; ret = -EIO ;
@@ -377,8 +322,6 @@ dir_err: parent_dir_err:kfree (bt->tpk); err: -if (dir) -blk_remove_tree (dir);if (bt) {free_percpu (bt->sequence);if (bt->rchan)
include/linux/blktrace_api.h +0 -1
@@ -125,7 +125,6 @@ struct blk_trace {u64 end_lba;u32 pid;u32 dev; -struct dentry *dir;struct trace_info *ti;struct trace_printk_data *tpk; };
RFC PATCH 4/5 Blktrace - Remove the rchan instance from blktrace.c
In reply to a message not in the archiveThis patch removes the rchan instance from blk_trace structure and its associated operations, since trace_dump() uses 'trace' infrastructure which internally uses relay buffers.
--- block/blktrace.c | 48 ------------------------------------------- include/linux/blktrace_api.h | 1 2 files changed, 49 deletions(-)
block/blktrace.c +0 -48
@@ -182,7 +182,6 @@ EXPORT_SYMBOL_GPL(__blk_add_trace);static void blk_trace_cleanup (struct blk_trace *bt) { -relay_close (bt->rchan);free_percpu (bt->sequence);trace_cleanup (bt->tpk->ti);
@@ -209,51 +208,12 @@ int blk_trace_remove(struct request_queuEXPORT_SYMBOL_GPL (blk_trace_remove);/* -* Keep track of how many times we encountered a full subbuffer, to aid -* the user space app in telling how many lost events there were. -*/ -static int blk_subbuf_start_callback (struct rchan_buf *buf,void *subbuf, -void *prev_subbuf,size_t prev_padding) -{ -struct blk_trace *bt; - -if (!relay_buf_full (buf)) -return 1 ; - - bt = buf->chan->private_data; -return 0 ; -} - -static int blk_remove_buf_file_callback (struct dentry *dentry) -{ -debugfs_remove (dentry); -return 0 ; -} - -static struct dentry *blk_create_buf_file_callback (const char *filename, -struct dentry *parent, -int mode, -struct rchan_buf *buf, -int *is_global) -{ -return debugfs_create_file (filename, mode, parent, buf, - &relay_file_operations); -} - -static struct rchan_callbacks blk_relay_callbacks = { - .subbuf_start = blk_subbuf_start_callback, - .create_buf_file = blk_create_buf_file_callback, - .remove_buf_file = blk_remove_buf_file_callback, -}; - -/* * Setup everything required to start tracing */ int do_blk_trace_setup (struct request_queue *q,char *name,dev_t dev,struct blk_user_trace_setup *buts) {struct blk_trace *old_bt, *bt =NULL ; -struct dentry *dir =NULL ;int ret, i;if (!buts->buf_size || !buts->buf_nr)
@@ -292,11 +252,6 @@ int do_blk_trace_setup(struct request_qu bt->dev = dev; ret = -EIO ; - bt->rchan =relay_open ("trace" , dir, buts->buf_size, - buts->buf_nr, &blk_relay_callbacks, bt); -if (!bt->rchan) - goto err; - bt->act_mask = buts->act_mask;if (!bt->act_mask) bt->act_mask = (u16) -1 ;
@@ -324,8 +279,6 @@ parent_dir_err: err:if (bt) {free_percpu (bt->sequence); -if (bt->rchan) -relay_close (bt->rchan);kfree (bt); }return ret;
@@ -378,7 +331,6 @@ int blk_trace_startstop(struct request_q }else {if (bt->trace_state == Blktrace_running) { bt->trace_state = Blktrace_stopped; -relay_flush (bt->rchan); ret =0 ; } }
include/linux/blktrace_api.h +0 -1
@@ -118,7 +118,6 @@ enum {struct blk_trace {int trace_state; -struct rchan *rchan;unsigned long *sequence;u16 act_mask;u64 start_lba;
RFC PATCH 5/5 Blktrace - Remove trace_state and associated flags from blktrace.[ch]
In reply to a message not in the archiveThis patch removes the 'trace_state' flag from blk_trace structure, since the state transitions will now be managed using 'trace' infrastructure.
--- block/blktrace.c | 26 +++++++------------------- include/linux/blktrace_api.h | 7 ------- 2 files changed, 7 insertions(+), 26 deletions(-)
include/linux/blktrace_api.h +0 -7
@@ -110,14 +110,7 @@ struct blk_io_trace_remap {__be64 sector; }; -enum { - Blktrace_setup =1 , - Blktrace_running, - Blktrace_stopped, -}; -struct blk_trace { -int trace_state;unsigned long *sequence;u16 act_mask;u64 start_lba;
block/blktrace.c +7 -19
@@ -127,9 +127,6 @@ void __blk_add_trace(struct blk_trace *bpid_t pid;int cpu; -if (unlikely (bt->trace_state != Blktrace_running)) -return ; - what |= ddir_act[rw &WRITE ]; what |= bio_act[trace_barrier_bit (rw)]; what |= bio_act[trace_sync_bit (rw)];
@@ -199,8 +196,7 @@ int blk_trace_remove(struct request_queuif (!bt)return -EINVAL ; -if (bt->trace_state == Blktrace_setup || - bt->trace_state == Blktrace_stopped) +if (!trace_running (bt->tpk->ti))blk_trace_cleanup (bt);return 0 ;
@@ -262,7 +258,6 @@ int do_blk_trace_setup(struct request_qu bt->end_lba =-1ULL ; bt->pid = buts->pid; - bt->trace_state = Blktrace_setup; ret = -EBUSY ; old_bt =xchg (&q->blk_trace, bt);
@@ -319,20 +314,13 @@ int blk_trace_startstop(struct request_q*/ ret = -EINVAL ;if (start) { -if (bt->trace_state == Blktrace_setup || - bt->trace_state == Blktrace_stopped) { - blktrace_seq++; -smp_mb (); - bt->trace_state = Blktrace_running; - -trace_note_time (bt); - ret =0 ; - } + blktrace_seq++; +smp_mb (); +trace_note_time (bt); + ret =0 ; }else { -if (bt->trace_state == Blktrace_running) { - bt->trace_state = Blktrace_stopped; - ret =0 ; - } +trace_stop (bt->tpk->ti); + ret =0 ; }return ret;
Re: [RFC Patch 5/5] Blktrace - Remove trace_state and associated flags from blktrace.[ch]
Re-sending the patch due to style issues found in the previous version.
This patch removes the 'trace_state' flag from blk_trace structure, since the state transitions will now be managed using 'trace' infrastructure.
--- block/blktrace.c | 26 +++++++------------------- include/linux/blktrace_api.h | 7 ------- 2 files changed, 7 insertions(+), 26 deletions(-)
include/linux/blktrace_api.h +0 -7
@@ -110,14 +110,7 @@ struct blk_io_trace_remap {__be64 sector; }; -enum { - Blktrace_setup =1 , - Blktrace_running, - Blktrace_stopped, -}; -struct blk_trace { -int trace_state;unsigned long *sequence;u16 act_mask;u64 start_lba;
block/blktrace.c +7 -19
@@ -127,9 +127,6 @@ void __blk_add_trace(struct blk_trace *bpid_t pid;int cpu; -if (unlikely (bt->trace_state != Blktrace_running)) -return ; - what |= ddir_act[rw &WRITE ]; what |= bio_act[trace_barrier_bit (rw)]; what |= bio_act[trace_sync_bit (rw)];
@@ -199,8 +196,7 @@ int blk_trace_remove(struct request_queuif (!bt)return -EINVAL ; -if (bt->trace_state == Blktrace_setup || - bt->trace_state == Blktrace_stopped) +if (!trace_running (bt->tpk->ti))blk_trace_cleanup (bt);return 0 ;
@@ -262,7 +258,6 @@ int do_blk_trace_setup(struct request_qu bt->end_lba =-1ULL ; bt->pid = buts->pid; - bt->trace_state = Blktrace_setup; ret = -EBUSY ; old_bt =xchg (&q->blk_trace, bt);
@@ -319,20 +314,13 @@ int blk_trace_startstop(struct request_q*/ ret = -EINVAL ;if (start) { -if (bt->trace_state == Blktrace_setup || - bt->trace_state == Blktrace_stopped) { - blktrace_seq++; -smp_mb (); - bt->trace_state = Blktrace_running; - -trace_note_time (bt); - ret =0 ; - } + blktrace_seq++; +smp_mb (); +trace_note_time (bt); + ret =0 ; }else { -if (bt->trace_state == Blktrace_running) { - bt->trace_state = Blktrace_stopped; - ret =0 ; - } +trace_stop (bt->tpk->ti); + ret =0 ; }return ret;