Commit Graph

729 Commits

Author SHA1 Message Date
Avi Kivity
a4c711afd4 future: fix future<>::get0()
Empty tuples don't have a first element.
2015-06-15 11:43:38 +03:00
Avi Kivity
ddaaa315c8 future: add a get0() helper to get the first/only member of the result tuple
Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-15 11:29:02 +03:00
Avi Kivity
053566b3e9 deleter: document 2015-06-15 08:47:44 +03:00
Avi Kivity
1769cb4520 temporary_buffer: document 2015-06-14 23:52:25 +03:00
Avi Kivity
25420a6fdf core: add support for --cpuset command line option
Syntax: [cpu-]cpu(,[cpu-]cpu=)...
Default: all processors
2015-06-14 16:11:31 +03:00
Avi Kivity
f85a2b48bb resource: support using only a subset of a machine's processors
This is useful for running multiple seastar applications on the same
machine, for testing purposes.
2015-06-14 16:10:21 +03:00
Gleb Natapov
361db498d1 semaphore: add wait() with timeout support 2015-06-14 16:02:19 +03:00
Gleb Natapov
f19ba7c334 Add timer move constructor 2015-06-14 16:02:18 +03:00
Gleb Natapov
1b2bf57a2b move timer out of reactor.hh to its own header 2015-06-14 16:02:16 +03:00
Avi Kivity
0b0ad13418 doc: prevent -- from becoming an emdash 2015-06-14 09:20:38 +03:00
Avi Kivity
5251c2523a thread: point out async() as an easy way to launch a thread 2015-06-14 09:14:30 +03:00
Avi Kivity
980a7dc881 thread: more documentation 2015-06-14 08:56:42 +03:00
Avi Kivity
c4756c7622 fstream: fix dropped future in write path
Noticed by Raphael.
2015-06-10 11:48:20 +03:00
Avi Kivity
4bbd90d14c reactor: workaround missing FALLOC_FL_ZERO_RANGE in kernel headers
Prehistoric kernels don't expose FALLOC_FL_ZERO_RANGE, humor them.
2015-06-09 12:53:58 +03:00
Avi Kivity
7a464ddf99 reactor: batch aio
Instead of issuing a system call for every aio, wait for them to accumulate,
and issue them all at once.  This reduces syscall count, and allows the kernel
to batch requests (bu plugging the I/O queues during the call).  A poller is
added so that requests are not delayed too much.

Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-09 12:52:40 +03:00
Avi Kivity
44e35ef545 fstream: preallocation support for file output stream
Preallocate disk blocks in advance of writing.

Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-09 08:44:59 +03:00
Avi Kivity
3ab32ae7a1 file: add allocate() method
Allocate disk blocks in advance of writing to them.

Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-09 08:44:53 +03:00
Raphael S. Carvalho
d864da71fc core: avoid fsyncing output stream twice
For some reason, I added a fsync call when the file underlying the
stream gets truncated. That happens when flushing a file, which
size isn't aligned to the requested DMA buffer.
Instead, fsync should only be called when closing the stream, so this
patch changes the code to do that.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-06-08 11:59:22 +03:00
Tomasz Grabiec
ed3d85d299 foreign_ptr: Use std::pointer_traits<> to get element type 2015-06-07 09:55:33 +03:00
Avi Kivity
27d9446f77 future: fix false-positive when a promise tied to a future that lost its state is destroyed
When a promise that still tracks its future is destroyed, but after
future::get() or future::then() was called, the promise thinks it was
destroyed before generating a value, and fails an assertion.

Fix be detaching the promise from the future as soon as get() or then()
remove the value.
2015-06-06 13:47:44 +03:00
Avi Kivity
3986ad6a11 thread: add seastar::async()
Following std::async(), seastar::async(func) causes func to be executed
in a seastar thread, where it can block using future<>::get().  Whatever
func returns is converted to a future, and returned as async()s return
value.
2015-06-04 20:57:00 +03:00
Gleb Natapov
b06f6f8209 foreign_ptr: introduce make_local_and_release()
Sometimes remote data has to be copied to local cpu, but if data is
already local copy can be avoided. Introduce helper function that moves
or copies data depending on origin cpu.
2015-06-04 18:54:05 +03:00
Vlad Zolotarov
db73024f0c core: distributed::local(): check the vector boundaries before trying to access the element
assert() if we are out of bounds or if the element is not initialized.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-06-04 14:34:58 +03:00
Avi Kivity
8d0bd44b08 do_with: doxygenize 2015-06-03 20:44:48 +03:00
Avi Kivity
5333c54958 Networking module documentation 2015-06-03 20:27:36 +03:00
Avi Kivity
604b13633e distributed: document foreign_ptr<> 2015-06-02 22:37:43 +03:00
Avi Kivity
3fe6bb505e future: document traitless map_reduce() 2015-06-02 22:20:13 +03:00
Avi Kivity
ba0e4e45bc future: disable inline continuations in debug mode
Inline continuations can hide bugs where a stack variable is captured by
reference.  Disable them in debug mode.
2015-06-02 15:12:10 +03:00
Avi Kivity
606368f6f6 shared_ptr: add debug option for detecting copies on wrong cpus
Track the cpu on which the reference count referred to by shared_ptr was
created, and prevent modifying it on the wrong cpu.
2015-06-01 18:18:52 +03:00
Avi Kivity
b0abe9230b doc: fix typo in do_until() 2015-06-01 11:37:42 +03:00
Avi Kivity
23d874f786 doc: low-level memory management 2015-06-01 11:35:37 +03:00
Avi Kivity
3d4314b7e4 doc: disambigute class future from the future documentation module 2015-05-31 19:08:16 +03:00
Avi Kivity
3a63706f97 future: document more future-util functions 2015-05-31 19:00:40 +03:00
Avi Kivity
abaad55a66 future: fix documentation errors
Noted by Nadav.
2015-05-31 18:10:54 +03:00
Avi Kivity
65ff797ec1 doc: add main doxygen page 2015-05-31 17:51:53 +03:00
Avi Kivity
aa519f86a8 future: user-level documentation 2015-05-31 17:29:31 +03:00
Avi Kivity
2877364947 future: separate task class into its own header
tasks are a lower-level concept than future/promise, so move them to their
own header.
2015-05-31 15:49:05 +03:00
Glauber Costa
b77605cdba reactor: call remove instead of unlink
remove() is a convenient glibc wrapper that will unlink() a file and rmdir() a
directory. It will allow us to operate on both without creating a separate
function for a directory.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-05-28 17:56:42 +03:00
Vlad Zolotarov
c547f9a718 fstream: prevent ANY exceptions to be thrown in good get() flow
There is a hidden exception that could be thrown insize file::dma_get_bulk()
if file size is not aligned with fstream::_buffer_size. In this case
file::dma_read_bulk() will be given a _buffer_size as a length for the last data
chunk in the file too. file::dma_read_bulk() will get a short read (till EOF)
and then will try to read beyond it (by calling file::read_maybe_eof())
in order to differentiate between I/O error and EOF. file::read_maybe_eof()
will throw a file::eof_error exception to indicate the EOF, it will be caught
by file::dma_read_bulk() and since we have read some "good" bytes by now this
exception won't be forwarded further. However the damage by throwing the exception
has already been done and we want to avoid this in fstream flow (unless there are
real errors).

