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

Rollup of 31 pull requests #59207

Closed
wants to merge 83 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
6da206b
Add back in MSVC version check for LLVM
alexcrichton Mar 1, 2019
02b0085
appveyor: Use VS2017 for all our images
alexcrichton Nov 13, 2018
e969de8
Fix "Auto-hide item methods documentation" setting
GuillaumeGomez Mar 2, 2019
1a19c46
fs::copy() unix: set file mode early
haraldh Mar 4, 2019
2b49ec0
Move alloc::prelude::* to alloc::prelude::v1, make alloc a subset of std
SimonSapin Mar 5, 2019
1243859
core: ensure VaList passes improper_ctypes lint
dlrobertson Mar 5, 2019
5d1022a
Rename the feature gate for alloc::prelude
SimonSapin Mar 5, 2019
72958ac
std: Spin for a global malloc lock on wasm32
alexcrichton Mar 1, 2019
710988a
MIPS: add r6 support
wzssyqa Mar 5, 2019
5cf5832
fs::copy() set file mode early
haraldh Feb 28, 2019
67eabc6
SGX target: Expose thread id function in os module
Mar 5, 2019
876258b
Default to integrated `rust-lld` linker for UEFI targets
phil-opp Mar 6, 2019
3477939
[CI] Update binutils for powerpc64 and powerpc64le
cuviper Mar 7, 2019
c843fe7
Wrap a long configure line
cuviper Mar 7, 2019
ec91f26
Fix SGX implementations of read/write_vectored.
sfackler Mar 8, 2019
ab8e1d2
Always call read/write from default vectored io methods
sfackler Mar 8, 2019
94a6936
Track embedded-book in the toolstate
kennytm Mar 9, 2019
a4ea084
Avoid some common false positives in intra doc link checking
Manishearth Mar 9, 2019
3a83cb2
Fix ICE in MIR pretty printing
dlrobertson Mar 9, 2019
135b686
Update src/tools/publish_toolstate.py
jamesmunns Mar 10, 2019
d6f5100
Fix tidy
kennytm Mar 10, 2019
4888b1f
we can now skip should_panic tests with the libtest harness
RalfJung Mar 10, 2019
52d9fa8
enabled too many tests
RalfJung Mar 10, 2019
8629fd3
Improvements to comments in libstd, libcore, liballoc.
alexreg Feb 9, 2019
e25df32
consistent naming for duration_float methods and additional f32 methods
newpavlov Mar 11, 2019
35c19c5
move MAX_NANOS_F64/32 to methods
newpavlov Mar 11, 2019
d4b2071
Resolved nits raised in review.
alexreg Mar 11, 2019
02f26e3
Add peer_addr function to UdpSocket
LinusU Mar 11, 2019
980871a
fix tests
newpavlov Mar 11, 2019
197efb0
fix test
newpavlov Mar 11, 2019
78b248d
fix typo
newpavlov Mar 12, 2019
df2dce3
Mark UdpSocket peer_addr unstable w/ tracking issue
LinusU Mar 12, 2019
54bf8e0
Document UdpSocket peer_addr NotConnected error
LinusU Mar 12, 2019
5074489
Unregress using scalar unions in constants.
oli-obk Mar 12, 2019
79695ea
Add test for UdpSocket peer_addr
LinusU Mar 12, 2019
ca32fe4
Fix test names regarding ip version
LinusU Mar 12, 2019
df05fbf
rustc: fix ICE when trait alias has bare Self
seanmonstar Mar 11, 2019
795d307
Suggest return lifetime when there's only one named lifetime
estebank Mar 12, 2019
f923476
review comments
estebank Mar 12, 2019
adbd0a6
Make std time tests more robust for platform differences
Mar 12, 2019
0ea9b58
Suggest adding lifetime to struct field
estebank Mar 13, 2019
266ca31
Stabilize Range*::contains.
smmalis37 Mar 13, 2019
9d938f6
Add test for #55809.
davidtwco Mar 13, 2019
311025e
Fix generic argument lookup for Self
Mar 7, 2019
c37dab7
Revert "Don't generate minification variable if minification disabled"
Manishearth Mar 13, 2019
5abd6d9
add suggestions to invalid macro item error
euclio Mar 11, 2019
88d43a0
Don't run test launching `echo` since that doesn't exist on Windows
Zoxc Mar 14, 2019
41cdf07
Run RustdocUi earlier
Zoxc Mar 14, 2019
ab19e58
Use try blocks in rustc_codegen_ssa
taiki-e Mar 14, 2019
d1fcd86
Update sources.rs
lukaslueg Mar 14, 2019
fa8fd3d
Add support for comma-separated option lists
tmandry Mar 14, 2019
7c59ce9
Add `-Z allow_features=...` flag
tmandry Mar 13, 2019
ad8e2b1
Rollup merge of #58803 - haraldh:fs_copy_fix, r=alexcrichton
kennytm Mar 15, 2019
2bb8c9b
Rollup merge of #58854 - alexcrichton:update-windows, r=Mark-Simulacrum
kennytm Mar 15, 2019
d0a4fac
Rollup merge of #58855 - alexcrichton:wasm-multithreaded-alloc, r=fit…
kennytm Mar 15, 2019
b3c597f
Rollup merge of #58873 - GuillaumeGomez:fix-auto-hide-method-doc, r=Q…
kennytm Mar 15, 2019
237d769
Rollup merge of #58933 - SimonSapin:alloc-prelude-v1, r=Amanieu
kennytm Mar 15, 2019
3d305f9
Rollup merge of #58938 - dlrobertson:fix_58280, r=joshtriplett
kennytm Mar 15, 2019
b072116
Rollup merge of #58941 - wzssyqa:master, r=alexcrichton
kennytm Mar 15, 2019
e0f7f9a
Rollup merge of #58949 - jethrogb:jb/sgx-thread-id, r=joshtriplett
kennytm Mar 15, 2019
4b4707e
Rollup merge of #58976 - phil-opp:patch-2, r=alexcrichton
kennytm Mar 15, 2019
6a0e3cd
Rollup merge of #58986 - cuviper:ppc64-binutils, r=alexcrichton
kennytm Mar 15, 2019
d3893c7
Rollup merge of #59009 - sfackler:fix-sgx-vectors, r=alexcrichton
kennytm Mar 15, 2019
05ad8ba
Rollup merge of #59025 - aoikonomopoulos:issue-57924, r=varkor
kennytm Mar 15, 2019
b0cc65b
Rollup merge of #59036 - dlrobertson:fix_59021, r=estebank
kennytm Mar 15, 2019
5b78001
Rollup merge of #59037 - Manishearth:intra-doc-false, r=QuietMisdreavus
kennytm Mar 15, 2019
cdc2f47
Rollup merge of #59038 - kennytm:track-embedded-book, r=oli-obk
kennytm Mar 15, 2019
3463053
Rollup merge of #59072 - RalfJung:miri-alloc-tests, r=kennytm
kennytm Mar 15, 2019
8a55a86
Rollup merge of #59079 - euclio:macro-semi, r=estebank
kennytm Mar 15, 2019
7267bce
Rollup merge of #59082 - alexreg:cosmetic-2-doc-comments, r=Centril
kennytm Mar 15, 2019
348ee6d
Rollup merge of #59102 - newpavlov:duration_float, r=alexcrichton
kennytm Mar 15, 2019
3672ef7
Rollup merge of #59106 - LinusU:udp-peer-addr, r=kennytm
kennytm Mar 15, 2019
3086e1d
Rollup merge of #59118 - seanmonstar:alias-where-self-ice, r=alexreg
kennytm Mar 15, 2019
7f70db6
Rollup merge of #59139 - oli-obk:unions_are_a_good_thing, r=RalfJung
kennytm Mar 15, 2019
d93e460
Rollup merge of #59146 - estebank:suggest-return-lt, r=varkor
kennytm Mar 15, 2019
ea3c111
Rollup merge of #59147 - jethrogb:jb/time-tests, r=sfackler
kennytm Mar 15, 2019
2a20230
Rollup merge of #59152 - smmalis37:range_contains, r=SimonSapin
kennytm Mar 15, 2019
5c680ee
Rollup merge of #59156 - davidtwco:issue-55809, r=nikomatsakis
kennytm Mar 15, 2019
14ba4d5
Rollup merge of #59158 - Manishearth:fix-minification, r=GuillaumeGomez
kennytm Mar 15, 2019
076be4d
Rollup merge of #59169 - tmandry:allow-features-flag, r=cramertj
kennytm Mar 15, 2019
6d865eb
Rollup merge of #59175 - Zoxc:fix-process-test, r=alexcrichton
kennytm Mar 15, 2019
a2f345e
Rollup merge of #59180 - taiki-e:try_blocks, r=scottmcm
kennytm Mar 15, 2019
f8257ab
Rollup merge of #59185 - lukaslueg:patch-2, r=cramertj
kennytm Mar 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
std: Spin for a global malloc lock on wasm32
There's lots of comments in the code, but the main gist of this commit
is that the acquisition of the global malloc lock on the
`wasm32-unknown-unknown` target when threads are enabled will not spin
on contention rather than block.
  • Loading branch information
