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 "tracefile.h"
26 #define get_cpu() smp_processor_id()
27 #define put_cpu() do { } while (0)
30 #define TCD_TYPE_MAX 1
32 event_t tracefile_event;
34 void tracefile_init_arch()
38 struct trace_cpu_data *tcd;
40 cfs_init_event(&tracefile_event, TRUE, TRUE);
42 /* initialize trace_data */
43 memset(trace_data, 0, sizeof(trace_data));
44 for (i = 0; i < TCD_TYPE_MAX; i++) {
45 trace_data[i]=cfs_alloc(sizeof(struct trace_data_union)*NR_CPUS, 0);
46 if (trace_data[i] == NULL)
50 /* arch related info initialized */
51 tcd_for_each(tcd, i, j) {
52 tcd->tcd_pages_factor = 100; /* Only one type */
57 memset(trace_console_buffers, 0, sizeof(trace_console_buffers));
59 for (i = 0; i < NR_CPUS; i++) {
60 for (j = 0; j < 1; j++) {
61 trace_console_buffers[i][j] =
62 cfs_alloc(TRACE_CONSOLE_BUFFER_SIZE,
65 if (trace_console_buffers[i][j] == NULL)
73 tracefile_fini_arch();
74 KsPrint((0, "lnet: No enough memory\n"));
78 void tracefile_fini_arch()
83 for (i = 0; i < NR_CPUS; i++) {
84 for (j = 0; j < 2; j++) {
85 if (trace_console_buffers[i][j] != NULL) {
86 cfs_free(trace_console_buffers[i][j]);
87 trace_console_buffers[i][j] = NULL;
92 for (i = 0; trace_data[i] != NULL; i++) {
93 cfs_free(trace_data[i]);
98 void tracefile_read_lock()
100 cfs_wait_event(&tracefile_event, 0);
103 void tracefile_read_unlock()
105 cfs_wake_event(&tracefile_event);
108 void tracefile_write_lock()
110 cfs_wait_event(&tracefile_event, 0);
113 void tracefile_write_unlock()
115 cfs_wake_event(&tracefile_event);
119 trace_get_console_buffer(void)
121 #pragma message ("is there possible problem with pre-emption ?")
122 int cpu = (int) KeGetCurrentProcessorNumber();
123 return trace_console_buffers[cpu][0];
127 trace_put_console_buffer(char *buffer)
131 struct trace_cpu_data *
134 #pragma message("todo: return NULL if in interrupt context")
136 int cpu = (int) KeGetCurrentProcessorNumber();
137 return &(*trace_data[0])[cpu].tcd;
141 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
146 trace_lock_tcd(struct trace_cpu_data *tcd)
148 __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
153 trace_unlock_tcd(struct trace_cpu_data *tcd)
155 __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
159 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
160 const int line, unsigned long stack)
164 do_gettimeofday(&tv);
166 header->ph_subsys = subsys;
167 header->ph_mask = mask;
168 header->ph_cpu_id = smp_processor_id();
169 header->ph_sec = (__u32)tv.tv_sec;
170 header->ph_usec = tv.tv_usec;
171 header->ph_stack = stack;
172 header->ph_pid = current->pid;
173 header->ph_line_num = line;
174 header->ph_extern_pid = 0;
178 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
179 int len, const char *file, const char *fn)
181 char *prefix = NULL, *ptype = NULL;
183 if ((mask & D_EMERG) != 0) {
184 prefix = "LustreError";
186 } else if ((mask & D_ERROR) != 0) {
187 prefix = "LustreError";
189 } else if ((mask & D_WARNING) != 0) {
191 ptype = KERN_WARNING;
192 } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
197 if ((mask & D_CONSOLE) != 0) {
198 printk("%s%s: %s", ptype, prefix, buf);
200 printk("%s%s: %d:%d:(%s:%d:%s()) %s", ptype, prefix, hdr->ph_pid,
201 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, buf);
206 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
211 int trace_max_debug_mb(void)
213 int total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
215 return MAX(512, (total_mb * 80)/100);
219 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)