Skip to contentSkip to conversation

scsi: add scsi trace core function and put trace points

PATCH Superseded Kei Tokunaga 4 participants 7 messages Jan 20, 2010 – Feb 1, 2010

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 scsi: add scsi trace core function and put trace points

In this first attempt, trace points are put in these timings:

- when a command is about to be dispatched.
- when a command dispatched returns in error.
- when a command is done.
- when an error handler is about to waken up.
- when timeout of a command is detected.

Here is an outputs exmaple:

# tracer: nop
#
# TASK-PID CPU# TIMESTAMP FUNCTION
# | | | | |

         flush-8:0-3746  [001]  1374.517152: scsi_dispatch_cmd_start: host_no=0 channel=0 id=0 lun=0 cmnd=(WRITE_10 lba=32267539 txlen=8 raw=2a 00 01 ec 5d 13 00 00 08 00)
            <idle>-0     [000]  1374.524964: scsi_dispatch_cmd_done: host_no=0 channel=0 id=0 lun=0 cmnd=(WRITE_10 lba=32267539 txlen=8 raw=2a 00 01 ec 5d 13 00 00 08 00) result=(driver=DRIVER_OK host=DID_OK message=COMMAND_COMPLETE status=SAM_STAT_GOOD)

---

 linux-2.6.33-rc4-trace-kei/drivers/scsi/scsi.c         |    6 
 linux-2.6.33-rc4-trace-kei/drivers/scsi/scsi_error.c   |    4 
 linux-2.6.33-rc4-trace-kei/include/trace/events/scsi.h |  328 +++++++++++++++++
 linux-2.6.33-rc4-trace-kei/kernel/trace/Makefile       |    3 
 linux-2.6.33-rc4-trace-kei/kernel/trace/scsitrace.c    |  168 ++++++++
 5 files changed, 509 insertions(+)
kernel/trace/Makefile renamed from kernel/trace/Makefile~scsi_trace +3 -0
diff -puN kernel/trace/Makefile~scsi_trace kernel/trace/Makefile
@@ -48,6 +48,9 @@ obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra
 ifeq ($(CONFIG_BLOCK),y)
 obj-$(CONFIG_EVENT_TRACING) += blktrace.o
 endif
+ifneq ($(CONFIG_SCSI),)
+obj-$(CONFIG_EVENT_TRACING) += scsitrace.o
+endif
 obj-$(CONFIG_EVENT_TRACING) += trace_events.o
 obj-$(CONFIG_EVENT_TRACING) += trace_export.o
 obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
include/trace/events/scsi.h new file +328 -0

328 lines not on this page · raw message

kernel/trace/scsitrace.c new file +168 -0

168 lines not on this page · raw message

drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~scsi_trace +6 -0
diff -puN drivers/scsi/scsi.c~scsi_trace drivers/scsi/scsi.c
@@ -67,6 +67,9 @@
 #include "scsi_priv.h"
 #include "scsi_logging.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/scsi.h>
+
 static void scsi_done(struct scsi_cmnd *cmd);
 
 /*
@@ -747,10 +750,12 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
 		cmd->result = (DID_NO_CONNECT << 16);
 		scsi_done(cmd);
 	} else {
+		trace_scsi_dispatch_cmd_start(cmd);
 		rtn = host->hostt->queuecommand(cmd, scsi_done);
 	}
 	spin_unlock_irqrestore(host->host_lock, flags);
 	if (rtn) {
+		trace_scsi_dispatch_cmd_error(cmd, rtn);
 		if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
 		    rtn != SCSI_MLQUEUE_TARGET_BUSY)
 			rtn = SCSI_MLQUEUE_HOST_BUSY;
@@ -781,6 +786,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
  */
 static void scsi_done(struct scsi_cmnd *cmd)
 {
+	trace_scsi_dispatch_cmd_done(cmd);
 	blk_complete_request(cmd->request);
 }
 
drivers/scsi/scsi_error.c renamed from drivers/scsi/scsi_error.c~scsi_trace +4 -0
diff -puN drivers/scsi/scsi_error.c~scsi_trace drivers/scsi/scsi_error.c
@@ -38,6 +38,8 @@
 #include "scsi_logging.h"
 #include "scsi_transport_api.h"
 
