1 #ifndef __LIBCFS_TRACEFILE_H__
2 #define __LIBCFS_TRACEFILE_H__
4 #include <libcfs/libcfs.h>
6 /* trace file lock routines */
8 int tracefile_init_arch(void);
9 void tracefile_fini_arch(void);
11 void tracefile_read_lock(void);
12 void tracefile_read_unlock(void);
13 void tracefile_write_lock(void);
14 void tracefile_write_unlock(void);
16 int tracefile_dump_all_pages(char *filename);
17 void trace_debug_print(void);
18 void trace_flush_pages(void);
19 int trace_start_thread(void);
20 void trace_stop_thread(void);
21 int tracefile_init(void);
22 void tracefile_exit(void);
23 int trace_write_daemon_file(struct file *file, const char *buffer,
24 unsigned long count, void *data);
25 int trace_read_daemon_file(char *page, char **start, off_t off, int count,
26 int *eof, void *data);
27 int trace_write_debug_mb(struct file *file, const char *buffer,
28 unsigned long count, void *data);
29 int trace_read_debug_mb(char *page, char **start, off_t off, int count,
30 int *eof, void *data);
31 int trace_dk(struct file *file, const char *buffer, unsigned long count,
34 extern void libcfs_debug_dumplog_internal(void *arg);
35 extern void libcfs_register_panic_notifier(void);
36 extern void libcfs_unregister_panic_notifier(void);
37 extern int libcfs_panic_in_progress;
39 #ifdef LUSTRE_TRACEFILE_PRIVATE
41 * Private declare for tracefile
43 #define TCD_MAX_PAGES (5 << (20 - CFS_PAGE_SHIFT))
44 #define TCD_STOCK_PAGES (TCD_MAX_PAGES)
46 #define TRACEFILE_SIZE (500 << 20)
48 /* Size of a buffer for sprinting console messages to in IRQ context (no
49 * logging in IRQ context) */
50 #define TRACE_CONSOLE_BUFFER_SIZE 1024
52 union trace_data_union {
53 struct trace_cpu_data {
55 * pages with trace records not yet processed by tracefiled.
57 struct list_head tcd_pages;
58 /* number of pages on ->tcd_pages */
59 unsigned long tcd_cur_pages;
62 * pages with trace records already processed by
63 * tracefiled. These pages are kept in memory, so that some
64 * portion of log can be written in the event of LBUG. This
65 * list is maintained in LRU order.
67 * Pages are moved to ->tcd_daemon_pages by tracefiled()
68 * (put_pages_on_daemon_list()). LRU pages from this list are
69 * discarded when list grows too large.
71 struct list_head tcd_daemon_pages;
72 /* number of pages on ->tcd_daemon_pages */
73 unsigned long tcd_cur_daemon_pages;
76 * Maximal number of pages allowed on ->tcd_pages and
77 * ->tcd_daemon_pages each. Always TCD_MAX_PAGES in current
80 unsigned long tcd_max_pages;
83 * preallocated pages to write trace records into. Pages from
84 * ->tcd_stock_pages are moved to ->tcd_pages by
85 * portals_debug_msg().
87 * This list is necessary, because on some platforms it's
88 * impossible to perform efficient atomic page allocation in a
89 * non-blockable context.
91 * Such platforms fill ->tcd_stock_pages "on occasion", when
92 * tracing code is entered in blockable context.
94 * trace_get_tage_try() tries to get a page from
95 * ->tcd_stock_pages first and resorts to atomic page
96 * allocation only if this queue is empty. ->tcd_stock_pages
97 * is replenished when tracing code is entered in blocking
98 * context (darwin-tracefile.c:trace_get_tcd()). We try to
99 * maintain TCD_STOCK_PAGES (40 by default) pages in this
100 * queue. Atomic allocation is only required if more than
101 * TCD_STOCK_PAGES pagesful are consumed by trace records all
102 * emitted in non-blocking contexts. Which is quite unlikely.
104 struct list_head tcd_stock_pages;
105 /* number of pages on ->tcd_stock_pages */
106 unsigned long tcd_cur_stock_pages;
108 int tcd_shutting_down;
111 char __pad[SMP_CACHE_BYTES];
114 /* XXX nikita: this declaration is internal to tracefile.c and should probably
116 struct page_collection {
117 struct list_head pc_pages;
119 * spin-lock protecting ->pc_pages. It is taken by smp_call_function()
120 * call-back functions. XXX nikita: Which is horrible: all processors
121 * receive NMI at the same time only to be serialized by this
122 * lock. Probably ->pc_pages should be replaced with an array of
123 * NR_CPUS elements accessed locklessly.
127 * if this flag is set, collect_pages() will spill both
128 * ->tcd_daemon_pages and ->tcd_pages to the ->pc_pages. Otherwise,
129 * only ->tcd_pages are spilled.
131 int pc_want_daemon_pages;
134 /* XXX nikita: this declaration is internal to tracefile.c and should probably
136 struct tracefiled_ctl {
137 struct completion tctl_start;
138 struct completion tctl_stop;
139 cfs_waitq_t tctl_waitq;
141 atomic_t tctl_shutdown;
145 * small data-structure for each page owned by tracefiled.
147 /* XXX nikita: this declaration is internal to tracefile.c and should probably
155 * linkage into one of the lists in trace_data_union or
158 struct list_head linkage;
160 * number of bytes used within this page
164 * cpu that owns this page
169 extern void set_ptldebug_header(struct ptldebug_header *header,
170 int subsys, int mask, const int line,
171 unsigned long stack);
172 extern void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
173 int len, const char *file, const char *fn);
175 extern struct trace_cpu_data *trace_get_tcd(void);
176 extern void trace_put_tcd(struct trace_cpu_data *tcd);
177 extern char *trace_get_console_buffer(void);
178 extern void trace_put_console_buffer(char *buffer);
180 extern void trace_call_on_all_cpus(void (*fn)(void *arg), void *arg);
182 int trace_refill_stock(struct trace_cpu_data *tcd, int gfp,
183 struct list_head *stock);
186 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage);
188 extern void trace_assertion_failed(const char *str, const char *fn,
189 const char *file, int line);
191 /* ASSERTION that is safe to use within the debug system */
192 #define __LASSERT(cond) \
194 if (unlikely(!(cond))) { \
195 trace_assertion_failed("ASSERTION("#cond") failed", \
196 __FUNCTION__, __FILE__, __LINE__); \
200 #define __LASSERT_TAGE_INVARIANT(tage) \
202 __LASSERT(tage != NULL); \
203 __LASSERT(tage->page != NULL); \
204 __LASSERT(tage->used <= CFS_PAGE_SIZE); \
205 __LASSERT(cfs_page_count(tage->page) > 0); \
208 #endif /* LUSTRE_TRACEFILE_PRIVATE */
210 #endif /* __LIBCFS_TRACEFILE_H__ */