tag 标签: printk

相关博文
  • 热度 28
    2012-4-4 12:12
    2471 次阅读|
    0 个评论
      作者:下家山 (转载,请注明作者,请尊重原创) 一:printk等级 Printk是一个带打印等级(loglevel)的内核打印语句。 Linux内核根据问题的严重程度定义了八种等级(loglevel) #define    KERN_EMERG     "0"     /* system is unusable                   */ #define    KERN_ALERT      "1"     /* action must be taken immediately     */ #define    KERN_CRIT  "2"     /* critical conditions                    */ #define    KERN_ERR   "3"     /* error conditions                */ #define    KERN_WARNING "4"     /* warning conditions                  */ #define    KERN_NOTICE    "5"     /* normal but significant condition       */ #define    KERN_INFO  "6"     /* informational                   */ #define    KERN_DEBUG     "7"     /* debug-level messages               */ 值越小等级越高。 (见include/linux/kernel.h linux2.6.15) 二:printk输出方式 Printk的输出方式有两种:syslog(日志)和console(控制台)。我们通常在调试驱动时一般 把控制台定向到了串口,然后通过串口显示到串口终端上。 2.1 通过console输出        当loglevel小于console_loglevel时,消息才能被打印到控制台上(也就能在串口终端看到内容了)。      2.2 通过日志查看        那么当loglevel大于console_loglevel,消息保存在哪里呢? 如果系统运行了klogd和syslogd,则无论console_loglevel为何值,内核消息都将追加到/var/log/messages中。如果klogd没有运行,消息不会传递到用户空间,只能查看/proc/kmsg。 也就是说messages或kmsg中会显示所有的打印信息。 三:console_loglevel值为多少        Console_loglevel同样定义在include/linux/kernel.h中 #define console_loglevel (console_printk ) #define default_message_loglevel (console_printk ) #define minimum_console_loglevel (console_printk ) #define default_console_loglevel (console_printk )        而console_printk定义在哪里呢?        (见kernel/printk.c) #define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */ /* We show everything that is MORE important than this.. */ #define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */ #define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */ int console_printk = {        DEFAULT_CONSOLE_LOGLEVEL,       /* console_loglevel */        DEFAULT_MESSAGE_LOGLEVEL,       /* default_message_loglevel */        MINIMUM_CONSOLE_LOGLEVEL,/* minimum_console_loglevel */        DEFAULT_CONSOLE_LOGLEVEL,       /* default_console_loglevel */ };        这样 console_loglevel值就为7 四:测试程序        #include #include #define       PRINTM_MSG(msg)   printk(KERN_DEBUG msg) #define       PRINTM(level,msg...) PRINTM_##level(msg) #define pr_debug(arg) printk(KERN_INFO arg) static int printk_test_init(void) {           printk(KERN_EMERG "Hello0\n");             printk(KERN_ALERT "Hello1\n");     printk(KERN_CRIT "Hello2\n");        printk(KERN_ERR "Hello3\n");          printk(KERN_WARNING "Hello4\n");       printk(KERN_NOTICE "Hello5\n");            printk(KERN_INFO "Hello6\n");        printk(KERN_DEBUG "Hello7\n");             printk(KERN_DEBUG "Hello7\n");             printk(KERN_DEBUG "%s\n","Hello7-1");         PRINTM_MSG("No external FW image\n");     PRINTM(MSG, "No external FW image\n");     pr_debug("success!\n") ;     return 0; } static void printk_test_exit(void) {         printk(KERN_EMERG"Goodbye\n");      } module_init(printk_test_init); module_exit(printk_test_exit); 五:测试结果 转载:请注明,作者,下家山   请尊重原创!  
  • 热度 27
    2012-4-4 12:11
    1398 次阅读|
    0 个评论
    作者:下家山(转载,请注明) 六:kmsg查看结果 # ls /proc/ 1              6              diskstats      locks          stat 10             7              driver         meminfo        swaps 11             8              execdomains    misc           sys 12             9              filesystems    modules        sysrq-trigger 13             buddyinfo      fs             mounts         sysvipc 18             bus            interrupts     mtd            tty 2              cmdline        iomem          net            uptime 28             cpu            ioports        partitions     version 3              cpuinfo        kallsyms       schedstat      vmstat 4              crypto         kmsg           self           zoneinfo 5              devices        loadavg        slabinfo # cat proc/kmsg 5Linux version 2.6.15 (root@pc-ubuntu) (gcc version 3.4.1) #100 Tue Jan 13 13:44:09 CST 2009 4CPU: ARM920Tid(wb) revision 0 (ARMv4T) 4Machine: SMDK2410 4Warning: bad configuration page, trying to continue 4Memory policy: ECC disabled, Data cache writeback 7On node 0 totalpages: 4096 7  DMA zone: 4096 pages, LIFO batch:0 7  DMA32 zone: 0 pages, LIFO batch:0 7  Normal zone: 0 pages, LIFO batch:0 7  HighMem zone: 0 pages, LIFO batch:0 4to Call s3c_lookup_cpu 4Call s3c_lookup_cpu end 4CPU S3C2410A (id 0x32410002) 4S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz 6S3C2410 Clocks, (c) 2004 Simtec Electronics 4CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on 4CPU0: D VIVT write-back cache 4CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets 4CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets 4Built 1 zonelists 5Kernel command line: noinitrd console=ttySAC0,115200 root=/dev/nfs rw nfsroot=10.128.34.77:/home/cgm/Linux/root_nfs ip=10.128.34.43:10.128.34.77:10.128.34.102:255.255.255.0:host:eth0:off 4irq: clearing subpending status 00000002 4PID hash table entries: 128 (order: 7, 2048 bytes) 4timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e4c 4Console: colour dummy device 80x30 7selected clock c020e26c (pclk) quot 27, calc 113169 4Dentry cache hash table entries: 4096 (order: 2, 16384 bytes) 4Inode-cache hash table entries: 2048 (order: 1, 8192 bytes) 6Memory: 16MB = 16MB total 5Memory: 13820KB available (1899K code, 367K data, 100K init) 7Calibrating delay loop... 50.48 BogoMIPS (lpj=126208) 6io scheduler anticipatory registered 6io scheduler deadline registered 6io scheduler cfq registered 4S3C2410 RTC, (c) 2004 Simtec Electronics 4cs89x0.c: v2.4.3-pre1 Russell Nelson , Andrew Morton @uow.edu.au@crynwr.com 6eth0: cs8900 rev K found at 0xf1300300 6NET: Registered protocol family 2 4IP route cache hash table entries: 256 (order: -2, 1024 bytes) 4TCP established hash table entries: 1024 (order: 0, 4096 bytes) 4TCP bind hash table entries: 1024 (order: 0, 4096 bytes) 6TCP: Hash tables configured (established 1024 bind 1024) 6TCP reno registered 6TCP bic registered 6NET: Registered protocol family 1 6eth0: using half-duplex 10Base-T (RJ-45) 4IP-Config: Complete: 4      device=eth0, addr=10.128.34.43, mask=255.255.255.0, gw=10.128.34.102, 4     host=host, domain=, nis-domain=(none), 4     bootserver=10.128.34.77, rootserver=10.128.34.77, rootpath= 5Looking up port of RPC 100003/2 on 10.128.34.77 5Looking up port of RPC 100005/1 on 10.128.34.77 4VFS: Mounted root (nfs filesystem). 6Freeing init memory: 100K 7selected clock c020e26c (pclk) quot 27, calc 113169 7selected clock c020e26c (pclk) quot 27, calc 113169 7selected clock c020e26c (pclk) quot 27, calc 113169 7selected clock c020e26c (pclk) quot 27, calc 113169 7selected clock c020e26c (pclk) quot 27, calc 113169 7selected clock c020e26c (pclk) quot 27, calc 113169 7selected clock c020e26c (pclk) quot 27, calc 113169 4printk_test: module license 'unspecified' taints kernel. 0Hello0 1Hello1 2Hello2 3Hello3 4Hello4 5Hello5 6Hello6 7Hello7 7Hello7 7Hello7-1 7No external FW image 7No external FW image 6success! 转载:请注明,作者,下家山   请尊重原创! @uow.edu.au@crynwr.com          
  • 热度 25
    2012-4-4 12:09
    2371 次阅读|
    0 个评论
    作者:下家山(转载,请注明)   七:如何查看console_loglevel当前等级          命令:          # cat /proc/sys/kernel/printk 7       4       1       7 这四个数字分别对应:console_loglevel  default_message_loglevel  minimum_console_loglevel  default_console_loglevel 八:如何改变console_loglevel当前等级  九:结束   转载:请注明,作者,下家山   请尊重原创!