1 /* $NetBSD: rf_acctrace.c,v 1.10 2002/09/14 18:17:52 oster 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@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/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: rf_acctrace.c,v 1.10 2002/09/14 18:17:52 oster Exp $"); 38 39 #include <sys/stat.h> 40 #include <sys/types.h> 41 #include <dev/raidframe/raidframevar.h> 42 43 #include "rf_threadstuff.h" 44 #include "rf_debugMem.h" 45 #include "rf_acctrace.h" 46 #include "rf_general.h" 47 #include "rf_raid.h" 48 #include "rf_etimer.h" 49 #include "rf_hist.h" 50 #include "rf_shutdown.h" 51 52 static long numTracesSoFar; 53 static int accessTraceBufCount = 0; 54 static RF_AccTraceEntry_t *access_tracebuf; 55 56 int rf_stopCollectingTraces; 57 RF_DECLARE_MUTEX(rf_tracing_mutex) 58 59 static void rf_ShutdownAccessTrace(void *); 60 61 static void rf_ShutdownAccessTrace(ignored) 62 void *ignored; 63 { 64 if (rf_accessTraceBufSize) { 65 if (accessTraceBufCount) 66 accessTraceBufCount = 0; 67 RF_Free(access_tracebuf, rf_accessTraceBufSize * sizeof(RF_AccTraceEntry_t)); 68 } 69 rf_mutex_destroy(&rf_tracing_mutex); 70 } 71 72 int 73 rf_ConfigureAccessTrace(listp) 74 RF_ShutdownList_t **listp; 75 { 76 int rc; 77 78 accessTraceBufCount = rf_stopCollectingTraces = 0; 79 if (rf_accessTraceBufSize) { 80 RF_Malloc(access_tracebuf, rf_accessTraceBufSize * sizeof(RF_AccTraceEntry_t), (RF_AccTraceEntry_t *)); 81 accessTraceBufCount = 0; 82 } 83 numTracesSoFar = 0; 84 rc = rf_mutex_init(&rf_tracing_mutex); 85 if (rc) { 86 rf_print_unable_to_init_mutex(__FILE__, __LINE__, rc); 87 } 88 rc = rf_ShutdownCreate(listp, rf_ShutdownAccessTrace, NULL); 89 if (rc) { 90 rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc); 91 if (rf_accessTraceBufSize) { 92 RF_Free(access_tracebuf, rf_accessTraceBufSize * sizeof(RF_AccTraceEntry_t)); 93 rf_mutex_destroy(&rf_tracing_mutex); 94 } 95 } 96 return (rc); 97 } 98 /* install a trace record. cause a flush to disk or to the trace collector daemon 99 * if the trace buffer is at least 1/2 full. 100 */ 101 void 102 rf_LogTraceRec(raid, rec) 103 RF_Raid_t *raid; 104 RF_AccTraceEntry_t *rec; 105 { 106 RF_AccTotals_t *acc = &raid->acc_totals; 107 108 if (rf_stopCollectingTraces || ((rf_maxNumTraces >= 0) && (numTracesSoFar >= rf_maxNumTraces))) 109 return; 110 111 /* update AccTotals for this device */ 112 if (!raid->keep_acc_totals) 113 return; 114 acc->num_log_ents++; 115 if (rec->reconacc) { 116 acc->recon_start_to_fetch_us += rec->specific.recon.recon_start_to_fetch_us; 117 acc->recon_fetch_to_return_us += rec->specific.recon.recon_fetch_to_return_us; 118 acc->recon_return_to_submit_us += rec->specific.recon.recon_return_to_submit_us; 119 acc->recon_num_phys_ios += rec->num_phys_ios; 120 acc->recon_phys_io_us += rec->phys_io_us; 121 acc->recon_diskwait_us += rec->diskwait_us; 122 acc->recon_reccount++; 123 } else { 124 RF_HIST_ADD(acc->tot_hist, rec->total_us); 125 RF_HIST_ADD(acc->dw_hist, rec->diskwait_us); 126 /* count of physical ios which are too big. often due to 127 * thermal recalibration */ 128 /* if bigvals > 0, you should probably ignore this data set */ 129 if (rec->diskwait_us > 100000) 130 acc->bigvals++; 131 acc->total_us += rec->total_us; 132 acc->suspend_ovhd_us += rec->specific.user.suspend_ovhd_us; 133 acc->map_us += rec->specific.user.map_us; 134 acc->lock_us += rec->specific.user.lock_us; 135 acc->dag_create_us += rec->specific.user.dag_create_us; 136 acc->dag_retry_us += rec->specific.user.dag_retry_us; 137 acc->exec_us += rec->specific.user.exec_us; 138 acc->cleanup_us += rec->specific.user.cleanup_us; 139 acc->exec_engine_us += rec->specific.user.exec_engine_us; 140 acc->xor_us += rec->xor_us; 141 acc->q_us += rec->q_us; 142 acc->plog_us += rec->plog_us; 143 acc->diskqueue_us += rec->diskqueue_us; 144 acc->diskwait_us += rec->diskwait_us; 145 acc->num_phys_ios += rec->num_phys_ios; 146 acc->phys_io_us = rec->phys_io_us; 147 acc->user_reccount++; 148 } 149 } 150