ricfv debug
dts
[root@centos7 images]# qemu-system-riscv64 -machine virt -machine dumpdtb=riscv64-virt.dtb -bios fw_jump.elf [root@centos7 images]# dtc -I dtb -O dts -o riscv64-virt.dts riscv64-virt.dtb -bash: dtc: command not found [root@centos7 images]# yum install dtc
# To convert dts file into dtb <kernel-source>/scripts/dtc/dtc -I dts -O dtb <dts_file> -o <dtb_file> # To convert dtb to dts <kernel-source>/scripts/dtc/dtc -I dtb -O dts <dtb_file> -o <dts_file> # Both of above commands are using dtc built with linux kernel source. # However you can also use dtc binary comes with ubuntu packages. For this you # need to install following package: sudo apt-get install -y device-tree-compiler # Ubuntu device-tree-compiler package comes with another utility known as fdtdump. # fdtdump can also be used to convert dtb file into dts. fdtdump <dtb_file> > <dts_dump>
fdtdump riscv64-virt.dtb **** fdtdump is a low-level debugging tool, not meant for general use. **** If you want to decompile a dtb, you probably want **** dtc -I dtb -O dts <filename> /dts-v1/; // magic: 0xd00dfeed // totalsize: 0xd1a (3354) // off_dt_struct: 0x38 // off_dt_strings: 0xbc4 // off_mem_rsvmap: 0x28 // version: 17 // last_comp_version: 2 // boot_cpuid_phys: 0x0 // size_dt_strings: 0x156 // size_dt_struct: 0xb8c / { #address-cells = <0x00000002>; #size-cells = <0x00000002>; compatible = "riscv-virtio"; model = "riscv-virtio,qemu"; flash@20000000 { bank-width = <0x00000004>; reg = <0x00000000 0x20000000 0x00000000 0x02000000 0x00000000 0x22000000 0x00000000 0x02000000>; compatible = "cfi-flash"; }; chosen { bootargs = [00]; stdout-path = "/uart@10000000"; }; uart@10000000 { interrupts = <0x0000000a>; interrupt-parent = <0x00000003>; clock-frequency = <0x00384000>; reg = <0x00000000 0x10000000 0x00000000 0x00000100>; compatible = "ns16550a"; }; test@100000 { reg = <0x00000000 0x00100000 0x00000000 0x00001000>; compatible = "sifive,test1", "sifive,test0"; };
[root@centos7 images]# cat riscv64-virt.dts /dts-v1/; / { #address-cells = <0x2>; #size-cells = <0x2>; compatible = "riscv-virtio"; model = "riscv-virtio,qemu"; flash@20000000 { bank-width = <0x4>; reg = <0x0 0x20000000 0x0 0x2000000 0x0 0x22000000 0x0 0x2000000>; compatible = "cfi-flash"; }; chosen { bootargs = [00]; stdout-path = "/uart@10000000"; }; uart@10000000 { interrupts = <0xa>; interrupt-parent = <0x3>; clock-frequency = <0x384000>; reg = <0x0 0x10000000 0x0 0x100>; compatible = "ns16550a"; }; test@100000 { reg = <0x0 0x100000 0x0 0x1000>; compatible = "sifive,test1", "sifive,test0"; }; virtio_mmio@10008000 { interrupts = <0x8>; interrupt-parent = <0x3>; reg = <0x0 0x10008000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10007000 { interrupts = <0x7>; interrupt-parent = <0x3>; reg = <0x0 0x10007000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10006000 { interrupts = <0x6>; interrupt-parent = <0x3>; reg = <0x0 0x10006000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10005000 { interrupts = <0x5>; interrupt-parent = <0x3>; reg = <0x0 0x10005000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10004000 { interrupts = <0x4>; interrupt-parent = <0x3>; reg = <0x0 0x10004000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10003000 { interrupts = <0x3>; interrupt-parent = <0x3>; reg = <0x0 0x10003000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10002000 { interrupts = <0x2>; interrupt-parent = <0x3>; reg = <0x0 0x10002000 0x0 0x1000>; compatible = "virtio,mmio"; }; virtio_mmio@10001000 { interrupts = <0x1>; interrupt-parent = <0x3>; reg = <0x0 0x10001000 0x0 0x1000>; compatible = "virtio,mmio"; }; cpus { #address-cells = <0x1>; #size-cells = <0x0>; timebase-frequency = <0x989680>; cpu-map { cluster0 { core0 { cpu = <0x1>; }; }; }; cpu@0 { phandle = <0x1>; device_type = "cpu"; reg = <0x0>; status = "okay"; compatible = "riscv"; riscv,isa = "rv64imafdcsu"; mmu-type = "riscv,sv48"; interrupt-controller { #interrupt-cells = <0x1>; interrupt-controller; compatible = "riscv,cpu-intc"; phandle = <0x2>; }; }; }; memory@80000000 { device_type = "memory"; reg = <0x0 0x80000000 0x0 0x8000000>; }; soc { #address-cells = <0x2>; #size-cells = <0x2>; compatible = "simple-bus"; ranges; pci@30000000 { interrupt-map-mask = <0x1800 0x0 0x0 0x7>; interrupt-map = <0x0 0x0 0x0 0x1 0x3 0x20 0x0 0x0 0x0 0x2 0x3 0x21 0x0 0x0 0x0 0x3 0x3 0x22 0x0 0x0 0x0 0x4 0x3 0x23 0x800 0x0 0x0 0x1 0x3 0x21 0x800 0x0 0x0 0x2 0x3 0x22 0x800 0x0 0x0 0x3 0x3 0x23 0x800 0x0 0x0 0x4 0x3 0x20 0x1000 0x0 0x0 0x1 0x3 0x22 0x1000 0x0 0x0 0x2 0x3 0x23 0x1000 0x0 0x0 0x3 0x3 0x20 0x1000 0x0 0x0 0x4 0x3 0x21 0x1800 0x0 0x0 0x1 0x3 0x23 0x1800 0x0 0x0 0x2 0x3 0x20 0x1800 0x0 0x0 0x3 0x3 0x21 0x1800 0x0 0x0 0x4 0x3 0x22>; ranges = <0x1000000 0x0 0x0 0x0 0x3000000 0x0 0x10000 0x2000000 0x0 0x40000000 0x0 0x40000000 0x0 0x40000000>; reg = <0x0 0x30000000 0x0 0x10000000>; dma-coherent; bus-range = <0x0 0xff>; linux,pci-domain = <0x0>; device_type = "pci"; compatible = "pci-host-ecam-generic"; #size-cells = <0x2>; #interrupt-cells = <0x1>; #address-cells = <0x3>; }; interrupt-controller@c000000 { phandle = <0x3>; riscv,ndev = <0x35>; reg = <0x0 0xc000000 0x0 0x4000000>; interrupts-extended = <0x2 0xb 0x2 0x9>; interrupt-controller; compatible = "riscv,plic0"; #interrupt-cells = <0x1>; #address-cells = <0x0>; }; clint@2000000 { interrupts-extended = <0x2 0x3 0x2 0x7>; reg = <0x0 0x2000000 0x0 0x10000>; compatible = "riscv,clint0"; }; }; };
dtb信息转化为device_node结构
http://sourcelink.top/2019/09/10/dts-unflatten_device_tree/

启动内核
qemu-system-riscv64 -nographic -machine virt -bios fw_jump.elf -m 1024 \ -kernel ~/riscv_debug/linux-5.14.g/arch/riscv/boot/Image -append "root=/dev/vda ro console=ttyS0,115200n8 earlycon" \ -drive file=rootfs.ext2,format=raw,id=hd0 \ -device virtio-blk-device,drive=hd0 \ -S -gdb tcp::1234 #-device virtio-blk-device,drive=hd0 \ #-S -gdb tcp::1234
[root@centos7 linux-5.14.g]# [root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b unflatten_dt_node Function "unflatten_dt_node" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (unflatten_dt_node) pending. (gdb) b unflatten_device_tree Breakpoint 2 at 0xffffffff80c2cb42: unflatten_device_tree. (2 locations) (gdb) c Continuing. Breakpoint 2, unflatten_device_tree () at drivers/of/fdt.c:1236 1236 __unflatten_device_tree(initial_boot_params, NULL, &of_root, (gdb) bt #0 unflatten_device_tree () at drivers/of/fdt.c:1236 #1 0xffffffff80c03188 in setup_arch (cmdline_p=0xffffffff81803fa0) at arch/riscv/kernel/setup.c:280 #2 0xffffffff80c0082e in start_kernel () at init/main.c:939 #3 0xffffffff80001182 in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) list 1231 * pointers of the nodes so the normal device-tree walking functions 1232 * can be used. 1233 */ 1234 void __init unflatten_device_tree(void) 1235 { 1236 __unflatten_device_tree(initial_boot_params, NULL, &of_root, 1237 early_init_dt_alloc_memory_arch, false); 1238 1239 /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ 1240 of_alias_scan(early_init_dt_alloc_memory_arch); (gdb) b __unflatten_device_tree Breakpoint 3 at 0xffffffff809457ec: __unflatten_device_tree. (2 locations) (gdb) c Continuing. Breakpoint 3, 0xffffffff809457ec in __unflatten_device_tree () at drivers/of/fdt.c:129 129 continue; (gdb) bt #0 0xffffffff809457ec in __unflatten_device_tree () at drivers/of/fdt.c:129 #1 0xffffffff80c2cb6e in unflatten_device_tree () at drivers/of/fdt.c:1236 #2 0xffffffff80c03188 in setup_arch (cmdline_p=0xffffffff81803fa0) at arch/riscv/kernel/setup.c:280 #3 0xffffffff80c0082e in start_kernel () at init/main.c:939 #4 0xffffffff80001182 in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) list 124 u32 sz; 125 126 val = fdt_getprop_by_offset(blob, cur, &pname, &sz); 127 if (!val) { 128 pr_warn("Cannot locate property at 0x%x\n", cur); 129 continue; 130 } 131 132 if (!pname) { 133 pr_warn("Cannot find property name at 0x%x\n", cur); (gdb) s Breakpoint 3, __unflatten_device_tree (blob=0xffffffe002000000, dad=dad@entry=0x0, mynodes=0xffffffff81a27838 <of_root>, dt_alloc=dt_alloc@entry=0xffffffff80c2b9ce <early_init_dt_alloc_memory_arch>, detached=detached@entry=false) at drivers/of/fdt.c:378 378 if (mynodes) (gdb) n 379 *mynodes = NULL; (gdb) list 374 int size; 375 void *mem; 376 int ret; 377 378 if (mynodes) 379 *mynodes = NULL; 380 381 pr_debug(" -> unflatten_device_tree()\n"); 382 383 if (!blob) { (gdb) n 383 if (!blob) { (gdb) n 393 if (fdt_check_header(blob)) { (gdb) n 399 size = unflatten_dt_nodes(blob, NULL, dad, NULL); (gdb) p *blob Attempt to dereference a generic pointer. (gdb) p blob $1 = (const void *) 0xffffffe002000000 (gdb) n 400 if (size <= 0) (gdb) c Continuing.
uboot
[root@centos7 riscv_debug]# git clone https://gitlab.denx.de/u-boot/u-boot.git --depth 1 Cloning into 'u-boot'... remote: Enumerating objects: 19347, done. remote: Counting objects: 100% (19347/19347), done. remote: Compressing objects: 100% (17268/17268), done. remote: Total 19347 (delta 3213), reused 6977 (delta 1739), pack-reused 0 Receiving objects: 100% (19347/19347), 25.13 MiB | 7.20 MiB/s, done. Resolving deltas: 100% (3213/3213), done. [root@centos7 riscv_debug]# make qemu-riscv64_smode_defconfig CROSS_COMPILE=iscv64-unknown-linux-gnu- make: *** No rule to make target 'qemu-riscv64_smode_defconfig'. Stop. [root@centos7 riscv_debug]#
[root@centos7 riscv_debug]# cd u-boot/
make CROSS_COMPILE=riscv64-unknown-linux-gnu- -j128
make[1]: *** [scripts/Makefile.host:104: tools/fit_info] Error 1
tools/libtools//ecdsalib//ecdsaecdsa-/libcrypto.oecdsa:- libcrypto.oIn: functionIn `functionprepare_ctx '`:prepare_ctx
'ecdsa:-
libcrypto.cecdsa:-(libcrypto.c.:text(+.0x98text)+:0x98 )undefined: referenceundefined toreference `toOPENSSL_init_ssl '`
OPENSSL_init_sslecdsa'-
libcrypto.cecdsa:-(libcrypto.c.:text(+.0x130text)+:0x130 )undefined: referenceundefined toreference `toEC_GROUP_order_bits '`
EC_GROUP_order_bitstools'/
libtools//ecdsalib//ecdsaecdsa-/libcrypto.oecdsa:- libcrypto.oIn: functionIn `functionecdsa_check_signature.isra.3 '`:
ecdsa_check_signature.isra.3ecdsa'-:libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x300.)text:+ 0x300undefined) :reference undefinedto reference` ECDSA_SIG_set0to'
`toolsECDSA_SIG_set0/'lib
/toolsecdsa//libecdsa/-ecdsalibcrypto.o/:ecdsa -Inlibcrypto.o :function In` ecdsa_signfunction' :`
ecdsa_signecdsa'-:libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x3ec.)text:+ 0x3ecundefined) :reference undefinedto reference` ECDSA_SIG_get0to'
`ecdsaECDSA_SIG_get0-'libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x3fc.)text:+ 0x3fcundefined) :reference undefinedto reference` BN_bn2binpadto'
`ecdsaBN_bn2binpad-'libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x40c.)text:+ 0x40cundefined) :reference undefinedto reference` BN_bn2binpadto'
`toolsBN_bn2binpad/'lib
/toolsecdsa//libecdsa/-ecdsalibcrypto.o/:ecdsa -Inlibcrypto.o :function In` ecdsa_add_verify_datafunction' :`
ecdsa_add_verify_dataecdsa'-:libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x5a8.)text:+ 0x5a8undefined) :reference undefinedto reference` EC_GROUP_order_bitsto'
`ecdsaEC_GROUP_order_bits-'libcrypto.c
:ecdsa(-.libcrypto.ctext:+(0x5ec.)text:+ 0x5ecundefined) :reference undefinedto reference` toEC_POINT_get_affine_coordinates '`
toolsEC_POINT_get_affine_coordinates/'lib
/toolsrsa//librsa/-rsasign.o/:rsa -Insign.o :function In` rsa_signfunction' :`
rsa_signrsa'-:sign.c
:rsa(-.sign.ctext:+(0x4e8.)text:+ 0x4e8undefined) :reference undefinedto reference` OPENSSL_init_sslto'
`rsaOPENSSL_init_ssl-'sign.c
:rsa(-.sign.ctext:+(0x790.)text:+ 0x790undefined) :reference undefinedto reference` EVP_MD_CTX_resetto'
`toolsEVP_MD_CTX_reset/'lib
/toolsrsa//librsa/-rsasign.o/:rsa -Insign.o :function In` rsa_get_paramsfunction' :`
rsa_get_paramsrsa'-:sign.c
:rsa(-.sign.ctext:+(0x874.)text:+ 0x874undefined) :reference undefinedto reference` RSA_get0_keyto'
`rsaRSA_get0_key-'sign.c
:rsa(-.sign.ctext:+(0x8bc.)text:+ 0x8bcundefined) :reference undefinedto reference` RSA_get0_keyto'
`toolsRSA_get0_key/'lib
/toolsrsa//librsa/-rsasign.o/:rsa -Insign.o :function In` rsa_add_verify_datafunction' :`
rsa_add_verify_datarsa'-:sign.c
:rsa(-.sign.ctext:+(0xc60.)text:+ 0xc60undefined) :reference undefinedto reference` EVP_PKEY_get0_RSAto'
`EVP_PKEY_get0_RSA'
collect2: error: ld returned 1 exit status
collect2: error: ld returned 1 exit status
make[1]: *** [scripts/Makefile.host:104: tools/mkimage] Error 1
make[1]: *** [scripts/Makefile.host:104: tools/fit_check_sign] Error 1
make: *** [Makefile:1801: tools] Error 2
yum -y install openssl
UBOOT_MAKE_FLAGS += \ HOSTLOADLIBES_mkimage="-pthread -lcrypto -lssl"
You may also use the following patch, submitted to u-boot: From a48643614cba7703f1ebbf92ecb5be5d73389f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= <bam@icognize.de> Date: Tue, 3 Dec 2019 09:52:34 +0100 Subject: [PATCH] Add -pthread to HOSTLOADLIBES_mkimage On some unix distributions, pthread is not automatically linked. This results in unresolved symbols when e.g. building u-boot via OpenWRT (using LibreSSL) in dumpimage and other host tools when i.E. CONFIG_FIT_SIGNATURE is set. Using -pthread to link pthread should be portable across all distributions and OS X. CHANGELOG: * Added -pthread to HOSTLOADLIBES_mkimage --- tools/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/Makefile b/tools/Makefile index 24581adccd..2f122bed8e 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -150,7 +150,8 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_ARMADA_39X)$(CON HOSTCFLAGS_kwbimage.o += \ $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "") HOSTLOADLIBES_mkimage += \ - $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto") + $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto") \ + -pthread # OS X deprecate openssl in favour of CommonCrypto, supress deprecation # warnings on those systems -- 2.20.1
Booting with qemu
Prerequisites:
- apt install qemu-system-misc opensbi u-boot-qemu qemu-utils
Hirsute's version of u-boot-qemu is required at the moment to boot hirsute images.
After installing the above prerequisites, one can use any of the above images to boot virtual machine.
First unpack the image
xz -dk focal-preinstalled-server-riscv64.img.xz
Optionally, if you want larger disk, you can expand the disk (filesystem will be automatically resized too).
qemu-img resize -f raw focal-preinstalled-server-riscv64.img +5G
Next use OpenSBI bootloader & u-boot-qemu to boot the virtual machine
Working example with all the options is:
qemu-system-riscv64 \
-machine virt -nographic -m 2048 -smp 4 \
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-drive file=focal-preinstalled-server-riscv64.img,format=raw,if=virtio
The important options to use are:
-
Machine type virt aka -machine virt
-
Bios is OpenSBI -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
-
"kernel" is qemu smode uboot -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf
One can use pass through networking, adjust memory (-m) & cpu counts (-smp) as needed.
Switch to the serial console, wait for cloud-init to complete, then login using ubuntu:ubuntu. See the cloud-init section below to further customise the first boot behaviour with cloud-init.
_start_kernel () at arch/riscv/kernel/head.S:327
[root@centos7 linux-5.14]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote :1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b sbi_console_write Breakpoint 1 at 0xffffffff80193634: file drivers/tty/serial/earlycon-riscv-sbi.c, line 24. (gdb) b early_sbi_setup Breakpoint 2 at 0xffffffff8021407c: file drivers/tty/serial/earlycon-riscv-sbi.c, line 31. (gdb) c Continuing. Breakpoint 2, early_sbi_setup (device=0xffffffff80a91658 <early_console_dev>, opt=0x0) at drivers/tty/serial/earlycon-riscv-sbi.c:31 31 device->con->write = sbi_console_write; (gdb) bt #0 early_sbi_setup (device=0xffffffff80a91658 <early_console_dev>, opt=0x0) at drivers/tty/serial/earlycon-riscv-sbi.c:31 #1 0xffffffff80213c08 in register_earlycon (match=<optimized out>, buf=0x0) at drivers/tty/serial/earlycon.c:147 #2 setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:205 #3 0xffffffff80213cc4 in param_setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:237 #4 0xffffffff802001c4 in do_early_param (param=0xffffffff80400218 <tmp_cmdline> "earlycon", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", unused=<optimized out>, arg=<optimized out>) at init/main.c:735 #5 0xffffffff8002867c in parse_one (handle_unknown=0xffffffff80200124 <do_early_param>, arg=0x0, max_level=<optimized out>, min_level=<optimized out>, num_params=0, params=0x0, doing=0xffffffff80648e48 "early options", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", param=0xffffffff80400218 <tmp_cmdline> "earlycon") at kernel/params.c:153 #6 parse_args (doing=doing@entry=0xffffffff80648e48 "early options", args=0xffffffff80400224 <tmp_cmdline+12> "", args@entry=0xffffffff80400218 <tmp_cmdline> "earlycon", params=params@entry=0x0, num=num@entry=0, min_level=min_level@entry=0, max_level=max_level@entry=0, arg=arg@entry=0x0, unknown=unknown@entry=0xffffffff80200124 <do_early_param>) at kernel/params.c:188 #7 0xffffffff80200940 in parse_early_options (cmdline=cmdline@entry=0xffffffff80400218 <tmp_cmdline> "earlycon") at init/main.c:745 #8 0xffffffff802009a0 in parse_early_param () at init/main.c:760 #9 0xffffffff80202400 in setup_arch (cmdline_p=cmdline_p@entry=0xffffffff80a03f98) at arch/riscv/kernel/setup.c:272 #10 0xffffffff80200b00 in start_kernel () at init/main.c:939 #11 0xffffffff8000016c in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 1, sbi_console_write (con=0xffffffff80a91860 <early_con>, s=0xffffffff80aaaa88 <text> "[ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021\n", n=150) at drivers/tty/serial/earlycon-riscv-sbi.c:24 24 for ( i= 0; i < n; ++i) (gdb) bt #0 sbi_console_write (con=0xffffffff80a91860 <early_con>, s=0xffffffff80aaaa88 <text> "[ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021\n", n=150) at drivers/tty/serial/earlycon-riscv-sbi.c:24 #1 0xffffffff80042094 in call_console_drivers (ext_text=0xffffffff80aaaec8 <ext_text> "", text=0xffffffff80aaaa88 <text> "[ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021\n", len=<optimized out>, ext_len=<optimized out>) at kernel/printk/printk.c:1938 #2 console_unlock () at kernel/printk/printk.c:2643 #3 0xffffffff80042af4 in register_console (newcon=0xffffffff80a91860 <early_con>) at kernel/printk/printk.c:2981 #4 0xffffffff80213c30 in register_earlycon (match=<optimized out>, buf=0x0) at drivers/tty/serial/earlycon.c:154 #5 setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:205 #6 0xffffffff80213cc4 in param_setup_earlycon (buf=<optimized out>) at drivers/tty/serial/earlycon.c:237 #7 0xffffffff802001c4 in do_early_param (param=0xffffffff80400218 <tmp_cmdline> "earlycon", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", unused=<optimized out>, arg=<optimized out>) at init/main.c:735 #8 0xffffffff8002867c in parse_one (handle_unknown=0xffffffff80200124 <do_early_param>, arg=0x0, max_level=<optimized out>, min_level=<optimized out>, num_params=0, params=0x0, doing=0xffffffff80648e48 "early options", val=0xffffffff80400221 <tmp_cmdline+9> "sbi", param=0xffffffff80400218 <tmp_cmdline> "earlycon") at kernel/params.c:153 #9 parse_args (doing=doing@entry=0xffffffff80648e48 "early options", args=0xffffffff80400224 <tmp_cmdline+12> "", args@entry=0xffffffff80400218 <tmp_cmdline> "earlycon", params=params@entry=0x0, num=num@entry=0, min_level=min_level@entry=0, max_level=max_level@entry=0, arg=arg@entry=0x0, unknown=unknown@entry=0xffffffff80200124 <do_early_param>) at kernel/params.c:188 #10 0xffffffff80200940 in parse_early_options (cmdline=cmdline@entry=0xffffffff80400218 <tmp_cmdline> "earlycon") at init/main.c:745 #11 0xffffffff802009a0 in parse_early_param () at init/main.c:760 #12 0xffffffff80202400 in setup_arch (cmdline_p=cmdline_p@entry=0xffffffff80a03f98)


