From 2be92b5e55bd88eb79fe4eb3971063944e5e32ec Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 22 Nov 2024 11:14:02 +0100 Subject: [PATCH 1/2] rust: bump rust-riot-wrappers --- examples/rust-async/Cargo.lock | 2 +- examples/rust-gcoap/Cargo.lock | 2 +- examples/rust-hello-world/Cargo.lock | 2 +- sys/rust_riotmodules_standalone/Cargo.lock | 2 +- tests/rust_minimal/Cargo.lock | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/rust-async/Cargo.lock b/examples/rust-async/Cargo.lock index 6d5d515cd9d8..7a4db6a77977 100644 --- a/examples/rust-async/Cargo.lock +++ b/examples/rust-async/Cargo.lock @@ -560,7 +560,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.9.1" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#b531cc9ccb9c3cebc99d626b74b0b84a453fe58c" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#cdf3fc2825591d897ffd2f5a43e10ff9dc179b0c" dependencies = [ "bare-metal", "coap-handler", diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index 47760dd54712..a593dfb60dea 100644 --- a/examples/rust-gcoap/Cargo.lock +++ b/examples/rust-gcoap/Cargo.lock @@ -774,7 +774,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.9.1" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#b531cc9ccb9c3cebc99d626b74b0b84a453fe58c" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#cdf3fc2825591d897ffd2f5a43e10ff9dc179b0c" dependencies = [ "bare-metal", "coap-handler", diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock index 9c487cacaee1..c8ef0d2da1b0 100644 --- a/examples/rust-hello-world/Cargo.lock +++ b/examples/rust-hello-world/Cargo.lock @@ -444,7 +444,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.9.1" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#b531cc9ccb9c3cebc99d626b74b0b84a453fe58c" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#cdf3fc2825591d897ffd2f5a43e10ff9dc179b0c" dependencies = [ "bare-metal", "coap-handler", diff --git a/sys/rust_riotmodules_standalone/Cargo.lock b/sys/rust_riotmodules_standalone/Cargo.lock index d0bb56902203..ffb4b5b3cec3 100644 --- a/sys/rust_riotmodules_standalone/Cargo.lock +++ b/sys/rust_riotmodules_standalone/Cargo.lock @@ -519,7 +519,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.9.1" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#b531cc9ccb9c3cebc99d626b74b0b84a453fe58c" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#cdf3fc2825591d897ffd2f5a43e10ff9dc179b0c" dependencies = [ "bare-metal", "coap-handler", diff --git a/tests/rust_minimal/Cargo.lock b/tests/rust_minimal/Cargo.lock index fcf2547a5de1..7ccd215124be 100644 --- a/tests/rust_minimal/Cargo.lock +++ b/tests/rust_minimal/Cargo.lock @@ -444,7 +444,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.9.1" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#b531cc9ccb9c3cebc99d626b74b0b84a453fe58c" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#cdf3fc2825591d897ffd2f5a43e10ff9dc179b0c" dependencies = [ "bare-metal", "coap-handler", From a7e251509d4c33f12cb07eeb70bf888fd3bbc6c3 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 6 Nov 2024 18:22:56 +0100 Subject: [PATCH 2/2] sys/shell: reduce overhead of XFA shell commands We do not need to add an array of pointers to the shell commands, just an array of shell commands is sufficient. This reduced the overhead of XFA by `sizeof(void *)` per command. --- sys/include/shell.h | 7 +++---- sys/shell/shell.c | 15 +++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sys/include/shell.h b/sys/include/shell.h index 72886ca5d41d..0a8e527caf62 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -302,15 +302,14 @@ int shell_parse_file(const shell_command_t *commands, * ``` */ #define SHELL_COMMAND(cmd, help, func) \ - XFA_USE_CONST(shell_command_xfa_t*, shell_commands_xfa); \ + XFA_USE_CONST(shell_command_xfa_t, shell_commands_xfa_v2); \ static FLASH_ATTR const char _xfa_ ## cmd ## _cmd_name[] = #cmd; \ static FLASH_ATTR const char _xfa_ ## cmd ## _cmd_desc[] = help; \ - static const shell_command_xfa_t _xfa_ ## cmd ## _cmd = { \ + XFA_CONST(shell_command_xfa_t, shell_commands_xfa_v2, 0) _xfa_ ## cmd ## _cmd = { \ .name = _xfa_ ## cmd ## _cmd_name, \ .desc = _xfa_ ## cmd ## _cmd_desc, \ .handler = &func \ - }; \ - XFA_ADD_PTR(shell_commands_xfa, cmd, cmd, &_xfa_ ## cmd ## _cmd) + }; #endif /* __cplusplus */ #ifdef __cplusplus diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 2d69b8e3b4a6..5b89a7fd009c 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -36,7 +36,6 @@ #include #include -#include "kernel_defines.h" #include "xfa.h" #include "shell.h" #include "shell_lock.h" @@ -47,7 +46,7 @@ #endif /* define shell command cross file array */ -XFA_INIT_CONST(shell_command_xfa_t*, shell_commands_xfa); +XFA_INIT_CONST(shell_command_xfa_t, shell_commands_xfa_v2); #define ETX '\x03' /** ASCII "End-of-Text", or Ctrl-C */ #define EOT '\x04' /** ASCII "End-of-Transmission", or Ctrl-D */ @@ -102,10 +101,10 @@ static shell_command_handler_t search_commands(const shell_command_t *entry, static shell_command_handler_t search_commands_xfa(char *command) { - unsigned n = XFA_LEN(shell_command_t*, shell_commands_xfa); + unsigned n = XFA_LEN(shell_command_t, shell_commands_xfa_v2); for (unsigned i = 0; i < n; i++) { - const volatile shell_command_xfa_t *entry = shell_commands_xfa[i]; + const volatile shell_command_xfa_t *entry = &shell_commands_xfa_v2[i]; if (flash_strcmp(command, entry->name) == 0) { return entry->handler; } @@ -147,7 +146,7 @@ static void print_commands_json(const shell_command_t *cmd_list) } } - unsigned n = XFA_LEN(shell_command_xfa_t*, shell_commands_xfa); + unsigned n = XFA_LEN(shell_command_xfa_t, shell_commands_xfa_v2); for (unsigned i = 0; i < n; i++) { if (first) { first = false; @@ -155,7 +154,7 @@ static void print_commands_json(const shell_command_t *cmd_list) else { printf(", "); } - const volatile shell_command_xfa_t *entry = shell_commands_xfa[i]; + const volatile shell_command_xfa_t *entry = &shell_commands_xfa_v2[i]; printf("{\"cmd\": \"%s\", \"desc\": \"%s\"}", entry->name, entry->desc); } puts("]}"); @@ -170,9 +169,9 @@ static void print_commands(const shell_command_t *entry) static void print_commands_xfa(void) { - unsigned n = XFA_LEN(shell_command_xfa_t*, shell_commands_xfa); + unsigned n = XFA_LEN(shell_command_xfa_t, shell_commands_xfa_v2); for (unsigned i = 0; i < n; i++) { - const volatile shell_command_xfa_t *entry = shell_commands_xfa[i]; + const volatile shell_command_xfa_t *entry = &shell_commands_xfa_v2[i]; printf("%-20" PRIsflash " %" PRIsflash "\n", entry->name, entry->desc); }