aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dynamic_debug.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-25 06:13:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-25 06:13:59 -0400
commit2d03423b2319cc854adeb28a03f65de5b5e0ab63 (patch)
tree20d9ddb661f3247f5dfaa6da8212123ed14a24c4 /lib/dynamic_debug.c
parent59e52534172d845ebffb0d7e85fc56fb7b857051 (diff)
parent2bbcb8788311a40714b585fc11b51da6ffa2ab92 (diff)
Merge branch 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
* 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (38 commits) mm: memory hotplug: Check if pages are correctly reserved on a per-section basis Revert "memory hotplug: Correct page reservation checking" Update email address for stable patch submission dynamic_debug: fix undefined reference to `__netdev_printk' dynamic_debug: use a single printk() to emit messages dynamic_debug: remove num_enabled accounting dynamic_debug: consolidate repetitive struct _ddebug descriptor definitions uio: Support physical addresses >32 bits on 32-bit systems sysfs: add unsigned long cast to prevent compile warning drivers: base: print rejected matches with DEBUG_DRIVER memory hotplug: Correct page reservation checking memory hotplug: Refuse to add unaligned memory regions remove the messy code file Documentation/zh_CN/SubmitChecklist ARM: mxc: convert device creation to use platform_device_register_full new helper to create platform devices with dma mask docs/driver-model: Update device class docs docs/driver-model: Document device.groups kobj_uevent: Ignore if some listeners cannot handle message dynamic_debug: make netif_dbg() call __netdev_printk() dynamic_debug: make netdev_dbg() call __netdev_printk() ...
Diffstat (limited to 'lib/dynamic_debug.c')
-rw-r--r--lib/dynamic_debug.c173
1 files changed, 119 insertions, 54 deletions
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 79fc20b65e74..dcdade39e47f 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -10,6 +10,8 @@
10 * Copyright (C) 2011 Bart Van Assche. All Rights Reserved. 10 * Copyright (C) 2011 Bart Van Assche. All Rights Reserved.
11 */ 11 */
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
14
13#include <linux/kernel.h> 15#include <linux/kernel.h>
14#include <linux/module.h> 16#include <linux/module.h>
15#include <linux/moduleparam.h> 17#include <linux/moduleparam.h>
@@ -29,6 +31,8 @@
29#include <linux/jump_label.h> 31#include <linux/jump_label.h>
30#include <linux/hardirq.h> 32#include <linux/hardirq.h>
31#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/device.h>
35#include <linux/netdevice.h>
32 36
33extern struct _ddebug __start___verbose[]; 37extern struct _ddebug __start___verbose[];
34extern struct _ddebug __stop___verbose[]; 38extern struct _ddebug __stop___verbose[];
@@ -37,7 +41,6 @@ struct ddebug_table {
37 struct list_head link; 41 struct list_head link;
38 char *mod_name; 42 char *mod_name;
39 unsigned int num_ddebugs; 43 unsigned int num_ddebugs;
40 unsigned int num_enabled;
41 struct _ddebug *ddebugs; 44 struct _ddebug *ddebugs;
42}; 45};
43 46
@@ -147,19 +150,13 @@ static void ddebug_change(const struct ddebug_query *query,
147 newflags = (dp->flags & mask) | flags; 150 newflags = (dp->flags & mask) | flags;
148 if (newflags == dp->flags) 151 if (newflags == dp->flags)
149 continue; 152 continue;
150
151 if (!newflags)
152 dt->num_enabled--;
153 else if (!dp->flags)
154 dt->num_enabled++;
155 dp->flags = newflags; 153 dp->flags = newflags;
156 if (newflags) 154 if (newflags)
157 dp->enabled = 1; 155 dp->enabled = 1;
158 else 156 else
159 dp->enabled = 0; 157 dp->enabled = 0;
160 if (verbose) 158 if (verbose)
161 printk(KERN_INFO 159 pr_info("changed %s:%d [%s]%s %s\n",
162 "ddebug: changed %s:%d [%s]%s %s\n",
163 dp->filename, dp->lineno, 160 dp->filename, dp->lineno,
164 dt->mod_name, dp->function, 161 dt->mod_name, dp->function,
165 ddebug_describe_flags(dp, flagbuf, 162 ddebug_describe_flags(dp, flagbuf,
@@ -169,7 +166,7 @@ static void ddebug_change(const struct ddebug_query *query,
169 mutex_unlock(&ddebug_lock); 166 mutex_unlock(&ddebug_lock);
170 167
171 if (!nfound && verbose) 168 if (!nfound && verbose)
172 printk(KERN_INFO "ddebug: no matches for query\n"); 169 pr_info("no matches for query\n");
173} 170}
174 171
175/* 172/*
@@ -214,10 +211,10 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
214 211
215 if (verbose) { 212 if (verbose) {
216 int i; 213 int i;
217 printk(KERN_INFO "%s: split into words:", __func__); 214 pr_info("split into words:");
218 for (i = 0 ; i < nwords ; i++) 215 for (i = 0 ; i < nwords ; i++)
219 printk(" \"%s\"", words[i]); 216 pr_cont(" \"%s\"", words[i]);
220 printk("\n"); 217 pr_cont("\n");
221 } 218 }
222 219
223 return nwords; 220 return nwords;
@@ -329,16 +326,15 @@ static int ddebug_parse_query(char *words[], int nwords,
329 } 326 }
330 } else { 327 } else {
331 if (verbose) 328 if (verbose)
332 printk(KERN_ERR "%s: unknown keyword \"%s\"\n", 329 pr_err("unknown keyword \"%s\"\n", words[i]);
333 __func__, words[i]);
334 return -EINVAL; 330 return -EINVAL;
335 } 331 }
336 } 332 }
337 333
338 if (verbose) 334 if (verbose)
339 printk(KERN_INFO "%s: q->function=\"%s\" q->filename=\"%s\" " 335 pr_info("q->function=\"%s\" q->filename=\"%s\" "
340 "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n", 336 "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n",
341 __func__, query->function, query->filename, 337 query->function, query->filename,
342 query->module, query->format, query->first_lineno, 338 query->module, query->format, query->first_lineno,
343 query->last_lineno); 339 query->last_lineno);
344 340
@@ -367,7 +363,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
367 return -EINVAL; 363 return -EINVAL;
368 } 364 }
369 if (verbose) 365 if (verbose)
370 printk(KERN_INFO "%s: op='%c'\n", __func__, op); 366 pr_info("op='%c'\n", op);
371 367
372 for ( ; *str ; ++str) { 368 for ( ; *str ; ++str) {
373 for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) { 369 for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
@@ -382,7 +378,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
382 if (flags == 0) 378 if (flags == 0)
383 return -EINVAL; 379 return -EINVAL;
384 if (verbose) 380 if (verbose)
385 printk(KERN_INFO "%s: flags=0x%x\n", __func__, flags); 381 pr_info("flags=0x%x\n", flags);
386 382
387 /* calculate final *flagsp, *maskp according to mask and op */ 383 /* calculate final *flagsp, *maskp according to mask and op */
388 switch (op) { 384 switch (op) {
@@ -400,8 +396,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
400 break; 396 break;
401 } 397 }
402 if (verbose) 398 if (verbose)
403 printk(KERN_INFO "%s: *flagsp=0x%x *maskp=0x%x\n", 399 pr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
404 __func__, *flagsp, *maskp);
405 return 0; 400 return 0;
406} 401}
407 402
@@ -426,40 +421,117 @@ static int ddebug_exec_query(char *query_string)
426 return 0; 421 return 0;
427} 422}
428 423
424#define PREFIX_SIZE 64
425
426static int remaining(int wrote)
427{
428 if (PREFIX_SIZE - wrote > 0)
429 return PREFIX_SIZE - wrote;
430 return 0;
431}
432
433static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
434{
435 int pos_after_tid;
436 int pos = 0;
437
438 pos += snprintf(buf + pos, remaining(pos), "%s", KERN_DEBUG);
439 if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
440 if (in_interrupt())
441 pos += snprintf(buf + pos, remaining(pos), "%s ",
442 "<intr>");
443 else
444 pos += snprintf(buf + pos, remaining(pos), "[%d] ",
445 task_pid_vnr(current));
446 }
447 pos_after_tid = pos;
448 if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
449 pos += snprintf(buf + pos, remaining(pos), "%s:",
450 desc->modname);
451 if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
452 pos += snprintf(buf + pos, remaining(pos), "%s:",
453 desc->function);
454 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
455 pos += snprintf(buf + pos, remaining(pos), "%d:", desc->lineno);
456 if (pos - pos_after_tid)
457 pos += snprintf(buf + pos, remaining(pos), " ");
458 if (pos >= PREFIX_SIZE)
459 buf[PREFIX_SIZE - 1] = '\0';
460
461 return buf;
462}
463
429int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) 464int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
430{ 465{
431 va_list args; 466 va_list args;
432 int res; 467 int res;
468 struct va_format vaf;
469 char buf[PREFIX_SIZE];
433 470
434 BUG_ON(!descriptor); 471 BUG_ON(!descriptor);
435 BUG_ON(!fmt); 472 BUG_ON(!fmt);
436 473
437 va_start(args, fmt); 474 va_start(args, fmt);
438 res = printk(KERN_DEBUG); 475 vaf.fmt = fmt;
439 if (descriptor->flags & _DPRINTK_FLAGS_INCL_TID) { 476 vaf.va = &args;
440 if (in_interrupt()) 477 res = printk("%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
441 res += printk(KERN_CONT "<intr> ");
442 else
443 res += printk(KERN_CONT "[%d] ", task_pid_vnr(current));
444 }
445 if (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME)
446 res += printk(KERN_CONT "%s:", descriptor->modname);
447 if (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
448 res += printk(KERN_CONT "%s:", descriptor->function);
449 if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO)
450 res += printk(KERN_CONT "%d ", descriptor->lineno);
451 res += vprintk(fmt, args);
452 va_end(args); 478 va_end(args);
453 479
454 return res; 480 return res;
455} 481}
456EXPORT_SYMBOL(__dynamic_pr_debug); 482EXPORT_SYMBOL(__dynamic_pr_debug);
457 483
484int __dynamic_dev_dbg(struct _ddebug *descriptor,
485 const struct device *dev, const char *fmt, ...)
486{
487 struct va_format vaf;
488 va_list args;
489 int res;
490 char buf[PREFIX_SIZE];
491
492 BUG_ON(!descriptor);
493 BUG_ON(!fmt);
494
495 va_start(args, fmt);
496 vaf.fmt = fmt;
497 vaf.va = &args;
498 res = __dev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
499 va_end(args);
500
501 return res;
502}
503EXPORT_SYMBOL(__dynamic_dev_dbg);
504
505#ifdef CONFIG_NET
506
507int __dynamic_netdev_dbg(struct _ddebug *descriptor,
508 const struct net_device *dev, const char *fmt, ...)
509{
510 struct va_format vaf;
511 va_list args;
512 int res;
513 char buf[PREFIX_SIZE];
514
515 BUG_ON(!descriptor);
516 BUG_ON(!fmt);
517
518 va_start(args, fmt);
519 vaf.fmt = fmt;
520 vaf.va = &args;
521 res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
522 va_end(args);
523
524 return res;
525}
526EXPORT_SYMBOL(__dynamic_netdev_dbg);
527
528#endif
529
458static __initdata char ddebug_setup_string[1024]; 530static __initdata char ddebug_setup_string[1024];
459static __init int ddebug_setup_query(char *str) 531static __init int ddebug_setup_query(char *str)
460{ 532{
461 if (strlen(str) >= 1024) { 533 if (strlen(str) >= 1024) {
462 pr_warning("ddebug boot param string too large\n"); 534 pr_warn("ddebug boot param string too large\n");
463 return 0; 535 return 0;
464 } 536 }
465 strcpy(ddebug_setup_string, str); 537 strcpy(ddebug_setup_string, str);
@@ -487,8 +559,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
487 return -EFAULT; 559 return -EFAULT;
488 tmpbuf[len] = '\0'; 560 tmpbuf[len] = '\0';
489 if (verbose) 561 if (verbose)
490 printk(KERN_INFO "%s: read %d bytes from userspace\n", 562 pr_info("read %d bytes from userspace\n", (int)len);
491 __func__, (int)len);
492 563
493 ret = ddebug_exec_query(tmpbuf); 564 ret = ddebug_exec_query(tmpbuf);
494 if (ret) 565 if (ret)
@@ -551,8 +622,7 @@ static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
551 int n = *pos; 622 int n = *pos;
552 623
553 if (verbose) 624 if (verbose)
554 printk(KERN_INFO "%s: called m=%p *pos=%lld\n", 625 pr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos);
555 __func__, m, (unsigned long long)*pos);
556 626
557 mutex_lock(&ddebug_lock); 627 mutex_lock(&ddebug_lock);
558 628
@@ -577,8 +647,8 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
577 struct _ddebug *dp; 647 struct _ddebug *dp;
578 648
579 if (verbose) 649 if (verbose)
580 printk(KERN_INFO "%s: called m=%p p=%p *pos=%lld\n", 650 pr_info("called m=%p p=%p *pos=%lld\n",
581 __func__, m, p, (unsigned long long)*pos); 651 m, p, (unsigned long long)*pos);
582 652
583 if (p == SEQ_START_TOKEN) 653 if (p == SEQ_START_TOKEN)
584 dp = ddebug_iter_first(iter); 654 dp = ddebug_iter_first(iter);
@@ -601,8 +671,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
601 char flagsbuf[8]; 671 char flagsbuf[8];
602 672
603 if (verbose) 673 if (verbose)
604 printk(KERN_INFO "%s: called m=%p p=%p\n", 674 pr_info("called m=%p p=%p\n", m, p);
605 __func__, m, p);
606 675
607 if (p == SEQ_START_TOKEN) { 676 if (p == SEQ_START_TOKEN) {
608 seq_puts(m, 677 seq_puts(m,
@@ -627,8 +696,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
627static void ddebug_proc_stop(struct seq_file *m, void *p) 696static void ddebug_proc_stop(struct seq_file *m, void *p)
628{ 697{
629 if (verbose) 698 if (verbose)
630 printk(KERN_INFO "%s: called m=%p p=%p\n", 699 pr_info("called m=%p p=%p\n", m, p);
631 __func__, m, p);
632 mutex_unlock(&ddebug_lock); 700 mutex_unlock(&ddebug_lock);
633} 701}
634 702
@@ -651,7 +719,7 @@ static int ddebug_proc_open(struct inode *inode, struct file *file)
651 int err; 719 int err;
652 720
653 if (verbose) 721 if (verbose)
654 printk(KERN_INFO "%s: called\n", __func__); 722 pr_info("called\n");
655 723
656 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 724 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
657 if (iter == NULL) 725 if (iter == NULL)
@@ -695,7 +763,6 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
695 } 763 }
696 dt->mod_name = new_name; 764 dt->mod_name = new_name;
697 dt->num_ddebugs = n; 765 dt->num_ddebugs = n;
698 dt->num_enabled = 0;
699 dt->ddebugs = tab; 766 dt->ddebugs = tab;
700 767
701 mutex_lock(&ddebug_lock); 768 mutex_lock(&ddebug_lock);
@@ -703,8 +770,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
703 mutex_unlock(&ddebug_lock); 770 mutex_unlock(&ddebug_lock);
704 771
705 if (verbose) 772 if (verbose)
706 printk(KERN_INFO "%u debug prints in module %s\n", 773 pr_info("%u debug prints in module %s\n", n, dt->mod_name);
707 n, dt->mod_name);
708 return 0; 774 return 0;
709} 775}
710EXPORT_SYMBOL_GPL(ddebug_add_module); 776EXPORT_SYMBOL_GPL(ddebug_add_module);
@@ -726,8 +792,7 @@ int ddebug_remove_module(const char *mod_name)
726 int ret = -ENOENT; 792 int ret = -ENOENT;
727 793
728 if (verbose) 794 if (verbose)
729 printk(KERN_INFO "%s: removing module \"%s\"\n", 795 pr_info("removing module \"%s\"\n", mod_name);
730 __func__, mod_name);
731 796
732 mutex_lock(&ddebug_lock); 797 mutex_lock(&ddebug_lock);
733 list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) { 798 list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
@@ -803,8 +868,8 @@ static int __init dynamic_debug_init(void)
803 if (ddebug_setup_string[0] != '\0') { 868 if (ddebug_setup_string[0] != '\0') {
804 ret = ddebug_exec_query(ddebug_setup_string); 869 ret = ddebug_exec_query(ddebug_setup_string);
805 if (ret) 870 if (ret)
806 pr_warning("Invalid ddebug boot param %s", 871 pr_warn("Invalid ddebug boot param %s",
807 ddebug_setup_string); 872 ddebug_setup_string);
808 else 873 else
809 pr_info("ddebug initialized with string %s", 874 pr_info("ddebug initialized with string %s",
810 ddebug_setup_string); 875 ddebug_setup_string);