* in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see [sun.com URL with a
- * copy of GPLv2].
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
#include <libcfs/libcfs.h>
+#if defined(__linux__)
+#include "linux/linux-tracefile.h"
+#elif defined(__WINNT__)
+#include "winnt/winnt-tracefile.h"
+#else
+#error Unsupported operating system.
+#endif
+
/* trace file lock routines */
#define TRACEFILE_NAME_SIZE 1024
extern char tracefile[TRACEFILE_NAME_SIZE];
extern long long tracefile_size;
+extern void libcfs_run_debug_log_upcall(char *file);
+
int tracefile_init_arch(void);
void tracefile_fini_arch(void);
#define TRACEFILE_SIZE (500 << 20)
-/* Size of a buffer for sprinting console messages if we can't get a page
+/* Size of a buffer for sprinting console messages if we can't get a page
* from system */
#define TRACE_CONSOLE_BUFFER_SIZE 1024
union trace_data_union {
struct trace_cpu_data {
/*
+ * Even though this structure is meant to be per-CPU, locking
+ * is needed because in some places the data may be accessed
+ * from other CPUs. This lock is directly used in trace_get_tcd
+ * and trace_put_tcd, which are called in libcfs_debug_vmsg2 and
+ * tcd_for_each_type_lock
+ */
+ spinlock_t tcd_lock;
+ unsigned long tcd_lock_flags;
+
+ /*
* pages with trace records not yet processed by tracefiled.
*/
struct list_head tcd_pages;
/*
* Maximal number of pages allowed on ->tcd_pages and
- * ->tcd_daemon_pages each.
+ * ->tcd_daemon_pages each.
* Always TCD_MAX_PAGES * tcd_pages_factor / 100 in current
* implementation.
*/
for (j = 0, ((tcd) = &(*trace_data[i])[j].tcd); \
j < num_possible_cpus(); j++, (tcd) = &(*trace_data[i])[j].tcd)
-#define tcd_for_each_type_lock(tcd, i) \
+#define tcd_for_each_type_lock(tcd, i, cpu) \
for (i = 0; trace_data[i] && \
- (tcd = &(*trace_data[i])[smp_processor_id()].tcd) && \
+ (tcd = &(*trace_data[i])[cpu].tcd) && \
trace_lock_tcd(tcd); trace_unlock_tcd(tcd), i++)
/* XXX nikita: this declaration is internal to tracefile.c and should probably
*/
unsigned short cpu;
/*
- * type(context) of this page
+ * type(context) of this page
*/
unsigned short type;
};
extern void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
int len, const char *file, const char *fn);
-extern struct trace_cpu_data *trace_get_tcd(void);
-extern void trace_put_tcd(struct trace_cpu_data *tcd);
extern int trace_lock_tcd(struct trace_cpu_data *tcd);
extern void trace_unlock_tcd(struct trace_cpu_data *tcd);
-extern char *trace_get_console_buffer(void);
-extern void trace_put_console_buffer(char *buffer);
-extern void trace_call_on_all_cpus(void (*fn)(void *arg), void *arg);
+/**
+ * trace_buf_type_t, trace_buf_idx_get() and trace_console_buffers[][]
+ * are not public libcfs API; they should be defined in
+ * platform-specific tracefile include files
+ * (see, for example, linux-tracefile.h).
+ */
+
+extern char *trace_console_buffers[NR_CPUS][TCD_TYPE_MAX];
+extern trace_buf_type_t trace_buf_idx_get(void);
+
+static inline char *
+trace_get_console_buffer(void)
+{
+ return trace_console_buffers[cfs_get_cpu()][trace_buf_idx_get()];
+}
+
+static inline void
+trace_put_console_buffer(char *buffer)
+{
+ cfs_put_cpu();
+}
+
+extern union trace_data_union (*trace_data[TCD_MAX_TYPES])[NR_CPUS];
+
+static inline struct trace_cpu_data *
+trace_get_tcd(void)
+{
+ struct trace_cpu_data *tcd =
+ &(*trace_data[trace_buf_idx_get()])[cfs_get_cpu()].tcd;
+
+ trace_lock_tcd(tcd);
+
+ return tcd;
+}
+
+static inline void
+trace_put_tcd (struct trace_cpu_data *tcd)
+{
+ trace_unlock_tcd(tcd);
+
+ cfs_put_cpu();
+}
int trace_refill_stock(struct trace_cpu_data *tcd, int gfp,
struct list_head *stock);
const char *file, int line);
/* ASSERTION that is safe to use within the debug system */
-#define __LASSERT(cond) \
-({ \
- if (unlikely(!(cond))) { \
- trace_assertion_failed("ASSERTION("#cond") failed", \
- __FUNCTION__, __FILE__, __LINE__); \
- } \
-})
-
-#define __LASSERT_TAGE_INVARIANT(tage) \
-({ \
- __LASSERT(tage != NULL); \
- __LASSERT(tage->page != NULL); \
- __LASSERT(tage->used <= CFS_PAGE_SIZE); \
- __LASSERT(cfs_page_count(tage->page) > 0); \
-})
+#define __LASSERT(cond) \
+ do { \
+ if (unlikely(!(cond))) { \
+ trace_assertion_failed("ASSERTION("#cond") failed", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ } \
+ } while (0)
+
+#define __LASSERT_TAGE_INVARIANT(tage) \
+ do { \
+ __LASSERT(tage != NULL); \
+ __LASSERT(tage->page != NULL); \
+ __LASSERT(tage->used <= CFS_PAGE_SIZE); \
+ __LASSERT(cfs_page_count(tage->page) > 0); \
+ } while (0)
#endif /* LUSTRE_TRACEFILE_PRIVATE */