Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / libcfs / darwin / darwin-tracefile.c
1
2 #define DEBUG_SUBSYSTEM S_LNET
3 #define LUSTRE_TRACEFILE_PRIVATE
4 #include <libcfs/libcfs.h>
5 #include <libcfs/kp30.h>
6 #include "tracefile.h"
7
8 /*
9  * We can't support smp tracefile currently.
10  * Everything is put on one cpu.
11  */
12
13 #define M_TCD_MAX_PAGES (128 * 1280)
14 extern union trace_data_union trace_data[NR_CPUS];
15
16 static long max_permit_mb = (64 * 1024);
17
18 spinlock_t trace_cpu_serializer;
19
20 /*
21  * thread currently executing tracefile code or NULL if none does. Used to
22  * detect recursive calls to libcfs_debug_msg().
23  */
24 static thread_t trace_owner = NULL;
25
26 extern int get_preemption_level(void);
27 extern atomic_t tage_allocated;
28
29 struct rw_semaphore tracefile_sem;
30
31 int tracefile_init_arch() {
32     init_rwsem(&tracefile_sem);
33 #error "Todo: initialise per-cpu console buffers"
34     return 0;
35 }
36
37 void tracefile_fini_arch() {
38 }
39
40 void tracefile_read_lock() {
41     down_read(&tracefile_sem);
42 }
43
44 void tracefile_read_unlock() {
45     up_read(&tracefile_sem);
46 }
47
48 void tracefile_write_lock() {
49     down_write(&tracefile_sem);
50 }
51
52 void tracefile_write_unlock() {
53     up_write(&tracefile_sem);
54 }
55
56 char *trace_get_console_buffer(void)
57 {
58 #error "todo: return a per-cpu/interrupt console buffer and disable pre-emption"
59 }
60
61 void trace_put_console_buffer(char *buffer)
62 {
63 #error "todo: re-enable pre-emption"
64 }
65
66 struct trace_cpu_data *trace_get_tcd(void)
67 {
68         struct trace_cpu_data *tcd;
69         int nr_pages;
70         struct list_head pages;
71
72         /*
73          * XXX nikita: do NOT call libcfs_debug_msg() (CDEBUG/ENTRY/EXIT)
74          * from here: this will lead to infinite recursion.
75          */
76
77         /*
78          * debugging check for recursive call to libcfs_debug_msg()
79          */
80         if (trace_owner == current_thread()) {
81                 /*
82                  * Cannot assert here.
83                  */
84                 printk(KERN_EMERG "recursive call to %s", __FUNCTION__);
85                 /*
86                  * "The death of God left the angels in a strange position."
87                  */
88                 cfs_enter_debugger();
89         }
90         tcd = &trace_data[0].tcd;
91         CFS_INIT_LIST_HEAD(&pages);
92         if (get_preemption_level() == 0)
93                 nr_pages = trace_refill_stock(tcd, CFS_ALLOC_STD, &pages);
94         else
95                 nr_pages = 0;
96         spin_lock(&trace_cpu_serializer);
97         trace_owner = current_thread();
98         tcd->tcd_cur_stock_pages += nr_pages;
99         list_splice(&pages, &tcd->tcd_stock_pages);
100         return tcd;
101 }
102
103 extern void raw_page_death_row_clean(void);
104
105 void __trace_put_tcd(struct trace_cpu_data *tcd)
106 {
107         /*
108          * XXX nikita: do NOT call libcfs_debug_msg() (CDEBUG/ENTRY/EXIT)
109          * from here: this will lead to infinite recursion.
110          */
111         LASSERT(trace_owner == current_thread());
112         trace_owner = NULL;
113         spin_unlock(&trace_cpu_serializer);
114         if (get_preemption_level() == 0)
115                 /* purge all pending pages */
116                 raw_page_death_row_clean();
117 }
118
119 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
120 {
121         /*
122          * XXX nikita: do NOT call libcfs_debug_msg() (CDEBUG/ENTRY/EXIT)
123          * from here: this will lead to infinite recursion.
124          */
125         /* XNU has global tcd, and all pages are owned by it */
126         return 1;
127 }
128
129 void
130 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
131                     const int line, unsigned long stack)
132 {
133         struct timeval tv;
134         
135         /*
136          * XXX nikita: do NOT call libcfs_debug_msg() (CDEBUG/ENTRY/EXIT)
137          * from here: this will lead to infinite recursion.
138          */
139         do_gettimeofday(&tv);
140         header->ph_subsys = subsys;
141         header->ph_mask = mask;
142         header->ph_cpu_id = smp_processor_id();
143         header->ph_sec = (__u32)tv.tv_sec;
144         header->ph_usec = tv.tv_usec;
145         header->ph_stack = stack;
146         header->ph_pid = cfs_curproc_pid();
147         header->ph_line_num = line;
148         header->ph_extern_pid = (__u32)current_thread();
149 }
150
151 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
152                       int len, const char *file, const char *fn)
153 {
154         char *prefix = "Lustre", *ptype = KERN_INFO;
155
156         /*
157          * XXX nikita: do NOT call libcfs_debug_msg() (CDEBUG/ENTRY/EXIT)
158          * from here: this will lead to infinite recursion.
159          */
160         if ((mask & D_EMERG) != 0) {
161                 prefix = "LustreError";
162                 ptype = KERN_EMERG;
163         } else if ((mask & D_ERROR) != 0) {
164                 prefix = "LustreError";
165                 ptype = KERN_ERR;
166         } else if ((mask & D_WARNING) != 0) {
167                 prefix = "Lustre";
168                 ptype = KERN_WARNING;
169         } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
170                 prefix = "Lustre";
171                 ptype = KERN_INFO;
172         }
173
174         if ((mask & D_CONSOLE) != 0) {
175                 printk("%s%s: %.*s", ptype, prefix, len, buf);
176         } else {
177                 printk("%s%s: %d:%d:(%s:%d:%s()) %*s",
178                        ptype, prefix, hdr->ph_pid, hdr->ph_extern_pid,
179                        file, hdr->ph_line_num, fn, len, buf);
180         }
181 }
182
183 int trace_max_debug_mb(void)
184 {
185         return max_permit_mb;
186 }
187
188 void
189 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
190 {
191 #error "tbd"
192 }