Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: kernel_service: reorg the commands #77668

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

ycsin
Copy link
Member

@ycsin ycsin commented Aug 28, 2024

Split the kernel_service.c into multiple subcommand files, each file would register with the L0 kernel cmd (or L1 thread cmd) based on the dependencies in Kconfig/CMakeLists.txt.

This greatly reduces the number of precompiler directives.


ROM target - before

kernel_service.c                      3074   4.46%  - 
├── _shell_kernel                       40   0.06%  0x8000ef48 rodata
├── cmd_kernel_cycles                   40   0.06%  0x80001002 text
├── cmd_kernel_reboot_cold              10   0.01%  0x80000ff8 text
├── cmd_kernel_reboot_warm              10   0.01%  0x80000fee text
├── cmd_kernel_sleep                    84   0.12%  0x8000102a text
├── cmd_kernel_thread_list              68   0.10%  0x80000d8e text
├── cmd_kernel_thread_mask_clear       144   0.21%  0x80000c6e text
├── cmd_kernel_thread_mask_disable     174   0.25%  0x80000a82 text
├── cmd_kernel_thread_mask_enable      174   0.25%  0x80000b30 text
├── cmd_kernel_thread_mask_enable_all  144   0.21%  0x80000bde text
├── cmd_kernel_thread_pin              204   0.30%  0x800009b6 text
├── cmd_kernel_thread_stacks           150   0.22%  0x80000f58 text
├── cmd_kernel_thread_unwind           144   0.21%  0x80000cfe text
├── cmd_kernel_uptime                  196   0.28%  0x800008d0 text
├── cmd_kernel_version                  32   0.05%  0x80000896 text
├── print_trace_address                 26   0.04%  0x800008b6 text
├── shell_cmd_kernel                     8   0.01%  0x8000e470 shell_root_cmds_area
├── shell_stack_dump                   116   0.17%  0x8000107e text
├── shell_sub_kernel                   280   0.41%  0x8000ef70 rodata
├── shell_sub_kernel_reboot            120   0.17%  0x8000f088 rodata
├── shell_sub_kernel_thread            240   0.35%  0x8000f100 rodata
├── shell_sub_kernel_thread_mask       200   0.29%  0x8000f1f0 rodata
├── shell_tdata_dump                   390   0.57%  0x80000dd2 text
├── sub_kernel                           8   0.01%  0x8000e4c0 tbss
├── sub_kernel_reboot                    8   0.01%  0x8000e4c8 tbss
├── sub_kernel_thread                    8   0.01%  0x8000e4d0 rodata
├── sub_kernel_thread_mask               8   0.01%  0x8000e4d8 rodata
├── thread_is_valid                     34   0.05%  0x80000994 text
└── thread_valid_cb                     14   0.02%  0x80000888 text

ROM target - this PR

kernel_service                                 3058   4.44%  - 
├── cycles.c                                     80   0.12%  - 
│   ├── cmd_kernel_cycles                        40   0.06%  0x80000888 text
│   └── shell_subcmds_kernel_cycles              40   0.06%  0x8000e4c0 shell_subcmds_area
├── kernel_shell.c                               88   0.13%  - 
│   ├── _shell_kernel                            40   0.06%  0x8000e968 rodata
│   ├── kernel_cmds                              40   0.06%  0x8000e498 shell_subcmds_area
│   └── shell_cmd_kernel                          8   0.01%  0x8000e470 shell_root_cmds_area
├── reboot.c                                    188   0.27%  - 
│   ├── cmd_kernel_reboot_cold                   10   0.01%  0x800009f2 text
│   ├── cmd_kernel_reboot_warm                   10   0.01%  0x800009e8 text
│   ├── shell_sub_kernel_reboot                 120   0.17%  0x8000eb48 rodata
│   ├── shell_subcmds_kernel_reboot              40   0.06%  0x8000e4e8 shell_subcmds_area
│   └── sub_kernel_reboot                         8   0.01%  0x8000e6c8 tbss
├── sleep.c                                     124   0.18%  - 
│   ├── cmd_kernel_sleep                         84   0.12%  0x800008b0 text
│   └── shell_subcmds_kernel_sleep               40   0.06%  0x8000e510 shell_subcmds_area
├── thread                                     2270   3.30%  - 
│   ├── list.c                                  498   0.72%  - 
│   │   ├── cmd_kernel_thread_list               68   0.10%  0x80000a2c text
│   │   ├── shell_subcmds_thread_list            40   0.06%  0x8000e5d8 shell_subcmds_area
│   │   └── shell_tdata_dump                    390   0.57%  0x80000a70 text
│   ├── mask.c                                  884   1.28%  - 
│   │   ├── cmd_kernel_thread_mask_clear        144   0.21%  0x80000de2 text
│   │   ├── cmd_kernel_thread_mask_disable      174   0.25%  0x80000bf6 text
│   │   ├── cmd_kernel_thread_mask_enable       174   0.25%  0x80000ca4 text
│   │   ├── cmd_kernel_thread_mask_enable_all   144   0.21%  0x80000d52 text
│   │   ├── shell_sub_kernel_thread_mask        200   0.29%  0x8000f078 rodata
│   │   ├── shell_subcmds_thread_mask            40   0.06%  0x8000e600 shell_subcmds_area
│   │   └── sub_kernel_thread_mask                8   0.01%  0x8000e6d0 tbss
│   ├── pin.c                                   244   0.35%  - 
│   │   ├── cmd_kernel_thread_pin               204   0.30%  0x80000e72 text
│   │   └── shell_subcmds_thread_pin             40   0.06%  0x8000e628 shell_subcmds_area
│   ├── stacks.c                                306   0.44%  - 
│   │   ├── cmd_kernel_thread_stacks            150   0.22%  0x80000f3e text
│   │   ├── shell_stack_dump                    116   0.17%  0x80000fd4 text
│   │   └── shell_subcmds_thread_stacks          40   0.06%  0x8000e650 shell_subcmds_area
│   ├── thread.c                                128   0.19%  - 
│   │   ├── shell_subcmds_kernel_thread          40   0.06%  0x8000e538 shell_subcmds_area
│   │   ├── sub_kernel_thread                    40   0.06%  0x8000e5b0 shell_subcmds_area
│   │   ├── thread_valid_cb                      14   0.02%  0x800009fc text
│   │   └── z_thread_is_valid                    34   0.05%  0x80000a0a text
│   └── unwind.c                                210   0.31%  - 
│       ├── cmd_kernel_thread_unwind            144   0.21%  0x80001062 text
│       ├── print_trace_address                  26   0.04%  0x80001048 text
│       └── shell_subcmds_thread_unwind          40   0.06%  0x8000e678 shell_subcmds_area
├── uptime.c                                    236   0.34%  - 
│   ├── cmd_kernel_uptime                       196   0.28%  0x80000904 text
│   └── shell_subcmds_kernel_uptime              40   0.06%  0x8000e560 shell_subcmds_area
└── version.c                                    72   0.10%  - 
    ├── cmd_kernel_version                       32   0.05%  0x800009c8 text
    └── shell_subcmds_kernel_version             40   0.06%  0x8000e588 shell_subcmds_area

zephyr.bin size is the same before and after this PR:

west build -b qemu_riscv64_smp -p always zephyr/samples/hello_world -- -DCONFIG_SHELL=y -DCONFIG_BUILD_OUTPUT_BIN=y

-rwxr-xr-x@  1 ycsin  staff    84764 Sep 12 15:53 zephyr.bin

@ycsin ycsin force-pushed the pr/kernel_service-reorg branch 3 times, most recently from 3b5cadc to 6b94ce8 Compare August 31, 2024 18:32
@ycsin ycsin marked this pull request as ready for review September 2, 2024 09:03
@zephyrbot zephyrbot added the area: Shell Shell subsystem label Sep 2, 2024
jakub-uC
jakub-uC previously approved these changes Sep 3, 2024
Copy link
Contributor

@jakub-uC jakub-uC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from a shell perspective, but perhaps a kernel maintainer might want to comment on it?

@ycsin ycsin requested review from andyross, dcpleung, nashif and carlescufi and removed request for carlescufi September 3, 2024 17:07
Split the `kernel_service.c` into multiple subcommand files,
each file would register with the main `kernel` cmd based on
the dependencies in Kconfig/CMakeLists.txt.

This greatly reduces the number of precompiler directives.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
Parts related to the thread runtime stats are somewhat
standalone, refactor it out instead of having two #ifdef
and two places.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
@ycsin
Copy link
Member Author

ycsin commented Sep 12, 2024

Rebased to solve merge conflict

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here because I was summoned, though I'll admit that she'll isn't really my strongest area. This looks like good cleanup though.

@nashif nashif merged commit aa9446c into zephyrproject-rtos:main Sep 18, 2024
24 checks passed
@ycsin ycsin deleted the pr/kernel_service-reorg branch September 18, 2024 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants