lkml.org 
[lkml]   [1998]   [Dec]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: disks stats through /proc
Date
From
Lately, Tigran Aivazian announced:
>
> PS. Btw, whoever is responsible for add_request() the if (disk_index < 4)
> should really be if (disk_index < DK_NDRIVE) in there.

I posted a patch to fix this a while ago (although I'm not responsible
for the original code.) I use it for over a year now...
See the patch below against 2.1.131.

It would be better to determine the number of disk at boottime and dynamically
allocate space for disk statistics array. Or even better to make it a list
so we can keep stats on dynamically added disks.

-Marcel
--
======-------- Marcel J.E. Mol MESA Consulting B.V.
=======--------- ph. 015-3101310/06-54724868 P.O. Box 9
=======--------- marcel@mesa.nl 2270 AA Voorburg
__==== www.mesa.nl ---____U_n_i_x______I_n_t_e_r_n_e_t____ The Netherlands ____

--- linux-2.1.131/drivers/block/ll_rw_blk.c Thu Nov 12 07:30:16 1998
+++ linux/drivers/block/ll_rw_blk.c Fri Dec 4 23:17:23 1998
@@ -3,6 +3,9 @@
*
* Copyright (C) 1991, 1992 Linus Torvalds
* Copyright (C) 1994, Karl Keyte: Added support for disk statistics
+ *
+ * Marcel Mol : 18feb1998 marcel@mesa.nl
+ * Disk statistics depend on DK_NDRIVE
*/

/*
@@ -268,6 +271,9 @@
static inline void drive_stat_acct(int cmd, unsigned long nr_sectors,
short disk_index)
{
+ if (disk_index >= DK_NDRIVE)
+ return;
+
kstat.dk_drive[disk_index]++;
if (cmd == READ) {
kstat.dk_drive_rio[disk_index]++;
@@ -299,20 +305,19 @@
switch (MAJOR(req->rq_dev)) {
case SCSI_DISK0_MAJOR:
disk_index = (MINOR(req->rq_dev) & 0x00f0) >> 4;
- if (disk_index < 4)
- drive_stat_acct(req->cmd, req->nr_sectors, disk_index);
break;
case IDE0_MAJOR: /* same as HD_MAJOR */
case XT_DISK_MAJOR:
disk_index = (MINOR(req->rq_dev) & 0x0040) >> 6;
- drive_stat_acct(req->cmd, req->nr_sectors, disk_index);
break;
case IDE1_MAJOR:
disk_index = ((MINOR(req->rq_dev) & 0x0040) >> 6) + 2;
- drive_stat_acct(req->cmd, req->nr_sectors, disk_index);
default:
+ disk_index = -1;
break;
}
+ if (disk_index >= 0)
+ drive_stat_acct(req->cmd, req->nr_sectors, disk_index);

req->next = NULL;

diff -u --recursive --ignore-all-space linux-2.1.131/fs/proc/array.c linux/fs/proc/array.c
--- linux-2.1.131/fs/proc/array.c Sun Nov 22 20:38:46 1998
+++ linux/fs/proc/array.c Fri Dec 4 19:50:10 1998
@@ -42,6 +42,8 @@
* Alan Cox : security fixes.
* <Alan.Cox@linux.org>
*
+ * Marcel Mol : 18feb1998 marcel@mesa.nl
+ * Disk info in /proc/stat depends on DK_NDRIVE
*/

#include <linux/types.h>
@@ -237,13 +239,13 @@
for (i = 0 ; i < NR_IRQS ; i++)
sum += kstat_irqs(i);

-#ifdef __SMP__
len = sprintf(buffer,
"cpu %u %u %u %lu\n",
kstat.cpu_user,
kstat.cpu_nice,
kstat.cpu_system,
- jiffies*smp_num_cpus - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system));
+ ticks - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system));
+#ifdef __SMP__
for (i = 0 ; i < smp_num_cpus; i++)
len += sprintf(buffer + len, "cpu%d %u %u %u %lu\n",
i,
@@ -253,41 +255,27 @@
jiffies - ( kstat.per_cpu_user[cpu_logical_map(i)] \
+ kstat.per_cpu_nice[cpu_logical_map(i)] \
+ kstat.per_cpu_system[cpu_logical_map(i)]));
+#endif
+ len += sprintf(buffer + len, "disk");
+ for (i = 0 ; i < DK_NDRIVE; i++)
+ len += sprintf(buffer + len, " %u", kstat.dk_drive[i]);
+ len += sprintf(buffer + len, "\ndisk_rio");
+ for (i = 0 ; i < DK_NDRIVE; i++)
+ len += sprintf(buffer + len, " %u", kstat.dk_drive_rio[i]);
+ len += sprintf(buffer + len, "\ndisk_wio");
+ for (i = 0 ; i < DK_NDRIVE; i++)
+ len += sprintf(buffer + len, " %u", kstat.dk_drive_wio[i]);
+ len += sprintf(buffer + len, "\ndisk_rblk");
+ for (i = 0 ; i < DK_NDRIVE; i++)
+ len += sprintf(buffer + len, " %u", kstat.dk_drive_rblk[i]);
+ len += sprintf(buffer + len, "\ndisk_wblk");
+ for (i = 0 ; i < DK_NDRIVE; i++)
+ len += sprintf(buffer + len, " %u", kstat.dk_drive_wblk[i]);
len += sprintf(buffer + len,
- "disk %u %u %u %u\n"
- "disk_rio %u %u %u %u\n"
- "disk_wio %u %u %u %u\n"
- "disk_rblk %u %u %u %u\n"
- "disk_wblk %u %u %u %u\n"
- "page %u %u\n"
- "swap %u %u\n"
- "intr %u",
-#else
- len = sprintf(buffer,
- "cpu %u %u %u %lu\n"
- "disk %u %u %u %u\n"
- "disk_rio %u %u %u %u\n"
- "disk_wio %u %u %u %u\n"
- "disk_rblk %u %u %u %u\n"
- "disk_wblk %u %u %u %u\n"
+ "\n"
"page %u %u\n"
"swap %u %u\n"
"intr %u",
- kstat.cpu_user,
- kstat.cpu_nice,
- kstat.cpu_system,
- ticks - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system),
-#endif
- kstat.dk_drive[0], kstat.dk_drive[1],
- kstat.dk_drive[2], kstat.dk_drive[3],
- kstat.dk_drive_rio[0], kstat.dk_drive_rio[1],
- kstat.dk_drive_rio[2], kstat.dk_drive_rio[3],
- kstat.dk_drive_wio[0], kstat.dk_drive_wio[1],
- kstat.dk_drive_wio[2], kstat.dk_drive_wio[3],
- kstat.dk_drive_rblk[0], kstat.dk_drive_rblk[1],
- kstat.dk_drive_rblk[2], kstat.dk_drive_rblk[3],
- kstat.dk_drive_wblk[0], kstat.dk_drive_wblk[1],
- kstat.dk_drive_wblk[2], kstat.dk_drive_wblk[3],
kstat.pgpgin,
kstat.pgpgout,
kstat.pswpin,
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:45    [W:0.256 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site