Commit Graph
3061 Commits
Author SHA1 Message Date
Carl Lerche 2effa7ff8a rt: update CurrentThread to use its own Handle (#5023)
This is the next step in the internal runtime refactoring. This patch
updates `CurrentThread` to use `Arc<Handle>` for all of its cross-thread
needs instead of `Arc<Shared>`.

The effect of this change is that the current-thread scheduler only has
a single `Arc` type, which includes the driver handles, keeping all
"shared state" together.
2022-09-16 17:34:09 -07:00
Carl Lerche ebeb78ed40 rt: split internal runtime::Handle concerns (#5022)
The `runtime::Handle` struct is part of the public API but is also used
internally. This has created a bit of tension. An earlier patch made
defined Handle as a private struct in some cases when `rt` is not
enabled.

This patch splits out internal handle concerns into a new
`scheduler::Handle` type, which will only be internal. This also defines
a `Handle` type for each scheduler variant. Eventually, the
per-scheduler `Handle` types will replace the per-scheduler `Spawner`
types, but more work is needed before we can make that change.
2022-09-16 14:05:09 -07:00
Hayden Stainsby b5709baa91 rt: add rng_seed option to runtime::Builder (#4910)
The `tokio::select!` macro polls branches in a random order. While this
is desirable in production, for testing purposes a more deterministic
approach can be useul.

This change adds an additional parameter `rng_seed` to the runtime
`Builder` to set the random number generator seed. This value is then
used to reset the seed on the current thread when the runtime is entered
into (restoring the previous value when the thread leaves the runtime). All
threads created explicitly by the runtime also have a seed set as the
runtime is built. Each thread is set with a seed from a deterministic
sequence.

This guarantees that calls to the `tokio::select!` macro which are
performed in the same order on the same thread will poll branches in the
same order.

Additionally, the peer chosen to attempt to steal work from also uses a
deterministic sequence if `rng_seed` is set.

Both the builder parameter as well as the `RngSeed` struct are marked
unstable initially.
2022-09-16 17:41:09 +02:00
Carl Lerche 9e02759779 rt: create driver::Handle struct (#5018)
Move all individual driver handles into a single `driver::Handle`
struct.
2022-09-15 16:31:55 -07:00
Carl Lerche 198e2d8e79 rt: rename internal runtime::Kind to Scheduler (#5017)
The `runtime::Kind` enum doesn't really represent the runtime flavor,
but is an enumeration of the different scheduler types. This patch
renames the enum to reflect this.

At a later time, it is likely the `Scheduler` enum will be moved to
`tokio::runtime::scheduler`, but that is punted to a later PR.

This rename is to make space for other enums
2022-09-15 15:10:08 -07:00
Carl Lerche 57e08e7147 chore: remove println from tests (#5015)
This patch removes println statements from tests. Some of these were
used to test that types implement `fmt::Debug`. These println statements
have been replaced with an equivalent test that does not output to
STDOUT. The rest of the println statements are most likely left over
from debugging sessions.
2022-09-14 18:43:40 -07:00
Carl Lerche 98e642d234 rt: remove driver drop implementations (#5014)
Currently, drivers are responsible for clean up when they are dropped.
This is possible today because each driver struct holds a reference to
its internal handle.

As part of an effort to decouple drivers from their handles, this patch
removes the drop implementations for the time and IO driver in favor of
having the scheduler explicitly call `shutdown()` as part of its
shutdown process. The scheduler will hold a reference to both the driver
and the driver handles, so in the future, it will be able to pass in the
driver handles as part of the shutdown process.
2022-09-14 15:47:41 -07:00
Carl Lerche 3f379abda4 rt: remove unparker from time driver (#5013)
Currently, the various resource drivers use a layered approach where
each driver contains the next one. When the scheduler calls park on the
top-most driver, it does work then calls park on the inner driver it
holds. The handles do the same with unparking.

This patch is a step towards refactoring the runtime to move away from
the nested approach towards keeping all drivers and handles together in
a single runtime driver/handle. The unparker is removed from the time
handle and placed in the runtime handle and is passed into the time
driver as needed.
2022-09-14 15:38:42 -07:00
Carl Lerche 588408c060 rt: update TimerEntry to use runtime::Handle
The `TimerEntry` struct is the internal integration point for public
time APIs (`sleep`, `interval`, ...) with the time driver. Currently,
`TimerEntry` holds an ref-counted reference to the time driver handle.

This patch replaces the reference to the time driver handle with a
reference to the runtime handle. This is part of a larger effort to
consolate internal handles across the runtime.
2022-09-14 15:38:42 -07:00
Taiki Endo ac1ae2cfbc ci: use latest Valgrind (#4367) 2022-09-14 21:49:32 +09:00
Carl Lerche 56ffea09e5 rt: store driver handles next to scheduler handle (#5008)
In an earlier PR (#4629), driver handles were moved into the scheduler
handle (`Spawner`). This was done to let the multi-threaded scheduler
have direct access to the thread pool spawner.

However, we are now working on a greater decoupling of the runtime
internals. All drivers and schedulers will be peers, stored in a single
thread-local variable, and the scheduler will be passed the full
runtime::Handle. This will achieve the original goal of giving the
scheduler access to the thread-pool while also (hopefully) simplifying
other aspects of the code.
2022-09-13 12:40:46 -07:00
Taiki Endo b891714bdb ci: use --feature-powerset --depth 2 in features check (#5007)
As has been pointed out a few times in the past (e.g., #4036 (comment)), each-feature 
is not sufficient for features check.

Ideally, we'd like to check all combinations of features, but there are too many
combinations. So limit the max number of simultaneous feature flags to 2 by --depth
option. I think this should be sufficient in most cases as @carllerche said in
taiki-e/cargo-hack#58.
2022-09-13 11:05:38 -07:00
Jernej Kos 0fddb765d4 ci: add build test for x86_64-fortanix-unknown-sgx target (#5001) 2022-09-13 15:12:35 +02:00
Alice Ryhl 29e3584c4d ci: don't auto-cancel CI on old commits on master (#5006) 2022-09-13 13:13:27 +02:00
Alice Ryhl 0d68bef7f7 Merge 'tokio-1.21.1' into 'master' 2022-09-13 11:43:54 +02:00
Alice Ryhl dea1cd4995 chore: prepare Tokio v1.21.1 (#5003) tokio-1.21.1 2022-09-13 11:20:59 +02:00
Alice Ryhl e4cbc70279 task: ignore failure to set TLS in LocalSet Drop (#4976) 2022-09-13 08:51:04 +02:00
Alice Ryhl 97e981e797 net: fix dependency resolution for socket2 (#5000) 2022-09-13 08:50:30 +02:00
Carl Lerche 3a4f18b93b rt: remove internal runtime::ToHandle trait (#5002)
The internal `runtime::ToHandle` trait is no longer needed as the
runtime handle is used everywhere now.
2022-09-12 16:18:17 -07:00
Yotam Ofek 1c823093cb codec: fix LengthDelimitedCodec buffer over-reservation (#4997) 2022-09-11 15:58:51 +02:00
Hayden Stainsby 0b1f640308 io: remove reference to missing functions from Registration docs (#4995)
The docs for `Registration::new_with_interest_and_handle` (internal
function) included a reference to two old functions `new_with_interest`
and `new` on the same struct. These functions no longer exist, which
could be confusing.

Since there is currently only a single constructor function on
`Registration`, the misleading text has simply been removed.
2022-09-09 20:36:42 +02:00
Carl Lerche d7b3b33c9c rt: move spawn_blocking methods to blocking mod (#4994)
A few spawn_blocking methods were implemented on a Handle struct that is
intended to hold all runtime driver handles. These methods make more
sense in the blocking module.
2022-09-08 13:38:20 -07:00
Carl Lerche 71b29b9409 rt: remove Handle reference from time driver (#4993)
A step towards the goal of consolidating thread-local variables, this
patch removes the `time::Handle` reference from the time driver struct.
The reference is moved a level up and passed into methods that need it.

The end goal is to have a single `Driver` struct that holds each
sub-driver and a single `Handle` ref-counted struct that holds all the
misc handles. Further work on the time driver is blocked by some other
refactoring that will happen in follow-up patches.
2022-09-08 11:42:08 -07:00
Piotr 3966acf966 io: rewrite immediate_exit_on_error test to use io::Mock (#4984) 2022-09-08 11:39:06 +02:00
Alice Ryhl dfdb550cd4 chore: prepare tokio-util 0.7.4 (#4987) tokio-util-0.7.4 2022-09-08 10:34:23 +02:00
Carl Lerche 99aa8d12b7 rt: rm internal Park,Unpark traits (#4991)
Years ago, Tokio was organized as a cluster of separate crates. This
architecture required a trait to represent "park the thread and do
work.". When all crates were combined into a single crate, the `Park`
and `Unpark` traits remained as internal details.

This patch removes these traits as they are no longer needed. This is in
service of a future refactor that will decouple the various resource
drivers and store them in a single struct instead of nesting them.
However, in the mean time, removing the Park/Unpark traits adds a bit of
messy code to make the conditional compilation work. This code will
(hopefully) be short-lived.
2022-09-07 18:39:45 -07:00
Carl Lerche 2ad347465e rt: minor time driver refactors (#4989)
This patch makes some minor refactors. It renames `ClockTime` to
`TimeSource` since that is how all variables refer to it. It also moves
the type into a new file.

Finally, it moves the `unpark` handle out of the mutex as it does not
need to be there. Note, the call to `unpark` is still called while the
mutex is held, so there is no functional change. Moving it out of the
mutex is in preparation for moving the unpark handle completely out of
the time driver.
2022-09-07 13:24:02 -07:00
Alex Rudy 291fce8de3 io: add error handling example to StreamReader (#4975) 2022-09-07 13:58:06 +00:00
Adam Chalmers 0267516214 net: fix links in UnixStream docs (#4985) 2022-09-07 08:40:55 +00:00
Carl Lerche bbfd34f6a3 rt: move time driver into runtime module (#4983)
This patch moves the time driver into the runtime module. The time driver
is a runtime concern and is only used by the runtime. Moving the drivers
is the first step to cleaning up some Tokio internals. There will be
follow-up patches that integrate the drivers and other runtime concerns
more closely.

This is an internal refactor and should not impact any public APIs.
2022-09-06 14:12:09 -07:00
Alice Ryhl 116fa7c614 task: introduce RcCell helper (#4977) 2022-09-06 13:40:07 +02:00
Hsiang-Cheng Yang 1fd7f82468 task: fix a doc typo in LocalKey::sync_scope (#4971) 2022-09-03 13:57:18 +00:00
Noah Kennedy c2612b446f io: reduce syscalls in poll_write (#4970)
This applies the same optimization made in #4840 to writes.
2022-09-02 15:23:17 -05:00
Alice Ryhl 50795e652e chore: prepare Tokio v1.21.0 (#4967) tokio-1.21.0 2022-09-02 13:51:31 +02:00
Alice Ryhl a6a95bb4a6 wasm: add documentation for wasm support (#4966) 2022-09-02 11:39:38 +02:00
Alice Ryhl ce5d2a466f task: fix some doc and test things related to stabilizing JoinSet (#4965) 2022-09-01 21:39:20 +00:00
Alice Ryhl e5467ca767 tokio: increase LTS duration to one year (#4964) 2022-09-01 21:30:51 +00:00
Jan Behrens 431ec68f93 sync: doc of watch::Sender::send improved (#4959)
Current documentation of `sync::watch::Sender::send` may be intepreted
as the method failing if at some point in past the channel has been
closed because every receiver has been dropped. This isn't true,
however, as the channel could have been reopened by using
`sync::watch::Sender::subscribe`.

This fix clarifies the behavior. Moreover, it is noted that on failure,
the value isn't made available to future subscribers (but returned as
part of the `SendError`).

Fixes #4957.
2022-09-01 21:11:01 +02:00
Alice Ryhl f207e1afe4 tokio: make 1.20.x an LTS release (#4962) 2022-09-01 21:08:31 +02:00
Alice RyhlandTaiki Endo d3cae06b5e wasm: use thread::sleep on non-wasi wasm too (#4963)
Co-authored-by: Taiki Endo <[email protected]>
2022-09-01 16:52:56 +02:00
Alice Ryhl 01ebb0aa29 task: fix warning (#4960) 2022-08-31 15:42:30 +02:00
Jon Kelley adc774bc4f Feature: Add more windows signal handlers (#4924) 2022-08-31 06:29:31 +00:00
TennyZhuang 5a2bc850af task: fix incorrect signature in Builder::spawn_on (#4953) 2022-08-30 09:23:53 +00:00
Vladimir ba93b28033 signal: make SignalKind methods const (#4956) 2022-08-29 19:47:55 +00:00
Clint Frederickson 505cc0901d time: add a comment to Interval::tick example (#4951) 2022-08-27 18:02:56 +00:00
Carl Lerche a3411a412c rt, chore: rename internal scheduler types (#4945)
For historical reasons, the current-thread runtime's scheduler was named
BasicScheduler and the multi-thread runtime's scheduler were named
ThreadPool. This patch renames the schedulers to mirror the runtime
names to increase consistency. This patch also moves the scheduler
implementations into a new `runtime::scheduler` module.
2022-08-26 09:47:19 -07:00
Carl Lerche 218f2629ff rt: move I/O driver into runtime module (#4942)
This patch moves the I/O driver into the runtime module. The I/O driver
is a runtime concern and is only used by the runtime. Moving the driver
is the first step to cleaning up some Tokio internals. There will be
follow-up patches that integrate the I/O driver and other runtime concerns
more closely.

Because `Interest` and `Ready` are public APIs, they were moved to the
top-level `io` module instead of moving the types to `runtime`.

This is an internal refactor and should not impact any public APIs.
2022-08-25 12:58:57 -07:00
Isaac Sikkema a66884a2fb net: add documentation to try_read() for zero-length buffers (#4937) 2022-08-25 09:33:25 +00:00
Carl Lerche b023522a37 rt: add unstable option to disable the LIFO slot (#4936)
The multi-threaded scheduler includes a per-worker LIFO slot to
store the last scheduled task. This can improve certain usage patterns,
especially message passing between tasks. However, this LIFO slot is not
currently stealable.

Eventually, the LIFO slot **will** become stealable. However, as a
stop-gap, this unstable option lets users disable the LIFO task when
doing so improves their application's overall performance.

Refs: #4941
2022-08-24 12:48:30 -07:00
imlk 733931d85f io: add SyncIoBridge::shutdown() (#4938) 2022-08-24 12:18:53 +00:00