1 #define DEBUG_SUBSYSTEM S_LNET
2 #define LUSTRE_TRACEFILE_PRIVATE
4 #include <libcfs/libcfs.h>
5 #include <libcfs/kp30.h>
9 #define get_cpu() smp_processor_id()
10 #define put_cpu() do { } while (0)
13 /* three types of trace_data in linux */
21 /* percents to share the total debug memory for each type */
22 static unsigned int pages_factor[TCD_TYPE_MAX] = {
23 80, /* 80% pages for TCD_TYPE_PROC */
24 10, /* 10% pages for TCD_TYPE_SOFTIRQ */
25 10 /* 10% pages for TCD_TYPE_IRQ */
28 char *trace_console_buffers[NR_CPUS][3];
30 struct rw_semaphore tracefile_sem;
32 int tracefile_init_arch()
36 struct trace_cpu_data *tcd;
38 init_rwsem(&tracefile_sem);
40 /* initialize trace_data */
41 memset(trace_data, 0, sizeof(trace_data));
42 for (i = 0; i < TCD_TYPE_MAX; i++) {
43 trace_data[i]=kmalloc(sizeof(union trace_data_union)*NR_CPUS,
45 if (trace_data[i] == NULL)
50 /* arch related info initialized */
51 tcd_for_each(tcd, i, j) {
52 tcd->tcd_pages_factor = pages_factor[i];
57 for (i = 0; i < num_possible_cpus(); i++)
58 for (j = 0; j < 3; j++) {
59 trace_console_buffers[i][j] =
60 kmalloc(TRACE_CONSOLE_BUFFER_SIZE,
63 if (trace_console_buffers[i][j] == NULL)
70 tracefile_fini_arch();
71 printk(KERN_ERR "lnet: No enough memory\n");
76 void tracefile_fini_arch()
81 for (i = 0; i < num_possible_cpus(); i++)
82 for (j = 0; j < 3; j++)
83 if (trace_console_buffers[i][j] != NULL) {
84 kfree(trace_console_buffers[i][j]);
85 trace_console_buffers[i][j] = NULL;
88 for (i = 0; trace_data[i] != NULL; i++) {
94 void tracefile_read_lock()
96 down_read(&tracefile_sem);
99 void tracefile_read_unlock()
101 up_read(&tracefile_sem);
104 void tracefile_write_lock()
106 down_write(&tracefile_sem);
109 void tracefile_write_unlock()
111 up_write(&tracefile_sem);
115 trace_get_console_buffer(void)
122 } else if (in_softirq()) {
128 return trace_console_buffers[cpu][idx];
132 trace_put_console_buffer(char *buffer)
137 struct trace_cpu_data *
144 return &(*trace_data[TCD_TYPE_IRQ])[cpu].tcd;
145 else if (in_softirq())
146 return &(*trace_data[TCD_TYPE_SOFTIRQ])[cpu].tcd;
147 return &(*trace_data[TCD_TYPE_PROC])[cpu].tcd;
151 trace_put_tcd (struct trace_cpu_data *tcd)
156 int trace_lock_tcd(struct trace_cpu_data *tcd)
158 __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
159 if (tcd->tcd_type == TCD_TYPE_IRQ)
161 else if (tcd->tcd_type == TCD_TYPE_SOFTIRQ)
166 void trace_unlock_tcd(struct trace_cpu_data *tcd)
168 __LASSERT(tcd->tcd_type < TCD_TYPE_MAX);
169 if (tcd->tcd_type == TCD_TYPE_IRQ)
171 else if (tcd->tcd_type == TCD_TYPE_SOFTIRQ)
175 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
178 * XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT)
179 * from here: this will lead to infinite recursion.
181 return tcd->tcd_cpu == tage->cpu;
185 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
186 const int line, unsigned long stack)
190 do_gettimeofday(&tv);
192 header->ph_subsys = subsys;
193 header->ph_mask = mask;
194 header->ph_cpu_id = smp_processor_id();
195 header->ph_sec = (__u32)tv.tv_sec;
196 header->ph_usec = tv.tv_usec;
197 header->ph_stack = stack;
198 header->ph_pid = current->pid;
199 header->ph_line_num = line;
200 #if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
201 header->ph_extern_pid = current->thread.extern_pid;
202 #elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
203 header->ph_extern_pid = current->thread.mode.tt.extern_pid;
205 header->ph_extern_pid = 0;
210 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
211 int len, const char *file, const char *fn)
213 char *prefix = "Lustre", *ptype = NULL;
215 if ((mask & D_EMERG) != 0) {
216 prefix = "LustreError";
218 } else if ((mask & D_ERROR) != 0) {
219 prefix = "LustreError";
221 } else if ((mask & D_WARNING) != 0) {
223 ptype = KERN_WARNING;
224 } else if ((mask & (D_CONSOLE | libcfs_printk)) != 0) {
229 if ((mask & D_CONSOLE) != 0) {
230 printk("%s%s: %.*s", ptype, prefix, len, buf);
232 printk("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, hdr->ph_pid,
233 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf);
238 int trace_max_debug_mb(void)
240 int total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
242 return MAX(512, (total_mb * 80)/100);
246 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
248 cpumask_t cpus_allowed = current->cpus_allowed;
249 /* use cpus_allowed to quiet 2.4 UP kernel warning only */
250 cpumask_t m = cpus_allowed;
253 /* Run the given routine on every CPU in thread context */
254 for (cpu = 0; cpu < num_possible_cpus(); cpu++) {
255 if (!cpu_online(cpu))
260 set_cpus_allowed(current, m);
264 set_cpus_allowed(current, cpus_allowed);