-
Notifications
You must be signed in to change notification settings - Fork 2.1k
core/thread_flags: add thread flags group #21254
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
base: master
Are you sure you want to change the base?
Conversation
675f752
to
dcffa32
Compare
dcffa32
to
96840fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, thx :)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
IMO we should avoid cluttering I think something along the lines of:
should work. |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now only a
$ make generate-Makefile.ci -C tests/core/thread_flags_group
is 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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