接续《debian内核代码执行流程(二)》未完成部分
下面这行输出信息是启动udevd进程产生的输出信息:
[ 3.306217] udevd[]: starting version
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 .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
下面信息是由setup_msi_irq输出的(但不知道是从哪个函数调用过去的):
[ 2.854395] pcieport 0000:00:1c.0: irq 40 for MSI/MSI-X
rtl8169_init_one中继续输出下面信息:
[ 3.346995] r8169 ::00.0: eth0: RTL8102e at 0xf821a000, :e0:4c:::, XID 14c00000 IRQ
接着加载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 ::1d.: setting latency timer to
usb_hcd_pci_probe接着调用usb_add_hcd,输出下面信息:
[ 3.385798] ehci_hcd ::1d.: EHCI Host Controller
usb_add_hcd调用usb_register_bus,输出下面信息:
[ 3.385826] ehci_hcd ::1d.: new USB bus registered, assigned bus number
usb_add_hcd调用hcd->driver->reset,即ehci_pci_hc_driver->reset,也即ehci_pci_setup,echi_pci_setup中输出下面信息:
[ 3.385849] ehci_hcd ::1d.: using broken periodic workaround
[ 3.385859] ehci_hcd ::1d.: debug port
ehci_pci_setup调用echi_pci_reinit,ehci_pci_reinit调用pci_set_mwi,pci_set_mwi调用pci_set_cacheline_size, 输出下面信息:
[ 3.389747] ehci_hcd ::1d.: cache line size of is not supported
usb_add_hcd调用usb_hcd_request_irqs,输出下面信息:
[ 3.408370] ehci_hcd ::1d.: irq , 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 is a post-
上面ehci-hcd模块中usb_add_hcd调用hcd->driver->start,即ehci_pci_hc_driver->start,即ehci_run函数,输出下面信息:
[ 3.424024] ehci_hcd ::1d.: 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=
[ 3.424095] usb usb1: New USB device strings: Mfr=, Product=, SerialNumber=
[ 3.424100] usb usb1: Product: EHCI Host Controller
[ 3.424104] usb usb1: Manufacturer: Linux 3.2. ehci_hcd
[ 3.424107] usb usb1: SerialNumber: ::1d.
调用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 ::1d.: setting latency timer to
[ 3.425267] uhci_hcd ::1d.: UHCI Host Controller
[ 3.425283] uhci_hcd ::1d.: new USB bus registered, assigned bus number
[ 3.425315] uhci_hcd ::1d.: irq , io base 0x0000fe00
[ 3.425351] usb usb2: New USB device found, idVendor=1d6b, idProduct=
[ 3.425353] usb usb2: New USB device strings: Mfr=, Product=, SerialNumber=
[ 3.425355] usb usb2: Product: UHCI Host Controller
[ 3.425357] usb usb2: Manufacturer: Linux 3.2. uhci_hcd
[ 3.425359] usb usb2: SerialNumber: ::1d.
[ 3.425647] hub -:1.0: USB hub found
[ 3.425653] hub -:1.0: ports detected
[ 3.425743] uhci_hcd ::1d.: setting latency timer to
[ 3.425746] uhci_hcd ::1d.: UHCI Host Controller
[ 3.425753] uhci_hcd ::1d.: new USB bus registered, assigned bus number
[ 3.425790] uhci_hcd ::1d.: irq , io base 0x0000fd00
[ 3.425824] usb usb3: New USB device found, idVendor=1d6b, idProduct=
[ 3.425826] usb usb3: New USB device strings: Mfr=, Product=, SerialNumber=
[ 3.425828] usb usb3: Product: UHCI Host Controller
[ 3.425830] usb usb3: Manufacturer: Linux 3.2. uhci_hcd
[ 3.425832] usb usb3: SerialNumber: ::1d.
[ 3.425938] hub -:1.0: USB hub found
[ 3.425942] hub -:1.0: ports detected
[ 3.426010] uhci_hcd ::1d.: setting latency timer to
[ 3.426014] uhci_hcd ::1d.: UHCI Host Controller
[ 3.426020] uhci_hcd ::1d.: new USB bus registered, assigned bus number
[ 3.426051] uhci_hcd ::1d.: irq , io base 0x0000fc00
[ 3.426082] usb usb4: New USB device found, idVendor=1d6b, idProduct=
[ 3.426085] usb usb4: New USB device strings: Mfr=, Product=, SerialNumber=
[ 3.426087] usb usb4: Product: UHCI Host Controller
[ 3.426089] usb usb4: Manufacturer: Linux 3.2. uhci_hcd
[ 3.426091] usb usb4: SerialNumber: ::1d.
[ 3.426198] hub -:1.0: USB hub found
[ 3.426202] hub -:1.0: ports detected
[ 3.426273] uhci_hcd ::1d.: setting latency timer to
[ 3.426276] uhci_hcd ::1d.: UHCI Host Controller
[ 3.426283] uhci_hcd ::1d.: new USB bus registered, assigned bus number
[ 3.426314] uhci_hcd ::1d.: irq , io base 0x0000fb00
[ 3.426344] usb usb5: New USB device found, idVendor=1d6b, idProduct=
[ 3.426347] usb usb5: New USB device strings: Mfr=, Product=, SerialNumber=
[ 3.426349] usb usb5: Product: UHCI Host Controller
[ 3.426351] usb usb5: Manufacturer: Linux 3.2. uhci_hcd
[ 3.426353] usb usb5: SerialNumber: ::1d.
[ 3.426454] hub -:1.0: USB hub found
[ 3.426457] hub -:1.0: ports detected
因为当前系统上有多个uhci hcd controller,对每个uhci hcd controller都有相应的输出信息。
在当前系统上可以列出所有的hcd controller信息:
$ tree /sys/bus/usb/devices
/sys/bus/usb/devices
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb1/-:1.0
├── - -> ../../../devices/pci0000:/::1d./usb1/-
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb1/-/-:1.0
├── -1.2 -> ../../../devices/pci0000:/::1d./usb1/-/-1.2
├── -1.2:1.0 -> ../../../devices/pci0000:/::1d./usb1/-/-1.2/-1.2:1.0
├── -1.2:1.1 -> ../../../devices/pci0000:/::1d./usb1/-/-1.2/-1.2:1.1
├── - -> ../../../devices/pci0000:/::1d./usb1/-
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb1/-/-:1.0
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb2/-:1.0
├── - -> ../../../devices/pci0000:/::1d./usb2/-
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb2/-/-:1.0
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb3/-:1.0
├── - -> ../../../devices/pci0000:/::1d./usb3/-
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb3/-/-:1.0
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb4/-:1.0
├── -:1.0 -> ../../../devices/pci0000:/::1d./usb5/-:1.0
├── usb1 -> ../../../devices/pci0000:/::1d./usb1
├── usb2 -> ../../../devices/pci0000:/::1d./usb2
├── usb3 -> ../../../devices/pci0000:/::1d./usb3
├── usb4 -> ../../../devices/pci0000:/::1d./usb4
└── usb5 -> ../../../devices/pci0000:/::1d./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 ::1f.: version 2.13
piix_init_one调用pci_set_master,pci_set_master调用pcibios_set_master,pcibios_set_master调用, 输出下面信息:
[ 3.426578] ata_piix ::1f.: setting latency timer to
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/ cmd 0x1f0 ctl 0x3f6 bmdma 0xfa00 irq
[ 3.427939] ata2: PATA max UDMA/ cmd 0x170 ctl 0x376 bmdma 0xfa08 irq
接着对于新的IDE controller,调用piix_pci_driver.probe,即piix_init_one。
piinx_init_one调用piix_init_sata_map,输出下面信息:
[ 3.427974] ata_piix ::1f.: 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
下面一行输出是ata2的错误信息(懒得分析是从哪儿产生的):
[ 3.428496] ata2: port disabled--ignoring
与前面类似,还有下面的输出:
[ 3.428513] scsi2 : ata_piix
[ 3.428907] scsi3 : ata_piix
[ 3.429356] ata3: SATA max UDMA/ cmd 0xf900 ctl 0xf800 bmdma 0xf500 irq
[ 3.429359] ata4: SATA max UDMA/ cmd 0xf700 ctl 0xf600 bmdma 0xf508 irq
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.: ATA-: ST3250318AS, CC38, max UDMA/
[ 3.600358] ata3.: sectors, multi : LBA48 NCQ (depth /)
ata_bus_probe调用ata_set_mode,ata_set_mode 调用ata_do_set_mode,ata_do_set_mode调用ata_dev_set_mode,输出下面信息:
[ 3.616337] ata3.: configured for UDMA/
前面提到过,在usbcore刚挂载时,创建了一个khubd内核线程,用于检查hub的状态并执行相应的功能,线程执行函数是hub_thread.
hub_thread中调用hub_events, hub_events调用hub_port_init,输出下面信息:
[ 3.736020] usb -: new high-speed USB device number using ehci_hcd
对ata1仍然也有调用async_schedule,虽然它先被调用,但是却执行比ata3还晚,输出下面信息:
[ 3.760302] ata1.: ATAPI: ATAPI iHDP118 , GL05, max UDMA/
[ 3.776191] ata1.: configured for UDMA/
下面两行不知道是哪个函数调用scsi_add_lun产生的:
[ 3.778163] scsi :::: CD-ROM ATAPI iHDP118 GL05 PQ: ANSI:
[ 3.778453] scsi :::: Direct-Access ATA ST3250318AS CC38 PQ: ANSI:
此时检测到硬盘,会调用sd_probe.sd_probe调用async_schedule异步调用sd_probe_async,sd_probe_async调用sd_revalidate_disk,
sd_revalidate_disk调用sd_read_capacity,输出下面信息:
[ 3.783064] sd :::: [sda] -byte logical blocks: ( GB/ GiB)
sd_revalidate_disk调用sd_read_write_protect_flag,输出下面信息:
[ 3.783126] sd :::: [sda] Write Protect is off
[ 3.783128] sd 2:0:0:0: [sda] Mode Sense: 00 3a 00
sd_revalidate_disk调用sd_read_cache_type,输出下面信息:
[ 3.783148] sd :::: [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 :::: 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 :::: [sda] Attached SCSI disk
下面两行信息是从sg_add函数产生的(但不知道是从哪个地方调用过去的):
[ 3.845469] sr :::: Attached scsi generic sg0 type
[ 3.845545] sd :::: Attached scsi generic sg1 type
下面的输出信息和前面类似(khubd检测并输出信息):
[ 3.868682] usb -: New USB device found, idVendor=1a40, idProduct=
[ 3.868685] usb -: New USB device strings: Mfr=, Product=, SerialNumber=
[ 3.868687] usb -: Product: USB 2.0 Hub
[ 3.868967] hub -:1.0: USB hub found
[ 3.869062] hub -:1.0: ports detected
[ 4.092020] usb -: new high-speed USB device number using ehci_hcd
[ 4.224322] usb -: New USB device found, idVendor=0b1e, idProduct=
[ 4.224328] usb -: New USB device strings: Mfr=, Product=, SerialNumber=
[ 4.464020] usb -: new low-speed USB device number using uhci_hcd
接着三行信息是电源管理模块相关:
[ 4.633397] PM: Starting manual resume from disk
[ 4.633400] PM: Hibernation image partition : present
[ 4.633401] PM: Looking for hibernation image.
检测到罗技光电鼠标:
[ 4.639360] usb -: New USB device found, idVendor=046d, idProduct=c05a
[ 4.639365] usb -: New USB device strings: Mfr=, Product=, SerialNumber=
[ 4.639370] usb -: Product: USB Optical Mouse
[ 4.639373] usb -: Manufacturer: Logitech
后面还有一些输出信息,以后有时间在分析具体模块的驱动时再来详细说明。