1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#ifndef __LIBCFS_TRACEFILE_H__
38#define __LIBCFS_TRACEFILE_H__
39
40#include "../../include/linux/libcfs/libcfs.h"
41
42enum cfs_trace_buf_type {
43 CFS_TCD_TYPE_PROC = 0,
44 CFS_TCD_TYPE_SOFTIRQ,
45 CFS_TCD_TYPE_IRQ,
46 CFS_TCD_TYPE_MAX
47};
48
49
50
51#define TRACEFILE_NAME_SIZE 1024
52extern char cfs_tracefile[TRACEFILE_NAME_SIZE];
53extern long long cfs_tracefile_size;
54
55void libcfs_run_debug_log_upcall(char *file);
56
57int cfs_tracefile_init_arch(void);
58void cfs_tracefile_fini_arch(void);
59
60void cfs_tracefile_read_lock(void);
61void cfs_tracefile_read_unlock(void);
62void cfs_tracefile_write_lock(void);
63void cfs_tracefile_write_unlock(void);
64
65int cfs_tracefile_dump_all_pages(char *filename);
66void cfs_trace_debug_print(void);
67void cfs_trace_flush_pages(void);
68int cfs_trace_start_thread(void);
69void cfs_trace_stop_thread(void);
70int cfs_tracefile_init(int max_pages);
71void cfs_tracefile_exit(void);
72
73int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
74 const char __user *usr_buffer, int usr_buffer_nob);
75int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,
76 const char *knl_str, char *append);
77int cfs_trace_allocate_string_buffer(char **str, int nob);
78int cfs_trace_dump_debug_buffer_usrstr(void __user *usr_str, int usr_str_nob);
79int cfs_trace_daemon_command(char *str);
80int cfs_trace_daemon_command_usrstr(void __user *usr_str, int usr_str_nob);
81int cfs_trace_set_debug_mb(int mb);
82int cfs_trace_get_debug_mb(void);
83
84void libcfs_debug_dumplog_internal(void *arg);
85void libcfs_register_panic_notifier(void);
86void libcfs_unregister_panic_notifier(void);
87extern int libcfs_panic_in_progress;
88int cfs_trace_max_debug_mb(void);
89
90#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))
91#define TCD_STOCK_PAGES (TCD_MAX_PAGES)
92#define CFS_TRACEFILE_SIZE (500 << 20)
93
94#ifdef LUSTRE_TRACEFILE_PRIVATE
95
96
97
98
99#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))
100#define TCD_STOCK_PAGES (TCD_MAX_PAGES)
101
102#define CFS_TRACEFILE_SIZE (500 << 20)
103
104
105
106
107
108#define CFS_TRACE_CONSOLE_BUFFER_SIZE 1024
109
110union cfs_trace_data_union {
111 struct cfs_trace_cpu_data {
112
113
114
115
116
117
118
119 spinlock_t tcd_lock;
120 unsigned long tcd_lock_flags;
121
122
123
124
125 struct list_head tcd_pages;
126
127 unsigned long tcd_cur_pages;
128
129
130
131
132
133
134
135
136
137
138
139 struct list_head tcd_daemon_pages;
140
141 unsigned long tcd_cur_daemon_pages;
142
143
144
145
146
147
148
149 unsigned long tcd_max_pages;
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 struct list_head tcd_stock_pages;
174
175 unsigned long tcd_cur_stock_pages;
176
177 unsigned short tcd_shutting_down;
178 unsigned short tcd_cpu;
179 unsigned short tcd_type;
180
181 unsigned short tcd_pages_factor;
182 } tcd;
183 char __pad[L1_CACHE_ALIGN(sizeof(struct cfs_trace_cpu_data))];
184};
185
186#define TCD_MAX_TYPES 8
187extern union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES])[NR_CPUS];
188
189#define cfs_tcd_for_each(tcd, i, j) \
190 for (i = 0; cfs_trace_data[i]; i++) \
191 for (j = 0, ((tcd) = &(*cfs_trace_data[i])[j].tcd); \
192 j < num_possible_cpus(); \
193 j++, (tcd) = &(*cfs_trace_data[i])[j].tcd)
194
195#define cfs_tcd_for_each_type_lock(tcd, i, cpu) \
196 for (i = 0; cfs_trace_data[i] && \
197 (tcd = &(*cfs_trace_data[i])[cpu].tcd) && \
198 cfs_trace_lock_tcd(tcd, 1); cfs_trace_unlock_tcd(tcd, 1), i++)
199
200void cfs_set_ptldebug_header(struct ptldebug_header *header,
201 struct libcfs_debug_msg_data *m,
202 unsigned long stack);
203void cfs_print_to_console(struct ptldebug_header *hdr, int mask,
204 const char *buf, int len, const char *file,
205 const char *fn);
206
207int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking);
208void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking);
209
210extern char *cfs_trace_console_buffers[NR_CPUS][CFS_TCD_TYPE_MAX];
211enum cfs_trace_buf_type cfs_trace_buf_idx_get(void);
212
213static inline char *
214cfs_trace_get_console_buffer(void)
215{
216 unsigned int i = get_cpu();
217 unsigned int j = cfs_trace_buf_idx_get();
218
219 return cfs_trace_console_buffers[i][j];
220}
221
222static inline struct cfs_trace_cpu_data *
223cfs_trace_get_tcd(void)
224{
225 struct cfs_trace_cpu_data *tcd =
226 &(*cfs_trace_data[cfs_trace_buf_idx_get()])[get_cpu()].tcd;
227
228 cfs_trace_lock_tcd(tcd, 0);
229
230 return tcd;
231}
232
233static inline void cfs_trace_put_tcd(struct cfs_trace_cpu_data *tcd)
234{
235 cfs_trace_unlock_tcd(tcd, 0);
236
237 put_cpu();
238}
239
240int cfs_trace_refill_stock(struct cfs_trace_cpu_data *tcd, gfp_t gfp,
241 struct list_head *stock);
242
243void cfs_trace_assertion_failed(const char *str,
244 struct libcfs_debug_msg_data *m);
245
246
247#define __LASSERT(cond) \
248do { \
249 if (unlikely(!(cond))) { \
250 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_EMERG, NULL); \
251 cfs_trace_assertion_failed("ASSERTION("#cond") failed", \
252 &msgdata); \
253 } \
254} while (0)
255
256#define __LASSERT_TAGE_INVARIANT(tage) \
257do { \
258 __LASSERT(tage); \
259 __LASSERT(tage->page); \
260 __LASSERT(tage->used <= PAGE_SIZE); \
261 __LASSERT(page_count(tage->page) > 0); \
262} while (0)
263
264#endif
265
266#endif
267