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

Async external events support #22

Open
mryndzionek opened this issue May 9, 2024 · 4 comments
Open

Async external events support #22

mryndzionek opened this issue May 9, 2024 · 4 comments

Comments

@mryndzionek
Copy link

Hello,

Would it be possible to add more generic support for external events? I tried to hook-up timer events based on epoll and timerfd. It seems however that the method showed in the external_events.py doesn't work for purely async events (e.g. for bthreads that start just waiting for an async event, etc). There is no way then to tell when to send an Idle event. Would it be possible to add a callback run here? Then also the bthread ending detection would have to be adjusted (i.e. based on the generator/continuation actually ending, not the absence of events).

@tomyaacov
Copy link
Collaborator

Hi @mryndzionek .
Largely, I am for a more general solution.

For clarity, can you share a small example of a program that uses this kind of external event?
Also, can you comment on how this callback should work?

@mryndzionek
Copy link
Author

Hi @mryndzionek . Largely, I am for a more general solution.

For clarity, can you share a small example of a program that uses this kind of external event? Also, can you comment on how this callback should work?

Hello @tomyaacov, I've found some more info regarding this in different papers. Here is no quote:

The first super-step begins when the system starts. Then, internal b-
thread-driven events are triggered until there are no more such events
to trigger. At this point the behavioral system halts, all b-threads are inside a
bSync method call, and the system is waiting for an external event. When an
external event occurs and introduced as a behavioral one, it marks the begin-
ning of a new super-step, which then continues until there are no events to
trigger, and so on. We propose a convention, whereby external events are not introduced as behavioral events as
long as there are other internal events to trigger. In LSC, this is enforced by
the Play-Engine and PlayGo tools. In BPJ, the programmer can assign to
a b-thread that introduces external events a priority lower than that of any
b-thread that may request other (internal) events at the same time. One may
view the super-step as an ordered sequence of events, which ideally takes
“zero time,” as in Berry’s synchrony hypothesis and in Statecharts, and
similar to hybrid time sets and logical execution time (LET) design.

And another one:

When there are no requested events that are not blocked at a given synchronization
point, no event is triggered, and the system is considered to have completed a superstep.
The next behavioral event, if any, must come from an external module (referred to as a
sensor) reporting some external environment event. As will be explained in Section 3.3, the
sensor-generated event initiates a new superstep which then continues until, again, there are
no events to be selected.

I started developing my own "toy" BP framework in C. Here is how I call the "external event" callback: https://github.com/mryndzionek/toy_bp_c/blob/main/src/bp.c#L207
Here is an example requiring external events and "timeout" events: https://github.com/mryndzionek/toy_bp_c/blob/main/src/pelican.c
You can find a short description here: https://github.com/mryndzionek/toy_bp_c/tree/main?tab=readme-ov-file#a-case-study---pedestrian-light-controlled-crossing-simulation

@tomyaacov
Copy link
Collaborator

Thanks, @mryndzionek, that's clearer now. I agree that this is an important feature we should add.

However, I'm not sure how the callback solution you mentioned works. If you have an idea in mind so maybe you can PR and we can start collaborating on some solution.

Also, I looked at solutions from BPjs, where the b-program has a "WaitForExternalEvents" flag. Maybe we can draw a solution from there.

Regarding the C implementation, are you familiar with BPC? I haven't tried it, and I'm not sure it is currently supported, but you should check it out if you haven't.

@mryndzionek
Copy link
Author

Thanks, @mryndzionek, that's clearer now. I agree that this is an important feature we should add.

However, I'm not sure how the callback solution you mentioned works. If you have an idea in mind so maybe you can PR and we can start collaborating on some solution.

After looking at BPpy a little bit more it seems the focus is more on verification and model checking, so maybe adding a "real time" engine like this is an overkill? The main issue I see is how to efficiently determine if there are only wait events for all the "rich" event definitions possible in BPpy (SMT formulas, etc.). My question then would also be how to "simulate" fully asynchronous, non-deterministic events in BPpy. Using the bp.choice "operator"?

Also, I looked at solutions from BPjs, where the b-program has a "WaitForExternalEvents" flag. Maybe we can draw a solution from there.

yeah, "WaitForExternalEvents" is just a way on enabling the functionality. The functionality itself seems to be what I have in mind and hinges on detecting when the superstep ends (as mentioned above).

Regarding the C implementation, are you familiar with BPC? I haven't tried it, and I'm not sure it is currently supported, but you should check it out if you haven't.

Yes, I've seen BPC, however I would like to have something in pure C and something that doesn't use OS-thread per b-thread (and therefore uses cooperative concurrency).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants