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 "tracefile.h"
24
25 #ifndef get_cpu
26 #define get_cpu() smp_processor_id()
27 #define put_cpu() do { } while (0)
28 #endif
29
30 #define TCD_TYPE_MAX        1
31
32 event_t     tracefile_event;
33
34 void tracefile_init_arch()
35 {
36         int    i;
37         int    j;
38     struct trace_cpu_data *tcd;
39
40     cfs_init_event(&tracefile_event, TRUE, TRUE);
41
42     /* initialize trace_data */
43     memset(trace_data, 0, sizeof(trace_data));
44     for (i = 0; i < TCD_TYPE_MAX; i++) {
45         trace_data[i]=cfs_alloc(sizeof(struct trace_data_union)*NR_CPUS, 0);
46         if (trace_data[i] == NULL)
47             goto out;
48     }
49
50     /* arch related info initialized */
51     tcd_for_each(tcd, i, j) {
52         tcd->tcd_pages_factor = 100; /* Only one type */
53         tcd->tcd_cpu = j;
54         tcd->tcd_type = i;
55     }
56
57     memset(trace_console_buffers, 0, sizeof(trace_console_buffers));
58
59         for (i = 0; i < NR_CPUS; i++) {
60                 for (j = 0; j < 1; j++) {
61                         trace_console_buffers[i][j] =
62                                 cfs_alloc(TRACE_CONSOLE_BUFFER_SIZE,
63                                         CFS_ALLOC_ZERO);
64
65                         if (trace_console_buffers[i][j] == NULL)
66                 goto out;
67                 }
68     }
69
70         return 0;
71
72 out:
73         tracefile_fini_arch();
74         KsPrint((0, "lnet: No enough memory\n"));
75         return -ENOMEM;
76 }
77
78 void tracefile_fini_arch()
79 {
80         int    i;
81         int    j;
82
83         for (i = 0; i < NR_CPUS; i++) {
84                 for (j = 0; j < 2; j++) {
85                         if (trace_console_buffers[i][j] != NULL) {
86                                 cfs_free(trace_console_buffers[i][j]);
87                                 trace_console_buffers[i][j] = NULL;
88                         }
89         }
90     }
91
92     for (i = 0; trace_data[i] != NULL; i++) {
93         cfs_free(trace_data[i]);
94         trace_data[i] = NULL;
95     }
96 }
97
98 void tracefile_read_lock()
99 {
100     cfs_wait_event(&tracefile_event, 0);
101 }
102
103 void tracefile_read_unlock()
104 {
105     cfs_wake_event(&tracefile_event);
106 }
107
108 void tracefile_write_lock()
109 {
110     cfs_wait_event(&tracefile_event, 0);
111 }
112
113 void tracefile_write_unlock()
114 {
115     cfs_wake_event(&tracefile_event);
116 }
117
118 char *
119 trace_get_console_buffer(void)
120 {
121 #pragma message ("is there possible problem with pre-emption ?")
122     int cpu = (int) KeGetCurrentProcessorNumber();
123     return trace_console_buffers[cpu][0];
124 }
125
126 void
127 trace_put_console_buffer(char *buffer)
128 {
129 }
130
131 struct trace_cpu_data *
132 trace_get_tcd(void)
133 {
134 #pragma message("todo: return NULL if in interrupt context")
135
136         int cpu = (int) KeGetCurrentProcessorNumber();
137         return &(*trace_data[0])[cpu].tcd;
138 }
139
140 void
141 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
142 {
143 }
144
145 int 
146 trace_lock_tcd(struct trace_cpu_data *tcd)
147 {
148     __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
149     return 1;
150 }
151
152 void
153 trace_unlock_tcd(struct trace_cpu_data *tcd)
154 {
155     __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
156 }
157
158 void
159 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
160                     const int line, unsigned long stack)
161 {
162         struct timeval tv;
163
164         do_gettimeofday(&tv);
165
166         header->ph_subsys = subsys;
167         header->ph_mask = mask;
168         header->ph_cpu_id = smp_processor_id();
169         header->ph_sec = (__u32)tv.tv_sec;
170         header->ph_usec = tv.tv_usec;
171         header->ph_stack = stack;
172         header->ph_pid = current->pid;
173         header->ph_line_num = line;
174         header->ph_extern_pid = 0;
175         return;
176 }
177
178 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
179                                   int len, const char *file, const char *fn)
180 {
181         char *prefix = NULL, *ptype = NULL;
182
183         if ((mask & D_EMERG) != 0) {
184                 prefix = "LustreError";
185                 ptype = KERN_EMERG;
186         } else if ((mask & D_ERROR) != 0) {
187                 prefix = "LustreError";
188                 ptype = KERN_ERR;
189         } else if ((mask & D_WARNING) != 0) {
190                 prefix = "Lustre";
191                 ptype = KERN_WARNING;
192         } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
193                 prefix = "Lustre";
194                 ptype = KERN_INFO;
195         }
196
197         if ((mask & D_CONSOLE) != 0) {
198                 printk("%s%s: %s", ptype, prefix, buf);
199         } else {
200                 printk("%s%s: %d:%d:(%s:%d:%s()) %s", ptype, prefix, hdr->ph_pid,
201                        hdr->ph_extern_pid, file, hdr->ph_line_num, fn, buf);
202         }
203         return;
204 }
205
206 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
207 {
208         return 1;
209 }
210
211 int trace_max_debug_mb(void)
212 {
213         int  total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
214         
215         return MAX(512, (total_mb * 80)/100);
216 }
217
218 void
219 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
220 {
221 #error "tbd"
222 }
223