In order to prevent the above we will always request file::dma_read_bulk() to
read the amount of data it should be able to deliver (not beyond EOF).

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-28 13:25:40 +03:00
Vlad Zolotarov
b70c9a2e18 file: read_maybe_eof(): Don't throw file::eof_error().
Make read_maybe_eof() return zero-sized buffer when pos is at or beyond
EOF. This will prevent an internal exception throwing inside "file" class
in cases when dma_read_bulk() is going to succeed and return read data, e.g. when
it was called with "offset" less than file size but "offset" + "range_size"
beyond EOF.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-28 13:25:40 +03:00
Vlad Zolotarov
ae03cfbb5d file: clarify the class interface.
Move read_state helper class, file::dma_read_bulk() and file::read_maybe_eof()
definitions outside the class declaration in order to make reading the class
interface easier.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-28 13:25:40 +03:00
Avi Kivity
9243187ac2 stream: make subscriptions a little more usable
Requiring next_fn to be available at listen() time means you can't pass
subscriptions around, and it is often hard to create next_fn, since it
usually needs to capture 'this', while this also points to the subscription
itself, creating a chicken and egg problem.

Fix by separating the registration process into two steps: listen() creates
the subscription, and start() accepts the next callback and starts processing
events.
2015-05-28 13:11:40 +03:00
Avi Kivity
ef11234d0c reactor: add counters for file reads, writes, fsyncs, and threaded fallbacks
Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-05-27 14:16:58 +03:00
Avi Kivity
bdfe41820a future-util.hh: add missing include 2015-05-26 16:42:15 +03:00
Vlad Zolotarov
7b1f433aed file: Rework read interface
Move the get() logic in fstream.cc into the file::dma_read_bulk()
fixing some issues:
   - Fix the funny "alignment" calculation.
   - Make sure the length is aligned too.
   - Added new functions:
      - dma_read(pos, len): returns a temporary_buffer with read data and
                            doesn't assume/require any alignment from either "pos"
                            or "len". Unlike dma_read_bulk() this function will
                            trim the resulting buffer to the requested size.
      - dma_read_exactly(pos, len): does exactly what dma_read(pos, len) does but it
                                    will also throw and exception if it failed to read
                                    the required number of bytes (e.g. EOF is reached).
   - Changed the names of parameters of dma_read(pos, buf, len) in order to emphasize
     that they have to be aligned.
   - Added a description to dma_read(pos, buf, len) to make it even more clear.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-26 15:15:39 +03:00
Vlad Zolotarov
796c203d68 core: remove #include "reactor.hh" from future-util.hh
When future-util.hh is included in files included in reactor.hh (e.g. file.hh).

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-26 15:15:28 +03:00
Avi Kivity
d115f9cef6 future: modernize lambda_task, make_task
Use inline, override, final, make_unique.
2015-05-25 22:21:49 +03:00
Avi Kivity
d1bc08e9e7 future: merge two variants of make_task()
Using universal references we can unify the two cases.
2015-05-25 22:18:24 +03:00
Avi Kivity
8812504e4b future: sprinke always_inline attributes in strategic places
gcc makes poor inlining decisions sometimes, which cause all the value-
tracking optimizations to be lost.  Forcing it to inline (particularly
around destructors) allows ready futures to be inlined with fewer always-
true tests and data movements.
2015-05-25 21:27:40 +03:00
Asias He
88e7dcfa86 Remove redundant const in static constexpr const
From http://en.cppreference.com/w/cpp/language/constexpr:

   A constexpr specifier used in an object declaration implies const.

However, We can not change from
   static constexpr const char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y";
to
   static constexpr char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y";

The compiler complains:

   In file included from json/formatter.cc:22:0:
   json/formatter.hh:132:42: error: deprecated conversion from string
   constant to ‘char*’ [-Werror=write-strings]
        static constexpr char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y";

Since, unlike const, constexpr does not modify a type. It just applies
to an object (or function), and incidentally implies const to the
top-level type.
2015-05-25 11:57:19 +03:00