现在的位置: 首页 > 综合 > 正文

Linux的oops内核调试信息 && Linux的JCPU与PCPU

2013年12月10日 ⁄ 综合 ⁄ 共 1633字 ⁄ 字号 评论关闭

      Oops可以看成是内核级的Segmentation Fault。应用程序如果进行了非法内存访问或执行了非法指令,会得到Segfault信号,一般的行为是coredump,应用程序也可以自己截获Segfault信号,自行处理。如果内核自己犯了这样的错误,则会打出Oops信息。处理器使用的所有地址几乎都是通过一个复杂的页表结构对物理地址映射而得到的虚拟地址(除了内存管理子系统自己所使用的物理地址)。当一个非法的指针被废弃时,内存分页机制将不能为指针映射一个物理地址,处理器就会向操作系统发出一个页故障信号。如果地址不合法,那么内核将不能在该地址“布页”;这时如果处理器处于超级用户模式,内核就会生成一条oops消息。

      解释一下它所产生的过程:
1,do_page_fault()(arch/i386/mm/fault.c)。如果是内核进行了非法访问,do_page_fault()会先打出EIP, PDE等信息,例如:
Unable to handle kernel paging request at virtual address f899b670
printing eip:
c01de48c
*pde = 00737067
然后调用 die("Oops", regs, error_code);这之后,如果系统还活着(至少要满足两个条件:1. 在进程上下文 2. 没有设置panic_on_oops),会杀死当前进程,导致死机。
2,die()(arch/i386/kernel/traps.c)。die() 首先打出一行:
Oops: 0002 [#1]
其中0002代表错误码,#1代表Oops发生次数。error_code:
 *      bit 0 == 0 means no page found, 1 means protection fault
 *      bit 1 == 0 means read, 1 means write
 *      bit 2 == 0 means kernel, 1 means user-mode
然后,调用 show_registers(regs) 输出寄存器、当前进程、堆栈、指令代码等信息,以供判断。

3,利用dmesg命令可以查看完整的系统内核信息,当然前提这是用Printk输出的。

=================================================================================================================

      使用w命令查看用户登录信息时,会显示到PCPU与JCPU,这个概念是什么意思呢?

JCPU -   the CPU time used by all processes and their children on that terminal (in minutes:seconds)

PCPU - the CPU time used by the currently active processes (in minutes:seconds)

使用:man w,得到的解释是

The   JCPU   time   is the time used by all processes attached to the tty.  It does not include past background jobs, but does include currently running background jobs.

The   PCPU   time   is   the time used by the current process.

中文可以这样理解:JCPU指的是与该tty终端连接的所由进程占用的时间,不包括过去的后台作业时间;PCPU 指的是当前进程(即w项中显示的)所占用的时间。

参考原文:http://www.ixpub.net/thread-759651-1-1.html
参考原文:http://hi.baidu.com/xysoul/blog/item/d85ebff2c2f1bc1bb17ec562.html

 

抱歉!评论已关闭.