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

sys: preprocessor successor module #18299

Merged
merged 6 commits into from
Oct 17, 2022

Conversation

fabian18
Copy link
Contributor

@fabian18 fabian18 commented Jul 6, 2022

Contribution description

Generate a header file, containing successor definitions up to a fixed maximum.
This allows to use the preprocessor to compute the successor of a number and is useful to construct priority values for auto_init.
This is similar to boost preprocessor arithmetik.

Testing procedure

See usage in tests/external_module_dirs/external_modules/external_module/external_module.c

CFLAGS+=-DCONFIG_AUTO_INIT_ENABLE_DEBUG=1 BOARD=nucleo-f767zi make flash term

2022-07-06 09:39:31,837 # auto_init: ztimer_init (1010)
2022-07-06 09:39:31,840 # auto_init: auto_init_random (1040)
2022-07-06 09:39:31,844 # auto_init: auto_init_external_module (1041)
2022-07-06 09:39:31,847 # auto_init: auto_init_miot_mtd (1249)
2022-07-06 09:39:31,851 # auto_init: auto_init_miot_node (1359)
2022-07-06 09:39:31,860 # main(): This is RIOT! (Version: 2022.07-devel-788-g87bda-preprocessor_successor)
2022-07-06 09:39:31,862 # Message: Linking worked
2022-07-06 09:39:31,863 # Initialization worked!

Issues/PRs references

#18003

@github-actions github-actions bot added Area: doc Area: Documentation Area: sys Area: System Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools labels Jul 6, 2022
@fabian18
Copy link
Contributor Author

fabian18 commented Jul 6, 2022

@fjmolinas could be interested

@maribu maribu self-requested a review July 6, 2022 10:36
@maribu
Copy link
Member

maribu commented Oct 12, 2022

I think this is useful for external modules to hook into the auto init code in a more robust fashion.

I think that @gdoffe and many @benpicco may be interested in this. IMO, this only needs a rebase to get in.

#include "auto_init_utils.h"

#define PRIO 1111
#define PRIO AUTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM)

Copy link
Contributor

@benpicco benpicco Oct 12, 2022

Choose a reason for hiding this comment

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

I suppose

#define PRIO2 AUTO_INIT_PRIORITY_AFTER(PRIO)

would not work, right?

But even if limited to in-tree modules as reference, this already is a big improvement.

What if two external modules both chose UTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM)?

Copy link
Member

Choose a reason for hiding this comment

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

The sorting is done by XFA alphabetically. The priorities just prefix numbers to the symbol name. So symbol 1337_foo would always come after 1337_bar, because b < f.

This may be good enough if both foo and bar really only care to be called after random is initialized and have no interdependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#define PRIO2 AUTO_INIT_PRIORITY_AFTER(PRIO)

That’s also possible. Note the priority is 1042 instead of 1041. And note the alphabetic order if some modules have the same priority.

diff --git a/tests/external_module_dirs/external_modules/external_module/external_module.c b/tests/external_module_dirs/external_modules/external_module/external_module.c
index f520d66631..351fa55526 100644
--- a/tests/external_module_dirs/external_modules/external_module/external_module.c
+++ b/tests/external_module_dirs/external_modules/external_module/external_module.c
@@ -23,9 +23,16 @@
 #include "auto_init_priorities.h"
 #include "auto_init_utils.h"
 
+void bauto_init_external_module(void)
+{
+    external_module_initialized = true;
+}
+
 #define PRIO AUTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM)
+#define PRIO2 AUTO_INIT_PRIORITY_AFTER(PRIO)
 
-AUTO_INIT(auto_init_external_module, PRIO);
+AUTO_INIT(bauto_init_external_module, PRIO2);
+AUTO_INIT(auto_init_external_module, PRIO2);
 
 bool external_module_initialized = false;
 char *external_module_message = "Linking worked";

tests/external_module_dirs/bin/miot-nucleo-f767zi/tests_external_module_dirs.map

 .roxfa.auto_init_xfa.5_1042
                0x0000000008003cc0       0x18 /home/fabian/forks/RIOT/tests/external_module_dirs/bin/miot-nucleo-f767zi/external_module/external_module.o
                0x0000000008003cc0                auto_init_xfa_auto_init_external_module
                0x0000000008003ccc                auto_init_xfa_bauto_init_external_module

tests/external_module_dirs

Type '/exit' to exit.
2022-10-13 17:48:25,548 # auto_init: ztimer_init (1010)
2022-10-13 17:48:25,551 # auto_init: auto_init_random (1040)
2022-10-13 17:48:25,555 # auto_init: auto_init_external_module (1042)
2022-10-13 17:48:25,559 # auto_init: bauto_init_external_module (1042)
2022-10-13 17:48:25,562 # auto_init: auto_init_miot_mtd (1249)
2022-10-13 17:48:25,566 # auto_init: auto_init_miot_node (1359)
2022-10-13 17:48:25,573 # main(): This is RIOT! (Version: 2022.07-devel-790-g44a6e-preprocessor_successor)
2022-10-13 17:48:25,575 # Message: Linking worked
2022-10-13 17:48:25,577 # Initialization worked!
2022-10-13 17:48:49,627 # Exiting Pyterm

@benpicco
Copy link
Contributor

Please rebase & squash

@fabian18 fabian18 force-pushed the preprocessor_successor branch from 44a6e7c to 86f2477 Compare October 13, 2022 16:08
@fabian18
Copy link
Contributor Author

Oops forgot the rebase ...

@fabian18 fabian18 force-pushed the preprocessor_successor branch from 86f2477 to c6363e3 Compare October 13, 2022 16:16
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

This is some dark magic, but the benefits are clearly worth it.

@fabian18 fabian18 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 13, 2022
@riot-ci
Copy link

riot-ci commented Oct 13, 2022

Murdock results

✔️ PASSED

fefd8ba sys/preprocessor: add Kconfig file

Success Failures Total Runtime
1983 0 1983 07m:47s

Artifacts

This only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now.

@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 13, 2022
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 14, 2022
@fabian18 fabian18 force-pushed the preprocessor_successor branch from c6363e3 to 2b4b61d Compare October 14, 2022 13:04
@benpicco
Copy link
Contributor

looks like KConfig is still missing

@github-actions github-actions bot added Area: Kconfig Area: Kconfig integration Area: build system Area: Build system labels Oct 16, 2022
@benpicco
Copy link
Contributor

Please squash!

@fabian18 fabian18 force-pushed the preprocessor_successor branch from 9c86bc6 to fefd8ba Compare October 17, 2022 08:38
@benpicco benpicco requested a review from kaspar030 October 17, 2022 14:57
@benpicco benpicco merged commit 0b2fbce into RIOT-OS:master Oct 17, 2022
@fabian18
Copy link
Contributor Author

Thank You!

@kaspar030 kaspar030 added this to the Release 2023.01 milestone Jan 19, 2023
@fabian18 fabian18 deleted the preprocessor_successor branch January 11, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: sys Area: System Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants