1 #ifndef __LIBCFS_TRACEFILE_H__
2 #define __LIBCFS_TRACEFILE_H__
4 #include <libcfs/libcfs.h>
6 /* trace file lock routines */
8 #define TRACEFILE_NAME_SIZE 1024
9 extern char tracefile[TRACEFILE_NAME_SIZE];
10 extern long long tracefile_size;
12 int tracefile_init_arch(void);
13 void tracefile_fini_arch(void);
15 void tracefile_read_lock(void);
16 void tracefile_read_unlock(void);
17 void tracefile_write_lock(void);
18 void tracefile_write_unlock(void);
20 int tracefile_dump_all_pages(char *filename);
21 void trace_debug_print(void);
22 void trace_flush_pages(void);
23 int trace_start_thread(void);
24 void trace_stop_thread(void);
25 int tracefile_init(int max_pages);
26 void tracefile_exit(void);
30 int trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
31 const char *usr_buffer, int usr_buffer_nob);
32 int trace_copyout_string(char *usr_buffer, int usr_buffer_nob,
33 const char *knl_str, char *append);
34 int trace_allocate_string_buffer(char **str, int nob);
35 void trace_free_string_buffer(char *str, int nob);
36 int trace_dump_debug_buffer_usrstr(void *usr_str, int usr_str_nob);
37 int trace_daemon_command(char *str);
38 int trace_daemon_command_usrstr(void *usr_str, int usr_str_nob);
39 int trace_set_debug_mb(int mb);
40 int trace_set_debug_mb_usrstr(void *usr_str, int usr_str_nob);
41 int trace_get_debug_mb(void);
43 extern void libcfs_debug_dumplog_internal(void *arg);
44 extern void libcfs_register_panic_notifier(void);
45 extern void libcfs_unregister_panic_notifier(void);
46 extern int libcfs_panic_in_progress;
47 extern int trace_max_debug_mb(void);
49 #define TCD_MAX_PAGES (5 << (20 - CFS_PAGE_SHIFT))
50 #define TCD_STOCK_PAGES (TCD_MAX_PAGES)
51 #define TRACEFILE_SIZE (500 << 20)
53 #ifdef LUSTRE_TRACEFILE_PRIVATE
56 * Private declare for tracefile
58 #define TCD_MAX_PAGES (5 << (20 - CFS_PAGE_SHIFT))
59 #define TCD_STOCK_PAGES (TCD_MAX_PAGES)
61 #define TRACEFILE_SIZE (500 << 20)
63 /* Size of a buffer for sprinting console messages if we can't get a page
65 #define TRACE_CONSOLE_BUFFER_SIZE 1024
67 union trace_data_union {
68 struct trace_cpu_data {
70 * pages with trace records not yet processed by tracefiled.
72 struct list_head tcd_pages;
73 /* number of pages on ->tcd_pages */
74 unsigned long tcd_cur_pages;
77 * pages with trace records already processed by
78 * tracefiled. These pages are kept in memory, so that some
79 * portion of log can be written in the event of LBUG. This
80 * list is maintained in LRU order.
82 * Pages are moved to ->tcd_daemon_pages by tracefiled()
83 * (put_pages_on_daemon_list()). LRU pages from this list are
84 * discarded when list grows too large.
86 struct list_head tcd_daemon_pages;
87 /* number of pages on ->tcd_daemon_pages */
88 unsigned long tcd_cur_daemon_pages;
91 * Maximal number of pages allowed on ->tcd_pages and
92 * ->tcd_daemon_pages each.
93 * Always TCD_MAX_PAGES * tcd_pages_factor / 100 in current
96 unsigned long tcd_max_pages;
99 * preallocated pages to write trace records into. Pages from
100 * ->tcd_stock_pages are moved to ->tcd_pages by
101 * portals_debug_msg().
103 * This list is necessary, because on some platforms it's
104 * impossible to perform efficient atomic page allocation in a
105 * non-blockable context.
107 * Such platforms fill ->tcd_stock_pages "on occasion", when
108 * tracing code is entered in blockable context.
110 * trace_get_tage_try() tries to get a page from
111 * ->tcd_stock_pages first and resorts to atomic page
112 * allocation only if this queue is empty. ->tcd_stock_pages
113 * is replenished when tracing code is entered in blocking
114 * context (darwin-tracefile.c:trace_get_tcd()). We try to
115 * maintain TCD_STOCK_PAGES (40 by default) pages in this
116 * queue. Atomic allocation is only required if more than
117 * TCD_STOCK_PAGES pagesful are consumed by trace records all
118 * emitted in non-blocking contexts. Which is quite unlikely.
120 struct list_head tcd_stock_pages;
121 /* number of pages on ->tcd_stock_pages */
122 unsigned long tcd_cur_stock_pages;
124 unsigned short tcd_shutting_down;
125 unsigned short tcd_cpu;
126 unsigned short tcd_type;
127 /* The factors to share debug memory. */
128 unsigned short tcd_pages_factor;
130 char __pad[L1_CACHE_ALIGN(sizeof(struct trace_cpu_data))];
133 #define TCD_MAX_TYPES 8
134 extern union trace_data_union (*trace_data[TCD_MAX_TYPES])[NR_CPUS];
136 #define tcd_for_each(tcd, i, j) \
137 for (i = 0; trace_data[i] != NULL; i++) \
138 for (j = 0, ((tcd) = &(*trace_data[i])[j].tcd); \
139 j < num_possible_cpus(); j++, (tcd) = &(*trace_data[i])[j].tcd)
141 #define tcd_for_each_type_lock(tcd, i) \
142 for (i = 0; trace_data[i] && \
143 (tcd = &(*trace_data[i])[smp_processor_id()].tcd) && \
144 trace_lock_tcd(tcd); trace_unlock_tcd(tcd), i++)
146 /* XXX nikita: this declaration is internal to tracefile.c and should probably
148 struct page_collection {
149 struct list_head pc_pages;
151 * spin-lock protecting ->pc_pages. It is taken by smp_call_function()
152 * call-back functions. XXX nikita: Which is horrible: all processors
153 * receive NMI at the same time only to be serialized by this
154 * lock. Probably ->pc_pages should be replaced with an array of
155 * NR_CPUS elements accessed locklessly.
159 * if this flag is set, collect_pages() will spill both
160 * ->tcd_daemon_pages and ->tcd_pages to the ->pc_pages. Otherwise,
161 * only ->tcd_pages are spilled.
163 int pc_want_daemon_pages;
166 /* XXX nikita: this declaration is internal to tracefile.c and should probably
168 struct tracefiled_ctl {
169 struct completion tctl_start;
170 struct completion tctl_stop;
171 cfs_waitq_t tctl_waitq;
173 atomic_t tctl_shutdown;
177 * small data-structure for each page owned by tracefiled.
179 /* XXX nikita: this declaration is internal to tracefile.c and should probably
187 * linkage into one of the lists in trace_data_union or
190 struct list_head linkage;
192 * number of bytes used within this page
196 * cpu that owns this page
200 * type(context) of this page
205 extern void set_ptldebug_header(struct ptldebug_header *header,
206 int subsys, int mask, const int line,
207 unsigned long stack);
208 extern void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
209 int len, const char *file, const char *fn);
211 extern struct trace_cpu_data *trace_get_tcd(void);
212 extern void trace_put_tcd(struct trace_cpu_data *tcd);
213 extern int trace_lock_tcd(struct trace_cpu_data *tcd);
214 extern void trace_unlock_tcd(struct trace_cpu_data *tcd);
215 extern char *trace_get_console_buffer(void);
216 extern void trace_put_console_buffer(char *buffer);
218 extern void trace_call_on_all_cpus(void (*fn)(void *arg), void *arg);
220 int trace_refill_stock(struct trace_cpu_data *tcd, int gfp,
221 struct list_head *stock);
224 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage);
226 extern void trace_assertion_failed(const char *str, const char *fn,
227 const char *file, int line);
229 /* ASSERTION that is safe to use within the debug system */
230 #define __LASSERT(cond) \
232 if (unlikely(!(cond))) { \
233 trace_assertion_failed("ASSERTION("#cond") failed", \
234 __FUNCTION__, __FILE__, __LINE__); \
238 #define __LASSERT_TAGE_INVARIANT(tage) \
240 __LASSERT(tage != NULL); \
241 __LASSERT(tage->page != NULL); \
242 __LASSERT(tage->used <= CFS_PAGE_SIZE); \
243 __LASSERT(cfs_page_count(tage->page) > 0); \
246 #endif /* LUSTRE_TRACEFILE_PRIVATE */
248 #endif /* __LIBCFS_TRACEFILE_H__ */