summary refs log tree commit diff
path: root/src/libstd/rt
AgeCommit message (Collapse)AuthorLines
2013-10-25TidyBrian Anderson-6/+6
2013-10-25minorJason Toffaletti-2/+6
2013-10-25minorJason Toffaletti-2/+2
2013-10-25fix bug introduced by previous clean up. more clean up.Jason Toffaletti-23/+19
2013-10-25clean upJason Toffaletti-36/+38
2013-10-25add padding to prevent false sharingJason Toffaletti-0/+8
2013-10-25add multi-producer multi-consumer bounded queue to use for sleeper listJason Toffaletti-56/+211
2013-10-25add cache line paddingJason Toffaletti-4/+11
2013-10-25lock-free queue for scheduler message queueJason Toffaletti-4/+210
2013-10-25Fire fewer homing missilesAlex Crichton-36/+49
This optimizes the `home_for_io` code path by requiring fewer scheduler operations in some situtations. When moving to your home scheduler, this no longer forces a context switch if you're already on the home scheduler. Instead, the homing code now simply pins you to your current scheduler (making it so you can't be stolen away). If you're not on your home scheduler, then we context switch away, sending you to your home scheduler. When the I/O operation is done, then we also no longer forcibly trigger a context switch. Instead, the action is cased on whether the task is homed or not. If a task does not have a home, then the task is re-flagged as not having a home and no context switch is performed. If a task is homed to the current scheduler, then we don't do anything, and if the task is homed to a foreign scheduler, then it's sent along its merry way. I verified that there are about a third as many `write` syscalls done in print operations now. Libuv uses write to implement async handles, and the homing before and after each I/O operation was triggering a write on these async handles. Additionally, using the terrible benchmark of printing 10k times in a loop, this drives the runtime from 0.6s down to 0.3s (yay!).
2013-10-25auto merge of #10060 : alexcrichton/rust/cached-stdout, r=brsonbors-30/+138
Almost all languages provide some form of buffering of the stdout stream, and this commit adds this feature for rust. A handle to stdout is lazily initialized in the Task structure as a buffered owned Writer trait object. The buffer behavior depends on where stdout is directed to. Like C, this line-buffers the stream when the output goes to a terminal (flushes on newlines), and also like C this uses a fixed-size buffer when output is not directed at a terminal. We may decide the fixed-size buffering is overkill, but it certainly does reduce write syscall counts when piping output elsewhere. This is a *huge* benefit to any code using logging macros or the printing macros. Formatting emits calls to `write` very frequently, and to have each of them backed by a write syscall was very expensive. In a local benchmark of printing 10000 lines of "what" to stdout, I got the following timings: when | terminal | redirected ----------|---------------|-------- before | 0.575s | 0.525s after | 0.197s | 0.013s C | 0.019s | 0.004s I can also confirm that we're buffering the output appropriately in both situtations. We're still far slower than C, but I believe much of that has to do with the "homing" that all tasks due, we're still performing an order of magnitude more write syscalls than C does.
2013-10-25Cache and buffer stdout per-task for printingAlex Crichton-30/+138
Almost all languages provide some form of buffering of the stdout stream, and this commit adds this feature for rust. A handle to stdout is lazily initialized in the Task structure as a buffered owned Writer trait object. The buffer behavior depends on where stdout is directed to. Like C, this line-buffers the stream when the output goes to a terminal (flushes on newlines), and also like C this uses a fixed-size buffer when output is not directed at a terminal. We may decide the fixed-size buffering is overkill, but it certainly does reduce write syscall counts when piping output elsewhere. This is a *huge* benefit to any code using logging macros or the printing macros. Formatting emits calls to `write` very frequently, and to have each of them backed by a write syscall was very expensive. In a local benchmark of printing 10000 lines of "what" to stdout, I got the following timings: when | terminal | redirected ---------------------------------- before | 0.575s | 0.525s after | 0.197s | 0.013s C | 0.019s | 0.004s I can also confirm that we're buffering the output appropriately in both situtations. We're still far slower than C, but I believe much of that has to do with the "homing" that all tasks due, we're still performing an order of magnitude more write syscalls than C does.
2013-10-24Implement a basic event loop built on LittleLockAlex Crichton-14/+316
It's not guaranteed that there will always be an event loop to run, and this implementation will serve as an incredibly basic one which does not provide any I/O, but allows the scheduler to still run. cc #9128
2013-10-24Remove the 'callback_ms' function from EventLoopAlex Crichton-20/+3
This is a peculiar function to require event loops to implement, and it's only used in one spot during tests right now. Instead, a possibly more robust apis for timers should be used rather than requiring all event loops to implement a curious-looking function.
2013-10-24Fix a bug with the scheduler and destructor orderAlex Crichton-1/+11
The PausibleIdleCallback must have some handle into the event loop, and because struct destructors are run in order of top-to-bottom in order of fields, this meant that the event loop was getting destroyed before the idle callback was getting destroyed. I can't confirm that this fixes a problem in how we use libuv, but it does semantically fix a problem for usage with other event loops.
2013-10-24Another round of test fixes and merge conflictsAlex Crichton-139/+222
2013-10-24Bring io::signal up to date with changes to rt::rtioAlex Crichton-79/+75
2013-10-24wrapping libuv signal for use in RustDo Nhat Minh-0/+374
descriptive names easier-to-use api reorganize and document
2013-10-24Fixing some tests, adding some pipesAlex Crichton-1/+33
This adds constructors to pipe streams in the new runtime to take ownership of file descriptors, and also fixes a few tests relating to the std::run changes (new errors are raised on io_error and one test is xfail'd).
2013-10-24Migrate std::run to libuv processesAlex Crichton-7/+6
2013-10-24Remove std::io once and for all!Alex Crichton-1/+82
2013-10-24Remove std::io from ebmlAlex Crichton-24/+62
2013-10-24Test fixes and merge conflictsAlex Crichton-54/+92
2013-10-24Move stdin to using libuv's pipes instead of a ttyAlex Crichton-84/+48
I was seeing a lot of weird behavior with stdin behaving as a tty, and it doesn't really quite make sense, so instead this moves to using libuv's pipes instead (which make more sense for stdin specifically). This prevents piping input to rustc hanging forever.
2013-10-24Remove io::read_errorAlex Crichton-44/+38
The general idea is to remove conditions completely from I/O, so in the meantime remove the read_error condition to mean the same thing as the io_error condition.
2013-10-24Stop logging task failure to task loggersAlex Crichton-9/+11
The isn't an ideal patch, and the comment why is in the code. Basically uvio uses task::unkillable which touches the kill flag for a task, and if the task is failing due to mismangement of the kill flag, then there will be serious problems when the task tries to print that it's failing.
2013-10-24Move as much I/O as possible off of native::ioAlex Crichton-99/+159
When uv's TTY I/O is used for the stdio streams, the file descriptors are put into a non-blocking mode. This means that other concurrent writes to the same stream can fail with EAGAIN or EWOULDBLOCK. By all I/O to event-loop I/O, we avoid this error. There is one location which cannot move, which is the runtime's dumb_println function. This was implemented to handle the EAGAIN and EWOULDBLOCK errors and simply retry again and again.
2013-10-24Migrate the last typedefs to ~Trait in rtioAlex Crichton-19/+14
There are no longer any remnants of typedefs, and everything is now built on true trait objects.
2013-10-24Don't attempt to export uv functions directlyAlex Crichton-45/+47
2013-10-24Remove IoFactoryObject for ~IoFactoryAlex Crichton-313/+300
This involved changing a fair amount of code, rooted in how we access the local IoFactory instance. I added a helper method to the rtio module to access the optional local IoFactory. This is different than before in which it was assumed that a local IoFactory was *always* present. Now, a separate io_error is raised when an IoFactory is not present, yet I/O is requested.
2013-10-24Remove rt::io::supportAlex Crichton-158/+83
This removes the PathLike trait associated with this "support module". This is yet another "container of bytes" trait, so I didn't want to duplicate what already exists throughout libstd. In actuality, we're going to pass of C strings to the libuv APIs, so instead the arguments are now bound with the 'ToCStr' trait instead. Additionally, a layer of complexity was removed by immediately converting these type-generic parameters into CStrings to get handed off to libuv apis.
2013-10-24Migrate Rtio objects to true trait objectsAlex Crichton-97/+90
This moves as many as I could over to ~Trait instead of ~Typedef. The only remaining one is the IoFactoryObject which should be coming soon...
2013-10-24Move rt::io::stdio from FileStream to a TTYAlex Crichton-162/+303
We get a little more functionality from libuv for these kinds of streams (things like terminal dimentions), and it also appears to more gracefully handle the stream being a window. Beforehand, if you used stdio and hit CTRL+d on a process, libuv would continually return 0-length successful reads instead of interpreting that the stream was closed. I was hoping to be able to write tests for this, but currently the testing infrastructure doesn't allow tests with a stdin and a stdout, but this has been manually tested! (not that it means much)
2013-10-24Remove unbound pipes from io::pipeAlex Crichton-41/+22
This isn't necessary for creating processes (or at least not right now), and it inherently attempts to expose implementation details.
2013-10-24Address a few XXX comments throughout the runtimeAlex Crichton-12/+20
* Implement Seek for Option<Seek> * Remove outdated comment for io::process * De-pub a component which didn't need to be pub
2013-10-24Finish implementing io::net::addrinfoAlex Crichton-92/+249
This fills in the `hints` structure and exposes libuv's full functionality for doing dns lookups.
2013-10-24Implement io::net::unixAlex Crichton-86/+587
2013-10-23mark some functions as returning !Daniel Micay-1/+1
Closes #10023
2013-10-23Made uv_stat_t.{st_dev, st_ino} public, #9958Ziad Hatahet-2/+2
2013-10-23Merge remote-tracking branch 'upstream/master'Ziad Hatahet-114/+110
2013-10-23auto merge of #9810 : huonw/rust/rand3, r=alexcrichtonbors-2/+2
- Adds the `Sample` and `IndependentSample` traits for generating numbers where there are parameters (e.g. a list of elements to draw from, or the mean/variance of a normal distribution). The former takes `&mut self` and the latter takes `&self` (this is the only difference). - Adds proper `Normal` and `Exp`-onential distributions - Adds `Range` which generates `[lo, hi)` generically & properly (via a new trait) replacing the incorrect behaviour of `Rng.gen_integer_range` (this has become `Rng.gen_range` for convenience, it's far more efficient to use `Range` itself) - Move the `Weighted` struct from `std::rand` to `std::rand::distributions` & improve it - optimisations and docs
2013-10-23auto merge of #10021 : alexcrichton/rust/asm-now-analyzed-correctly, r=luqmanabors-11/+7
We got a snapshot, taking care of a note to myself.
2013-10-22Remove thread-blocking call to `libc::stat` in `Path::stat`Ziad Hatahet-2/+11
Fixes #9958
2013-10-22auto merge of #10020 : mletterle/rust/documentation-fixes, r=thestingerbors-2/+2
I'm planning on doing more updates, but the section in the tutorial stood out at me since the 'rust' tool no longer exists, this should probably be removed to lessen confusion.
2013-10-23std::rand: add distributions::Range for generating [lo, hi).Huon Wilson-2/+2
This reifies the computations required for uniformity done by (the old) `Rng.gen_integer_range` (now Rng.gen_range), so that they can be amortised over many invocations, if it is called in a loop. Also, it makes it correct, but using a trait + impls for each type, rather than trying to coerce `Int` + `u64` to do the right thing. This also makes it more extensible, e.g. big integers could & should implement SampleRange.
2013-10-22Tidy up asm! usage in libstdAlex Crichton-11/+7
2013-10-23Making ai_next field publicreedlepee-1/+1
2013-10-23Removed unnecessary comments and white spaces as suggestedreedlepee-14/+14
2013-10-23Removed Unnecessary comments and white spaces #4386reedlepee-112/+25
2013-10-23Making fields in std and extra : private #4386reedlepee-127/+214