4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
35 #define DEBUG_SUBSYSTEM S_LNET
36 #define LUSTRE_TRACEFILE_PRIVATE
38 #include <libcfs/libcfs.h>
39 #include "tracefile.h"
41 /* percents to share the total debug memory for each type */
42 static unsigned int pages_factor[CFS_TCD_TYPE_MAX] = {
43 90, /* 90% pages for CFS_TCD_TYPE_PASSIVE */
44 10 /* 10% pages for CFS_TCD_TYPE_DISPATCH */
47 char *cfs_trace_console_buffers[CFS_NR_CPUS][CFS_TCD_TYPE_MAX];
49 cfs_rw_semaphore_t cfs_tracefile_sem;
51 int cfs_tracefile_init_arch()
55 struct cfs_trace_cpu_data *tcd;
57 cfs_init_rwsem(&cfs_tracefile_sem);
59 /* initialize trace_data */
60 memset(cfs_trace_data, 0, sizeof(cfs_trace_data));
61 for (i = 0; i < CFS_TCD_TYPE_MAX; i++) {
63 cfs_alloc(sizeof(union cfs_trace_data_union) * \
64 CFS_NR_CPUS, GFP_KERNEL);
65 if (cfs_trace_data[i] == NULL)
69 /* arch related info initialized */
70 cfs_tcd_for_each(tcd, i, j) {
71 tcd->tcd_pages_factor = (USHORT) pages_factor[i];
72 tcd->tcd_type = (USHORT) i;
73 tcd->tcd_cpu = (USHORT)j;
76 for (i = 0; i < cfs_num_possible_cpus(); i++)
77 for (j = 0; j < CFS_TCD_TYPE_MAX; j++) {
78 cfs_trace_console_buffers[i][j] =
79 cfs_alloc(CFS_TRACE_CONSOLE_BUFFER_SIZE,
82 if (cfs_trace_console_buffers[i][j] == NULL)
89 cfs_tracefile_fini_arch();
90 printk(CFS_KERN_ERR "lnet: Not enough memory\n");
95 void cfs_tracefile_fini_arch()
100 for (i = 0; i < cfs_num_possible_cpus(); i++) {
101 for (j = 0; j < CFS_TCD_TYPE_MAX; j++) {
102 if (cfs_trace_console_buffers[i][j] != NULL) {
103 cfs_free(cfs_trace_console_buffers[i][j]);
104 cfs_trace_console_buffers[i][j] = NULL;
109 for (i = 0; cfs_trace_data[i] != NULL; i++) {
110 cfs_free(cfs_trace_data[i]);
111 cfs_trace_data[i] = NULL;
114 cfs_fini_rwsem(&cfs_tracefile_sem);
117 void cfs_tracefile_read_lock()
119 cfs_down_read(&cfs_tracefile_sem);
122 void cfs_tracefile_read_unlock()
124 cfs_up_read(&cfs_tracefile_sem);
127 void cfs_tracefile_write_lock()
129 cfs_down_write(&cfs_tracefile_sem);
132 void cfs_tracefile_write_unlock()
134 cfs_up_write(&cfs_tracefile_sem);
137 cfs_trace_buf_type_t cfs_trace_buf_idx_get()
139 if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
140 return CFS_TCD_TYPE_DISPATCH;
142 return CFS_TCD_TYPE_PASSIVE;
145 int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
147 __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
151 void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)
153 __LASSERT(tcd->tcd_type < CFS_TCD_TYPE_MAX);
156 int cfs_tcd_owns_tage(struct cfs_trace_cpu_data *tcd,
157 struct cfs_trace_page *tage)
160 * XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT)
161 * from here: this will lead to infinite recursion.
163 return tcd->tcd_cpu == tage->cpu;
167 cfs_set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
168 const int line, unsigned long stack)
172 cfs_gettimeofday(&tv);
174 header->ph_subsys = subsys;
175 header->ph_mask = mask;
176 header->ph_cpu_id = cfs_smp_processor_id();
177 header->ph_type = cfs_trace_buf_idx_get();
178 header->ph_sec = (__u32)tv.tv_sec;
179 header->ph_usec = tv.tv_usec;
180 header->ph_stack = stack;
181 header->ph_pid = (__u32)(ULONG_PTR)current->pid;
182 header->ph_line_num = line;
183 header->ph_extern_pid = 0;
187 void cfs_print_to_console(struct ptldebug_header *hdr, int mask,
188 const char *buf, int len, const char *file,
191 char *prefix = "Lustre", *ptype = NULL;
193 if ((mask & D_EMERG) != 0) {
194 prefix = "LustreError";
195 ptype = CFS_KERN_EMERG;
196 } else if ((mask & D_ERROR) != 0) {
197 prefix = "LustreError";
198 ptype = CFS_KERN_ERR;
199 } else if ((mask & D_WARNING) != 0) {
201 ptype = CFS_KERN_WARNING;
202 } else if ((mask & (D_CONSOLE | libcfs_printk)) != 0) {
204 ptype = CFS_KERN_INFO;
207 if ((mask & D_CONSOLE) != 0) {
208 printk("%s%s: %.*s", ptype, prefix, len, buf);
210 printk("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, hdr->ph_pid,
211 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf);
216 int cfs_trace_max_debug_mb(void)
218 int total_mb = (cfs_num_physpages >> (20 - CFS_PAGE_SHIFT));
220 return MAX(512, (total_mb * 80)/100);