Commit graph

38 commits

Author SHA1 Message Date
François Laignel 59ca466081 ts: log max throttling when creating Context 2022-03-28 08:47:32 +00:00
François Laignel 8eb8ea0e7d ts/rt/Task: use light weight executor blocking on ack or join handle
Previous version used the Context::block_on_or_add_sub_task which
spawns a full-fledged executor with timer and io Reactor for no
reason when we just need to wait for a Receiver or JoinHandle.
2022-03-28 08:47:32 +00:00
François Laignel c1615d01e6 ts/rt/Task: awake the iteration loop when it needs to be aborted
When the iteration loop is throttling, the call to `abort` on the
`loop_abort_handle` returns immediately, but the actual `Future`
for the iteration loop is aborted only when the scheduler throttling
completes. State transitions which requires the loop to be aborted &
which are serialized at the pipeline level can incur long delays.

This commit makes sure the Task Context's scheduler is awaken as soon
as the task loop is aborted.
2022-03-28 08:47:32 +00:00
François Laignel 72d9d3dc58 generic/threadshare: fix for nightly build 2022-02-22 00:18:28 +01:00
François Laignel 422ea740ca Update to gst::_log_macro_
See the details:
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/980
2022-02-21 20:50:01 +01:00
Sebastian Dröge 51f8e963d6 Add SPDX-License-Identifier to all file headers 2022-01-15 21:18:47 +02:00
François Laignel 64dd588734 ts/runtime/scheduler: check must_awake before sleeping 2022-01-05 19:00:00 +01:00
François Laignel 1573522520 ts/runtime: rewrite runnable loop
Previous version relied on a plain loop / match / break because
I experimented different strategies. The while variant is better
for the final solution.
2022-01-05 18:59:43 +01:00
François Laignel 5e4fc8b138 ts/executor: relax the static bound on enter
The function `enter` is executed in a blocking way from the caller's
point of view. This means that we can guaranty that the provided
function and its output will outlive the underlying Scheduler Task
execution. This requires an unsafe call to
`async_task::spawn_unchecked`. See:

https://docs.rs/async-task/latest/async_task/fn.spawn_unchecked.html
2021-12-25 11:25:56 +00:00
François Laignel 6163589ac7 ts/executor: replace tokio with smol-like implementation
The threadshare executor was based on a modified version of tokio
which implemented the throttling strategy in the BasicScheduler.
Upstream tokio codebase has significantly diverged from what it
was when the throttling strategy was implemented making it hard
to follow. This means that we can hardly get updates from the
upstream project and when we cherry pick fixes, we can't reflect
the state of the project on our fork's version. As a consequence,
tools such as cargo-deny can't check for RUSTSEC fixes in our fork.

The smol ecosystem makes it quite easy to implement and maintain
a custom async executor. This MR imports the smol parts that
need modifications to comply with the threadshare model and implements
a throttling executor in place of the tokio fork.

Networking tokio specific types are replaced with Async wrappers
in the spirit of [smol-rs/async-io]. Note however that the Async
wrappers needed modifications in order to use the per thread
Reactor model. This means that higher level upstream networking
crates such as [async-net] can not be used with our Async
implementation.

Based on the example benchmark with ts-udpsrc, performances seem on par
with what we achieved using the tokio fork.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/118

Related to https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/604
2021-12-25 11:25:56 +00:00
François Laignel db9c38aa93 ts/runtime: shuffle some structs to dedicated modules 2021-12-25 11:25:56 +00:00
François Laignel c5ef83d5b0 ts/runtime: use a directory for executor module
This will ease the introduction of other concepts which are required
for our own executor implementation.
2021-12-25 11:25:56 +00:00
François Laignel cd0773662f ts: migrate most tests so that they don't use tokio 2021-12-25 11:25:56 +00:00
François Laignel 27b9f0d868 Improve usability thanks to opt-ops
The crate option-operations simplifies usage when dealing with
`Option`s, which is often the case with `ClockTime`.
2021-10-18 15:09:47 +02:00
François Laignel ed90b338f8 ts: runtime: add delay_for_at_least
The time driver for the threadshare runtime assigns the timer
entries to the nearest throttling time frame so that the timer
fires as close as possible to the expected instant. This means
that the timer might fire before or after the expected instant
(at most `wait / 2` away).