alexcrichton committed Mar 5, 2019
commit 72958acd57fb32e0f8027c0d7e76c9a0c7f155d2
95 changes: 80 additions & 15 deletions src/libstd/sys/wasm/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ unsafe impl GlobalAlloc for System {

#[cfg(target_feature = "atomics")]
mod lock {
use crate::arch::wasm32;
use crate::sync::atomic::{AtomicI32, Ordering::SeqCst};

static LOCKED: AtomicI32 = AtomicI32::new(0);
Expand All @@ -61,27 +60,93 @@ mod lock {
if LOCKED.swap(1, SeqCst) == 0 {
return DropLock
}
unsafe {
let r = wasm32::i32_atomic_wait(
&LOCKED as *const AtomicI32 as *mut i32,
1, // expected value
-1, // timeout
);
debug_assert!(r == 0 || r == 1);
}
// Ok so here's where things get a little depressing. At this point
// in time we need to synchronously acquire a lock, but we're
// contending with some other thread. Typically we'd execute some
// form of `i32.atomic.wait` like so:
//
// unsafe {
// let r = core::arch::wasm32::i32_atomic_wait(
// &LOCKED as *const AtomicI32 as *mut i32,
// 1, // expected value
// -1, // timeout
// );
// debug_assert!(r == 0 || r == 1);
// }
//
// Unfortunately though in doing so we would cause issues for the
// main thread. The main thread in a web browser *cannot ever
// block*, no exceptions. This means that the main thread can't
// actually execute the `i32.atomic.wait` instruction.
//
// As a result if we want to work within the context of browsers we
// need to figure out some sort of allocation scheme for the main
// thread where when there's contention on the global malloc lock we
// do... something.
//
// Possible ideas include:
//
// 1. Attempt to acquire the global lock. If it fails, fall back to
// memory allocation via `memory.grow`. Later just ... somehow
// ... inject this raw page back into the main allocator as it
// gets sliced up over time. This strategy has the downside of
// forcing allocation of a page to happen whenever the main
// thread contents with other threads, which is unfortunate.
//
// 2. Maintain a form of "two level" allocator scheme where the main
// thread has its own allocator. Somehow this allocator would
// also be balanced with a global allocator, not only to have
// allocations cross between threads but also to ensure that the
// two allocators stay "balanced" in terms of free'd memory and
// such. This, however, seems significantly complicated.
//
// Out of a lack of other ideas, the current strategy implemented
// here is to simply spin. Typical spin loop algorithms have some
// form of "hint" here to the CPU that it's what we're doing to
// ensure that the CPU doesn't get too hot, but wasm doesn't have
// such an instruction.
//
// To be clear, spinning here is not a great solution.
// Another thread with the lock may take quite a long time to wake
// up. For example it could be in `memory.grow` or it could be
// evicted from the CPU for a timeslice like 10ms. For these periods
// of time our thread will "helpfully" sit here and eat CPU time
// until it itself is evicted or the lock holder finishes. This
// means we're just burning and wasting CPU time to no one's
// benefit.
//
// Spinning does have the nice properties, though, of being
// semantically correct, being fair to all threads for memory
// allocation, and being simple enough to implement.
//
// This will surely (hopefully) be replaced in the future with a
// real memory allocator that can handle the restriction of the main
// thread.
//
//
// FIXME: We can also possibly add an optimization here to detect
// when a thread is the main thread or not and block on all
// non-main-thread threads. Currently, however, we have no way
// of knowing which wasm thread is on the browser main thread, but
// if we could figure out we could at least somewhat mitigate the
// cost of this spinning.
}
}

impl Drop for DropLock {
fn drop(&mut self) {
let r = LOCKED.swap(0, SeqCst);
debug_assert_eq!(r, 1);
unsafe {
wasm32::atomic_notify(
&LOCKED as *const AtomicI32 as *mut i32,
1, // only one thread
);
}

// Note that due to the above logic we don't actually need to wake
// anyone up, but if we did it'd likely look something like this:
//
// unsafe {
// core::arch::wasm32::atomic_notify(
// &LOCKED as *const AtomicI32 as *mut i32,
// 1, // only one thread
// );
// }
}
}
}
Expand Down