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