1 Index: linux-2.6.9-5.0.3.EL/drivers/scsi/Kconfig
2 ===================================================================
3 --- linux-2.6.9-5.0.3.EL.orig/drivers/scsi/Kconfig 2005-04-01 18:36:39.218039672 +0300
4 +++ linux-2.6.9-5.0.3.EL/drivers/scsi/Kconfig 2005-04-01 18:36:45.571073864 +0300
10 + bool "Enable SCSI disk I/O stats"
11 + depends on BLK_DEV_SD
14 + This enables SCSI disk I/O stats collection. You must also enable
15 + /proc file system support if you want this feature.
18 tristate "SCSI tape support"
20 Index: linux-2.6.9-5.0.3.EL/drivers/scsi/sd.c
21 ===================================================================
22 --- linux-2.6.9-5.0.3.EL.orig/drivers/scsi/sd.c 2005-04-01 18:36:39.223038912 +0300
23 +++ linux-2.6.9-5.0.3.EL/drivers/scsi/sd.c 2005-04-01 18:37:42.537413664 +0300
26 #include "scsi_logging.h"
28 +#if (defined(CONFIG_SD_IOSTATS) && defined(CONFIG_PROC_FS))
29 +# include <linux/proc_fs.h>
30 +# include <linux/seq_file.h>
33 + unsigned long long iostat_size;
34 + unsigned long long iostat_count;
37 +#define IOSTAT_NCOUNTERS 16
39 + iostat_counter_t iostat_read_histogram[IOSTAT_NCOUNTERS];
40 + iostat_counter_t iostat_write_histogram[IOSTAT_NCOUNTERS];
41 + struct timeval iostat_timeval;
44 +iostat_stats_t **sd_iostats;
45 +spinlock_t sd_iostats_lock;
46 +struct proc_dir_entry *sd_iostats_procdir;
47 +char sd_iostats_procdir_name[] = "sd_iostats";
49 +extern void sd_iostats_init(void);
50 +extern void sd_iostats_init_disk(struct gendisk *);
51 +extern void sd_iostats_fini(void);
52 +extern void sd_iostats_bump(int disk, unsigned int nsect, int iswrite);
54 +static inline void sd_iostats_init(void) {}
55 +static inline void sd_iostats_init_disk(struct gendisk *disk) {}
56 +static inline void sd_iostats_fini(void) {}
57 +static inline void sd_iostats_bump(int disk, unsigned int nsect, int iswrite) {}
61 * More than enough for everybody ;) The huge number of majors
62 * is a leftover from 16bit dev_t days, we don't really need that
65 #define SD_MAX_DISKS (((26 * 26) + 26 + 1) * 26)
69 * Time out in seconds for disks and Magneto-opticals (which are slower).
72 SCSI_LOG_HLQUEUE(2, printk("%s : block=%llu\n",
73 disk->disk_name, (unsigned long long)block));
75 + sd_iostats_bump(scsi_disk(disk)->index, this_count,
76 + rq_data_dir(SCpnt->request) == WRITE);
79 * If we have a 1K hardware sectorsize, prevent access to single
80 * 512 byte sectors. In theory we could handle this - in fact
82 scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT);
85 + sd_iostats_init_disk(disk);
89 @@ -1573,6 +1610,327 @@
93 +#if (defined(CONFIG_SD_IOSTATS) && defined(CONFIG_PROC_FS))
95 +sd_iostats_seq_show(struct seq_file *seq, void *v)
98 + struct gendisk *disk = seq->private;
99 + iostat_stats_t *stats;
100 + unsigned long long read_len;
101 + unsigned long long read_len_tot;
102 + unsigned long read_num;
103 + unsigned long read_num_tot;
104 + unsigned long long write_len;
105 + unsigned long long write_len_tot;
106 + unsigned long write_num;
107 + unsigned long write_num_tot;
111 + if (sd_iostats == NULL) {
112 + printk(KERN_ERR "sd_iostats_seq_show: NULL stats array\n");
116 + stats = sd_iostats[scsi_disk(disk)->index];
117 + if (stats == NULL) {
118 + printk(KERN_ERR "sd_iostats_seq_show: NULL stats entry\n");
122 + do_gettimeofday(&now);
123 + now.tv_sec -= stats->iostat_timeval.tv_sec;
124 + now.tv_usec -= stats->iostat_timeval.tv_usec;
125 + if (now.tv_usec < 0) {
126 + now.tv_usec += 1000000;
130 + /* this sampling races with updates */
131 + seq_printf(seq, "index: %lu snapshot_time: %lu.%06lu\n",
132 + scsi_disk(disk)->index, now.tv_sec, now.tv_usec);
134 + for (i = IOSTAT_NCOUNTERS - 1; i > 0; i--)
135 + if (stats->iostat_read_histogram[i].iostat_count != 0 ||
136 + stats->iostat_write_histogram[i].iostat_count != 0)
140 + seq_printf(seq, "%8s %8s %12s %8s %12s\n", "size",
141 + "reads", "total", "writes", "total");
143 + read_len_tot = write_len_tot = 0;
144 + read_num_tot = write_num_tot = 0;
145 + for (i = 0; i <= maxi; i++) {
146 + read_len = stats->iostat_read_histogram[i].iostat_size;
147 + read_len_tot += read_len;
148 + read_num = stats->iostat_read_histogram[i].iostat_count;
149 + read_num_tot += read_num;
151 + write_len = stats->iostat_write_histogram[i].iostat_size;
152 + write_len_tot += write_len;
153 + write_num = stats->iostat_write_histogram[i].iostat_count;
154 + write_num_tot += write_num;
156 + seq_printf (seq, "%8d %8lu %12llu %8lu %12llu\n",
157 + 512<<i, read_num, read_len, write_num, write_len);
160 + seq_printf(seq, "%8s %8lu %12llu %8lu %12llu\n", "total",
161 + read_num_tot, read_len_tot,
162 + write_num_tot, write_len_tot);
167 +sd_iostats_seq_start(struct seq_file *p, loff_t *pos)
169 + return (*pos == 0) ? (void *)1 : NULL;
173 +sd_iostats_seq_next(struct seq_file *p, void *v, loff_t *pos)
180 +sd_iostats_seq_stop(struct seq_file *p, void *v)
184 +static struct seq_operations sd_iostats_seqops = {
185 + .start = sd_iostats_seq_start,
186 + .stop = sd_iostats_seq_stop,
187 + .next = sd_iostats_seq_next,
188 + .show = sd_iostats_seq_show,
192 +sd_iostats_seq_open (struct inode *inode, struct file *file)
196 + rc = seq_open(file, &sd_iostats_seqops);
200 + ((struct seq_file *)file->private_data)->private = PDE(inode)->data;
205 +sd_iostats_seq_write(struct file *file, const char *buffer,
206 + size_t len, loff_t *off)
208 + struct seq_file *seq = file->private_data;
209 + struct gendisk *disk = seq->private;
210 + iostat_stats_t *stats = sd_iostats[scsi_disk(disk)->index];
211 + unsigned long flags;
214 + spin_lock_irqsave (&sd_iostats_lock, flags);
215 + memset (stats, 0, sizeof(*stats));
216 + do_gettimeofday(&stats->iostat_timeval);
217 + spin_unlock_irqrestore (&sd_iostats_lock, flags);
222 +static struct file_operations sd_iostats_proc_fops = {
223 + .owner = THIS_MODULE,
224 + .open = sd_iostats_seq_open,
226 + .write = sd_iostats_seq_write,
227 + .llseek = seq_lseek,
228 + .release = seq_release,
231 +extern struct proc_dir_entry *proc_scsi;
234 +sd_iostats_init(void)
238 + spin_lock_init(&sd_iostats_lock);
240 + sd_iostats = kmalloc(SD_STATS * sizeof(iostat_stats_t *), GFP_KERNEL);
241 + if (sd_iostats == NULL) {
242 + printk(KERN_WARNING "Can't keep sd iostats: "
243 + "ENOMEM allocating stats array size %ld\n",
244 + SD_STATS * sizeof(iostat_stats_t *));
248 + for (i = 0; i < SD_STATS; i++)
249 + sd_iostats[i] = NULL;
251 + if (proc_scsi == NULL) {
252 + printk(KERN_WARNING "No access to sd iostats: "
253 + "proc_scsi is NULL\n");
257 + sd_iostats_procdir = create_proc_entry(sd_iostats_procdir_name,
258 + S_IFDIR | S_IRUGO | S_IXUGO,
260 + if (sd_iostats_procdir == NULL) {
261 + printk(KERN_WARNING "No access to sd iostats: "
262 + "can't create /proc/scsi/%s\n", sd_iostats_procdir_name);
268 +sd_iostats_init_disk(struct gendisk *disk)
270 + struct proc_dir_entry *pde;
271 + unsigned long flags;
272 + iostat_stats_t *stats;
274 + if (sd_iostats == NULL ||
275 + sd_iostats_procdir == NULL)
278 + if (scsi_disk(disk)->index > SD_STATS) {
279 + printk(KERN_ERR "sd_iostats_init_disk: "
280 + "unexpected disk index %d(%d)\n",
281 + scsi_disk(disk)->index, SD_STATS);
285 + if (sd_iostats[scsi_disk(disk)->index] != NULL)
288 + stats = kmalloc(sizeof(*stats), GFP_KERNEL);
289 + if (stats == NULL) {
290 + printk(KERN_WARNING "Can't keep %s iostats: "
291 + "ENOMEM allocating stats size %ld\n",
292 + disk->disk_name, sizeof(*stats));
296 + memset (stats, 0, sizeof(*stats));
297 + do_gettimeofday(&stats->iostat_timeval);
299 + spin_lock_irqsave(&sd_iostats_lock, flags);
301 + if (sd_iostats[scsi_disk(disk)->index] != NULL) {
302 + spin_unlock_irqrestore(&sd_iostats_lock, flags);
307 + sd_iostats[scsi_disk(disk)->index] = stats;
309 + spin_unlock_irqrestore(&sd_iostats_lock, flags);
311 + pde = create_proc_entry(disk->disk_name, S_IRUGO | S_IWUSR,
312 + sd_iostats_procdir);
314 + printk(KERN_WARNING "Can't create /proc/scsi/%s/%s\n",
315 + sd_iostats_procdir_name, disk->disk_name);
317 + pde->proc_fops = &sd_iostats_proc_fops;
322 +static void sd_devname(unsigned int disknum, char *buffer)
325 + sprintf(buffer, "sd%c", 'a' + disknum);
330 + * For larger numbers of disks, we need to go to a new
333 + min1 = disknum / 26;
334 + min2 = disknum % 26;
335 + sprintf(buffer, "sd%c%c", 'a' + min1 - 1, 'a' + min2);
340 +sd_iostats_fini(void)
345 + if (sd_iostats_procdir != NULL) {
346 + for (i = 0; i < SD_STATS; i++) {
347 + sd_devname(i, name);
348 + remove_proc_entry(name, sd_iostats_procdir);
351 + if (proc_scsi == NULL) {
352 + printk(KERN_ERR "sd_iostats_fini: proc_scsi NULL\n");
355 + remove_proc_entry(sd_iostats_procdir_name,
358 + sd_iostats_procdir = NULL;
361 + if (sd_iostats != NULL) {
362 + for (i = 0; i < SD_STATS; i++) {
363 + if (sd_iostats[i] != NULL)
364 + kfree (sd_iostats[i]);
373 +sd_iostats_bump(int disk, unsigned int nsect, int iswrite)
375 + iostat_stats_t *stats;
376 + iostat_counter_t *counter;
379 + unsigned long irqflags;
381 + if (sd_iostats == NULL)
384 + if (disk < 0 || disk >= SD_STATS) {
385 + printk(KERN_ERR "sd_iostats_bump: unexpected disk index %d([0-%d])\n",
390 + for (bucket = 0, tmp = nsect; tmp > 1; bucket++)
393 + if (bucket >= IOSTAT_NCOUNTERS) {
394 + printk (KERN_ERR "sd_iostats_bump: nsect %d too big\n", nsect);
398 + spin_lock_irqsave(&sd_iostats_lock, irqflags);
400 + stats = sd_iostats[disk];
401 + if (stats != NULL) {
402 + counter = iswrite ?
403 + &stats->iostat_write_histogram[bucket] :
404 + &stats->iostat_read_histogram[bucket];
406 + counter->iostat_size += nsect;
407 + counter->iostat_count++;
410 + spin_unlock_irqrestore(&sd_iostats_lock, irqflags);
415 * init_sd - entry point for this driver (both when built in or when
417 @@ -1582,6 +1940,7 @@
418 static int __init init_sd(void)
423 SCSI_LOG_HLQUEUE(3, printk("init_sd: sd driver entry point\n"));
425 @@ -1592,7 +1951,10 @@
429 - return scsi_register_driver(&sd_template.gendrv);
430 + rc = scsi_register_driver(&sd_template.gendrv);
437 @@ -1606,6 +1968,7 @@
439 SCSI_LOG_HLQUEUE(3, printk("exit_sd: exiting sd driver\n"));
442 scsi_unregister_driver(&sd_template.gendrv);
443 for (i = 0; i < SD_MAJORS; i++)
444 unregister_blkdev(sd_major(i), "sd");
445 Index: linux-2.6.9-5.0.3.EL/drivers/scsi/scsi_proc.c
446 ===================================================================
447 --- linux-2.6.9-5.0.3.EL.orig/drivers/scsi/scsi_proc.c 2005-04-01 18:36:39.234037240 +0300
448 +++ linux-2.6.9-5.0.3.EL/drivers/scsi/scsi_proc.c 2005-04-01 18:36:45.578072800 +0300
450 /* 4K page size, but our output routines, use some slack for overruns */
451 #define PROC_BLOCK_SIZE (3*1024)
453 -static struct proc_dir_entry *proc_scsi;
454 +struct proc_dir_entry *proc_scsi;
455 +EXPORT_SYMBOL(proc_scsi);
457 /* Protect sht->present and sht->proc_dir */
458 static DECLARE_MUTEX(global_host_template_sem);