I created a nice module on top of the ChibiOS event system that makes it super easy to register/unregister events, associate callbacks, send notifications to different places (sdcard file, console, etc). all with minimal boilerplate. A single thread listens to all the events and serves them up accordingly. I assumed 32 events would be more than enough, but now it's looking like I might run out of events at some point and want to explore my options.
As I understand it, a single thread can only wait on a max of 32 unique events at a time if you need to be able to tell which event woke the thread up and retrieve its flags. (If I'm wrong about this there is probably no reason to continue reading...I need to go read the docs again) This means I really have two options if I want to continue using my event module in the same way I have been:
1. Have two separate threads that pretty much do the exact same thing, only one thread is responsible for events with ids 0-31, while the other thread listens for a separate set of 32 threads. When registering an event with my module, I'd need to specify which of the two threads to associate it with.
2. Change the event_mask_t type to an uint64_t. This would double the number of events I could register and would require no other modification to my module. I'm just wondering if making such a change is going to kill performance or create other issues I'm not aware of. My target board is a 32bit cortex M4f, so while I'm aware a few extra instructions would be required to operate on a 64 bit mask, it doesn't seem like it would make a huge difference in performance and I'm not concerned about the extra memory requirements.
Obviously I can't really know the performance implications of #2 without benchmarking it, but I wanted to see if anybody else has tried this or can definitively say "bad idea", in which case I'll skip the testing and start implementing #1.
Bad idea to change event_mask_t to uint64_t?
Moderators: RoccoMarco, lbednarz, tfAteba
-
jayalfredprufrock
- Posts: 36
- Joined: Tue Jan 13, 2015 6:33 am
- Has thanked: 8 times
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Bad idea to change event_mask_t to uint64_t?
Hi,
I never tested uint64_t for events, just try it and look at code size, I expect size should not grow much because those types are only used with logic operations.
Of course there will be a performance hit for event-related operations.
Giovanni
I never tested uint64_t for events, just try it and look at code size, I expect size should not grow much because those types are only used with logic operations.
Of course there will be a performance hit for event-related operations.
Giovanni