patch for 2.1.92: cleanup of disk statistics code

Marcel J.E. Mol (marcel@mesa.nl)
Fri, 3 Apr 1998 23:44:05 +0200 (MET DST)


Hi Linus,

One more try. This patch does some cleanup on disk statistics.
All it does is removing a hardcoded number in the code that
collects disk io count stats. The hardcoded number is replaced
by the DK_NDRIVE definition as it should be in the first place.
This causes changes in drivers/block/ll_rw_blk.c and fs/proc/array.c.
It also cleans up around the __SMP__ code get_kstat().

I've been running this patch for over a year now without any problems.

Below diffs are against 2.1.92. I'd appreciate to see them back in
the next 2.1 or 2.2 release...

-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 ____

diff -u --recursive linux/drivers/block/ll_rw_blk.c linux-2.1.92/drivers/block/ll_rw_blk.c --- linux/drivers/block/ll_rw_blk.c Sun Mar 29 22:24:05 1998 +++ linux-2.1.92/drivers/block/ll_rw_blk.c Thu Apr 2 23:38:27 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 + * Made disk statistics depend on DK_NDRIVE */ /* @@ -248,6 +251,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]++; @@ -271,25 +277,23 @@ void add_request(struct blk_dev_struct * dev, struct request * req) { struct request * tmp, **current_request; - short disk_index; + short disk_index = -1; switch (MAJOR(req->rq_dev)) { case SCSI_DISK_MAJOR: disk_index = (MINOR(req->rq_dev) & 0x0070) >> 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: break; } + if (disk_index != -1) + drive_stat_acct(req->cmd, req->nr_sectors, disk_index); req->next = NULL; current_request = get_queue(req->rq_dev); diff -u --recursive linux/fs/proc/array.c linux-2.1.92/fs/proc/array.c --- linux/fs/proc/array.c Thu Mar 12 00:53:18 1998 +++ linux-2.1.92/fs/proc/array.c Tue Mar 24 10:48:29 1998 @@ -35,6 +35,9 @@ * - Incorporation and non-SMP safe operation * of forissier patch in 2.1.78 by * Hans Marcus <crowbar@concepts.nl> + * + * Marcel Mol : 18feb1998 marcel@mesa.nl + * MAde disk info in /proc/stat depend on DK_NDRIVE */ #include <linux/types.h> @@ -230,13 +233,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, @@ -246,41 +249,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, "disk_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" - "page %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