Boot HART ID : 0 Boot HART Domain : root Boot HART ISA : rv64imafdcsu Boot HART Features : scounteren,mcounteren Boot HART PMP Count : 16 Boot HART PMP Granularity : 4 Boot HART PMP Address Bits: 54 Boot HART MHPM Count : 0 Boot HART MHPM Count : 0 Boot HART MIDELEG : 0x0000000000000222 Boot HART MEDELEG : 0x000000000000b109 [ 0.000000] Linux version 5.14.0 (root@centos7) (riscv64-unknown-elf-gcc (GCC) 11.1.0, GNU ld (GNU Binutils) 2.37) #2 Thu Oct 21 02:50:49 EDT 2021
riscv Kernel panic - not syncing: No working init found
[root@centos7 images]# file rootfs.ext2 rootfs.ext2: Linux rev 1.0 ext2 filesystem data, UUID=f782840d-9251-495d-b646-32800af3ca12 (large files) [root@centos7 images]# ls /data data/ data1/ data2/ data3/ [root@centos7 images]# ls /data3/ boot lost+found [root@centos7 images]# mkdir /data4 [root@centos7 images]# mount rootfs.ext2 /data4 [root@centos7 images]# ls /data4/ bin dev etc lib lib64 linuxrc lost+found media mnt opt proc root run sbin sys tmp usr var [root@centos7 images]# ls /data4/bin/ arch chgrp df fdflush kill lsattr mt pipe_progress run-parts stty uname ash chmod dmesg fgrep link mkdir mv printenv sed su usleep base32 chown dnsdomainname getopt linux32 mknod netstat ps setarch sync vi base64 cp dumpkmap grep linux64 mktemp nice pwd setpriv tar watch busybox cpio echo gunzip ln more nuke resume setserial touch zcat cat date egrep gzip login mount pidof rm sh true chattr dd false hostname ls mountpoint ping rmdir sleep umount [root@centos7 images]#
[root@centos7 linux-5.14.g]# gdb vmlinux GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "aarch64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /root/riscv_debug/linux-5.14.g/vmlinux...Dwarf Error: wrong version in compilation unit header (is 5, should be 2, 3, or 4) [in module /root/riscv_debug/linux-5.14.g/vmlinux] (no debugging symbols found)...done. (gdb) target remote:1234 Remote debugging using :1234 warning: Architecture rejected target-supplied description 0x0000000000001000 in ?? () (gdb) b try_to_run_init_process Breakpoint 1 at 0xffffffff8016276e (gdb) b print_trace_address Breakpoint 2 at 0xffffffff80162984 (gdb) c Continuing. Breakpoint 1, 0xffffffff8016276e in try_to_run_init_process () (gdb) bt #0 0xffffffff8016276e in try_to_run_init_process () #1 0x000000000000003d in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) info f Stack level 0, frame at 0xffffffd00400bec0: pc = 0xffffffff8016276e in try_to_run_init_process; saved pc 0x3d called by frame at 0xffffffd00400bec0 Arglist at unknown address. Locals at unknown address, Previous frame's sp is 0xffffffd00400bec0 Could not fetch register "v31"; remote failure reply 'E14' (gdb) info registers x0 0x0 0 x1 0xffffffff8016517a -2146020998 x2 0xffffffd00400bec0 -206091272512 x3 0xffffffff80aa1b80 -2136335488 x4 0xffffffe000ef0000 -137423290368 x5 0x40 64 x6 0x0 0 x7 0xd 13 x8 0xffffffd00400bee0 -206091272480 x9 0xffffffff80aa2028 -2136334296 x10 0xffffffff806520b8 -2140856136 x11 0x13d 317 x12 0xffffffe000e3db60 -137424020640 x13 0xffffffe03eff0060 -136382054304 x14 0x13c 316 x15 0x2 2 x16 0xffffffe000e3daf0 -137424020752 x17 0x9 9 x18 0x0 0 x19 0x0 0 x20 0x0 0 x21 0x0 0 ---Type <return> to continue, or q <return> to quit--- x22 0x0 0 x23 0x0 0 x24 0x0 0 x25 0x0 0 x26 0x0 0 x27 0x0 0 x28 0xffffffff8061fde8 -2141061656 x29 0x22 34 x30 0x3d 61 sp 0x0 0x0 pc 0xffffffff8016276e 0xffffffff8016276e <try_to_run_init_process> cpsr 0x0 0 fpsr 0x0 0 fpcr 0x0 0 (gdb) (gdb) (gdb) c Continuing. Breakpoint 1, 0xffffffff8016276e in try_to_run_init_process () (gdb) bt #0 0xffffffff8016276e in try_to_run_init_process () #1 0x000000000000003d in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) c
gdb 错了[root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinuxGNU gdb (GDB) 1Copyright (C) 2021 Free Software Foundation, InLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) b try_to_run_init_process Breakpoint 1 at 0xffffffff8016276e: file init/main.c, line 1437. (gdb) b print_trace_address Breakpoint 2 at 0xffffffff80162984: file arch/riscv/kernel/stacktrace.c, line 104. (gdb) c The program is not being run. (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b try_to_run_init_process Note: breakpoint 1 also set at pc 0xffffffff8016276e. Breakpoint 3 at 0xffffffff8016276e: file init/main.c, line 1437. (gdb) b print_trace_address Note: breakpoint 2 also set at pc 0xffffffff80162984. Breakpoint 4 at 0xffffffff80162984: file arch/riscv/kernel/stacktrace.c, line 104. (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520b8 "/sbin/init") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) bt #0 try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520b8 "/sbin/init") at init/main.c:1437 #1 0xffffffff8016517a in kernel_init (unused=<optimized out>) at init/main.c:1554 #2 0xffffffff8000299c in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) p 0xffffffff806520b8 $1 = 18446744071568695480 (gdb) info registers ra 0xffffffff8016517a 0xffffffff8016517a <kernel_init+200> sp 0xffffffd00400bec0 0xffffffd00400bec0 gp 0xffffffff80aa1b80 0xffffffff80aa1b80 tp 0xffffffe000ef0000 0xffffffe000ef0000 t0 0x40 64 t1 0x0 0 t2 0xd 13 fp 0xffffffd00400bee0 0xffffffd00400bee0 s1 0xffffffff80aa2028 -2136334296 a0 0xffffffff806520b8 -2140856136 a1 0x13d 317 a2 0xffffffe000e3db60 -137424020640 a3 0xffffffe03eff0060 -136382054304 a4 0x13c 316 a5 0x2 2 a6 0xffffffe000e3daf0 -137424020752 a7 0x9 9 s2 0x0 0 s3 0x0 0 s4 0x0 0 s5 0x0 0 s6 0x0 0 --Type <RET> for more, q to quit, c to continue without paging-- s7 0x0 0 s8 0x0 0 s9 0x0 0 s10 0x0 0 s11 0x0 0 t3 0xffffffff8061fde8 -2141061656 t4 0x22 34 t5 0x3d 61 t6 0x0 0 pc 0xffffffff8016276e 0xffffffff8016276e <try_to_run_init_process> (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520c8 "/etc/init") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520d8 "/bin/init") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) c Continuing. Breakpoint 1, try_to_run_init_process (init_filename=init_filename@entry=0xffffffff806520e8 "/bin/sh") at init/main.c:1437 1437 ret = run_init_process(init_filename); (gdb) c Continuing. Breakpoint 2, print_trace_address (arg=0xffffffff80663448, pc=18446744071563520692) at arch/riscv/kernel/stacktrace.c:104 104 { (gdb) bt #0 print_trace_address (arg=0xffffffff80663448, pc=18446744071563520692) at arch/riscv/kernel/stacktrace.c:104 #1 0xffffffff80162a30 in walk_stackframe (task=task@entry=0x0, regs=regs@entry=0x0, fn=fn@entry=0xffffffff80162984 <print_trace_address>, arg=arg@entry=0xffffffff80663448) at arch/riscv/kernel/stacktrace.c:46 #2 0xffffffff80162ab4 in dump_backtrace (regs=regs@entry=0x0, task=task@entry=0x0, loglvl=loglvl@entry=0xffffffff80663448 "") at arch/riscv/kernel/stacktrace.c:114 #3 0xffffffff80162ae4 in show_stack (task=task@entry=0x0, sp=sp@entry=0x0, loglvl=loglvl@entry=0xffffffff80663448 "") at arch/riscv/kernel/stacktrace.c:120 #4 0xffffffff80164f04 in __dump_stack (log_lvl=0xffffffff80663448 "") at lib/dump_stack.c:88 #5 dump_stack_lvl (log_lvl=0xffffffff80663448 "") at lib/dump_stack.c:105 #6 dump_stack () at lib/dump_stack.c:112 #7 0xffffffff80162c1e in panic ( fmt=fmt@entry=0xffffffff806520f0 "No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.") at kernel/panic.c:232 #8 0xffffffff801651b2 in kernel_init (unused=<optimized out>) at init/main.c:1560 #9 0xffffffff8000299c in handle_exception () at arch/riscv/kernel/entry.S:232 ----调用
handle_syscall_trace_exit
Backtrace stopped: frame did not save the PC (gdb) n 105 const char *loglvl = arg; (gdb) p *arg Attempt to dereference a generic pointer. (gdb) p *loglvl value has been optimized out (gdb) n 106 pr_cont("yuncong************* %s[<%px>] %pS\n", loglvl, (void *) pc, (void *) pc); (gdb) n 107 print_ip_sym(loglvl, pc); (gdb) p loglvl $2 = 0xffffffff80663448 "" (gdb) p *loglvl $3 = 0 '\000' (gdb) c Continuing. Breakpoint 2, print_trace_address (arg=0xffffffff80663448, pc=18446744071563529988) at arch/riscv/kernel/stacktrace.c:104 104 { (gdb) c Continuing. Breakpoint 2, print_trace_address (arg=0xffffffff80663448, pc=18446744071563521054) at arch/riscv/kernel/stacktrace.c:104 104 { (gdb)
arch/riscv/kernel/entry.S :232
228 ret_from_syscall_rejected: 229 /* Trace syscalls, but only if requested by the user. */ 230 REG_L t0, TASK_TI_FLAGS(tp) 231 andi t0, t0, _TIF_SYSCALL_WORK 232 bnez t0, handle_syscall_trace_exit
make: *** [Makefile:1851: arch/riscv] Error 2
make[1]: *** [scripts/Makefile.build:514: arch/riscv/kernel] Error 2 make[1]: *** Waiting for unfinished jobs.... AR drivers/soc/bcm/built-in.a CC fs/proc/proc_tty.o AR fs/devpts/built-in.a CC fs/select.o AR drivers/soc/fsl/built-in.a AR drivers/reset/hisilicon/built-in.a AR drivers/clk/bcm/built-in.a CC drivers/reset/core.o CC drivers/reset/reset-simple.o AR arch/riscv/mm/built-in.a AR fs/ramfs/built-in.a CC drivers/tty/vt/vt_ioctl.o AR drivers/clk/imgtec/built-in.a CC fs/dcache.o AR drivers/soc/imx/built-in.a CC drivers/tty/vt/vc_screen.o CC drivers/char/mem.o make: *** [Makefile:1851: arch/riscv] Error 2 make: *** Waiting for unfinished jobs....
kernel_init
arch/riscv/kernel/head.S:184:setup_trap_vector
.align 2 setup_trap_vector: /* Set trap vector to exception handler */ la a0, handle_exception csrw CSR_TVEC, a0 /* * Set sup0 scratch register to 0, indicating to exception vector that * we are presently executing in kernel. */ csrw CSR_SCRATCH, zero ret .Lsecondary_park: /* We lack SMP support or have too many harts, so park this hart */ wfi j .Lsecondary_park END(_start)
当一个hart(Risc-V的一个硬件线程)发生异常时,硬件会将异常指令的PC保存在mepc寄存器中。Risc-V还支持向量中断,即若将mtvec[0]设置为1,则表示mtvec中保存的是中断向量的起始地址,因此PC实际上是会根据中断原因 x(mcause中的值)将PC设置为(mtvec - 1 + 4x)。而mtvec寄存器的值是系统程序员来设置的,一般在CPU一开始执行代码时就设置mtvec寄存器,其值是中断向量的起始地址。
其中:
a. 把handle_exception的地址填入mtvec寄存器,作为中断向量表的基地址;handle_exception在entry.S中定义,其定义如下:
ENTRY(handle_exception) /* * If coming from userspace, preserve the user thread pointer and load * the kernel thread pointer. If we came from the kernel, the scratch * register will contain 0, and we should continue on the current TP. */ csrrw tp, CSR_SCRATCH, tp bnez tp, _save_context _restore_kernel_tpsp: csrr tp, CSR_SCRATCH REG_S sp, TASK_TI_KERNEL_SP(tp) #ifdef CONFIG_VMAP_STACK addi sp, sp, -(PT_SIZE_ON_STACK) srli sp, sp, THREAD_SHIFT andi sp, sp, 0x1
. handle_arch_irq
handle_arch_irq是一个变量,其中存放了中断处理程序的地址
内核启动异常--entry.S
[root@centos7 riscv]# grep handle_exception -rn * kernel/kgdb.c:298:int kgdb_arch_handle_exception(int vector, int signo, int err_code, kernel/kgdb.c:351: if (kgdb_handle_exception(type == KGDB_SW_SINGLE_STEP ? 0 : 1, kernel/head.S:186: la a0, handle_exception kernel/entry.S:21:ENTRY(handle_exception) kernel/entry.S:175: * handle_exception did not do set SR_IE as it always sees SR_PIE kernel/entry.S:487:END(handle_exception)
LD [M] fs/efivarfs/efivarfs.ko [root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b arch/riscv/kernel/entry.S:232 Breakpoint 1 at 0xffffffff8000300c: file arch/riscv/kernel/entry.S, line 232. (gdb) b handle_exception Breakpoint 2 at 0xffffffff80002ed4: file arch/riscv/kernel/entry.S, line 27. (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8004d04e in try_enable_new_console (newcon=newcon@entry=0xffffffff81296ae8 <vt_console_driver>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2817 #2 0xffffffff8004e2a8 in register_console (newcon=newcon@entry=0xffffffff81296ae8 <vt_console_driver>) at kernel/printk/printk.c:2921 #3 0xffffffff808193e8 in con_init () at drivers/tty/vt/vt.c:3505 #4 0xffffffff80807a30 in console_init () at kernel/printk/printk.c:3091 #5 0xffffffff80800bf0 in start_kernel () at init/main.c:1061 #6 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff80819d4c in serial8250_isa_init_ports () at drivers/tty/serial/8250/8250_core.c:517 #2 0xffffffff81203f60 in init_thread_union () Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8004d04e in try_enable_new_console (newcon=newcon@entry=0xffffffff8129bf78 <sifive_serial_console>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2817 #2 0xffffffff8004e2a8 in register_console (newcon=newcon@entry=0xffffffff8129bf78 <sifive_serial_console>) at kernel/printk/printk.c:2921 #3 0xffffffff8081a1e2 in sifive_console_init () at drivers/tty/serial/sifive.c:877 #4 0xffffffff80807a30 in console_init () at kernel/printk/printk.c:3091 #5 0xffffffff80800bf0 in start_kernel () at init/main.c:1061 #6 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8070c69e in __raw_spin_unlock_irqrestore (flags=549755813888, lock=lock@entry=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock_api_smp.h:159 #2 _raw_spin_unlock_irqrestore (lock=lock@entry=0xffffffff8128a540 <pcpu_lock>, flags=flags@entry=2) at kernel/locking/spinlock.c:191 #3 0xffffffff800e9d6c in spin_unlock_irqrestore (flags=2, lock=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock.h:409 #4 pcpu_alloc (size=<optimized out>, size@entry=11, align=<optimized out>, align@entry=1, reserved=reserved@entry=false, gfp=<optimized out>, gfp@entry=3264) at mm/percpu.c:1854 #5 0xffffffff800ea126 in __alloc_percpu (size=size@entry=11, align=align@entry=1) at mm/percpu.c:1954 #6 0xffffffff8082f2ec in setup_zone_pageset (zone=zone@entry=0xffffffff812cc440 <contig_page_data>) at mm/page_alloc.c:6936 #7 0xffffffff8080d546 in setup_per_cpu_pageset () at mm/page_alloc.c:6962 #8 0xffffffff80800cde in start_kernel () at init/main.c:1092 #9 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) =========================================================================== (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8070c69e in __raw_spin_unlock_irqrestore (flags=549755813888, lock=lock@entry=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock_api_smp.h:159 #2 _raw_spin_unlock_irqrestore (lock=lock@entry=0xffffffff8128a540 <pcpu_lock>, flags=flags@entry=2) at kernel/locking/spinlock.c:191 #3 0xffffffff800e9d6c in spin_unlock_irqrestore (flags=2, lock=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock.h:409 #4 pcpu_alloc (size=<optimized out>, size@entry=11, align=<optimized out>, align@entry=1, reserved=reserved@entry=false, gfp=<optimized out>, gfp@entry=3264) at mm/percpu.c:1854 #5 0xffffffff800ea126 in __alloc_percpu (size=size@entry=11, align=align@entry=1) at mm/percpu.c:1954 #6 0xffffffff8082f2ec in setup_zone_pageset (zone=zone@entry=0xffffffff812cc440 <contig_page_data>) at mm/page_alloc.c:6936 #7 0xffffffff8080d546 in setup_per_cpu_pageset () at mm/page_alloc.c:6962 #8 0xffffffff80800cde in start_kernel () at init/main.c:1092 #9 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8070c69e in __raw_spin_unlock_irqrestore (flags=4503599627370496, lock=lock@entry=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock_api_smp.h:159 #2 _raw_spin_unlock_irqrestore (lock=lock@entry=0xffffffff8128a540 <pcpu_lock>, flags=flags@entry=2) at kernel/locking/spinlock.c:191 #3 0xffffffff800e9d6c in spin_unlock_irqrestore (flags=2, lock=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock.h:409 #4 pcpu_alloc (size=<optimized out>, size@entry=208, align=<optimized out>, align@entry=8, reserved=reserved@entry=false, gfp=<optimized out>, gfp@entry=3264) at mm/percpu.c:1854 #5 0xffffffff800ea126 in __alloc_percpu (size=size@entry=208, align=align@entry=8) at mm/percpu.c:1954 #6 0xffffffff8082f2fc in setup_zone_pageset (zone=zone@entry=0xffffffff812cc440 <contig_page_data>) at mm/page_alloc.c:6938 #7 0xffffffff8080d546 in setup_per_cpu_pageset () at mm/page_alloc.c:6962 #8 0xffffffff80800cde in start_kernel () at init/main.c:1092 #9 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff800ea126 in __alloc_percpu (size=<optimized out>, align=<optimized out>) at mm/percpu.c:1954 #2 0xffffffff800ea126 in __alloc_percpu (size=size@entry=40, align=align@entry=1) at mm/percpu.c:1954 #3 0xffffffff8080d570 in setup_per_cpu_pageset () at mm/page_alloc.c:6980 #4 0xffffffff80800cde in start_kernel () at init/main.c:1092 #5 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8070c69e in __raw_spin_unlock_irqrestore (flags=288230376151711744, lock=lock@entry=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock_api_smp.h:159 #2 _raw_spin_unlock_irqrestore (lock=lock@entry=0xffffffff8128a540 <pcpu_lock>, flags=flags@entry=2) at kernel/locking/spinlock.c:191 #3 0xffffffff800e9d6c in spin_unlock_irqrestore (flags=2, lock=0xffffffff8128a540 <pcpu_lock>) at ./include/linux/spinlock.h:409 #4 pcpu_alloc (size=<optimized out>, size@entry=40, align=<optimized out>, align@entry=1, reserved=reserved@entry=false, gfp=<optimized out>, gfp@entry=3264) at mm/percpu.c:1854 #5 0xffffffff800ea126 in __alloc_percpu (size=size@entry=40, align=align@entry=1) at mm/percpu.c:1954 #6 0xffffffff8080d570 in setup_per_cpu_pageset () at mm/page_alloc.c:6980 #7 0xffffffff80800cde in start_kernel () at init/main.c:1092 #8 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff800c6e16 in jump_label_can_update (init=true, entry=0xffffffff80dd73b8) at kernel/jump_label.c:411 #2 __jump_label_update (key=0xffffffff812f0ab8 <sched_clock_running>, entry=0xffffffff80dd73b8, stop=<optimized out>, init=<optimized out>) at kernel/jump_label.c:436 #3 0xffffffff800c6e16 in jump_label_can_update (init=158, entry=0xffffffff81203f60) at kernel/jump_label.c:411 #4 __jump_label_update (key=0xffffffff80dd6430 <pcpu_unit_offsets>, key@entry=0xffffffff812f0ab8 <sched_clock_running>, entry=0xffffffff81203f60, stop=<optimized out>, init=<optimized out>) at kernel/jump_label.c:436 #5 0xffffffff800c7050 in jump_label_update (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>) at kernel/jump_label.c:830 #6 0xffffffff800c77d6 in static_key_slow_inc_cpuslocked (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>) at kernel/jump_label.c:144 #7 0xffffffff800c77f6 in static_key_slow_inc (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>) at kernel/jump_label.c:159 #8 0xffffffff80806a90 in sched_clock_init () at kernel/sched/clock.c:455 #9 0xffffffff80800cf2 in start_kernel () at init/main.c:1097 #10 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff80006c76 in __sbi_rfence_v02 (fid=<optimized out>, hart_mask=<optimized out>, start=0, size=0, arg4=0, arg5=<optimized out>) at arch/riscv/kernel/sbi.c:341 #2 0xffffffff80006c76 in __sbi_rfence_v02 (fid=<optimized out>, hart_mask=<optimized out>, start=0, size=0, arg4=0, arg5=<optimized out>) at arch/riscv/kernel/sbi.c:341 #3 0xffffffff80006770 in sbi_remote_fence_i (hart_mask=hart_mask@entry=0x0) at arch/riscv/kernel/sbi.c:381 #4 0xffffffff80007cb6 in flush_icache_all () at arch/riscv/mm/cacheflush.c:20 #5 0xffffffff80005092 in patch_text_nosync (addr=<optimized out>, insns=<optimized out>, len=<optimized out>) at arch/riscv/kernel/patch.c:96 #6 0xffffffff800070c4 in arch_jump_label_transform (entry=<optimized out>, type=<optimized out>) at arch/riscv/kernel/jump_label.c:39 #7 0xffffffff800c6e32 in __jump_label_update (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>, entry=0xffffffff80dd73b8, stop=<optimized out>, init=<optimized out>) at kernel/jump_label.c:437 #8 0xffffffff800c7050 in jump_label_update (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>) at kernel/jump_label.c:830 #9 0xffffffff800c77d6 in static_key_slow_inc_cpuslocked (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>) at kernel/jump_label.c:144 #10 0xffffffff800c77f6 in static_key_slow_inc (key=key@entry=0xffffffff812f0ab8 <sched_clock_running>) at kernel/jump_label.c:159 #11 0xffffffff80806a90 in sched_clock_init () at kernel/sched/clock.c:455 #12 0xffffffff80800cf2 in start_kernel () at init/main.c:1097 #13 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 --Type <RET> for more, q to quit, c to continue without paging-- Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff80806a9c in sched_clock_init () at kernel/sched/clock.c:457 #2 0xffffffff80800cf2 in start_kernel () at init/main.c:1097 #3 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8004f0f6 in vprintk_emit (facility=facility@entry=0, level=<optimized out>, level@entry=-1, dev_info=dev_info@entry=0x0, fmt=fmt@entry=0xffffffff80d45a78 "\001\066Calibrating delay loop (skipped), value calculated using timer frequency.. ", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk.c:2158 #2 0xffffffff8004f202 in vprintk_default ( fmt=fmt@entry=0xffffffff80d45a78 "\001\066Calibrating delay loop (skipped), value calculated using timer frequency.. ", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk.c:2185 #3 0xffffffff8004f7aa in vprintk ( fmt=fmt@entry=0xffffffff80d45a78 "\001\066Calibrating delay loop (skipped), value calculated using timer frequency.. ", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk_safe.c:392 #4 0xffffffff806fccf6 in printk ( fmt=fmt@entry=0xffffffff80d45a78 "\001\066Calibrating delay loop (skipped), value calculated using timer frequency.. ") at kernel/printk/printk.c:2216 #5 0xffffffff80002ae2 in calibrate_delay () at init/calibrate.c:293 #6 0xffffffff80800cfa in start_kernel () at init/main.c:1098 #7 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8004f202 in vprintk_default (fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk.c:2185 #2 0xffffffff8004f7aa in vprintk (fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk_safe.c:392 #3 0xffffffff806fccf6 in printk (fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n") at kernel/printk/printk.c:2216 #4 0xffffffff800027b8 in calibrate_delay () at init/calibrate.c:308 #5 0xffffffff80800cfa in start_kernel () at init/main.c:1098 #6 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, handle_exception () at arch/riscv/kernel/entry.S:27 27 csrrw tp, CSR_SCRATCH, tp (gdb) bt #0 handle_exception () at arch/riscv/kernel/entry.S:27 #1 0xffffffff8004f0f6 in vprintk_emit (facility=facility@entry=0, level=<optimized out>, level@entry=-1, dev_info=dev_info@entry=0x0, fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk.c:2158 #2 0xffffffff8004f202 in vprintk_default (fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk.c:2185 #3 0xffffffff8004f7aa in vprintk (fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n", args=args@entry=0xffffffff81203ea8) at kernel/printk/printk_safe.c:392 #4 0xffffffff806fccf6 in printk (fmt=fmt@entry=0xffffffff80d45cb8 "\001c%lu.%02lu BogoMIPS (lpj=%lu)\n") at kernel/printk/printk.c:2216 #5 0xffffffff800027b8 in calibrate_delay () at init/calibrate.c:308 #6 0xffffffff80800cfa in start_kernel () at init/main.c:1098 #7 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb)
sifive_console_init
[root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b try_enable_new_console Breakpoint 1 at 0xffffffff8004d000: file kernel/printk/printk.c, line 2809. (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff81299c28 <early_con>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) list 2804 { 2805 struct console_cmdline *c; 2806 int i, err; 2807 2808 for (i = 0, c = console_cmdline; 2809 i < MAX_CMDLINECONSOLES && c->name[0]; 2810 i++, c++) { 2811 if (c->user_specified != user_specified) 2812 continue; 2813 if (!newcon->match || (gdb) set print pretty on (gdb) p *c $1 = { name = '\000' <repeats 15 times>, index = 0, user_specified = false, options = 0x0 } (gdb) b sifive_console_init Breakpoint 2 at 0xffffffff8081a1ca: file drivers/tty/serial/sifive.c, line 877. (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff81299c28 <early_con>, user_specified=user_specified@entry=false) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) p *c $2 = { name = '\000' <repeats 15 times>, index = 0, user_specified = false, options = 0x0 } (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff81296ae8 <vt_console_driver>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff81296ae8 <vt_console_driver>, user_specified=user_specified@entry=false) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff812996c0 <hvc_console>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff812996c0 <hvc_console>, user_specified=user_specified@entry=false) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff81299c88 <univ8250_console>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 2, sifive_console_init () at drivers/tty/serial/sifive.c:877 877 register_console(&sifive_serial_console); (gdb) bt #0 sifive_console_init () at drivers/tty/serial/sifive.c:877 #1 0xffffffff80807a30 in console_init () at kernel/printk/printk.c:3091 #2 0xffffffff80800bf0 in start_kernel () at init/main.c:1061 #3 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) list 872 .data = &sifive_serial_uart_driver, 873 }; 874 875 static int __init sifive_console_init(void) 876 { 877 register_console(&sifive_serial_console); 878 return 0; 879 } 880 881 console_initcall(sifive_console_init); (gdb) p sifive_serial_console) Junk after end of expression. (gdb) p *sifive_serial_console) Junk after end of expression. (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff8129bf78 <sifive_serial_console>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff8129bf78 <sifive_serial_console>, user_specified=user_specified@entry=false) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb) c Continuing. Breakpoint 1, try_enable_new_console (newcon=newcon@entry=0xffffffff81299c88 <univ8250_console>, user_specified=user_specified@entry=true) at kernel/printk/printk.c:2809 2809 i < MAX_CMDLINECONSOLES && c->name[0]; (gdb)
中断处理
[root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b generic_handle_irq_desc Breakpoint 1 at 0xffffffff80050cc8: generic_handle_irq_desc. (5 locations) (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc); (gdb) bt #0 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 #1 handle_irq_desc (desc=0xffffffe00160f400) at kernel/irq/irqdesc.c:646 #2 handle_domain_irq (domain=0xffffffe00160c400, hwirq=<optimized out>, regs=<optimized out>) at kernel/irq/irqdesc.c:701 #3 0xffffffff802e4136 in riscv_intc_irq (regs=<optimized out>) at drivers/irqchip/irq-riscv-intc.c:42 #4 0xffffffff80003010 in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) b __handle_irq_event_percpu Breakpoint 2 at 0xffffffff80051b22: file kernel/irq/handle.c, line 140. (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc); (gdb) bt #0 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 #1 handle_irq_desc (desc=0xffffffe00160f400) at kernel/irq/irqdesc.c:646 #2 handle_domain_irq (domain=0xffffffe00160c400, hwirq=<optimized out>, regs=<optimized out>) at kernel/irq/irqdesc.c:701 #3 0xffffffff802e4136 in riscv_intc_irq (regs=<optimized out>) at drivers/irqchip/irq-riscv-intc.c:42 #4 0xffffffff80003010 in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc); (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc); (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc); (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc); (gdb) c Continuing. Breakpoint 1, 0xffffffff800514d6 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 158 desc->handle_irq(desc)
(gdb) bt #0 __handle_irq_event_percpu (desc=desc@entry=0xffffffe001743600, flags=flags@entry=0xffffffd0040db984) at kernel/irq/handle.c:140 #1 0xffffffff80051cea in handle_irq_event_percpu (desc=0xffffffe001743600) at kernel/irq/handle.c:196 #2 handle_irq_event (desc=desc@entry=0xffffffe001743600) at kernel/irq/handle.c:213 #3 0xffffffff80055494 in handle_fasteoi_irq (desc=<optimized out>) at kernel/irq/chip.c:717 #4 0xffffffff80051154 in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 #5 handle_irq_desc (desc=<optimized out>) at kernel/irq/irqdesc.c:646 #6 generic_handle_domain_irq (domain=<optimized out>, hwirq=<optimized out>) at kernel/irq/irqdesc.c:675 #7 0xffffffff802e4336 in plic_handle_irq (desc=0xffffffe00160f200) at drivers/irqchip/irq-sifive-plic.c:238 #8 0xffffffff800514de in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 #9 handle_irq_desc (desc=<optimized out>) at kernel/irq/irqdesc.c:646 #10 handle_domain_irq (domain=<optimized out>, hwirq=<optimized out>, regs=<optimized out>) at kernel/irq/irqdesc.c:701 #11 0xffffffff802e4136 in riscv_intc_irq (regs=<optimized out>) at drivers/irqchip/irq-riscv-intc.c:42 #12 0xffffffff80003010 in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) c
时钟
时钟初始化
error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
"clockevents/riscv/timer:starting",
riscv_timer_starting_cpu, riscv_timer_dying_cpu)
[root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configura For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b clockevents_config_and_register Breakpoint 1 at 0xffffffff800721c2: file kernel/time/clockevents.c, line 507. (gdb) b setup_irq Function "setup_irq" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) b update_process_times Breakpoint 2 at 0xffffffff80067600: file kernel/time/timer.c, line 1780. (gdb) c Continuing. Breakpoint 1, clockevents_config_and_register (dev=0xffffffe03efeb8c0, freq=10000000, min_delta=min_delta@entry=100, max_delta=max_delta@entry=2147483647) at kernel/time/clockevents.c:507 507 { (gdb) bt #0 clockevents_config_and_register (dev=0xffffffe03efeb8c0, freq=10000000, min_delta=min_delta@entry=100, max_delta=max_delta@entry=2147483647) at kernel/time/clockevents.c:507 #1 0xffffffff805a2f16 in riscv_timer_starting_cpu (cpu=<optimized out>) at drivers/clocksource/timer-riscv.c:72 #2 0xffffffff8000bcae in cpuhp_invoke_callback (cpu=<optimized out>, state=<optimized out>, bringup=bringup@entry=true, node=<optimized out>, lastp=lastp@entry=0x0) at kernel/cpu.c:180 #3 0xffffffff8000caea in cpuhp_issue_call (node=<optimized out>, bringup=true, state=<optimized out>, cpu=<optimized out>) at kernel/cpu.c:1887 #4 cpuhp_issue_call (cpu=<optimized out>, state=<optimized out>, bringup=<optimized out>, node=<optimized out>) at kernel/cpu.c:1867 #5 0xffffffff8000ce6e in __cpuhp_setup_state_cpuslocked (state=<optimized out>, state@entry=CPUHP_AP_RISCV_TIMER_STARTING, name=name@entry=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", invoke=invoke@entry=true, startup=startup@entry=0xffffffff805a2eaa <riscv_timer_starting_cpu>, teardown=teardown@entry=0xffffffff805a2e88 <riscv_timer_dying_cpu>, multi_instance=multi_instance@entry=false) at kernel/cpu.c:2032 #6 0xffffffff8000d00a in __cpuhp_setup_state (state=state@entry=CPUHP_AP_RISCV_TIMER_STARTING, name=name@entry=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", invoke=invoke@entry=true, startup=startup@entry=0xffffffff805a2eaa <riscv_timer_starting_cpu>, teardown=teardown@entry=0xffffffff805a2e88 <riscv_timer_dying_cpu>, multi_instance=multi_instance@entry=false) at kernel/cpu.c:2061 #7 0xffffffff8082069c in cpuhp_setup_state (teardown=<optimized out>, startup=<optimized out>, name=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", state=CPUHP_AP_RISCV_TIMER_STARTING) at ./include/linux/cpuhotplug.h:231 --Type <RET> for more, q to quit, c to continue without paging-- #8 riscv_timer_init_dt (n=<optimized out>) at drivers/clocksource/timer-riscv.c:157 #9 0xffffffff808203fa in timer_probe () at drivers/clocksource/timer-probe.c:30 #10 0xffffffff808031f6 in time_init () at arch/riscv/kernel/time.c:31 #11 0xffffffff80800b82 in start_kernel () at init/main.c:1041 #12 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, update_process_times (user_tick=0) at kernel/time/timer.c:1780 1780 PRANDOM_ADD_NOISE(jiffies, user_tick, p, 0); (gdb) bt #0 update_process_times (user_tick=0) at kernel/time/timer.c:1780 #1 0xffffffff8007294c in tick_periodic (cpu=cpu@entry=0) at kernel/time/tick-common.c:100 #2 0xffffffff800729d4 in tick_handle_periodic (dev=0xffffffe03efeb8c0) at kernel/time/tick-common.c:112 #3 0xffffffff805a2e7e in riscv_timer_interrupt (irq=<optimized out>, dev_id=<optimized out>) at drivers/clocksource/timer-riscv.c:92 #4 0xffffffff800560da in handle_percpu_devid_irq (desc=<optimized out>) at ./arch/riscv/include/asm/current.h:31 #5 0xffffffff800514de in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 #6 handle_irq_desc (desc=<optimized out>) at kernel/irq/irqdesc.c:646 #7 handle_domain_irq (domain=<optimized out>, hwirq=<optimized out>, regs=<optimized out>) at kernel/irq/irqdesc.c:701 #8 0xffffffff802e4136 in riscv_intc_irq (regs=<optimized out>) at drivers/irqchip/irq-riscv-intc.c:42 #9 0xffffffff80003010 in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 2, update_process_times (user_tick=0) at kernel/time/timer.c:1780 1780 PRANDOM_ADD_NOISE(jiffies, user_tick, p, 0); (gdb) bt #0 update_process_times (user_tick=0) at kernel/time/timer.c:1780 #1 0xffffffff8007294c in tick_periodic (cpu=cpu@entry=0) at kernel/time/tick-common.c:100 #2 0xffffffff800729d4 in tick_handle_periodic (dev=0xffffffe03efeb8c0) at kernel/time/tick-common.c:112 #3 0xffffffff805a2e7e in riscv_timer_interrupt (irq=<optimized out>, dev_id=<optimized out>) at drivers/clocksource/timer-riscv.c:92 #4 0xffffffff800560da in handle_percpu_devid_irq (desc=<optimized out>) at ./arch/riscv/include/asm/current.h:31 #5 0xffffffff800514de in generic_handle_irq_desc (desc=<optimized out>) at ./include/linux/irqdesc.h:158 #6 handle_irq_desc (desc=<optimized out>) at kernel/irq/irqdesc.c:646 #7 handle_domain_irq (domain=<optimized out>, hwirq=<optimized out>, regs=<optimized out>) at kernel/irq/irqdesc.c:701 #8 0xffffffff802e4136 in riscv_intc_irq (regs=<optimized out>) at drivers/irqchip/irq-riscv-intc.c:42 #9 0xffffffff80003010 in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) info breaks Undefined info command: "breaks". Try "help info". (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep y 0xffffffff800721c2 in clockevents_config_and_register at kernel/time/clockevents.c:507 breakpoint already hit 1 time 2 breakpoint keep y 0xffffffff80067600 in update_process_times at kernel/time/timer.c:1780 breakpoint already hit 2 times (gdb) delete 1 (gdb) delete 2 (gdb) c Continuing.
timer_probe(void)
Linux 时钟框架学习笔记
#define TIMER_OF_DECLARE(name, compat, fn) \ OF_DECLARE_1_RET(timer, name, compat, fn)
#define OF_DECLARE_1(table, name, compat, fn) \ _OF_DECLARE(table, name, compat, fn, of_init_fn_1) #define OF_DECLARE_1_RET(table, name, compat, fn) \ _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret) #define OF_DECLARE_2(table, name, compat, fn) \ _OF_DECLARE(table, name, compat, fn, of_init_fn_2)
static int __init arm_sp804_of_init(struct device_node *np) { return sp804_of_init(np, &arm_sp804_timer); } TIMER_OF_DECLARE(sp804, "arm,sp804", arm_sp804_of_init); static int __init hisi_sp804_of_init(struct device_node *np) { return sp804_of_init(np, &hisi_sp804_timer); } TIMER_OF_DECLARE(hisi_sp804, "hisilicon,sp804", hisi_sp804_of_init);
timer0: timer@20020000 { compatible = "arm,sp804", "arm,primecell"; };
void __init timer_probe(void) { struct device_node *np; const struct of_device_id *match; of_init_fn_1_ret init_func_ret; unsigned timers = 0; int ret; for_each_matching_node_and_match(np, __timer_of_table, &match) { if (!of_device_is_available(np)) continue; init_func_ret = match->data; ret = init_func_ret(np); if (ret) { if (ret != -EPROBE_DEFER) pr_err("Failed to initialize '%pOF': %d\n", np, ret); continue; } timers++; } timers += acpi_probe_device_table(timer); if (!timers) pr_crit("%s: no matching timers found\n", __func__); }
TIMER_OF_DECLARE(riscv_timer, "riscv", riscv_timer_init_dt);
drivers/clocksource/timer-riscv.c:166:TIMER_OF_DECLARE(riscv_timer, "riscv", riscv_timer_init_dt);
drivers/clocksource/timer-clint.c:243:TIMER_OF_DECLARE(clint_timer, "riscv,clint0", clint_timer_init_dt);
(gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b timer_probe Breakpoint 1 at 0xffffffff80820398: file drivers/clocksource/timer-probe.c, line 17. (gdb) c Continuing. Breakpoint 1, timer_probe () at drivers/clocksource/timer-probe.c:17 17 { (gdb) s 24 for_each_matching_node_and_match(np, __timer_of_table, &match) { (gdb) p __timer_of_tabl No symbol "__timer_of_tabl" in current context. (gdb) p __timer_of_table $1 = 0xffffffff80a0e6d0 <__of_table_riscv_timer> (gdb) p *__timer_of_table $2 = {name = '\000' <repeats 31 times>, type = '\000' <repeats 31 times>, compatible = "riscv", '\000' <repeats 122 times>, data = 0xffffffff8082049c <riscv_timer_init_dt>} (gdb) set print pretty on (gdb) p *__timer_of_table $3 = { name = '\000' <repeats 31 times>, type = '\000' <repeats 31 times>, compatible = "riscv", '\000' <repeats 122 times>, data = 0xffffffff8082049c <riscv_timer_init_dt> } (gdb) n 25 if (!of_device_is_available(np)) (gdb) p *np $4 = { name = 0xffffffe03fdfcbb0 "cpu", phandle = 1, full_name = 0xffffffe03fdfc8a8 "cpu@0", fwnode = { secondary = 0x0, ops = 0xffffffff80cac4a0 <of_fwnode_ops>, dev = 0x0, suppliers = { next = 0xffffffe03fdfc808, prev = 0xffffffe03fdfc808 }, consumers = { next = 0xffffffe03fdfc818, prev = 0xffffffe03fdfc818 }, flags = 0 '\000' }, properties = 0xffffffe03fdfc8b0, deadprops = 0x0, parent = 0xffffffe03fdfc148, child = 0xffffffe03fdfcbb8, sibling = 0x0, kobj = { name = 0x0, entry = { next = 0xffffffe03fdfc860, prev = 0xffffffe03fdfc860 }, parent = 0x0, kset = 0x0, ktype = 0xffffffff812bdd28 <of_node_ktype>, sd = 0x0, kref = { refcount = { refs = { counter = 1 } } }, state_initialized = 1, state_in_sysfs = 0, state_add_uevent_sent = 0, state_remove_uevent_sent = 0, uevent_suppress = 0 }, _flags = 0, data = 0x0 } (gdb) p *match $5 = { name = '\000' <repeats 31 times>, type = '\000' <repeats 31 times>, compatible = "riscv", '\000' <repeats 122 times>, data = 0xffffffff8082049c <riscv_timer_init_dt> } (gdb) c Continuing.
timer_of_table

[root@centos7 linux-5.14.g]# grep __timer_of_table -rn * arch/riscv/kernel/vmlinux.lds:65: .init.data : AT(ADDR(.init.data) - ((((-1))) - 0x80000000 + 1)) { KEEP(*(SORT(___kentry+*))) *(.init.data init.data.*) *(.meminit.data*) *(.init.rodata .init.rodata.*) *(.meminit.rodata) . = ALIGN(8); __clk_of_table = .; KEEP(*(__clk_of_table)) KEEP(*(__clk_of_table_end)) . = ALIGN(8); __reservedmem_of_table = .; KEEP(*(__reservedmem_of_table)) KEEP(*(__reservedmem_of_table_end)) . = ALIGN(8); __timer_of_table = .; KEEP(*(__timer_of_table)) KEEP(*(__timer_of_table_end)) . = ALIGN(8); __cpu_method_of_table = .; KEEP(*(__cpu_method_of_table)) KEEP(*(__cpu_method_of_table_end)) . = ALIGN(32); __dtb_start = .; KEEP(*(.dtb.init.rodata)) __dtb_end = .; . = ALIGN(8); __irqchip_of_table = .; KEEP(*(__irqchip_of_table)) KEEP(*(__irqchip_of_table_end)) . = ALIGN(8); __earlycon_table = .; KEEP(*(__earlycon_table)) __earlycon_table_end = .; . = ALIGN(8); __kunit_suites_start = .; KEEP(*(.kunit_test_suites)) __kunit_suites_end = .; . = ALIGN(16); __setup_start = .; KEEP(*(.init.setup)) __setup_end = .; __initcall_start = .; KEEP(*(.initcallearly.init)) __initcall0_start = .; KEEP(*(.initcall0.init)) KEEP(*(.initcall0s.init)) __initcall1_start = .; KEEP(*(.initcall1.init)) KEEP(*(.initcall1s.init)) __initcall2_start = .; KEEP(*(.initcall2.init)) KEEP(*(.initcall2s.init)) __initcall3_start = .; KEEP(*(.initcall3.init)) KEEP(*(.initcall3s.init)) __initcall4_start = .; KEEP(*(.initcall4.init)) KEEP(*(.initcall4s.init)) __initcall5_start = .; KEEP(*(.initcall5.init)) KEEP(*(.initcall5s.init)) __initcallrootfs_start = .; KEEP(*(.initcallrootfs.init)) KEEP(*(.initcallrootfss.init)) __initcall6_start = .; KEEP(*(.initcall6.init)) KEEP(*(.initcall6s.init)) __initcall7_start = .; KEEP(*(.initcall7.init)) KEEP(*(.initcall7s.init)) __initcall_end = .; __con_initcall_start = .; KEEP(*(.con_initcall.init)) __con_initcall_end = .; . = ALIGN(4); __initramfs_start = .; KEEP(*(.init.ramfs)) . = ALIGN(8); KEEP(*(.init.ramfs.info)) } drivers/clocksource/timer-probe.c:11:extern struct of_device_id __timer_of_table[]; drivers/clocksource/timer-probe.c:13:static const struct of_device_id __timer_of_table_sentinel drivers/clocksource/timer-probe.c:14: __used __section("__timer_of_table_end"); drivers/clocksource/timer-probe.c:24: for_each_matching_node_and_match(np, __timer_of_table, &match) { Binary file drivers/clocksource/timer-probe.o matches Binary file drivers/clocksource/timer-riscv.o matches linux-dr:1191212: 128c4: R_RISCV_PCREL_HI20 __timer_of_table linux-dr:1191236: 128e6: R_RISCV_PCREL_HI20 __timer_of_table System.map:44626:ffffffff80a0e6d0 D __timer_of_table System.map:44627:ffffffff80a0e798 d __timer_of_table_sentinel
tick_set_periodic_handler
tick_set_periodic_handler /* * Set the periodic handler depending on broadcast on/off */ void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast) { if (!broadcast) dev->event_handler = tick_handle_periodic; else dev->event_handler = tick_handle_periodic_broadcast; } [root@centos7 linux-5.14.g]# riscv64-unknown-elf-gdb vmlinux GNU gdb (GDB) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=aarch64-unknown-linux-gnu --target=riscv64-unknown-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from vmlinux... (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b tick_set_periodic_handler Breakpoint 1 at 0xffffffff80073d42: file kernel/time/tick-broadcast.c, line 516. (gdb) c Continuing. Breakpoint 1, tick_set_periodic_handler (dev=dev@entry=0xffffffe03efeb8c0, broadcast=0) at kernel/time/tick-broadcast.c:516 516 if (!broadcast) (gdb) bt #0 tick_set_periodic_handler (dev=dev@entry=0xffffffe03efeb8c0, broadcast=0) at kernel/time/tick-broadcast.c:516 #1 0xffffffff80072ade in tick_setup_periodic (dev=0xffffffe03efeb8c0, broadcast=<optimized out>) at kernel/time/tick-common.c:154 #2 0xffffffff80072bc0 in tick_setup_device (td=td@entry=0xffffffe03efea068, newdev=newdev@entry=0xffffffe03efeb8c0, cpu=cpu@entry=0, cpumask=<optimized out>) at kernel/time/tick-common.c:272 #3 0xffffffff80072e3a in tick_check_new_device (newdev=newdev@entry=0xffffffe03efeb8c0) at kernel/time/tick-common.c:367 #4 0xffffffff800720c8 in clockevents_register_device (dev=dev@entry=0xffffffe03efeb8c0) at kernel/time/clockevents.c:464 #5 0xffffffff800721e2 in clockevents_config_and_register (dev=0xffffffe03efeb8c0, freq=<optimized out>, min_delta=min_delta@entry=100, max_delta=max_delta@entry=2147483647) at kernel/time/clockevents.c:511 #6 0xffffffff805a2f16 in riscv_timer_starting_cpu (cpu=<optimized out>) at drivers/clocksource/timer-riscv.c:72 #7 0xffffffff8000bcae in cpuhp_invoke_callback (cpu=<optimized out>, state=<optimized out>, bringup=bringup@entry=true, node=<optimized out>, lastp=lastp@entry=0x0) at kernel/cpu.c:180 #8 0xffffffff8000caea in cpuhp_issue_call (node=<optimized out>, bringup=true, state=<optimized out>, cpu=<optimized out>) at kernel/cpu.c:1887 #9 cpuhp_issue_call (cpu=<optimized out>, state=<optimized out>, bringup=<optimized out>, node=<optimized out>) at kernel/cpu.c:1867 #10 0xffffffff8000ce6e in __cpuhp_setup_state_cpuslocked (state=<optimized out>, state@entry=CPUHP_AP_RISCV_TIMER_STARTING, name=name@entry=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", invoke=invoke@entry=true, startup=startup@entry=0xffffffff805a2eaa <riscv_timer_starting_cpu>, teardown=teardown@entry=0xffffffff805a2e88 <riscv_timer_dying_cpu>, multi_instance=multi_instance@entry=false) --Type <RET> for more, q to quit, c to continue without paging-- at kernel/cpu.c:2032 #11 0xffffffff8000d00a in __cpuhp_setup_state (state=state@entry=CPUHP_AP_RISCV_TIMER_STARTING, name=name@entry=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", invoke=invoke@entry=true, startup=startup@entry=0xffffffff805a2eaa <riscv_timer_starting_cpu>, teardown=teardown@entry=0xffffffff805a2e88 <riscv_timer_dying_cpu>, multi_instance=multi_instance@entry=false) at kernel/cpu.c:2061 #12 0xffffffff8082069c in cpuhp_setup_state (teardown=<optimized out>, startup=<optimized out>, name=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", state=CPUHP_AP_RISCV_TIMER_STARTING) at ./include/linux/cpuhotplug.h:231 #13 riscv_timer_init_dt (n=<optimized out>) at drivers/clocksource/timer-riscv.c:157 #14 0xffffffff808203fa in timer_probe () at drivers/clocksource/timer-probe.c:30 #15 0xffffffff808031f6 in time_init () at arch/riscv/kernel/time.c:31 #16 0xffffffff80800b82 in start_kernel () at init/main.c:1041 #17 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) s tick_setup_periodic (dev=0xffffffe03efeb8c0, broadcast=<optimized out>) at kernel/time/tick-common.c:157 157 if (!tick_device_is_functional(dev)) (gdb) list 152 void tick_setup_periodic(struct clock_event_device *dev, int broadcast) 153 { 154 tick_set_periodic_handler(dev, broadcast); 155 156 /* Broadcast setup ? */ 157 if (!tick_device_is_functional(dev)) 158 return; 159 160 if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) && 161 !tick_broadcast_oneshot_active()) { (gdb) n 160 if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) && (gdb) n 152 void tick_setup_periodic(struct clock_event_device *dev, int broadcast) (gdb) bt #0 tick_setup_periodic (dev=0xffffffe03efeb8c0, broadcast=<optimized out>) at kernel/time/tick-common.c:152 #1 0xffffffff80072bc0 in tick_setup_device (td=td@entry=0xffffffe03efea068, newdev=newdev@entry=0xffffffe03efeb8c0, cpu=cpu@entry=0, cpumask=<optimized out>) at kernel/time/tick-common.c:272 #2 0xffffffff80072e3a in tick_check_new_device (newdev=newdev@entry=0xffffffe03efeb8c0) at kernel/time/tick-common.c:367 #3 0xffffffff800720c8 in clockevents_register_device (dev=dev@entry=0xffffffe03efeb8c0) at kernel/time/clockevents.c:464 #4 0xffffffff800721e2 in clockevents_config_and_register (dev=0xffffffe03efeb8c0, freq=<optimized out>, min_delta=min_delta@entry=100, max_delta=max_delta@entry=2147483647) at kernel/time/clockevents.c:511 #5 0xffffffff805a2f16 in riscv_timer_starting_cpu (cpu=<optimized out>) at drivers/clocksource/timer-riscv.c:72 #6 0xffffffff8000bcae in cpuhp_invoke_callback (cpu=<optimized out>, state=<optimized out>, bringup=bringup@entry=true, node=<optimized out>, lastp=lastp@entry=0x0) at kernel/cpu.c:180 #7 0xffffffff8000caea in cpuhp_issue_call (node=<optimized out>, bringup=true, state=<optimized out>, cpu=<optimized out>) at kernel/cpu.c:1887 #8 cpuhp_issue_call (cpu=<optimized out>, state=<optimized out>, bringup=<optimized out>, node=<optimized out>) at kernel/cpu.c:1867 #9 0xffffffff8000ce6e in __cpuhp_setup_state_cpuslocked (state=<optimized out>, state@entry=CPUHP_AP_RISCV_TIMER_STARTING, name=name@entry=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", invoke=invoke@entry=true, startup=startup@entry=0xffffffff805a2eaa <riscv_timer_starting_cpu>, teardown=teardown@entry=0xffffffff805a2e88 <riscv_timer_dying_cpu>, multi_instance=multi_instance@entry=false) at kernel/cpu.c:2032 #10 0xffffffff8000d00a in __cpuhp_setup_state (state=state@entry=CPUHP_AP_RISCV_TIMER_STARTING, --Type <RET> for more, q to quit, c to continue without paging-- name=name@entry=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", invoke=invoke@entry=true, startup=startup@entry=0xffffffff805a2eaa <riscv_timer_starting_cpu>, teardown=teardown@entry=0xffffffff805a2e88 <riscv_timer_dying_cpu>, multi_instance=multi_instance@entry=false) at kernel/cpu.c:2061 #11 0xffffffff8082069c in cpuhp_setup_state (teardown=<optimized out>, startup=<optimized out>, name=0xffffffff80dc3c98 "clockevents/riscv/timer:starting", state=CPUHP_AP_RISCV_TIMER_STARTING) at ./include/linux/cpuhotplug.h:231 #12 riscv_timer_init_dt (n=<optimized out>) at drivers/clocksource/timer-riscv.c:157 #13 0xffffffff808203fa in timer_probe () at drivers/clocksource/timer-probe.c:30 #14 0xffffffff808031f6 in time_init () at arch/riscv/kernel/time.c:31 #15 0xffffffff80800b82 in start_kernel () at init/main.c:1041 #16 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) s tick_setup_periodic (broadcast=<optimized out>, dev=<optimized out>) at kernel/time/tick-common.c:168 168 seq = read_seqcount_begin(&jiffies_seq); (gdb) list 163 } else { 164 unsigned int seq; 165 ktime_t next; 166 167 do { 168 seq = read_seqcount_begin(&jiffies_seq); 169 next = tick_next_period; 170 } while (read_seqcount_retry(&jiffies_seq, seq)); 171 172 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT); (gdb) c Continuing.
set_handle_irq(&riscv_intc_irq);
set_handle_irq(&riscv_intc_irq); (gdb) target remote:1234 Remote debugging using :1234 warning: Can not parse XML target description; XML support was disabled at compile time 0x0000000000001000 in ?? () (gdb) b set_handle_irq Note: breakpoint 1 also set at pc 0xffffffff80807cee. Breakpoint 2 at 0xffffffff80807cee: file kernel/irq/handle.c, line 223. (gdb) c Continuing. Breakpoint 1, set_handle_irq (handle_irq=handle_irq@entry=0xffffffff802e4100 <riscv_intc_irq>) at kernel/irq/handle.c:223 223 if (handle_arch_irq) (gdb) bt #0 set_handle_irq (handle_irq=handle_irq@entry=0xffffffff802e4100 <riscv_intc_irq>) at kernel/irq/handle.c:223 #1 0xffffffff8081714a in riscv_intc_init (node=<optimized out>, parent=<optimized out>) at drivers/irqchip/irq-riscv-intc.c:124 #2 0xffffffff80822178 in of_irq_init (matches=<optimized out>) at drivers/of/irq.c:540 #3 0xffffffff808170ae in irqchip_init () at drivers/irqchip/irqchip.c:31 #4 0xffffffff80802b0a in init_IRQ () at arch/riscv/kernel/irq.c:21 #5 0xffffffff80800af6 in start_kernel () at init/main.c:1017 #6 0xffffffff8000116a in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb)
account_process_tick更新cpu统计信息。
run_local_timers触发TIMER_SOFTIRQ软中断。
scheduler_tick进行进程调度(在hrtimer激活的情况下,这个操作基本是空的)。
void update_process_times(int user_tick) { struct task_struct *p = current; int cpu = smp_processor_id(); /* Note: this timer irq context must be accounted for as well. */ account_process_tick(p, user_tick); run_local_timers(); rcu_check_callbacks(cpu, user_tick); printk_tick(); #ifdef CONFIG_IRQ_WORK if (in_irq()) irq_work_run(); #endif scheduler_tick(); run_posix_cpu_timers(p); }
void update_process_times(int user_tick) { struct task_struct *p = current; int cpu = smp_processor_id(); /* Note: this timer irq context must be accounted for as well. */ account_process_tick(p, user_tick); run_local_timers(); rcu_check_callbacks(cpu, user_tick); printk_tick(); #ifdef CONFIG_IRQ_WORK if (in_irq()) irq_work_run(); #endif scheduler_tick(); run_posix_cpu_timers(p); }
到这里为止,cpu0的timer中断已经是准备好并且开始工作了。jiffies_64也在不断的增加了。
大概只需要10来个jiffies(HZ=100)之后, local timer也参与到kernel中来了。
sP804

[root@centos7 clocksource]# grep 804 Kconfig config ARM_TIMER_SP804 bool "Support for Dual Timer SP804 module" if COMPILE_TEST [root@centos7 clocksource]# grep 804 Makefile obj-$(CONFIG_ARM_TIMER_SP804) += timer-sp804.o [root@centos7 clocksource]# cat ../../System.map | grep sp804 [root@centos7 clocksource]# grep CONFIG_ARM_TIMER_SP804 -rn * Makefile:66:obj-$(CONFIG_ARM_TIMER_SP804) += timer-sp804.o [root@centos7 clocksource]#
[root@centos7 clocksource]# grep 804 Kconfig -A 5 config ARM_TIMER_SP804 bool "Support for Dual Timer SP804 module" if COMPILE_TEST depends on GENERIC_SCHED_CLOCK && HAVE_CLK select CLKSRC_MMIO select TIMER_OF if OF config CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK




drivers/clocksource/Kconfig
config MICROCHIP_PIT64B bool "Microchip PIT64B support" depends on OF || COMPILE_TEST select CLKSRC_MMIO select TIMER_OF help This option enables Microchip PIT64B timer for Atmel based system. It supports the oneshot, the periodic modes and high resolution. It is used as a clocksource and a clockevent.
grep PIT64B -rn *
arch/arm/configs/at91_dt_defconfig:197:CONFIG_MICROCHIP_PIT64B=y
arch/riscv/Kconfig添加
menu "Clock Source drivers" choice config ARM_TIMER_SP804 bool "Support for Dual Timer SP804 module" if COMPILE_TEST depends on GENERIC_SCHED_CLOCK && HAVE_CLK select CLKSRC_MMIO select TIMER_OF if OF endchoice endmenu

竟然依赖COMPILE_TEST
menu "Clock Source drivers*****" #choice config RISCV_TIMER_SP804 bool "Support for Dual Timer SP804 module" depends on GENERIC_SCHED_CLOCK && HAVE_CLK select CLKSRC_MMIO select TIMER_OF if OF #endchoice endmenu
终于出来了

第二种方法
#menu "Clock Source drivers" ##choice # #config RISCV_TIMER_SP804 # bool "Support for Dual Timer SP804 module" # depends on GENERIC_SCHED_CLOCK && HAVE_CLK # select CLKSRC_MMIO # select TIMER_OF if OF # # ##endchoice #endmenu source "arch/riscv/Kconfig.arm"
[root@centos7 linux-5.14.g]# cat arch/riscv/Kconfig.arm menu "Clock Source drivers*****" #choice config ARM_TIMER_SP804 #bool "Support for Dual Timer SP804 module" if COMPILE_TEST bool "Support for Dual Timer SP804 module" depends on GENERIC_SCHED_CLOCK && HAVE_CLK select CLKSRC_MMIO select TIMER_OF if OF #endchoice endmenu


更改drivers/clocksource/Kconfig


[root@centos7 linux-5.14.g]# grep ARM_TIMER_SP804 .config CONFIG_ARM_TIMER_SP804=y [root@centos7 linux-5.14.g]#
[root@centos7 linux-5.14.g]# grep ARM_TIMER_SP804 .config CONFIG_ARM_TIMER_SP804=y [root@centos7 linux-5.14.g]# grep GENERIC_SCHED_CLOCK .config CONFIG_GENERIC_SCHED_CLOCK=y [root@centos7 linux-5.14.g]# grep HAVE_CLK .config CONFIG_HAVE_CLK=y CONFIG_HAVE_CLK_PREPARE=y [root@centos7 linux-5.14.g]#
[root@centos7 linux-5.14.g]# make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j128 SYNC include/config/auto.conf.cmd HOSTCC scripts/kconfig/conf.o HOSTLD scripts/kconfig/conf CALL scripts/atomic/check-atomics.sh CALL scripts/checksyscalls.sh CHK include/generated/compile.h CC drivers/clocksource/mmio.o CC drivers/clocksource/timer-sp804.o AR drivers/clocksource/built-in.a AR drivers/built-in.a GEN .version CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o AR init/built-in.a LD vmlinux.o MODPOST vmlinux.symvers MODINFO modules.builtin.modinfo GEN modules.builtin LD .tmp_vmlinux.kallsyms1 KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux SYSMAP System.map OBJCOPY arch/riscv/boot/Image GZIP arch/riscv/boot/Image.gz Kernel: arch/riscv/boot/Image.gz is ready
[root@centos7 linux-5.14.g]# cat System.map | grep hisi_sp804_of_init ffffffff8021440e t hisi_sp804_of_init [root@centos7 linux-5.14.g]#
# ls /s sbin/ sys/ # ls /sys/bus/ clockevents gpio mmc_rpmb platform serio workqueue clocksource hid nvmem rpmsg spi container i2c pci scsi usb cpu mmc pci_express sdio virtio # # ls /sys/bus/clocksource/ devices drivers_autoprobe uevent drivers drivers_probe # # ls /sys/bus/clocksource/devices/ clocksource0 # # ls /sys/bus/clocksource/devices/clocksource0/ available_clocksource subsystem unbind_clocksource current_clocksource uevent # # cat /sys/bus/clocksource/devices/clocksource0/available_clocksource riscv_clocksource arm,sp804 #
struct clk_hw *of_clk_get_hw(struct device_node *np, int index, const char *con_id) { int ret; struct clk_hw *hw; struct of_phandle_args clkspec; ret = of_parse_clkspec(np, index, con_id, &clkspec); if (ret) return ERR_PTR(ret); hw = of_clk_get_hw_from_clkspec(&clkspec); of_node_put(clkspec.np); return hw; }
/**
* of_parse_clkspec() - Parse a DT clock specifier for a given device node
* @np: device node to parse clock specifier from
* @index: index of phandle to parse clock out of. If index < 0, @name is used
* @name: clock name to find and parse. If name is NULL, the index is used
* @out_args: Result of parsing the clock specifier
*
* Parses a device node's "clocks" and "clock-names" properties to find the
* phandle and cells for the index or name that is desired. The resulting clock
* specifier is placed into @out_args, or an errno is returned when there's a
* parsing error. The @index argument is ignored if @name is non-NULL.
*
* Example:
*
* phandle1: clock-controller@1 {
* #clock-cells = <2>;
* }
*
* phandle2: clock-controller@2 {
* #clock-cells = <1>;
* }
*
* clock-consumer@3 {
* clocks = <&phandle1 1 2 &phandle2 3>;
* clock-names = "name1", "name2";
* }
*
* To get a device_node for `clock-controller@2' node you may call this
* function a few different ways:
*
* of_parse_clkspec(clock-consumer@3, -1, "name2", &args);
* of_parse_clkspec(clock-consumer@3, 1, NULL, &args);
* of_parse_clkspec(clock-consumer@3, 1, "name2", &args);
*
* Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT
* if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in
* the "clock-names" property of @np.
*/
static int of_parse_clkspec(const struct device_node *np, int index,
const char *name, struct of_phandle_args *out_args)
{
* Return: 0 upon successfully parsing the clock specifier. Otherwise, -ENOENT * if @name is NULL or -EINVAL if @name is non-NULL and it can't be found in * the "clock-names" property of @np. */ static int of_parse_clkspec(const struct device_node *np, int index, const char *name, struct of_phandle_args *out_args) { int ret = -ENOENT; /* Walk up the tree of devices looking for a clock property that matches */ while (np) { /* * For named clocks, first look up the name in the * "clock-names" property. If it cannot be found, then index * will be an error code and of_parse_phandle_with_args() will * return -EINVAL. */ if (name) index = of_property_match_string(np, "clock-names", name); ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, out_args); if (!ret) break; if (name && index >= 0) break; /* * No matching clock found on this node. If the parent node * has a "clock-ranges" property, then we can try one of its * clocks. */ np = np->parent; if (np && !of_get_property(np, "clock-ranges", NULL)) break; index = 0; } return ret; }
clocksource_sysfs
1393 int error = subsys_system_register(&clocksource_subsys, NULL); (gdb) bt #0 init_clocksource_sysfs () at kernel/time/clocksource.c:1393 #1 0xffffffff80002740 in do_one_initcall (fn=0xffffffff80c0a06c <init_clocksource_sysfs>) at init/main.c:1297 #2 0xffffffff80c011c6 in do_initcall_level (command_line=0xffffffe0023ad640 "root", level=6) at init/main.c:1370 #3 do_initcalls () at init/main.c:1386 #4 do_basic_setup () at init/main.c:1406 #5 kernel_init_freeable () at init/main.c:1609 #6 0xffffffff80b14572 in kernel_init (unused=<optimized out>) at init/main.c:1501 #7 0xffffffff8000378c in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) c Continuing.
[root@centos7 images]# ls /sys/devices/system/clocksource/clocksource0 available_clocksource current_clocksource power subsystem uevent unbind_clocksource [root@centos7 images]# ls /sys/bus/clocksource -al total 0 drwxr-xr-x 4 root root 0 Oct 31 23:51 . drwxr-xr-x 26 root root 0 Sep 27 22:16 .. drwxr-xr-x 2 root root 0 Sep 27 22:16 devices drwxr-xr-x 2 root root 0 Sep 27 22:16 drivers -rw-r--r-- 1 root root 65536 Oct 31 23:39 drivers_autoprobe --w------- 1 root root 65536 Oct 31 23:39 drivers_probe --w------- 1 root root 65536 Oct 31 23:39 uevent [root@centos7 images]# ls /sys/bus/ -al total 0 drwxr-xr-x 26 root root 0 Oct 31 23:51 . dr-xr-xr-x 12 root root 0 Sep 27 22:16 .. drwxr-xr-x 4 root root 0 Sep 27 22:16 acpi drwxr-xr-x 4 root root 0 Sep 27 22:16 amba drwxr-xr-x 4 root root 0 Sep 27 22:16 clockevents drwxr-xr-x 4 root root 0 Oct 31 23:51 clocksource drwxr-xr-x 4 root root 0 Sep 27 22:16 container drwxr-xr-x 4 root root 0 Sep 27 22:16 cpu drwxr-xr-x 4 root root 0 Sep 27 22:16 edac drwxr-xr-x 4 root root 0 Sep 27 22:16 event_source drwxr-xr-x 4 root root 0 Sep 27 22:16 gpio drwxr-xr-x 4 root root 0 Sep 27 22:16 hid drwxr-xr-x 4 root root 0 Sep 27 22:16 i2c drwxr-xr-x 4 root root 0 Sep 27 22:16 mdio_bus drwxr-xr-x 4 root root 0 Sep 27 22:16 node drwxr-xr-x 4 root root 0 Sep 27 22:16 nvmem drwxr-xr-x 5 root root 0 Sep 27 22:16 pci drwxr-xr-x 4 root root 0 Sep 27 22:16 pci_express drwxr-xr-x 4 root root 0 Sep 27 22:16 platform drwxr-xr-x 4 root root 0 Sep 27 22:16 pnp drwxr-xr-x 4 root root 0 Sep 27 22:16 scsi drwxr-xr-x 4 root root 0 Sep 27 22:16 serio drwxr-xr-x 4 root root 0 Sep 27 22:16 spi drwxr-xr-x 4 root root 0 Sep 27 22:16 usb drwxr-xr-x 4 root root 0 Sep 27 22:16 usb-serial drwxr-xr-x 4 root root 0 Sep 27 22:16 workqueue [root@centos7 images]# ls /sys/bus/clocksource/ devices/ drivers/ drivers_autoprobe drivers_probe uevent [root@centos7 images]# ls /sys/bus/clocksource/devices/ -al total 0 drwxr-xr-x 2 root root 0 Oct 31 23:51 . drwxr-xr-x 4 root root 0 Oct 31 23:51 .. lrwxrwxrwx 1 root root 0 Sep 27 22:16 clocksource0 -> ../../../devices/system/clocksource/clocksource0 --链接 [root@centos7 images]#
nit_clocksource_sysfs -->
subsys_system_register
subsys_register
bus_register
kset_register
Breakpoint 4, 0xffffffff80747384 in bus_register () at drivers/base/bus.c:1089 1089 err = -ENOMEM; (gdb) bt #0 0xffffffff80747384 in bus_register () at drivers/base/bus.c:1089 #1 0xffffffff80747724 in subsys_register (parent_of_root=0xffffffe0023a7738, groups=0x0, subsys=0xffffffff81891560 <clocksource_subsys>) at drivers/base/bus.c:1083 #2 subsys_system_register (subsys=0xffffffff81891560 <clocksource_subsys>, groups=0x0) at drivers/base/bus.c:1139 #3 0xffffffff80c0a096 in init_clocksource_sysfs () at kernel/time/clocksource.c:1393 #4 0xffffffff80002740 in do_one_initcall (fn=0xffffffff80c0a06c <init_clocksource_sysfs>) at init/main.c:1297 #5 0xffffffff80c011c6 in do_initcall_level (command_line=0xffffffe0023ad640 "root", level=6) at init/main.c:1370 #6 do_initcalls () at init/main.c:1386 #7 do_basic_setup () at init/main.c:1406 #8 kernel_init_freeable () at init/main.c:1609 #9 0xffffffff80b14572 in kernel_init (unused=<optimized out>) at init/main.c:1501 #10 0xffffffff8000378c in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) list 1084 if (err < 0) 1085 return err; 1086 1087 dev = kzalloc(sizeof(struct device), GFP_KERNEL); 1088 if (!dev) { 1089 err = -ENOMEM; 1090 goto err_dev; 1091 } 1092 1093 err = dev_set_name(dev, "%s", subsys->name); (gdb) s Breakpoint 4, bus_register (bus=bus@entry=0xffffffff81891560 <clocksource_subsys>) at ./include/linux/slab.h:591 591 return kmem_cache_alloc_trace( (gdb) list 586 index = kmalloc_index(size); 587 588 if (!index) 589 return ZERO_SIZE_PTR; 590 591 return kmem_cache_alloc_trace( 592 kmalloc_caches[kmalloc_type(flags)][index], 593 flags, size); 594 #endif 595 } (gdb) n 787 priv = kzalloc(sizeof(struct subsys_private), GFP_KERNEL); (gdb) n 788 if (!priv) (gdb) n 791 priv->bus = bus; (gdb) p *bus $1 = {name = 0xffffffff81320050 "clocksource", dev_name = 0xffffffff81320050 "clocksource", dev_root = 0x0, bus_groups = 0x0, dev_groups = 0x0, drv_groups = 0x0, match = 0x0, uevent = 0x0, probe = 0x0, sync_state = 0x0, remove = 0x0, shutdown = 0x0, online = 0x0, offline = 0x0, suspend = 0x0, resume = 0x0, num_vf = 0x0, dma_configure = 0x0, pm = 0x0, iommu_ops = 0x0, p = 0x0, lock_key = {<No data fields>}, need_parent_lock = false} (gdb) n 794 BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier); (gdb) n 796 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); (gdb) p bus->name $2 = 0xffffffff81320050 "clocksource" (gdb) n 797 if (retval) (gdb) n 800 priv->subsys.kobj.kset = bus_kset; (gdb) p bus_kset $3 = (struct kset *) 0xffffffe0023a76c0 (gdb) p *bus_kset $4 = {list = {next = 0xffffffe0023a5c20, prev = 0xffffffe002509020}, list_lock = {{rlock = {raw_lock = {lock = 0}}}}, kobj = {name = 0xffffffff8133e010 "bus", entry = {next = 0xffffffe0023a76e0, prev = 0xffffffe0023a76e0}, parent = 0x0, kset = 0x0, ktype = 0xffffffff81964640 <kset_ktype>, sd = 0xffffffe0023a8f80, kref = {refcount = {refs = {counter = 41}}}, state_initialized = 1, state_in_sysfs = 1, state_add_uevent_sent = 0, state_remove_uevent_sent = 0, uevent_suppress = 0}, uevent_ops = 0xffffffff810b59c8 <bus_uevent_ops>} (gdb) n 801 priv->subsys.kobj.ktype = &bus_ktype; (gdb) n 802 priv->drivers_autoprobe = 1; (gdb) n 804 retval = kset_register(&priv->subsys); (gdb) n 805 if (retval) (gdb) n 808 retval = bus_create_file(bus, &bus_attr_uevent); (gdb) n 809 if (retval) (gdb) n 812 priv->devices_kset = kset_create_and_add("devices", NULL, (gdb) n 814 if (!priv->devices_kset) { (gdb) n 819 priv->drivers_kset = kset_create_and_add("drivers", NULL, (gdb) n 821 if (!priv->drivers_kset) { (gdb) n 826 INIT_LIST_HEAD(&priv->interfaces); (gdb) n 827 __mutex_init(&priv->mutex, "subsys mutex", key); (gdb) n 828 klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put); (gdb) n 829 klist_init(&priv->klist_drivers, NULL, NULL); (gdb) n 831 retval = add_probe_files(bus); (gdb) n 835 retval = bus_add_groups(bus, bus->bus_groups); (gdb) c Continuing.
static int __init init_clocksource_sysfs(void) { int error = subsys_system_register(&clocksource_subsys, NULL); if (!error) error = device_register(&device_clocksource); return error; }
/** * subsys_system_register - register a subsystem at /sys/devices/system/ * @subsys: system subsystem * @groups: default attributes for the root device * * All 'system' subsystems have a /sys/devices/system/<name> root device * with the name of the subsystem. The root device can carry subsystem- * wide attributes. All registered devices are below this single root * device and are named after the subsystem with a simple enumeration * number appended. The registered devices are not explicitly named; * only 'id' in the device needs to be set. * * Do not use this interface for anything new, it exists for compatibility * with bad ideas only. New subsystems should use plain subsystems; and * add the subsystem-wide attributes should be added to the subsystem * directory itself and not some create fake root-device placed in * /sys/devices/system/<name>. */ int subsys_system_register(struct bus_type *subsys, const struct attribute_group **groups) { return subsys_register(subsys, groups, &system_kset->kobj); }
__clocksource_register_scale
(gdb) target remote:1234 Remote debugging using :1234 0x0000000000001000 in ?? () (gdb) b clocksource_register_scale Function "clocksource_register_scale" not defined. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) b __clocksource_register_scale Breakpoint 5 at 0xffffffff8008370c: __clocksource_register_scale. (2 locations) (gdb) c Continuing. Breakpoint 5, 0xffffffff8008370c in __clocksource_register_scale () at kernel/time/clocksource.c:864 864 max_cycles = min(max_cycles, mask); (gdb) bt #0 0xffffffff8008370c in __clocksource_register_scale () at kernel/time/clocksource.c:864 #1 0xffffffff80c2b5f8 in clocksource_register_hz (hz=<optimized out>, cs=0xffffffff819a3f58 <riscv_clocksource>) at ./include/linux/clocksource.h:246 #2 riscv_timer_init_dt (n=<optimized out>) at drivers/clocksource/timer-riscv.c:140 #3 0xffffffff80c2b3d6 in timer_probe () at drivers/clocksource/timer-probe.c:30 #4 0xffffffff80c0367c in time_init () at arch/riscv/kernel/time.c:31 #5 0xffffffff80c00d38 in start_kernel () at init/main.c:1041 #6 0xffffffff80001182 in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 5, __clocksource_register_scale (cs=0xffffffff819a3f58 <riscv_clocksource>, scale=1, freq=10000000) at kernel/time/clocksource.c:1122 1122 clocksource_arch_init(cs); (gdb) bt #0 __clocksource_register_scale (cs=0xffffffff819a3f58 <riscv_clocksource>, scale=1, freq=10000000) at kernel/time/clocksource.c:1122 #1 0xffffffff80c2b5f8 in clocksource_register_hz (hz=<optimized out>, cs=0xffffffff819a3f58 <riscv_clocksource>) at ./include/linux/clocksource.h:246 #2 riscv_timer_init_dt (n=<optimized out>) at drivers/clocksource/timer-riscv.c:140 #3 0xffffffff80c2b3d6 in timer_probe () at drivers/clocksource/timer-probe.c:30 #4 0xffffffff80c0367c in time_init () at arch/riscv/kernel/time.c:31 #5 0xffffffff80c00d38 in start_kernel () at init/main.c:1041 #6 0xffffffff80001182 in _start_kernel () at arch/riscv/kernel/head.S:327 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 5, 0xffffffff8008370c in __clocksource_register_scale () at kernel/time/clocksource.c:864 864 max_cycles = min(max_cycles, mask); (gdb) bt #0 0xffffffff8008370c in __clocksource_register_scale () at kernel/time/clocksource.c:864 #1 0xffffffff80c0a1b0 in __clocksource_register (cs=0xffffffff81891870 <clocksource_jiffies>) at ./include/linux/clocksource.h:241 #2 init_jiffies_clocksource () at kernel/time/jiffies.c:85 #3 0xffffffff80002740 in do_one_initcall (fn=0xffffffff80c0a184 <init_jiffies_clocksource>) at init/main.c:1297 #4 0xffffffff80c011c6 in do_initcall_level (command_line=0xffffffe0023ad640 "root", level=1) at init/main.c:1370 #5 do_initcalls () at init/main.c:1386 #6 do_basic_setup () at init/main.c:1406 #7 kernel_init_freeable () at init/main.c:1609 #8 0xffffffff80b14572 in kernel_init (unused=<optimized out>) at init/main.c:1501 #9 0xffffffff8000378c in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) c Continuing. Breakpoint 5, __clocksource_register_scale (cs=0xffffffff81891870 <clocksource_jiffies>, scale=1, freq=0) at kernel/time/clocksource.c:1122 1122 clocksource_arch_init(cs); (gdb) bt #0 __clocksource_register_scale (cs=0xffffffff81891870 <clocksource_jiffies>, scale=1, freq=0) at kernel/time/clocksource.c:1122 #1 0xffffffff80c0a1b0 in __clocksource_register (cs=0xffffffff81891870 <clocksource_jiffies>) at ./include/linux/clocksource.h:241 #2 init_jiffies_clocksource () at kernel/time/jiffies.c:85 #3 0xffffffff80002740 in do_one_initcall (fn=0xffffffff80c0a184 <init_jiffies_clocksource>) at init/main.c:1297 #4 0xffffffff80c011c6 in do_initcall_level (command_line=0xffffffe0023ad640 "root", level=1) at init/main.c:1370 #5 do_initcalls () at init/main.c:1386 #6 do_basic_setup () at init/main.c:1406 #7 kernel_init_freeable () at init/main.c:1609 #8 0xffffffff80b14572 in kernel_init (unused=<optimized out>) at init/main.c:1501 #9 0xffffffff8000378c in handle_exception () at arch/riscv/kernel/entry.S:232 Backtrace stopped: frame did not save the PC (gdb) c Continuing.
# # # cat /sys/devices/system/clocksource/clocksource0/current_clocksource riscv_clocksource # echo 'arm,sp804' > /sys/devices/system/clocksource/clocksource0/current_clock source [ 153.328448] clocksource: Switched to clocksource arm,sp804 # # cat /sys/devices/system/clocksource/clocksource0/current_clocksource arm,sp804 # # date Thu Jan 1 00:02:56 UTC 1970 # # ls #
[时钟管理] arm 时间系统 1
Linux 时钟框架学习笔记
handle_syscall_trace_exit
浙公网安备 33010602011771号