Home | History | Annotate | Line # | Download | only in raidframe
rf_debugprint.c revision 1.4
      1  1.4  oster /*	$NetBSD: rf_debugprint.c,v 1.4 2001/10/04 15:58:52 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.3  oster /*
     30  1.1  oster  * Code to do debug printfs. Calls to rf_debug_printf cause the corresponding
     31  1.1  oster  * information to be printed to a circular buffer rather than the screen.
     32  1.1  oster  * The point is to try and minimize the timing variations induced by the
     33  1.1  oster  * printfs, and to capture only the printf's immediately preceding a failure.
     34  1.1  oster  */
     35  1.1  oster 
     36  1.4  oster #include <dev/raidframe/raidframevar.h>
     37  1.4  oster 
     38  1.1  oster #include "rf_threadstuff.h"
     39  1.1  oster #include "rf_debugprint.h"
     40  1.1  oster #include "rf_general.h"
     41  1.1  oster #include "rf_options.h"
     42  1.1  oster 
     43  1.1  oster #include <sys/param.h>
     44  1.1  oster 
     45  1.1  oster struct RF_Entry_s {
     46  1.3  oster 	char   *cstring;
     47  1.3  oster 	void   *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
     48  1.1  oster };
     49  1.1  oster /* space for 1k lines */
     50  1.1  oster #define BUFSHIFT 10
     51  1.1  oster #define BUFSIZE  (1<<BUFSHIFT)
     52  1.1  oster #define BUFMASK  (BUFSIZE-1)
     53  1.1  oster 
     54  1.1  oster static struct RF_Entry_s rf_debugprint_buf[BUFSIZE];
     55  1.1  oster static int rf_debugprint_index = 0;
     56  1.1  oster RF_DECLARE_STATIC_MUTEX(rf_debug_print_mutex)
     57  1.3  oster 	int     rf_ConfigureDebugPrint(listp)
     58  1.3  oster 	RF_ShutdownList_t **listp;
     59  1.1  oster {
     60  1.3  oster 	int     rc;
     61  1.1  oster 
     62  1.3  oster 	rc = rf_create_managed_mutex(listp, &rf_debug_print_mutex);
     63  1.3  oster 	if (rc) {
     64  1.3  oster 		RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
     65  1.3  oster 		    __LINE__, rc);
     66  1.3  oster 		return (rc);
     67  1.3  oster 	}
     68  1.3  oster 	rf_clear_debug_print_buffer();
     69  1.3  oster 	return (0);
     70  1.1  oster }
     71  1.1  oster 
     72  1.3  oster void
     73  1.3  oster rf_clear_debug_print_buffer()
     74  1.1  oster {
     75  1.3  oster 	int     i;
     76  1.1  oster 
     77  1.3  oster 	for (i = 0; i < BUFSIZE; i++)
     78  1.3  oster 		rf_debugprint_buf[i].cstring = NULL;
     79  1.3  oster 	rf_debugprint_index = 0;
     80  1.1  oster }
     81  1.1  oster 
     82  1.3  oster void
     83  1.3  oster rf_debug_printf(s, a1, a2, a3, a4, a5, a6, a7, a8)
     84  1.3  oster 	char   *s;
     85  1.3  oster 	void   *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
     86  1.1  oster {
     87  1.3  oster 	int     idx;
     88  1.1  oster 
     89  1.3  oster 	if (rf_debugPrintUseBuffer) {
     90  1.1  oster 
     91  1.3  oster 		RF_LOCK_MUTEX(rf_debug_print_mutex);
     92  1.3  oster 		idx = rf_debugprint_index;
     93  1.3  oster 		rf_debugprint_index = (rf_debugprint_index + 1) & BUFMASK;
     94  1.3  oster 		RF_UNLOCK_MUTEX(rf_debug_print_mutex);
     95  1.3  oster 
     96  1.3  oster 		rf_debugprint_buf[idx].cstring = s;
     97  1.3  oster 		rf_debugprint_buf[idx].a1 = a1;
     98  1.3  oster 		rf_debugprint_buf[idx].a2 = a2;
     99  1.3  oster 		rf_debugprint_buf[idx].a3 = a3;
    100  1.3  oster 		rf_debugprint_buf[idx].a4 = a4;
    101  1.3  oster 		rf_debugprint_buf[idx].a5 = a5;
    102  1.3  oster 		rf_debugprint_buf[idx].a6 = a6;
    103  1.3  oster 		rf_debugprint_buf[idx].a7 = a7;
    104  1.3  oster 		rf_debugprint_buf[idx].a8 = a8;
    105  1.3  oster 	} else {
    106  1.3  oster 		printf(s, a1, a2, a3, a4, a5, a6, a7, a8);
    107  1.3  oster 	}
    108  1.1  oster }
    109  1.1  oster 
    110  1.3  oster void
    111  1.3  oster rf_print_debug_buffer()
    112  1.1  oster {
    113  1.3  oster 	rf_spill_debug_buffer(NULL);
    114  1.1  oster }
    115  1.1  oster 
    116  1.3  oster void
    117  1.3  oster rf_spill_debug_buffer(fname)
    118  1.3  oster 	char   *fname;
    119  1.1  oster {
    120  1.3  oster 	int     i;
    121  1.1  oster 
    122  1.3  oster 	if (!rf_debugPrintUseBuffer)
    123  1.3  oster 		return;
    124  1.1  oster 
    125  1.3  oster 	RF_LOCK_MUTEX(rf_debug_print_mutex);
    126  1.2  oster 
    127  1.3  oster 	for (i = rf_debugprint_index + 1; i != rf_debugprint_index; i = (i + 1) & BUFMASK)
    128  1.3  oster 		if (rf_debugprint_buf[i].cstring)
    129  1.3  oster 			printf(rf_debugprint_buf[i].cstring, rf_debugprint_buf[i].a1, rf_debugprint_buf[i].a2, rf_debugprint_buf[i].a3,
    130  1.3  oster 			    rf_debugprint_buf[i].a4, rf_debugprint_buf[i].a5, rf_debugprint_buf[i].a6, rf_debugprint_buf[i].a7, rf_debugprint_buf[i].a8);
    131  1.3  oster 	printf(rf_debugprint_buf[i].cstring, rf_debugprint_buf[i].a1, rf_debugprint_buf[i].a2, rf_debugprint_buf[i].a3,
    132  1.3  oster 	    rf_debugprint_buf[i].a4, rf_debugprint_buf[i].a5, rf_debugprint_buf[i].a6, rf_debugprint_buf[i].a7, rf_debugprint_buf[i].a8);
    133  1.3  oster 	RF_UNLOCK_MUTEX(rf_debug_print_mutex);
    134  1.1  oster }
    135