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 extern union trace_data_union trace_data[NR_CPUS];
15 char *trace_console_buffers[NR_CPUS][3];
17 struct rw_semaphore tracefile_sem;
19 int tracefile_init_arch()
24 init_rwsem(&tracefile_sem);
26 for (i = 0; i < num_possible_cpus(); i++)
27 for (j = 0; j < 3; j++) {
28 trace_console_buffers[i][j] =
29 kmalloc(TRACE_CONSOLE_BUFFER_SIZE,
32 if (trace_console_buffers[i][j] == NULL) {
33 tracefile_fini_arch();
36 "console message buffer\n");
44 void tracefile_fini_arch()
49 for (i = 0; i < num_possible_cpus(); i++)
50 for (j = 0; j < 3; j++)
51 if (trace_console_buffers[i][j] != NULL) {
52 kfree(trace_console_buffers[i][j]);
53 trace_console_buffers[i][j] = NULL;
57 void tracefile_read_lock()
59 down_read(&tracefile_sem);
62 void tracefile_read_unlock()
64 up_read(&tracefile_sem);
67 void tracefile_write_lock()
69 down_write(&tracefile_sem);
72 void tracefile_write_unlock()
74 up_write(&tracefile_sem);
78 trace_get_console_buffer(void)
85 } else if (in_softirq()) {
91 return trace_console_buffers[cpu][idx];
95 trace_put_console_buffer(char *buffer)
100 struct trace_cpu_data *
105 if (in_interrupt()) /* no logging in IRQ context */
109 return &trace_data[cpu].tcd;
113 trace_put_tcd (struct trace_cpu_data *tcd)
115 __LASSERT (!in_interrupt());
119 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
122 * XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT)
123 * from here: this will lead to infinite recursion.
125 return tcd->tcd_cpu == tage->cpu;
129 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
130 const int line, unsigned long stack)
134 do_gettimeofday(&tv);
136 header->ph_subsys = subsys;
137 header->ph_mask = mask;
138 header->ph_cpu_id = smp_processor_id();
139 header->ph_sec = (__u32)tv.tv_sec;
140 header->ph_usec = tv.tv_usec;
141 header->ph_stack = stack;
142 header->ph_pid = current->pid;
143 header->ph_line_num = line;
144 #if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
145 header->ph_extern_pid = current->thread.extern_pid;
146 #elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
147 header->ph_extern_pid = current->thread.mode.tt.extern_pid;
149 header->ph_extern_pid = 0;
154 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
155 int len, const char *file, const char *fn)
157 char *prefix = "Lustre", *ptype = NULL;
159 if ((mask & D_EMERG) != 0) {
160 prefix = "LustreError";
162 } else if ((mask & D_ERROR) != 0) {
163 prefix = "LustreError";
165 } else if ((mask & D_WARNING) != 0) {
167 ptype = KERN_WARNING;
168 } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
173 if ((mask & D_CONSOLE) != 0) {
174 printk("%s%s: %.*s", ptype, prefix, len, buf);
176 printk("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, hdr->ph_pid,
177 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf);
182 int trace_max_debug_mb(void)
184 int total_mb = (num_physpages >> (20 - CFS_PAGE_SHIFT));
186 return MAX(512, (total_mb * 80)/100);
190 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
192 cpumask_t cpus_allowed = current->cpus_allowed;
193 /* use cpus_allowed to quiet 2.4 UP kernel warning only */
194 cpumask_t m = cpus_allowed;
197 /* Run the given routine on every CPU in thread context */
198 for (cpu = 0; cpu < num_possible_cpus(); cpu++) {
199 if (!cpu_online(cpu))
204 set_cpus_allowed(current, m);
208 set_cpus_allowed(current, cpus_allowed);