1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=4:tabstop=4:
4 * Copyright (c) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or modify it under
9 * the terms of version 2 of the GNU General Public License as published by
10 * the Free Software Foundation. Lustre is distributed in the hope that it
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. You should have received a
14 * copy of the GNU General Public License along with Lustre; if not, write
15 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
19 #define DEBUG_SUBSYSTEM S_LNET
20 #define LUSTRE_TRACEFILE_PRIVATE
22 #include <libcfs/libcfs.h>
23 #include <libcfs/kp30.h>
24 #include "tracefile.h"
27 #define get_cpu() smp_processor_id()
28 #define put_cpu() do { } while (0)
31 extern union trace_data_union trace_data[NR_CPUS];
33 event_t tracefile_event;
35 void tracefile_init_arch()
40 cfs_init_event(&tracefile_event, TRUE, TRUE);
42 memset(trace_console_buffers, 0, sizeof(trace_console_buffers));
44 for (i = 0; i < NR_CPUS; i++) {
45 for (j = 0; j < 1; j++) {
46 trace_console_buffers[i][j] =
47 cfs_alloc(TRACE_CONSOLE_BUFFER_SIZE,
50 if (trace_console_buffers[i][j] == NULL) {
51 tracefile_fini_arch();
52 KsPrint((0, "Can't allocate console message buffer\n"));
61 void tracefile_fini_arch()
66 for (i = 0; i < NR_CPUS; i++) {
67 for (j = 0; j < 2; j++) {
68 if (trace_console_buffers[i][j] != NULL) {
69 cfs_free(trace_console_buffers[i][j]);
70 trace_console_buffers[i][j] = NULL;
76 void tracefile_read_lock()
78 cfs_wait_event(&tracefile_event, 0);
81 void tracefile_read_unlock()
83 cfs_wake_event(&tracefile_event);
86 void tracefile_write_lock()
88 cfs_wait_event(&tracefile_event, 0);
91 void tracefile_write_unlock()
93 cfs_wake_event(&tracefile_event);
97 trace_get_console_buffer(void)
99 #pragma message ("is there possible problem with pre-emption ?")
100 int cpu = (int) KeGetCurrentProcessorNumber();
101 return trace_console_buffers[cpu][0];
105 trace_put_console_buffer(char *buffer)
109 struct trace_cpu_data *
112 #pragma message("todo: return NULL if in interrupt context")
114 int cpu = (int) KeGetCurrentProcessorNumber();
115 return &trace_data[cpu].tcd;
119 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
124 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
125 const int line, unsigned long stack)
129 do_gettimeofday(&tv);
131 header->ph_subsys = subsys;
132 header->ph_mask = mask;
133 header->ph_cpu_id = smp_processor_id();
134 header->ph_sec = (__u32)tv.tv_sec;
135 header->ph_usec = tv.tv_usec;
136 header->ph_stack = stack;
137 header->ph_pid = current->pid;
138 header->ph_line_num = line;
139 header->ph_extern_pid = 0;
143 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
144 int len, const char *file, const char *fn)
146 char *prefix = NULL, *ptype = NULL;
148 if ((mask & D_EMERG) != 0) {
149 prefix = "LustreError";
151 } else if ((mask & D_ERROR) != 0) {
152 prefix = "LustreError";
154 } else if ((mask & D_WARNING) != 0) {
156 ptype = KERN_WARNING;
157 } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
162 if ((mask & D_CONSOLE) != 0) {
163 printk("%s%s: %s", ptype, prefix, buf);
165 printk("%s%s: %d:%d:(%s:%d:%s()) %s", ptype, prefix, hdr->ph_pid,
166 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, buf);
171 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
176 int trace_max_debug_mb(void)
178 int total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
180 return MAX(512, (total_mb * 80)/100);
184 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)