debian内核代码执行流程(三)
接续《debian内核代码执行流程(二)》未完成部分
下面这行输出信息是启动udevd进程产生的输出信息:
[ 3.306217] udevd[49]: starting version 175
175是udevd的版本号。
根据《essential linux device drivers》中关于udev的说明(英文书140页),设备可以分成热插拔和冷插拔。
热插拔是在已经运行的系统中连接的设备,冷插拔是系统启动前插入的设备。
当系统检测到热插拔设备时,系统使用netlink socket向用户空间发送uevents。
在用户端,udev管理设备的创建和删除、接收uevent,管理热插拔设备。udev也可以处理冷插拔。因为udev是用户程序,只能在内核驱动后才开始执行,需要特殊的机制来模拟热插拔时间。
在启动时,内核在sysfs下为所有设备创建名为uevent的文件,然后向这些文件发送冷插拔时间。
当udev启动后,它会从sysfs中读取uevent,为每个冷插拔设备产生热插拔时间。
此时加载r8169.ko模块,执行r8169.ko模块的初始化函数,即rtl8169_init_module(drivers/net/ethernet/realtek/r8169.c).
之后调用rtl8169_pci_driver.probe函数,即rtl8169_init_one,rtl8169_init_one中输出下面信息:
[ 3.346446] r8169 Gigabit Ethernet driver 2.3LK-NAPI loaded
rtl8169_init_one中调用pci_set_master,pci_set_master调用pcibios_set_master,输出下面信息:
[ 2.854355] pcieport 0000:00:1c.0: setting latency timer to 64
下面信息是由setup_msi_irq输出的(但不知道是从哪个函数调用过去的):
[ 2.854395] pcieport 0000:00:1c.0: irq 40 for MSI/MSI-X
rtl8169_init_one中继续输出下面信息:
[ 3.346995] r8169 0000:04:00.0: eth0: RTL8102e at 0xf821a000, 00:e0:4c:26:51:75, XID 14c00000 IRQ 44
接着加载scsi模块,执行init_scsi,输出下面信息:
[ 3.372657] SCSI subsystem initialized
接着加载usbcore模块,执行usb_init(drivers/usb/core/usb.c),usb_init调用usb_register(&usbfs_driver),输出下面信息:
[ 3.384633] usbcore: registered new interface driver usbfs
usb_init调用usb_hub_init,usb_hub_init调用usb_register(&hub_driver),输出下面信息:
[ 3.384665] usbcore: registered new interface driver hub
usb_hub_init中还创建了khubd线程,线程执行函数是hub_thread,用于监控hub状态变更。
usb_init中接着调用usb_register_device_driver(&usb_generic_driver,THIS_MODULE),输出下面信息:
[ 3.384694] usbcore: registered new device driver usb
接着加载ehci-hcd模块,执行ehci_hcd_init(drivers/usb/host/ehci-hcd.c),输出下面信息:
[ 3.385735] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci_hcd_init调用pci_register_driver(&PCI_DRIVER),而PCI_DRIVER即ehci_pci_driver.
之后会调用ehci_pci_driver.probe,即usb_hcd_pci_probe函数。
usb_hcd_pci_probe调用pci_set_master, pci_set_master调用pcibios_set_master,输出下面信息:
[ 3.385794] ehci_hcd 0000:00:1d.7: setting latency timer to 64
usb_hcd_pci_probe接着调用usb_add_hcd,输出下面信息:
[ 3.385798] ehci_hcd 0000:00:1d.7: EHCI Host Controller
usb_add_hcd调用usb_register_bus,输出下面信息:
[ 3.385826] ehci_hcd 0000:00:1d.7: new USB bus registered, assigned bus number 1
usb_add_hcd调用hcd->driver->reset,即ehci_pci_hc_driver->reset,也即ehci_pci_setup,echi_pci_setup中输出下面信息:
[ 3.385849] ehci_hcd 0000:00:1d.7: using broken periodic workaround [ 3.385859] ehci_hcd 0000:00:1d.7: debug port 1
ehci_pci_setup调用echi_pci_reinit,ehci_pci_reinit调用pci_set_mwi,pci_set_mwi调用pci_set_cacheline_size, 输出下面信息:
[ 3.389747] ehci_hcd 0000:00:1d.7: cache line size of 32 is not supported
usb_add_hcd调用usb_hcd_request_irqs,输出下面信息:
[ 3.408370] ehci_hcd 0000:00:1d.7: irq 23, io mem 0xfdfff000
接着加载libata.ko模块,调用ata_init,输出下面信息:
[ 3.412309] libata version 3.00 loaded.
接着加载uhci-hcd.ko模块,调用uhci_hcd_init,输出下面信息:
[ 3.412721] uhci_hcd: USB Universal Host Controller Interface driver
接着加载floppy.ko模块,调用floppy_module_init, floppy_module_init调用floppy_init,floppy_init调用get_fdc_version,输出下面信息:
[ 3.423746] FDC 0 is a post-1991 82077
上面ehci-hcd模块中usb_add_hcd调用hcd->driver->start,即ehci_pci_hc_driver->start,即ehci_run函数,输出下面信息:
[ 3.424024] ehci_hcd 0000:00:1d.7: USB 2.0 started, EHCI 1.00
由此可见,模块加载可能是并发执行的。
usb_add_hcd中接着调用register_root_hub,register_root_hub调用usb_new_device,usb_new_device调用annouce_device,输出下面信息:
[ 3.424090] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002 [ 3.424095] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 3.424100] usb usb1: Product: EHCI Host Controller [ 3.424104] usb usb1: Manufacturer: Linux 3.2.57 ehci_hcd [ 3.424107] usb usb1: SerialNumber: 0000:00:1d.7
调用hub_probe(不知道从哪儿开始调用的),输出下面信息:
[ 3.424288] hub 1-0:1.0: USB hub found
hub_probe调用hub_configure,输出下面信息:
[ 3.424294] hub 1-0:1.0: 8 ports detected
上面uhci_hcd_init调用pci_register_driver(&PCI_DRIVER),而PCI_DRIVER即uhci_pci_driver,
之后调用uhci_pci_driver.probe,即usb_hcd_pci_probe函数,跟前面ehci的例子类似输出下面信息:
[ 3.425261] uhci_hcd 0000:00:1d.0: setting latency timer to 64 [ 3.425267] uhci_hcd 0000:00:1d.0: UHCI Host Controller [ 3.425283] uhci_hcd 0000:00:1d.0: new USB bus registered, assigned bus number 2 [ 3.425315] uhci_hcd 0000:00:1d.0: irq 23, io base 0x0000fe00 [ 3.425351] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001 [ 3.425353] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 3.425355] usb usb2: Product: UHCI Host Controller [ 3.425357] usb usb2: Manufacturer: Linux 3.2.57 uhci_hcd [ 3.425359] usb usb2: SerialNumber: 0000:00:1d.0 [ 3.425647] hub 2-0:1.0: USB hub found [ 3.425653] hub 2-0:1.0: 2 ports detected [ 3.425743] uhci_hcd 0000:00:1d.1: setting latency timer to 64 [ 3.425746] uhci_hcd 0000:00:1d.1: UHCI Host Controller [ 3.425753] uhci_hcd 0000:00:1d.1: new USB bus registered, assigned bus number 3 [ 3.425790] uhci_hcd 0000:00:1d.1: irq 19, io base 0x0000fd00 [ 3.425824] usb usb3: New USB device found, idVendor=1d6b, idProduct=0001 [ 3.425826] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 3.425828] usb usb3: Product: UHCI Host Controller [ 3.425830] usb usb3: Manufacturer: Linux 3.2.57 uhci_hcd [ 3.425832] usb usb3: SerialNumber: 0000:00:1d.1 [ 3.425938] hub 3-0:1.0: USB hub found [ 3.425942] hub 3-0:1.0: 2 ports detected [ 3.426010] uhci_hcd 0000:00:1d.2: setting latency timer to 64 [ 3.426014] uhci_hcd 0000:00:1d.2: UHCI Host Controller [ 3.426020] uhci_hcd 0000:00:1d.2: new USB bus registered, assigned bus number 4 [ 3.426051] uhci_hcd 0000:00:1d.2: irq 18, io base 0x0000fc00 [ 3.426082] usb usb4: New USB device found, idVendor=1d6b, idProduct=0001 [ 3.426085] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 3.426087] usb usb4: Product: UHCI Host Controller [ 3.426089] usb usb4: Manufacturer: Linux 3.2.57 uhci_hcd [ 3.426091] usb usb4: SerialNumber: 0000:00:1d.2 [ 3.426198] hub 4-0:1.0: USB hub found [ 3.426202] hub 4-0:1.0: 2 ports detected [ 3.426273] uhci_hcd 0000:00:1d.3: setting latency timer to 64 [ 3.426276] uhci_hcd 0000:00:1d.3: UHCI Host Controller [ 3.426283] uhci_hcd 0000:00:1d.3: new USB bus registered, assigned bus number 5 [ 3.426314] uhci_hcd 0000:00:1d.3: irq 16, io base 0x0000fb00 [ 3.426344] usb usb5: New USB device found, idVendor=1d6b, idProduct=0001 [ 3.426347] usb usb5: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 3.426349] usb usb5: Product: UHCI Host Controller [ 3.426351] usb usb5: Manufacturer: Linux 3.2.57 uhci_hcd [ 3.426353] usb usb5: SerialNumber: 0000:00:1d.3 [ 3.426454] hub 5-0:1.0: USB hub found [ 3.426457] hub 5-0:1.0: 2 ports detected
因为当前系统上有多个uhci hcd controller,对每个uhci hcd controller都有相应的输出信息。
在当前系统上可以列出所有的hcd controller信息:
$ tree /sys/bus/usb/devices /sys/bus/usb/devices ├── 1-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-0:1.0 ├── 1-1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1 ├── 1-1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0 ├── 1-1.2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1.2 ├── 1-1.2:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1.2/1-1.2:1.0 ├── 1-1.2:1.1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1.2/1-1.2:1.1 ├── 1-4 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-4 ├── 1-4:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4:1.0 ├── 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0 ├── 2-2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-2 ├── 2-2:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0 ├── 3-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3/3-0:1.0 ├── 3-1 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3/3-1 ├── 3-1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0 ├── 4-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.2/usb4/4-0:1.0 ├── 5-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.3/usb5/5-0:1.0 ├── usb1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1 ├── usb2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2 ├── usb3 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3 ├── usb4 -> ../../../devices/pci0000:00/0000:00:1d.2/usb4 └── usb5 -> ../../../devices/pci0000:00/0000:00:1d.3/usb5
加载ata-piix.ko模块,调用piix_init,piix_init调用pci_register_driver(&piix_pci_driver),之后调用piix_pci_driver.probe,即piix_init_one。
输出下面信息:
[ 3.426522] ata_piix 0000:00:1f.1: version 2.13
piix_init_one调用pci_set_master,pci_set_master调用pcibios_set_master,pcibios_set_master调用, 输出下面信息:
[ 3.426578] ata_piix 0000:00:1f.1: setting latency timer to 64
piix_init_one调用ata_pci_sff_activate_host,ata_pci_sff_activate_host调用ata_host_register,ata_host_register调用ata_scsi_add_hosts,
ata_scsi_add_hosts对每个port调用scsi_add_host,scsi_add_host调用scsi_add_host_with_dma,输出下面信息(因为多次调用,所以多行输出):
[ 3.427370] scsi0 : ata_piix [ 3.427473] scsi1 : ata_piix
ata_host_register中对每个port输出信息,得到如下内容:
[ 3.427936] ata1: PATA max UDMA/100 cmd 0x1f0 ctl 0x3f6 bmdma 0xfa00 irq 14 [ 3.427939] ata2: PATA max UDMA/100 cmd 0x170 ctl 0x376 bmdma 0xfa08 irq 15
接着对于新的IDE controller,调用piix_pci_driver.probe,即piix_init_one。
piinx_init_one调用piix_init_sata_map,输出下面信息:
[ 3.427974] ata_piix 0000:00:1f.2: MAP [ P0 P2 P1 P3 ]
piix_init_one调用pci_set_master,pci_set_master调用pcibios_set_master,pcibios_set_master调用, 输出下面信息:
[ 3.426578] ata_piix 0000:00:1f.1: setting latency timer to 64
下面一行输出是ata2的错误信息(懒得分析是从哪儿产生的):
[ 3.428496] ata2: port disabled--ignoring
与前面类似,还有下面的输出:
[ 3.428513] scsi2 : ata_piix [ 3.428907] scsi3 : ata_piix [ 3.429356] ata3: SATA max UDMA/133 cmd 0xf900 ctl 0xf800 bmdma 0xf500 irq 19 [ 3.429359] ata4: SATA max UDMA/133 cmd 0xf700 ctl 0xf600 bmdma 0xf508 irq 19
ata_host_register对每个port调用async_schedule异步执行async_port_probe.
async_port_probe调用ata_port_probe,ata_port_probe调用ata_bus_probe,ata_bus_probe对总线上设备调用ata_dev_configure.
[ 3.600351] ata3.00: ATA-8: ST3250318AS, CC38, max UDMA/133 [ 3.600358] ata3.00: 488397168 sectors, multi 16: LBA48 NCQ (depth 0/32)
ata_bus_probe调用ata_set_mode,ata_set_mode 调用ata_do_set_mode,ata_do_set_mode调用ata_dev_set_mode,输出下面信息:
[ 3.616337] ata3.00: configured for UDMA/133
前面提到过,在usbcore刚挂载时,创建了一个khubd内核线程,用于检查hub的状态并执行相应的功能,线程执行函数是hub_thread.
hub_thread中调用hub_events, hub_events调用hub_port_init,输出下面信息:
[ 3.736020] usb 1-1: new high-speed USB device number 2 using ehci_hcd
对ata1仍然也有调用async_schedule,虽然它先被调用,但是却执行比ata3还晚,输出下面信息:
[ 3.760302] ata1.01: ATAPI: ATAPI iHDP118 4, GL05, max UDMA/33 [ 3.776191] ata1.01: configured for UDMA/33
下面两行不知道是哪个函数调用scsi_add_lun产生的:
[ 3.778163] scsi 0:0:1:0: CD-ROM ATAPI iHDP118 4 GL05 PQ: 0 ANSI: 5 [ 3.778453] scsi 2:0:0:0: Direct-Access ATA ST3250318AS CC38 PQ: 0 ANSI: 5
此时检测到硬盘,会调用sd_probe.sd_probe调用async_schedule异步调用sd_probe_async,sd_probe_async调用sd_revalidate_disk,
sd_revalidate_disk调用sd_read_capacity,输出下面信息:
[ 3.783064] sd 2:0:0:0: [sda] 488397168 512-byte logical blocks: (250 GB/232 GiB)
sd_revalidate_disk调用sd_read_write_protect_flag,输出下面信息:
[ 3.783126] sd 2:0:0:0: [sda] Write Protect is off
[ 3.783128] sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00
sd_revalidate_disk调用sd_read_cache_type,输出下面信息:
[ 3.783148] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
此时检测到光驱,调用sr_probe,sr_probe调用get_capabilites,输出下面信息:
[ 3.785910] sr0: scsi3-mmc drive: 48x/48x cd/rw xa/form2 cdda tray
sr_probe调用register_cdrom,输出下面信息:
[ 3.785915] cdrom: Uniform CD-ROM driver Revision: 3.20
sr_probe中输出下面信息:
[ 3.786106] sr 0:0:1:0: Attached scsi CD-ROM sr0
下面两行输出不知道是从哪个地方调用过去的。
tsc_refine_calibration_work中产生下面输出:
[ 3.836020] Refined TSC clocksource calibration: 2510.403 MHz.
clocksource_select中产生下面输出:
[ 3.836028] Switching to clocksource tsc
下面一行输出信息不知道是如何产生的(应该是在sd_probe_async中产生的?):
[ 3.842587] sda: sda1 sda2 < sda5 sda6 sda7 sda8 > sda3
sd_probe_async中输出下面信息:
[ 3.843109] sd 2:0:0:0: [sda] Attached SCSI disk
下面两行信息是从sg_add函数产生的(但不知道是从哪个地方调用过去的):
[ 3.845469] sr 0:0:1:0: Attached scsi generic sg0 type 5 [ 3.845545] sd 2:0:0:0: Attached scsi generic sg1 type 0
下面的输出信息和前面类似(khubd检测并输出信息):
[ 3.868682] usb 1-1: New USB device found, idVendor=1a40, idProduct=0101 [ 3.868685] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0 [ 3.868687] usb 1-1: Product: USB 2.0 Hub [ 3.868967] hub 1-1:1.0: USB hub found [ 3.869062] hub 1-1:1.0: 4 ports detected [ 4.092020] usb 1-4: new high-speed USB device number 5 using ehci_hcd [ 4.224322] usb 1-4: New USB device found, idVendor=0b1e, idProduct=0006 [ 4.224328] usb 1-4: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 4.464020] usb 2-2: new low-speed USB device number 2 using uhci_hcd
接着三行信息是电源管理模块相关:
[ 4.633397] PM: Starting manual resume from disk [ 4.633400] PM: Hibernation image partition 8:8 present [ 4.633401] PM: Looking for hibernation image.
检测到罗技光电鼠标:
[ 4.639360] usb 2-2: New USB device found, idVendor=046d, idProduct=c05a [ 4.639365] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 4.639370] usb 2-2: Product: USB Optical Mouse [ 4.639373] usb 2-2: Manufacturer: Logitech
后面还有一些输出信息,以后有时间在分析具体模块的驱动时再来详细说明。
posted on 2014-06-27 17:05 qiaoqiao2003 阅读(749) 评论(0) 编辑 收藏 举报