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];
14 extern char *tracefile;
15 extern long long tracefile_size;
17 char *trace_console_buffers[NR_CPUS][3];
19 struct rw_semaphore tracefile_sem;
21 int tracefile_init_arch()
26 init_rwsem(&tracefile_sem);
28 for (i = 0; i < NR_CPUS; i++)
29 for (j = 0; j < 3; j++) {
30 trace_console_buffers[i][j] =
31 kmalloc(TRACE_CONSOLE_BUFFER_SIZE,
34 if (trace_console_buffers[i][j] == NULL) {
35 tracefile_fini_arch();
38 "console message buffer\n");
46 void tracefile_fini_arch()
51 for (i = 0; i < NR_CPUS; i++)
52 for (j = 0; j < 3; j++)
53 if (trace_console_buffers[i][j] != NULL) {
54 kfree(trace_console_buffers[i][j]);
55 trace_console_buffers[i][j] = NULL;
59 void tracefile_read_lock()
61 down_read(&tracefile_sem);
64 void tracefile_read_unlock()
66 up_read(&tracefile_sem);
69 void tracefile_write_lock()
71 down_write(&tracefile_sem);
74 void tracefile_write_unlock()
76 up_write(&tracefile_sem);
80 trace_get_console_buffer(void)
87 } else if (in_softirq()) {
93 return trace_console_buffers[cpu][idx];
97 trace_put_console_buffer(char *buffer)
102 struct trace_cpu_data *
107 if (in_interrupt()) /* no logging in IRQ context */
111 return &trace_data[cpu].tcd;
115 trace_put_tcd (struct trace_cpu_data *tcd)
117 __LASSERT (!in_interrupt());
121 int tcd_owns_tage(struct trace_cpu_data *tcd, struct trace_page *tage)
124 * XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT)
125 * from here: this will lead to infinite recursion.
127 return tcd->tcd_cpu == tage->cpu;
131 set_ptldebug_header(struct ptldebug_header *header, int subsys, int mask,
132 const int line, unsigned long stack)
136 do_gettimeofday(&tv);
138 header->ph_subsys = subsys;
139 header->ph_mask = mask;
140 header->ph_cpu_id = smp_processor_id();
141 header->ph_sec = (__u32)tv.tv_sec;
142 header->ph_usec = tv.tv_usec;
143 header->ph_stack = stack;
144 header->ph_pid = current->pid;
145 header->ph_line_num = line;
146 #if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
147 header->ph_extern_pid = current->thread.extern_pid;
148 #elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
149 header->ph_extern_pid = current->thread.mode.tt.extern_pid;
151 header->ph_extern_pid = 0;
156 void print_to_console(struct ptldebug_header *hdr, int mask, const char *buf,
157 int len, const char *file, const char *fn)
159 char *prefix = "Lustre", *ptype = NULL;
161 if ((mask & D_EMERG) != 0) {
162 prefix = "LustreError";
164 } else if ((mask & D_ERROR) != 0) {
165 prefix = "LustreError";
167 } else if ((mask & D_WARNING) != 0) {
169 ptype = KERN_WARNING;
170 } else if ((mask & libcfs_printk) != 0 || (mask & D_CONSOLE)) {
175 if ((mask & D_CONSOLE) != 0) {
176 printk("%s%s: %.*s", ptype, prefix, len, buf);
178 printk("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, hdr->ph_pid,
179 hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf);
184 int trace_write_daemon_file(struct file *file, const char *buffer,
185 unsigned long count, void *data)
191 name = kmalloc(count + 1, GFP_KERNEL);
195 if (copy_from_user(name, buffer, count)) {
200 /* be nice and strip out trailing '\n' */
201 for (off = count ; off > 2 && isspace(name[off - 1]); off--)
206 tracefile_write_lock();
207 if (strcmp(name, "stop") == 0) {
211 } else if (strncmp(name, "size=", 5) == 0) {
212 tracefile_size = simple_strtoul(name + 5, NULL, 0);
213 if (tracefile_size < 10 || tracefile_size > 20480)
214 tracefile_size = TRACEFILE_SIZE;
216 tracefile_size <<= 20;
220 if (name[0] != '/') {
225 if (tracefile != NULL)
230 printk(KERN_INFO "Lustre: debug daemon will attempt to start writing "
231 "to %s (%lukB max)\n", tracefile, (long)(tracefile_size >> 10));
233 trace_start_thread();
235 tracefile_write_unlock();
241 int trace_read_daemon_file(char *page, char **start, off_t off, int count,
242 int *eof, void *data)
246 tracefile_read_lock();
247 rc = snprintf(page, count, "%s", tracefile);
248 tracefile_read_unlock();
253 int trace_write_debug_mb(struct file *file, const char *buffer,
254 unsigned long count, void *data)
260 if (count >= sizeof(string)) {
261 printk(KERN_ERR "Lustre: value too large (length %lu bytes)\n",
266 if (copy_from_user(string, buffer, count))
269 max = simple_strtoul(string, NULL, 0);
273 if (max > (num_physpages >> (20 - 2 - CFS_PAGE_SHIFT)) / 5 || max >= 512) {
274 printk(KERN_ERR "Lustre: Refusing to set debug buffer size to "
275 "%dMB, which is more than 80%% of available RAM (%lu)\n",
276 max, (num_physpages >> (20 - 2 - CFS_PAGE_SHIFT)) / 5);
282 for (i = 0; i < NR_CPUS; i++) {
283 struct trace_cpu_data *tcd;
284 tcd = &trace_data[i].tcd;
285 tcd->tcd_max_pages = max << (20 - CFS_PAGE_SHIFT);
290 int trace_read_debug_mb(char *page, char **start, off_t off, int count,
291 int *eof, void *data)
293 struct trace_cpu_data *tcd;
296 tcd = trace_get_tcd();
297 __LASSERT (tcd != NULL);
299 rc = snprintf(page, count, "%lu\n",
300 (tcd->tcd_max_pages >> (20 - CFS_PAGE_SHIFT)) * smp_num_cpus);
307 trace_call_on_all_cpus(void (*fn)(void *arg), void *arg)
309 cpumask_t cpus_allowed = current->cpus_allowed;
310 /* use cpus_allowed to quiet 2.4 UP kernel warning only */
311 cpumask_t m = cpus_allowed;
314 /* Run the given routine on every CPU in thread context */
315 for (cpu = 0; cpu < NR_CPUS; cpu++) {
316 if (!cpu_online(cpu))
321 set_cpus_allowed(current, m);
325 set_cpus_allowed(current, cpus_allowed);