Home | History | Annotate | Line # | Download | only in raidframe
rf_acctrace.c revision 1.4.14.1
      1 /*	$NetBSD: rf_acctrace.c,v 1.4.14.1 2001/10/22 20:41:32 nathanw Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: Mark Holland
      7  *
      8  * Permission to use, copy, modify and distribute this software and
      9  * its documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie the
     26  * rights to redistribute these changes.
     27  */
     28 
     29 /*****************************************************************************
     30  *
     31  * acctrace.c -- code to support collecting information about each access
     32  *
     33  *****************************************************************************/
     34 
     35 
     36 #include <sys/stat.h>
     37 #include <sys/types.h>
     38 #include <dev/raidframe/raidframevar.h>
     39 
     40 #include "rf_threadstuff.h"
     41 #include "rf_debugMem.h"
     42 #include "rf_acctrace.h"
     43 #include "rf_general.h"
     44 #include "rf_raid.h"
     45 #include "rf_etimer.h"
     46 #include "rf_hist.h"
     47 #include "rf_shutdown.h"
     48 
     49 static long numTracesSoFar;
     50 static int accessTraceBufCount = 0;
     51 static RF_AccTraceEntry_t *access_tracebuf;
     52 static long traceCount;
     53 
     54 int     rf_stopCollectingTraces;
     55 RF_DECLARE_MUTEX(rf_tracing_mutex)
     56 	int     rf_trace_fd;
     57 
     58 	static void rf_ShutdownAccessTrace(void *);
     59 
     60 	static void rf_ShutdownAccessTrace(ignored)
     61 	void   *ignored;
     62 {
     63 	if (rf_accessTraceBufSize) {
     64 		if (accessTraceBufCount)
     65 			rf_FlushAccessTraceBuf();
     66 		RF_Free(access_tracebuf, rf_accessTraceBufSize * sizeof(RF_AccTraceEntry_t));
     67 	}
     68 	rf_mutex_destroy(&rf_tracing_mutex);
     69 }
     70 
     71 int
     72 rf_ConfigureAccessTrace(listp)
     73 	RF_ShutdownList_t **listp;
     74 {
     75 	int     rc;
     76 
     77 	numTracesSoFar = accessTraceBufCount = rf_stopCollectingTraces = 0;
     78 	if (rf_accessTraceBufSize) {
     79 		RF_Malloc(access_tracebuf, rf_accessTraceBufSize * sizeof(RF_AccTraceEntry_t), (RF_AccTraceEntry_t *));
     80 		accessTraceBufCount = 0;
     81 	}
     82 	traceCount = 0;
     83 	numTracesSoFar = 0;
     84 	rc = rf_mutex_init(&rf_tracing_mutex);
     85 	if (rc) {
     86 		RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
     87 		    __LINE__, rc);
     88 	}
     89 	rc = rf_ShutdownCreate(listp, rf_ShutdownAccessTrace, NULL);
     90 	if (rc) {
     91 		RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
     92 		    __LINE__, rc);
     93 		if (rf_accessTraceBufSize) {
     94 			RF_Free(access_tracebuf, rf_accessTraceBufSize * sizeof(RF_AccTraceEntry_t));
     95 			rf_mutex_destroy(&rf_tracing_mutex);
     96 		}
     97 	}
     98 	return (rc);
     99 }
    100 /* install a trace record.  cause a flush to disk or to the trace collector daemon
    101  * if the trace buffer is at least 1/2 full.
    102  */
    103 void
    104 rf_LogTraceRec(raid, rec)
    105 	RF_Raid_t *raid;
    106 	RF_AccTraceEntry_t *rec;
    107 {
    108 	RF_AccTotals_t *acc = &raid->acc_totals;
    109 
    110 	if (rf_stopCollectingTraces || ((rf_maxNumTraces >= 0) && (numTracesSoFar >= rf_maxNumTraces)))
    111 		return;
    112 
    113 	/* update AccTotals for this device */
    114 	if (!raid->keep_acc_totals)
    115 		return;
    116 	acc->num_log_ents++;
    117 	if (rec->reconacc) {
    118 		acc->recon_start_to_fetch_us += rec->specific.recon.recon_start_to_fetch_us;
    119 		acc->recon_fetch_to_return_us += rec->specific.recon.recon_fetch_to_return_us;
    120 		acc->recon_return_to_submit_us += rec->specific.recon.recon_return_to_submit_us;
    121 		acc->recon_num_phys_ios += rec->num_phys_ios;
    122 		acc->recon_phys_io_us += rec->phys_io_us;
    123 		acc->recon_diskwait_us += rec->diskwait_us;
    124 		acc->recon_reccount++;
    125 	} else {
    126 		RF_HIST_ADD(acc->tot_hist, rec->total_us);
    127 		RF_HIST_ADD(acc->dw_hist, rec->diskwait_us);
    128 		/* count of physical ios which are too big.  often due to
    129 		 * thermal recalibration */
    130 		/* if bigvals > 0, you should probably ignore this data set */
    131 		if (rec->diskwait_us > 100000)
    132 			acc->bigvals++;
    133 		acc->total_us += rec->total_us;
    134 		acc->suspend_ovhd_us += rec->specific.user.suspend_ovhd_us;
    135 		acc->map_us += rec->specific.user.map_us;
    136 		acc->lock_us += rec->specific.user.lock_us;
    137 		acc->dag_create_us += rec->specific.user.dag_create_us;
    138 		acc->dag_retry_us += rec->specific.user.dag_retry_us;
    139 		acc->exec_us += rec->specific.user.exec_us;
    140 		acc->cleanup_us += rec->specific.user.cleanup_us;
    141 		acc->exec_engine_us += rec->specific.user.exec_engine_us;
    142 		acc->xor_us += rec->xor_us;
    143 		acc->q_us += rec->q_us;
    144 		acc->plog_us += rec->plog_us;
    145 		acc->diskqueue_us += rec->diskqueue_us;
    146 		acc->diskwait_us += rec->diskwait_us;
    147 		acc->num_phys_ios += rec->num_phys_ios;
    148 		acc->phys_io_us = rec->phys_io_us;
    149 		acc->user_reccount++;
    150 	}
    151 }
    152 
    153 
    154 /* assumes the tracing mutex is locked at entry.  In order to allow this to be called
    155  * from interrupt context, we don't do any copyouts here, but rather just wake trace
    156  * buffer collector thread.
    157  */
    158 void
    159 rf_FlushAccessTraceBuf()
    160 {
    161 	accessTraceBufCount = 0;
    162 }
    163