rf_debugprint.c revision 1.5 1 1.5 lukem /* $NetBSD: rf_debugprint.c,v 1.5 2001/11/13 07:11:13 lukem 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.5 lukem
36 1.5 lukem #include <sys/cdefs.h>
37 1.5 lukem __KERNEL_RCSID(0, "$NetBSD: rf_debugprint.c,v 1.5 2001/11/13 07:11:13 lukem Exp $");
38 1.1 oster
39 1.4 oster #include <dev/raidframe/raidframevar.h>
40 1.4 oster
41 1.1 oster #include "rf_threadstuff.h"
42 1.1 oster #include "rf_debugprint.h"
43 1.1 oster #include "rf_general.h"
44 1.1 oster #include "rf_options.h"
45 1.1 oster
46 1.1 oster #include <sys/param.h>
47 1.1 oster
48 1.1 oster struct RF_Entry_s {
49 1.3 oster char *cstring;
50 1.3 oster void *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
51 1.1 oster };
52 1.1 oster /* space for 1k lines */
53 1.1 oster #define BUFSHIFT 10
54 1.1 oster #define BUFSIZE (1<<BUFSHIFT)
55 1.1 oster #define BUFMASK (BUFSIZE-1)
56 1.1 oster
57 1.1 oster static struct RF_Entry_s rf_debugprint_buf[BUFSIZE];
58 1.1 oster static int rf_debugprint_index = 0;
59 1.1 oster RF_DECLARE_STATIC_MUTEX(rf_debug_print_mutex)
60 1.3 oster int rf_ConfigureDebugPrint(listp)
61 1.3 oster RF_ShutdownList_t **listp;
62 1.1 oster {
63 1.3 oster int rc;
64 1.1 oster
65 1.3 oster rc = rf_create_managed_mutex(listp, &rf_debug_print_mutex);
66 1.3 oster if (rc) {
67 1.3 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
68 1.3 oster __LINE__, rc);
69 1.3 oster return (rc);
70 1.3 oster }
71 1.3 oster rf_clear_debug_print_buffer();
72 1.3 oster return (0);
73 1.1 oster }
74 1.1 oster
75 1.3 oster void
76 1.3 oster rf_clear_debug_print_buffer()
77 1.1 oster {
78 1.3 oster int i;
79 1.1 oster
80 1.3 oster for (i = 0; i < BUFSIZE; i++)
81 1.3 oster rf_debugprint_buf[i].cstring = NULL;
82 1.3 oster rf_debugprint_index = 0;
83 1.1 oster }
84 1.1 oster
85 1.3 oster void
86 1.3 oster rf_debug_printf(s, a1, a2, a3, a4, a5, a6, a7, a8)
87 1.3 oster char *s;
88 1.3 oster void *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
89 1.1 oster {
90 1.3 oster int idx;
91 1.1 oster
92 1.3 oster if (rf_debugPrintUseBuffer) {
93 1.1 oster
94 1.3 oster RF_LOCK_MUTEX(rf_debug_print_mutex);
95 1.3 oster idx = rf_debugprint_index;
96 1.3 oster rf_debugprint_index = (rf_debugprint_index + 1) & BUFMASK;
97 1.3 oster RF_UNLOCK_MUTEX(rf_debug_print_mutex);
98 1.3 oster
99 1.3 oster rf_debugprint_buf[idx].cstring = s;
100 1.3 oster rf_debugprint_buf[idx].a1 = a1;
101 1.3 oster rf_debugprint_buf[idx].a2 = a2;
102 1.3 oster rf_debugprint_buf[idx].a3 = a3;
103 1.3 oster rf_debugprint_buf[idx].a4 = a4;
104 1.3 oster rf_debugprint_buf[idx].a5 = a5;
105 1.3 oster rf_debugprint_buf[idx].a6 = a6;
106 1.3 oster rf_debugprint_buf[idx].a7 = a7;
107 1.3 oster rf_debugprint_buf[idx].a8 = a8;
108 1.3 oster } else {
109 1.3 oster printf(s, a1, a2, a3, a4, a5, a6, a7, a8);
110 1.3 oster }
111 1.1 oster }
112 1.1 oster
113 1.3 oster void
114 1.3 oster rf_print_debug_buffer()
115 1.1 oster {
116 1.3 oster rf_spill_debug_buffer(NULL);
117 1.1 oster }
118 1.1 oster
119 1.3 oster void
120 1.3 oster rf_spill_debug_buffer(fname)
121 1.3 oster char *fname;
122 1.1 oster {
123 1.3 oster int i;
124 1.1 oster
125 1.3 oster if (!rf_debugPrintUseBuffer)
126 1.3 oster return;
127 1.1 oster
128 1.3 oster RF_LOCK_MUTEX(rf_debug_print_mutex);
129 1.2 oster
130 1.3 oster for (i = rf_debugprint_index + 1; i != rf_debugprint_index; i = (i + 1) & BUFMASK)
131 1.3 oster if (rf_debugprint_buf[i].cstring)
132 1.3 oster printf(rf_debugprint_buf[i].cstring, rf_debugprint_buf[i].a1, rf_debugprint_buf[i].a2, rf_debugprint_buf[i].a3,
133 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);
134 1.3 oster printf(rf_debugprint_buf[i].cstring, rf_debugprint_buf[i].a1, rf_debugprint_buf[i].a2, rf_debugprint_buf[i].a3,
135 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);
136 1.3 oster RF_UNLOCK_MUTEX(rf_debug_print_mutex);
137 1.1 oster }
138