![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
dmesg -l emerg# shows emergency messagesdmesg -l alert# shows alertsdmesg -l crit# shows critical messagesdmesg -l err# shows error messages below emergency and critical levelsdmesg -l err+# shows all error levels emergency, critical and errordmesg -f kerndmesg -f daemondmesg -t -x
Here is an excerpt from dmesg that includes info, debug, warn-level messages:
kern :warn : [drm] Fence fallback timer expired on ring gfx kern :info : fbcon: amdgpudrmfb (fb0) is primary device kern :info : [drm] DSC precompute is not needed. kern :debug : calling nf_defrag_init+0x0/0xff0 [nf_defrag_ipv4] @ 1037 kern :debug : initcall nf_defrag_init+0x0/0xff0 [nf_defrag_ipv4] returned 0 aft er 1 usecs kern :debug : calling nf_defrag_init+0x0/0xff0 [nf_defrag_ipv6] @ 1037
early_initcall() defined in the kernel. A pure initcall is much more restricted, has no dependencies on anything else and purely initializes variables that couldn’t be statically initialized. Like early_initcall(), pure_initcall() also exists for built-in code, not for modules. There are just about 10 pure_initcall() definitions in the kernel as one would expect based on the restrictive uses of this type of initcall. One such use of a pure initcall can be found in the pci subsystem to initialize parameters when early parameters are parsed in pci_realloc_setup_params().
There are eight initcall call levels as defined in include/linux/init.h:
#define pure_initcall(fn) __define_initcall(fn, 0) #define core_initcall(fn) __define_initcall(fn, 1) #define core_initcall_sync(fn) __define_initcall(fn, 1s) #define postcore_initcall(fn) __define_initcall(fn, 2) #define postcore_initcall_sync(fn) __define_initcall(fn, 2s) #define arch_initcall(fn) __define_initcall(fn, 3) #define arch_initcall_sync(fn) __define_initcall(fn, 3s) #define subsys_initcall(fn) __define_initcall(fn, 4) #define subsys_initcall_sync(fn) __define_initcall(fn, 4s) #define fs_initcall(fn) __define_initcall(fn, 5) #define fs_initcall_sync(fn) __define_initcall(fn, 5s) #define rootfs_initcall(fn) __define_initcall(fn, rootfs) #define device_initcall(fn) __define_initcall(fn, 6) #define device_initcall_sync(fn) __define_initcall(fn, 6s) #define late_initcall(fn) __define_initcall(fn, 7) #define late_initcall_sync(fn) __define_initcall(fn, 7s)
static const char *initcall_level_names[] __initdata = {
"pure",
"core",
"postcore",
"arch",
"subsys",
"fs",
"device",
"late",
};
GRUB_CMDLINE_LINUX="earlyprintk=vga printk.time=1 initcall_debug"
Now let’s reboot and run `dmesg -t -x` command once the system is ready. I usually save the `dmesg` to a file to parse and analyze.
kern :debug : initcall con_init+0x0/0x378 returned 0 after 0 usecs kern :debug : initcall hvc_console_init+0x0/0x1f returned 0 after 0 usecs kern :debug : initcall xen_cons_init+0x0/0x80 returned 0 after 0 usecs kern :debug : initcall univ8250_console_init+0x0/0x39 returned 0 after 0 usecs kern :debug : initcall kgdboc_earlycon_late_init+0x0/0x31 returned 0 after 0 usecs kern :debug : initcall init_hw_perf_events+0x0/0x6d8 returned 0 after 0 usecs kern :debug : initcall do_init_real_mode+0x0/0x1a returned 0 after 0 usecs kern :debug : initcall trace_init_perf_perm_irq_work_exit+0x0/0x1c returned 0 after 0 usecs
cat dmesg.out | grep "initcall" | sed "s/\(.*\)after\(.*\)/\2 \1/g" | sort -n
Example from my system:
64564 usecs kern :debug : initcall serial8250_init+0x0/0x245 returned 0 87029 usecs kern :debug : initcall btusb_driver_init+0x0/0xff0 [btusb] returned 0 110960 usecs kern :debug : initcall ahci_pci_driver_init+0x0/0xff0 [ahci] returned 0 120384 usecs kern :debug : initcall init_kprobe_trace+0x0/0x21c returned 0 227677 usecs kern :debug : initcall br_init+0x0/0x12a [bridge] returned 0 281999 usecs kern :debug : initcall init_module+0x0/0xff0 [raid6_pq] returned 0 1104000 usecs kern :debug : initcall acpi_init+0x0/0x647 returned 0 2218805 usecs kern :debug : initcall inet6_init+0x0/0x413 returned 0
====================================================================
#!/bin/bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright(c) Shuah Khan <skhan@linuxfoundation.org>
# License: GPLv2
#
# Generates wiki format table of initcall times list from
# dmesg | grep initcall output
# Boot kernel with printk.time=1 initcall_debug command line options
# Usage: boot_initcall_tbl.sh <dmesg.out>
# See async_run_entry_fn() and Documentation/core-api/printk-formats.rst
# Print Table header
echo "Init Call times"
uname -a
cat /proc/cmdline
grep "Command line" $1 | awk -F ']' '{print $2}'
echo "===================================================================="
echo "Init calls that took longer to complete > 0 usecs"
echo "===================================================================="
echo "| **Init Call** | **Module** | **Retun Value** | **Time (uses)** |"
echo "===================================================================="
grep initcall $1 | awk -F ' ' '{ if (NF == 9 && $8 > 0) print "| " $4 " | --- | " $6 " | " $8 " | "}'
grep initcall $1 | awk -F ' ' '{ if (NF == 10 && $9 > 0) print "| " $4 " | " $5 " | " $7 " | " $9 " | "}'
echo "===================================================================="
echo "Failed Init calls (return value < 0)"
echo "===================================================================="
echo "| **Init Call** | **Module** | **Retun Value** | **Time (uses)** |"
echo "===================================================================="
grep initcall $1 | awk -F ' ' '{ if (NF == 9 && $6 < 0) print "| " $4 " | --- | " $6 " | " $8 " | "}'
grep initcall $1 | awk -F ' ' '{ if (NF == 10 && $7 < 0) print "| " $4 " | " $5 " | " $7 " | " $9 " | "}'
echo "===================================================================="
====================================================================