Package: scsitools / 0.12-3

sraw.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
Description: updated code to work on modern Linux systems:
 - Removed GCC warnings
 - send SCSI commands using SG_IO
 - Debian FHS compliant.
Forwarded: no
Author: Eric Delaunay <delaunay@debian.org>

--- a/sraw/srawread.c
+++ n/sraw/srawread.c
@@ -79,19 +79,25 @@
  *
  */
 
-#define USE_READ_10
-#undef  SET_FUA  /* "force unit access" for READ(10): don't read from cache but from media */
-#define LESS_VERBOSE_OUTPUT
 #define USE_GETTIMEOFDAY /* please, always! gettimeofday(2) is much more accurate */
+#define USE_SG_IO
 
 
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
 #include <sys/times.h>
 #include <linux/hdreg.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#ifdef USE_SG_IO
+# include <scsi/sg.h>
+#endif
 
-FILE *infile, *ptable;
-unsigned char buffer[2*64*1024];
+FILE *infile = NULL;
+unsigned char buffer[2*64*1024+8];
 
 
 int read_size=32768;
@@ -121,54 +127,99 @@
 int main( int argc, char *argv[] )
 {
   int b,bstart=0,bstep=1;
+  int c=1,verbose=0;
   int status, i;
   unsigned char *cmd;
-  int capacity, sectorsize;
+  unsigned int capacity, sectorsize;
   int this_count, block;
   int rate;
   double starttime, endtime;
-
-  if (argc==1) { 
-    printf("usage: srawread scsi-device [ bstart [ bstop ] ]\n");
-    exit(0);
+  int read_len = 10;			/* length of read command */
+  int fua = 0;				/* "force unit access" for READ(10): don't read from cache but from media */
+#ifdef USE_SG_IO
+  sg_io_hdr_t sgbuf;
+  int legacy_ioctl=0;
+#endif
+
+  while (argc>c && argv[c][0] == '-') {
+    for(i=1; i < strlen(argv[c]); i++)
+      switch (argv[c][i]) {
+	case 'v': verbose = 1; break;
+#ifdef USE_SG_IO
+	case 'i': legacy_ioctl = 1; break;
+#endif
+	case 'f': fua = 1; break;
+	case '6': read_len = 6; break;
+	default: goto error;
+      }
+    c++;
+  }
+  if (argc>c) {
+    infile = fopen( argv[c], "r" );
+    if (!infile) {
+      perror(argv[c]);
+      return 2;
+    }
   }
+  if (argc>c+1) bstart = atoi(argv[c+1]);
+  if (argc>c+2) bstep  = atoi(argv[c+2]);
 
-  infile = fopen( argv[1], "r" );
-  if(!infile) exit(0);
+  if (infile == NULL || argc==1 || argc>c+3) {
+error:
+    printf("usage: sraw [-v]%s scsi-device [ bstart [ bstep ] ]\n",
+#ifdef USE_SG_IO
+	    "[-i]"
+#else
+	    ""
+#endif
+	    );
+    return 1;
+  }
 
-  if (argc>2) bstart = atoi(argv[2]);
-  if (argc>3) bstep  = atoi(argv[2]);
+  memset(buffer, 0, sizeof(buffer));
 
-  for (i=0; i<10*1024; i++)
-  {
-    buffer[i] = 0;
-  }
-  
   *( (int *)  buffer )		= 0;	/* length of input data */
   *( ((int *) buffer) + 1 )	= read_size;	/* length of output buffer */
 
-  cmd = (char *) ( ((int *) buffer) + 2 );
+  cmd = (unsigned char *) ( ((int *) buffer) + 2 );
   
-  cmd[0] = 0x25;			/* INQUIRY */
-  cmd[1] = 0x00;			/* lun=0, evpd=0 */
-  cmd[2] = 0x00;			/* page code = 0 */
-  cmd[3] = 0x00;			/* (reserved) */
-  cmd[4] = 0x00;			/* allocation length */
-  cmd[5] = 0x00;			/* control */
-
+  cmd[0] = 0x25;			/* READ CAPICTY (10 bytes)*/
+  cmd[1] = 0x00;			/* b7-5: lun=0, b4-1: reserved, b0: reladdr=0 */
+  /* cmd[2..5] = 0x00;			   logical block address = 0 */
+  /* cmd[6..8] = 0x00;			   (reserved), cmd[8].b0=PMI(0) */
+  /* cmd[9] = 0x00;			   control */
+
+#ifdef USE_SG_IO
+  if (! legacy_ioctl) {
+    memset(&sgbuf, 0, sizeof(sgbuf));
+    sgbuf.interface_id = 'S';		/* SCSI Generic Interface */
+    sgbuf.dxfer_direction = SG_DXFER_FROM_DEV;
+    sgbuf.cmd_len = 10;
+    sgbuf.cmdp = cmd;
+    sgbuf.dxfer_len = 8;		/* send back 8 bytes of data (capacity, sectorsize) */
+    sgbuf.dxferp = cmd;
+    sgbuf.timeout = 2000;
+    status = ioctl( fileno(infile), SG_IO, &sgbuf );
+  }
+  else
+#endif
   status = ioctl( fileno(infile), 1 /* SCSI_IOCTL_SEND_COMMAND */, buffer );
-
+  if (status < 0) {
+    perror("ioctl");
+    return 3;
+  }
   capacity = (buffer[8] << 24) | (buffer[9] << 16)  | (buffer[10] << 8) | buffer[11];
   sectorsize = (buffer[12] << 24) | (buffer[13] << 16)  | (buffer[14] << 8) | buffer[15];
-  printf("Size %d  sectorsize %d\n", capacity * (sectorsize >> 9), sectorsize);
-
+  if (verbose)
+    printf("Size %llu bytes, sectorsize %u\n", ((uint64_t)capacity) * sectorsize, sectorsize);
 
   do{
+/*
 	  for (i=0; i<10*1024; i++)
 	  {
 		  buffer[i] = 0;
 	  }
-	  
+*/
 	  block = 0;
 	  this_count = read_size / sectorsize;
 	  starttime = time_so_far();
@@ -176,45 +227,62 @@
 		  *( (int *)  buffer )		= 0;	/* length of input data */
 		  *( ((int *) buffer) + 1 )	= read_size;	/* length of output buffer */
 		  
-		  cmd = (char *) ( ((int *) buffer) + 2 );
+		  cmd = (unsigned char *) ( ((int *) buffer) + 2 );
 		  
 		  b = bstart + bstep * block;
-#ifdef USE_READ_10
-		  cmd[0] = 0x28;			/* read_10 */
-		  cmd[1] = 0x00;
-#ifdef SET_FUA
-		  cmd[1] |= 0x08;
-#endif /* SET_FUA */
-		  cmd[2] = (b >> 24) & 0xff;
-		  cmd[3] = (b >> 16) & 0xff;
-		  cmd[4] = (b >>  8) & 0xff;
-		  cmd[5] =  b        & 0xff;
-		  cmd[6] = 0;
-		  cmd[7] = (this_count >> 8) & 0xff; /* transfer length */
-		  cmd[8] =  this_count       & 0xff;
-		  cmd[9] = 0x00; /* control */
-#else /* USE_READ_10 */
-		  cmd[0] = 0x08;			/* read_6 */
-		  cmd[1] = (b >> 16) & 0x1f;
-		  cmd[2] = (b >> 8) & 0xff;
-		  cmd[3] = b & 0xff;
-		  cmd[4] = this_count;
-		  cmd[5] = 0x00;
-#endif /* USE_READ_10 */
-		  
+		  if (read_len == 10) {
+		    cmd[0] = 0x28;			/* read_10 */
+		    cmd[1] = 0x00;
+		    if (fua)
+		      cmd[1] |= 0x08;
+		    cmd[2] = (b >> 24) & 0xff;
+		    cmd[3] = (b >> 16) & 0xff;
+		    cmd[4] = (b >>  8) & 0xff;
+		    cmd[5] =  b        & 0xff;
+		    cmd[6] = 0;
+		    cmd[7] = (this_count >> 8) & 0xff; /* transfer length */
+		    cmd[8] =  this_count       & 0xff;
+		    cmd[9] = 0x00; /* control */
+		  }
+		  else {
+		    cmd[0] = 0x08;			/* read_6 */
+		    cmd[1] = (b >> 16) & 0x1f;
+		    cmd[2] = (b >> 8) & 0xff;
+		    cmd[3] = b & 0xff;
+		    cmd[4] = this_count;
+		    cmd[5] = 0x00;
+		  }
+#ifdef USE_SG_IO
+		  if (! legacy_ioctl) {
+		    memset(&sgbuf, 0, sizeof(sgbuf));
+		    sgbuf.interface_id = 'S';		/* SCSI Generic Interface */
+		    sgbuf.dxfer_direction = SG_DXFER_FROM_DEV;
+		    sgbuf.cmd_len = read_len;
+		    sgbuf.cmdp = cmd;
+		    sgbuf.dxfer_len = read_size;
+		    sgbuf.dxferp = cmd;
+		    sgbuf.timeout = 2000;
+		    status = ioctl( fileno(infile), SG_IO, &sgbuf );
+		  }
+		  else
+#endif
 		  status = ioctl( fileno(infile), 3 /* SCSI_IOCTL_BENCHMARK_COMMAND */, buffer );
-		  if(status) fprintf(stderr,"%x ", status);
+		  if (status < 0) {
+		    if (verbose)
+		      printf("ioctl: %s\n", strerror(errno));
+		    else
+		      printf("(%d) ", status);
+		  }
 		  block += this_count;
 	  } while(block < (10000 / (sectorsize >> 9)));
 	  endtime = time_so_far() - starttime;
 	  rate = (block * sectorsize) / endtime;
-#ifdef LESS_VERBOSE_OUTPUT
-	  printf("%6d   %10.4f  %6d    %8d \n",
+	  if (!verbose)
+	    printf("%6d   %10.4f  %6d    %8d \n",
 		 read_size, endtime, block, rate);
-#else /* LESS_VERBOSE_OUTPUT */
-	  printf("Blocksize %d, time elapsed %1.4f seconds, %d blocks.  Throughput = %d bytes/sec\n",
+	  else
+	    printf("Blocksize %d, time elapsed %1.4f seconds, %d blocks.  Throughput = %d bytes/sec\n",
 		 read_size, endtime, block, rate);
-#endif /* LESS_VERBOSE_OUTPUT */
 
 	  read_size += 4096;
   } while(read_size <= 2*64*1024);
--- a/sraw/sraw.8
+++ b/sraw/sraw.8
@@ -0,0 +1,82 @@
+.\" -*- nroff -*-
+.TH SRAW 8 "Nov 1993"
+.SH NAME
+sraw \- benchmark raw scsi I/O performance under linux
+.SH SYNOPSIS
+.B sraw
+[
+.B -fiv6
+]
+.B scsi-device
+[
+.B bstart
+[
+.B bstep
+] ]
+.SH DESCRIPTION
+This program basically reads the specified scsi device and measures the
+throughput.  Note that the filesystem *AND* the buffer cache are
+bypassed by this code, this program was designed to benchmark the naked
+scsi drivers by themselves without the need to account for the overhead
+of any other portion of the kernel. It also could be used to benchmark
+disk read throughput.
+.P
+This program does a series of reads of the disk, of consecutive
+areas on the disk.  The device is first queried to determine the
+sector size for the device, and then the series of reads is begun.
+About 5.0 Mb is read from the device, and then the performance numbers
+are reported.  Note that since the buffer cache is completely bypassed,
+there is no need to be concerned about cache hits or anything.
+.P
+Output of
+.B sraw
+is a set of lines, 4 numbers per line:
+.I blocksize, elapsed time, nblocks
+and
+.I throughput
+(in bytes per second).
+.P
+.B scsi-device
+is either a block device (e.g. /dev/sda, /dev/scd0) or a generic SCSI
+device (e.g. /dev/sg0).
+.SH OPTIONS
+.TP
+.I -f
+set FUA (Force Unit Access) bit during read. Data is then read from
+media instead of internal drive cache.
+.TP
+.I -i
+use legacy ioctl instead of new SG I/O layer (will not work on 2.6
+kernel and block devices).
+.TP
+.I -v
+more verbose output.
+.TP
+.I -6
+use 6-bytes instead of 10-bytes read command. In this case, only the
+first GB of data could be read from media.
+.TP
+.I bstart
+starting block to check different zones on ZBR discs
+.TP
+.I bstep
+factor for sequential stepping, default 1.
+Use 0 for reading always the same blocks (from cache)
+.SH ERRORS
+.B sraw
+could issue input/output errors when reading too many blocks at the
+same time from a block device like /dev/sda. To get rid of them, use
+/dev/sgN instead.
+.SH AUTHOR
+.B sraw
+was first written by Eric Youngdale.
+Extensions (-v, -f, -6, SG IO, man page) were written by Eric Delaunay.
+.SH SEE ALSO
+.B sg_dd(8)
+from sg3-utils package.
+.SH AVAILABILITY
+.B sraw
+is available at
+.nf
+.B ftp://tsx-11.mit.edu/pub/linux/ALPHA/scsi/
+.fi