Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / libcfs / libcfs / winnt / winnt-tracefile.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:
3  *
4  *  Copyright (c) 2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or modify it under
9  *   the terms of version 2 of the GNU General Public License as published by
10  *   the Free Software Foundation. Lustre is distributed in the hope that it
11  *   will be useful, but WITHOUT ANY WARRANTY; without even the implied
12  *   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details. You should have received a
14  *   copy of the GNU General Public License along with Lustre; if not, write
15  *   to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
16  *   USA.
17  */
18
19 #define DEBUG_SUBSYSTEM S_LNET
20 #define LUSTRE_TRACEFILE_PRIVATE
21
22 #include <libcfs/libcfs.h>
23 #include <libcfs/kp30.h>
24 #include "tracefile.h"
25
26 #ifndef get_cpu
27 #define get_cpu() smp_processor_id()
28 #define put_cpu() do { } while (0)
29 #endif
30
31 #define TCD_TYPE_MAX        1
32
33 event_t     tracefile_event;
34
35 void tracefile_init_arch()
36 {
37         int    i;
38         int    j;
39     struct trace_cpu_data *tcd;
40
41     cfs_init_event(&tracefile_event, TRUE, TRUE);
42
43     /* initialize trace_data */
44     memset(trace_data, 0, sizeof(trace_data));
45     for (i = 0; i < TCD_TYPE_MAX; i++) {
46         trace_data[i]=cfs_alloc(sizeof(struct trace_data_union)*NR_CPUS, 0);
47         if (trace_data[i] == NULL)
48             goto out;
49     }
50
51     /* arch related info initialized */
52     tcd_for_each(tcd, i, j) {
53         tcd->tcd_pages_factor = 100; /* Only one type */
54         tcd->tcd_cpu = j;
55         tcd->tcd_type = i;
56     }
57
58     memset(trace_console_buffers, 0, sizeof(trace_console_buffers));
59
60         for (i = 0; i < NR_CPUS; i++) {
61                 for (j = 0; j < 1; j++) {
62                         trace_console_buffers[i][j] =
63                                 cfs_alloc(TRACE_CONSOLE_BUFFER_SIZE,
64                                         CFS_ALLOC_ZERO);
65
66                         if (trace_console_buffers[i][j] == NULL)
67                 goto out;
68                 }
69     }
70
71         return 0;
72
73 out:
74         tracefile_fini_arch();
75         KsPrint((0, "lnet: No enough memory\n"));
76         return -ENOMEM;
77 }
78
79 void tracefile_fini_arch()
80 {
81         int    i;
82         int    j;
83
84         for (i = 0; i < NR_CPUS; i++) {
85                 for (j = 0; j < 2; j++) {
86                         if (trace_console_buffers[i][j] != NULL) {
87                                 cfs_free(trace_console_buffers[i][j]);
88                                 trace_console_buffers[i][j] = NULL;
89                         }
90         }
91     }
92
93     for (i = 0; trace_data[i] != NULL; i++) {
94         cfs_free(trace_data[i]);
95         trace_data[i] = NULL;
96     }
97 }
98
99 void tracefile_read_lock()
100 {
101     cfs_wait_event(&tracefile_event, 0);
102 }
103
104 void tracefile_read_unlock()
105 {
106     cfs_wake_event(&tracefile_event);
107 }
108
109 void tracefile_write_lock()
110 {
111     cfs_wait_event(&tracefile_event, 0);
112 }
113
114 void tracefile_write_unlock()
115 {
116     cfs_wake_event(&tracefile_event);
117 }
118
119 char *
120 trace_get_console_buffer(void)
121 {
122 #pragma message ("is there possible problem with pre-emption ?")
123     int cpu = (int) KeGetCurrentProcessorNumber();
124     return trace_console_buffers[cpu][0];
125 }
126
127 void
128 trace_put_console_buffer(char *buffer)
129 {
130 }
131
132 struct trace_cpu_data *
133 trace_get_tcd(void)
134 {
135 #pragma message("todo: return NULL if in interrupt context")
136
137         int cpu = (int) KeGetCurrentProcessorNumber();
138         return &(*trace_data[0])[cpu].tcd;
139 }
140
141 void
142 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
143 {
144 }
145
146 int 
147 trace_lock_tcd(struct trace_cpu_data *tcd)
148 {
149     __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
150     return 1;
151 }
152
153 void
154 trace_unlock_tcd(struct trace_cpu_data *tcd)
155 {
156     __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
157 }
158
159 void
160 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
161                     const int line, unsigned long stack)
162 {
163         struct timeval tv;
164
165         do_gettimeofday(&tv);
166
167         header->ph_subsys = subsys;
168         header->ph_mask = mask;
169         header->ph_cpu_id = smp_processor_id();
170         header->ph_sec = (__u32)tv.tv_sec;
171         header->ph_usec = tv.tv_usec;
172         header->ph_stack = stack;
173         header->ph_pid = current->pid;
174         header->ph_line_num = line;
175         header->ph_extern_pid = 0;
176         return;
177 }
178
179 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
180                                   int len, const char *file, const char *fn)
181 {
182         char *prefix = NULL, *ptype = NULL;
183
184         if ((mask & D_EMERG) != 0) {
185                 prefix = "LustreError";
186                 ptype = KERN_EMERG;
187         } else if ((mask & D_ERROR) != 0) {
188                 prefix = "LustreError";
189                 ptype = KERN_ERR;
190         } else if ((mask & D_WARNING) != 0) {
191                 prefix = "Lustre";
192                 ptype = KERN_WARNING;
193         } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
194                 prefix = "Lustre";
195                 ptype = KERN_INFO;
196         }
197
198         if ((mask & D_CONSOLE) != 0) {
199                 printk("%s%s: %s", ptype, prefix, buf);
200         } else {
201                 printk("%s%s: %d:%d:(%s:%d:%s()) %s", ptype, prefix, hdr->ph_pid,
202                        hdr->ph_extern_pid, file, hdr->ph_line_num, fn, buf);
203         }
204         return;
205 }
206
207 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
208 {
209         return 1;
210 }
211
212 int trace_max_debug_mb(void)
213 {
214         int  total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
215         
216         return MAX(512, (total_mb * 80)/100);
217 }
218
219 void
220 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
221 {
222 #error "tbd"
223 }
224