Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / 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 extern union trace_data_union trace_data[NR_CPUS];
32
33 event_t     tracefile_event;
34
35 void tracefile_init_arch()
36 {
37         int    i;
38         int    j;
39
40     cfs_init_event(&tracefile_event, TRUE, TRUE);
41
42     memset(trace_console_buffers, 0, sizeof(trace_console_buffers));
43
44         for (i = 0; i < NR_CPUS; i++) {
45                 for (j = 0; j < 1; j++) {
46                         trace_console_buffers[i][j] =
47                                 cfs_alloc(TRACE_CONSOLE_BUFFER_SIZE,
48                                         CFS_ALLOC_ZERO);
49
50                         if (trace_console_buffers[i][j] == NULL) {
51                                 tracefile_fini_arch();
52                                 KsPrint((0, "Can't allocate console message buffer\n"));
53                                 return -ENOMEM;
54                         }
55                 }
56     }
57
58         return 0;
59 }
60
61 void tracefile_fini_arch()
62 {
63         int    i;
64         int    j;
65
66         for (i = 0; i < NR_CPUS; i++) {
67                 for (j = 0; j < 2; j++) {
68                         if (trace_console_buffers[i][j] != NULL) {
69                                 cfs_free(trace_console_buffers[i][j]);
70                                 trace_console_buffers[i][j] = NULL;
71                         }
72         }
73     }
74 }
75
76 void tracefile_read_lock()
77 {
78     cfs_wait_event(&tracefile_event, 0);
79 }
80
81 void tracefile_read_unlock()
82 {
83     cfs_wake_event(&tracefile_event);
84 }
85
86 void tracefile_write_lock()
87 {
88     cfs_wait_event(&tracefile_event, 0);
89 }
90
91 void tracefile_write_unlock()
92 {
93     cfs_wake_event(&tracefile_event);
94 }
95
96 char *
97 trace_get_console_buffer(void)
98 {
99 #pragma message ("is there possible problem with pre-emption ?")
100     int cpu = (int) KeGetCurrentProcessorNumber();
101     return trace_console_buffers[cpu][0];
102 }
103
104 void
105 trace_put_console_buffer(char *buffer)
106 {
107 }
108
109 struct trace_cpu_data *
110 trace_get_tcd(void)
111 {
112 #pragma message("todo: return NULL if in interrupt context")
113
114         int cpu = (int) KeGetCurrentProcessorNumber();
115         return &trace_data[cpu].tcd;
116 }
117
118 void
119 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
120 {
121 }
122
123 void
124 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
125                     const int line, unsigned long stack)
126 {
127         struct timeval tv;
128
129         do_gettimeofday(&tv);
130
131         header->ph_subsys = subsys;
132         header->ph_mask = mask;
133         header->ph_cpu_id = smp_processor_id();
134         header->ph_sec = (__u32)tv.tv_sec;
135         header->ph_usec = tv.tv_usec;
136         header->ph_stack = stack;
137         header->ph_pid = current->pid;
138         header->ph_line_num = line;
139         header->ph_extern_pid = 0;
140         return;
141 }
142
143 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
144                                   int len, const char *file, const char *fn)
145 {
146         char *prefix = NULL, *ptype = NULL;
147
148         if ((mask & D_EMERG) != 0) {
149                 prefix = "LustreError";
150                 ptype = KERN_EMERG;
151         } else if ((mask & D_ERROR) != 0) {
152                 prefix = "LustreError";
153                 ptype = KERN_ERR;
154         } else if ((mask & D_WARNING) != 0) {
155                 prefix = "Lustre";
156                 ptype = KERN_WARNING;
157         } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
158                 prefix = "Lustre";
159                 ptype = KERN_INFO;
160         }
161
162         if ((mask & D_CONSOLE) != 0) {
163                 printk("%s%s: %s", ptype, prefix, buf);
164         } else {
165                 printk("%s%s: %d:%d:(%s:%d:%s()) %s", ptype, prefix, hdr->ph_pid,
166                        hdr->ph_extern_pid, file, hdr->ph_line_num, fn, buf);
167         }
168         return;
169 }
170
171 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
172 {
173         return 1;
174 }
175
176 int trace_max_debug_mb(void)
177 {
178         int  total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
179         
180         return MAX(512, (total_mb * 80)/100);
181 }
182
183 void
184 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
185 {
186 #error "tbd"
187 }
188