core/thread_flags: add thread flags group#21254
Conversation
675f752 to
dcffa32
Compare
dcffa32 to
96840fa
Compare
|
PR adds new feature to Feel free to squash right away. |
|
Why not a bit field for the pids that want to be group members? |
We only expect a handful of waiters. In that case I guess it's probably faster than iterating the bitfield? On the other hand joining and especially leaving would probably be faster with a bitfield... I'll prepare an alternative impl with bitfields. |
96840fa to
b785d24
Compare
I pushed a bitfield version. I'm explicitly not using the RIOT's bitfield implementation as it forces some bit ordering which I don't care about, and as result doesn't use the atomics in |
1b1aaf8 to
52bdfdf
Compare
core/include/thread_flags_group.h
Outdated
| * @brief Thread flags group. | ||
| */ | ||
| typedef struct { | ||
| uint8_t members[MAXTHREADS / 8 + !!(MAXTHREADS % 8)]; /**< members bit field */ |
There was a problem hiding this comment.
hm, does RIOT still want to support >32 threads? ... if yes, this is maybe fine. If not, why not just use uint32_t (atomic) here.
Then, re-use the bitarithm.h functionality (there's e.g., an ffs that would use cpu intrinsics like CLZ under the hood), dropping the need for the loop below.
There was a problem hiding this comment.
I really don't know, but I assumed it's possible to have more that 32 threads. There's currently nothing preventing me from setting e.g. MAXTHREADS to 64.
There was a problem hiding this comment.
Ok I changed the bitfield array to native integer size (by that I mean whatever unsigned int is). If MAXTHREADS <= 32 and if the arch is 32 bit, the whole bitfield arithmetic is compiled out of existence.
ea26c1d to
34bb960
Compare
34bb960 to
42e2442
Compare
3c7fe36 to
2e9af62
Compare
|
Any updates here? |
Looks like other compilers (including the ARM gcc) don't have this either... |
|
Someone (tm) really should fix the CI image... I wonder why it is different for legacy ARM and Cortex M. On Alpine, we are using the same GCC for all ARM systems. |
|
I added a fallback define, my ARM toolchain on Ubuntu 22.04 doesn't have |
maribu
left a comment
There was a problem hiding this comment.
Now only a
$ make generate-Makefile.ci -C tests/core/thread_flags_groupis missing to get it past the CI :)
core/include/thread_flags_group.h
Outdated
| /** | ||
| * @brief Number of bits in unsigned int | ||
| */ | ||
| #define UINT_WIDTH (sizeof(unsigned) * 8) |
There was a problem hiding this comment.
| #define UINT_WIDTH (sizeof(unsigned) * 8) | |
| # define UINT_WIDTH (sizeof(unsigned) * 8) |
core/include/thread_flags_group.h
Outdated
| /* Some compilers don't define UINT_WIDTH */ | ||
| #ifndef UINT_WIDTH |
There was a problem hiding this comment.
The defines are actually provided on the GCC 13.2.1 packed in Ubuntu, but guarded with:
#if (defined __STDC_WANT_IEC_60559_BFP_EXT__ \
|| (defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
This matches what https://en.cppreference.com/w/c/header/limits says.
| /* Some compilers don't define UINT_WIDTH */ | |
| #ifndef UINT_WIDTH | |
| /* UINT_WIDTH is only provided starting with -std=c23 or newer. Until RIOT | |
| * requires C23 as C version, we need provide it by hand when missing. */ | |
| #ifndef UINT_WIDTH |
I also managed to shrink the RAM usage to widen the coverage. |
|
@kaspar030 I think I addressed your suggestions, can we merge this? |
crasbe
left a comment
There was a problem hiding this comment.
I can't really comment on what the code actually does, I don't have much experience with the core and thread internals.
Therefore some general remarks.
ff87cfe to
f99603d
Compare
|
@crasbe sorry I had a really busy week. I think I addressed your suggestions! |
f99603d to
505843b
Compare
505843b to
eb3c8c3
Compare
Contribution description
Adds thread flags group overlay.
From
core/include/thread_flags_group.h:A thread flags group allows setting thread flags for an arbitrary number of
threads (called waiters) at the same time. The waiters can join and leave
the group at any time. An additional advantage is that the signaler (the
"flags setter") is de-coupled from the list of waiters, i.e. it does not
need to know which specific thread must be signaled.
Example (waiter):
Example (signaler):
Testing procedure
Run the test application on:
Issues/PRs references
This construct was suggested by @kaspar030 as alternative for wait queues in #21123