为什么内核启动太晚了?

时间:2014-06-16 06:22:30

标签: linux-kernel linux-device-driver embedded-linux bootloader u-boot

我有zynq-microzed board,我的日志消息正在跟踪......

[Mon Jun 09 19:28:38.231 2014] SF: Detected S25FL129P_64K/S25FL128S_64K with page size 64 KiB, total 16 MiB
[Mon Jun 09 19:28:38.446 2014] SF: 1245184 bytes @ 0x520000 Read: OK
[Mon Jun 09 19:28:38.446 2014] ## Loading kernel from FIT Image at 01000000 ...
[Mon Jun 09 19:28:38.446 2014]    Using 'conf@1' configuration
[Mon Jun 09 19:28:38.446 2014]    Trying 'kernel@1' kernel subimage
[Mon Jun 09 19:28:38.446 2014]      Description:  PetaLinux Kernel
[Mon Jun 09 19:28:38.446 2014]      Type:         Kernel Image
[Mon Jun 09 19:28:38.446 2014]      Compression:  gzip compressed
[Mon Jun 09 19:28:38.446 2014]      Data Start:   0x010000f0
[Mon Jun 09 19:28:38.446 2014]      Data Size:    1215908 Bytes = 1.2 MiB
[Mon Jun 09 19:28:38.446 2014]      Architecture: ARM
[Mon Jun 09 19:28:38.446 2014]      OS:           Linux
[Mon Jun 09 19:28:38.446 2014]      Load Address: 0x00008000
[Mon Jun 09 19:28:38.446 2014]      Entry Point:  0x00008000
[Mon Jun 09 19:28:38.446 2014]    Verifying Hash Integrity ... OK
[Mon Jun 09 19:28:38.446 2014] ## Loading fdt from FIT Image at 01000000 ...
[Mon Jun 09 19:28:38.490 2014]    Using 'conf@1' configuration
[Mon Jun 09 19:28:38.490 2014]    Trying 'fdt@1' fdt subimage
[Mon Jun 09 19:28:38.490 2014]      Description:  Flattened Device Tree blob
[Mon Jun 09 19:28:38.490 2014]      Type:         Flat Device Tree
[Mon Jun 09 19:28:38.490 2014]      Compression:  uncompressed
[Mon Jun 09 19:28:38.490 2014]      Data Start:   0x01128f44
[Mon Jun 09 19:28:38.490 2014]      Data Size:    9766 Bytes = 9.5 KiB
[Mon Jun 09 19:28:38.490 2014]      Architecture: ARM
[Mon Jun 09 19:28:38.490 2014]      Hash algo:    crc32
[Mon Jun 09 19:28:38.490 2014]      Hash value:   fad9c7a8
[Mon Jun 09 19:28:38.490 2014]      Hash algo:    sha1
[Mon Jun 09 19:28:38.490 2014]      Hash value:   4ffcd311a61838768c94b2cb0c2e3d5312861fb4
[Mon Jun 09 19:28:38.490 2014]    Verifying Hash Integrity ... crc32+ sha1+ OK
[Mon Jun 09 19:28:38.490 2014]    Booting using the fdt blob at 0x1128f44
[Mon Jun 09 19:28:38.492 2014]    Uncompressing Kernel Image ... OK
[Mon Jun 09 19:28:38.595 2014]    Loading Device Tree to 07ffa000, end 07fff625 ... OK
[Mon Jun 09 19:28:38.595 2014] 
[Mon Jun 09 19:28:38.595 2014] Starting kernel ...
[Mon Jun 09 19:28:38.595 2014] 
[Mon Jun 09 19:28:39.137 2014] Booting Linux on physical CPU 0x0
[Mon Jun 09 19:28:39.137 2014] Linux version 3.8.11 (root@xilinx) (gcc version 4.7.3 (Sourcery CodeBench Lite 2013.05-40) ) #33 SMP PREEMPT Mon Jun 9 19:23:59 IST 2014
[Mon Jun 09 19:28:39.137 2014] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=18c53c7d
[Mon Jun 09 19:28:39.137 2014] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[Mon Jun 09 19:28:39.137 2014] Machine: Xilinx Zynq Platform, model: suheb_24
[Mon Jun 09 19:28:39.137 2014] Memory policy: ECC disabled, Data cache writealloc
[Mon Jun 09 19:28:39.137 2014] PERCPU: Embedded 7 pages/cpu @c0aa3000 s5568 r8192 d14912 u32768
[Mon Jun 09 19:28:39.137 2014] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 260096
[Mon Jun 09 19:28:39.181 2014] Kernel command line: console=ttyPS0,115200
[Mon Jun 09 19:28:39.181 2014] PID hash table entries: 4096 (order: 2, 16384 bytes)
[Mon Jun 09 19:28:39.181 2014] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[Mon Jun 09 19:28:39.181 2014] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[Mon Jun 09 19:28:39.181 2014] __ex_table already sorted, skipping sort
[Mon Jun 09 19:28:39.181 2014] Memory: 1024MB = 1024MB total
[Mon Jun 09 19:28:39.181 2014] Memory: 1036800k/1036800k available, 11776k reserved, 270336K highmem
[Mon Jun 09 19:28:39.181 2014] Virtual kernel memory layout:
[Mon Jun 09 19:28:39.181 2014]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[Mon Jun 09 19:28:39.181 2014]     fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
[Mon Jun 09 19:28:39.226 2014]     vmalloc : 0xf0000000 - 0xff000000   ( 240 MB)
[Mon Jun 09 19:28:39.226 2014]     lowmem  : 0xc0000000 - 0xef800000   ( 760 MB)
[Mon Jun 09 19:28:39.226 2014]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[Mon Jun 09 19:28:39.226 2014]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[Mon Jun 09 19:28:39.226 2014]       .text : 0xc0008000 - 0xc01b8c4c   (1732 kB)
[Mon Jun 09 19:28:39.226 2014]       .init : 0xc01b9000 - 0xc02785c0   ( 766 kB)
[Mon Jun 09 19:28:39.226 2014]       .data : 0xc027a000 - 0xc0289980   (  63 kB)
[Mon Jun 09 19:28:39.226 2014]        .bss : 0xc0289980 - 0xc0298798   (  60 kB)
[Mon Jun 09 19:28:39.226 2014] Preemptible hierarchical RCU implementation.
[Mon Jun 09 19:28:39.226 2014]  RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=2.
[Mon Jun 09 19:28:39.267 2014] NR_IRQS:16 nr_irqs:16 16
[Mon Jun 09 19:28:39.267 2014] xslcr mapped to f0002000
[Mon Jun 09 19:28:39.267 2014] Zynq clock init
[Mon Jun 09 19:28:39.267 2014] sched_clock: 16 bits at 54kHz, resolution 18432ns, wraps every 1207ms
[Mon Jun 09 19:28:39.267 2014] ps7-ttc #0 at f0004000, irq=43

......之间需要0.542秒

[Mon Jun 09 19:28:38.595 2014] Starting kernel ...
[Mon Jun 09 19:28:38.595 2014] 
[Mon Jun 09 19:28:39.137 2014] Booting Linux on physical CPU 0x0

现在我想减少这个时间.. 但我不知道如何减少这个时间(0.542秒) 我想知道,那时它做了什么。

您能否告诉我如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

您计算经过时间的方法是使用有缺陷的数据 您认为0.5秒“延迟”实际上是U-Boot在 实时 中输出“Starting kernel ...”,而内核 缓冲区 推迟 输出“Booting Linux ...”,直到初始化系统和控制台。这是将苹果与橙子进行比较 至少你必须让内核实时输出(就像U-Boot一样)。然后您的时间戳将更好地指示实际经过的时间。

当内核执行早期初始化时,中断被禁用,并且任何输出到控制台(包括“引导Linux on ... ”消息)都保存在缓冲区中,直到 console_init()Linux/init/main.c的第572行执行。请注意,突出显示“ Booting Linux on ... ”文本在 start_kernel()过程的开头是“输出”,来自例程 smp_setup_processor_id()< / strong>,第478行。在内核启动时出现“引导Linux on ... ”文本之前注意到的大多数“延迟”是由控制台输出的缓冲引起的。

您可以通过启用内核调试功能早期printk 来克服因缓冲导致的明显延迟。
需要两个步骤:

  1. 在配置中启用此功能:

    make menuconfig
      内核黑客
        内核低级调试功能
          早期的printk

  2. 将参数“earlyprintk”添加到内核命令行,该命令行通常存储在U-Boot环境变量 bootargs 或设备树中。

  3. 内核启动日志应指示已启用此功能:

      

    在物理CPU 0x0上启动Linux   Linux版本3.10 ...
      CPU:ARMv7处理器[410fc051]版本1(ARMv7),cr = 10c53c7d
      CPU:PIPT / VIPT非混叠数据缓存,VIPT别名指令缓存
      机器:Atmel SAMA5(设备树),型号:Atmel SAMA5D36-EK
      启动bootconsole [earlycon0]
      内存策略:ECC禁用,数据缓存写回
      ...
      内核命令行:console = ttyS0,115200 earlyprintk rootfstype = ubifs ...