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