1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
38 #define LUSTRE_TRACEFILE_PRIVATE
40 #include <libcfs/libcfs.h>
41 #include "tracefile.h"
44 #define get_cpu() smp_processor_id()
45 #define put_cpu() do { } while (0)
48 #define TCD_TYPE_MAX 1
50 event_t tracefile_event;
52 void tracefile_init_arch()
56 struct trace_cpu_data *tcd;
58 cfs_init_event(&tracefile_event, TRUE, TRUE);
60 /* initialize trace_data */
61 memset(trace_data, 0, sizeof(trace_data));
62 for (i = 0; i < TCD_TYPE_MAX; i++) {
63 trace_data[i]=cfs_alloc(sizeof(struct trace_data_union)*NR_CPUS, 0);
64 if (trace_data[i] == NULL)
68 /* arch related info initialized */
69 tcd_for_each(tcd, i, j) {
70 tcd->tcd_pages_factor = 100; /* Only one type */
75 memset(trace_console_buffers, 0, sizeof(trace_console_buffers));
77 for (i = 0; i < NR_CPUS; i++) {
78 for (j = 0; j < 1; j++) {
79 trace_console_buffers[i][j] =
80 cfs_alloc(TRACE_CONSOLE_BUFFER_SIZE,
83 if (trace_console_buffers[i][j] == NULL)
91 tracefile_fini_arch();
92 KsPrint((0, "lnet: No enough memory\n"));
96 void tracefile_fini_arch()
101 for (i = 0; i < NR_CPUS; i++) {
102 for (j = 0; j < 2; j++) {
103 if (trace_console_buffers[i][j] != NULL) {
104 cfs_free(trace_console_buffers[i][j]);
105 trace_console_buffers[i][j] = NULL;
110 for (i = 0; trace_data[i] != NULL; i++) {
111 cfs_free(trace_data[i]);
112 trace_data[i] = NULL;
116 void tracefile_read_lock()
118 cfs_wait_event(&tracefile_event, 0);
121 void tracefile_read_unlock()
123 cfs_wake_event(&tracefile_event);
126 void tracefile_write_lock()
128 cfs_wait_event(&tracefile_event, 0);
131 void tracefile_write_unlock()
133 cfs_wake_event(&tracefile_event);
137 trace_get_console_buffer(void)
139 #pragma message ("is there possible problem with pre-emption ?")
140 int cpu = (int) KeGetCurrentProcessorNumber();
141 return trace_console_buffers[cpu][0];
145 trace_put_console_buffer(char *buffer)
149 struct trace_cpu_data *
152 #pragma message("todo: return NULL if in interrupt context")
154 int cpu = (int) KeGetCurrentProcessorNumber();
155 return &(*trace_data[0])[cpu].tcd;
159 trace_put_tcd (struct trace_cpu_data *tcd, unsigned long flags)
164 trace_lock_tcd(struct trace_cpu_data *tcd)
166 __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
171 trace_unlock_tcd(struct trace_cpu_data *tcd)
173 __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
177 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
178 const int line, unsigned long stack)
182 do_gettimeofday(&tv);
184 header->ph_subsys = subsys;
185 header->ph_mask = mask;
186 header->ph_cpu_id = smp_processor_id();
187 header->ph_sec = (__u32)tv.tv_sec;
188 header->ph_usec = tv.tv_usec;
189 header->ph_stack = stack;
190 header->ph_pid = current->pid;
191 header->ph_line_num = line;
192 header->ph_extern_pid = 0;
196 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
197 int len, const char *file, const char *fn)
199 char *prefix = NULL, *ptype = NULL;
201 if ((mask & D_EMERG) != 0) {
202 prefix = "LustreError";
204 } else if ((mask & D_ERROR) != 0) {
205 prefix = "LustreError";
207 } else if ((mask & D_WARNING) != 0) {
209 ptype = KERN_WARNING;
210 } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
215 if ((mask & D_CONSOLE) != 0) {
216 printk("%s%s: %s", ptype, prefix, buf);
218 printk("%s%s: %d:%d:(%s:%d:%s()) %s", ptype, prefix, hdr->ph_pid,
219 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, buf);
224 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
229 int trace_max_debug_mb(void)
231 int total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
233 return MAX(512, (total_mb * 80)/100);
237 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)