+#include <trace/events/scsi.h>
+
 #define SENSE_TIMEOUT		(10*HZ)
 
 /*
@@ -51,6 +53,7 @@
 void scsi_eh_wakeup(struct Scsi_Host *shost)
 {
 	if (shost->host_busy == shost->host_failed) {
+		trace_scsi_eh_wakeup(shost);
 		wake_up_process(shost->ehandler);
 		SCSI_LOG_ERROR_RECOVERY(5,
 				printk("Waking error handler thread\n"));
@@ -126,6 +129,7 @@ enum blk_eh_timer_return scsi_times_out(
 	struct scsi_cmnd *scmd = req->special;
 	enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED;
 
+	trace_scsi_dispatch_cmd_timeout(scmd);
 	scsi_log_completion(scmd, TIMEOUT_ERROR);
 
 	if (scmd->device->host->transportt->eh_timed_out)

_

#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kei" == Kei Tokunaga <[email protected]> writes:

+ TP_printk("host_no=%u channel=%u id=%u lun=%u cmnd=(%s %s raw=%s) "

                              ^^^^^^^^^^

I'm not sure anybody cares about channels in this millennium so that may be a waste of space.

+scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len) +scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len) +scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len) +scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)

Would be handy to get FUA and {RD,WR}PROTECT decoded in these commands. And prot_op would be nice too.

Other decode-worthy commands might be WRITE SAME(16) and UNMAP.

+scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)

+{
        [...]

+ case READ_32:
+ case WRITE_32:
+ return scsi_trace_rw32(p, cdb, len);

This won't work. READ/WRITE(32) are variable length commands. They share the same operation code and are distinguished by the service action field. Several of the most recent additions to the SCSI protocols are implemented like this.

Other commands requiring two-level parsing are READ CAPACITY(16) and GET LBA STATUS.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw
Quoted 7 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kei" == Kei Tokunaga <[email protected]> writes:

(quoted diff) +1 -0
+	TP_printk("host_no=%u channel=%u id=%u lun=%u cmnd=(%s %s raw=%s) "
                              ^^^^^^^^^^

I'm not sure anybody cares about channels in this millennium so that may be a waste of space.

IT;s still used for adressing things internally. E.g. in sas we typically map ports to them.

#3 lore raw
In reply to Martin K. Petersen
Quoted 14 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kei" == Kei Tokunaga <[email protected]> writes:

(quoted diff) +1 -0
+	TP_printk("host_no=%u channel=%u id=%u lun=%u cmnd=(%s %s raw=%s) "
                              ^^^^^^^^^^

I'm not sure anybody cares about channels in this millennium so that may be a waste of space.

kernel/trace/scsitrace.c new file +4 -0
+scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
+scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
+scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
+scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
Quoted 4 lines

Would be handy to get FUA and {RD,WR}PROTECT decoded in these commands. And prot_op would be nice too.

Other decode-worthy commands might be WRITE SAME(16) and UNMAP.

Thanks for the suggestions. I'm going to post v2 series of this patchset soon, and please note, in that version, I didn't add the decoding on these stuff you mentioned above.

Quoted 7 lines
kernel/trace/scsitrace.c new file +5 -0
+scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
+{
[...]
+	case READ_32:
+	case WRITE_32:
+		return scsi_trace_rw32(p, cdb, len);
Quoted 7 lines

This won't work. READ/WRITE(32) are variable length commands. They share the same operation code and are distinguished by the service action field. Several of the most recent additions to the SCSI protocols are implemented like this.

Other commands requiring two-level parsing are READ CAPACITY(16) and GET LBA STATUS.

This is definitely a valid point. In the v2 patchset, I tried to fix it. (Only DIF_TYPE2 READ/WRITE(32) are handled in that version.) It'd be great if you would review it.

I'm sorry that I didn't reply sooner.

Thanks,
Kei

#4 lore raw
In reply to Kei Tokunaga

kernel/trace/Makefile obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra · line 56

Quoted 12 lines
kernel/trace/Makefile renamed from kernel/trace/Makefile~scsi_trace +3 -0
@@ -48,6 +48,9 @@ obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra
 ifeq ($(CONFIG_BLOCK),y)
 obj-$(CONFIG_EVENT_TRACING) += blktrace.o
 endif
+ifneq ($(CONFIG_SCSI),)
+obj-$(CONFIG_EVENT_TRACING) += scsitrace.o
+endif
 obj-$(CONFIG_EVENT_TRACING) += trace_events.o
 obj-$(CONFIG_EVENT_TRACING) += trace_export.o
 obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o

The code should be built into scsi_mod.ko and thus from drivers/scsi/

maintainer
#5 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 6 lines
kernel/trace/Makefile renamed from kernel/trace/Makefile~scsi_trace +0 -0
@@ -48,6 +48,9 @@ obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra
 ifeq ($(CONFIG_BLOCK),y)
 obj-$(CONFIG_EVENT_TRACING) += blktrace.o
 endif
Quoted 9 lines

kernel/trace/Makefile obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra · line 56

Quoted 6 lines
kernel/trace/Makefile renamed from kernel/trace/Makefile~scsi_trace +3 -0
+ifneq ($(CONFIG_SCSI),)
+obj-$(CONFIG_EVENT_TRACING) += scsitrace.o
+endif
 obj-$(CONFIG_EVENT_TRACING) += trace_events.o
 obj-$(CONFIG_EVENT_TRACING) += trace_export.o
 obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o

The code should be built into scsi_mod.ko and thus from drivers/scsi/

Yes, none of this code belongs in kernel/trace/.

-- Steve

#6 lore raw
Quoted 16 lines · Steven Rostedt
Quoted 5 lines · Christoph Hellwig
Quoted 5 lines
kernel/trace/Makefile renamed from kernel/trace/Makefile~scsi_trace +0 -0
@@ -48,6 +48,9 @@ obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra
 ifeq ($(CONFIG_BLOCK),y)
 obj-$(CONFIG_EVENT_TRACING) += blktrace.o
Quoted 9 lines

kernel/trace/Makefile obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktra · line 56

Quoted 7 lines
kernel/trace/Makefile renamed from kernel/trace/Makefile~scsi_trace +3 -0
 endif
+ifneq ($(CONFIG_SCSI),)
+obj-$(CONFIG_EVENT_TRACING) += scsitrace.o
+endif
 obj-$(CONFIG_EVENT_TRACING) += trace_events.o
 obj-$(CONFIG_EVENT_TRACING) += trace_export.o
 obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o

The code should be built into scsi_mod.ko and thus from drivers/scsi/

Quoted 1 line

Yes, none of this code belongs in kernel/trace/.

Thanks for the comments, Christoph, Steven. In v2 patchset that I'm going to post soon, I've moved the stuff to drivers/scsi/.

Thanks,
Kei