In some cases, we don't want the timer to fire early. The new
function `delay_for_at_least` ensures that the timer is assigned
to the time frame after the expected instant.
2021-09-30 09:00:05 +02:00
Sebastian Dröge 052365ba1a Fix various needless-borrow clippy warnings and others 2021-07-30 13:53:35 +03:00
François Laignel 8f81cb8812 generic: migrate to new ClockTime design 2021-06-05 10:36:21 +02:00
François Laignel 06accc8d98 fix-getters-{def,calls} pass 2021-04-12 15:57:19 +02:00
Sebastian Dröge 39a75632c8 threadshare: Update for glib subclass API cleanups 2021-03-08 12:50:03 +02:00
Sebastian Dröge 3d617371af Update for macro renames 2020-12-20 20:43:45 +02:00
Sebastian Dröge 1c9c22df0c generic: Update to 2018 edition 2020-11-23 10:28:33 +02:00
Sebastian Dröge df6a229f58 Fix or silence various clippy warnings 2020-11-19 15:31:50 +00:00
Sebastian Dröge af0337c26c generic: Update for subclassing API changes 2020-11-15 18:25:42 +02:00
François Laignel 4eacce80a5 threadshare: runtime: simplify a function thanks to clippy 2020-10-20 23:45:01 +02:00
François Laignel 7c3e69bb4a Fix ClockTime comparisons not being Ord and use saturating_sub
See:
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/607
2020-10-20 23:45:01 +02:00
Sebastian Dröge a022bbe260 Fix some new clippy warnings 2020-07-28 18:52:11 +03:00
Sebastian Dröge 9bb3e75fb9 Update to use the new pad builders for safely setting pad functions
Only two uses of unsafely setting the pad functions is left:
- fallbacksrc for overriding the chain function of the proxy pad of a
  ghost pad
- threadshare for overriding the pad functions after creationg, which
  probably needs some fixing at some point
2020-06-22 11:28:19 +03:00
François Laignel dfaf59a59b threadshare: simplify Pad{Src,Sink} implementations
Pad{Src,Sink}[Ref] delegate some functions to their respective
Pad{Src,Sink}Inner. Since they act as smart pointers, we can
safely implement the Deref trait to simplify the implementations.
2020-05-30 08:30:27 +00:00
François Laignel 244f6dd6f7 threadshare: fix Transition naming 2020-05-25 18:31:49 +02:00
François Laignel 725eb0a093 threadshare: spawn StateMachine on the futures::executor::ThreadPool
StateMachines are spawned on a runtime::Context which uses a tokio
runtime. The StateMachine doesn't need all the features from tokio
such as the IO and timers drivers.

This commit makes use of a light-weight futures executor to spawn
the StateMachines.
2020-05-25 18:31:49 +02:00
François Laignel f0793587f6 threadshare/TaskImpl: allow transition hooks to fail...
... and add error handlers for iterate and transitions hooks with
default implementation.
2020-05-25 18:31:49 +02:00
François Laignel 5c9bbc6818 threadshare: Task: reduce memory usage
Using dynamic dispatch instead of monomorphization reduces the lib size
and memory use without affecting CPU nor throughput significantly.
2020-05-25 18:31:49 +02:00
François Laignel 1bea2ad279 threadshare: introduce TaskImpl trait
TaskImpl is the trait for specific Task behaviour. It is the basis
of a new Task model. The main motivation for this model is to ease
threadsafe implementations of state transitions.

See https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/298
2020-05-25 18:31:48 +02:00
François Laignel 8e38d861b4 threadshare: save upgrade in Pad functions
When initializing Pad functions in `Pad{Src,Sink}`, we downgrade the
`Pad{Src,Sink}` and upgrade it when necessary. This was implemented
to avoid reference cycles:

`gst::Pad` -> pad function -> `Pad{Src,Sink}` -> `gst::Pad`.

Since `Pad{Src,Sink}` reset the pad functions when dropping, there is
no cycles, so we can use an `Arc<Pad{Src,Sink}>` in the pad functions,
thus saving an `upgrade`.
2020-04-29 16:10:19 +02:00
François Laignel 26634f591a threadshare: build Pad{Src,Sink} with handlers
Handlers for `Pad{Src,Sink}` are assigned when `prepare` is called
which prevents them from handling pre-prepare queries.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/247
2020-04-29 16:08:16 +02:00
Sebastian Dröge 5a7fcfad7f Fix various new clippy warnings with clippy 1.43 2020-04-24 13:55:01 +03:00
Sebastian Dröge 5ad93604ef threadshare: Call gst::init() in all tests 2020-04-13 15:00:27 +03:00
Arun Raghavan dc3c8fd049 Drop gst-plugin- prefix in plugin directory name 2020-04-05 19:10:47 +00:00