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

refac(melpomene): run TCP serial driver on Tokio #20

Merged
merged 2 commits into from
Jul 15, 2022
Merged

Conversation

hawkw
Copy link
Contributor

@hawkw hawkw commented Jul 15, 2022

This branch rewrites the TCP serial port simulated driver to run in
Melpomene's Tokio runtime, rather than spawning its own thread. This
should make Melpomene a bit more efficient, since the runtime thread can
run other simulated drivers while the serial driver task is waiting for
IO, instead of doing a bunch of little sleeps.

I think this shouldn't result in any real behavioral change, although
I haven't tested it super extensively. If I open crowtty and then kill
it after a while, Melpomene still sees the TCP stream
disconnection...but I wasn't sure how I was supposed to actually start
the simulated serial port after launching crowtty? Any suggestions on
further testing would be appreciated! :)

@hawkw hawkw requested a review from jamesmunns July 15, 2022 17:10
@jamesmunns
Copy link
Contributor

Something is causing the TCP task to be polled constantly, I sent you a message in matrix with a screencap video

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw
Copy link
Contributor Author

hawkw commented Jul 15, 2022

Something is causing the TCP task to be polled constantly, I sent you a message in matrix with a screencap video

Yup, just fixed that --- that's my fault for copying the blocking code too religiously. 6402f28 fixes that.

I also figured out how to use crowtty immediately after opening the PR, so I noticed the issue as soon as I ran with trace logging.

@jamesmunns
Copy link
Contributor

Awesome, thanks! Can confirm it looks good to me.

Also, if you want to break this into two tasks, that's totally fine with me. The BidiHandles have a .split() method that will give you the producer and consumer halves separately to give to each task.

Copy link
Contributor

@jamesmunns jamesmunns left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@hawkw hawkw merged commit 09ef159 into main Jul 15, 2022
@jamesmunns jamesmunns deleted the eliza/tokio-serial branch July 17, 2022 00:01
jamesmunns pushed a commit that referenced this pull request Jun 4, 2023
The `Forth` and `AsyncForth` types are `!Send`. This makes them
difficult to use with the latest `maitake`, which requires futures be
`Send` in order to be spawned as a task.

These types are `!Send` because they contain raw pointers to the buffer
regions provided when the VM is constructed. I think they can be made
`Send` (and `Sync`), based on the rationale that the unsafety is in the
invariants of calling `Forth::new` --- if the VM is sent across a thread
boundary, the buffer regions provided to `Forth::new` must travel with
it. Thus, `Forth::new` should still be unsafe, but the VM *can* be
`Send` if `Forth::new`'s invariants are upheld.

Alternatively, we could solve this by wrapping `Forth` in a type which
has ownership over the buffers plus a deallocation callback for those
buffers, instead. This would be similar to `LBForth` but without the use
of `Box`. That type could always be `Send` and `Sync`, without the
caveats I mentioned above.
@jamesmunns jamesmunns added platform: melpomene Specific to the Melpomene simulator platform area: drivers Related to driver implementation for hardware devices. labels Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: drivers Related to driver implementation for hardware devices. platform: melpomene Specific to the Melpomene simulator platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants